webphone_api._messagelist = (function () { function onCreate (event) // called only once - bind events here { try{ webphone_api.common.PutToDebugLog(4, "EVENT, _messagelist: onCreate"); webphone_api.$('#messagelist_list').on('click', 'li', function(event) { OnListItemClick(webphone_api.$(this).attr('id')); }); webphone_api.$('#messagelist_notification_list').on('click', '.nt_anchor', function(event) { webphone_api.$("#messagelist_not").panel( "close" ); webphone_api.common.NotificationOnClick2(webphone_api.$(this).attr('id'), false); }); webphone_api.$('#messagelist_notification_list').on('click', '.nt_menu', function(event) { webphone_api.$("#messagelist_not").panel( "close" ); webphone_api.common.NotificationOnClick2(webphone_api.$(this).attr('id'), true); }); webphone_api.$("#messagelist_not_btn").on("click", function() { webphone_api.common.SaveParameter('notification_count2', 0); webphone_api.common.ShowNotifications2(); // repopulate notifications (hide red dot number) }); webphone_api.$( window ).resize(function() // window resize handling { if (webphone_api.$.mobile.activePage.attr('id') === 'page_messagelist') { MeasureMessagelist(); } }); webphone_api.$('#messagelist_menu_ul').on('click', 'li', function(event) { MenuItemSelected(webphone_api.$(this).attr('id')); }); webphone_api.$("#btn_messagelist_menu").on("click", function() { CreateOptionsMenu('#messagelist_menu_ul'); }); webphone_api.$("#btn_messagelist_menu").attr("title", webphone_api.stringres.get("hint_menu")); webphone_api.$("#msglist_btnback").attr("title", webphone_api.stringres.get("hint_btnback")); webphone_api.$("#btn_newmessage").on("click", function() { NewMessage(); }); webphone_api.$( "#page_messagelist" ).keyup(function( event ) { HandleKeyUp(event); }); } catch(err) { webphone_api.common.PutToDebugLogException(2, "_messagelist: onCreate", err); } } function onStart(event) { try{ webphone_api.common.PutToDebugLog(4, "EVENT, _messagelist: onStart"); webphone_api.global.isMessagelistStarted = true; setTimeout(function() // otherwise keyup will not work, because the element is not focused { webphone_api.$("#page_messagelist").focus(); }, 100); //-- webphone_api.$("#phone_number").attr("placeholder", webphone_api.stringres.get("phone_nr")); //-- document.getElementById("app_name_messagelist").innerHTML = webphone_api.common.GetBrandName(); webphone_api.$('#btn_newmessage').html(webphone_api.stringres.get('btn_new_message')); webphone_api.$(".separator_line_thick").css( 'background-color', webphone_api.common.HoverCalc(webphone_api.common.getBgColor('#page_messagelist'), -30) ); if (!webphone_api.common.isNull(document.getElementById('msglist_title'))) { document.getElementById('msglist_title').innerHTML = webphone_api.stringres.get("msglist_title"); } webphone_api.$("#msglist_title").attr("title", webphone_api.stringres.get("hint_page")); if (!webphone_api.common.isNull(document.getElementById('msglist_btnback'))) { document.getElementById('msglist_btnback').innerHTML = '< ' + webphone_api.stringres.get("go_back_btn_txt"); } // needed for proper display and scrolling of listview MeasureMessagelist(); webphone_api.common.HideMessageNotifications2(); // show only call notification // fix for IE 10 if (webphone_api.common.IsIeVersion(10)) { webphone_api.$("#messagelist_list").children().css('line-height', 'normal'); } if (webphone_api.common.IsIeVersion(10)) { webphone_api.$("#messagelist_notification_list").children().css('line-height', 'normal'); } webphone_api.$("#messagelist_notification_list").height(webphone_api.common.GetDeviceHeight() - 55); PopulateList(); } catch(err) { webphone_api.common.PutToDebugLogException(2, "_messagelist: onStart", err); } } function MeasureMessagelist() // resolve window height size change { try{ //-- var pgh = webphone_api.common.GetDeviceHeight() - 1; webphone_api.$('#page_messagelist').css('min-height', pgh + 'px'); // must be set when softphone is skin in div webphone_api.$('#page_messagelist').css('min-height', 'auto'); // must be set when softphone is skin in div // handle notifiaction additional_header_right var notwidth = webphone_api.common.GetDeviceWidth() - webphone_api.$("#messagelist_additional_header_left").width() - webphone_api.$("#messagelist_additional_header_right").width(); var margin = webphone_api.common.StrToIntPx( webphone_api.$("#messagelist_additional_header_left").css("margin-left") ); if (webphone_api.common.isNull(margin) || margin === 0) { margin = 10; } margin = Math.ceil( margin * 6 ); notwidth = Math.floor(notwidth - margin) - 20; // handle page height var heightTemp = webphone_api.common.GetDeviceHeight() - webphone_api.$("#messagelist_header").height() - webphone_api.$("#btn_newmessage_container").height(); heightTemp = Math.floor( heightTemp - 3 ); webphone_api.$("#messagelist_list").height(heightTemp); } catch(err) { webphone_api.common.PutToDebugLogException(2, "_messagelist: MeasureMessagelist", err); } } function LoadMessages() { try{ PopulateList(); //-- if (webphone_api.global.isdebugversion) //-- { //-- if ( webphone_api.common.isNull(webphone_api.global.ctlist) || webphone_api.global.ctlist.length < 1 ) //-- { //-- webphone_api.global.ctlist = []; //-- // String Name, String[] {numbers/sip uris}, String[] {number types}, int usage, long lastmodified, int delete flag, int isfavorit //-- var ctitem = ['Ambrus Akos', ['40724335358', '0268123456', '13245679'], ['home', 'work', 'other'], '0', '13464346', '0', '0']; //-- var ctitem2 = ['Ambrus Tunde', ['123456', '987654'], ['other', 'fax_home'], '0', '23464346', '0', '0']; //-- var ctitem3 = ['Mariska Mari', ['123456', '987654'], ['other', 'fax_home'], '0', '23464346', '0', '0']; //-- webphone_api.global.ctlist.push(ctitem); webphone_api.global.ctlist.push(ctitem2); webphone_api.global.ctlist.push(ctitem3); //-- for (var i = 0; i < 12; i++) //-- { //-- var ctitem_generated = ['Test_' + i, ['123456_' + i, '987654_' + i], ['other', 'fax_home'], '0', '23464346', '0', '0']; //-- webphone_api.global.ctlist.push(ctitem_generated); //-- } //-- } //-- } //-- if (webphone_api.common.isNull(webphone_api.global.ctlist) || webphone_api.global.ctlist.length < 1) //-- { //-- webphone_api.common.GetContacts(function (success) //-- { //-- if (!success) //-- { //-- webphone_api.common.PutToDebugLog(2, 'ERROR, _messagelist: LoadContacts failed'); //-- } //-- PopulateList(); //-- }); //-- }else //-- { //-- PopulateList(); //-- } } catch(err) { webphone_api.common.PutToDebugLogException(2, "_messagelist: LoadMessages", err); } } function PopulateList() // :no return value { try{ if ( webphone_api.common.isNull(document.getElementById('messagelist_list')) ) { webphone_api.common.PutToDebugLog(2, "ERROR, _messagelist: PopulateList listelement is null"); return; } webphone_api.$('#messagelist_list').html(''); // filenames: sms/chat_username_number //-- isdebugversion // type_myusername_tousername[#nrofmissedmsg // var msgfilestest = 'sms_9999_1111[#3,chat_9999_2222,chat_9999_3333,sms_9999_4444,sms_9999_5555,sms_9999_6666'; // webphone_api.common.SaveParameter('messagefiles', msgfilestest); var files = webphone_api.common.GetParameter('messagefiles'); if (webphone_api.common.isNull(files) || files.length < 3) { webphone_api.common.PutToDebugLog(3, 'EVENT, _messagelist: PopulateList no message files'); return; } webphone_api.common.PutToDebugLog(2, 'EVENT, _messagelist Starting populate list'); var msglist = []; if (!webphone_api.common.isNull(files) && files.length > 0) { msglist = files.split(','); } var listview = ''; for (var i = 0; i < msglist.length; i++) { if (webphone_api.common.isNull(msglist[i]) || msglist[i].length < 3) { continue; } var number = msglist[i].substring( msglist[i].lastIndexOf('_') + 1 ); var type = msglist[i].substring(0, msglist[i].indexOf('_') ); var missedmsg = ''; var nrMissed = 0; // check if there are missed messages var pos = number.indexOf('[#'); if (pos > 0) { var tmp = number.substring(pos + 2, number.length); number = number.substring(0, pos); try{ nrMissed = webphone_api.common.StrToInt( webphone_api.common.Trim(tmp) ); } catch(errin) { } } var name = webphone_api.common.GetContactNameFromNumber(number); if (!webphone_api.common.isNull(nrMissed) && nrMissed > 0) { missedmsg = '' + nrMissed + ''; } if (webphone_api.common.isNull(name) || name.length < 1) { name = number; } var listitem = '' + '