// // // OBSERVERS // // $(function() { // // LOGIN PAGE OBSERVERS // if ($("#loginMainPage").doesExist()){ $('#forgotPwButton').click(function(ev){ $('#forgotPw').on('shown', function () { $("#forgotUsername").first().focus(); }); $('#forgotPw').modal('show'); return false; }); $('#registrerButton').click(function(ev){ $('#registrer').on('shown', function () { $("#brukernavn").first().focus(); }); $('#registrer').modal('show'); return false; }); $('#submitRegistrer').click(function(ev){ alert('Registrer NY bruker'); }); $('#loginButton').bind('click', function(){ auth_request(); return false; }); $('#submitPinSMS').bind('click', function(){ pin_request(); return false; }); $('#submitVerifyPinSMS').bind('click', function(){ verify_pin_request(); return false; }); $('#loginForm input').keyup(function(e) { // submit form on enter if (e.keyCode == '13'){ auth_request(); } }); $('#loginForm input').each(function(iter, e){ // auto focus the text box for username e.focus(); return false; // abort on first find }); function submit_forgot_pw(e){ $('#submitForgotPw').hide(); $('#forgotPw').find('.alert.alert-error').remove(); // remove errors if exists loader('#forgotPw', 'add', 50); $.get('/ajax/auth.php', $('#forgotForm').serialize(), function(response){ loader(null, 'remove'); if (response.status=='ok'){ $('#forgotPw > .modal-body').html(response.html); }else{ $('#submitForgotPw').show(); $('#forgotPw > .modal-body').prepend(response.html); } }, 'json'); return false; } // enter press on forgot pw $('#forgotUsername').keyup(function(e) { if (e.keyCode == '13'){ submit_forgot_pw(e); } }); // // observe the forgot password button // $('#submitForgotPw').click(submit_forgot_pw); } // // reset pw page // if ($("#resetpwPage").doesExist()){ $('#resetPWButton').bind('click', function(){ auth_request_reset(); return false; }); } // // observe the logout button // if ($('#logOutButton').doesExist()){ $('#logOutButton').click(function(){ $.get('/ajax/auth.php', {method:'logout'}, function(response){ if (response.status='ok'){ top.location.href=response.redir; }else{ // failsafe! top.location.href='/ajax/auth.php?method=logout'; } }, 'json'); return false; }); } // // RESPONSE SELECTOR OBSERVE // if ($("#responsSelect").doesExist()){ $('#responsSelect').change(function(e) { var newUrlQuery = query_params({id:e.currentTarget.value}); location.search = newUrlQuery; }); /*$('#clientSelectorReset').click(function(e) { e.preventDefault(); var newUrlQuery = query_params({c:$(e.currentTarget).data('id')}); location.search = newUrlQuery; });*/ } // // CLIENT SELECTOR OBSERVE // if ($("#clientSelector").doesExist()){ $('#clientSelector').change(function(e) { var newUrlQuery = query_params({c:e.currentTarget.value}); location.search = newUrlQuery; }); $('#clientSelectorReset').click(function(e) { e.preventDefault(); var newUrlQuery = query_params({c:$(e.currentTarget).data('id')}); location.search = newUrlQuery; }); } // // DATE PICKER OBSERVERS // if ($("#dateview-box").doesExist()){ // only execute if element exists on page // observe the date open selector $("#dateview-box").click(function(el) {toggle_date_box(this);}); // observe the date submit button $("#dateButton").click(function() { $('#dateAlert').hide(); toggle_date_box(); var dStart=$('#date-start').datepicker().data().date; var dEnd = $('#date-end').datepicker().data().date; // get prefix var prefix = $('#dateSelector').data('prefix'); var newUrlQuery = query_params({ds:dStart, de:dEnd}, prefix); location.search = newUrlQuery; }); if ($('#date-start') && $('#date-end')){ init_datePicker(); } } if ($("#dateview-box_nosub").doesExist()){ // only execute if element exists on page // observe the date open selector $("#dateview-box_nosub").click(function(el) {toggle_date_box(this);}); // observe the date submit button $("#dateButton").click(function() { $('#dateAlert').hide(); toggle_date_box(); var dStart=$('#date-start').datepicker().data().date; var dEnd = $('#date-end').datepicker().data().date; // get prefix var prefix = $('#dateSelector').data('prefix'); var newUrlQuery = query_params({ds:dStart, de:dEnd}, prefix); location.search = newUrlQuery; }); if ($('#date-start') && $('#date-end')){ init_datePicker_nosub(); } } // // SIDEBAR OBSERVERS // if ($(".sidebar").doesExist()){ $(".menu-enabler").on("click", function(event){ //$('.sidebar').toggleClass('show-sidebar'); $('.sidebar').toggleClass(function() { if ($(this).hasClass('show-sidebar')) { $(this).removeClass('show-sidebar'); $('.sidebar > div').removeClass('active'); $('.menu-enabler > span').addClass('icon-chevron-right'); $('.menu-enabler > span').removeClass('icon-chevron-left'); return ''; } else { $('.sidebar > div').addClass('active'); $('.menu-enabler > span').addClass('icon-chevron-left'); $('.menu-enabler > span').removeClass('icon-chevron-right'); return 'show-sidebar'; } }); return false; }); $(window).scroll(function (event) { position_sidebar(); }); $(window).resize(function (event) { position_sidebar(); }); position_sidebar(); // rposition the sidebar, acording to window size } // resize observe and set heigth of maincontainer set_container_height(); $(window).resize(function (event) { set_container_height(); }); // // Auto scroller when linked with an url hash, for smaller screens // var $hash = window.location.hash; if($hash) { if ($(window).width() <= 700){ if ($($hash).length != 0){ var $elTopPos = jQuery($hash).offset().top; jQuery('html, body').animate({scrollTop:$elTopPos}, 'slow'); //remove hash window.location.hash = ''; } } } // // INITIATE TOOLTIP // $("[rel=tooltip]").tooltip(); // // HighCharts locale and other default settings settings // if (typeof Highcharts !="undefined"){ Highcharts.setOptions({ global: { useUTC: true }, lang: { months: ['Januar', 'Februar', 'Mars', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Desember'], weekdays: ['Søndag', 'Mandag', 'Tirsdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lørdag'] } }); } // serach for click2show class init_click2show(); // // init dropdown lists // // observe the config buttons $('.dropdownList').each(function(index, element) { var userid = $(element).data('userid'); // observe delete button $(element).find('.dropdownListDelete').click(function(e){ e.preventDefault(); action_buttons('deleteUser', userid, "removeLine", ['Er du sikker på at du vil slette denne brukeren?', 'Avbryt', 'Slett bruker']); }); // observe deactivate button $(element).find('.dropdownListActivateToggle').click(function(e){ e.preventDefault(); action_buttons('clientActivateToggle', userid, "muteLine"); }); // observe deactivate kw button $(element).find('.dropdownListCwActivateToggle').click(function(e){ e.preventDefault(); action_buttons('codewordActivateToggle', userid, "muteLine"); }); }); }); // // function simple search filter // function simple_table_filter(searchBox, rowSelector, targetSeslector){ $(searchBox).delayInput(function(el){ var value = el.val(); $(rowSelector).each(function(index, row){ // skip header if (index!=0){ if (value=="") $(row).show(); else{ var curtext = $(row).find(targetSeslector).text().toLowerCase(); if (curtext.indexOf( value.toLowerCase() ) ==-1) $(row).hide(); else $(row).show(); } } }); },200).keypress(function (evt) { //Deterime where our character code is coming from within the event var charCode = evt.charCode || evt.keyCode; if (charCode == 13) { //Enter key's keycode return false; } });; } // // Dropdown config buttons helpers // function action_buttons(action, id, visualAction, confirmText){ createOverlay('listView'); var obj = {method:action, uid:id}; if (typeof confirmText !="undefined" && confirmText[0].length >=1){ bootbox.confirm({ message: confirmText[0], buttons: { 'cancel': { label: confirmText[1] }, 'confirm': { label: confirmText[2] } }, callback: function(r) { if (r === true) action_buttons_req(obj, visualAction); else removeOverlay('listView'); } }); }else{ action_buttons_req(obj, visualAction); } } function action_buttons_req(obj, visualAction){ simpleAjax(obj, "auth").done(function ( data ) { removeOverlay('listView'); if (data.status=="ok"){ //if (typeof data.msg != 'undefined'){ if (visualAction == "removeLine"){ $('#row_'+obj['uid']).find('td').css({background:'#f6dadb'}); setTimeout(function(){ $('#row_'+obj['uid']).addClass('fade').delay(500).queue(function( n ) {$(this).remove()}); }, 500); //bootbox.alert(data.msg, function() { //}); }else if (visualAction == "muteLine"){ var foundLabel = $('#row_'+obj['uid']).find('td.labelHolder'); var foundbutton = $('#row_'+obj['uid']).find('.dropdownListActivateToggle span'); var foundbutton_cw = $('#row_'+obj['uid']).find('.dropdownListCwActivateToggle span'); if (data.lineStatus == "active") { foundLabel.html('Aktiv'); foundbutton.text('Deaktiver'); foundbutton_cw.text('Deaktiver'); $('#row_'+obj['uid']).removeClass('muted'); }else { foundLabel.html('Deaktivert'); foundbutton.text('Aktiver'); foundbutton_cw.text('Aktiver'); $('#row_'+obj['uid']).addClass('muted'); } } //} return true; }else{ var msg = (typeof data.msg !="undefined")?data.msg:"Error, vennligst kontakt kundeservice hvis problemet vedvarer."; bootbox.alert(msg, function() {}); } }); return false; } // // function to show big info // function click2show(el, forceHeight, addClass){ var addedClass = (typeof addClass != "undefined")?addClass:""; var element = $(el); element.addClass('click2showHidden ' + addedClass); // get height of wrapped element if (typeof forceHeight !="undefined" && !isNaN(forceHeight)){ var elHeight = forceHeight; }else{ var elHeight = element.children(":first").height; } var container = $('
').addClass('click2showLink text-center').appendTo(element); $('').attr({href:'#'}).click(function(e){ e.preventDefault(); element.removeClass('click2showHidden'); element.attr('style', 'height: '+elHeight+'px !important'); $(this).remove(); //log(element); }).html('…').appendTo(container); } // // function to initiate big info function // function init_click2show(){ $('.click2show').each(function(index, element) { click2show(element); }); } // // Update/modify current url params // function query_params(paramsArray, prefix){ if (typeof prefix !== "undefined") var prefix = prefix; else var prefix = ''; var queryParameters = {}, queryString = location.search.substring(1), re = /([^&=]+)=([^&]*)/g, m; // Creates a map with the query string parameters while (m = re.exec(queryString)) { queryParameters[decodeURIComponent(m[1])] = decodeURIComponent(m[2]); } // Add new parameters or update existing ones $.each(paramsArray, function(index, value){ queryParameters[prefix+index] = value; }); return $.param(queryParameters); //location.search = $.param(queryParameters); } // // Simplyfy ajax calls // function simpleAjax(formID, fileName){ if (jQuery.isPlainObject(formID)) var params = $.param(formID); else var params = $(formID).serialize(); return $.ajax({ url: "/ajax/"+fileName+".php", data: params, dataType:'json', type:'post', beforeSend: function ( xhr ) { xhr.overrideMimeType("text/plain; charset=UTF-8"); } }); } // // modal dialog template // function modal_template(id){ return ''; } // // format inline alert messages // function simpleAlert(message, type, id){ var id = (typeof id == "undefined")?'':id; return '
' + message+'' + '
' } // // Number format from highcharts // function number_format(n, decimals){ if (typeof decimals =="undefined") decimals = 0; if (typeof Highcharts !="undefined"){ return Highcharts.numberFormat(n, decimals, ',', ' '); } } // // JQUERY EXTENCIONS // $.fn.doesExist = function(){ return jQuery(this).length > 0; }; // // // LOCAL FUNCTIONS // // function loader(id, method, offsettop){ if (typeof offsettop !=="number") offsettop = 0; if (method=="add"){ var elmentHeight=(id=='body')?$(document).outerHeight():$(id).outerHeight(); var loaderHeight=elmentHeight-offsettop; // create loader var image = $("", {src:'/img/loader.gif'}).css({marginTop:(elmentHeight/2)-30+'px'}); var loader = $("
", { id: "loaderOverlay" }).css({'height': loaderHeight+'px', 'width':'100%', 'z-index':1031, 'top':offsettop+'px' }).append(image); $(id).append(loader); }else if(method=="remove"){ $('#loaderOverlay').remove(); } } function auth_request(){ // remove the error if exists if ($('#loginError')) $('#loginError').remove(); loader('.login', 'add', 40); $.post('/ajax/auth.php', $('#loginForm').serialize(), function(response){ if (response.status=="failed"){ // remove loader loader('.login', 'remove'); var error=$('
×'+response.msg+'
').hide(); $('.login form').prepend(error); $(error).slideDown(); } else if(response.status=="failedIP") { // remove loader loader('.login', 'remove'); $('#verifiserPIN').modal('show'); if(response.gsm==0) { $("#submitPinSMS").hide(); } else { $("#submitPinSMS").show(); } $('#IPINFO').html(response.msg); } else if (response.status=="ok"){ if (response.redirect=="smspro"){ top.location.href='/'+response.redirect; } else if (response.redirect !== null && response.msg==null){ top.location.href='/'+response.redirect; return false; } else if (response.redirect !== null){ //alert(response.redirect); var $wDialog = $(modal_template('welcome')).modal(); $wDialog.find('.modal-header') .prepend("Velkommen"); $wDialog.find('.modal-body') .html(response.msg); $wDialog.find('.modal-footer') .html('OK'); // disable enter press $('#welcome input').keypress(function(e) { // submit form on enter if (e.keyCode == '13'){ e.preventDefault(); top.location.href='/'+response.redirect; return false; } }); $('#welcomeok').click(function(e){ e.preventDefault(); top.location.href='/'+response.redirect; return false; }); $('#welcome').on('hidden', function () { top.location.href='/'+response.redirect; }) }else{ top.location.href='/'; } } else{ loader('.login', 'remove'); } }, 'json'); } function pin_request(){ $('#verifiserPIN').modal('hide'); $('#verifiserPIN2').modal('show'); // remove the error if exists $.post('/ajax/auth.php', $('#pinsmsForm').serialize(), function(response){ if (response.status=="feil"){ $('#PININFO').html(response.msg); $("#submitVerifyPinSMS").hide(); } else if (response.status=="ok"){ $("#submitVerifyPinSMS").show(); $('#PININFO').html(response.msg); } else{ $('#PININFO').html('Opps, noe feil skjedde :('); } }, 'json'); } function verify_pin_request(){ $.post('/ajax/auth.php', $('#VerifyPinSMSForm').serialize(), function(response){ if (response.status=="feil"){ $('#PININFO').html(response.msg); } else if (response.status=="ok"){ // IP VERIFISERT $('#verifiserPIN2').modal('hide'); var info=$('
×'+response.msg+'
').hide(); $('.login form').prepend(info); $(info).slideDown(); } else{ $('#PININFO').html('Opps, noe feil skjedde :('); } }, 'json'); } function auth_request_reset(){ // remove the error if exists if ($('#err')) $('#err').remove(); loader('.resetpwCont', 'add', 40); $.post('/ajax/auth.php', $('#changepwForm').serialize(), function(response){ if (response.status=="failed"){ // remove loader loader('.resetpwCont', 'remove'); var error=$('
×'+response.msg+'
').hide(); $('.resetpwCont form').prepend(error); $(error).slideDown(); }else if (response.status=="ok"){ alert(response.msg); top.location.href='/'; }else{ loader('.login', 'remove'); } }, 'json'); } function update_date_display(elem){ elem = typeof elem !== 'undefined' ? elem : 'dateview-box'; var str = $('#date-start').data('date')+ ' - ' +$('#date-end').data('date'); //$('#dateview-box > span').html(str); $('#'+elem+' > span').html(str); } function init_datePicker(){ /* DATE PICKER */ var startDate = newDate($('#date-start').data('date')); var endDate = newDate($('#date-end').data('date')); var minDate = $('#date-start').data('mindate'); var maxDate = $('#date-start').data('maxdate'); $('#date-start') .datepicker({"language":"nb", startDate:minDate, endDate:maxDate, todayHighlight:true }) .on('changeDate', function(ev){ //console.log(ev.date); //console.log(endDate); if (ev.date.valueOf() > endDate.valueOf()){ $('#dateAlert').show().find('strong').text('Start dato må være en tid før Slutt dato'); $('#dateButton').prop("disabled", true).addClass("ui-state-disabled"); } else { $('#dateButton').prop("disabled", false).removeClass("ui-state-disabled"); $('#dateAlert').hide(); //$('#date-start').datepicker('place'); startDate = new Date(ev.date); $('#date-start-display').val($('#date-start').data('date')); update_date_display(); } $('#date-start').datepicker('hide'); }); $('#date-end') .datepicker({"language":"nb", startDate:minDate, endDate:maxDate, todayHighlight:true}) .on('changeDate', function(ev){ //log(ev.date); //log(startDate); if (ev.date.valueOf() < startDate.valueOf()){ $('#dateAlert').show().find('strong').text('Slutt dato må være en tid etter Start dato'); $('#dateButton').prop("disabled", true).addClass("ui-state-disabled"); } else { $('#dateButton').prop("disabled", false).removeClass("ui-state-disabled"); $('#dateAlert').hide(); //$('#date-end').datepicker('place'); endDate = new Date(ev.date); $('#date-end-display').val($('#date-end').data('date')); update_date_display(); } $('#date-end').datepicker('hide'); }); /* DATE PICKER END */ } function init_datePicker_nosub(){ /* DATE PICKER */ var startDate = newDate($('#date-start').data('date')); var endDate = newDate($('#date-end').data('date')); var minDate = $('#date-start').data('mindate'); var maxDate = $('#date-start').data('maxdate'); $('#date-start') .datepicker({"language":"nb", startDate:minDate, endDate:maxDate, todayHighlight:true }) .on('changeDate', function(ev){ //console.log(ev.date); //console.log(endDate); if (ev.date.valueOf() > endDate.valueOf()){ $('#dateAlert').show().find('strong').text('Start dato må være en tid før Slutt dato'); //$('#dateButton').prop("disabled", true).addClass("ui-state-disabled"); } else { //$('#dateButton').prop("disabled", false).removeClass("ui-state-disabled"); $('#dateAlert').hide(); //$('#date-start').datepicker('place'); startDate = new Date(ev.date); $('#date-start-display').val($('#date-start').data('date')); update_date_display('dateview-box_nosub'); var prefix = $('#dateSelector').data('prefix'); var ds = $('#date-start').data('date'); var de = $('#date-end').data('date'); var $ret = simpleAjax({'method':'sessionDate', ds:ds , de:de , prefix:prefix}, 'auth').done(function ( json ) { if (json.status=="ok"){ }else{ bootbox.alert({message: json.msg,buttons: {'ok': { label: "Lukk"}}}); } }); } $('#date-start').datepicker('hide'); }); $('#date-end') .datepicker({"language":"nb", startDate:minDate, endDate:maxDate, todayHighlight:true}) .on('changeDate', function(ev){ //log(ev.date); //log(startDate); if (ev.date.valueOf() < startDate.valueOf()){ $('#dateAlert').show().find('strong').text('Slutt dato må være en tid etter Start dato'); //$('#dateButton').prop("disabled", true).addClass("ui-state-disabled"); } else { //$('#dateButton').prop("disabled", false).removeClass("ui-state-disabled"); $('#dateAlert').hide(); //$('#date-end').datepicker('place'); endDate = new Date(ev.date); $('#date-end-display').val($('#date-end').data('date')); update_date_display('dateview-box_nosub'); var prefix = $('#dateSelector').data('prefix'); var ds = $('#date-start').data('date'); var de = $('#date-end').data('date'); var $ret = simpleAjax({'method':'sessionDate', ds:ds , de:de , prefix:prefix}, 'auth').done(function ( json ) { if (json.status=="ok"){ }else{ bootbox.alert({message: json.msg,buttons: {'ok': { label: "Lukk"}}}); } }); } $('#date-end').datepicker('hide'); }); /* DATE PICKER END */ } function newDate(date){ var s = date.split('-'); // this needs to be set to have same date time as the datepick plugin for comparison function UTCDate(){ return new Date(Date.UTC.apply(Date, arguments)); } if (s[2].length){ var d = UTCDate(s[2],s[1]-1,s[0]); return new Date(d.getTime()); //return new Date(d.getTime() + d.getTimezoneOffset()*60000); }else { log('ERROR DID NOT FIND ANY DATE '+date); return new Date(); } } function toggle_date_box(el){ $('#dateSelector').toggle(); $(el).find('i').toggleClass('icon-chevron-down').toggleClass('icon-chevron-up'); } function set_container_height(){ var maincontHeight = $('.mainContainer').height(); var windowHeight = $(window).height(); //log('maincontainer height:'+maincontHeight +' window height:'+windowHeight); if (maincontHeight <= windowHeight) $('.mainContainer').css({height:(windowHeight-62)}); // 62 is the height of the header else $('.mainContainer').css({height:'auto'}); } function position_sidebar(){ // do only position didebar if topbar is not static var navbarPos = $('.navbar-fixed-top').css('position'); var topHeight = $('.header-container').height(); var winWidth=$(window).width(); if (winWidth > 568){ if (navbarPos=="static"){ var scrT=$(window).scrollTop(); //console.log(scrT); // if the header still in view, do not ovelap if (scrT <= topHeight){ var newTop= topHeight-scrT+20; $('.sidebar').css({top: newTop+'px'}); // if top header is outside view }else{ if (scrT==0){ $('.sidebar').css({top:(topHeight+20)+'px'}); }else{ $('.sidebar').css({top:'20px'}); } } }else{ $('.sidebar').css({top:''}); } } } function createOverlay(id) { $('#'+id).css({position:'relative'}); if($('#dialog_overlay_'+id).length) { var overlay = $('#dialog_overlay_'+id); } else { var overlay=$('
'); $('#'+id).prepend(overlay); } // the loader, in its own container so it doesent get affected by opacity if($('#dialog_overlay_loader_'+id).length) { var overlay_loader = $('#dialog_overlay_loader_'+id); } else { var overlay_loader=$('
'); $('#'+id).prepend(overlay_loader); } } function removeOverlay(id) { if($('#dialog_overlay_'+id).length) { var overlay = $('#dialog_overlay_'+id); overlay.remove(); } if($('#dialog_overlay_loader_'+id).length) { var overlay_loader = $('#dialog_overlay_loader_'+id); overlay_loader.remove(); } } function quick_stat (element, ds, de){ var $ret = simpleAjax({'method':'quickStat', ds:ds , de:de}, 'stats').done(function ( json ) { if (json.status=="ok"){ fast_counter('#stat_addr', json.data.addr); fast_counter('#stat_nrdb', json.data.nrdb); fast_counter('#stat_bulk', json.data.bulk); fast_counter('#stat_epost',json.data.email); //$('#stat_nrdb').html(number_format(json.data.nrdb)); //$('#stat_addr').html(number_format(json.data.addr)); //$('#stat_bulk').html(number_format(json.data.bulk)); }else{ bootbox.alert({message: json.msg,buttons: {'ok': { label: "Lukk"}}}); } }); } function quick_stat_email (element, ds, de){ var $ret = simpleAjax({'method':'quickStatEmail', ds:ds , de:de}, 'stats').done(function ( json ) { if (json.status=="ok"){ fast_counter('#stat_sent', json.data.sent); fast_counter('#stat_delivered', json.data.delivered); fast_counter('#stat_open', json.data.open); fast_counter('#stat_click',json.data.click); fast_counter('#stat_click_uniq',json.data.click_uniq); fast_counter('#stat_unreg_push',json.data.unreg_push); }else{ bootbox.alert({message: json.msg,buttons: {'ok': { label: "Lukk"}}}); } }); } function fast_counter(element, num){ if (num <= 20) return $(element).html(num); var clockI = 0; var divider = Math.round(num / 20); var clock = setInterval(function(){ clockI = clockI+divider; $(element).html(number_format(clockI)); if (clockI >= num) { $(element).html(number_format(num)); clearInterval(clock); } },40); } function chart_push(element, ds, de, showButton){ createOverlay(element.substr(1)); if (typeof showButton == "undefined") var showButton = false; var $ret = simpleAjax({'method':'pushStat', ds:ds , de:de}, 'stats').done(function ( json ) { if (json.status=="ok"){ if (true){ var numbersCont = $('
').addClass('row-fluid headNumbers').appendTo(element); var billingTotal = $('
').addClass('span4 inner').html('
Turnover in the period
0').appendTo(numbersCont); var billingSent = $('
').addClass('span4 inner').html('
Sent during the period
0').appendTo(numbersCont); var billingAvr = $('
').addClass('span4 inner').html('
Average per sent
0').appendTo(numbersCont); removeOverlay(element.substr(1)); // do not display chart if data is empty if (json.data.length >=1){ var chart = $('
').appendTo(element); var listCont = $('
').appendTo(element); if (showButton == true){ var buttonCont = $('
').addClass('btnCont').appendTo(element); $('').click(function(){top.location.href='?page=stats&sub=push'}).appendTo(buttonCont); } $(chart).highcharts({ chart: { type: 'line', animation: false, height : 200, zoomType: 'x', resetZoomButton: { theme: { fill: '#F5F5F5', stroke: '#B3B3B3', r: 4, states: { hover: { fill: '#E6E6E6', stroke: '#B3B3B3', } } } } }, title: false, subtitle: { text: '' }, rangeSelector: { selected: 1 },navigator: { enabled: true }, plotOptions: { line: { marker: { enabled: false } }, series:{ shadow: false, animation:true } }, xAxis: { type: 'datetime' }, yAxis: [{ title: false, min: 0 },{ // Secondary yAxis title: { text: 'Turnover', style: { color: '#4572A7' } }, labels: { format: '{value} NOK', style: { color: '#4572A7' } }, opposite: true }], series: json.data, tooltip: { shared: true } }); } // list only if there are several lines if (json.data.length > 1){ $('

