From 6f8ac8dc6fd8284999e6b4b2551d2989d2fabfbf Mon Sep 17 00:00:00 2001 From: hide_d Date: Mon, 12 Feb 2018 23:57:12 +0900 Subject: [PATCH] =?UTF-8?q?=EC=83=88=EB=A9=94=EC=8B=9C=EC=A7=80,=20?= =?UTF-8?q?=EB=A1=9C=EB=94=A9=20=EC=A6=89=EC=8B=9C=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=93=A4=EC=9D=84=20?= =?UTF-8?q?=EB=AA=A8=EB=91=90=20=EB=B9=84=EB=8F=99=EA=B8=B0=EB=A1=9C=20?= =?UTF-8?q?=EB=B6=88=EB=9F=AC=EC=98=A4=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tmp_msg/msg.js | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/tmp_msg/msg.js b/tmp_msg/msg.js index cf8b8c41..d6bea1d9 100644 --- a/tmp_msg/msg.js +++ b/tmp_msg/msg.js @@ -27,8 +27,13 @@ var sequence =null; var myNation = null; var lastMsg = null; + function refreshMsg(){ - var deferred = $.ajax({ + return redrawMsg(fetchMsg()); +} + +function fetchMsg(){ + return $.ajax({ url: 'json_result.php', type: 'post', dataType:'json', @@ -37,7 +42,12 @@ function refreshMsg(){ sequence:sequence }) }); +} + +function redrawMsg(deferred){ + console.log(deferred); + function registerSequence(obj){ if(!obj.result){ deferred.reject(); @@ -120,6 +130,11 @@ function refreshMsg(){ } function refreshMailboxList(obj){ + //$.ajax는 data, textStatus, jqXHR를 가진다 + //when으로 묶었으므로 data를 풀어야함. + obj = obj[0]; + + var $mailboxList = $('#mailbox_list'); $mailboxList.change(function(){ @@ -132,7 +147,7 @@ function refreshMailboxList(obj){ $.each(obj.nation, function(){ var nation = this; - console.log(nation); + //console.log(nation); var $optgroup = $(''.format(nation.nation)); $optgroup.css('background-color', nation.color); @@ -199,11 +214,8 @@ function refreshMailboxList(obj){ } } -function registerGlobal(basicInfo, senderList){ - //$.ajax는 data, textStatus, jqXHR를 가진다 - //when으로 묶었으므로 data를 풀어야함. - basicInfo = basicInfo[0]; - senderList = senderList[0]; +function registerGlobal(basicInfo){ + myNation = { 'mailbox':basicInfo.myNationMailbox, 'color':'#000000', @@ -214,8 +226,6 @@ function registerGlobal(basicInfo, senderList){ }; myGeneralID = basicInfo.generalID; isChief = basicInfo.isChief; - - return senderList; } jQuery(function($){ @@ -234,7 +244,7 @@ jQuery(function($){ data: JSON.stringify({ }) - }); + }).then(registerGlobal); //sender_list.json 은 서버측에선 캐시 가능한 데이터임. var senderList = $.ajax({ @@ -246,11 +256,14 @@ jQuery(function($){ }) }); + + var MessageList = fetchMsg(); - $.when(basicInfo, senderList) - .then(registerGlobal) + $.when(senderList, basicInfo) .then(refreshMailboxList); - $.when(basicInfo, getTemplate) - .then(refreshMsg); + $.when(MessageList, getTemplate, basicInfo) + .then(function(){ + redrawMsg(MessageList); + }); }); \ No newline at end of file