(function( $ ) { 'use strict'; })( jQuery ); function addNewAccount() { $('#form-tab').text('Add new sub-accounts'); $('#update-account').hide(); $('#add-account').show(); $('#full-name').val(''); $('#user_email').val(''); $('#pass_cred').show(); $('#form-tab').show(); $('#form-tab-update').hide(); //$(".chkb-page-priv").attr("checked",false); } function saveUserPriv() { var ajaxurl = $('#ajax-url').val(); var data = { action: "save_user_priv", pages: JSON.stringify($("#frm-edit-priv").serializeObject()) } $.post(ajaxurl, data, function (response) { if(response.success === 1) { window.location.reload(); swal({ title: 'Thanks!', text: 'Updating user privilege.', timer: 5000, onOpen: function () { swal.showLoading() } }) } }); } function editPriv(user_id, name, e) { var ajaxurl = $('#ajax-url').val(); e.preventDefault(); var data = { action: "get_user_pages", user_id: user_id } $.get(ajaxurl, data, function (response) { if(response.pages != false) { var data = response.pages; // Add user priviledged pages $.each(data, function(i, val) { $(".chkb-page-priv[tag="+val+"]").attr("checked", "checked"); }); } $('a[href="#menu3"]').tab('show'); $('span#display-name').text(name); $('#user_id').val(user_id); }); } function saveNewAccount() { var ajaxurl = $('#ajax-url').val(); if($('#user_pass').val() != '' && $('#user_email').val() != '' && $('#full_name').val() != '') { if($('#user_pass').val() === $('#confirm_pass').val()) { var data = { action: 'save_new_account', display_name: $('#full-name').val(), user_email: $('#user_email').val(), user_pass: $('#user_pass').val() } $.post(ajaxurl, data, function (response) { if(response.status === 1) { window.location.reload(); swal({ title: 'Thanks!', text: 'Creating new user.', timer: 5000, onOpen: function () { swal.showLoading() } }) } }); } else { swal({ title: 'Oops!', text: 'Password does not match!', type: 'error', confirmButtonClass: 'btn swal-btn-umbrella' }).then(function () { return; }); } } else { swal({ title: 'Oops!', text: 'All fields are required!', type: 'error', confirmButtonClass: 'btn swal-btn-umbrella' }).then(function () { return; }); } } function limitReach() { swal('Oops!', "You've reach your allowed sub accounts.", 'warning'); } function editUser(user_id, e) { e.preventDefault(); var ajaxurl = $('#ajax-url').val(); var data = { action : 'get_user_data', id: user_id } $.get(ajaxurl, data, function (response) { console.log(response.data) $('#full-name').val(response.data.display_name); $('#user_email').val(response.data.user_email); $('#form-tab').hide(); $('#form-tab-update').show(); $('#form-tab').off('click'); $('a[href="#menu2"]').tab('show'); $('#update-account').show(); $('#add-account').hide(); $('#edit_user_id').val(user_id); $('#pass_cred').hide(); }); } function deleteUser(user_id, e) { e.preventDefault(); swal({ title: 'Are you sure?', text: "You want to delete this sub-account?!", type: 'warning', showCancelButton: true, confirmButtonColor: '#d33', cancelButtonColor: '#3085d6', confirmButtonText: 'Yes, delete it!', cancelButtonText: 'No, cancel!', confirmButtonClass: 'btn swal-btn-umbrella btn-swal-right', cancelButtonClass: 'btn btn-primary', buttonsStyling: false }).then(function (result) { if (result) { var ajaxurl = $('#ajax-url').val(); var data = { action : 'delete_user', id: user_id } $.get(ajaxurl, data, function (response) { $('#'+user_id).hide(); swal({ title:'Great job!', text: 'Your file has been deleted.', type:'success', confirmButtonClass: 'btn swal-btn-umbrella' }); }); } else { swal({ title:'Great job!', text: 'User is safe.', type:'success', confirmButtonClass: 'btn swal-btn-umbrella' }); } }) } function updateAccount() { var ajaxurl = $('#ajax-url').val(); if($('#user_email').val() != '' && $('#full_name').val() != '') { var data = { action: 'update_user_account', display_name: $('#full-name').val(), user_email: $('#user_email').val(), user_id: $('#edit_user_id').val() } $.post(ajaxurl, data, function (response) { console.log(response) if(response.success === 1) { window.location.reload(); swal({ title: 'Thanks!', text: 'Updating user.', timer: 5000, onOpen: function () { swal.showLoading() } }) } }); } else { swal({ title: 'Oops!', text: 'Both fields are required!', type: 'error', confirmButtonClass: 'btn swal-btn-umbrella' }).then(function () { return; }); } } function disableInput(inputObject) { if($(inputObject).is(':checked')){ $("#working-time-table .data-td-"+$(inputObject).val()).find("select").attr("disabled", "disabled").css({'border-color':'#dcdcdc', 'color':'#dcdcdc'}); $("#working-time-table .data-td-"+$(inputObject).val()).find("input").attr("disabled", "disabled"); $('#working-time-table .break-option-'+$(inputObject).val()).css('display', 'none'); } else { $("#working-time-table .data-td-"+$(inputObject).val()).find("select").removeAttr('disabled').css({'border-color':'', 'color':''}); $("#working-time-table .data-td-"+$(inputObject).val()).find("input").removeAttr("disabled").css({'color':''}); } } function disableInputCallBack(inputObject) { if($(inputObject).is(':checked')){ $("#callback-time-table .data-td-"+$(inputObject).val()).find("select").attr("disabled", "disabled").css({'border-color':'#dcdcdc', 'color':'#dcdcdc'}); $("#callback-time-table .data-td-"+$(inputObject).val()).find("input").attr("disabled", "disabled"); $('#callback-time-table .break-option-'+$(inputObject).val()).css('display', 'none'); } else { $("#callback-time-table .data-td-"+$(inputObject).val()).find("select").removeAttr('disabled').css({'border-color':'', 'color':''}); $("#callback-time-table .data-td-"+$(inputObject).val()).find("input").removeAttr("disabled").css({'color':''}); } } function saveCallBackSettings() { var days = {}; var pass = []; $.each($("#callback-time-table .time-table"), function () { var from = $("#callback-time-table select[name='from_"+$(this).attr('id')+"_hour']").val() + ':' + $("#callback-time-table select[name='from_"+$(this).attr('id')+"_min']").val()+':00'; var to = $("#callback-time-table select[name='to_"+$(this).attr('id')+"_hour']").val() + ':' + $("#callback-time-table select[name='to_"+$(this).attr('id')+"_min']").val()+':00'; var from_break = $("#callback-time-table select[name='from_"+$(this).attr('id')+"_hour_break']").val() + ':' + $("#callback-time-table select[name='from_"+$(this).attr('id')+"_min_break']").val()+':00'; var to_break = $("#callback-time-table select[name='to_"+$(this).attr('id')+"_hour_break']").val() + ':' + $("#callback-time-table select[name='to_"+$(this).attr('id')+"_min_break']").val()+':00'; var checkbox = $(this).attr('id'); if($('#callback-time-table #close_input_'+checkbox+'day').is(':checked')){ days[$(this).attr('id')+'day'] = { "closed" : true }; pass.push(true); } else { var from_parse = Date.parse('01/01/2011 '+from); var to_parse = Date.parse('01/01/2011 '+to); var from_parse_break = Date.parse('01/01/2011 '+from_break); var to_parse_break = Date.parse('01/01/2011 '+to_break); if(from_parse >= to_parse){ pass.push(false); } else { if(from_break != '00:00:00' || to_break != '00:00:00'){ if(from_parse_break <= to_parse_break && inRange(from_parse_break, from_parse, to_parse) && inRange(to_parse_break, from_parse, to_parse) ){ pass.push(true); } else { pass.push(false); } } else { pass.push(true); } } days[$(this).attr('id')+'day'] = { "range" : { "from" : from, "to" : to }, "break" : { "from" : from_break, "to" : to_break }, "closed" : false }; } }); if($('select[name="call_back_delay_unit"]').val() === 'mins'){ days['delay'] = { 'unit': $('select[name="call_back_delay_unit"]').val(), 'time' : "00:"+$('select[name="call_back_delay"]').val()+":00", 'value' : $('select[name="call_back_delay"]').val() }; } else { days['delay'] = { 'unit': $('select[name="call_back_delay_unit"]').val(), 'time' : $('select[name="call_back_delay"]').val()+":00:00", 'value' : $('select[name="call_back_delay"]').val() }; } if($('select[name="call_back_length_unit"]').val() === 'hours'){ days['length'] = { 'unit': $('select[name="call_back_length_unit"]').val(), 'time' : $('select[name="call_back_length"]').val()+":00:00", 'value' : $('select[name="call_back_length"]').val() }; } else { days['length'] = { 'unit': $('select[name="call_back_length_unit"]').val(), 'time' : "00:"+$('select[name="call_back_length"]').val()+":00", 'value' : $('select[name="call_back_length"]').val() }; } if(!pass.includes(false)){ var data = { action: 'save_callback_table', days: days, timezone: $('select[name="umbrella_timezome"]').val(), dateformat: $('select[name="umbrella_dateformat"]').val() }; var ajaxurl = $('#time-table-ajax').val(); $.post(ajaxurl, data, function (response) { console.log(response); swal({ title:'Great job!', text:'You successfully update the settings!', type:'success', confirmButtonClass: 'btn swal-btn-umbrella' }); }); } else { validityError(); } } function saveTimeTableSettings() { var days = {}; var pass = []; $.each($("#working-time-table .time-table"), function () { var from = $("#working-time-table select[name='from_"+$(this).attr('id')+"_hour']").val() + ':' + $("#working-time-table select[name='from_"+$(this).attr('id')+"_min']").val()+':00'; var to = $("#working-time-table select[name='to_"+$(this).attr('id')+"_hour']").val() + ':' + $("#working-time-table select[name='to_"+$(this).attr('id')+"_min']").val()+':00'; var from_break = $("#working-time-table select[name='from_"+$(this).attr('id')+"_hour_break']").val() + ':' + $("#working-time-table select[name='from_"+$(this).attr('id')+"_min_break']").val()+':00'; var to_break = $("#working-time-table select[name='to_"+$(this).attr('id')+"_hour_break']").val() + ':' + $("#working-time-table select[name='to_"+$(this).attr('id')+"_min_break']").val()+':00'; var checkbox = $(this).attr('id'); if($('#working-time-table #close_input_'+checkbox+'day').is(':checked')){ days[$(this).attr('id')+'day'] = { "closed" : true }; pass.push(true); } else { var from_parse = Date.parse('01/01/2011 '+from); var to_parse = Date.parse('01/01/2011 '+to); var from_parse_break = Date.parse('01/01/2011 '+from_break); var to_parse_break = Date.parse('01/01/2011 '+to_break); if(from_parse >= to_parse){ pass.push(false); } else { if(from_break != '00:00:00' || to_break != '00:00:00'){ if(from_parse_break <= to_parse_break && inRange(from_parse_break, from_parse, to_parse) && inRange(to_parse_break, from_parse, to_parse) ){ pass.push(true); } else { pass.push(false); } } else { pass.push(true); } } days[$(this).attr('id')+'day'] = { "range" : { "from" : from, "to" : to }, "break" : { "from" : from_break, "to" : to_break }, "closed" : false }; } }); if(!pass.includes(false)){ var data = { action: 'save_openning_table', days: days, timezone: $('select[name="umbrella_timezome"]').val(), dateformat: $('select[name="umbrella_dateformat"]').val() }; var ajaxurl = $('#time-table-ajax').val(); $.post(ajaxurl, data, function (response) { console.log(response); swal({ title:'Great job!', text:'You successfully update the settings!', type:'success', confirmButtonClass: 'btn swal-btn-umbrella' }); }); } else { validityError(); } } function inRange(current, start, end) { if(current > start && current < end) return true; return false; } function addBreak(day) { $('#working-time-table .break-option-'+day).css('display', 'block'); $('#working-time-table #break-'+day).css('display', 'none'); $('#working-time-table #nobreak-'+day).css('display', 'block'); } function addBreakCallBack(day) { $('#callback-time-table .break-option-'+day).css('display', 'block'); $('#callback-time-table #break-'+day).css('display', 'none'); $('#callback-time-table #nobreak-'+day).css('display', 'block'); } function noBreakCallBack(day) { $('#callback-time-table .break-option-'+day).css('display', 'none'); $('#callback-time-table #break-'+day).css('display', 'block'); $('#callback-time-table #nobreak-'+day).css('display', 'none'); day = day.replace('day', ''); $('#callback-time-table select[name="from_'+day+'_hour_break').val('00'); $('#callback-time-table select[name="from_'+day+'_min_break').val('00'); $('#callback-time-table select[name="to_'+day+'_hour_break').val('00'); $('#callback-time-table select[name="to_'+day+'_min_break').val('00'); } function noBreak(day) { $('#working-time-table .break-option-'+day).css('display', 'none'); $('#working-time-table #break-'+day).css('display', 'block'); $('#working-time-table #nobreak-'+day).css('display', 'none'); day = day.replace('day', ''); $('#working-time-table select[name="from_'+day+'_hour_break').val('00'); $('#working-time-table select[name="from_'+day+'_min_break').val('00'); $('#working-time-table select[name="to_'+day+'_hour_break').val('00'); $('#working-time-table select[name="to_'+day+'_min_break').val('00'); } function validityError() { swal({ title: 'Oops!', text: 'Invalid time schedule!', type: 'error', confirmButtonClass: 'btn swal-btn-umbrella' }).then(function () { return; }); }