var $MODAL = $('#Modal-main') , $MODAL_BT_SUBMIT = $("#main-modal-Submit") , $MODAL_TITLE = $('#main-modal-title') , $MODAL_BT_CLOSE = $('#close-modal') , $MENU_TOGGLE = $('#sidebarToggle') , $MAND_CONTENT = $('.body');WH = (new function () { this.loading = '
Loading...
'; this.iconloading = '
đang tải...'; this.Miconloading = '
đang tải...
'; this.iconsearch = '
đang tìm dữ liệu...
'; this.searching = false; this.delay = 10; this.Xong = function () { $('.Mloading').fadeOut('slow').html(''); $('#wrapper').show(); WH.GoLink(); }; this.ajaxTPView = function () { $.each($('[sms-view="ajaxTpleft"]'), function () { var curren = $(this); var url = curren.attr('data-href'); var title = curren.attr('data-title'); if (typeof url === "undefined" || url === "" || url === '#') { return; } curren.unbind("click").on('click', function (e) { var h = window.innerHeight - 67; var d = ''; WH.ShowTpLeft({ id: 1, data: d, title: title, x: -3, y: -3 }); e.preventDefault(); } ); }); }; this.ShowTpLeft = function (option) { if (option.id == "" || typeof option.id === "undefined" || option.id == null) { option.id = 1; } if (option.data == "" || typeof option.data === "undefined" || option.data == null) { option.data = "No data"; } if (option.title == "" || typeof option.title === "undefined" || option.title == null) { option.title = "No title"; } if (option.x == "" || typeof option.x === "undefined" || option.x == null) { option.x = null; } if (option.y == "" || typeof option.y === "undefined" || option.y == null) { option.y = null; } $('.pt-left' + option.id + ' .panel-body').html('
' + WH.iconloading + '
'); $('.pt-left' + option.id + ' .panel-body').append(option.data); $('.pt-left' + option.id + ' .title').html(option.title); $('.pt-left' + option.id + ' .panel-body iframe').hide(); if (option.x != null) { $('.pt-left' + option.id).css({ 'top': option.x + 'px' }); } if (option.y != null) { if (option.y == "r") { $('.pt-left' + option.id).css({ 'right': 0 + 'px' }); $('.pt-left' + option.id).css({ 'left': 'auto' }); if ($('.pt-left' + option.id).is(":hidden")) { $('.pt-left' + option.id).toggle("slide:right") } } else { $('.pt-left' + option.id).css({ 'left': option.y + 'px' }); if ($('.pt-left' + option.id).is(":hidden")) { $('.pt-left' + option.id).toggle("slide:left") } } } else { if ($('.pt-left' + option.id).is(":hidden")) { $('.pt-left' + option.id).toggle("slide:left"); } } if ($('.pt-left' + option.id + ' .panel-body embed').length > 0) { $('.pt-left' + option.id + ' .panel-body embed').show(); $('.pt-left' + option.id + ' .panel-body .loading').remove(); $('.pt-left' + option.id + ' .Mloader').remove(); } }; this.HideTpLeft = function (i) { $('.pt-left' + i).toggle("slide:left"); $('.pt-left' + i + ' .title').html(""); $('.pt-left' + i + ' .panel-body').html(""); }; this.GoLink = function () { $.each($('a:not(".addclick")'), function () { var e = $(this); var url = e.attr("href"); var check = e.attr("target"); if (typeof check !== "undefined") { e.addClass("addclick"); } else { if (url && typeof url !== "undefined") { if (url.startsWith("/") || url.startsWith("http")) { e.click(function () { $('.Mloading').html(WH.Miconloading).show(); /*$('#wrapper').remove();*/ setTimeout( function () { $('.Mloading').fadeOut('slow').html(''); }, 5000); }).addClass("addclick"); } } } }); }; this.ChatZalo = function () { if(isMobile.any()) { $.each($('.linkzalo'), function () { var e = $(this); var url = e.attr("href"); if(url.startsWith("https://chat.zalo.me/")) { url = url.replace("https://chat.zalo.me/", "https://zalo.me/"); url = url.replace("?phone=", ""); e.attr("href", url); } }); } }; this.ViewGoLink = function () { $('.Mloading').html(WH.Miconloading).show(); $('#wrapper').remove(); }; this.ini = function () { this.AjaxUpdate(); this.AjaxModal(); this.AutoComplete(); this.FormatNumber(); this.select(); this.Ajaxselect(); this.Datetime(); this.AjaxDelete(); this.GoLink(); this.ajaxTPView(); }; this.LoadMask = function (id) { if (typeof id === "undefined" || id === "" || id == null) { id = '.wrapper' } $(id).addClass('overlay'); $('.overlay').append(''); }; this.hideMask = function () { $('.overlay .spinner-border').remove(); $('.overlay').removeClass('overlay'); }; this.FormatSave = function () { $.each($('.form-save'), function () { var curren = $(this); curren.removeClass('form-save'); var id = curren.attr('id'); var msg_success = curren.attr('data-success'); if (typeof id === "undefined" || id === "") { return; } $(curren).submit(function (e) { e.preventDefault(); var form = $(this); var url = form.attr('action'); WH.LoadMask("#" + id); $('.formatNumber', form).autoNumeric('update', { aSign: '', aDec: '.', aSep: '' }); var formData = new FormData(); var files = $('input[type=file]'); if (files && files.length>0) { for (var i = 0; i < files.length; i++) { if (files[i].value == "" || files[i].value == null) { continue; } else { formData.append(files[i].name, files[i].files[0]); } } formData.append("upload_file", true); } var formSerializeArray = form.serializeArray(); for (var i = 0; i < formSerializeArray.length; i++) { formData.append(formSerializeArray[i].name, formSerializeArray[i].value) } $.ajax({ type: "POST", url: url, success: function (data) { WH.ThongBao(msg_success, 'center'); WH.hideMask(); if (typeof SaveComplete != "undefined" && SaveComplete instanceof Function) { SaveComplete(data); } }, error: function (xhr) { WH.Loi(xhr.responseText, 'center'); WH.hideMask(); }, async: true, data: formData, cache: false, contentType: false, processData: false, timeout: 60000 }); }); }); }; this.formData = function (id) { var form = $(id); var formData = new FormData(); var formSerializeArray = form.serializeArray(); for (var i = 0; i < formSerializeArray.length; i++) { formData.append(formSerializeArray[i].name, formSerializeArray[i].value) } return formData; }; this.AjaxDelete = function() { $.each($('[sms-control="ajaxdelete"]'), function() { var curren = $(this); var icon = curren; var test = $FORM = $('.fa', curren); if (test.length > 0) { icon = $(test[0]); } curren.unbind("click").on('click', function (e) { var cfm = curren.attr('data-cfm'); if (typeof cfm !== "undefined" && cfm !== "") { var r = confirm(cfm); if (r !== true) { return; } } icon.removeClass('fa-trash,fa-ship'); icon.addClass('fa-spinner fa-pulse'); var data = { 'id': encodeURIComponent(curren.attr('data-id')) }; $.post(curren.attr('data-href'), data, function() { }) .done(function(data) { var complete = $(curren).attr('delete-complete'); if (typeof complete !== "undefined" && complete !== "") { window[complete](data); } }) .fail(function(data) { icon.addClass('fa-exclamation-triangle'); icon.removeClass('fa-spinner fa-pulse'); WH.Loi(data.responseText); }).always(function() { }); e.preventDefault(); } ); }); }; this.urlRule = { "fileNo": "/AutoComplete/fileNo", "contact": "/AutoComplete/Contact", "contactE": "/AutoComplete/ContactE", "port": "/AutoComplete/Port", "vehicles": "/AutoComplete/vehicles", "vsl": "/AutoComplete/vsl", "flight": "/AutoComplete/flight", "package": "/AutoComplete/Package", "Employee": "/AutoComplete/Employee", "Task": "/AutoComplete/Task", "Address": "/AutoComplete/Address", "AccountCode": "/AutoComplete/AccountCode", "BookingNo": "/AutoComplete/BookingNo", "BookingFile": "/AutoComplete/BookingFile", "AjaxPort": "/AutoComplete/AjaxPort", "AjaxContact": "/AutoComplete/AjaxContact", "AjaxCerrie": "/AutoComplete/AjaxCerrie", "AjaxGetListAgt": "/AutoComplete/AjaxGetListAgt", "AjaxPackage": "/AutoComplete/AjaxPackage", "PhieuDau": "/AutoComplete/PhieuDau", "MblNo": "/AutoComplete/MblNo", "CDNo": "/AutoComplete/CDNo", "ContNo": "/AutoComplete/ContNo", "ContactAddress": "/AutoComplete/ContactAddress", "AjaxTinhThanh": "/AutoComplete/AjaxTinhThanh", "Soxe": "/AutoComplete/Soxe", "InvTK": "/AutoComplete/InvTK", "InvTK": "/AutoComplete/InvTK", }; this.Cparam = function (v) { return encodeURIComponent(v); }; this.AllKeyEnterSearch = function () { $.each($('.getdata:not(".addenter")'), function () { $(this).enterKey(function (e) { e.stopPropagation(); Search(); return false; }).addClass("addenter"); }); }; this.GetData = function (page) { var d = ''; $.each($('.getdata'), function () { var e = $(this); if (d != '') { d += ","; } d += '"' + e.attr('id') + '":"' + WH.Cparam(e.val()) + '"'; }); if (!(page == "" || typeof page === "undefined" || page == null)) { if (d != '') { d += ","; } d += '"page":"' + page + '"'; } var data = "{" + d + "}"; return jQuery.parseJSON(data); }; this.ClearData = function () { $.each($('.getdata'), function () { var e = $(this); e.val('').trigger('change'); }); }; this.FormatNumber = function () { $.each($('.formatNumber:not(".added-number")'), function () { $(this).click(function () { this.select(); }).autoNumeric('init', { mDec: 6, aPad: false, aForm: false }) .removeClass("addselect") .addClass('added-number'); }); }; this.addCommas = function (nStr) { if (nStr == null || nStr == 'null' || nStr == '' || typeof nStr === "undefined") return ""; nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; }; this.CloseItem = function (id) { $('.' + id).fadeOut('slow', function () { $(this).remove(); }); }; this.CloseDg = function (t) { $MODAL_BT_CLOSE.trigger("click"); }; this.ThongBao = function (t, icon) { if (t == '') return; if (icon == "" || typeof icon === "undefined" || icon == null) { icon = "fa fa-bell"; } $.dialog({ icon: 'fa ' + icon, type: 'green', title: 'Thông báo!', content: t, }); }; this.Loi = function (t) { $.dialog({ icon: 'fa fa-bug', type: 'red', title: 'Lỗi!', content: t, }); }; this.Print = function (t) { if (t == "" || typeof t === "undefined" || t == null) { window.print(); } else { var printContents = $(t).html(); var originalContents = $('body').html(); $('body').html(printContents); window.print(); $('body').html(originalContents); } }; this.SelectOnFocus = function () { $.each($('.addselect'), function () { $(this).click(function () { this.select(); }).removeClass("addselect"); }); }; this.ConfigFocus = function () { $.each($('.EnterNextControl:not(".addedEnterNextControl")'), function (e) { $(this).enterKey(function () { event.preventDefault(); WH.Focus($(this).attr('EnterNextControl')); }).addClass("addedEnterNextControl"); }); }; this.Focus = function (t) { setTimeout(function () { var curren = $(t); if (curren.hasClass("formatNumber")) { curren.focus().select();; } else if (curren.hasClass("addedSelect")) { curren.select2('open'); } else { curren.focus(); } }, WH.delay); }; this.Focus2 = function (t,time) { setTimeout(function () { var curren = $(t); if (curren.hasClass("formatNumber")) { curren.focus().select();; } else if (curren.hasClass("addedSelect")) { curren.select2('open'); } else { curren.focus(); } }, WH.delay * time); }; this.NextRowFocus = function (t,f) { setTimeout(function () { var curren = $('input:first', $(t).parent('td').parent('tr').next()); if (curren.length==0 || curren == "" || typeof curren === "undefined" || curren == null) { WH.Confirm({ text: "Bạn có muốn tạo thêm sản dòng mới", f: f }); return; } if (curren.hasClass("formatNumber")) { curren.focus().select(); } else if (curren.hasClass("addedSelect")) { curren.select2('open'); } else { curren.focus(); } }, WH.delay); }; this.AutoComplete = function () { $.each($('[sms-control="autoComplete"]:not(".addedAutocomplete")'), function () { var curren = $(this); var rule = curren.attr('sms-data-url'); var url = "/AutoComplete/" + rule; var mustMatch = false; var multiple = false; if (curren.attr('sms-multiple') == 'true') { multiple = true; } curren.autocomplete(url, { multiple: multiple, minChars: 0, autoFill: false, mustMatch: mustMatch, formatItem: function (data, i, n, value) { if (data === "" || data == null) return ""; return value; } }) .result(function (event, data) { if (!multiple && !mustMatch) { curren.val(data); } var functionResult = curren.attr('sms-function-result'); if (typeof functionResult !== "undefined" && functionResult !== "") { window[functionResult](); } $(curren).trigger("change"); }).addClass("addedAutocomplete") .enterKey(function () { curren.trigger("keydown", [9]); }); }); }; this.Search = function (option) { if (WH.searching) return; if (!(option.click == "" || typeof option.click === "undefined" || option.click == null)) { $(option.click).trigger("click"); } if (option.param == 'auto') { option.param = WH.GetData(); } if (option.param == "" || typeof option.param === "undefined" || option.param == null) { option.param = {}; } if (option.f == "" || typeof option.f === "undefined" || option.f == null) { option.f = function () { }; } if (option.overload == "" || typeof option.overload === "undefined" || option.overload == null) { if (option.overload != false) option.overload = true; } var taget; if (option.t == 'modal') { taget = $('.modal-body', $MODAL); } else { taget = $(option.t); } if (option.overload) { taget.html(WH.iconsearch); /* if (taget.html() == '') { taget.html(WH.iconsearch); } else { taget.addClass('overlay index-top'); }*/ } WH.searching = true; $.post(option.url, option.param, function (data) { taget.html(data); WH.searching = false; option.f(); }).fail(function (data) { WH.Loi(data.responseText); taget.html(""); }).always(function () { if (option.overload) { taget.removeClass('overlay index-top'); }; WH.searching = false; }); }; this.SearchNext = function (option) { if (WH.searching) return; if (!(option.click == "" || typeof option.click === "undefined" || option.click == null)) { $(option.click).trigger("click"); } if (option.param == 'auto') { option.param = WH.GetData(option.page); } if (option.param == "" || typeof option.param === "undefined" || option.param == null) { option.param = {}; } if (option.f == "" || typeof option.f === "undefined" || option.f == null) { option.f = function () { }; } if (option.overload == "" || typeof option.overload === "undefined" || option.overload == null) { if (option.overload != false) option.overload = true; } var taget; if (option.t == 'modal') { taget = $('.modal-body', $MODAL); } else { taget = $(option.t); } if (option.overload) { if (taget.html() == '') { taget.html(WH.iconsearch); } else { taget.addClass('overlay index-top'); } } WH.searching = true; if ($('.v-m-items').length > 0) $('.v-m-items').remove(); if ($('.s-tong').length > 0) $('.s-tong').remove(); $.post(option.url, option.param, function (data) { taget.append(data); option.f(); }).fail(function (data) { WH.Loi(data.responseText); }).always(function () { if (option.overload) { taget.removeClass('overlay index-top'); } WH.searching = false; }); }; this.AddMask = function (e) { var taget = $(e); if (taget.html() == '') { taget.html(WH.iconsearch); } else { taget.addClass('overlay index-top'); } }; this.RemoveMask = function (e) { $(e).removeClass('overlay index-top'); }; this.AddItem = function (option) { if (WH.searching) return; if (option.param == "" || typeof option.param === "undefined" || option.param == null) { option.param = {}; } if (option.f == "" || typeof option.f === "undefined" || option.f == null) { option.f = function () { }; } if ($(option.t).html() == '') { $(option.t).html(WH.iconsearch); } else { $(option.t).addClass('overlay index-top'); } WH.searching = true; $.post(option.url, option.param, function (data) { setTimeout(function () { option.f(); }, WH.delay); }).fail(function (data) { WH.Loi(data.responseText); }).always(function () { $(option.t).removeClass('overlay index-top'); WH.searching = false; }); }; this.Confirm = function (option) { if (WH.searching) return; if (option.text == "" || typeof option.text === "undefined" || option.text == null) { option.text = ''; } if (option.param == "" || typeof option.param === "undefined" || option.param == null) { option.param = {}; } if (option.f == "" || typeof option.f === "undefined" || option.f == null) { option.f = function () { }; } $.confirm({ title: 'Xác nhận!', type: 'orange', typeAnimated: true, content: option.text, buttons: { yes: { text: 'Yes', btnClass: 'btn-btn-danger', keys: ['enter'], action: function () { option.f(); } }, cancel: { text: 'Cancel', btnClass: 'btn-btn-primary', keys: ['esc'], action: function () { } } } }); }; this.Delete = function (option) { if (WH.searching) return; if (option.text == "" || typeof option.text === "undefined" || option.text == null) { option.text = ''; } if (option.param == "" || typeof option.param === "undefined" || option.param == null) { option.param = {}; } if (option.f == "" || typeof option.f === "undefined" || option.f == null) { option.f = function () { }; } $.confirm({ type: 'orange', typeAnimated: true, title: 'Xác nhận xóa', content: "bạn muốn xóa " + option.text + "?", buttons: { yes: { text: 'Yes', btnClass: 'btn-btn-danger', keys: ['enter'], action: function () { $(option.t).addClass('overlay index-top'); WH.searching = true; $.post(option.url, option.param, function (data) { $(option.t).remove(); setTimeout(function () { option.f(); }, WH.delay); }).fail(function (data) { WH.Loi(data.responseText); }).always(function () { $(option.t).removeClass('overlay index-top'); WH.searching = false; }); } }, cancel: { text: 'Cancel', btnClass: 'btn-btn-primary', keys: ['esc'], action: function () { } } } }); }; this.XacNhan = function (option) { if (WH.searching) return; if (option.text == "" || typeof option.text === "undefined" || option.text == null) { option.text = ''; } if (option.param == "" || typeof option.param === "undefined" || option.param == null) { option.param = {}; } if (option.f == "" || typeof option.f === "undefined" || option.f == null) { option.f = function () { }; } $.confirm({ type: 'orange', typeAnimated: true, title: 'Xác nhận', content: option.text + "?", buttons: { yes: { text: 'Yes', btnClass: 'btn-btn-danger', keys: ['enter'], action: function () { $(option.t).addClass('overlay index-top'); WH.searching = true; $.post(option.url, option.param, function (data) { setTimeout(function () { option.f(); }, WH.delay); }).fail(function (data) { WH.Loi(data.responseText); }).always(function () { $(option.t).removeClass('overlay index-top'); WH.searching = false; }); } }, cancel: { text: 'Cancel', btnClass: 'btn-btn-primary', keys: ['esc'], action: function () { } } } }); }; this.AjaxPostData = function (option) { var data = { 't': option.table, 'p': option.name, 'v': encodeURIComponent(option.value), 'id': option.id, 'a': option.a }; $.post(option.url, data, function () { }) .done(function () { if (typeof option.f !== "undefined" && option.f !== "") { window[option.f](option.id); } }) .fail(function (xhr) { if (xhr.responseText == " ") { return; } if ('NotviewFalse' != xhr.responseText) WH.Loi(xhr.responseText); }) .always(function () { }); }; this.AjaxUpdateUrl = ""; this.AjaxUpdateTable = ""; this.AJaxUpdateId = ""; this.value = ""; this.id = ""; this.p = ""; this.AjaxUpdate = function () { $.each($('.data-sms-AjaxUpdate:not(".addhandler")'), function () { var curren = $(this); curren.removeClass("data-sms-AjaxUpdate"); var oldV = curren.val(); var name = curren.attr('name'); var NotviewFalse = curren.hasClass('NotviewFalse'); if (name === '' || typeof name === "undefined") return; curren.addClass("addhandler").unbind('change').change(function () { if (name === '' || typeof name === "undefined") return; var smsbeforeupdate = curren.attr('smsBeforeUpdate'); if (typeof smsbeforeupdate !== "undefined" && smsbeforeupdate !== "") { if (!window[smsbeforeupdate]()) return; } var a = 'text'; var table_update = curren.attr('data-table-update'); if (typeof table_update === "undefined" || table_update === "" || table_update === '#') { table_update = WH.AjaxUpdateTable; } var table_id = curren.attr('data-id-update'); if (typeof table_id === "undefined" || table_id === "" || table_id === '#') { table_id = WH.AJaxUpdateId; } var value = curren.val(); if (curren.hasClass("formatNumber")) { value = curren.autoNumeric('get'); a = 'number'; } if (curren.hasClass("checkbox")) { value = curren.is(":checked") ? 1 : 0; a = 'checkbox'; } if (curren.hasClass("addedDatetime")) { a = 'date'; } var data = { 't': table_update, 'p': name, 'v': encodeURIComponent(value), 'id': table_id, 'a':a }; if ((($.now() - WH.time < 20) && WH.value == data.v) || ( data.v == WH.value && data.id == WH.id && data.p == WH.p ) ) { return; } WH.time = $.now(); WH.value = data.v; WH.id = data.id; WH.p = data.p; var url = curren.attr('data-href-update'); if (typeof url === "undefined" || url === "" || url === '#') { url = WH.AjaxUpdateUrl; } $.post(url, data, function () { }) .done(function () { var smsdoneupdate = curren.attr('smsDoneUpdate'); if (typeof smsdoneupdate !== "undefined" && smsdoneupdate !== "") { window[smsdoneupdate](table_id); } }) .fail(function (xhr) { curren.val(oldV); if (xhr.responseText == " ") { return; } var smsfailupdate = curren.attr('smsFailUpdate'); if (typeof smsfailupdate !== "undefined" && smsfailupdate !== "") { window[smsfailupdate](); } if (!curren.hasClass("datetime") && NotviewFalse != true) { if ('NotviewFalse' != xhr.responseText) WH.Loi(xhr.responseText); } }) .always(function () { }); }); }); }; this.AjaxModal = function () { $.each($('[sms-view="ajaxModal"]'), function () { var curren = $(this); var url = curren.attr('data-href'); if (typeof url === "undefined" || url === "" || url === '#') { return; } curren.unbind("click").on('click', function (e) { $MODAL_TITLE.html(''); $MODAL_BT_SUBMIT.unbind("click") .on('click', function () { $MODAL.modal('hide'); }).html("Close"); var target_data = $('.modal-body', $MODAL); var modal_lg = $(curren).attr('Modal-lg'); if (typeof modal_lg !== "undefined" && modal_lg !== "") { $('.modal-dialog', $MODAL).addClass('modal-xl'); } else { $('.modal-dialog', $MODAL).removeClass('modal-xl'); } if (url.startsWith("#")) { target_data.html($(url).html()); $MODAL_TITLE.html($(curren).attr('data-title')); $MODAL_BT_SUBMIT.unbind("click") .on('click', function () { $MAND_CONTENT.show(); $MODAL.modal('hide'); }).html("Close"); WH.ini(); } else { target_data.html(WH.iconloading); $.post(url, function () { }).done(function (data) { target_data.html(data); }) .fail(function (data) { target_data.html(data.responseText); }); } $MODAL.modal({ backdrop: "static" }); e.preventDefault(); } ); }); }; this.SetValueToSelect = function (t,v) { $(t).empty().append($("