$(document).ready(function(){ // customer details edit screen if($('#edit-form').length > 0){ $('#edit-form').on('submit', function(){ //Serialize the form and post it to the server $.post("/ajax/customer/details", $(this).serialize(), function(){ $("#editModal").modal('hide'); // refresh the screen window.location.reload(); }); // Stop the normal form submission return false; }); } // Direct Debit received button if($('.ddr-button').length > 0){ $('.ddr-button').click(function(){ $('.ddr-button').toggleClass('btn-success btn-danger'); // change the colour of the button by toggling classes var state = $('.ddr-button').hasClass('active'); if(state){ $.post("/ajax/customer/ddr_received", 'ddr_received=0&id='+customer_id); }else{ $.post("/ajax/customer/ddr_received", 'ddr_received=1&id='+customer_id); } }); } if($('.suspend-button').length > 0){ $('.suspend-button').click(function(){ $('.suspend-button').toggleClass('btn-info btn-primary'); // change the colour of the button by toggling classes var state = $('.suspend-button').hasClass('active'); if(state){ $.post("/ajax/service/suspend", 'suspend=0&id='+$(this).attr("data-id")+'&service_id='+$(this).attr("data-serviceid")); }else{ $.post("/ajax/service/suspend", 'suspend=1&id='+$(this).attr("data-id")+'&service_id='+$(this).attr("data-serviceid")); } }); } if($('.archive_customer').length > 0){ $('.archive_customer').click(function(){ //$('.archive_customer').toggleClass('btn-success btn-danger'); // change the colour of the button by toggling classes $.post("/ajax/customer/archive_customer", 'archive_customer=1&id='+customer_id, function(){ window.location.reload(); }); }); } if($('.unarchive_customer').length > 0){ $('.unarchive_customer').click(function(){ $.post("/ajax/customer/archive_customer", 'archive_customer=0&id='+customer_id, function(){ window.location.reload(); }); }); } if($('.non-ddr-button').length > 0){ $('.non-ddr-button').click(function(){ $('.non-ddr-button').toggleClass('btn-success btn-danger'); // change the colour of the button by toggling classes var state = $('.non-ddr-button').hasClass('active'); if(state){ $.post("/ajax/customer/non_ddr", 'non_ddr=0&id='+customer_id); }else{ $.post("/ajax/customer/non_ddr", 'non_ddr=1&id='+customer_id); } }); } if($('.cc-surcharge-button').length > 0){ $('.cc-surcharge-button').click(function(){ $('.cc-surcharge-button').toggleClass('btn-success btn-danger'); // change the colour of the button by toggling classes var state = $('.cc-surcharge-button').hasClass('active'); if(state){ $.post("/ajax/customer/cc_surcharge", 'cc_surcharge=0&id='+customer_id); }else{ $.post("/ajax/customer/cc_surcharge", 'cc_surcharge=1&id='+customer_id); } }); } // customer details edit screen if($('#billing-form').length > 0){ $('#billing-form').on('submit', function(){ $.post("/ajax/customer/billing", $(this).serialize(), function(){ $("#billingModal").modal('hide'); window.location.reload(); }); return false; }); } // customer details edit screen if($('#notes-form').length > 0){ $('#notes-form').on('submit', function(){ $.post($(this).attr("action"), $(this).serialize(), function(){ $("#notesModal").modal('hide'); window.location.reload(); }); return false; }); } if($('#bill_type').length > 0){ // add customer form $('#bill_type').change(function(){ // work out which form the user wants if($('#bill_type').val() == 'inv'){ $('.dd').hide(); }else{ $('.dd').show(); // work out which subform to show if($('#ddr_type').val() == 'dd'){ $('.credit-card').hide(); // bank account $('.bank-account').show(); }else{ $('.credit-card').show(); // credit card $('.bank-account').hide(); } } }); $('#ddr_type').change(function(){ // work out which form the user wants if($('#ddr_type').val() == 'dd'){ $('.credit-card').hide(); // bank account $('.bank-account').show(); }else{ $('.credit-card').show(); // credit card $('.bank-account').hide(); } }); } // customer invoice section if($('.load_invoice_history').length > 0){ $(".load_invoice_history").click(function(){ $('.invoice_history_hide').toggleClass('invoice_history_hide'); $('.invoice_history_hide_btn').hide(); }); } if($('.load_payt_history').length > 0){ $(".load_payt_history").click(function(){ $('.payt_history_hide').toggleClass('payt_history_hide'); $('.payt_history_hide_btn').hide(); }); } if($('.load_adjust_history').length > 0){ $(".load_adjust_history").click(function(){ $('.adjust_history_hide').toggleClass('adjust_history_hide'); $('.adjust_history_hide_btn').hide(); }); } if($('.load_invoice_item').length > 0){ $(".load_invoice_item").click(function(){ $('.invoice_item_hide').toggleClass('invoice_item_hide'); $('.invoice_item_hide_btn').hide(); }); } // payment history delete button if($('.payt-delete').length > 0){ $('.payt-delete').click(function(){ var theid = $(this).attr('id'); $.post("/ajax/customer/delete_payment_history", 'id='+customer_id+'&payt_id='+theid, function(){ $('.payt_delete_row-'+theid).hide(); window.location.reload(); }); }); } // Adjustment history delete button if($('.adj-delete').length > 0){ $('.adj-delete').click(function(){ var theid = $(this).attr('id'); $('.adj_delete_row-'+theid).hide(); $.post("/ajax/customer/delete_adjustment_history", 'id='+customer_id+'&adj_id='+theid); }); } if($('.inv-item-once-delete').length > 0){ $('.inv-item-once-delete').click(function(){ var theid = $(this).attr('id'); $('.invoice_item_delete_row-'+theid).hide(); $.post("/ajax/customer/delete_invoice_item", 'id='+customer_id+'&inv_item_id='+theid); }); } if($('.inv-item-reoccur-delete').length > 0){ $('.inv-item-reoccur-delete').click(function(){ var theid = $(this).attr('id'); $('.invoice_item_delete_row-'+theid).hide(); $.post("/ajax/customer/delete_invoice_reoccur", 'id='+customer_id+'&inv_item_id='+theid); }); } // invoice delete button if($('.invoice_delete').length > 0){ $('.invoice_delete').click(function(){ var theid = $(this).attr('id'); $(this).parent().hide(); $.post("/ajax/customer/delete_instant_invoice", 'inv_num='+theid); }); } // apply payment form if($('#apply-payment-form').length > 0){ $('#apply-payment-form').on('submit', function(){ $.post("/ajax/customer/apply_payment", $(this).serialize(), function(){ $("#applyPaymentModal").modal('hide'); window.location.reload(); }); return false; }); } // apply-adjustment-form if($('#apply-adjustment-form').length > 0){ $('#apply-adjustment-form').on('submit', function(){ $.post("/ajax/customer/apply_adjustment", $(this).serialize(), function(){ $("#applyAdjustmentModal").modal('hide'); window.location.reload(); }); return false; }); } // add invoice item modal if($('#add-invoice-item-form').length > 0){ $('#add-invoice-item-form').on('submit', function(){ $.post("/ajax/customer/add_invoice_item", $(this).serialize(), function(){ $("#addInvoiceItemModal").modal('hide'); window.location.reload(); }); return false; }); } if($('#instant-invoice-form').length > 0){ $('#instant-invoice-form').on('submit', function(){ $.post("/ajax/customer/create_instant_invoice", $(this).serialize(), function(){ $("#instantInvoiceModal").modal('hide'); window.location.reload(); }); return false; }); } if($('#service-form').length > 0){ $('#service-form').on('submit', function(){ $.post($(this).attr("action"), $(this).serialize(), function(result){ $('#service-form .result-box').html(result); }); return false; }); } if($('.service-form').length > 0){ $('.service-form').on('submit', function(){ var e = $(this); if(typeof CKEDITOR !== 'undefined'){ var data = CKEDITOR.instances.email_body.getData(); var postdata = $(this).serialize() + "&new_email_body=" + encodeURIComponent(data); }else var postdata = $(this).serialize(); //alert(postdata); $.post($(this).attr("action"), postdata, function(result){ //console.log(e); e.parent().find('.result-box').html(result); }); return false; }); } if($('.service-form-refresh').length > 0){ $('.service-form-refresh').on('submit', function(){ if(typeof CKEDITOR !== 'undefined'){ var data = CKEDITOR.instances.email_body.getData(); var postdata = $(this).serialize() + "&new_email_body=" + encodeURIComponent(data); }else var postdata = $(this).serialize(); //alert(postdata); $.post($(this).attr("action"), postdata, function(result){ window.location.reload(); }); return false; }); } if($('#plan-form').length > 0){ $('#plan-form').on('submit', function(){ $.post($(this).attr("action"), $(this).serialize(), function(result){ $('#plan-form .result-box').html(result); }); return false; }); } if($('#plan-form-refresh').length > 0){ $('#plan-form-refresh').on('submit', function(){ $.post($(this).attr("action"), $(this).serialize(), function(result){ window.location.reload(); }); return false; }); } if($('.delete-la-email').length > 0){ bind_live_answer(); } if($('#service-add-email').length > 0){ $('#service-add-email').on('submit', function(){ $.post($(this).attr("action"), $(this).serialize(), function(result){ window.location.reload(); }); return false; }); } if($('.delete-la-sms').length > 0){ bind_live_answer(); } if($('#service-add-sms').length > 0){ $('#service-add-sms').on('submit', function(){ $.post($(this).attr("action"), $(this).serialize(), function(result){ window.location.reload(); }); return false; }); } if($('.delete-la-alias').length > 0){ bind_live_answer(); } if($('#service-add-alias').length > 0){ $('#service-add-alias').on('submit', function(){ $.post($(this).attr("action"), $(this).serialize(), function(result){ window.location.reload(); }); return false; }); } if($('#answer_point_type').length > 0){ $('#answer_point_type').on('change', function(){ if($('#answer_point_type').val() == 'manual'){ $('#answer_point').show(); }else{ $('#answer_point').val($('#answer_point_type').val()); $('#answer_point').hide(); } return false; }); } if($('.delete-action-ivr').length > 0){ $('.delete-action-ivr').click(function(){ //alert("test"); var theid = $(this).attr('id'); //console.log($("#id")); $.post("/ajax/service/delete_action_ivr_value", 'id='+$("#id").val()+'&service_id='+$('#service_id').val()+'&keypress='+theid, function(){ $('.ivr_row-'+theid).hide(); //window.location.reload(); }); return false; }); } //new-service-form if($('#new-service-form').length > 0){ switch($("#service_type").val()){ case '1': //alert("sdoing this"); $('#new-service-form').validate({ rules:{ service_number:{ pattern: /1300\d{6}/i }, answer_point:{ minlength: 10 } }, messages:{ service_number:"Enter a valid 1300 number", answer_point:{ required:"Enter the answer point", min:"Enter a valid phone number for the answer point" } }, highlight: function(label) { $(label).closest('.control-group').addClass('error'); }, success: function(label) { label .text('OK!').addClass('valid') .closest('.control-group').addClass('success'); } }); break; } $("#new_type").on('change', function(){ switch($("#new_type").val()){ case 'new': $('.smartnumber_detail').hide(); $('.post_acc_num').hide(); $('.port_acc_name').hide(); $('.brand_new_detail').hide(); $('.held').show(); $('.service_num').hide(); break; case 'port': $('.smartnumber_detail').hide(); $('.post_acc_num').show(); $('.port_acc_name').show(); $('.brand_new_detail').hide(); $('.held').hide(); $('.service_num').show(); break; case 'smart': $('.smartnumber_detail').show(); $('.post_acc_num').hide(); $('.port_acc_name').hide(); $('.brand_new_detail').hide(); $('.held').hide(); $('.service_num').show(); break; case 'brand_new': $('.smartnumber_detail').hide(); $('.post_acc_num').hide(); $('.port_acc_name').hide(); $('.brand_new_detail').show(); $('.held').hide(); $('.service_num').show(); break; } }); } if($(".add_action").length > 0){ $(".add_action").click(function(e){ e.preventDefault(); // line_hunt add action var target = $("."+$(this).attr('data-target')); console.log(target); var new_one = target.last().clone(); console.log(new_one); // increment the id //console.log(parseInt(new_one.attr("id").replace(/\D/g,''))); new_one.attr("id",'tr_action_'+(parseInt(new_one.attr("id").replace(/\D/g,''))+1)); new_one.find("input[type=hidden]").remove(); new_one.removeClass("hide"); new_one.appendTo(target.parent()); }); } if($(".delete-sound-file").length > 0){ $(".delete-sound-file").click(function(e){ //alert("Hi"); e.preventDefault(); //console.log($(this).parent().parent()); var elm = $(this).parents("form"); $(this).parent().parent().remove(); // delete the row onscreen var mapped_values = {}; mapped_values['id'] = $("#id").val(); mapped_values['service_id'] = $("#service_id").val(); mapped_values['call_type_id'] = $(this).attr('data-info'); //console.log(mapped_values); $.post($(this).attr("href"), mapped_values, function(data){ elm.find('.result-box').html(data); }); }); } if($(".delete-action").length > 0){ $(".delete-action").click(function(e){ //alert("Hi"); e.preventDefault(); //console.log($(this).parents("form")); var elm = $(this).parents("form"); $(this).parent().parent().remove(); // delete the row onscreen var mapped_values = {}; mapped_values['id'] = $("#id").val(); mapped_values['service_id'] = $("#service_id").val(); mapped_values['call_type_id'] = $(this).attr('data-info'); //console.log(mapped_values); //console.log(elm.find('.result-box')); //return; $.post($(this).attr("href"), mapped_values, function(data){ elm.find('.result-box').html(data); }); }); } if($(".suspend-extension").length > 0){ $(".suspend-extension").click(function(e){ //alert("Hi"); e.preventDefault(); //console.log($(this).parents("form")); var elm = $(this).parents("form"); //$(this).parent().parent().remove(); // delete the row onscreen var mapped_values = {}; mapped_values['id'] = $("#id").val(); mapped_values['service_id'] = $("#service_id").val(); mapped_values['extension'] = $(this).attr('data-serviceid'); //console.log(mapped_values); var state = $(this).hasClass('active'); if(state){ mapped_values['suspend'] = 0; }else{ mapped_values['suspend'] = 1; } //alert(mapped_values['suspend']);return; $.post($(this).attr("href"), mapped_values, function(data){ window.location.reload(); }); }); } if($(".cancel-extension").length > 0){ $(".cancel-extension").click(function(e){ //alert("Hi"); e.preventDefault(); var r=confirm("Are you sure you want to cancel this extension?"); if(r == true){ //console.log($(this).parents("form")); var elm = $(this).parents("form"); //$(this).parent().parent().remove(); // delete the row onscreen var mapped_values = {}; mapped_values['id'] = $("#id").val(); mapped_values['service_id'] = $("#service_id").val(); mapped_values['extension'] = $(this).attr('data-serviceid'); //console.log(mapped_values); //alert(mapped_values['suspend']);return; $.post($(this).attr("href"), mapped_values, function(data){ window.location.reload(); }); } }); } if($(".cancel-indial").length > 0){ $(".cancel-indial").click(function(e){ //alert("Hi"); e.preventDefault(); var r=confirm("Are you sure you want to cancel this indial?"); if(r == true){ //console.log($(this).parents("form")); var elm = $(this).parents("form"); //$(this).parent().parent().remove(); // delete the row onscreen var mapped_values = {}; mapped_values['id'] = $("#id").val(); mapped_values['service_id'] = $("#service_id").val(); mapped_values['indial'] = $(this).attr('data-info'); //console.log(mapped_values); //alert(mapped_values['suspend']);return; $.post($(this).attr("href"), mapped_values, function(data){ window.location.reload(); }); } }); } if($(".call_type").length > 0){ $(".call_type").change(function(e){ //alert("Hi"); e.preventDefault(); // now the value is the css class to toggle. // hide everything $(".IvrMenu").hide(); $(".IntroVoiceMessage").hide(); $(".LineHunt").hide(); $(".VoiceToEmail").hide(); $(".PstnNumber").hide(); $(".Queue").hide(); $(".RVARecordable").hide(); // show this css class.. $("."+$(this).val()).show(); }); } /*if($(".time_based_mode").length > 0){ $(".action_type").change(function(e){ //alert("Hi"); e.preventDefault(); // now the value is the css class to toggle. // hide everything $(".IvrMenu").hide(); $(".IntroVoiceMessage").hide(); $(".LineHunt").hide(); $(".VoiceToEmail").hide(); // show this css class.. $("."+$(this).val()).show(); }); }*/ if($('.remove_debtor_reminder').length > 0){ $('.remove_debtor_reminder').on('click', function(){ var elem = $(this); $.post('/ajax/customer/remove_debtor_reminder', 'id='+$(this).attr('id')+'&reminder_id='+$(this).attr('reminder_id'), function(){ //alert("hi"); elem.parent().hide(); }); return false; }); } if($('#location').length > 0){ // add customer form $('#location').change(function(){ var mapped_values = {}; mapped_values['location'] = $("#location").val(); $('#available_number').prop("disabled", true); // do ajax to get actual list of numbers for this. $.post('/ajax/service/get_available_numbers', mapped_values, function(data){ $('#available_number').html(data); $('#available_number').prop("disabled", false); }); }); } }); function bind_live_answer(){ //alert("Binding"); $('.delete-la-email').unbind(); $('.delete-la-sms').unbind(); $('.delete-la-alias').unbind(); $('.delete-la-email').on('click', function(){ $.post($(this).attr("href"), function(result){ window.location.reload(); }); return false; }); $('.delete-la-sms').on('click', function(){ $.post($(this).attr("href"), function(result){ window.location.reload(); }); return false; }); $('.delete-la-alias').on('click', function(){ $.post($(this).attr("href"), function(result){ window.location.reload(); }); return false; }); } function handle_menu(obj){ // check what value is selected if(obj.options[obj.selectedIndex].value == '1'){ $('#destination_number').hide(); $('#ovr_wk1_destination_number').show(); $('#ovr_wk1_start_time').show(); $('#ovr_wk1_end_time').show(); $('#ovr_wk2_destination_number').show(); $('#ovr_wk2_start_time').show(); $('#ovr_wk2_end_time').show(); $('#ovr_ss1_destination_number').show(); $('#ovr_ss1_start_time').show(); $('#ovr_ss1_end_time').show(); $('#ovr_ss2_destination_number').show(); $('#ovr_ss2_start_time').show(); $('#ovr_ss2_end_time').show(); $('#time_based_heading').show(); }else{ $('#destination_number').show(); $('#ovr_wk1_destination_number').hide(); $('#ovr_wk1_start_time').hide(); $('#ovr_wk1_end_time').hide(); $('#ovr_wk2_destination_number').hide(); $('#ovr_wk2_start_time').hide(); $('#ovr_wk2_end_time').hide(); $('#ovr_ss1_destination_number').hide(); $('#ovr_ss1_start_time').hide(); $('#ovr_ss1_end_time').hide(); $('#ovr_ss2_destination_number').hide(); $('#ovr_ss2_start_time').hide(); $('#ovr_ss2_end_time').hide(); $('#time_based_heading').hide(); } } function handleWeekdayMenu(obj){ if(obj.options[obj.selectedIndex].value == 'time'){ $('#week_start_tr').show(); $('#week_end_tr').show(); }else{ $('#week_start_tr').hide(); $('#week_end_tr').hide(); } } function handleSunMenu(obj){ if(obj.options[obj.selectedIndex].value == 'time'){ $('#sun_start_tr').show(); $('#sun_end_tr').show(); }else{ $('#sun_start_tr').hide(); $('#sun_end_tr').hide(); } } function handleSatMenu(obj){ if(obj.options[obj.selectedIndex].value == 'time'){ $('#sat_start_tr').show(); $('#sat_end_tr').show(); }else{ $('#sat_start_tr').hide(); $('#sat_end_tr').hide(); } } function showTypes(obj){ var typeId = obj; if(typeId == 1) $('#multi_q').show(); else $('#multi_q').hide(); if(typeId == 2) $('#multi_a').show(); else $('#multi_a').hide(); if(typeId == 4) $('#multi_c').show(); else $('#multi_c').hide(); } function order_type(obj){ // show relevant fields if(obj.value == 'port'){ $('#sNumber').attr("disabled",false); $('#select2').attr("disabled",false); $('#select3').attr("disabled",false); $('#ex_acc_num').attr("disabled",false); }else{ $('#sNumber').attr("disabled",true); $('#select2').attr("disabled",true); $('#select3').attr("disabled",true); $('#ex_acc_num').attr("disabled",true); } // dob $('#select4').attr("disabled",false); $('#dob_month').attr("disabled",false); $('#select6').attr("disabled",false); $('#newType').attr("disabled",false); $('#sim_num').attr("disabled",false); } function submit_edit_action(e){ $.post($("#edit-action-form").attr("action"), $("#edit-action-form").serialize(), function(data){ $("#editActionModal").modal('hide'); //window.location.reload(); return false; }); return false; } function submit_edit_sip_extension(e){ $.post($("#edit-sip-extension-form").attr("action"), $("#edit-sip-extension-form").serialize(), function(data){ $("#controlSipModal").modal('hide'); window.location.reload(); return false; }); return false; } function submit_add_extension(e){ $.post($("#add-ext-form").attr("action"), $("#add-ext-form").serialize(), function(data){ $("#activateExtModal").modal('hide'); window.location.reload(); return false; }); return false; } function submit_edit_timedbased(e){ // we just want to refresh our modal.. //e.preventDefault(); //console.log($("#indial-timed-based").attr("action")); //$("#controlRoutingModal").removeData("bs.modal"); $.get($("#indial-timed-based").attr("action"), $("#indial-timed-based").serialize(), function(data){ // reload the modal $("#controlRoutingModal").html(data); return false; }); return false; } function add_action_modal(e){ // line_hunt add action var parent = $("#lh_edit_normal"); //console.log(parent); var new_one = parent.children().last().prev().clone(); //var new_one = parent.children().last().prev().clone(); //console.log(new_one); // increment the id //console.log(parseInt(new_one.attr("id").replace(/\D/g,''))); new_one.attr("id",'tr_action_'+(parseInt(new_one.attr("id").replace(/\D/g,''))+1)); new_one.find("input[type=hidden]").remove(); new_one.removeClass("hide"); new_one.appendTo(parent); return false; } function add_action_modal_tb(e){ // line_hunt add action var parent = $("#lh_edit_normal"); //console.log(parent); var new_one = parent.children().last().clone(); //var new_one = parent.children().last().prev().clone(); //console.log(new_one); // increment the id //console.log(parseInt(new_one.attr("id").replace(/\D/g,''))); new_one.attr("id",'tr_action_'+(parseInt(new_one.attr("id").replace(/\D/g,''))+1)); new_one.find("input[type=hidden]").remove(); new_one.removeClass("hide"); new_one.appendTo(parent); return false; } function add_action_modal_sd(e){ // line_hunt add action var parent = $("#sd_edit_normal"); //console.log(parent); var new_one = parent.children().last().prev().clone(); //console.log(new_one); // increment the id //console.log(parseInt(new_one.attr("id").replace(/\D/g,''))); new_one.attr("id",'tr_action_'+(parseInt(new_one.attr("id").replace(/\D/g,''))+1)); new_one.find("input[type=hidden]").remove(); new_one.removeClass("hide"); new_one.appendTo(parent); return false; } function handle_ip_select(obj,type,did,ip_address){ var func = ""; if(type == 'white') func = "whitelist_ip"; if(type == 'black') func = "blacklist_ip"; // if we select 'no' - run the reset function if(obj.options[obj.selectedIndex].value == "0") func = "reset_ip" //http.open("GET", "ajax_ip.php?func=" + func + "&did=" + did + "&ip_address=" + ip_address, true); //http.onreadystatechange = handleHttpResponse; //http.send(null); $.post('/ajax/service/'+func, "&did=" + did + "&ip_address=" + ip_address + "&id=" + customer_id); return false; } function handle_ph_select(obj,type,did,phone){ var func = ""; if(type == 'white') func = "whitelist_ph"; if(type == 'black') func = "blacklist_ph"; // if we select 'no' - run the reset function if(obj.options[obj.selectedIndex].value == "0") func = "reset_ph"; //http.open("GET", "ajax_phone.php?func=" + func + "&did=" + did + "&phone=" + phone, true); //http.onreadystatechange = handleHttpResponse; //http.send(null); $.post('/ajax/service/'+func, "&did=" + did + "&phone=" + phone+ "&id=" + customer_id); } function submit_modal_refresh(e){ $.post($(e).attr("action"), $(e).serialize(), function(data){ $(e).parent().parent().modal('hide'); window.location.reload(); return false; }); return false; } function submit_modal(e){ console.log($(e).parent().parent()); $.post($(e).attr("action"), $(e).serialize(), function(data){ $(e).parent().parent().modal('hide'); return false; }); return false; }