diff --git a/tmp_msg/msg.css b/tmp_msg/msg.css index adc4da9f..6e60782e 100644 --- a/tmp_msg/msg.css +++ b/tmp_msg/msg.css @@ -44,7 +44,7 @@ } .msg_time{ - font-size:0.7em; + font-size:0.75em; font-weight:normal; } @@ -90,9 +90,11 @@ border-radius: 3px; } +/* .public_message .msg_target{ box-shadow: 2px 2px darkslategrey; } +*/ .msg_target.msg_bright{ color:black; @@ -115,4 +117,9 @@ text-align:right; margin-top:5px; margin-right:5px; +} + +#mailbox_list option{ + color:white; + background-color:black; } \ No newline at end of file diff --git a/tmp_msg/msg.js b/tmp_msg/msg.js index ff3429fd..67e1083d 100644 --- a/tmp_msg/msg.js +++ b/tmp_msg/msg.js @@ -21,109 +21,202 @@ function isBrightColor(color){ } var messageTemplate = ''; +var generalID=null; +var isChief = false; +var sequence =null; -var refreshMsg = (function(){ - var generalID=null; - var isChief = false; - var sequence =null; +function refreshMsg(){ + var deferred = $.ajax({ + url: 'json_result.php', + type: 'post', + dataType:'json', + contentType: 'application/json', + data: JSON.stringify({ + sequence:sequence + }) + }); - return function(){ - var deferred = $.ajax({ - url: 'json_result.php', - type: 'post', - dataType:'json', - contentType: 'application/json', - data: JSON.stringify({ - sequence:sequence - }) - }); - - function registerGlobal(obj){ - if(!obj.result){ - deferred.reject(); - return; + function registerGlobal(obj){ + if(!obj.result){ + deferred.reject(); + return; + } + sequence = obj.sequence; + return obj; + } + + function refineMessageObjs(obj){ + var msgList = [obj.public, obj.private, obj.diplomacy, obj.national]; + $.each(msgList, function(){ + if(!this){ + return true; } - generalID = obj.generalID; - isChief = obj.isChief; - sequence = obj.sequence; - return obj; - } - function refineMessageObjs(obj){ - var msgList = [obj.public, obj.private, obj.diplomacy, obj.national]; - $.each(msgList, function(){ - if(!this){ - return true; + $.each(this, function(){ + var msg = this; + if(!msg.src.nation){ + msg.src.nation = '재야'; + msg.src.color = '#ffffff'; } - console.log(this); - - $.each(this, function(){ - var msg = this; - if(!msg.src.nation){ - msg.src.nation = '재야'; - msg.src.color = '#ffffff'; - } - - if(!msg.dest.nation){ - msg.dest.nation = '재야'; - msg.dest.color = '#ffffff'; - } - - msg.src.colorType = isBrightColor(msg.src.color)?'bright':'dark'; - msg.dest.colorType = isBrightColor(msg.dest.color)?'bright':'dark'; - }); - }); - return obj; - } - - function printTemplate(obj){ - var printList = [ - [obj.public, $('#message_board .public_message'), 'public'], - [obj.private, $('#message_board .private_message'), 'private'], - [obj.diplomacy, $('#message_board .diplomacy_message'), 'diplomacy'], - [obj.national, $('#message_board .national_message'), 'national'], - ]; - - $.each(printList, function(){ - var msgSource = this[0]; - var $msgBoard = this[1]; - var msgType = this[2]; - - if(!msgSource || $msgBoard.length == 0){ - console.log('No Items', msgSource, $msgBoard); - return true; + if(!msg.dest.nation){ + msg.dest.nation = '재야'; + msg.dest.color = '#ffffff'; } - //list의 맨 앞이 가장 최신 메시지임. - var msgHtmls = msgSource.map(function(msg){ - msg.msgType = msgType; - var msgHtml = TemplateEngine(messageTemplate, msg); - console.log(msgHtml); - return msgHtml; - }); + msg.src.colorType = isBrightColor(msg.src.color)?'bright':'dark'; + msg.dest.colorType = isBrightColor(msg.dest.color)?'bright':'dark'; + }); + }); + return obj; + } - var $items = $(msgHtmls.join('')); - console.log($items); - $msgBoard.prepend($items); + function printTemplate(obj){ + var printList = [ + [obj.public, $('#message_board .public_message'), 'public'], + [obj.private, $('#message_board .private_message'), 'private'], + [obj.diplomacy, $('#message_board .diplomacy_message'), 'diplomacy'], + [obj.national, $('#message_board .national_message'), 'national'], + ]; + + $.each(printList, function(){ + var msgSource = this[0]; + var $msgBoard = this[1]; + var msgType = this[2]; + + if(!msgSource || $msgBoard.length == 0){ + console.log('No Items', msgSource, $msgBoard); + return true; + } + + if(msgType == 'diplomacy'){ + //외교는 항상 새로 그린다 + $msgBoard.empty(); + } + + //list의 맨 앞이 가장 최신 메시지임. + var msgHtmls = msgSource.map(function(msg){ + msg.msgType = msgType; + var msgHtml = TemplateEngine(messageTemplate, msg); + return msgHtml; }); - } + var $items = $(msgHtmls.join('')); + $msgBoard.prepend($items); + }); - deferred - .then(registerGlobal) - .then(refineMessageObjs) - .then(printTemplate); + } + + deferred + .then(registerGlobal) + .then(refineMessageObjs) + .then(printTemplate); +} + +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 = $(''.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 = $(''.format(generalID, textName)); + $optgroup.append($item); + }); + + $mailboxList.append($optgroup); + }); + + var $favorite = $(''); + + //아국메시지, 전체메시지 + var $ourCountry = $(''.format(myNation.mailbox)) + .css({'background-color':myNation.color, 'color':isBrightColor(myNation.color)?'black':'white'}); + var $toPublic = $(''); + $favorite.append($ourCountry); + $favorite.append($toPublic); + + //최근 대화상대 + if(last.id){ + var $last = $(''.format(last.id, last.name)); + $favorite.append($last); + } + + //TODO:운영자를 추가하는 코드도 넣을 것. + + $mailboxList.prepend($favorite); + + if(!oldSelected){ + $mailboxList.val(myNation.mailbox); + } + else{ + $mailboxList.val(oldSelected); + } +} jQuery(function($){ $.get('tmp_template.html',function(obj){ messageTemplate = obj; }).then(refreshMsg); //refreshMsg(); + + $.ajax({ + url: 'sender_list.json', + type: 'post', + dataType:'json', + contentType: 'application/json', + data: JSON.stringify({ + + }) + }).then(refreshMailboxList); }); \ No newline at end of file diff --git a/tmp_msg/tmp_template.html b/tmp_msg/tmp_template.html index a7048e93..ea398a8b 100644 --- a/tmp_msg/tmp_template.html +++ b/tmp_msg/tmp_template.html @@ -27,10 +27,8 @@ <<%e(time)%>> -
- <%e(text)%> -
- <%if(this.option){ console.log('HasOption!!'); %> +
<%e(text)%>
+ <%if(this.option) {%>