From b47285c545362f213b6dbd9f672dedc25b9b8105 Mon Sep 17 00:00:00 2001 From: hide_d Date: Tue, 13 Feb 2018 01:01:02 +0900 Subject: [PATCH] =?UTF-8?q?=EC=83=88=EB=A9=94=EC=8B=9C=EC=A7=80,=20?= =?UTF-8?q?=ED=81=B4=EB=9D=BC=EC=9D=B4=EC=96=B8=ED=8A=B8=20=EB=8B=A8=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=8B=9C=EC=8A=A4=ED=85=9C=201?= =?UTF-8?q?=EC=B0=A8=20=EC=99=84=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tmp_msg/add_msg_dummy.php | 11 +++ tmp_msg/fresh_result.json | 20 +++--- tmp_msg/json_result.php | 4 +- tmp_msg/msg.html | 2 +- tmp_msg/msg.js | 105 ++++++++++++++++++++++++++-- tmp_msg/prompt_dummy.php | 4 +- tmp_msg/tmp_template.html | 1 + tmp_msg/update_national_result.json | 43 +++++++++++- tmp_msg/update_private_result.json | 70 ++++++++++++++++++- tmp_msg/update_public_result.json | 18 ++++- 10 files changed, 254 insertions(+), 24 deletions(-) create mode 100644 tmp_msg/add_msg_dummy.php diff --git a/tmp_msg/add_msg_dummy.php b/tmp_msg/add_msg_dummy.php new file mode 100644 index 00000000..d95645df --- /dev/null +++ b/tmp_msg/add_msg_dummy.php @@ -0,0 +1,11 @@ +true, + 'reason'=>'success', + 'msgID'=>1997 +], JSON_UNESCAPED_UNICODE); \ No newline at end of file diff --git a/tmp_msg/fresh_result.json b/tmp_msg/fresh_result.json index 4ae8d13a..d2388f6a 100644 --- a/tmp_msg/fresh_result.json +++ b/tmp_msg/fresh_result.json @@ -187,7 +187,7 @@ ], "public":[ { - "id":1013, + "id":1103, "time":"2018-02-10 22:05:02", "isSender":false, "src":{ @@ -203,7 +203,7 @@ "text":"전메놀이3, 특수" }, { - "id":1012, + "id":1102, "time":"2018-02-10 22:05:01", "isSender":false, "src":{ @@ -232,7 +232,7 @@ }, "text":"최대한많은길이의텍스트를전메에넣어보려고시도하는중입니다글자수기준이니띄어쓰기나숫자알파벳이없도록해야꽉꽉밀어넣을수있습니다어디까지들어가려나얼마나더적어야하는거지잘모르겠다의외로칸이꽤길구나메시지" },{ - "id":1010, + "id":1100, "time":"2018-02-10 22:05:00", "isSender":false, "src":{ @@ -250,7 +250,7 @@ ], "private":[ { - "id":1025, + "id":1205, "time":"2018-02-10 22:04:04", "isSender":false, "src":{ @@ -273,7 +273,7 @@ "action":"scout" } },{ - "id":1024, + "id":1204, "time":"2018-02-10 22:04:04", "isSender":false, "src":{ @@ -290,7 +290,7 @@ }, "text":"재야로부터 갠메(수신)" },{ - "id":1023, + "id":1203, "time":"2018-02-10 22:04:03", "isSender":true, "src":{ @@ -309,7 +309,7 @@ }, "text":"타국 갠메(송신)" },{ - "id":1022, + "id":1202, "time":"2018-02-10 22:04:02", "isSender":true, "src":{ @@ -328,7 +328,7 @@ }, "text":"아국 갠메(수신)" },{ - "id":1021, + "id":1201, "time":"2018-02-10 22:04:01", "isSender":true, "src":{ @@ -347,7 +347,7 @@ }, "text":"아국 갠메(수신)" },{ - "id":1020, + "id":1200, "time":"2018-02-10 22:04:00", "isSender":true, "src":{ @@ -369,7 +369,7 @@ ], "diplomacy":[ { - "id":1030, + "id":1300, "time":"2018-02-10 22:05:04", "isSender":false, "src":{ diff --git a/tmp_msg/json_result.php b/tmp_msg/json_result.php index a9213754..71f56de2 100644 --- a/tmp_msg/json_result.php +++ b/tmp_msg/json_result.php @@ -43,10 +43,10 @@ switch($reqSequence){ relayJson('update_private_result.json'); break; case 1366: - relayJson('update_public_result.json'); + relayJson('update_national_result.json'); break; case 1811: - relayJson('update_national_result.json'); + relayJson('update_public_result.json'); break; } diff --git a/tmp_msg/msg.html b/tmp_msg/msg.html index 8fd05984..32bd7031 100644 --- a/tmp_msg/msg.html +++ b/tmp_msg/msg.html @@ -27,7 +27,7 @@ - +
diff --git a/tmp_msg/msg.js b/tmp_msg/msg.js index d6bea1d9..f45be012 100644 --- a/tmp_msg/msg.js +++ b/tmp_msg/msg.js @@ -27,6 +27,18 @@ var sequence =null; var myNation = null; var lastMsg = null; +function responseMessage(msgID, response){ + $.ajax({ + url: 'prompt_dummy.php', + type: 'post', + dataType:'json', + contentType: 'application/json', + data: JSON.stringify({ + msgID:msgID, + response:response + }) + }).then(refreshMsg); +} function refreshMsg(){ return redrawMsg(fetchMsg()); @@ -107,14 +119,47 @@ function redrawMsg(deferred){ } //list의 맨 앞이 가장 최신 메시지임. - var msgHtmls = msgSource.map(function(msg){ + var $msgs = msgSource.map(function(msg){ + + + msg.msgType = msgType; var msgHtml = TemplateEngine(messageTemplate, msg); - return msgHtml; + + + //만약 이전 메시지가 변경된 것인가 확인한다. + var $existMsg = $('#msg_{0}'.format(msg.id)); + var $msg = $(msgHtml); + if($existMsg.length){ + $existMsg.html($msg.html()); + $msg = $existMsg; + } + + $msg.find('button.prompt_yes').click(function(){ + if(!confirm("수락하시겠습니까?")){ + return false; + } + responseMessage(msg.id, true); + + }); + + $msg.find('button.prompt_no').click(function(){ + if(!confirm("거절하시겠습니까?")){ + return false; + } + responseMessage(msg.id, false); + }); + + if($existMsg.length){ + return null; + } + else{ + return $msg; + } + }); - var $items = $(msgHtmls.join('')); - $msgBoard.prepend($items); + $msgBoard.prepend($msgs); }); } @@ -145,6 +190,8 @@ function refreshMailboxList(obj){ $mailboxList.empty(); + //TODO:수뇌인 경우 각국에 대해 외교 국메를 넣을 수 있어야함. + $.each(obj.nation, function(){ var nation = this; //console.log(nation); @@ -228,6 +275,53 @@ function registerGlobal(basicInfo){ isChief = basicInfo.isChief; } +function activateMessageForm(){ + var $msgInput = $('#msg_input'); + var $msgSubmit = $('#msg_submit'); + var $mailboxList = $('#mailbox_list'); + + $msgInput.keypress(function (e) { + var code = (e.keyCode ? e.keyCode : e.which); + if (code == 13) { + $msgSubmit.trigger('click'); + return true; + } + }); + + $msgSubmit.click(function(){ + + var text = $.trim($msgInput.val()); + $msgInput.val('').focus(); + + var targetMailbox = $mailboxList.val(); + console.log(targetMailbox, text); + + var deferred; + + if(text){ + deferred = $.ajax({ + url:'add_msg_dummy.php', + type: 'post', + dataType:'json', + contentType: 'application/json', + data: JSON.stringify({ + mailbox:targetMailbox, + text:text + }) + }); + } + else{ + deferred = $.Deferred(); + deferred.resolve({ + result:true, + reason:'no_text' + }); + } + + deferred.then(refreshMsg); + }); +} + jQuery(function($){ //tmp_template.html은 추후 msg.js에 통합될 수 있음 @@ -260,7 +354,8 @@ jQuery(function($){ var MessageList = fetchMsg(); $.when(senderList, basicInfo) - .then(refreshMailboxList); + .then(refreshMailboxList) + .then(activateMessageForm); $.when(MessageList, getTemplate, basicInfo) .then(function(){ diff --git a/tmp_msg/prompt_dummy.php b/tmp_msg/prompt_dummy.php index 0acbab10..d036c30e 100644 --- a/tmp_msg/prompt_dummy.php +++ b/tmp_msg/prompt_dummy.php @@ -2,7 +2,9 @@ require('../twe/lib.php'); use utilphp\util as util; -return json_encode([ +$jsonPost = parseJsonPost(); + +echo json_encode([ 'result'=>true, 'reason'=>'success' ], JSON_UNESCAPED_UNICODE); \ No newline at end of file diff --git a/tmp_msg/tmp_template.html b/tmp_msg/tmp_template.html index ea398a8b..6d1d0a61 100644 --- a/tmp_msg/tmp_template.html +++ b/tmp_msg/tmp_template.html @@ -1,6 +1,7 @@
<%if(src.icon) { %> diff --git a/tmp_msg/update_national_result.json b/tmp_msg/update_national_result.json index 1547750c..2b8e6047 100644 --- a/tmp_msg/update_national_result.json +++ b/tmp_msg/update_national_result.json @@ -1,9 +1,48 @@ { "result":true, "server":"d1af658a-f094-4303-9496-9a27a8180b0b", - "sequence":1357, + "sequence":1811, "national":[ - + { + "id":1210, + "time":"2018-02-10 22:05:09", + "isSender":false, + "src":{ + "id":11, + "nation_id":1, + "name":"Hide_D", + "icon":"pic_781.jpg", + "nation":"연구소", + "color":"#ffd700" + }, + "dest":{ + "id":9001, + "nation_id":1, + "nation":"연구소", + "color":"#ffd700" + }, + "text":"새롭게 추가된 나의 텍스트!" + }, + { + "id":1209, + "time":"2018-02-10 22:05:08", + "isSender":false, + "src":{ + "id":11, + "nation_id":1, + "name":"Hide_D", + "icon":"pic_781.jpg", + "nation":"연구소", + "color":"#ffd700" + }, + "dest":{ + "id":9001, + "nation_id":1, + "nation":"연구소", + "color":"#ffd700" + }, + "text":"외교를 거절해버렸당" + } ], "public":[ diff --git a/tmp_msg/update_private_result.json b/tmp_msg/update_private_result.json index 29182742..e1b69b10 100644 --- a/tmp_msg/update_private_result.json +++ b/tmp_msg/update_private_result.json @@ -9,9 +9,75 @@ ], "private":[ - + { + "id":1205, + "time":"2018-02-10 22:06:00", + "isSender":false, + "src":{ + "id":21, + "nation_id":2, + "name":"Hide_Dx2", + "nation":"연구소2", + "color":"#ff0000" + }, + "dest":{ + "id":11, + "nation_id":1, + "name":"Hide_D", + "nation":"연구소", + "color":"#ffd700" + }, + "text":"연구소2로 망명 권유 서신을 거절" + }, + { + "id":1206, + "time":"2018-02-10 22:04:04", + "isSender":false, + "src":{ + "id":21, + "nation_id":2, + "name":"Hide_Dx2", + "nation":"연구소2", + "color":"#ff0000" + }, + "dest":{ + "id":11, + "nation_id":1, + "name":"Hide_D", + "nation":"연구소", + "color":"#ffd700" + }, + "text":"추가해라 더 많은 갠메!" + } ], "diplomacy":[ - + { + "id":1300, + "time":"2018-02-10 22:05:04", + "isSender":false, + "src":{ + "id":21, + "nation_id":2, + "name":"Hide_Dx2", + "nation":"연구소2", + "color":"#ff0000", + "icon":"pic_1.jpg" + }, + "dest":{ + "id":9001, + "nation_id":1, + "nation":"연구소", + "color":"#ffd700" + }, + "text":"타국->아국", + "option":{ + "used":false, + "result":false, + "until":[210, 9], + "action":"ally", + "allyYear":20, + "allyText":"메롱" + } + } ] } \ No newline at end of file diff --git a/tmp_msg/update_public_result.json b/tmp_msg/update_public_result.json index 7ab665be..dfc99f48 100644 --- a/tmp_msg/update_public_result.json +++ b/tmp_msg/update_public_result.json @@ -1,11 +1,27 @@ { "result":true, "server":"d1af658a-f094-4303-9496-9a27a8180b0b", - "sequence":1811, + "sequence":1997, "national":[ ], "public":[ + { + "id":1106, + "time":"2018-02-10 22:05:02", + "isSender":false, + "src":{ + "id":41, + "nation_id":3, + "name":"Hide_Dz1", + "nation":"연구소3", + "color":"#000080" + }, + "dest":{ + "id":9999 + }, + "text":"나는 전메를 입력했당" + } ], "private":[