새메시지, 로딩 즉시 필요한 데이터들을 모두 비동기로 불러오도록 변경
This commit is contained in:
+27
-14
@@ -27,8 +27,13 @@ var sequence =null;
|
|||||||
var myNation = null;
|
var myNation = null;
|
||||||
var lastMsg = null;
|
var lastMsg = null;
|
||||||
|
|
||||||
|
|
||||||
function refreshMsg(){
|
function refreshMsg(){
|
||||||
var deferred = $.ajax({
|
return redrawMsg(fetchMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchMsg(){
|
||||||
|
return $.ajax({
|
||||||
url: 'json_result.php',
|
url: 'json_result.php',
|
||||||
type: 'post',
|
type: 'post',
|
||||||
dataType:'json',
|
dataType:'json',
|
||||||
@@ -37,7 +42,12 @@ function refreshMsg(){
|
|||||||
sequence:sequence
|
sequence:sequence
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function redrawMsg(deferred){
|
||||||
|
|
||||||
|
console.log(deferred);
|
||||||
|
|
||||||
function registerSequence(obj){
|
function registerSequence(obj){
|
||||||
if(!obj.result){
|
if(!obj.result){
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
@@ -120,6 +130,11 @@ function refreshMsg(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function refreshMailboxList(obj){
|
function refreshMailboxList(obj){
|
||||||
|
//$.ajax는 data, textStatus, jqXHR를 가진다
|
||||||
|
//when으로 묶었으므로 data를 풀어야함.
|
||||||
|
obj = obj[0];
|
||||||
|
|
||||||
|
|
||||||
var $mailboxList = $('#mailbox_list');
|
var $mailboxList = $('#mailbox_list');
|
||||||
|
|
||||||
$mailboxList.change(function(){
|
$mailboxList.change(function(){
|
||||||
@@ -132,7 +147,7 @@ function refreshMailboxList(obj){
|
|||||||
|
|
||||||
$.each(obj.nation, function(){
|
$.each(obj.nation, function(){
|
||||||
var nation = this;
|
var nation = this;
|
||||||
console.log(nation);
|
//console.log(nation);
|
||||||
var $optgroup = $('<optgroup label="{0}"></optgroup>'.format(nation.nation));
|
var $optgroup = $('<optgroup label="{0}"></optgroup>'.format(nation.nation));
|
||||||
$optgroup.css('background-color', nation.color);
|
$optgroup.css('background-color', nation.color);
|
||||||
|
|
||||||
@@ -199,11 +214,8 @@ function refreshMailboxList(obj){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerGlobal(basicInfo, senderList){
|
function registerGlobal(basicInfo){
|
||||||
//$.ajax는 data, textStatus, jqXHR를 가진다
|
|
||||||
//when으로 묶었으므로 data를 풀어야함.
|
|
||||||
basicInfo = basicInfo[0];
|
|
||||||
senderList = senderList[0];
|
|
||||||
myNation = {
|
myNation = {
|
||||||
'mailbox':basicInfo.myNationMailbox,
|
'mailbox':basicInfo.myNationMailbox,
|
||||||
'color':'#000000',
|
'color':'#000000',
|
||||||
@@ -214,8 +226,6 @@ function registerGlobal(basicInfo, senderList){
|
|||||||
};
|
};
|
||||||
myGeneralID = basicInfo.generalID;
|
myGeneralID = basicInfo.generalID;
|
||||||
isChief = basicInfo.isChief;
|
isChief = basicInfo.isChief;
|
||||||
|
|
||||||
return senderList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jQuery(function($){
|
jQuery(function($){
|
||||||
@@ -234,7 +244,7 @@ jQuery(function($){
|
|||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
|
|
||||||
})
|
})
|
||||||
});
|
}).then(registerGlobal);
|
||||||
|
|
||||||
//sender_list.json 은 서버측에선 캐시 가능한 데이터임.
|
//sender_list.json 은 서버측에선 캐시 가능한 데이터임.
|
||||||
var senderList = $.ajax({
|
var senderList = $.ajax({
|
||||||
@@ -246,11 +256,14 @@ jQuery(function($){
|
|||||||
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var MessageList = fetchMsg();
|
||||||
|
|
||||||
$.when(basicInfo, senderList)
|
$.when(senderList, basicInfo)
|
||||||
.then(registerGlobal)
|
|
||||||
.then(refreshMailboxList);
|
.then(refreshMailboxList);
|
||||||
|
|
||||||
$.when(basicInfo, getTemplate)
|
$.when(MessageList, getTemplate, basicInfo)
|
||||||
.then(refreshMsg);
|
.then(function(){
|
||||||
|
redrawMsg(MessageList);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user