/// if (typeof _fleet !== 'object') { _fleet = {}; _fleet.currentLang = "en-us"; Object.defineProperty(_fleet, 'currentMapLang', { get: function () { var lang = (_fleet.currentLang || '').toLowerCase(); switch (lang) { case 'zh-cn': return 'zh-CN'; case 'zh-hk': return 'zh-HK'; case 'zh-tw': return 'zh-TW'; case 'pt-br': return 'pt-BR'; case 'pt': return 'pt-PT'; default: return lang.split('-')[0]; } } }); } // 网络操作类 if (typeof _network !== 'object') { _network = { 'root': '' }; (function () { 'use strict'; // 请求服务器 _network.request = function (url, methodid, method, param, callback, error, nolog, isSync) { //var ajaxTime = new Date().getTime(); $.ajax({ url: _network.root + url, type: 'POST', dataType: 'json', //contentType: 'application/xml;charset=utf-8', cache: false, data: { 'MethodID': methodid, 'MethodName': method, 'ClientData': param, //'RequestID': ajaxTime }, async: !isSync, success: callback, error: function (request, textStatus, errorThrown) { if (error) error(request, textStatus, errorThrown); if (!nolog) { if (request && request.readyState == 0) console.log(request); else writelog_ironintel("_network.request", url + "." + methodid + "." + method + "." + JSON.stringify(param), JSON.stringify(request), textStatus + errorThrown); } } }).done(function () { //var dt2 = new Date().getTime(); //var totalTime = dt2 - ajaxTime; //writelog_ironintel("_network.request", url + "." + method, totalTime + "-" + ajaxTime + "-" + dt2, ajaxTime); }); }; //CommonPage _network.commonpagequery = function (methodid, param, callback, error, nolog, isSync) { //_network.request("commonsvc.ashx", methodid, "", param, callback, error); $.ajax({ url: _network.root + 'commonsvc.ashx', type: 'POST', dataType: 'json', cache: false, data: JSON.stringify({ 'MethodID': methodid, 'ClientData': param }), async: !isSync, success: callback, error: function (request, textStatus, errorThrown) { if (error) error(request, textStatus, errorThrown); if (!nolog) { if (request && request.readyState == 0) console.log(request); else writelog_ironintel("_network.commonpagequery", "commonsvc.ashx" + "." + methodid + "." + JSON.stringify(param), JSON.stringify(request), textStatus + errorThrown); } } }); } // MainPage _network.mainpagequery = function (method, param, callback, error, nolog) { _network.request("IronIntelMain.aspx?tp=ashx", -1, method, param, callback, error, nolog); } _network.apiget = function (url, custid, data, callback, error, nolog) { $.ajax({ url: url, headers: { 'CustId': custid }, type: 'GET', dataType: 'text', //contentType: 'text/plain', cache: false, data: data, async: true, xhrFields: { withCredentials: true }, success: callback, error: function (request, textStatus, errorThrown) { if (error) error(request, textStatus, errorThrown); if (!nolog) { if (request && request.readyState == 0) console.log(request); else writelog_ironintel("_network.apiget", url + "." + JSON.stringify(data), JSON.stringify(request), textStatus + errorThrown); } } }); } _network.apipost = function (url, custid, data, callback, error, nolog) { $.ajax({ url: url, headers: { 'CustId': custid }, type: 'POST', dataType: 'text', contentType: 'text/plain', cache: false, data: typeof data === 'string' ? data : JSON.stringify(data), async: true, xhrFields: { withCredentials: true }, success: callback, error: function (request, textStatus, errorThrown) { if (error) error(request, textStatus, errorThrown); if (!nolog) { if (request && request.readyState == 0) console.log(request); else writelog_ironintel("_network.apiget", url + "." + JSON.stringify(data), JSON.stringify(request), textStatus + errorThrown); } } }); } function getFilterHandlerURL() { if (typeof sitePath !== 'string') return 'fic/SelectAutoFilterHandler.ashx?SN=' + Math.random(); return sitePath + 'fic/SelectAutoFilterHandler.ashx?SN=' + Math.random(); } // 请求服务器 _network.pivotRequest = function (method, param, callback, error, nolog, isSync) { $.ajax({ url: getFilterHandlerURL(), type: 'POST', dataType: 'json', //contentType: 'application/xml;charset=utf-8', cache: false, data: encodeURIComponent(JSON.stringify({ 'LoginIID': loginedUser('userIId'), 'SessionID': '', 'LanguageID': _utility.currentLang, 'UtcOffset': new Date().getTimezoneOffset(), 'Flag': 0, 'AppName': '', 'MethodName': method, 'Parameters': param, 'RequestTime': _utility.getTicksFromDate(new Date()) })), async: !isSync, success: callback, error: function (request, textStatus, errorThrown) { if (error) error(request, textStatus, errorThrown); if (!nolog) { writelog("_network.pivotRequest", textStatus, errorThrown + ""); } //console.log(request); //console.log(textStatus); } }); }; }()); } //websocket if (typeof $websocket !== 'function') { $websocket = function (url) { var _url = url; var socket; var state = 0; var _this = this; this.onreceive = null; var _timer = null; this.connect = function () { if (!_url || !_url.startsWith("ws")) return; if (socket) { socket.onopen = null; socket.onclose = null; socket.onmessage = null socket.onerror = null; if (_timer) { clearInterval(_timer); _timer = null; } } socket = new WebSocket(_url); socket.onopen = onopen; socket.onclose = onclose; socket.onmessage = onmessage socket.onerror = onerror; _timer = setInterval(function () { _this.send(0); }, 120 * 1000); state = 0; } this.disconnect = function () { if (socket) { socket.close(1000, "close"); state = 100;//closed; } } this.send = function (content) { socket.send(content); } function onopen(e) { } function onclose(e) { if (state != 100) { setTimeout(function () { _this.connect(); }, 10000); } } function onmessage(e) { if (_this.onreceive) { var d = JSON.parse(e.data); _this.onreceive(d); } } function onerror(e) { //if (state != 100) { // setTimeout(function () { // _this.connect(); // }, 10000); //} } }; } (function () { 'use strict'; var iX, iY; function dragTitle(ev) { if (ev.target && ev.target.nodeName === 'EM') return; var dialog = ev.data; window.draggingDialog = dialog; var o = getInnerOffset(dialog); iX = ev.clientX - o.left; iY = ev.clientY - o.top; $(document).mousemove(dragmove); $(document).mouseup(dragup); var _this = this; _this.setCapture && _this.setCapture(); var window_width = $(window).width(); var window_height = $(window).height(); var dragging_width = dialog.width(); var dragging_height = dialog.height(); function dragmove(e) { var e = e || window.event; var left, top; left = Math.max(Math.min((e.clientX - iX), window_width - dragging_width - 2), 0); top = Math.max(Math.min((e.clientY - iY), window_height - dragging_height - 2), 0); window.draggingDialog.css({ 'left': left, 'top': top }); }; function dragup(e) { $(document).unbind('mousemove', dragmove); $(document).unbind('mouseup', dragup); delete window.draggingDialog; _this.releaseCapture && _this.releaseCapture(); e.cancelBubble = true; }; return; } $.fn.dialog = function (closefunc, removable) { this.children('.dialog-title').mousedown(this, dragTitle); function onclose(e) { if (removable) { e.data.remove(); } else { e.data.hideDialog(); } if (typeof closefunc === 'function') { closefunc(e); } } this.find('.dialog-close').click(this, onclose); this.find('.form-close').click(this, onclose); this.find('input.dialog-close').keydown(resettab); var _this = this; function resettab(e) { if (e.keyCode == 9) { var input = _this.find("input:not(:disabled),select:not(:disabled)").eq(0); input.focus(); return false; } } return this; }; $.fn.showDialogfixed = function (unfocus) { var top = (document.documentElement.clientHeight - this.height()) / 3; if (top < 0) top = 0; var left = (document.documentElement.clientWidth - this.width()) / 2; if (left < 0) left = 0; this.css({ 'top': top, 'left': left }); this.show(); if (!unfocus) { var input = this.find("input:not(:disabled),select:not(:disabled)").eq(0); input.focus(); } }; $.fn.showDialogAuto = function (maxwidth) { var width = maxwidth; var awidth = document.documentElement.clientWidth * 98 / 100; if (width > awidth) width = awidth; this.css("width", width); var top = (document.documentElement.clientHeight - this.height()) / 3; if (top < 0) top = 0; var left = (document.documentElement.clientWidth - width) / 2; if (left < 0) left = 0; this.css({ 'top': top, 'left': left }); this.show(); var input = this.find("input:not(:disabled),select:not(:disabled)").eq(0); input.focus(); }; $.fn.showDialog = function () { //if (this.maskbg == undefined) { // this.maskbg = $('
'); // this.maskbg.appendTo(document.body); //} //this.maskbg.show(); var top = (document.documentElement.clientHeight - this.height()) / 3; if (top < 0) top = 0; var left = (document.documentElement.clientWidth - this.width()) / 2; if (left < 0) left = 0; this.css({ 'top': top, 'left': left }); var maskheight = this.parent().outerHeight(false); var maskwidth = this.parent().outerWidth(false); if (maskheight > 0) $('#mask_bg').height(maskheight); if (maskwidth > 0) $('#mask_bg').width(maskwidth); if (this.attr("init") !== "1") { this.attr("init", "1"); var _this = this; $(window).resize(function () { _this.height(_this.parent().outerHeight(false) - 64).width(_this.parent().outerWidth(false) - left - 2); $('#mask_bg').height($(document).outerHeight(false) - 64).width($(document).outerWidth(false)); }); } this.show(); var input = this.find("input:not(:disabled),select:not(:disabled)").eq(0); input.focus(); return this; }; $.fn.showDialogRight = function () { //if (this.maskbg == undefined) { // this.maskbg = $('
'); // this.maskbg.appendTo(document.body); //} //this.maskbg.show(); this.css({ 'top': 0, //'bottom': 0, 'left': 0, //'right': 0, 'width': $(document).outerWidth(false) - 2, 'height': $(document).outerHeight(false) }); $('#mask_bg').height($(document).outerHeight(false)).width($(document).outerWidth(false)); if (this.attr("init") !== "1") { this.attr("init", "1"); var _this = this; $(window).resize(function () { _this.height($(document).outerHeight(false)).width($(document).outerWidth(false) - 2); }); } this.show(); var input = this.find("input:not(:disabled),select:not(:disabled)").eq(0); input.focus(); }; $.fn.showDialogRight1 = function (left) { if (!left) left = 100; this.css({ 'top': 0, //'bottom': 0, 'left': left, //'right': 0, 'width': $(document).outerWidth(false) - left - 50, 'height': $(document).outerHeight(false) - 64 }); $('#mask_bg').height($(document).outerHeight(false)).width($(document).outerWidth(false)); if (this.attr("init") !== "1") { this.attr("init", "1"); var _this = this; $(window).resize(function () { _this.height($(document).outerHeight(false) - 64).width($(document).outerWidth(false) - left - 2); $('#mask_bg').height($(document).outerHeight(false) - 64).width($(document).outerWidth(false)); }); } this.show(); var input = this.find("input:not(:disabled),select:not(:disabled)").eq(0); input.focus(); }; $.fn.showDialogRight2 = function () { //if (this.maskbg == undefined) { // this.maskbg = $('
'); // this.maskbg.appendTo(document.body); //} //this.maskbg.show(); this.css({ 'top': 0, //'bottom': 0, 'right': 0, 'width': 800, 'height': $(document).outerHeight(false) }); $('#mask_bg').height($(document).outerHeight(false)).width($(document).outerWidth(false)); if (this.attr("init") !== "1") { this.attr("init", "1"); var _this = this; $(window).resize(function () { _this.height($(document).outerHeight(false)).width($(document).outerWidth(false) - 2); }); } this.show(); var input = this.find("input:not(:disabled),select:not(:disabled)").eq(0); input.focus(); }; $.fn.hideDialog = function () { //if (this.maskbg) { // this.maskbg.hide(); //} this.hide(); }; function clearDropdowns(flag) { var dropdownpanel = $('.dropdown-wrapper .dropdown-panel.active'); dropdownpanel.removeClass('active'); if (flag) { $('.dropdown-panel-sep.active').removeClass('active'); //var activeSeps = $('.dropdown-panel-sep.active'); //if (activeSeps.length > 0) { // activeSeps.removeClass('active'); // //setTimeout(function () { activeSeps.remove(); }, 1000); //} } var dd = dropdownpanel.parent().data('dropdown'); if (dd && dd.multiselect && dd.oncollapsed) dd.oncollapsed(); } $(function () { $(document) .on('mousedown.dropdown', clearDropdowns) .on('mousedown.dropdown', '.dropdown-wrapper .dropdown-panel, .dropdown-panel-sep', function (e) { e.stopPropagation() }); }); var Dropdown = function () { }; function triggerMultiSelect(li) { var textKey = this.textKey; var list; var checkbox = li.children('input'); if (checkbox.attr('isall') == '1') { li.parent().find('input:enabled').prop('checked', this.__isallchecked = checkbox.prop('checked')); list = []; } else { if (checkbox.prop('checked')) { list = Array.prototype.slice.apply(li.parent().find('input.dataitem:checked')).map(function (e) { return $(e).parent().data('item') }); } else { list = this.label.data('selectedlist') || []; var item = li.data('item'); if (this.__isallchecked) { this.__isallchecked = false; li.parent().find('input[isall="1"]').prop('checked', false); for (var i = 0; i < this.source.length; i++) { var it = this.source[i]; if (it != item) { list.push(it); } } } else { for (var i = 0; i < list.length; i++) { if (list[i] == item) { list.splice(i, 1); //break; } } } } } var text = this.__isallchecked ? GetTextByKey('P_GRID_ALL', '(All)') : list.map(function (it) { return it[textKey] }).join(', '); if (text == null || text.trim() == '') { this.label.data('selectedlist', list).html(' '); } else { this.label.data('selectedlist', list).text(text); } if (typeof this.onselectedlist === 'function') { this.onselectedlist(list); } } function fillList(list, source) { list.empty(); var selected = this.label.data('selected'); var selectedlist = this.label.data('selectedlist') || []; var scrolled = null; var valueKey = this.valueKey; var textKey = this.textKey; var enableKey = this.enableKey; var htmlKey = this.htmlKey; var multiselect = this.multiselect; var allowselectall = this.allowselectall !== false; var search = this.search; var This = this; var allchecked = this.__isallchecked; if (multiselect && allowselectall) { // && source == this.source var liall = $('
  • '); list.append(liall.append( $('').prop('checked', allchecked).on('change', function () { triggerMultiSelect.call(This, liall) }), $('').text(GetTextByKey('P_GRID_ALL', '(All)')) )); } for (var i = 0; i < source.length; i++) { if (search && i >= 200) break; var item = source[i]; var li = $('
  • ').data('item', item).attr({ 'value': item[valueKey], 'title': item[textKey] }); if (multiselect) { var lbl; var html = item[htmlKey]; if (html != null) { lbl = $('').html(html); } else { lbl = $('').text(item[textKey]); } var chkbox = $(''); if (item.__selected) chkbox.prop('checked', true); if (item.sublevel > 0) chkbox.css("margin-left", "" + (20 * item.sublevel) + "px"); if (allchecked || selectedlist.filter(function (s) { return s[valueKey] === item[valueKey] }).length > 0) { if (!enableKey || item[enableKey] !== false) chkbox.prop('checked', true); } if (enableKey) { var enable = item[enableKey]; chkbox.prop('disabled', enable === false); } !function (l) { chkbox.on('change', function () { triggerMultiSelect.call(This, l); }); }(li); li.append(chkbox, lbl); } else { var html = item[htmlKey]; if (html != null) { li.html(html); } else { li.text(item[textKey]); } if (selected && selected[valueKey] === item[valueKey]) { scrolled = 30 * i; li.addClass('selected'); } } list.append(li); } if (scrolled != null) { setTimeout(function () { list.scrollTop(scrolled); }, 1); } } Dropdown.prototype.create = function (options) { var This = this; if (options == null) { options = {}; } this.multiselect = options.multiselect; this.allowselectall = options.allowselectall; this.search = options.search; this.parent = options.parent; this.textKey = options.textKey || 'text'; this.valueKey = options.valueKey || 'value'; this.enableKey = options.enableKey; this.htmlKey = options.htmlKey || 'html'; this.searchKeys = options.searchKeys; this.disabled = options.disabled || false; this.maxlength = options.maxlength || 500; this.miniWidth = options.miniWidth || false; this.holder = options.holder; this.searchPlaceholder = options.searchPlaceholder || (GetTextByKey('P_WO_SEARCH', 'Search') + '...'); var container = $(''); container.data('dropdown', this); this.container = container; var header = $(''); if (options.disabled) { header.addClass('disabled'); } header.on('click', function () { if (This.disabled) { return; } var active = This.dropdownContainer != null && This.dropdownContainer.css('visibility') === 'visible'; if (active && This.label.is(':focus')) { return; } This.dropdown(!active); if (!active && typeof This.onexpanded === 'function') { setTimeout(function () { This.onexpanded() }, 120); } }); var label; if (options.input && !this.multiselect) { label = $('').attr('maxlength', this.maxlength) .on('mousedown', function (e) { if (This.dropdownContainer != null && This.dropdownContainer.css('visibility') === 'visible') { e.stopPropagation(); } }) .on('blur', function () { This.select($(this).val(), true); }); } else { label = $('').html(' '); } this.label = label; if (options.selected != null) { this.select(options.selected); } header.append(label); header.append(''); container.append(header); return container; }; Dropdown.prototype.setDisabled = function (flag) { this.disabled = flag; if (flag) { this.container.children('.dropdown-header').addClass('disabled'); } else { this.container.children('.dropdown-header').removeClass('disabled'); } }; Dropdown.prototype.setSource = function (source) { this.source = source; if (this.dropdownContainer != null && this.dropdownContainer.css('visibility') === 'visible') { var This = this; //this.dropdownContainer.removeClass('active'); setTimeout(function () { This.dropdown(true) }, 120); } }; Dropdown.prototype.select = function (selected, blur) { if (blur && this.__lastSelected == selected) { return; } this.__lastSelected = selected; if (this.source == null) { if (typeof this.sourceFilter === 'function') { this.source = this.sourceFilter(true); } if (!$.isArray(this.source)) { return; } } var valueKey = this.valueKey; var textKey = this.textKey; var item = this.source.filter(function (i) { return i[valueKey] == selected })[0]; if (item == null) { if (this.label.is('input')) { item = {}; item[valueKey] = selected; this.label.data('selected', item).val(selected); if (typeof this.onselected === 'function') { this.onselected(item); } } else { this.label.removeData('selected').val('').html(' '); return false; } } else { if (item[textKey] == null || String(item[textKey]).trim() == '') { this.label.data('selected', item).val(item[valueKey]).html(' '); } else { if (this.label.is('input')) this.label.data('selected', item).val(item[textKey]); else this.label.data('selected', item).val(item[valueKey]).text(item[textKey]); } } }; Dropdown.prototype.selectlist = function (selectedlist) { if (this.source == null) { if (typeof this.sourceFilter === 'function') { this.source = this.sourceFilter(true); } if (!$.isArray(this.source)) { return; } } var valueKey = this.valueKey; var textKey = this.textKey; var itemlist = this.source.filter(function (i) { i.__selected = selectedlist.indexOf(i[valueKey]) >= 0; return selectedlist.indexOf(i[valueKey]) >= 0 }); if (itemlist.length == 0) { this.label.removeData('selectedlist').html(' '); return false; } else { var text = itemlist.map(function (it) { return it[textKey] }).join(', '); if (text == null || text.trim() == '') { this.label.data('selectedlist', itemlist).html(' '); } else { this.label.data('selectedlist', itemlist).text(text); } } }; Object.defineProperty(Dropdown.prototype, 'selected', { get: function () { return this.label.data('selected'); } }); Object.defineProperty(Dropdown.prototype, 'selectedlist', { get: function () { return this.label.data('selectedlist') || []; } }) Dropdown.prototype.dropdown = function (flag) { if (flag == null) { flag = true; } var This = this; var textKey = this.textKey; var valueKey = this.valueKey; var enableKey = this.enableKey; var searchKeys = this.searchKeys; if (!searchKeys || searchKeys.length == 0) searchKeys = [textKey]; if (this.dropdownContainer == null) { var panel = $(''); // search box if (this.search) { var search = $(''); var input = $('').attr('placeholder', This.searchPlaceholder); input.on('input', function () { var key = $(this).val().toLowerCase(); var source = This.source; if (source == null) { if (typeof This.sourceFilter === 'function') { source = This.sourceFilter(); } if ($.isArray(source)) { source = []; } This.source = source; } if (key.length > 0) { source = source.filter(function (i) { for (var k = 0; k < searchKeys.length; k++) { var text = i[searchKeys[k]].toLowerCase(); if (i.__selected || text.indexOf(key) >= 0) return true; } return false; }); } fillList.call(This, panel.children('.dropdown-list'), source); }); search.append(input, ''); panel.append(search); } // create list var list = $(''); if (this.multiselect) { list.on('mouseup', function (e) { var t = $(e.target); var li = t; if (t.is('input[type="checkbox"]') || t.is('label')) li = t.parent(); var item = li.data('item'); if (t.is('input[type="checkbox"]')) { if (item) item.__selected = !t.prop('checked'); return; } if (item && enableKey && item[enableKey] === false) { return; } if (li.is('li')) { e.preventDefault(); var checkbox = li.children('input[type="checkbox"]'); var checked = !checkbox.prop('checked'); checkbox.prop('checked', checked); if (checkbox.attr("isall") !== "1") item.__selected = checked; triggerMultiSelect.call(This, li); } }); } else { list.on('click', function (e) { var li = $(e.target); if (li.is('li')) { var item = li.data('item'); clearDropdowns(true); if (item[textKey] == null || String(item[textKey]).trim() == '') { This.label.data('selected', item).val(item[valueKey]).html(' '); } else { if (This.label.is('input')) This.label.data('selected', item).val(item[textKey]); else This.label.data('selected', item).val(item[valueKey]).text(item[textKey]); } if (typeof This.onselected === 'function') { This.onselected(item); } } }); } panel.append(list); this.dropdownContainer = panel; if (this.holder instanceof $) { panel.addClass('dropdown-panel-sep'); this.holder.append(panel); } else { this.container.append(panel); } } var source = this.source; if (typeof this.sourceFilter === 'function') { source = this.sourceFilter(); if (!$.isArray(source)) { source = []; } this.source = source; } fillList.call(this, this.dropdownContainer.children('.dropdown-list'), source); if (flag) { var parent; if (this.parent != null) { parent = this.container.parents(this.parent); } else { parent = $(document.body); } var offset = this.container.offset(); var height = this.dropdownContainer.height(); if (offset.top - parent.offset().top + 28 + height > parent.height()) { this.dropdownContainer.css('margin-top', -height - 29).addClass('slide-up'); } else { this.dropdownContainer.css('margin-top', '').removeClass('slide-up'); } this.dropdownContainer.css('min-width', this.container.width() + 2); if (this.miniWidth) { this.dropdownContainer.css('width', this.container.width() + 2); } if (this.holder != null) { this.dropdownContainer.offset({ 'top': offset.top + 28, 'left': offset.left }); } this.dropdownContainer.addClass('active'); var panel = this.dropdownContainer; setTimeout(function () { panel.children('.dropdown-search').children('input[type="text"]').focus().val("") }, 120); } else { this.dropdownContainer.removeClass('active'); } }; $.fn.dropdown = function (source, opts) { var This = this; var dropdown = new Dropdown(); dropdown.source = source; dropdown.onexpanded = function () { This.trigger('expand'); }; dropdown.oncollapsed = function () { This.trigger('collapsed'); }; dropdown.onselected = function (it) { This.trigger('select', it); }; //dropdown.onselectedlist = function (list) { // This.trigger('select', list); //}; this.data('dropdown', dropdown); this.append(dropdown.create(opts)); return this; }; $.fn.dropdownDisabled = function (flag) { var dropdown = this.data('dropdown'); if (!dropdown) return; dropdown.setDisabled(flag); return this; }; $.fn.dropdownItem = function () { var dropdown = this.data('dropdown'); if (!dropdown) return; var item = dropdown.selected; return item; }; $.fn.dropdownVal = function (value) { var dropdown = this.data('dropdown'); if (!dropdown) return; if (value === void 0) { var item = dropdown.selected; return item && item[dropdown.valueKey]; } var result = dropdown.select(value); if (result === false && value === '') { var it = dropdown.source[0]; dropdown.select(it && it[dropdown.valueKey]); } return this; }; $.fn.dropdownVals = function (list) { var dropdown = this.data('dropdown'); if (!dropdown) return; if (list === void 0) { if (dropdown == null) { return []; } var list = dropdown.selectedlist; return list.map(function (it) { return it[dropdown.valueKey] }); } dropdown.__isallchecked = false; dropdown.selectlist(list); return this; }; $.fn.dropdownTexts = function () { var dropdown = this.data('dropdown'); if (dropdown == null) { return []; } var list = dropdown.selectedlist; return list.map(function (it) { return it[dropdown.textKey] }); }; $.fn.dropdownSource = function (source) { var dropdown = this.data('dropdown'); if (!dropdown) return; dropdown.setSource(source); return this; }; $.fn.allselected = function (checked) { var dropdown = this.data('dropdown'); if (!dropdown) return; if (checked === void 0) { return dropdown.__isallchecked; } dropdown.__isallchecked = checked; dropdown.label.text(GetTextByKey('P_GRID_ALL', '(All)')); //this.find('input[isall="1"]').prop('checked', checked).change(); return this; }; $.fn.allowselectall = function (checked) { var dropdown = this.data('dropdown'); if (!dropdown) return; if (checked === void 0) { return dropdown.allowselectall; } dropdown.allowselectall = checked; return this; }; })(); if (typeof _dialog !== 'object') { _dialog = {}; _dialog.showConfirm = function (msg, title, fyes, fno, fclose, iniframe, shownote) { if (!fclose) fclose = fno; _dialog.showButtonDialog(msg, title, 'question', fclose, [{ value: GetTextByKey("P_UTILITY_NO", 'No'), func: fno }, { value: GetTextByKey("P_UTILITY_YES", 'Yes'), func: fyes }], iniframe, shownote); }; _dialog.showConfirmOKCancel = function (msg, title, fok, fcancel, fclose, iniframe) { if (!fclose) fclose = fcancel; _dialog.showButtonDialog(msg, title, 'question', fclose, [{ value: GetTextByKey("P_UTILITY_CANCEL", 'Cancel'), func: fcancel }, { value: GetTextByKey("P_UTILITY_OK", 'OK'), func: fok }], iniframe); }; _dialog.showConfirmYesNoCancel = function (msg, title, fok, fcancel, fclose, iniframe) { if (!fclose) fclose = fcancel; _dialog.showButtonDialog(msg, title, 'question', fclose, [{ value: GetTextByKey("P_UTILITY_CANCEL", 'Cancel'), func: fclose }, { value: GetTextByKey("P_UTILITY_NO", 'No'), func: fcancel }, { value: GetTextByKey("P_UTILITY_YES", 'Yes'), func: fok }], iniframe); }; _dialog.showButtonDialog = function (msg, title, icon, fno, buttons, iniframe, shownote) { var dialog = $('
    '); dialog.css("position", "fixed"); var title = $('
    ').append([ $('').text(title), $('') ]); title.appendTo(dialog); var dialogText = $('
    ').html(msg); var note; if (shownote) { note = $(''); dialogText.append(note); } var content = $('
    ').append([ $('').addClass(icon), dialogText ]); content.appendTo(dialog); var btns = []; for (var i = 0; i < buttons.length; i++) { if (buttons[i].func == 'dialog-close') { btns.push($('').val(buttons[i].value)); } else { btns.push($('').val(buttons[i].value).click(i, function (e) { dialog.remove(); if (typeof buttons[e.data].func === 'function') { var notes = (note != null) && note.val(); buttons[e.data].func(e, notes); } })); } } btns.push($('
    ')); var func = $('
    ').append(btns); func.appendTo(dialog); dialog.appendTo($(document.body)).show(); if (iniframe) { dialog.prop('iframe', true); } dialog.dialog(fno, true); var top = (document.documentElement.clientHeight - dialog.height()) / 3; if (top < 0) top = 0; var left = (document.documentElement.clientWidth - dialog.width()) / 2; if (left < 0) left = 0; dialog.css({ 'top': top, 'left': left }); }; _dialog.showAlert = function (msg, title, icon, fclose, width, height) { var dialog = $('
    '); dialog.css("position", "fixed"); var title = $('
    ').append([ $('').text(title), $('') ]); title.appendTo(dialog); var dialog_text = $('
    ').html( htmlencode(msg).replace(/\n/g, '
    ').replace(/ /g, '  ')); if (typeof width == 'boolean' && width) { dialog.prop('iframe', true); } else if (!isNaN(width)) { dialog_text.css('min-width', width); } if (!isNaN(height)) { dialog_text.css('min-height', height); } var content = $('
    ').append([ $('').addClass(icon || 'info'), dialog_text ]); content.appendTo(dialog); var func = $('
    ').append([ $(''), $('
    ') ]); func.appendTo(dialog); var maskbg = $('
    ').css('display', 'none'); maskbg.appendTo($(document.body)).fadeIn(100); dialog.appendTo($(document.body)).show(); dialog.maskbg = maskbg; dialog.dialog(function (e) { maskbg.fadeOut(100, function () { $(this).remove(); }); if (typeof fclose === 'function') { fclose(e); } }, true); var top = (document.documentElement.clientHeight - dialog.height()) / 3; if (top < 0) top = 0; var left = (document.documentElement.clientWidth - dialog.width()) / 2; if (left < 0) left = 0; dialog.css({ 'top': top, 'left': left }); return dialog; }; _dialog.close = function (dialog) { if (dialog) { dialog.remove(); if (dialog.maskbg) dialog.maskbg.remove(); } } } function htmlencode(str, ele) { if (ele) { return ele.text(str).html(); } return $('').text(str).html(); } function htmldecode(str, ele) { if (ele) { return ele.html(str).text(); } return $('').html(str).text(); } function replaceHtmlText(text) { if (!text) return ""; if (text.indexOf("&") > -1) { var reg = new RegExp("&", "g"); //创建正则RegExp对象 text = text.replace(reg, "&"); } if (text.indexOf("<") > -1) { var reg = new RegExp("<", "g"); //创建正则RegExp对象 text = text.replace(reg, "<"); } if (text.indexOf(">") > -1) { reg = new RegExp(">", "g"); text = text.replace(reg, ">"); } if (text.indexOf("\r\n") > -1) { reg = new RegExp("\r\n", "g"); text = text.replace(reg, "
    "); } if (text.indexOf("\n") > -1) { reg = new RegExp("\n", "g"); text = text.replace(reg, "
    "); } if (text.indexOf(" ") > -1) { reg = new RegExp(" ", "g"); text = text.replace(reg, "  "); } return text; } // 0-weak, 1-medium, 2-strong function getStrength(val) { if (typeof val !== 'string') { return 0; } if (val.length < 8) { return 0; } var lowers = 0; var uppers = 0; var nums = 0; var others = 0; for (var i = 0; i < val.length; i++) { var c = val[i]; if (c >= 'A' && c <= 'Z') { uppers++; } else if (c >= 'a' && c <= 'z') { lowers++; } else if (c >= '0' && c <= '9') { nums++; } else { others++; } } if (lowers == val.length || uppers == val.length || nums == val.length || others == val.length) { return 0; } else if (lowers + uppers == val.length || lowers + nums == val.length || lowers + others == val.length || uppers + nums == val.length || uppers + others == val.length || nums + others == val.length || uppers == 0 || lowers == 0 || nums == 0) { return 1; } return 2; } function isEmail(val) { //var r = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; var r = /^\w[-\w.+]*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; return r.test(val); } function checkPhoneNumber(num) { if (/^[1-9]\d{9,}$/.test(num)) { return true; } if (/^\+?[1-9][\d-]{9,}\d$/.test(num) && /^[1-9]\d{9,}$/.test(num.replace('+', '').replace(new RegExp('-', 'g'), ''))) { return true; } return false; } function convertDateFormat(dateString) { const date = new Date(dateString); const month = date.getMonth() + 1; //月份是从0开始的 const day = date.getDate(); const year = date.getFullYear(); // 使用两位数表示月份和日期 return `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`; } function getInnerOffset(ele) { // _this.chartDiv.offset().left - (_this.container ? _this.getContainer().offset().left : 0) + _this.getContainer().scrollLeft(); //var offset = ele.offset(); //var obj = ele[0]; //while (obj && obj.offsetParent) { // var j = ele.offsetParent(); // var o = j.offset(); // offset.left -= o.left - j.scrollLeft(); // offset.top -= o.top - j.scrollTop(); // obj = obj.offsetParent; //} //return offset; return { left: ele[0].offsetLeft, top: ele[0].offsetTop }; }; function writelog_ironintel(logtype, source, message, detail) { var s = String.fromCharCode(170); var log = logtype + s + source + s + message + s + detail; var obj = { MethodID: 3, ClientData: log }; var xmlhttp = new XMLHttpRequest(); xmlhttp.open("POST", _network.root + "commonsvc.ashx", true); xmlhttp.send(JSON.stringify(obj)); } function writeexlog(source, err) { var message, detail = ""; if (err) { message = err.message; detail = err.stack; } writelog_ironintel("Error", source, message, detail); } //table排序 function setTableSort(tableid, dosort) { var table = $("#" + tableid); table.find("th").each(function () { var th = $(this); var sortPath = th.attr("sort"); if (sortPath) { var asc = $(""); th.append(asc); var desc = $(""); th.append(desc); th.click(function (e) { if (th.data("sort") == "asc") { th.data("sort", "desc"); table.find(".sorticon").hide(); desc.show(); table.data("sortPath", sortPath).data("desc", true); if (dosort) dosort(sortPath, true); } else { th.data("sort", "asc"); table.find(".sorticon").hide(); asc.show(); table.data("sortPath", sortPath).data("desc", false); if (dosort) dosort(sortPath, false); } }); } }); } //按Table已有的排序状态进行排序,主要用于数据刷新 function sortTableData(tb, data) { var sortPath = tb.data("sortPath"); var desc = tb.data("desc"); if (sortPath) { data.sort(dataSort(sortPath, desc)); } } //按Table已有的排序状态进行排序,主要用于数据刷新 function sortTableSubData(tb, data) { var sortPath = tb.data("sortPath"); var desc = tb.data("desc"); if (sortPath) { data.sort(subDataSort(sortPath, desc)); } } function dataSort(key, desc) { return function (a, b) { var value1 = a[key]; var value2 = b[key]; if (value1 == value2) return 0; if (value1 == null) return desc ? 1 : -1; if (value2 == null) return desc ? -1 : 1; if (typeof (value1) === "string") { value1 = value1.toLowerCase(); value2 = value2.toLowerCase(); } if (value1 < value2) return desc ? 1 : -1; else return desc ? -1 : 1; } } function subDataSort(key, desc) { return function (a, b) { var keys = key.split("."); var value1 = a[keys[0]]; var value2 = b[keys[0]]; for (var i = 1; i < keys.length; i++) { value1 = value1[keys[i]]; value2 = value2[keys[i]]; } if (value1 == value2) return 0; if (value1 == null) return desc ? 1 : -1; if (value2 == null) return desc ? -1 : 1; if (typeof (value1) === "string") { value1 = value1.toLowerCase(); value2 = value2.toLowerCase(); } if (value1 < value2) return desc ? 1 : -1; else return desc ? -1 : 1; } } function resetSort(table) { if (table) table.find(".sorticon").hide(); else $(".sorticon").hide(); } //执行iframe中函数 function execIframeFunc(v_mymethod, v_params, v_frmName) { if (document.getElementById(v_frmName)) { var fn = document.getElementById(v_frmName).contentWindow[v_mymethod]; if (fn) { if (v_params == null) return fn(); else { return fn.apply(this, v_params); } } return null; } } function formatNumber(num) {//千分位显示 if (isNaN(num)) return num; var digits = 0;//小数位数 var parts = num.toString().split('.'); if (parts.length === 2) digits = parts[1].length; var str = num.toFixed(digits) + (digits > 0 ? "" : ".00"); return str.replace(/(\d)(?=(\d{3})+\.)/g, '$1,'); } function isMobile() { var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"]; var userAgentInfo = navigator.userAgent; for (var v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) return true; } return false; } function getAddressLabel(address) { var label; if ((address.Address || '').length > 0) { var txts = []; txts.push(address.Address); //if ((address.Neighborhood || '').length > 0) { // txts.push(address.Neighborhood); //} if (address.City == address.Region) { txts.push(address.City); } else { txts.push(address.City, address.Region); } if ((address.Postal || '').length > 0) { txts.push(address.Postal); } label = txts.join(', '); } else { label = address.Match_addr; } return label; } $.debounce = function throttle(method, delay, context) { delay = void 0 !== delay ? delay : 100; context = void 0 !== context ? context : window; for (var count = arguments.length, args = Array(count > 3 ? count - 3 : 0), i = 3; i < count; i++) { args[i - 3] = arguments[i]; } clearTimeout(method.tiid); method.tiid = setTimeout(function () { method.apply(context, args) }, delay); }; $.throttle = function throttle(method, delay, context) { delay = void 0 !== delay ? delay : 100; context = void 0 !== context ? context : window; for (var count = arguments.length, args = Array(count > 3 ? count - 3 : 0), i = 3; i < count; i++) { args[i - 3] = arguments[i]; } clearTimeout(method.tiid); var current = new Date(); if (method.tdate === void 0 || current - method.tdate > delay) { method.apply(context, args); method.tdate = current; } else { method.tiid = setTimeout(function () { method.apply(context, args) }, delay); } }; function Guid() { 'use strict'; this.date = new Date(); if (typeof this.create != 'function') { Guid.prototype.create = function () { this.date = new Date(); var guidStr = ''; var sexadecimalDate = this.hexadecimal(this.getGUIDDate(), 16); var sexadecimalTime = this.hexadecimal(this.getGUIDTime(), 16); for (var i = 0; i < 9; i++) { guidStr += Math.floor(Math.random() * 16).toString(16); } guidStr += sexadecimalDate; guidStr += sexadecimalTime; while (guidStr.length < 32) { guidStr += Math.floor(Math.random() * 16).toString(16); } return this.formatGUID(guidStr); } Guid.prototype.getGUIDDate = function () { return this.date.getFullYear() + this.addZero(this.date.getMonth() + 1) + this.addZero(this.date.getDay()); } Guid.prototype.getGUIDTime = function () { return this.addZero(this.date.getHours()) + this.addZero(this.date.getMinutes()) + this.addZero(this.date.getSeconds()) + this.addZero(parseInt(this.date.getMilliseconds() / 10)); } Guid.prototype.addZero = function (num) { if (!isNaN(Number(num)) && num >= 0 && num < 10) { // .toString() != 'NaN' return '0' + Math.floor(num); } else { return num.toString(); } } Guid.prototype.hexadecimal = function (num, x, y) { if (y != undefined) { return parseInt(num.toString(), y).toString(x); } else { return parseInt(num.toString()).toString(x); } } Guid.prototype.formatGUID = function (guidStr) { var str1 = guidStr.slice(0, 8) + '-', str2 = guidStr.slice(8, 12) + '-', str3 = guidStr.slice(12, 16) + '-', str4 = guidStr.slice(16, 20) + '-', str5 = guidStr.slice(20); return str1 + str2 + str3 + str4 + str5; } } } $.newGuid = function () { return new Guid().create(); } $.isGuid = function (v) { return /^[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$/.test(v); } $.generateUUID = function () { var d = new Date().getTime(); var d2 = ((typeof performance !== 'undefined') && performance.now && (performance.now() * 1000)) || 0; return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16; if (d > 0) { r = (d + r) % 16 | 0; d = Math.floor(d / 16); } else { r = (d2 + r) % 16 | 0; d2 = Math.floor(d2 / 16); } return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); }); }; function converthtmlurl(msg) { if (msg == null) { return ''; } return msg .replace(//g, '>') .replace(/ /g, ' ') .replace(/(https?|ftp):\/\/[\w-_]+(\.[\w-_]+)+\/?[^\s\r\n"'$]*/g, '$&') .replace(/\r\n/g, '
    ') .replace(/\n/g, '
    '); //const p = /(http|ftp|https):\/\/.+?(\s|\r\n|\r|\n|\"|\'|\*|$)/g; //var r = msg.match(p); //var rs = []; //if (r && r.length > 0) { // for (var i = 0; i < r.length; i++) { // var t = r[i].replace("\"", "").replace("\'", "").replace("\r\n", "").replace("\r", "").replace("\n", "").replace(" ", ""); // if (rs.indexOf(t) < 0) // rs.push(t); // } // for (var i = 0; i < rs.length; i++) { // msg = msg.replaceAll(rs[i], "" + rs[i] + ""); // } //} //if (msg.indexOf("\r\n") > -1) { // reg = new RegExp("\r\n", "g"); // msg = msg.replace(reg, "
    "); //} //if (msg.indexOf("\n") > -1) { // reg = new RegExp("\n", "g"); // msg = msg.replace(reg, "
    "); //} //if (msg.indexOf(" ") > -1) { // reg = new RegExp(" ", "g"); // msg = msg.replace(reg, "  "); //} //return msg; } function formatUrl(msg) { //const urlReg = /(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?/ig; //const urlArrray = str.match(urlReg); const p = /(http|ftp|https):\/\/.+?(\<|\s|\r\n|\r|\n|\"|\'|$)/g; var r = msg.match(p); msg = htmlencode(msg); var rs = []; if (r && r.length > 0) { for (var i = 0; i < r.length; i++) { var t = r[i].replace("\"", "").replace("\'", "").replace("\r\n", "").replace("\r", "").replace("\n", "").replace(" ", "").replace("<", ""); if (rs.indexOf(t) < 0) rs.push(htmlencode(t)); } for (var i = 0; i < rs.length; i++) { msg = msg.replace(new RegExp(rs[i], "g"), "\uf0c1"); } } if (msg.indexOf("\r\n") > -1) { reg = new RegExp("\r\n", "g"); msg = msg.replace(reg, "
    "); } if (msg.indexOf("\n") > -1) { reg = new RegExp("\n", "g"); msg = msg.replace(reg, "
    "); } if (msg.indexOf(" ") > -1) { reg = new RegExp(" ", "g"); msg = msg.replace(reg, "  "); } return msg; } function setPageTitle(title, setparent) { var win = window; if (setparent) { while (win.parent && win != win.parent) win = win.parent; } win.document.title = title; } function setAttachemntIcon(filetype, sdown) { if ([".doc", ".docx"].indexOf(filetype) >= 0) { sdown.attr('src', '../img/icon/word.jpg') } else if ([".xls", ".xlsx"].indexOf(filetype) >= 0) { sdown.attr('src', '../img/icon/excel.jpg') } else if ([".ppt", ".pptx"].indexOf(filetype) >= 0) { sdown.attr('src', '../img/icon/ppt.jpg') } else if ([".pdf", ".xps"].indexOf(filetype) >= 0) { sdown.attr('src', '../img/icon/pdf.jpg') } else if ([".mp4", ".mov", ".avi", ".mkv", ".3gp", ".ts", ".m2ts"].indexOf(filetype) >= 0) { sdown.attr('src', '../img/icon/vedio.jpg') } else if ([".zip", ".rar", ".7z"].indexOf(filetype) >= 0) { sdown.attr('src', '../img/icon/zip.jpg') } else if ([".msg"].indexOf(filetype) >= 0) { sdown.attr('src', '../img/icon/msg.jpg') } else if ([".xml"].indexOf(filetype) >= 0) { sdown.attr('src', '../img/icon/xml.jpg') } else { sdown.attr('src', '../img/icon/txt.jpg') } } function getCurrentDate() { var s = ""; _network.commonpagequery(14, "", function (data) { s = data; }, function (err) { }, true, true); return s; }; function hidePanels() { $('.panel_holder').each(function () { var _this = $(this); if (_this.is(':visible')) { _this.stop().css('opacity', 0).hide(); } }); $('.button button').removeClass('selected'); } function showmaskbg(flag, noanimation) { if (window.parent && typeof window.parent.onmaskbg == 'function') { window.parent.onmaskbg(flag, noanimation); } $('#mask_bg').children().hide(); if (noanimation) { $('#mask_bg').css('display', flag ? '' : 'none'); } else { if (flag) { $('#mask_bg').fadeIn(100); } else { $('#mask_bg').fadeOut(100); } } } function showloading(flag, noanimation) { if (window.parent && typeof window.parent.onmaskbg == 'function') { window.parent.onmaskbg(flag, noanimation); } $('#mask_bg').children().show(); if (noanimation) { $('#mask_bg').css('display', flag ? '' : 'none'); } else { if (flag) { $('#mask_bg').fadeIn(100); } else { $('#mask_bg').fadeOut(100); } } } function showConfirm(msg, title, fok, fcancel) { if (window.parent && typeof window.parent.showconfirm == 'function') { window.parent.showconfirm(msg, title, fok, fcancel); } else { showmaskbg(true); _dialog.showConfirm(msg, title, function (e) { showmaskbg(false); if (typeof fok === 'function') { fok(e); } }, function () { if (fcancel) fcancel(); showmaskbg(false); }); } } function showConfirmYesNoCancel(msg, title, fok, fcancel, fclose) { showmaskbg(true); _dialog.showConfirmYesNoCancel(msg, title, function (e) { showmaskbg(false); if (typeof fok === 'function') { fok(e); } }, function () { if (fcancel) fcancel(); showmaskbg(false); }, function () { if (fclose) fclose(); showmaskbg(false); }); } function showConfirmOKCancel(msg, title, fok, fcancel, fclose) { showmaskbg(true); _dialog.showConfirmOKCancel(msg, title, function (e) { showmaskbg(false); if (typeof fok === 'function') { fok(e); } }, function () { if (fcancel) fcancel(); showmaskbg(false); }, function () { if (fclose) fclose(); showmaskbg(false); }); } function showAlert(msg, title, icon, next) { if (window.parent && typeof window.parent.showalert == 'function') { window.parent.showalert(msg, title, icon, next); } else { if (msg && msg.hasOwnProperty('LGID')) { if (!msg.LGID.startWith('LHBIS_') && !msg.LGID.startWith('FI_HOST_')) { msg.LGID = 'LHBIS_FIC_CLIENT_MODULES_' + msg.LGID; } msg = GetLanguageByKey(msg.LGID, msg.Default); } else if (title === true) { msg = msg.escapeHtml().replace(/\n/g, '
    '); title = undefined; } _dialog.showAlert(msg, title, icon, next); } } function createGridView(parent, fulllang) { var grid = new GridView(parent); grid.langs = getGridLanguages(fulllang); return grid; } function createGridView1(parent, fulllang) { var grid = new GridView1(parent); grid.langs = getGridLanguages(fulllang); return grid; } function getGridLanguages(full) { if (full) { return { all: GetTextByKey("P_GRID_ALL", "(All)"), ok: GetTextByKey("P_GRID_OK", "OK"), reset: GetTextByKey("P_GRID_RESET", "Reset"), null: GetTextByKey("P_GRID_NULL", "(Null)"), // 内置多列排序面板中的资源 sort: GetTextByKey("P_GRID_SORT", "Sort"), addLevel: GetTextByKey("P_GRID_ADDLEVEL", "Add Level"), deleteLevel: GetTextByKey("P_GRID_DELETELEVEL", "Delete Level"), copyLevel: GetTextByKey("P_GRID_COPYLEVEL", "Copy Level"), column: GetTextByKey("P_GRID_COLUMN", "Column"), order: GetTextByKey("P_GRID_ORDER", "Order"), asc: GetTextByKey("P_GRID_ASC", "Ascending"), desc: GetTextByKey("P_GRID_DESC", "Descending"), cancel: GetTextByKey("P_GRID_CANCEL", "Cancel"), duplicatePrompt: GetTextByKey("P_GRID_DUPLICATEPROMPT", "{column} is being sorted more than once. Delete the duplicate sort criteria and try again."), requirePrompt: GetTextByKey("P_GRID_REQUIREPROMPT", "All sort criteria must have a column specified. Check the selected sort criteria and try again.") }; } return { all: GetTextByKey("P_GRID_ALL", "(All)"), ok: GetTextByKey("P_GRID_OK", "OK"), reset: GetTextByKey("P_GRID_RESET", "Reset"), null: GetTextByKey("P_GRID_NULL", "(Null)") }; } function getdaytext(day) { var text = day; switch (day) { case "Sunday": text = GetTextByKey("P_CM_SUNDAY", "Sunday"); break; case "Monday": text = GetTextByKey("P_CM_MONDAY", "Monday"); break; case "Tuesday": text = GetTextByKey("P_CM_TUESDAY", "Tuesday"); break; case "Wednesday": text = GetTextByKey("P_CM_WEDNESDAY", "Wednesday"); break; case "Thursday": text = GetTextByKey("P_CM_THURSDAY", "Thursday"); break; case "Friday": text = GetTextByKey("P_CM_FRIDAY", "Friday"); break; case "Saturday": text = GetTextByKey("P_CM_SATURDAY", "Saturday"); break; } return text; } var libui = window['lib-ui']; if (libui != null) { var CheckboxColumn = Object.create(libui.GridCheckboxColumn, { setValue: { value: function (element, val) { if (element.tagName !== 'LABEL') { element.innerText = val; } else { Object.getPrototypeOf(this).setValue(element, val); } } }, setEnabled: { value: function (element, enabled) { if (element.tagName === 'LABEL') { Object.getPrototypeOf(this).setEnabled(element, enabled); } } }, toString: { value: function () { return 'Checkbox' } } }); var NoteColumn = Object.create(libui.GridColumn, { canEdit: { get: function () { return true } }, create: { value: function (col, index, grid) { var flex = libui.createElement('div', 'cell-flex'); var iconedit = libui.createIcon('fa-light', 'pen'); iconedit.classList.add('cell-flex-icon'); iconedit.style.display = 'none'; flex.append(iconedit, libui.createElement('span', 'cell-flex-memo')); if (!col.readonly) { if (typeof col.onClicked === 'function') { iconedit.addEventListener('click', function () { var item = grid.source[grid.startIndex + index]; col.onClicked.call(col, item, flex); }); } } return flex; } }, getElement: { value: function (element) { return element.children[1]; } }, setValue: { value: function (element, val) { element.children[1].innerHTML = converthtmlurl(val || ''); } }, //getValue: { // value: function (e) { // var label = e.target.querySelector('.cell-flex-memo'); // if (label != null) { // return label.innerText; // } // return e.target.innerText; // } //}, setEditing: { value: function (element, editing) { var icon = element.children[0]; icon.style.display = editing && !icon.disabled ? '' : 'none'; } }, setEnabled: { value: function (element, enabled, editing) { var icon = element.children[0]; icon.disabled = enabled === false; icon.style.display = editing && enabled !== false ? '' : 'none'; } }, toString: { value: function () { return 'Note' } } }); var CommunicationColumn = Object.create(NoteColumn, { create: { value: function (col, index, grid) { var flex = libui.createElement('div', 'cell-flex'); var span = libui.createElement('span', 'cell-flex-icon'); span.style.display = 'none'; span.title = GetTextByKey('P_WO_COMMUNICATIONACKNOWLEDGED', 'Communication Acknowledged'); var iconedit = libui.createIcon('fa-light', 'clipboard-check'); span.appendChild(iconedit); flex.append(span, libui.createElement('span', 'cell-flex-memo')); if (!col.readonly) { if (typeof col.onClicked === 'function') { iconedit.addEventListener('click', function () { var item = grid.source[grid.startIndex + index]; col.onClicked.call(col, item, flex); }); } } return flex; } }, setValue: { value: function (element, val) { element.children[1].innerHTML = window['lib-utility'].escapeEmoji(val || ''); } }, toString: { value: function () { return 'Communication' } } }); var ContactsColumn = Object.create(libui.GridColumn, { create: { value: function () { return libui.createElement('span', 'span-contacts'); } }, setValue: { value: function (element, contacts) { element.innerText = contacts.join('\n'); } }, toString: { value: function () { return 'Contacts' } } }); var ThumbnailUrlColumn = Object.create(libui.GridColumn, { create: { value: function () { return libui.createElement('img', ''); } }, setValue: { value: function (element, val, vals, col) { var filetype = vals.values.FileType; var sdown = $(element); if (imgTypes.indexOf(vals.values.FileType.toLowerCase()) >= 0) { sdown.css('width', 30).css('height', 30).css('vertical-align', 'middle'); sdown.attr('src', vals.values.ThumbnailUrl); } else { sdown.css('width', 30).css('height', 30).css('line-height', 40).css('vertical-align', 'middle');; if ([".doc", ".docx"].indexOf(filetype) >= 0) { sdown.attr('src', '../img/icon/word.jpg') } else if ([".xls", ".xlsx"].indexOf(filetype) >= 0) { sdown.attr('src', '../img/icon/excel.jpg') } else if ([".ppt", ".pptx"].indexOf(filetype) >= 0) { sdown.attr('src', '../img/icon/ppt.jpg') } else if ([".pdf", ".xps"].indexOf(filetype) >= 0) { sdown.attr('src', '../img/icon/pdf.jpg') } else if ([".mp4", ".mov", ".avi", ".mkv", ".3gp", ".ts", ".m2ts"].indexOf(filetype) >= 0) { sdown.attr('src', '../img/icon/vedio.jpg') } else if ([".zip", ".rar", ".7z"].indexOf(filetype) >= 0) { sdown.attr('src', '../img/icon/zip.jpg') } else if ([".msg"].indexOf(filetype) >= 0) { sdown.attr('src', '../img/icon/msg.jpg') } else if ([".xml"].indexOf(filetype) >= 0) { sdown.attr('src', '../img/icon/xml.jpg') } else { sdown.attr('src', '../img/icon/txt.jpg') } } } }, toString: { value: function () { return 'Thumbnail' } } }); var SchedulesColumn = Object.create(libui.GridColumn, { createCaption: { value: function () { if (!assetsObj?.HasSchedule) { return; } var container = $('').css({ position: 'relative', height: 26, width: '100%', display: 'block' }); var left = 0; for (var i = 0; i < assetsObj.Labels.length; i++) { var label = assetsObj.Labels[i]; var sp = $('').text(label.Key).css({ left: left }); left += parseInt(label.Value) * 5; container.append(sp); } //grid_dt.resize(); //var totalDays = (led.getTime() - fbd.getTime()) / (1000 * 60 * 60 * 24); //var interval = parseInt(totalDays / labelCount); //if (totalDays % labelCount != 0) // interval += 1; //var d = new Date(assetsObj.BeginDate); //var w = col.width / labelCount; //for (var i = 0; i < labelCount; i++) { // var label = new DateFormatter().formatDate(d, 'm/d/Y'); // var sp = $('').text(label).css({ left: w * i }); // container.append(sp); // d = new Date(d.getTime() + interval * 1000 * 60 * 60 * 24); //} return container[0]; } }, create: { value: function () { var container = document.createElement('div'); container.style.cssText = 'position: relative; height: 20px'; return container; } }, setValue: { value: function (element, _val, row, col) { element.replaceChildren(); var item = row.values; if (item.ScheduleParts && assetsObj?.HasSchedule) { var labelCount = 4; var totalDays = assetsObj.TotalDays; var interval = parseInt(totalDays / labelCount); if (totalDays % labelCount != 0) { interval += 1; } totalDays = interval * labelCount; var d = new Date(assetsObj.BeginDate); for (var i = 0; i < item.ScheduleParts.length; i++) { var sp = item.ScheduleParts[i]; var bdate = new Date(sp.BeginDate); var edate = new Date(sp.EndDate); var l = (bdate.getTime() - d.getTime()) / (1000 * 60 * 60 * 24) / totalDays * col.width; var w = (edate.getTime() - bdate.getTime()) / (1000 * 60 * 60 * 24) / totalDays * col.width; var color = ""; if (sp.Schedules.length == 1) { color = sp.Schedules[0].Color; } else { for (var j = 0; j < sp.Schedules.length; j++) { if (color !== "") color += "," color += sp.Schedules[j].Color; } } var df = new DateFormatter(); var title = df.formatDate(bdate, 'm/d/Y') + " - " + df.formatDate(new Date((edate.getTime() - 1000 * 60 * 60 * 24)), 'm/d/Y') + "\n"; for (var j = 0; j < sp.Schedules.length; j++) { var bd = new Date(sp.Schedules[j].BeginDate); var ed = new Date(sp.Schedules[j].EndDate); title += sp.Schedules[j].JobSiteName + ": " + df.formatDate(bd, 'm/d/Y') + " - " + df.formatDate(ed, 'm/d/Y'); if (sp.Schedules[j].PointOfContact) title += "\n " + GetTextByKey("P_JS_CONTACT_COLON", "Contact: ") + " " + sp.Schedules[j].PointOfContact; if (sp.Schedules[j].Creator) title += "\n " + GetTextByKey("P_JS_CREATOR_COLON", "Creator: ") + " " + sp.Schedules[j].Creator; if (j != sp.Schedules.length - 1) title += "\n"; } var bar = libui.createElement('span', 'span-bar'); bar.style.cssText = 'left: ' + l + 'px; width: ' + Math.max(1, w - 1) + 'px; border-left: 1px solid transparent'; if (sp.Schedules.length == 1) { bar.style.backgroundColor = color; } else { //bar.css("background", "url(img/gridline.jpg) repeat 20px 20px"); //bar.css("background", "linear-gradient(45deg," + color + ")"); //bar.css("background-image", "repeating-linear-gradient(45deg,white, white 5px,#ff9900 5px,#ff9900 7px)"); //bar.css("background-image", "repeating-linear-gradient(135deg,blue 1px, transparent 0), repeating-linear-gradient(45deg, red 1px, transparent 0)"); //bar.css("background-size", "5px 5px"); //bar.css("background-image", "url(\"data:image/svg+xml,\")"); bar.style.backgroundImage = "url(\"data:image/svg+xml,\")"; } bar.title = title; if (!IsReadOnly && typeof col.onScheduleClicked === 'function') { bar.addEventListener('dblclick', (function (sp) { return col.onScheduleClicked.bind(col, item, sp) })(sp)); } element.append(bar); } } } }, toString: { value: function () { return 'Schedules' } } }); var DispatchSchedulesColumn = Object.create(SchedulesColumn, { createCaption: { value: function (col) { if (!dispatchAssetsObj?.HasSchedule) { return; } var labelCount = 4; var totalDays = dispatchAssetsObj.TotalDays; var interval = parseInt(totalDays / labelCount); if (totalDays % labelCount != 0) { interval += 1; } var container = $('').css({ position: 'relative', height: 26, width: '100%', display: 'block' }); var d = new Date(dispatchAssetsObj.BeginDate); var w = col.width / labelCount; for (var i = 0; i < labelCount; i++) { var label = new DateFormatter().formatDate(d, 'm/d/Y'); var sp = $('').text(label).css({ left: w * i }); container.append(sp); d = new Date(d.getTime() + interval * 1000 * 60 * 60 * 24); } return container[0]; } }, setValue: { value: function (element, _val, row, col) { element.replaceChildren(); var item = row.values; if (item.ScheduleParts && dispatchAssetsObj?.HasSchedule) { var labelCount = 4; var totalDays = dispatchAssetsObj.TotalDays; var interval = parseInt(totalDays / labelCount); if (totalDays % labelCount != 0) { interval += 1; } totalDays = interval * labelCount; var d = new Date(dispatchAssetsObj.BeginDate); for (var i = 0; i < item.ScheduleParts.length; i++) { var sp = item.ScheduleParts[i]; var bdate = new Date(sp.BeginDate); var edate = new Date(sp.EndDate); var l = (bdate.getTime() - d.getTime()) / (1000 * 60 * 60 * 24) / totalDays * col.width; if (l < i + 1) { l = i + 1; } var w = (edate.getTime() - bdate.getTime()) / (1000 * 60 * 60 * 24) / totalDays * col.width; if (w < 1) { w = 1; } var color = ""; if (sp.Schedules.length == 1) { color = sp.Schedules[0].Color; } else { for (var j = 0; j < sp.Schedules.length; j++) { if (color !== "") color += "," color += sp.Schedules[j].Color; } } var title = ""; var df = new DateFormatter(); for (var j = 0; j < sp.Schedules.length; j++) { var bd = new Date(sp.Schedules[j].BeginDate); var ed = new Date(sp.Schedules[j].EndDate); title += sp.Schedules[j].JobSiteName + ": " + df.formatDate(bd, 'm/d/Y') + " - " + df.formatDate(ed, 'm/d/Y'); if (j != sp.Schedules.length - 1) { title += "\n"; } } var bar = libui.createElement('span', 'span-bar'); bar.style.cssText = 'left: ' + l + 'px; width: ' + w + 'px'; if (sp.Schedules.length == 1) { bar.style.backgroundColor = color; } else { bar.style.backgroundImage = "url(\"data:image/svg+xml,\")"; } bar.title = title; element.append(bar); } } } }, toString: { value: function () { return 'DispatchSchedules' } } }); }