Summary

').appendTo(listCont); var table = $('').addClass('table table-bordered').appendTo(listCont); var count = 0; var TotalSent = 0; $(json.data).each(function(index, element) { //log(element); count = 0; // create tr var tr = $('').appendTo(table); if (element.name == "Turnover"){ $('
').addClass('dblist').html('Turnover').appendTo(tr); } else { $('').addClass('dblist').html(element.name).appendTo(tr); } $(element.data).each(function(index2, d) { count += d[1]; }); if (element.name == "Turnover"){ billingTotal.find('span').html(number_format(count) +'.-'); $('').html(number_format(count) +'.-').appendTo(tr); totalRevenue = count; }else{ $('').html(number_format(count)).appendTo(tr); TotalSent += count; } }); billingSent.find('span').html(number_format(TotalSent)); var average = totalRevenue / TotalSent; billingAvr.find('span').html(number_format((average), 2) + '.-' ); // add the wrapper if (json.data.length > 3) { $(table).wrap( "
"); click2show('#BillingSummaryWrap'); } } } /* Temporarly remove highcharts link, until production release */ $('.highcharts-container svg:last-child > text').hide(); }else{ bootbox.alert({message: json.msg,buttons: {'ok': { label: "Lukk"}}}); } }); } function gen_excel_rapport(fra_dato,til_dato,avsender,status,reload) { var $ret = simpleAjax({'method':'excel_rapport', fra_dato:fra_dato , til_dato:til_dato, avsender:avsender, status:status}, 'ajaxmq').done(function ( json ) { if (json.status=="ok"){ //alert(fra_dato+avsender+status); if(reload==1) { location.reload(); } else { bootbox.alert({message: json.msg,buttons: {'ok': { label: "Lukk"}}}); } } else{ bootbox.alert({message: json.msg,buttons: {'ok': { label: "Lukk"}}}); } }); } function raw_bulk(element, ds, de){ var $ret = simpleAjax({'method':'bulkRaw', ds:ds, de:de}, 'stats').done(function ( json ) { if(json.status=="ok"){ if (json.data != null){ var App = {}; App.mainCollection = new Backbone.Collection(json.data); bbGrid.setDict('no'); var MyGrid = new bbGrid.View({ subgrid: true, subgridAccordion: false, container: $(element), collection: App.mainCollection, colModel: [{ title: 'Date', name: 'dato', sortType:'number', index:true}, { title: 'Number', name: 'antall' , sortType:'number', index:true,actions:function(thisid){ var antall = App.mainCollection.get(thisid)['attributes']['antall']; return antall.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1 "); } }, ], onRowExpanded: function($el, rowid) { var $selectedRow = App.mainCollection.get(rowid)['attributes']['dato']; //console.log($selectedRow); var _subCollection = Backbone.Collection.extend({ url: 'ajax/stats.php?method=quickSubStat&d='+ $selectedRow }); var subCollection = new _subCollection(); var fetchObj = subCollection.fetch({ success: function(o,coll){ if (typeof coll['status'] !="undefined" && coll['status']=="failed") { alert(subCollection.models[0]['attributes']['msg']); } } }); var subgrid = new bbGrid.View({ autofetch:false, subgrid: true, subgridAccordion: false, container: $el, collection: subCollection, buttons: [{ 'id': 'EksportDatoID', 'title': 'Export all rows from '+$selectedRow+' to Excel', onClick: function(event){ //var dato = $selectedRow; //var avsender = subCollection.get(thisid)['attributes']['avsender']; //alert('test2:'+dato); gen_excel_rapport($selectedRow,$selectedRow,'',''); } }], onBeforeRender: function(){}, colModel: [{title:'Sender', name : 'avsender'}, {title:'Number', name : 'antall',actions:function(thisid){ var antall = subCollection.get(thisid)['attributes']['antall']; return antall.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1 "); } }, ], onRowExpanded: function($el2, rowid2) { //console.log(rowid2); var $sender = subCollection.get(rowid2)['attributes']['avsender']; var _subCollection2 = Backbone.Collection.extend({ url: 'ajax/stats.php?method=quickSubStat&d=' + $selectedRow +'&s='+ encodeURIComponent($sender) }); var subCollection2 = new _subCollection2(); subCollection2.fetch({ success: function(){ var ifNote = subCollection2.first().pick("note"); if (typeof ifNote.note != "undefined"){ $($el2).prepend("
"+ifNote.note+"
"); } } }); var subgrid2 = new bbGrid.View({ autofetch:false, subgrid: true, subgridAccordion: false, rows: 100, container: $el2, collection: subCollection2, colModel: [{title:'ID', name : 'id', className:'hidden', index:true}, {title:'Avsender', name : 'avsender', className:'hidden', index:true}, {title:'Status', name : 'status' ,filter: true, filterColName: 'status', index: true, actions:function(thisid){ var color = 'label-warning'; var thisStatus = subCollection2.get(thisid)['attributes']['status']; if (thisStatus == "delivered") color = 'label-success'; else if (thisStatus == "failed") color = 'label-important'; return ""+thisStatus+""} }, {title:'Number', name : 'antall',actions:function(thisid){ var antall = subCollection2.get(thisid)['attributes']['antall']; return antall.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1 "); } } ], buttons: [{ 'id': 'EksportDatoAvsenderID', 'title': 'Export all rows from '+$selectedRow+' with sender "'+$sender+'" to Excel', onClick: function(event){ gen_excel_rapport($selectedRow,$selectedRow,$sender,''); } }], onReady: function(){ $('.gridShowFullMessage').unbind().click(function(e){ e.preventDefault(); var el = e.currentTarget; simpleAjax({'method':'quickStatMessage', id:$(el).data('id'), db:'bulk'}, 'stats').done(function ( json ) { //console.log('counter'); bootbox.alert(json.data.melding); }); }); }, onRowExpanded: function($el3, rowid3) { //console.log(rowid2); var $status = subCollection2.get(rowid3)['attributes']['status']; var $sender = subCollection2.get(rowid3)['attributes']['avsender']; var _subCollection3 = Backbone.Collection.extend({ url: 'ajax/stats.php?method=quickSubStat&d=' + $selectedRow +'&status='+ encodeURIComponent($status)+'&s='+ encodeURIComponent($sender) }); var subCollection3 = new _subCollection3(); subCollection3.fetch({ success: function(){ var ifNote = subCollection3.first().pick("note"); if (typeof ifNote.note != "undefined"){ $($el3).prepend("
"+ifNote.note+"
"); } } }); var subgrid3 = new bbGrid.View({ autofetch:false, rows: 100, container: $el3, collection: subCollection3, colModel: [{title:'ID', name : 'id', className:'hidden-phone', index:true}, {title:'Time', name : 'tid_ut', sortType:'number', index:true}, {title:'Country code', name : 'land', index:true, className:'hidden-phone'}, {title:'GSM', name : 'gsm'}, {title:'Operator', name : 'operator'}, {title:'Parts', name : 'deler'}, {title:'Message', name : 'melding', className:'hidden-phone', actions:function(thisid){ var message = subCollection3.get(thisid)['attributes']['melding']; if (typeof message != "undefined") return ""+message+"..." else return ''; } }], buttons: [{ 'id': 'EksportDatoAvsenderStatusID', 'title': 'Export all rows from '+$selectedRow+' with sender "'+$sender+'" and status "'+$status+'" to Excel', onClick: function(event){ gen_excel_rapport($selectedRow,$selectedRow,$sender,$status); } }], onReady: function(){ $('.gridShowFullMessage').unbind().click(function(e){ e.preventDefault(); var el = e.currentTarget; simpleAjax({'method':'quickStatMessage', id:$(el).data('id'), db:'bulk'}, 'stats').done(function ( json ) { //console.log('counter'); bootbox.alert(json.data.melding); }); }); } }); } }); } }); } }); } else{ // nothing to get $('#bulkContainerRaw').html('
No data for this customer.
'); } } }); } function raw_push(element, ds, de, country){ if (typeof country=="undefined") country = 47; var $ret = simpleAjax({'method':'pushRaw', ds:ds, de:de, c:country}, 'stats').done(function ( json ) { if(json.status=="ok"){ if (json.data != null){ // empty contents to update fresh when a country is changed $(element).html(''); var App = {}; App.mainCollection = new Backbone.Collection(json.data); bbGrid.setDict('no'); var MyGrid = new bbGrid.View({ subgrid: true, subgridAccordion: false, container: $(element), collection: App.mainCollection, colModel: [{title:'ID', name : 'id', className:'hidden'}, { title: 'Date', name: 'dato', sortType:'number', index:true}, { title: 'Number', name: 'antall' , sortType:'number', index:true}, { title: 'Tried', name: 'pris' , sortType:'number', index:true}, { title: 'Turnover', name: 'delivered_pris' , sortType:'number', index:true}, { title: 'Success rate', name: 'success_rate' , sortType:'number', className:'color', index:true, actions:function(thisid){ var value = App.mainCollection.get(thisid)['attributes']['success_rate']; var num = value.split(','); var $col = '#498351'; if (num[0] <= 50){ $col = '#a96c66'; }else if (num[0] <= 70){ $col = '#a99a66'; }else if (num[0] <= 90){ $col = '#5aa063'; }else if (num[0] < 100){ $col = '#498351'; } $($(this.$el)).find('.color').css({background:$col}); return '
'+value+'
'; } }], onRowExpanded: function($el, rowid) { var $selectedRow = App.mainCollection.get(rowid)['attributes']['dato']; var _subCollection = Backbone.Collection.extend({ url: 'ajax/stats.php?method=quickSubStatPush&d='+ $selectedRow +'&c='+ country }); var subCollection = new _subCollection(); var subgrid = new bbGrid.View({ autofetch:true, container: $el, subgrid: true, subgridAccordion: false, rows:100, collection: subCollection, onBeforeRender: function(){ //console.log(subCollection.models[0]['attributes']['status']); subgrid.dict.noData = "Ingen data å vise. "; if (typeof subCollection.models[0] !="undefined" && subCollection.models[0]['attributes']['status']=="failed") { alert(subCollection.models[0]['attributes']['msg']); return false; } }, colModel: [{title:'ID', name : 'id', className:'hidden', index:true}, {title:'Keyword', name : 'kode', className:'hidden-phone', index:true}, {title:'Price', name : 'pris', index:true, className:'hidden-phone'}, {title:'Shortnumber', name : 'kortnr'}, {title:'Status', name : 'dlrstatus' ,filter: true, filterColName: 'dlrstatus', index: true,actions:function(thisid){ var color = 'label-warning'; var thisStatus = subCollection.get(thisid)['attributes']['dlrstatus']; if (thisStatus == "delivered") color = 'label-success'; else if (thisStatus == "failed") color = 'label-important'; return ""+thisStatus+""} }, {title:'Number', name : 'antall'}, ], onReady: function(){ }, onRowExpanded: function($el2, rowid2) { console.log(rowid2); var $status = subCollection.get(rowid2)['attributes']['dlrstatus']; var $tjid = subCollection.get(rowid2)['attributes']['tjeneste_id']; var $pris = subCollection.get(rowid2)['attributes']['pris']; var _subCollection2 = Backbone.Collection.extend({ url: 'ajax/stats.php?method=quickSubStatPush&d=' + $selectedRow +'&status='+ encodeURIComponent($status)+'&tjid='+ encodeURIComponent($tjid)+'&pris='+encodeURIComponent($pris) }); var subCollection2 = new _subCollection2(); subCollection2.fetch({ success: function(){ var ifNote = subCollection2.first().pick("note"); if (typeof ifNote.note != "undefined"){ $($el2).prepend("
"+ifNote.note+"
"); } } }); var subgrid2 = new bbGrid.View({ autofetch:false, rows: 100, container: $el2, collection: subCollection2, colModel: [{title:'Id', name : 'id', className:'hidden-phone', index:true}, {title:'Time', name : 'tid_ut', sortType:'number', index:true}, {title:'Gsm', name : 'gsm'}, {title:'Operator', name : 'operator'}, {title:'Message', name : 'melding', className:'hidden-phone', actions:function(thisid){ var message = subCollection2.get(thisid)['attributes']['melding']; if (typeof message != "undefined") return ""+message+"..." else return ''; } }], onReady: function(){ $('.gridShowFullMessage').unbind().click(function(e){ e.preventDefault(); var el = e.currentTarget; simpleAjax({'method':'quickStatMessage', id:$(el).data('id'), db:'push'}, 'stats').done(function ( json ) { //console.log('counter'); bootbox.alert(json.data.melding); }); }); } }); } }); } }); } else{ // nothing to get $('#pushContainerRaw').html('
No data for this customer
'); } } }); } function pushCodeWords(element, ds, de, country){ if (typeof country=="undefined") country = 47; var $ret = simpleAjax({'method':'pushCodeWords', ds:ds, de:de, c:country}, 'stats').done(function ( json ) { //console.log(json); // empty contents to update fresh when a country is changed $(element).html(''); var App = {}; var totalt=0; App.mainCollection = new Backbone.Collection(json.data); bbGrid.setDict('no'); var MyGrid = new bbGrid.View({ subgrid: true, subgridAccordion: false, container: $(element), collection: App.mainCollection, colModel: [{title:'ID', name : 'id', className:'hidden'}, {title:'Tjeneste ID', name : 'tjeneste_id',className:'hidden'}, {title:'Eier ID', name : 'eier_id',className:'hidden'}, {title:'Keyword', name : 'kode', sortType:'string', index:true,actions:function(thisid){ //console.log('ID: '+thisid); var thiskode = App.mainCollection.get(thisid)['attributes']['kode']; if (thiskode == "ÅÅÅ") return 'TOTALT' else return thiskode; } }, {title:'Customer', name : 'kunde', index:true, className:'hidden-phone'}, {title:'Price', name : 'pris', index:true, className:'hidden-phone'}, {title:'Shortnumber', name : 'kortnr'}, {title:'Number', name : 'antall', sortType:'number', index:true,actions:function(thisid){ //console.log('ID: '+thisid); var antall = App.mainCollection.get(thisid)['attributes']['antall']; //console.log('ID: '+thisid+' Antall:'+antall); if (antall == "TOTAL") { return ''+totalt+''; } else { totalt = +antall+ +totalt; return antall; } } }], onRowExpanded: function($el, rowid) { var $tjid = App.mainCollection.get(rowid)['attributes']['tjeneste_id']; var $eierid = App.mainCollection.get(rowid)['attributes']['eier_id']; var $pris = App.mainCollection.get(rowid)['attributes']['pris']; //var $selectedCountry = $('#countrySelector').find('select').val(); if($tjid>0 && $eierid>0) { var _subCollection = Backbone.Collection.extend({ url: 'ajax/stats.php?method=pushGroupStatus&tjid='+ $tjid +'&eier='+ $eierid +'&pris='+ $pris }); var subCollection = new _subCollection(); var subgrid = new bbGrid.View({ autofetch:true, subgrid: true, subgridAccordion: false, container: $el, rows:100, collection: subCollection, onBeforeRender: function(){ //console.log(subCollection.models[0]['attributes']['status']); subgrid.dict.noData = "Ingen data å vise. "; if (typeof subCollection.models[0] !="undefined" && subCollection.models[0]['attributes']['status']=="failed") { alert(subCollection.models[0]['attributes']['msg']); return false; } }, colModel: [ { title: 'Id', name: 'id',className:'hidden'}, {title:'Tjeneste ID', name : 'tjeneste_id',className:'hidden'}, { title: 'eier', name: 'eier_id', className:'hidden'}, { title: 'Number', name: 'antall' , sortType:'number', index:true}, {title:'Status', name : 'dlrstatus' ,filter: true, filterColName: 'dlrstatus', index: true,actions:function(thisid){ var color = 'label-warning'; var thisStatus = subCollection.get(thisid)['attributes']['dlrstatus']; if (thisStatus == "delivered") color = 'label-success'; else if (thisStatus == "failed") color = 'label-important'; return ""+thisStatus+""} } ], onRowExpanded: function($el2, rowid2) { var $tjid = subCollection.get(rowid2)['attributes']['tjeneste_id']; var $eierid = subCollection.get(rowid2)['attributes']['eier_id']; var $status = subCollection.get(rowid2)['attributes']['dlrstatus']; //var $selectedCountry = $('#countrySelector').find('select').val(); var _subCollection2 = Backbone.Collection.extend({ url: 'ajax/stats.php?method=pushDaysCodeWord&tjid='+ $tjid +'&eier='+ $eierid +'&status='+ $status+'&pris='+ $pris }); var subCollection2 = new _subCollection2(); var subgrid2 = new bbGrid.View({ autofetch:true, container: $el2, rows:100, collection: subCollection2, onBeforeRender: function(){ //console.log(subCollection.models[0]['attributes']['status']); subgrid.dict.noData = "Ingen data å vise. Hvis du forsøker å hente detaljer for dato tidligere enn 1 November 2014, har dette blitt arkivert da vi flyttet over til nye KUNDEWEB. Ønsker du å få en detaljert rapport for en tidligere dato ta kontakt med oss og vi vil ta et manuellt søk for deg."; if (typeof subCollection2.models[0] !="undefined" && subCollection2.models[0]['attributes']['status']=="failed") { alert(subCollection2.models[0]['attributes']['msg']); return false; } }, colModel: [ { title: 'Id', name: 'id',className:'hidden'}, { title: 'Date', name: 'dato', sortType:'number', index:true}, { title: 'Number', name: 'antall' , sortType:'number', index:true} ], onReady: function(){ } }); } // SUBGRID2 slutt }); } } }); }); } function bulkCodewords(element, ds, de, country){ if (typeof country=="undefined") country = 47; var $ret = simpleAjax({'method':'bulkCodeWords', ds:ds, de:de, c:country}, 'stats').done(function ( json ) { //console.log(json); // empty contents to update fresh when a country is changed $(element).html(''); var App = {}; var totalt=0; App.mainCollection = new Backbone.Collection(json.data); bbGrid.setDict('no'); var MyGrid = new bbGrid.View({ subgrid: false, subgridAccordion: false, container: $(element), collection: App.mainCollection, colModel: [{title:'ID', name : 'id', className:'hidden'}, {title:'Tjeneste ID', name : 'tjeneste_id',className:'hidden'}, {title:'Keyword', name : 'kode', sortType:'string', index:true,actions:function(thisid){ var thiskode = App.mainCollection.get(thisid)['attributes']['kode']; if (thiskode == "ÅÅÅ") return 'TOTALT'; else return thiskode; } }, {title:'Customer', name : 'kunde', sortType:'string', index:true}, {title:'Number', name : 'antall', sortType:'number', index:true,actions:function(thisid){ //console.log('ID: '+thisid); var antall = App.mainCollection.get(thisid)['attributes']['antall']; //console.log('ID: '+thisid+' Antall:'+antall); if (antall == "TOTAL") { return ''+totalt.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1 ")+''; } else { totalt = +antall+ +totalt; return antall.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1 "); } } }], onRowExpanded: function($el, rowid) { } }); }); } function bulkUsers(element, ds, de, country){ if (typeof country=="undefined") country = 47; var $ret = simpleAjax({'method':'bulkUsers', ds:ds, de:de, c:country}, 'stats').done(function ( json ) { //console.log(json); // empty contents to update fresh when a country is changed $(element).html(''); var App = {}; var totalt=0; App.mainCollection = new Backbone.Collection(json.data); bbGrid.setDict('no'); var MyGrid = new bbGrid.View({ subgrid: false, subgridAccordion: false, container: $(element), collection: App.mainCollection, colModel: [{title:'ID', name : 'id', className:'hidden'}, {title:'User', name : 'bruker', sortType:'string', index:true }, {title:'Number', name : 'antall', sortType:'number', index:true}, {title:'Country', name : 'land', sortType:'string', index:true} ], onRowExpanded: function($el, rowid) { } }); }); } function chart_bulk(element, ds, de, showButton, height){ createOverlay(element.substr(1)); if (typeof height != "number") var height = 200; if (typeof showButton == "undefined") var showButton = false; var $ret = simpleAjax({'method':'bulkStat', ds:ds, de:de}, 'stats').done(function ( json ) { removeOverlay(element.substr(1)); if (json.status=="ok"){ $('
').addClass('row-fluid headNumbers').html('
Sent during the period
'+number_format(json.senttotal)+'
').prependTo(element); // do not display chart if data is empty if (json.data.length >=1){ var chart = $('
').appendTo(element); var listCont = $('
').appendTo(element); if (showButton == true){ var buttonCont = $('
').addClass('btnCont').appendTo(element); $('').click(function(){top.location.href='?page=stats&sub=bulk'}).appendTo(buttonCont); } $('#bulkContainer button').show(); chart.highcharts({ chart: { renderTo: 'bulkChart', type: 'line', animation: false, height : height, zoomType: 'x', resetZoomButton: { theme: { fill: '#F5F5F5', stroke: '#B3B3B3', r: 4, states: { hover: { fill: '#E6E6E6', stroke: '#B3B3B3', } } } } }, legend: { maxHeight:60 }, /*title: { text: json.title },*/ title: false, subtitle: { text: '' }, plotOptions: { line: { marker: { enabled: false } }, series:{ shadow: false, animation:true } }, xAxis: { type: 'datetime'/*, title: { text: 'Dato' }*/ }, yAxis: { title: false, min: 0 }, tooltip: { shared: true }, series: json.data }); } // list only if there are several lines if (json.data.length > 1){ $('

Summary

').appendTo(listCont); var table = $('').addClass('table table-bordered').css({'margin-top':'0px'}).appendTo(listCont); var count = 0; $(json.data).each(function(index, element) { //log(element); count = 0; // create tr var tr = $('').appendTo(table); $('
').addClass('dblist').html(element.name).appendTo(tr); $(element.data).each(function(index2, d) { count += d[1]; }); $('').html(number_format(count)).appendTo(tr); }); // add the wrapper if (json.data.length > 3) { $(table).wrap( "
"); click2show('#BulkSummaryWrap'); } } /* Temporarly remove highcharts link, until production release */ $('.highcharts-container svg:last-child > text').hide(); }else{ bootbox.alert({message: json.msg,buttons: {'ok': { label: "Lukk"}}}); } }); } function chart_smsinn(element, ds, de, showButton, height){ createOverlay(element.substr(1)); if (typeof height != "number") var height = 100; if (typeof showButton == "undefined") var showButton = false; var $ret = simpleAjax({'method': 'smsinnStat', ds:ds, de:de}, 'stats').done(function ( json ) { removeOverlay(element.substr(1)); if (json.status=="ok"){ $('
').addClass('row-fluid headNumbers').html('
Incoming for the period
'+number_format(json.senttotal)+'
').prependTo(element); // do not display chart if data is empty if (json.data.length >=1){ var chart = $('
').appendTo(element); var listCont = $('
').appendTo(element); if (showButton == true){ var buttonCont = $('
').addClass('btnCont').appendTo(element); $('').click(function(){top.location.href='?page=stats&sub=smsinn'}).appendTo(buttonCont); } $('#smsinnContainer button').show(); chart.highcharts({ chart: { renderTo: 'smsinnChart', type: 'line', animation: false, height : height, zoomType: 'x', resetZoomButton: { theme: { fill: '#F5F5F5', stroke: '#B3B3B3', r: 4, states: { hover: { fill: '#E6E6E6', stroke: '#B3B3B3', } } } } }, legend: { maxHeight:60 }, /*title: { text: json.title },*/ title: false, subtitle: { text: '' }, plotOptions: { line: { marker: { enabled: false } }, series:{ shadow: false, animation:true } }, xAxis: { type: 'datetime'/*, title: { text: 'Dato' }*/ }, yAxis: { title: false, min: 0 }, tooltip: { shared: true }, series: json.data }); } // list only if there are several lines if (json.data.length > 1){ $('

Summary

').appendTo(listCont); var table = $('').addClass('table table-bordered').css({'margin-top':'0px'}).appendTo(listCont); var count = 0; $(json.data).each(function(index, element) { //log(element); count = 0; // create tr var tr = $('').appendTo(table); $('
').addClass('dblist').html(element.name).appendTo(tr); $(element.data).each(function(index2, d) { count += d[1]; }); $('').html(number_format(count)).appendTo(tr); }); // add the wrapper if (json.data.length > 3) { $(table).wrap( "
"); click2show('#SmsinnSummaryWrap'); } } /* Temporarly remove highcharts link, until production release */ $('.highcharts-container svg:last-child > text').hide(); }else{ bootbox.alert({message: json.msg,buttons: {'ok': { label: "Lukk"}}}); } }); } function raw_smsinn(element, ds, de){ var $ret = simpleAjax({'method':'smsinnRaw', ds:ds, de:de}, 'stats').done(function ( json ) { if(json.status=="ok"){ if (json.data != null){ var App = {}; App.mainCollection = new Backbone.Collection(json.data); bbGrid.setDict('no'); var MyGrid = new bbGrid.View({ subgrid: true, subgridAccordion: false, container: $(element), collection: App.mainCollection, colModel: [{ title: 'Date', name: 'dato', sortType:'number', index:true}, { title: 'Number', name: 'antall' , sortType:'number', index:true,actions:function(thisid){ var antall = App.mainCollection.get(thisid)['attributes']['antall']; return antall.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1 "); } }], onRowExpanded: function($el, rowid) { var $selectedRow = App.mainCollection.get(rowid)['attributes']['dato']; //console.log($selectedRow); var _subCollection = Backbone.Collection.extend({ url: 'ajax/stats.php?method=quickSubStatSmsinn&d='+ $selectedRow }); var subCollection = new _subCollection(); var fetchObj = subCollection.fetch({ success: function(o,coll){ if (typeof coll['status'] !="undefined" && coll['status']=="failed") { alert(subCollection.models[0]['attributes']['msg']); } } }); var subgrid = new bbGrid.View({ autofetch:false, subgrid: true, subgridAccordion: false, container: $el, collection: subCollection, onBeforeRender: function(){}, colModel: [{title:'Keyword', name : 'kode'}, {title:'Shortnumber', name : 'kortnr'}, {title:'Number', name : 'antall',actions:function(thisid){ var antall = subCollection.get(thisid)['attributes']['antall']; return antall.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1 "); } }], onRowExpanded: function($el2, rowid2) { //console.log(rowid2); var $tjid = subCollection.get(rowid2)['attributes']['tjeneste_id']; var _subCollection2 = Backbone.Collection.extend({ url: 'ajax/stats.php?method=quickSubStatSmsinn&d=' + $selectedRow +'&tjid='+ encodeURIComponent($tjid) }); var subCollection2 = new _subCollection2(); subCollection2.fetch({ success: function(){ var ifNote = subCollection2.first().pick("note"); if (typeof ifNote.note != "undefined"){ $($el2).prepend("
"+ifNote.note+"
"); } } }); var subgrid2 = new bbGrid.View({ autofetch:false, subgrid: false, subgridAccordion: false, rows: 100, container: $el2, collection: subCollection2, colModel: [{title:'ID', name : 'id', className:'hidden', index:true}, {title:'Time', name : 'tid', index:true}, {title:'Gsm', name: 'gsm',index: true}, {title:'Operator', name: 'operator'}, {title:'Subnumber', name: 'subnummer',index: true, className:'hidden-phone'}, {title:'Message', name: 'melding', className:'hidden-phone', actions:function(thisid){ var message = subCollection2.get(thisid)['attributes']['melding']; if (typeof message != "undefined") return ""+message+"..." else return ''; } } ], onReady: function(){ $('.gridShowFullMessage').unbind().click(function(e){ e.preventDefault(); var el = e.currentTarget; simpleAjax({'method':'quickStatMessage', id:$(el).data('id'), db:'smsinn'}, 'stats').done(function ( json ) { //console.log('counter'); bootbox.alert(json.data.melding); }); }); } }); } }); } }); } else{ // nothing to get $('#smsinnContainerRaw').html('
No data for this customer.
'); } } }); } function smsinnCodeWords(element, ds, de, country){ if (typeof country=="undefined") country = 47; var $ret = simpleAjax({'method':'smsinnCodeWords', ds:ds, de:de, c:country}, 'stats').done(function ( json ) { //console.log(json); // empty contents to update fresh when a country is changed $(element).html(''); var App = {}; var totalt=0; App.mainCollection = new Backbone.Collection(json.data); bbGrid.setDict('no'); var MyGrid = new bbGrid.View({ subgrid: true, subgridAccordion: false, container: $(element), collection: App.mainCollection, colModel: [{title:'ID', name : 'id', className:'hidden'}, {title:'Tjeneste ID', name : 'tjeneste_id',className:'hidden'}, {title:'Eier ID', name : 'eier_id',className:'hidden'}, {title:'Kodeord', name : 'kode', sortType:'string', index:true,actions:function(thisid){ //console.log('ID: '+thisid); var thiskode = App.mainCollection.get(thisid)['attributes']['kode']; if (thiskode == "TOT_ANTALL") return 'TOTALT' else return thiskode; } }, {title:'Kunde', name : 'kunde', index:true, className:'hidden-phone'}, {title:'Kortnr', name : 'kortnr'}, {title:'Antall', name : 'antall', sortType:'number', index:true,actions:function(thisid){ //console.log('ID: '+thisid); var antall = App.mainCollection.get(thisid)['attributes']['antall']; //console.log('ID: '+thisid+' Antall:'+antall); if (antall == "TOTAL") { return ''+totalt+''; } else { totalt = +antall+ +totalt; return antall; } } }], onRowExpanded: function($el, rowid) { var $tjid = App.mainCollection.get(rowid)['attributes']['tjeneste_id']; var $eierid = App.mainCollection.get(rowid)['attributes']['eier_id']; //var $pris = App.mainCollection.get(rowid)['attributes']['pris']; //var $selectedCountry = $('#countrySelector').find('select').val(); if($tjid>0 && $eierid>0) { var _subCollection = Backbone.Collection.extend({ url: 'ajax/stats.php?method=smsinnDaysCodeWord&tjid='+ $tjid +'&eier='+ $eierid }); var subCollection = new _subCollection(); var subgrid = new bbGrid.View({ autofetch:true, subgrid: false, subgridAccordion: false, container: $el, rows:100, collection: subCollection, onBeforeRender: function(){ //console.log(subCollection.models[0]['attributes']['status']); subgrid.dict.noData = "Ingen data å vise. "; if (typeof subCollection.models[0] !="undefined" && subCollection.models[0]['attributes']['status']=="failed") { alert(subCollection.models[0]['attributes']['msg']); return false; } }, colModel: [ { title: 'Id', name: 'id',className:'hidden'}, { title: 'Tjeneste_id', name: 'tjeneste_id',className:'hidden'}, { title: 'Dato', name: 'dat', sortType:'number', index:true}, { title: 'Antall', name: 'antall' , sortType:'number', index:true} ], }); } } }); }); } function SMS_counter(el){ var hale = 0; var tegn1 = (160 - hale); var tegn2 = (153 - hale); var $smsLength = $(el).val().length; var tegn = tegn1; if($smsLength > 160){ tegn = tegn2; } if ($smsLength > (10*tegn2)) { $(el).value = $(el).value.substring(0, (10*tegn2)); } return Math.ceil($smsLength / (tegn)); } // usage: log('inside coolFunc', this, arguments); // paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/ window.log = function(){ log.history = log.history || []; // store logs to an array for reference log.history.push(arguments); if(this.console) { arguments.callee = arguments.callee.caller; var newarr = [].slice.call(arguments); (typeof console.log === 'object' ? log.apply.call(console.log, console, newarr) : console.log.apply(console, newarr)); } }; // make it safe to use console.log always (function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try {console.log();return window.console;}catch(err){return window.console={};}})());