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":[