새메시지, mailboxList를 처리하는 코드 일부 추가

This commit is contained in:
2018-02-12 22:42:05 +09:00
parent 8a2d4c3540
commit 7d465c444d
3 changed files with 185 additions and 87 deletions
+8 -1
View File
@@ -44,7 +44,7 @@
} }
.msg_time{ .msg_time{
font-size:0.7em; font-size:0.75em;
font-weight:normal; font-weight:normal;
} }
@@ -90,9 +90,11 @@
border-radius: 3px; border-radius: 3px;
} }
/*
.public_message .msg_target{ .public_message .msg_target{
box-shadow: 2px 2px darkslategrey; box-shadow: 2px 2px darkslategrey;
} }
*/
.msg_target.msg_bright{ .msg_target.msg_bright{
color:black; color:black;
@@ -116,3 +118,8 @@
margin-top:5px; margin-top:5px;
margin-right:5px; margin-right:5px;
} }
#mailbox_list option{
color:white;
background-color:black;
}
+106 -13
View File
@@ -21,13 +21,11 @@ function isBrightColor(color){
} }
var messageTemplate = ''; var messageTemplate = '';
var generalID=null;
var isChief = false;
var sequence =null;
var refreshMsg = (function(){ function refreshMsg(){
var generalID=null;
var isChief = false;
var sequence =null;
return function(){
var deferred = $.ajax({ var deferred = $.ajax({
url: 'json_result.php', url: 'json_result.php',
type: 'post', type: 'post',
@@ -43,8 +41,6 @@ var refreshMsg = (function(){
deferred.reject(); deferred.reject();
return; return;
} }
generalID = obj.generalID;
isChief = obj.isChief;
sequence = obj.sequence; sequence = obj.sequence;
return obj; return obj;
} }
@@ -56,8 +52,6 @@ var refreshMsg = (function(){
return true; return true;
} }
console.log(this);
$.each(this, function(){ $.each(this, function(){
var msg = this; var msg = this;
if(!msg.src.nation){ if(!msg.src.nation){
@@ -95,16 +89,19 @@ var refreshMsg = (function(){
return true; return true;
} }
if(msgType == 'diplomacy'){
//외교는 항상 새로 그린다
$msgBoard.empty();
}
//list의 맨 앞이 가장 최신 메시지임. //list의 맨 앞이 가장 최신 메시지임.
var msgHtmls = msgSource.map(function(msg){ var msgHtmls = msgSource.map(function(msg){
msg.msgType = msgType; msg.msgType = msgType;
var msgHtml = TemplateEngine(messageTemplate, msg); var msgHtml = TemplateEngine(messageTemplate, msg);
console.log(msgHtml);
return msgHtml; return msgHtml;
}); });
var $items = $(msgHtmls.join('')); var $items = $(msgHtmls.join(''));
console.log($items);
$msgBoard.prepend($items); $msgBoard.prepend($items);
}); });
@@ -118,12 +115,108 @@ var refreshMsg = (function(){
}
function refreshMailboxList(obj){
generalID = obj.generalID;
isChief = obj.isChief;
var last = {
'id':obj.last
}; };
})(); var myNation = {
'mailbox':obj.myNationMailbox,
'color':'#000000',
'nation':'재야'
};
var $mailboxList = $('#mailbox_list');
$mailboxList.change(function(){
console.log($(this).val());
})
var oldSelected = $mailboxList.val();
$mailboxList.empty();
$.each(obj.nation, function(){
var nation = this;
var $optgroup = $('<optgroup label="{0}"></optgroup>'.format(nation.nation));
$optgroup.css('background-color', nation.color);
if(myNation.mailbox == nation.mailbox){
myNation.color = nation.color;
}
if(isBrightColor(nation.color)){
$optgroup.css('color', 'black');
}
else{
$optgroup.css('color', 'white');
}
$.each(nation.general, function(){
var generalID = this[0];
var generalName = this[1];
var isRuler = this.length>2;
if(generalID == last.id){
last.name = generalName;
}
var textName = generalName;
if(isRuler){
textName = '*{0}*'.format(textName);
}
var $item = $('<option value="{0}">{1}</option>'.format(generalID, textName));
$optgroup.append($item);
});
$mailboxList.append($optgroup);
});
var $favorite = $('<optgroup label="즐겨찾기"></optgroup>');
//아국메시지, 전체메시지
var $ourCountry = $('<option value="{0}">【 아국 메세지 】</option>'.format(myNation.mailbox))
.css({'background-color':myNation.color, 'color':isBrightColor(myNation.color)?'black':'white'});
var $toPublic = $('<option value="9999">【 전체 메세지 】</option>');
$favorite.append($ourCountry);
$favorite.append($toPublic);
//최근 대화상대
if(last.id){
var $last = $('<option value="{0}">{1}</option>'.format(last.id, last.name));
$favorite.append($last);
}
//TODO:운영자를 추가하는 코드도 넣을 것.
$mailboxList.prepend($favorite);
if(!oldSelected){
$mailboxList.val(myNation.mailbox);
}
else{
$mailboxList.val(oldSelected);
}
}
jQuery(function($){ jQuery(function($){
$.get('tmp_template.html',function(obj){ $.get('tmp_template.html',function(obj){
messageTemplate = obj; messageTemplate = obj;
}).then(refreshMsg); }).then(refreshMsg);
//refreshMsg(); //refreshMsg();
$.ajax({
url: 'sender_list.json',
type: 'post',
dataType:'json',
contentType: 'application/json',
data: JSON.stringify({
})
}).then(refreshMailboxList);
}); });
+2 -4
View File
@@ -27,10 +27,8 @@
<span class="msg_time">&lt;<%e(time)%>&gt;</span> <span class="msg_time">&lt;<%e(time)%>&gt;</span>
</div> </div>
<div class="msg_content"> <div class="msg_content"><%e(text)%></div>
<%e(text)%> <%if(this.option) {%>
</div>
<%if(this.option){ console.log('HasOption!!'); %>
<div class="msg_prompt"> <div class="msg_prompt">
<button class="prompt_yes btn_prompt">수락</button> <button class="prompt_no btn_prompt">거절</button> <button class="prompt_yes btn_prompt">수락</button> <button class="prompt_no btn_prompt">거절</button>
</div> </div>