|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | + |
| 4 | +<head> |
| 5 | + <% include ../partials/head %> |
| 6 | + <script> |
| 7 | + var load = null; |
| 8 | + var del = null; |
| 9 | +
|
| 10 | + $(document).ready(function() { |
| 11 | + //작성된 메모 목록을 로드합니다. |
| 12 | + var load = function() { |
| 13 | + $.get('/load', function(data) { |
| 14 | + // $(".user_data").empty(); |
| 15 | +
|
| 16 | + user_index = $(data).length; |
| 17 | +
|
| 18 | + $("#user_board").append("<tr class='board_title'><th>ID</th><th>NAME</th><th>EMAIL</th><th>POSITION</th><th>INTEREST</th></tr>"); |
| 19 | +
|
| 20 | + var data_id = []; |
| 21 | +
|
| 22 | + $($(data).get()).each(function(i) { |
| 23 | + var id = this._id; |
| 24 | + data_id.push(id); |
| 25 | + }); |
| 26 | +
|
| 27 | + function shuffle(array) { |
| 28 | + var currentIndex = array.length, temporaryValue, randomIndex; |
| 29 | +
|
| 30 | + // While there remain elements to shuffle... |
| 31 | + while (0 !== currentIndex) { |
| 32 | +
|
| 33 | + // Pick a remaining element... |
| 34 | + randomIndex = Math.floor(Math.random() * currentIndex); |
| 35 | + currentIndex -= 1; |
| 36 | +
|
| 37 | + // And swap it with the current element. |
| 38 | + temporaryValue = array[currentIndex]; |
| 39 | + array[currentIndex] = array[randomIndex]; |
| 40 | + array[randomIndex] = temporaryValue; |
| 41 | + } |
| 42 | +
|
| 43 | + return array; |
| 44 | + } |
| 45 | +
|
| 46 | + // Used like so |
| 47 | + rand_data = shuffle($(data).get()); |
| 48 | +
|
| 49 | + $(rand_data).each(function(i) { |
| 50 | + user_id_index = data_id.indexOf(this._id); |
| 51 | +
|
| 52 | + var id = this._id; |
| 53 | +
|
| 54 | + $("#user_board").append("<tr class='board_item'></tr>"); |
| 55 | +
|
| 56 | + $("#user_board .board_item:last").append("<td rowspan='2' class='user_index board_sep " + id + "'>" + (user_id_index + 1) + "</td>"); |
| 57 | + $("#user_board .board_item:last").append("<td class='user_name'>" + this.user_name + "</td>"); |
| 58 | + $("#user_board .board_item:last").append("<td class='user_email'>" + this.user_email + "</td>"); |
| 59 | + $("#user_board .board_item:last").append("<td class='user_position'>" + this.user_position + "</td>"); |
| 60 | + $("#user_board .board_item:last").append("<td class='user_interest'>" + this.user_interest + "</td>"); |
| 61 | +
|
| 62 | + $("#user_board").append("<tr class='contents board_sep " + id + "'><td colspan='4'>" + this.user_description + "</td></tr>"); |
| 63 | +
|
| 64 | + user_index = user_index - 1; |
| 65 | + }); |
| 66 | +
|
| 67 | + }); |
| 68 | + }; |
| 69 | +
|
| 70 | + //메모 삭제 요청을 처리하는 부분입니다. |
| 71 | + var del = function(id) { |
| 72 | + var postdata = { |
| 73 | + '_id': id |
| 74 | + }; |
| 75 | +
|
| 76 | + $.post('/del', postdata, function() { |
| 77 | + load(); |
| 78 | + }); |
| 79 | + }; |
| 80 | +
|
| 81 | + load(); |
| 82 | + }); |
| 83 | + </script> |
| 84 | +</head> |
| 85 | + |
| 86 | +<body> |
| 87 | + <table id='user_board'> |
| 88 | + </table> |
| 89 | + <% include ../partials/body_script %> |
| 90 | +</body> |
| 91 | + |
| 92 | +</html> |
0 commit comments