text: define(["service","configPath"],function(e,t){function n(){o=s.DEVICE,c.switchPage(a.LIST),c.loadData()}var a={LIST:1,DELETE:2,CHAT:3},s={DEVICE:1,SIM:0},o=s.DEVICE,i="",c={cacheEle:{},getEle:function(e){return this.cacheEle.hasOwnProperty("id")?this.cacheEle[e]:(this.cacheEle[e]=$("#"+e),this.cacheEle[e])},switchPage:function(e){switch(e){case a.LIST:$(".in-delete,.in-chat").hide(),$(".in-list").show(),$(window).scrollTop(0);break;case a.DELETE:$(".in-list,.in-chat").hide(),$(".in-delete").show(),$(window).scrollTop(0);break;case a.CHAT:$(".in-list,.in-delete").hide(),$(".in-chat").show(),$(window).scrollTop(9999)}},getSmartDate:function(e){var t=e.split(" "),n=t[0].split("/"),a=t[1].split(":");return smartDate(new Date(n[0],n[1]-1,n[2],a[0],a[1],a[2]).getTime())},phonebookReady:!1,messageReady:!1,loadCounter:t.HAS_PHONEBOOK?1:2,canMergeData:!t.HAS_PHONEBOOK,contacts:[],messages:[],loadData:function(){showLoading(),t.HAS_PHONEBOOK&&0==this.phonebookReady?this.checkPhonebookReady():t.HAS_PHONEBOOK&&c.loadPhonebook(),0==this.messageReady?this.checkMessageReady():c.loadMessage()},checkPhonebookReady:function(){e.getPhoneBookReady({},function(e){"6"==e.pbm_init_flag?c.loadCounter++:"0"!=e.pbm_init_flag?addTimeout(function(){c.checkPhonebookReady()},1e3):(c.phonebookReady=!0,c.loadPhonebook(!0))})},loadPhonebook:function(){e.getPhoneBooks({page:0,data_per_page:2e3,orderBy:"name",isAsc:!0},function(e){$.isArray(e.pbm_data)&&e.pbm_data.length>0&&(c.contacts=e.pbm_data),c.canMergeData?c.mergeData():c.canMergeData=!0},function(){c.canMergeData?c.mergeData():c.canMergeData=!0})},checkMessageReady:function(){e.getSMSReady({},function(e){"2"==e.sms_cmd_status_result?(hideLoading(),showAlert("sms_init_fail")):"1"==e.sms_cmd_status_result?addTimeout(function(){c.checkMessageReady()},1e3):(c.messageReady=!0,c.loadMessage())})},loadMessage:function(t){return e.getSMSMessages({page:0,smsCount:500,nMessageStoreType:o,tags:10,orderBy:"order by id desc"},function(e){c.messages=e.messages,c.canMergeData?c.mergeData():c.canMergeData=!0,_.isFunction(t)&&t.apply(this)},function(){})},nameMap:{},listMessage:{},mergeData:function(){c.nameMap={},c.listMessage={};for(var e=0;e<c.contacts.length;e++){var t=c.contacts[e];c.nameMap[getLast8Number(t.pbm_number)]||(c.nameMap[getLast8Number(t.pbm_number)]=t.pbm_name)}for(var n={},a={},s=0;s<c.messages.length;s++){var o=c.messages[s];o.smartDate=c.getSmartDate(o.timeOri),o.date=o.time,o.name=c.nameMap[o.number8]||"",o.shortContent=c.subString(o.content,28),""==o.groupId?a[o.number8]?(a[o.number8].msgs.push(o),a[o.number8].count++,o.isNew&&a[o.number8].newCount++,"4"==o.tag&&(a[o.number8].hasDraft=!0)):a[o.number8]={msgs:[o],title:o.name||o.number,shortTitle:c.subString(o.name||o.number,15),count:1,newCount:o.isNew?1:0,hasDraft:"4"==o.tag,groupId:""}:n[o.groupId]?(n[o.groupId].msgs.push(o),n[o.groupId].count++,n[o.groupId].title+=","+(o.name||o.number)):n[o.groupId]={msgs:[o],title:o.name||o.number,count:1,newCount:0,hasDraft:!0,groupId:o.groupId}}var i={};for(var r in n){var l=n[r];l.shortTitle=c.subString(l.title,15),i[r]=l}c.listMessage=_.extend(a,i);var m=_.template($("#smsItemTmpl").html());c.getEle("sms-list-ul").html(m({messages:c.listMessage})).listview("refresh"),addTimeout(function(){var e=_.template($("#smsDeleteTmpl").html());c.getEle("sms-delete-fieldset").controlgroup("container").html(e({messages:c.listMessage})),$(":checkbox").checkboxradio()},100),this.setSelectCount(),hideLoading()},setSelectCount:function(){setTimeout(function(){var e=$("[name='contactCheckbox']:checked").length;e?(c.getEle("smsDelete").removeClass("ui-state-disabled"),c.getEle("sms-header-title").hide(),c.getEle("sms-header-title-selected").html($.i18n.prop("sms_n_selected",e)).show()):(c.getEle("smsDelete").addClass("ui-state-disabled"),c.getEle("sms-header-title").show(),c.getEle("sms-header-title-selected").hide())},0)},subString:function(e,t){return"UNICODE"==getEncodeType(e).encodeType&&(t/=2),e.length<t?e:e.substring(0,t)+"..."}};return window.smsEvtHandler={backToList:function(){c.switchPage(a.LIST)},switchToDeletePage:function(){c.switchPage(a.DELETE),$("[name='contactCheckbox']").prop("checked",!1).checkboxradio("refresh"),c.setSelectCount()},deleteActionHandler:function(){var t=$("[name='contactCheckbox']:checked");t.length&&showConfirm("confirm_data_delete",function(){showLoading();var n=[],a=[];t.each(function(e,t){t.value.length>SMS_NUMBER_CUT_LENGTH?a.push(t.value):n.push(t.value)});var s=_.filter(c.messages,function(e){return-1!=_.indexOf(n,e.number8)||-1!=_.indexOf(a,e.groupId)}),o=_.map(s,function(e){return e.id});e.deleteMessage({ids:o},function(){c.loadMessage(function(){successOverlay(),addTimeout(function(){c.setSelectCount()},1e3)})},function(e){errorOverlay(e.errorText)})})},cancelHandler:function(){this.backToList()},smsCheckboxChangeHandler:function(){c.setSelectCount()},checkAllChangeHandler:function(e){$(e).is(":checked")?$("[name='contactCheckbox']").prop("checked",!0).checkboxradio("refresh"):$("[name='contactCheckbox']").prop("checked",!1).checkboxradio("refresh"),c.setSelectCount()},locationChangeHandler:function(e){o=e.value,showLoading(),c.loadMessage(function(){hideLoading()})},smsItemClickHandler:function(t){i=t;var n=_.filter(c.messages,function(e){return e.number8==i||e.groupId==i}),s=[];_.map(n,function(e){return e.position="0"==e.tag||"1"==e.tag?"left":"right","3"==e.tag?e.desc=$.i18n.prop("send_fail"):"4"==e.tag?e.desc=$.i18n.prop("draft"):e.desc="","1"==e.tag&&(e.tag="0",s.push(e.id)),e}),e.setSmsRead({ids:s},function(){$(".sms-new-count","#smsListItem"+t).remove()});var o=_.template($("#smsChatTmpl").html());c.getEle("sms-chat-div").html(o({messages:n})),""==n[0].name?(c.getEle("sms-chat-name").html(n[0].number),c.getEle("sms-chat-number").html("")):(c.getEle("sms-chat-name").html(HTMLEncode(n[0].name)),c.getEle("sms-chat-number").html(n[0].number)),c.switchPage(a.CHAT)},deleteChatActionHandler:function(){showConfirm("confirm_number_sms_delete",function(){showLoading();var t=_.filter(c.messages,function(e){return e.number8==i||e.groupId==i}),n=_.map(t,function(e){return e.id});e.deleteMessage({ids:n},function(){c.loadMessage(function(){c.switchPage(a.LIST),successOverlay()})},function(e){errorOverlay(e.errorText)})})}},{init:n}});
  //# sourceMappingURL=../../../sourcemaps/m/sms/list.js.map
  