diff --git a/core/nuajax.js b/core/nuajax.js index b49b23a..d582599 100644 --- a/core/nuajax.js +++ b/core/nuajax.js @@ -1,822 +1,699 @@ -function nuAjax(w, successCallback, errorCallback) { - - // Serialize data - const data = JSON.stringify(nuAddEditFieldsToHash(w)); - - // Send AJAX request - $.ajax({ - async: true, - dataType: "json", - url: "core/nuapi.php", - method: "POST", - data: { - nuSTATE: data - }, - success: (data, textStatus, jqXHR) => successCallback(data, textStatus, jqXHR), - error: (jqXHR, textStatus, errorThrown) => { - // Call error callback if defined - if (errorCallback) { - errorCallback(jqXHR, textStatus, errorThrown); - } - - nuAjaxShowError(jqXHR, errorThrown); - - }, - complete: (jqXHR, textStatus) => { - // Do something when the request completes - }, - }); +function nuAjax (w, successCallback, errorCallback) { + // Serialize data + const data = JSON.stringify(nuAddEditFieldsToHash(w)) + + // Send AJAX request + $.ajax({ + async: true, + dataType: 'json', + url: 'core/nuapi.php', + method: 'POST', + data: { + nuSTATE: data + }, + success: (data, textStatus, jqXHR) => successCallback(data, textStatus, jqXHR), + error: (jqXHR, textStatus, errorThrown) => { + // Call error callback if defined + if (errorCallback) { + errorCallback(jqXHR, textStatus, errorThrown) + } + + nuAjaxShowError(jqXHR, errorThrown) + }, + complete: (jqXHR, textStatus) => { + // Do something when the request completes + } + }) } -function nuAjaxShowError() { - - // Format error message and display it - const err = nuFormatAjaxErrorMessage(jqXHR, errorThrown); - let msgDiv; - if (nuHasHiddenModalDragDialog()) { - msgDiv = parent.nuMessage(err); - nuClosePopup(); - } else { - msgDiv = nuMessage(err); - } - if (window.nuOnMessage) { - nuOnMessage(msgDiv, err); - } - +function nuAjaxShowError () { + // Format error message and display it + const err = nuFormatAjaxErrorMessage(jqXHR, errorThrown) + let msgDiv + if (nuHasHiddenModalDragDialog()) { + msgDiv = parent.nuMessage(err) + nuClosePopup() + } else { + msgDiv = nuMessage(err) + } + if (window.nuOnMessage) { + nuOnMessage(msgDiv, err) + } } -function nuHasHiddenModalDragDialog() { - return parent.$('#nuModal').length > 0 && parent.$('#nuModal').siblings(".nuDragDialog").css("visibility") == "hidden"; +function nuHasHiddenModalDragDialog () { + return parent.$('#nuModal').length > 0 && parent.$('#nuModal').siblings('.nuDragDialog').css('visibility') == 'hidden' } -function nuForm(f, r, filter, search, n, like) { - - if (n == 2) { - - window.nuNEW = 1; - search = ''; - - } - - if (like == undefined) { - like = ''; - } else { - like = nuDecode(like); - } - - if (nuOpenNewBrowserTab('getform', f, r, filter)) { return; } - - if (n != 1) { //-- add a new breadcrumb - window.nuFORM.addBreadcrumb(); - } - - var current = window.nuFORM.getCurrent(); - current.search = search; - - if (current.filter == '') { - - if (filter != '') { - current.filter = filter; - } else { +function nuForm (f, r, filter, search, n, like) { + if (n == 2) { + window.nuNEW = 1 + search = '' + } - if (window.nuFILTER != '') { - current.filter = window.nuFILTER; - } + if (like == undefined) { + like = '' + } else { + like = nuDecode(like) + } - } + if (nuOpenNewBrowserTab('getform', f, r, filter)) { return } - } + if (n != 1) { // -- add a new breadcrumb + window.nuFORM.addBreadcrumb() + } - var last = $.extend(true, {}, current); + const current = window.nuFORM.getCurrent() + current.search = search - last.call_type = 'getform'; - last.form_id = f; - last.record_id = r; - last.filter = filter == '' ? window.nuFILTER : filter; - last.search = search; + if (current.filter == '') { + if (filter != '') { + current.filter = filter + } else { + if (window.nuFILTER != '') { + current.filter = window.nuFILTER + } + } + } - if (parent['nuHashFromEditForm'] === undefined) { - last.hash = []; - } else { - last.hash = parent.nuHashFromEditForm(); - } + const last = $.extend(true, {}, current) - last.AAA = 'hw'; - last.like = like; + last.call_type = 'getform' + last.form_id = f + last.record_id = r + last.filter = filter == '' ? window.nuFILTER : filter + last.search = search - var successCallback = function (data, textStatus, jqXHR) { + if (parent.nuHashFromEditForm === undefined) { + last.hash = [] + } else { + last.hash = parent.nuHashFromEditForm() + } - var fm = data; + last.AAA = 'hw' + last.like = like - if (nuDisplayError(fm)) { + const successCallback = function (data, textStatus, jqXHR) { + const fm = data - nuCursor('default'); + if (nuDisplayError(fm)) { + nuCursor('default') - parent.$('#nuModal').remove(); + parent.$('#nuModal').remove() - if (parent.$('#nuDragDialog').css('visibility') == 'hidden') { - parent.nuDisplayError(fm); - parent.$('#nuDragDialog').remove(); - } + if (parent.$('#nuDragDialog').css('visibility') == 'hidden') { + parent.nuDisplayError(fm) + parent.$('#nuDragDialog').remove() + } - nuFORM.breadcrumbs.pop(); + nuFORM.breadcrumbs.pop() - if (fm.log_again == 1) { location.reload(); } + if (fm.log_again == 1) { location.reload() } + } else { + const last = window.nuFORM.getCurrent() + last.record_id = fm.record_id + last.FORM = fm.form - } else { - - var last = window.nuFORM.getCurrent(); - last.record_id = fm.record_id; - last.FORM = fm.form; - - nuBuildForm(fm); - - } - }; - - nuAjax(last, successCallback); + nuBuildForm(fm) + } + } + nuAjax(last, successCallback) } - -function nuGetReport(formId, recordId) { - - if (nuOpenNewBrowserTab('getreport', formId, recordId, '')) { - return; - } - - let last = window.nuFORM.addBreadcrumb(); - last.session_id = window.nuSESSION; - last.call_type = 'getreport'; - last.form_id = formId; - last.record_id = recordId; - last.hash = parent.nuHashFromEditForm ? parent.nuHashFromEditForm() : []; - - let successCallback = function (data) { - if (!nuDisplayError(data)) { - nuBuildForm(data); - } - }; - - nuAjax(last, successCallback); - +function nuGetReport (formId, recordId) { + if (nuOpenNewBrowserTab('getreport', formId, recordId, '')) { + return + } + + const last = window.nuFORM.addBreadcrumb() + last.session_id = window.nuSESSION + last.call_type = 'getreport' + last.form_id = formId + last.record_id = recordId + last.hash = parent.nuHashFromEditForm ? parent.nuHashFromEditForm() : [] + + const successCallback = function (data) { + if (!nuDisplayError(data)) { + nuBuildForm(data) + } + } + + nuAjax(last, successCallback) } -function nuRunReport(formId, iFrame) { +function nuRunReport (formId, iFrame) { + const current = nuFORM.getCurrent() + const last = $.extend(true, {}, current) - const current = nuFORM.getCurrent(); - let last = $.extend(true, {}, current); + last.session_id = window.nuSESSION + last.call_type = 'runreport' + last.form_id = formId + last.hash = parent.nuHashFromEditForm ? parent.nuHashFromEditForm() : [] - last.session_id = window.nuSESSION; - last.call_type = 'runreport'; - last.form_id = formId; - last.hash = parent.nuHashFromEditForm ? parent.nuHashFromEditForm() : []; + const successCallback = function (data, textStatus, jqXHR) { + if (!nuDisplayError(data)) { + const pdfUrl = 'core/nurunpdf.php?i=' + data.id - const successCallback = function (data, textStatus, jqXHR) { - - if (!nuDisplayError(data)) { - - const pdfUrl = 'core/nurunpdf.php?i=' + data.id; - - if (iFrame === undefined) { - window.open(pdfUrl); - } else { - parent.$('#' + iFrame).attr('src', pdfUrl); - } - - } - - }; - - nuAjax(last, successCallback); + if (iFrame === undefined) { + window.open(pdfUrl) + } else { + parent.$('#' + iFrame).attr('src', pdfUrl) + } + } + } + nuAjax(last, successCallback) } -function nuRunReportSave(formId, tag = null, callback = null) { - - const current = nuFORM.getCurrent(); - const last = $.extend(true, {}, current); - - last.session_id = window.nuSESSION; - last.call_type = 'runreport'; - last.form_id = formId; - last.hash = nuHashFromEditForm(); - - const successCallback = function (data, textStatus, jqXHR) { - - const fm = data; - - if (!nuDisplayError(fm)) { - - let formData = new FormData(); - formData.append('ID', fm.id); - formData.append('tag', tag); - let xhr = new XMLHttpRequest(); - - if (callback !== null) { - xhr.onreadystatechange = function () { - if (this.readyState == 4 && this.status == 200) { - const data = JSON.parse(xhr.responseText); - callback(data.filename, data.id, this); - } - } - } - - xhr.open('POST', 'core/nurunpdf.php', true); - xhr.send(formData); - - } - - }; - - nuAjax(last, successCallback); - +function nuRunReportSave (formId, tag = null, callback = null) { + const current = nuFORM.getCurrent() + const last = $.extend(true, {}, current) + + last.session_id = window.nuSESSION + last.call_type = 'runreport' + last.form_id = formId + last.hash = nuHashFromEditForm() + + const successCallback = function (data, textStatus, jqXHR) { + const fm = data + + if (!nuDisplayError(fm)) { + const formData = new FormData() + formData.append('ID', fm.id) + formData.append('tag', tag) + const xhr = new XMLHttpRequest() + + if (callback !== null) { + xhr.onreadystatechange = function () { + if (this.readyState == 4 && this.status == 200) { + const data = JSON.parse(xhr.responseText) + callback(data.filename, data.id, this) + } + } + } + + xhr.open('POST', 'core/nurunpdf.php', true) + xhr.send(formData) + } + } + + nuAjax(last, successCallback) } -function nuAskLogout() { - - if (nuFormsUnsaved() > 0) { - if (!confirm(nuTranslate('There are unsaved changes. Do you really want to leave the page?'))) return; - } - - nuLogout(); +function nuAskLogout () { + if (nuFormsUnsaved() > 0) { + if (!confirm(nuTranslate('There are unsaved changes. Do you really want to leave the page?'))) return + } + nuLogout() } -function nuLogout() { - - const winTop = window.top; - winTop.nuFORM.addBreadcrumb(); - - const last = winTop.nuFORM.getCurrent(); - last.session_id = window.nuSESSION; - last.call_type = 'logout'; - - const successCallback = function (data, textStatus, jqXHR) { - - if (!nuDisplayError(data)) { - sessionStorage.removeItem('nukeepalive'); - winTop.window.open('index.php', '_self'); - } +function nuLogout () { + const winTop = window.top + winTop.nuFORM.addBreadcrumb() - }; + const last = winTop.nuFORM.getCurrent() + last.session_id = window.nuSESSION + last.call_type = 'logout' - nuAjax(last, successCallback); + const successCallback = function (data, textStatus, jqXHR) { + if (!nuDisplayError(data)) { + sessionStorage.removeItem('nukeepalive') + winTop.window.open('index.php', '_self') + } + } + nuAjax(last, successCallback) } -function nuGetPHP(formId, recordId) { - - if (nuOpenNewBrowserTab('getphp', formId, recordId, '')) { - return; - } - - window.nuFORM.addBreadcrumb(); - - const current = nuFORM.getCurrent(); - let last = $.extend(true, {}, current); - - last.session_id = window.nuSESSION; - last.call_type = 'getphp'; - last.form_id = formId; - last.record_id = recordId; - - if (parent['nuHashFromEditForm'] === undefined) { - last.hash = []; - } else { - last.hash = parent.nuHashFromEditForm(); - } - - const successCallback = function (data) { - - if (!nuDisplayError(data)) { - nuFORM.setProperty('record_id', data.record_id); - nuBuildForm(data); - } else { - window.nuFORM.breadcrumbs.pop(); - } - }; - - nuAjax(last, successCallback); - +function nuGetPHP (formId, recordId) { + if (nuOpenNewBrowserTab('getphp', formId, recordId, '')) { + return + } + + window.nuFORM.addBreadcrumb() + + const current = nuFORM.getCurrent() + const last = $.extend(true, {}, current) + + last.session_id = window.nuSESSION + last.call_type = 'getphp' + last.form_id = formId + last.record_id = recordId + + if (parent.nuHashFromEditForm === undefined) { + last.hash = [] + } else { + last.hash = parent.nuHashFromEditForm() + } + + const successCallback = function (data) { + if (!nuDisplayError(data)) { + nuFORM.setProperty('record_id', data.record_id) + nuBuildForm(data) + } else { + window.nuFORM.breadcrumbs.pop() + } + } + + nuAjax(last, successCallback) } -function nuRunPHP(code, iFrame, runBeforeSave) { - - if (!runBeforeSave) { - if (nuBeforeSave && nuBeforeSave() === false) { - return; - } - } - - const current = nuFORM.getCurrent(); - let last = $.extend(true, {}, current); - - last.session_id = nuSESSION; - last.call_type = 'runphp'; - last.form_id = code; - last.nuFORMdata = nuFORM.data(); - - if (nuFORM.getCurrent() === undefined) { - last.record_id = parent.nuFORM.getCurrent().record_id; - last.hash = parent['nuHashFromEditForm'] === undefined ? [] : parent.nuHashFromEditForm(); - } else { - last.record_id = nuFORM.getCurrent().record_id; - last.hash = nuHashFromEditForm(); - } - - const successCallback = function (data, textStatus, jqXHR) { - - if (!nuDisplayError(data)) { - - const pdfUrl = `core/nurunphp.php?i=${fm.id}`; - - if (!iFrame) { - window.open(pdfUrl); - } else { - parent.$('#' + iFrame).attr('src', pdfUrl); - } - - } - - }; - - nuAjax(last, successCallback); - +function nuRunPHP (code, iFrame, runBeforeSave) { + if (!runBeforeSave) { + if (nuBeforeSave && nuBeforeSave() === false) { + return + } + } + + const current = nuFORM.getCurrent() + const last = $.extend(true, {}, current) + + last.session_id = nuSESSION + last.call_type = 'runphp' + last.form_id = code + last.nuFORMdata = nuFORM.data() + + if (nuFORM.getCurrent() === undefined) { + last.record_id = parent.nuFORM.getCurrent().record_id + last.hash = parent.nuHashFromEditForm === undefined ? [] : parent.nuHashFromEditForm() + } else { + last.record_id = nuFORM.getCurrent().record_id + last.hash = nuHashFromEditForm() + } + + const successCallback = function (data, textStatus, jqXHR) { + if (!nuDisplayError(data)) { + const pdfUrl = `core/nurunphp.php?i=${fm.id}` + + if (!iFrame) { + window.open(pdfUrl) + } else { + parent.$('#' + iFrame).attr('src', pdfUrl) + } + } + } + + nuAjax(last, successCallback) } +function nuRunPHPHidden (code, rbs, params) { + if (arguments.length == 1) { + if (window.nuBeforeSave) { + if (nuBeforeSave() === false) { return } + } + } -function nuRunPHPHidden(code, rbs, params) { - - if (arguments.length == 1) { - - if (window.nuBeforeSave) { - if (nuBeforeSave() === false) { return; } - } - - } - - var current = nuFORM.getCurrent(); - var last = $.extend(true, {}, current); + const current = nuFORM.getCurrent() + const last = $.extend(true, {}, current) - last.session_id = window.nuSESSION; - last.call_type = 'runhiddenphp'; - last.form_id = 'doesntmatter'; - last.params = params ? params: null; - last.hash_record_id = last.record_id; - last.record_id = code; //-- php code - last.nuFORMdata = nuFORM.data(); - last.hash = nuHashFromEditForm(); + last.session_id = window.nuSESSION + last.call_type = 'runhiddenphp' + last.form_id = 'doesntmatter' + last.params = params || null + last.hash_record_id = last.record_id + last.record_id = code // -- php code + last.nuFORMdata = nuFORM.data() + last.hash = nuHashFromEditForm() - var successCallback = function (data, textStatus, jqXHR) { + const successCallback = function (data, textStatus, jqXHR) { + const fm = data - var fm = data; + if (nuDisplayError(fm)) { return }; - if (nuDisplayError(fm)) { return; }; - - window.nuSERVERRESPONSE_HIDDEN = fm; - eval(fm.callback + ';'); - - }; - - nuAjax(last, successCallback); + window.nuSERVERRESPONSE_HIDDEN = fm + eval(fm.callback + ';') + } + nuAjax(last, successCallback) } -function nuRunPHPHiddenWithParams(code, paramName, paramValue, rbs) { - nuSetProperty(paramName, btoa(JSON.stringify(paramValue))); - nuRunPHPHidden(code, rbs); +function nuRunPHPHiddenWithParams (code, paramName, paramValue, rbs) { + nuSetProperty(paramName, btoa(JSON.stringify(paramValue))) + nuRunPHPHidden(code, rbs) } -function nuSystemUpdate() { - - var msg = nuTranslate("Update system? Be sure to backup first."); - if (confirm(msg) == false) { return; } - - if (nuCurrentProperties().form_code == 'nuupdate') { - var myWindow = window.open("", "_self"); - myWindow.document.write(nuTranslate('This tab can be closed after the update.') + '
' + nuTranslate('You will need to log in again for the changes to take effect.')); - } - - var current = nuFORM.getCurrent(); - var last = $.extend(true, {}, current); - - last.session_id = nuSESSION; - last.call_type = 'systemupdate'; - last.form_id = 'systemupdate'; - last.nuFORMdata = nuFORM.data(); - last.hash = nuHashFromEditForm(); - - var successCallback = function (data, textStatus, jqXHR) { - - var fm = data; +function nuSystemUpdate () { + const msg = nuTranslate('Update system? Be sure to backup first.') + if (confirm(msg) == false) { return } - if (!nuDisplayError(fm)) { + if (nuCurrentProperties().form_code == 'nuupdate') { + const myWindow = window.open('', '_self') + myWindow.document.write(nuTranslate('This tab can be closed after the update.') + '
' + nuTranslate('You will need to log in again for the changes to take effect.')) + } - var updateUrl = 'core/nusystemupdate.php?i=' + fm.id; - window.open(updateUrl); + const current = nuFORM.getCurrent() + const last = $.extend(true, {}, current) - } + last.session_id = nuSESSION + last.call_type = 'systemupdate' + last.form_id = 'systemupdate' + last.nuFORMdata = nuFORM.data() + last.hash = nuHashFromEditForm() - }; + const successCallback = function (data, textStatus, jqXHR) { + const fm = data - nuAjax(last, successCallback); + if (!nuDisplayError(fm)) { + const updateUrl = 'core/nusystemupdate.php?i=' + fm.id + window.open(updateUrl) + } + } + nuAjax(last, successCallback) } -function nuAttachImage(i, code, fit) { +function nuAttachImage (i, code, fit) { + code = String(code).toLowerCase() + const imgID = 'image_' + i + const w = $('#' + i).css('width') + const h = $('#' + i).css('height') - code = String(code).toLowerCase(); - var imgID = 'image_' + i; - var w = $('#' + i).css('width'); - var h = $('#' + i).css('height'); + const size = fit === false ? '' : ' width="' + w + '" height="' + h + $('#' + i).html('') - let size = fit === false ? '' : ' width="' + w + '" height="' + h; - $('#' + i).html(''); + if (window.nuGraphics.indexOf(code + '.png') != -1) { // -- check filenames in graphics dir. + $('#' + imgID).attr('src', 'core/graphics/' + code + '.png') - if (window.nuGraphics.indexOf(code + '.png') != -1) { //-- check filenames in graphics dir. + return + } - $('#' + imgID).attr('src', "core/graphics/" + code + ".png"); + const PARENT = parent.parent.parent.parent.parent.parent.parent.parent.parent - return; + if (PARENT.nuImages[code] !== undefined) { + const p = JSON.parse(PARENT.nuImages[code]) + const b = atob(p.file) - } + $('#' + imgID).attr('src', b) - var PARENT = parent.parent.parent.parent.parent.parent.parent.parent.parent; + return + } - if (PARENT.nuImages[code] !== undefined) { + const current = nuFORM.getCurrent() + const last = $.extend(true, {}, current) - const p = JSON.parse(PARENT.nuImages[code]); - const b = atob(p.file); + last.session_id = window.nuSESSION + last.call_type = 'getfile' + last.fileCode = code - $('#' + imgID).attr('src', b); + const successCallback = function (data, textStatus, jqXHR) { + if (nuDisplayError(data)) { return }; - return; + if (data.JSONfile !== null) { + PARENT.nuImages[code] = data.JSONfile + const p = JSON.parse(PARENT.nuImages[code]) + const b = atob(p.file) - } - - const current = nuFORM.getCurrent(); - let last = $.extend(true, {}, current); - - last.session_id = window.nuSESSION; - last.call_type = 'getfile'; - last.fileCode = code; - - var successCallback = function (data, textStatus, jqXHR) { - - if (nuDisplayError(data)) { return; }; - - if (data.JSONfile !== null) { - - PARENT.nuImages[code] = data.JSONfile; - const p = JSON.parse(PARENT.nuImages[code]); - const b = atob(p.file); - - $('#' + imgID).attr('src', b) - - } - - }; - - nuAjax(last, successCallback); + $('#' + imgID).attr('src', b) + } + } + nuAjax(last, successCallback) } -function nuAttachButtonImage(i, c, cssClass = 'nuButtonImage') { - - c = String(c).toLowerCase(); - - if (window.nuGraphics.indexOf(c + '.png') != -1) { //-- check filenames in graphics dir. - - $('#' + i) - .css({ 'background-image': 'url("core/graphics/' + c + '.png', 'background-position': '3px 0' }) - .addClass(cssClass); - - return; - - } - - var PARENT = parent.parent.parent.parent.parent.parent.parent.parent.parent; - - var pi = PARENT.nuImages !== undefined ? PARENT.nuImages[c] : ''; - - if (pi !== undefined && pi !== '') { - - var p = JSON.parse(pi); - var b = atob(p.file); - - $('#' + i) - .css('background-image', 'url("' + b + '")') - .addClass(cssClass); +function nuAttachButtonImage (i, c, cssClass = 'nuButtonImage') { + c = String(c).toLowerCase() - return; + if (window.nuGraphics.indexOf(c + '.png') != -1) { // -- check filenames in graphics dir. + $('#' + i) + .css({ 'background-image': 'url("core/graphics/' + c + '.png', 'background-position': '3px 0' }) + .addClass(cssClass) - } + return + } - var current = nuFORM.getCurrent(); - var last = $.extend(true, {}, current); + const PARENT = parent.parent.parent.parent.parent.parent.parent.parent.parent - last.session_id = window.nuSESSION; - last.call_type = 'getfile'; - last.fileCode = c; + const pi = PARENT.nuImages !== undefined ? PARENT.nuImages[c] : '' - var successCallback = function (data, textStatus, jqXHR) { + if (pi !== undefined && pi !== '') { + const p = JSON.parse(pi) + const b = atob(p.file) - if (nuDisplayError(data)) { return; }; + $('#' + i) + .css('background-image', 'url("' + b + '")') + .addClass(cssClass) - if (data.JSONfile !== null) { + return + } - PARENT.nuImages[c] = data.JSONfile; - const p = JSON.parse(pi); - const b = atob(p.file); + const current = nuFORM.getCurrent() + const last = $.extend(true, {}, current) - $('#' + i) - .css('background-image', 'url("' + b + '")') - .addClass(cssClass); + last.session_id = window.nuSESSION + last.call_type = 'getfile' + last.fileCode = c - } + const successCallback = function (data, textStatus, jqXHR) { + if (nuDisplayError(data)) { return }; - }; + if (data.JSONfile !== null) { + PARENT.nuImages[c] = data.JSONfile + const p = JSON.parse(pi) + const b = atob(p.file) - nuAjax(last, successCallback); + $('#' + i) + .css('background-image', 'url("' + b + '")') + .addClass(cssClass) + } + } + nuAjax(last, successCallback) } +function nuGetLookupId (pk, id, setFocus, setEdited) { + if (window.nuLOOKUPCLEARING) return -function nuGetLookupId(pk, id, setFocus, setEdited) { + $('#nuLookupList').remove() - if (window.nuLOOKUPCLEARING) return; + const l = $('#' + id) - $('#nuLookupList').remove(); + const last = nuFORM.getCurrent() - var l = $('#' + id); + last.session_id = nuSESSION + last.call_type = 'getlookupid' + last.object_id = l.attr('data-nu-object-id') + last.target = l.attr('data-nu-target') + last.prefix = l.attr('data-nu-prefix') + last.primary_key = pk - var last = nuFORM.getCurrent(); + const successCallback = function (data, textStatus, jqXHR) { + nuSERVERRESPONSELU = data - last.session_id = nuSESSION; - last.call_type = 'getlookupid'; - last.object_id = l.attr('data-nu-object-id'); - last.target = l.attr('data-nu-target'); - last.prefix = l.attr('data-nu-prefix'); - last.primary_key = pk; + nuCursor('default') - var successCallback = function (data, textStatus, jqXHR) { + if (!nuDisplayError(data)) { + nuPopulateLookup(data, id, setFocus) + $('#' + id).addClass('nuEdited') - nuSERVERRESPONSELU = data; + if (setEdited != false) { + nuHasBeenEdited() + } - nuCursor('default'); + const o = $('#' + id) - if (!nuDisplayError(data)) { + if (o.attr('data-nu-prefix') == '') { return } - nuPopulateLookup(data, id, setFocus); - $('#' + id).addClass('nuEdited'); - - if (setEdited != false) { - nuHasBeenEdited(); - } - - var o = $('#' + id); - - if (o.attr('data-nu-prefix') == '') { return; } - - nuAddSubformRow(o[0], false); - - } - - }; - - nuAjax(last, successCallback); + nuAddSubformRow(o[0], false) + } + } + nuAjax(last, successCallback) } -function nuGetLookupCode(event) { - - const nuTarget = event.target.getAttribute('data-nu-target'); - - if (event.currentTarget && event.currentTarget.value.length == 0) { - window.nuLOOKUPCLEARING = true; - $('#' + nuTarget).addClass('nuEdited'); - nuSetValue(nuTarget, ''); - nuSetValue(nuTarget + 'description', ''); - window.nuLOOKUPCLEARING = false; - return; - } - - let last = window.nuFORM.getCurrent(); - - last.session_id = window.nuSESSION; - last.call_type = 'getlookupcode'; - last.object_id = event.target.getAttribute('data-nu-object-id'); - last.target = nuTarget; - last.code = event.target.value; - last.hash = nuHashFromEditForm(); +function nuGetLookupCode (event) { + const nuTarget = event.target.getAttribute('data-nu-target') - window.nuLOOKUPSTATE[last.object_id] = 'looking'; + if (event.currentTarget && event.currentTarget.value.length == 0) { + window.nuLOOKUPCLEARING = true + $('#' + nuTarget).addClass('nuEdited') + nuSetValue(nuTarget, '') + nuSetValue(nuTarget + 'description', '') + window.nuLOOKUPCLEARING = false + return + } - const successCallback = function (data) { + const last = window.nuFORM.getCurrent() - nuSERVERRESPONSELU = data; + last.session_id = window.nuSESSION + last.call_type = 'getlookupcode' + last.object_id = event.target.getAttribute('data-nu-object-id') + last.target = nuTarget + last.code = event.target.value + last.hash = nuHashFromEditForm() - if (!nuDisplayError(data)) { - nuChooseOneLookupRecord(event, data); - } + window.nuLOOKUPSTATE[last.object_id] = 'looking' - }; + const successCallback = function (data) { + nuSERVERRESPONSELU = data - nuAjax(last, successCallback); + if (!nuDisplayError(data)) { + nuChooseOneLookupRecord(event, data) + } + } + nuAjax(last, successCallback) } +function nuPrintAction () { + const last = window.nuFORM.getCurrent() -function nuPrintAction() { - - let last = window.nuFORM.getCurrent(); - - last.call_type = 'runhtml'; - last.browse_columns = nuSERVERRESPONSE.browse_columns; - last.browse_sql = nuSERVERRESPONSE.browse_sql; - last.session_id = window.nuSESSION; - - const successCallback = function (data, textStatus, jqXHR) { + last.call_type = 'runhtml' + last.browse_columns = nuSERVERRESPONSE.browse_columns + last.browse_sql = nuSERVERRESPONSE.browse_sql + last.session_id = window.nuSESSION - if (!nuDisplayError(data)) { - var p = 'core/nurunhtml.php?i=' + data.id; - window.open(p); - } - - }; - - nuAjax(last, successCallback); + const successCallback = function (data, textStatus, jqXHR) { + if (!nuDisplayError(data)) { + const p = 'core/nurunhtml.php?i=' + data.id + window.open(p) + } + } + nuAjax(last, successCallback) } -function nuUpdateData(action, instruction, close) { - - if (action == 'save') { - - if (window.nuBeforeSaveGlobal) { - if (nuBeforeSaveGlobal() === false) { - return; - } - } - - if (window.nuBeforeSave) { - if (nuBeforeSave() === false) { - return; - } - } - - } - - if (action != 'save' && window.nuBeforeDelete) { - if (nuBeforeDelete() === false) { - $('#nuDelete').prop('checked', false); - return; - } - } - - if (action == 'save') { - // nuSavingProgressMessage(); - nuSaveEditor(); - } - - if (nuFORM.getCurrent().record_id == -1) { nuSetProperty('NEW_RECORD', 1); } - - const current = window.nuFORM.getCurrent(); - let last = $.extend(true, {}, current); - - const formId = last.form_id; - window.nuLASTRECORD = last.record_id; - - if (instruction !== undefined) { - last.instruction = instruction; - } - - last.call_type = 'update'; - last.deleteAll = $('#nuDelete').is(":checked") ? 'Yes' : 'No'; - last.nuFORMdata = nuFORM.data(action); - last.hash = nuHashFromEditForm(); - last.session_id = window.nuSESSION; - - $('.nuActionButton').hide(); - - const successCallback = function (data, textStatus, jqXHR) { - - if (nuDisplayError(data)) { - - $('.nuActionButton').show(); - nuAbortSave(); - - } else { - - if (data.after_event) { - nuMESSAGES = data.errors; - } - - if ($('#nuDelete').prop('checked')) { - - if (action == "delete" && instruction == "all" && data.record_id == "") { - - nuSearchAction(); - nuGetBreadcrumb(); - return; - - } - - window.nuFORM.removeLast(); //-- return to browse - if ($('.nuBreadcrumb').length == 0) { - window.close(); - } else { - nuGetBreadcrumb(); - } - - if (nuCurrentProperties() == undefined) { - - parent.$('#nuModal').remove(); - parent.$('#nuDragDialog').remove(); - - } - - nuUpdateMessage('Record Deleted'); - - if (window.nuAfterDeleteGlobal) { - nuAfterDeleteGlobal(); - } - - if (window.nuAfterDelete) { - nuAfterDelete(); - } - - } else { - - nuForm(formId, data.record_id, data.filter, data.search, 1); //-- go to saved or created record - nuUpdateMessage('Record Saved'); - - if (instruction === 'close') { - nuFORM.edited = false; - nuOpenPreviousBreadcrumb(); - } - } - - } - }; - - nuAjax(last, successCallback, nuAbortSave); - +function nuUpdateData (action, instruction, close) { + if (action == 'save') { + if (window.nuBeforeSaveGlobal) { + if (nuBeforeSaveGlobal() === false) { + return + } + } + + if (window.nuBeforeSave) { + if (nuBeforeSave() === false) { + return + } + } + } + + if (action != 'save' && window.nuBeforeDelete) { + if (nuBeforeDelete() === false) { + $('#nuDelete').prop('checked', false) + return + } + } + + if (action == 'save') { + // nuSavingProgressMessage(); + nuSaveEditor() + } + + if (nuFORM.getCurrent().record_id == -1) { nuSetProperty('NEW_RECORD', 1) } + + const current = window.nuFORM.getCurrent() + const last = $.extend(true, {}, current) + + const formId = last.form_id + window.nuLASTRECORD = last.record_id + + if (instruction !== undefined) { + last.instruction = instruction + } + + last.call_type = 'update' + last.deleteAll = $('#nuDelete').is(':checked') ? 'Yes' : 'No' + last.nuFORMdata = nuFORM.data(action) + last.hash = nuHashFromEditForm() + last.session_id = window.nuSESSION + + $('.nuActionButton').hide() + + const successCallback = function (data, textStatus, jqXHR) { + if (nuDisplayError(data)) { + $('.nuActionButton').show() + nuAbortSave() + } else { + if (data.after_event) { + nuMESSAGES = data.errors + } + + if ($('#nuDelete').prop('checked')) { + if (action == 'delete' && instruction == 'all' && data.record_id == '') { + nuSearchAction() + nuGetBreadcrumb() + return + } + + window.nuFORM.removeLast() // -- return to browse + if ($('.nuBreadcrumb').length == 0) { + window.close() + } else { + nuGetBreadcrumb() + } + + if (nuCurrentProperties() == undefined) { + parent.$('#nuModal').remove() + parent.$('#nuDragDialog').remove() + } + + nuUpdateMessage('Record Deleted') + + if (window.nuAfterDeleteGlobal) { + nuAfterDeleteGlobal() + } + + if (window.nuAfterDelete) { + nuAfterDelete() + } + } else { + nuForm(formId, data.record_id, data.filter, data.search, 1) // -- go to saved or created record + nuUpdateMessage('Record Saved') + + if (instruction === 'close') { + nuFORM.edited = false + nuOpenPreviousBreadcrumb() + } + } + } + } + + nuAjax(last, successCallback, nuAbortSave) } -function nuSaveAfterDrag() { - - const contentWin = getNuDragDialogIframes[0].contentWindow; - let last = contentWin.nuFORM.getCurrent(); - - last.call_type = 'nudragsave'; - last.nuDragState = contentWin.nuDragOptionsState; +function nuSaveAfterDrag () { + const contentWin = getNuDragDialogIframes[0].contentWindow + const last = contentWin.nuFORM.getCurrent() - const successCallback = function (data, textStatus, jqXHR) { + last.call_type = 'nudragsave' + last.nuDragState = contentWin.nuDragOptionsState - if (nuDisplayError(data.errors)) { - alert(data.errors[0]); - } else { + const successCallback = function (data, textStatus, jqXHR) { + if (nuDisplayError(data.errors)) { + alert(data.errors[0]) + } else { + $('div#nuDragDialog div#dialogTitle img#dialogClose').click() + nuGetBreadcrumb() + } - $('div#nuDragDialog div#dialogTitle img#dialogClose').click(); - nuGetBreadcrumb(); - - } - - $("#overlay").remove(); - }; - - nuAjax(last, successCallback, nuAbortSaveDrag); + $('#overlay').remove() + } + nuAjax(last, successCallback, nuAbortSaveDrag) } -function nuOpenNewBrowserTab(type, formId, recordId, filter) { - - if (window.nuNEW == 1) { - - window.nuNEW = 0; - window.nuOPENER.push(new nuOpener('F', formId, recordId, filter)); +function nuOpenNewBrowserTab (type, formId, recordId, filter) { + if (window.nuNEW == 1) { + window.nuNEW = 0 + window.nuOPENER.push(new nuOpener('F', formId, recordId, filter)) - nuOpenerAppend('type', type); + nuOpenerAppend('type', type) - const len = window.nuOPENER.length - 1; - const openerId = window.nuOPENER[len].id; - const url = `${window.location.origin}${window.location.pathname}?i=${len}&opener=${openerId}`; + const len = window.nuOPENER.length - 1 + const openerId = window.nuOPENER[len].id + const url = `${window.location.origin}${window.location.pathname}?i=${len}&opener=${openerId}` - window.open(url); + window.open(url) - return true; - - } - - return false; + return true + } + return false } -function nuAbortSave() { - - $("#nuProgressUpdate").hide(); - $('.nuActionButton').show(); - +function nuAbortSave () { + $('#nuProgressUpdate').hide() + $('.nuActionButton').show() } diff --git a/core/nucommon.js b/core/nucommon.js index 94ce0b7..a2f7976 100644 --- a/core/nucommon.js +++ b/core/nucommon.js @@ -1,451 +1,417 @@ -window.nuDialog = new nuCreateDialog(''); -window.nuFORM = new nuFormObject(); -window.nuRESPONSIVE = new nuResponseForm(); -window.nuOnLoad = null; -window.nuBeforeSaveGlobal = null; -window.nuLoadBrowseGlobal = null; -window.nuLoadEditGlobal = null; -window.nuOnLookupPopulatedGlobal = null; -window.nuOnPopupOpenedGlobal = null; -window.nuHideMessage = true; -window.nuDragID = 1000; -window.nuLastForm = ''; -window.nuNEW = ''; -window.nuColor = ''; -window.nuImage = ''; -window.nuSESSION = ''; -window.nuDRAGLINEVSTART = ''; -window.nuDRAGLINEVID = ''; -window.nuLASTRECORD = ''; -window.nuMESSAGES = []; -window.nuSAVED = true; -window.nuImages = []; -window.nuOPENER = []; -window.nuSUBFORMROW = []; -window.nuSUBFORMJSON = []; -window.nuSCHEMA = []; -window.nuLANGUAGE = []; -window.nuFIELD = []; -window.nuHASH = []; -window.nuBEFORE = []; -window.nuAFTER = []; +window.nuDialog = new nuCreateDialog('') +window.nuFORM = new nuFormObject() +window.nuRESPONSIVE = new nuResponseForm() +window.nuOnLoad = null +window.nuBeforeSaveGlobal = null +window.nuLoadBrowseGlobal = null +window.nuLoadEditGlobal = null +window.nuOnLookupPopulatedGlobal = null +window.nuOnPopupOpenedGlobal = null +window.nuHideMessage = true +window.nuDragID = 1000 +window.nuLastForm = '' +window.nuNEW = '' +window.nuColor = '' +window.nuImage = '' +window.nuSESSION = '' +window.nuDRAGLINEVSTART = '' +window.nuDRAGLINEVID = '' +window.nuLASTRECORD = '' +window.nuMESSAGES = [] +window.nuSAVED = true +window.nuImages = [] +window.nuOPENER = [] +window.nuSUBFORMROW = [] +window.nuSUBFORMJSON = [] +window.nuSCHEMA = [] +window.nuLANGUAGE = [] +window.nuFIELD = [] +window.nuHASH = [] +window.nuBEFORE = [] +window.nuAFTER = [] window.nuBROWSERESIZE = { - x_position: 0, - mouse_down: false, - moving_element: '', - pointer: '', - current_cell_width: 0, - next_cell_left: 0, - array_current_cell_left: '', - last_moved_element: '' -}; - - -String.prototype.nuEndsWith = function(substr, ignoreCase) { - - if (ignoreCase === undefined || ignoreCase === false) return this.endsWith(substr); - return this.toLowerCase().endsWith(substr.toLowerCase()); - + x_position: 0, + mouse_down: false, + moving_element: '', + pointer: '', + current_cell_width: 0, + next_cell_left: 0, + array_current_cell_left: '', + last_moved_element: '' } -String.prototype.nuStartsWith = function(substr, ignoreCase) { - - if (ignoreCase === undefined || ignoreCase === false) return this.startsWith(substr); - return this.toLowerCase().startsWith(substr.toLowerCase()); +String.prototype.nuEndsWith = function (substr, ignoreCase) { + if (ignoreCase === undefined || ignoreCase === false) return this.endsWith(substr) + return this.toLowerCase().endsWith(substr.toLowerCase()) +} +String.prototype.nuStartsWith = function (substr, ignoreCase) { + if (ignoreCase === undefined || ignoreCase === false) return this.startsWith(substr) + return this.toLowerCase().startsWith(substr.toLowerCase()) } String.prototype.nuReplaceAll = function (str1, str2, ignore) { - return this.replace(new RegExp(str1.replace(/([\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g, function (c) { return "\\" + c; }), "g" + (ignore ? "i" : "")), str2); -}; + return this.replace(new RegExp(str1.replace(/([\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g, function (c) { return '\\' + c }), 'g' + (ignore ? 'i' : '')), str2) +} String.prototype.ltrim = function () { - return this.replace(/^\s+/, ""); + return this.replace(/^\s+/, '') } String.prototype.rtrim = function () { - return this.replace(/\s+$/, ""); + return this.replace(/\s+$/, '') } String.prototype.containsAny = String.prototype.containsAny || function (arr) { - - for (var i = 0; i < arr.length; i++) { - if (this.indexOf(arr[i]) > -1) { - return true; - } - } - return false; - -}; + for (let i = 0; i < arr.length; i++) { + if (this.indexOf(arr[i]) > -1) { + return true + } + } + return false +} String.prototype.fixNbsp = function () { - return this.replace(/\xA0/g, " ") + return this.replace(/\xA0/g, ' ') } String.prototype.capitalise = function () { - return this.charAt(0).toUpperCase() + this.slice(1); + return this.charAt(0).toUpperCase() + this.slice(1) } String.prototype.toTitleCase = function () { - return this.toLowerCase().replace(/^(\w)|\s(\w)/g, (grp) => grp.toUpperCase()); + return this.toLowerCase().replace(/^(\w)|\s(\w)/g, (grp) => grp.toUpperCase()) } String.prototype.justNumbers = function () { - return this.replace(/[^0-9]/g, ''); + return this.replace(/[^0-9]/g, '') } String.prototype.withoutNumbers = function () { - return this.replace(/\d+/g, ''); + return this.replace(/\d+/g, '') } String.prototype.nuInsertString = function (index, string) { + if (index > 0) { + return this.substring(0, index) + string + this.substr(index) + } - if (index > 0) { - return this.substring(0, index) + string + this.substr(index); - } - - return string + this; - -}; + return string + this +} String.prototype.isEmpty = function () { - return (this === null || this.length === 0); + return (this === null || this.length === 0) } Date.prototype.withoutTime = function () { - var d = new Date(this); - d.setHours(0, 0, 0, 0); - return d; + const d = new Date(this) + d.setHours(0, 0, 0, 0) + return d } Date.prototype.addDays = function (days) { - var date = new Date(this.valueOf()); - date.setDate(date.getDate() + days); - return date; + const date = new Date(this.valueOf()) + date.setDate(date.getDate() + days) + return date } String.prototype.nuFormat = function () { - var args; - args = arguments; - if (args.length === 1 && args[0] !== null && typeof args[0] === 'object') { - args = args[0]; - } - return this.replace(/{([^}]*)}/g, function (match, key) { - return (typeof args[key] !== "undefined" ? args[key] : match); - }); -}; + let args + args = arguments + if (args.length === 1 && args[0] !== null && typeof args[0] === 'object') { + args = args[0] + } + return this.replace(/{([^}]*)}/g, function (match, key) { + return (typeof args[key] !== 'undefined' ? args[key] : match) + }) +} // Examples: // "This is an example from {name}".format({name:"Blaine"}); // "This is an example from {0}".format("Blaine"); $.fn.enterKey = function (fnc) { - return this.each(function () { - $(this).keypress(function (e) { - if (e.key == 'Enter') { - fnc.call(this, e); - } - }) - }) + return this.each(function () { + $(this).keypress(function (e) { + if (e.key == 'Enter') { + fnc.call(this, e) + } + }) + }) } $.fn.nuFocusWithoutScrolling = function () { + const t = $(this)[0] + const x = t.scrollX; const y = t.scrollY - let t = $(this)[0]; - let x = t.scrollX, y = t.scrollY; - - this.focus(); - t.scrollTo(x, y); - return this; - -}; - -jQuery.fn.extend({ - nuEnable: function (enable) { - return this.each(function () { - nuEnable(this.id, enable); - }); - }, - nuDisable: function () { - return this.each(function () { - nuDisable(this.id); - }); - }, - nuShow: function (visible, openTab) { - return this.each(function () { - nuShow(this.id, visible, openTab); - }); - }, - nuHide: function () { - return this.each(function () { - nuHide(this.id); - }); - }, - nuRemove: function () { - return this.each(function () { - nuRemove(this.id); - }); - }, - nuSelectRemoveEmpty: function (setIndex) { - return this.each(function () { - nuSelectRemoveEmpty(this.id, setIndex); - }); - }, - nuGetValue: function (method) { - return nuGetValue(this.attr('id'), method); - }, - nuSetValue: function (v, method, change) { - return this.each(function () { - return nuSetValue(this.id, v, method, change); - }); - }, - nuGetText: function () { - return nuGetValue(this.attr('id'), 'text'); - }, - nuSetText: function (v) { - return this.each(function () { - return nuSetValue(this.id, v, 'text'); - }); - }, - nuTranslate: function (method) { - return this.each(function () { - nuSetValue(this.id, nuTranslate(nuGetValue(this.id, method)), method); - }); - }, - nuRemoveFormatting: function () { - return nuFORM.removeFormatting($(this).val(), $(this).attr('data-nu-format')); - }, - nuIsVisible: function () { - return nuIsVisible(this.attr('id')); - }, - nuIsHidden: function () { - return nuIsHidden(this.attr('id')); - }, - nuIsDisabled: function () { - return nuIsDisabled(this.attr('id')); - }, - nuIsEnabled: function () { - return nuIsEnabled(this.attr('id')); - }, - nuSetPlaceholder: function(placeholder, translate) { - return nuSetPlaceholder(this.attr('id'), placeholder, translate); - }, - nuTogglePassword: function(show) { - return this.each(function() { - let $input = $(this); - let type = $input.attr('type') === 'password' ? 'text' : 'password'; - if (show !== undefined) { - type = show ? 'text' : 'password'; - } - $input.attr('type', type); - }); - } - -}); - -function nuPad4(i) { - return nuPad(i, 4); -} - -function nuPad3(i) { - return nuPad(i, 3); -} - -function nuPad2(i) { - return nuPad(i, 2); -} - -function nuPad(i, length, pad) { - - if (typeof (pad) == "undefined") { var pad = 0; } - return i.toString().padStart(length, pad).toString(); - -} - -function nuGlobalAccess() { - return window.global_access; + this.focus() + t.scrollTo(x, y) + return this } -function loginInputKeyup(event) { - if (event.key == 'Enter') { - $('input#submit').click(); - } -} - -function nuOpener(t, f, r, filter, parameters) { - - nuSetSuffix(); - - this.id = String(Date.now()) + String(window.nuSuffix); - this.form_id = f; - this.record_id = r; - this.type = t; - - this.filter = nuDefine(filter); - this.parameters = nuDefine(parameters); - -} - -function nuOpenerAppend(t, k) { - window.nuOPENER[window.nuOPENER.length - 1][t] = k; -} - -function nuGetOpenerById(pOPENER, pid) { - - for (var i = 0; i < pOPENER.length; i++) { - if (pOPENER[i].id == pid) { - return pOPENER[i]; - } - } - - return; -} - -function nuRemoveOpenerById(o, pid) { - - for (var i = 0; i < o.length; i++) { - - if (o[i].id == pid) { - o.splice(i, 1); - } - - } - +jQuery.fn.extend({ + nuEnable: function (enable) { + return this.each(function () { + nuEnable(this.id, enable) + }) + }, + nuDisable: function () { + return this.each(function () { + nuDisable(this.id) + }) + }, + nuShow: function (visible, openTab) { + return this.each(function () { + nuShow(this.id, visible, openTab) + }) + }, + nuHide: function () { + return this.each(function () { + nuHide(this.id) + }) + }, + nuRemove: function () { + return this.each(function () { + nuRemove(this.id) + }) + }, + nuSelectRemoveEmpty: function (setIndex) { + return this.each(function () { + nuSelectRemoveEmpty(this.id, setIndex) + }) + }, + nuGetValue: function (method) { + return nuGetValue(this.attr('id'), method) + }, + nuSetValue: function (v, method, change) { + return this.each(function () { + return nuSetValue(this.id, v, method, change) + }) + }, + nuGetText: function () { + return nuGetValue(this.attr('id'), 'text') + }, + nuSetText: function (v) { + return this.each(function () { + return nuSetValue(this.id, v, 'text') + }) + }, + nuTranslate: function (method) { + return this.each(function () { + nuSetValue(this.id, nuTranslate(nuGetValue(this.id, method)), method) + }) + }, + nuRemoveFormatting: function () { + return nuFORM.removeFormatting($(this).val(), $(this).attr('data-nu-format')) + }, + nuIsVisible: function () { + return nuIsVisible(this.attr('id')) + }, + nuIsHidden: function () { + return nuIsHidden(this.attr('id')) + }, + nuIsDisabled: function () { + return nuIsDisabled(this.attr('id')) + }, + nuIsEnabled: function () { + return nuIsEnabled(this.attr('id')) + }, + nuSetPlaceholder: function (placeholder, translate) { + return nuSetPlaceholder(this.attr('id'), placeholder, translate) + }, + nuTogglePassword: function (show) { + return this.each(function () { + const $input = $(this) + let type = $input.attr('type') === 'password' ? 'text' : 'password' + if (show !== undefined) { + type = show ? 'text' : 'password' + } + $input.attr('type', type) + }) + } + +}) + +function nuPad4 (i) { + return nuPad(i, 4) +} + +function nuPad3 (i) { + return nuPad(i, 3) +} + +function nuPad2 (i) { + return nuPad(i, 2) +} + +function nuPad (i, length, pad) { + if (typeof (pad) === 'undefined') { var pad = 0 } + return i.toString().padStart(length, pad).toString() +} + +function nuGlobalAccess () { + return window.global_access +} + +function loginInputKeyup (event) { + if (event.key == 'Enter') { + $('input#submit').click() + } +} + +function nuOpener (t, f, r, filter, parameters) { + nuSetSuffix() + + this.id = String(Date.now()) + String(window.nuSuffix) + this.form_id = f + this.record_id = r + this.type = t + + this.filter = nuDefine(filter) + this.parameters = nuDefine(parameters) +} + +function nuOpenerAppend (t, k) { + window.nuOPENER[window.nuOPENER.length - 1][t] = k +} + +function nuGetOpenerById (pOPENER, pid) { + for (let i = 0; i < pOPENER.length; i++) { + if (pOPENER[i].id == pid) { + return pOPENER[i] + } + } +} + +function nuRemoveOpenerById (o, pid) { + for (let i = 0; i < o.length; i++) { + if (o[i].id == pid) { + o.splice(i, 1) + } + } } -function nuGetBreadcrumb(bc) { - - if (window.nuOnBeforeGetBreadcrumb) { - if (nuOnBeforeGetBreadcrumb(bc) == false) return; - } - - nuCursor('progress'); - - var a = arguments.length; - var e = nuFORM.edited; - - if (a == 0) { - var b = nuFORM.breadcrumbs.length - 1; - } else { - var b = bc; - } +function nuGetBreadcrumb (bc) { + if (window.nuOnBeforeGetBreadcrumb) { + if (nuOnBeforeGetBreadcrumb(bc) == false) return + } - window.nuTimesSaved = -1; + nuCursor('progress') - if (e && nuFORM.getCurrent().form_type != 'launch') { + const a = arguments.length + const e = nuFORM.edited - if (!confirm(nuTranslate('Leave this form without saving?'))) { - nuCursor('default'); - return; - } + if (a == 0) { + var b = nuFORM.breadcrumbs.length - 1 + } else { + var b = bc + } - } + window.nuTimesSaved = -1 - window.nuFORM.removeAfter(b); + if (e && nuFORM.getCurrent().form_type != 'launch') { + if (!confirm(nuTranslate('Leave this form without saving?'))) { + nuCursor('default') + return + } + } - var c = window.nuFORM.getCurrent(); - - if (c === undefined) { - getNuDragDialogIframes().remove(); - } else { - nuForm(c.form_id, c.record_id, c.filter, c.search, 1); - } + window.nuFORM.removeAfter(b) + const c = window.nuFORM.getCurrent() + if (c === undefined) { + getNuDragDialogIframes().remove() + } else { + nuForm(c.form_id, c.record_id, c.filter, c.search, 1) + } } -function nuOpenPreviousBreadcrumb(b) { - - const breadcrumbs = window.nuFORM.breadcrumbs; - const modal = parent.$('#nuModal'); +function nuOpenPreviousBreadcrumb (b) { + const breadcrumbs = window.nuFORM.breadcrumbs + const modal = parent.$('#nuModal') - if (modal.length) { - nuClosePopup(); - return; - } + if (modal.length) { + nuClosePopup() + return + } - b = b ? b + 1 : 2; - - const l = breadcrumbs.length; - if (l > 1) { - nuGetBreadcrumb(l - b); - } + b = b ? b + 1 : 2 + const l = breadcrumbs.length + if (l > 1) { + nuGetBreadcrumb(l - b) + } } -function nuDisplayError(e) { - - if (e.errors === undefined || e.errors.length == 0) { //-- no error messages - return false; - } - - let msgDiv = nuMessage(e.errors); +function nuDisplayError (e) { + if (e.errors === undefined || e.errors.length == 0) { // -- no error messages + return false + } - if (window.nuOnMessage) { - nuOnMessage(msgDiv, e.errors); - } + const msgDiv = nuMessage(e.errors) - return e.after_event == false; //-- errors are really just messages if from after save or after delete. + if (window.nuOnMessage) { + nuOnMessage(msgDiv, e.errors) + } + return e.after_event == false // -- errors are really just messages if from after save or after delete. } -function nuFormatAjaxErrorMessage(jqXHR, exception) { +function nuFormatAjaxErrorMessage (jqXHR, exception) { + const errorMessages = { + 0: nuTranslate('Not connected. Please verify your network connection.'), + 403: { + message: `

${nuTranslate('Access Forbidden.')}

`, + response: jqXHR.responseText + }, + 404: nuTranslate('The requested page was not found.') + ' [404]', + 500: nuTranslate('Internal Server Error.') + ' [500]', + parsererror: nuTranslate('Requested JSON parse failed.'), + timeout: nuTranslate('Time out error.'), + abort: nuTranslate('Ajax request aborted.') + } - const errorMessages = { - 0: nuTranslate('Not connected. Please verify your network connection.'), - 403: { - message: `

${nuTranslate('Access Forbidden.')}

`, - response: jqXHR.responseText, - }, - 404: nuTranslate('The requested page was not found.') + ' [404]', - 500: nuTranslate('Internal Server Error.') + ' [500]', - parsererror: nuTranslate('Requested JSON parse failed.'), - timeout: nuTranslate('Time out error.'), - abort: nuTranslate('Ajax request aborted.'), - }; + const errorMessage = errorMessages[jqXHR.status] || errorMessages[exception] || { + message: `

${nuTranslate('Uncaught Error.')}

`, + response: jqXHR.responseText + } - const errorMessage = errorMessages[jqXHR.status] || errorMessages[exception] || { - message: `

${nuTranslate('Uncaught Error.')}

`, - response: jqXHR.responseText, - }; - - return errorMessage; - + return errorMessage } -function nuLogin(loginTopRow, nuconfigNuWelcomeBodyInnerHTML, logonMode='normal', onlySsoExcept={}, lastUser="") { - - var HTML = String(nuconfigNuWelcomeBodyInnerHTML).trim(); - loginTopRow = String(loginTopRow).trim(); - window.nuSESSION = ''; - window.nuFORM = new nuFormObject(); +function nuLogin (loginTopRow, nuconfigNuWelcomeBodyInnerHTML, logonMode = 'normal', onlySsoExcept = {}, lastUser = '') { + const HTML = String(nuconfigNuWelcomeBodyInnerHTML).trim() + loginTopRow = String(loginTopRow).trim() + window.nuSESSION = '' + window.nuFORM = new nuFormObject() - $('body').html(''); + $('body').html('') - var defaulTopRow = ` + const defaulTopRow = `

- `; + ` - var topRow = loginTopRow == '' ? defaulTopRow : loginTopRow; + const topRow = loginTopRow == '' ? defaulTopRow : loginTopRow - var h1 = ` + const h1 = `
- ` - + topRow + ` - `; - var h2sso = ` +
` + + topRow + ` + ` + const h2sso = ` - `; - var h3normal = ` + ` + const h3normal = ` @@ -456,1721 +422,1453 @@ function nuLogin(loginTopRow, nuconfigNuWelcomeBodyInnerHTML, logonMode='normal' - `; - var h4 = ` + ` + const h4 = `


Username




- `; - - - if(logonMode == 'normal') { - var h = h1 + h3normal + h4; - } else if (logonMode == 'sso') { - var h = h1 + h2sso + h4; - } else if (logonMode == 'both') { - if (lastUser in onlySsoExcept || "allusers" in onlySsoExcept) { // Selectively show username/password login option if found in 'onlySsoExcept' dictionary - most users only see SSO button - var h = h1 + h2sso + h3normal + h4; - } else { - var h = h1 + h2sso + h4; - } - } else { // Original/normal mode - var h = h1 + h3normal + h4; - } - - var H = HTML == '' ? h : HTML; - - var e = document.createElement('div'); - - e.setAttribute('id', 'loginbg'); - - window.nuLoginU = window.nuLoginU === undefined ? '' : window.nuLoginU; - window.nuLoginP = window.nuLoginP === undefined ? '' : window.nuLoginP; - - $('body').html(H); - - if (nuIsMobile()) { - $('body').css('width', 300).css('height', 300); - } - - if (window.nuLoginU == '' && window.nuLoginP == '') { - $('#nuusername').focus(); - } - - if (window.nuLoginU != '' && window.nuLoginP == '') { - - $('#nuusername').val(window.nuLoginU); - $('#nupassword').focus(); - - } - - if (window.nuLoginU != '' && window.nuLoginP != '') { - - $('#nuusername').val(window.nuLoginU); - $('#nupassword').val(window.nuLoginP); - - nuLoginRequest(); - - } - - if (sessionStorage.logout == 'true') { - nuMessage(['You have been logged out']); - } - - sessionStorage.logout = ''; - -} - -function nuSubmit(e) { - - if (e.key == 'Enter') { - $('#submit').click(); - } - -} - -function nuBuildLookup(t, s, like) { - - if ($(t).prop('disabled')) { return; } - - nuCursor('progress'); - - let obj = $('#' + t.id); - var f = obj.attr('data-nu-form-id'); - var tar = obj.attr('data-nu-target'); - var p = obj.attr('data-nu-prefix'); - window.nuSubformRow = Number(p.substr(p.length - 3)); - - if (arguments.length < 3) { - like = ''; - } - - window.nuOPENER.push(new nuOpener('F', f, '')); - - var open = window.nuOPENER[window.nuOPENER.length - 1]; - - if (parent.window == window) { - let left = nuIsMobile() ? 0 : 50; - window.nuDialog.createDialog(left, 25, 50, 50, ''); - } else { - window.nuDialog.createDialog(0, 30, 50, 50, ''); - } - - $('#nuDragDialog') - .css('visibility', 'hidden') - .append(''); - -} - -function nuPopup(f, r, filter) { - - nuCursor('progress'); - - if (!nuGlobalAccess() && f == 'nuobject') { return; } - if (nuSERVERRESPONSE.objects.length == 0 && r == '-2') { return; } - - $('#nuCalendar').remove(); - - window.nuOPENER.push(new nuOpener('F', f, r, filter)); - - var id = window.nuOPENER[window.nuOPENER.length - 1].id; - - if (parent.window == window) { - let left = nuIsMobile() ? 0 : 50; - window.nuDialog.createDialog(left + window.pageXOffset, 25 + window.pageYOffset, 50, 50, ''); - } else { - window.nuDialog.createDialog(0, 30, 50, 50, ''); - } - - $('#nuDragDialog') - .css('visibility', 'hidden') - .append('') - .prepend('
'); - - - if (window.nuOnPopupOpenedGlobal) { - nuOnPopupOpenedGlobal(f, r, filter); - } - -} - -function nuOptionsListAction(f, r, filter) { - - if (!(nuIsMacintosh() ? window.event.metaKey : window.event.ctrlKey)) { - nuPopup(f, r, filter) - } else { - nuForm(f, r, filter, '', ''); - } -} - -//-- object for dragging dialog --// - -function nuCreateDialog(t) { - - this.startX = 0; - this.startY = 0; - this.moveX = 0; - this.moveY = 0; - this.title = t; - this.pos = {}; - - this.move = function (event) { - - this.moveX = event.clientX - this.startX; - this.moveY = event.clientY - this.startY; - this.startX = event.clientX; - this.startY = event.clientY; - - if (event.buttons == 1) { - this.moveDialog(event); - } - - var dir = event.target.parentElement.baseURI.includes('nureportdesigner') ? '' : 'core/'; - - if (event.target.id == 'dialogClose') { - $('#dialogClose').attr("src", dir + "graphics/close_red.png"); - } else { - $('#dialogClose').attr("src", dir + "graphics/close.png"); - } - - } - - this.click = function (event) { - - if (event.target.id == 'dialogClose') { + ` - if ($('#nuWindow').contents().find('#nuSaveButton.nuSaveButtonEdited').length > 0) { + if (logonMode == 'normal') { + var h = h1 + h3normal + h4 + } else if (logonMode == 'sso') { + var h = h1 + h2sso + h4 + } else if (logonMode == 'both') { + if (lastUser in onlySsoExcept || 'allusers' in onlySsoExcept) { // Selectively show username/password login option if found in 'onlySsoExcept' dictionary - most users only see SSO button + var h = h1 + h2sso + h3normal + h4 + } else { + var h = h1 + h2sso + h4 + } + } else { // Original/normal mode + var h = h1 + h3normal + h4 + } - if (!confirm(nuTranslate('Leave this form without saving?'))) { - return false; - } + const H = HTML == '' ? h : HTML - } - $('#nuDragDialog').remove(); - $('#nuModal').remove(); - $('body').off('.popup'); + const e = document.createElement('div') - } + e.setAttribute('id', 'loginbg') - } + window.nuLoginU = window.nuLoginU === undefined ? '' : window.nuLoginU + window.nuLoginP = window.nuLoginP === undefined ? '' : window.nuLoginP + $('body').html(H) - this.down = function (event) { + if (nuIsMobile()) { + $('body').css('width', 300).css('height', 300) + } - window.nuCurrentID = event.target.id; + if (window.nuLoginU == '' && window.nuLoginP == '') { + $('#nuusername').focus() + } - if (event.target.id == 'dialogTitleWords') { + if (window.nuLoginU != '' && window.nuLoginP == '') { + $('#nuusername').val(window.nuLoginU) + $('#nupassword').focus() + } - $('#nuDragDialog').append('
'); - } + if (window.nuLoginU != '' && window.nuLoginP != '') { + $('#nuusername').val(window.nuLoginU) + $('#nupassword').val(window.nuLoginP) - } + nuLoginRequest() + } - this.moveDialog = function (e) { - - if (window.nuCurrentID == 'nuModal') { return; } - - var s = document.getElementById('nuDragDialog'); - if (s === null) return; - - var o = s.style; - var l = parseInt(o.left, 10) + this.moveX; - var t = parseInt(o.top, 10) + this.moveY; - - if (e.target.classList == '' && e.target.id != 'nuSelectBox') { - - o.left = l + 'px'; - o.top = t + 'px'; - - } - - } - - this.createDialog = function (l, t, w, h, title) { - - var callerName = this.createDialog.caller.name; - nuDialog.dialog = callerName; - - var e = document.createElement('div'); - - var translation = nuTranslate(title); - - e.setAttribute('id', 'nuDragDialog'); - - let scrollHeight = Math.max( - document.body.scrollHeight, document.documentElement.scrollHeight, - document.body.offsetHeight, document.documentElement.offsetHeight, - document.body.clientHeight, document.documentElement.clientHeight - ); - - $('body').append('
') - .append(e); - - var subDir = callerName == 'nuPopup' || callerName == 'nuBuildLookup' ? 'core/' : ''; - - $('#nuDragDialog').addClass('nuDragDialog nuDragNoSelect') - .css({ - 'left': l, - 'top': t, - 'width': w, - 'height': h, - 'background-color': '#fff', - 'z-index': 3000, - 'position': 'absolute', - 'visibility': 'hidden' - }) - .html('
        ' + translation + '
') - - $('body') - .on('mousemove.popup', function (event) { nuDialog.move(event); }) - .on('click.popup', function (event) { nuDialog.click(event); }) - .on('mousedown.popup', function (event) { nuDialog.down(event); }) - .on('mouseup.popup', function (event) { window.nuCurrentID = ''; $('#nuPopupModal').remove(); }) - .on('dblclick.popup', function (event) { nuResizeWindow(event); }) - - this.startX = l; - this.startY = t; - - } - -} - -function nuReformat(t) { - - function nuReapplyFormat(v, f) { - - let r = nuFORM.removeFormatting(v, f); - return nuFORM.addFormatting(r, f); - - } - - let o = $('#' + t.id); - let f = o.attr('data-nu-format'); - let v = o.val(); - - if (f == '' || v == '') { - return v; - } - - if (f[0] == 'D') { - - let a = nuReapplyFormat(v, f); - if (v != a) { - - o.val(''); - - if (window.nuFormatValueClearedGlobal) { - nuFormatValueClearedGlobal(o, v); - } - - if (window.nuFormatValueCleared) { - nuFormatValueCleared(o, v); - } - - } - - } - - if (f[0] == 'N') { - - let a = nuReapplyFormat(v, f); - o.val(a); - - } + if (sessionStorage.logout == 'true') { + nuMessage(['You have been logged out']) + } + sessionStorage.logout = '' } - -function nuOpenAce(lang, obj) { - - var ts = new Date().getTime(); - window.nuAce = [lang, obj]; - - window.open('core/nuace.php?' + ts); - +function nuSubmit (e) { + if (e.key == 'Enter') { + $('#submit').click() + } } +function nuBuildLookup (t, s, like) { + if ($(t).prop('disabled')) { return } -function nuRunIt(t, email, type) { - - var r = $('#' + t.id).attr('data-nu-row'); - var c = '000'; - var p = $('#' + r + c).html(); - - if (arguments.length < 3) { //-- set type - - var type = $('#' + r + '001').html(); //-- report - PDF,or procedure - PHP - - } + nuCursor('progress') - if (arguments.length == 1) { //-- set email + const obj = $('#' + t.id) + const f = obj.attr('data-nu-form-id') + const tar = obj.attr('data-nu-target') + const p = obj.attr('data-nu-prefix') + window.nuSubformRow = Number(p.substr(p.length - 3)) - var email = 0; + if (arguments.length < 3) { + like = '' + } - } + window.nuOPENER.push(new nuOpener('F', f, '')) - var f = $('#' + t.id).attr('data-nu-primary-key'); - var i = nuRecordId(); + const open = window.nuOPENER[window.nuOPENER.length - 1] - if (email == 1) { - - if (type == 'php') { - nuEmailPHP(i); - } - - if (type == 'pdf') { - nuEmailPDF(i); - } - - } else { - - if (type == 'php') { - nuGetPHP(f, p); - } - - if (type == 'pdf') { - nuGetReport(f, p); - } - - } + if (parent.window == window) { + const left = nuIsMobile() ? 0 : 50 + window.nuDialog.createDialog(left, 25, 50, 50, '') + } else { + window.nuDialog.createDialog(0, 30, 50, 50, '') + } + $('#nuDragDialog') + .css('visibility', 'hidden') + .append('') } -function nuBindCtrlEvents() { - - var nuCtrlKeydownListener = function (e) { - - if (e.key === 'F3' || ((nuIsMacintosh() ? e.metaKey : e.ctrlKey) && e.key === 'f')) { // exclude Ctrl + f - window.nuNEW = 0; - } else { - if (e.key == 'Control') { - window.nuNEW = 1; - } - - } - - } - - $(document).keydown(function (e) { - - if((e.key === 'PageDown' || e.key === 'PageUp') && nuFormType() == 'browse'){ - const $nuRecord = $("#nuRECORD"); - const scrollBy = e.key === 'PageDown' ? 400 : -400; - $nuRecord.scrollTop($nuRecord.scrollTop() + scrollBy); - } - - if (e.key == 'Escape') { - - if (nuIsVisible('nuMessageDiv')) { - $('#nuMessageDiv').remove(); - } else if (nuIsVisible('nuOptionsListBox')) { - $('#nuOptionsListBox').remove(); - } else if (parent.$('#nuModal').length == 1) { - let ae = document.activeElement; - $(ae).blur(); - $(ae).focus(); - if (nuFormsUnsaved() == 0) { - nuClosePopup(); - } else { - if (confirm(nuTranslate('Leave this form without saving?'))) { - nuClosePopup(); - } - } - } else if (nuFormType() == 'browse') { - nuSearchAction(""); - } - - } +function nuPopup (f, r, filter) { + nuCursor('progress') - if ((nuIsMacintosh() ? e.metaKey : e.ctrlKey) && e.shiftKey) { + if (!nuGlobalAccess() && f == 'nuobject') { return } + if (nuSERVERRESPONSE.objects.length == 0 && r == '-2') { return } - window.nuNEW = 0; + $('#nuCalendar').remove() - e.preventDefault(); + window.nuOPENER.push(new nuOpener('F', f, r, filter)) - var g = nuGlobalAccess(); - var formId = window.nuFORM.getCurrent().form_id; + const id = window.nuOPENER[window.nuOPENER.length - 1].id - if (nuFormType() == 'browse' || nuFormType() == 'edit') { + if (parent.window == window) { + const left = nuIsMobile() ? 0 : 50 + window.nuDialog.createDialog(left + window.pageXOffset, 25 + window.pageYOffset, 50, 50, '') + } else { + window.nuDialog.createDialog(0, 30, 50, 50, '') + } - if (e.code == 'KeyF' && g) { //-- f Form Properties - nuPopup("nuform", formId); - } else if (e.code == 'KeyO' && g) { //-- O Object List - nuPopup("nuobject", "", formId); - } else if (e.code == 'KeyM' && g) { //-- m Form Info - nuShowFormInfo(); - } else if (e.code == 'KeyE' && g) { //-- e Database - nuVendorLogin('PMA'); - } else if (e.code == 'KeyI' && g) { //-- i Sessions - nuForm("nusession","","", "", 2); - } else if (e.code == 'KeyQ' && g) { //-- e File Manager - nuVendorLogin("TFM"); - } else if (e.code == 'KeyB' && g) { //-- b Backup - nuRunBackup(); - } else if (e.code == 'KeyR') { //-- r Refresh - nuGetBreadcrumb(); - } else if (e.code == 'KeyU' && g) { //-- u Setup - nuForm('nusetup', '1', '', '', 2); - } else if (e.code == 'KeyD' && g) { //-- d nuDebug Results - nuPopup("nudebug", ""); - } else if (e.code == 'KeyY' && g) { //-- y Current Properties - nuPrettyPrintMessage(e, nuCurrentProperties()); - } else if (e.code == 'KeyL') { //-- l Log out - nuAskLogout(); - } - - } - - if (nuFormType() == 'browse') { - - if (e.code == 'KeyC' && g) { //-- c Searchable Columns - nuGetSearchList(); - } else if (e.code == 'KeyS') { //-- s Search - nuSearchAction(); - } else if (e.code == 'KeyA' && g) { //-- a Add - nuAddAction(); - } else if (e.code == 'KeyP' && g) { //-- p Print - nuPrintAction(); - } - - } - - if (nuFormType() == 'edit') { - - if (e.code == 'KeyA' && g) { //-- a Arrange - nuPopup(formId, "-2"); - } else if (e.code == 'KeyQ' && !g) { //-- q Change Password - nuPopup("nupassword", "5b6bb7108a75efc", ""); - } else if (e.code == 'KeyH' && g) { //-- t Add Object - nuPopup('nuobject', '-1', ''); - } else if (e.code == 'KeyG' && g) { //-- G Object Grid - nuForm("nuobjectgrid", formId, "", "", 2); - } else if (e.code == 'KeyS') { //-- s Save - $(":focus").blur(); - nuSaveAction(); - } else if (e.code == 'KeyC') { //-- c Clone - nuCloneAction(); - } else if (e.code == 'KeyY') { //-- y Delete - nuDeleteAction(); - } else if (e.code == 'ArrowRight') { //-- -> Select next tab - nuSelectNextTab(1); - } else if (e.code == 'ArrowLeft') { //-- <- Select previous tab - nuSelectNextTab(-1); - } - - } - - var nosearch = window.nuFORM.getProperty('nosearch_columns'); - var searchIndex = -1; - - //Numbers - const numberCode = e.code.replace('Digit',''); - if (numberCode >= "1" && numberCode <= "9") { - searchIndex = Number(numberCode) - 1; - } - - if (searchIndex != -1) { - - if ($.inArray(searchIndex, nosearch) != '-1') { - - nosearch.pop(searchIndex); - $('#nusort_' + searchIndex).removeClass('nuNoSearch'); - - } else { - - nosearch.push(searchIndex); - $('#nusort_' + searchIndex).addClass('nuNoSearch'); - - } - - } - - window.nuFORM.setProperty('nosearch_columns', nosearch); - } - }); - - var nuCtrlKeyupListener = function (e) { - - window.nuNEW = 0; - } - - $(document).on('keydown.nubindctrl', nuCtrlKeydownListener); - - $(document).on('keyup.nubindctrl', nuCtrlKeyupListener); + $('#nuDragDialog') + .css('visibility', 'hidden') + .append('') + .prepend('
') + if (window.nuOnPopupOpenedGlobal) { + nuOnPopupOpenedGlobal(f, r, filter) + } } -function nuUnbindDragEvents() { - $(document).off('.nubindctrl'); +function nuOptionsListAction (f, r, filter) { + if (!(nuIsMacintosh() ? window.event.metaKey : window.event.ctrlKey)) { + nuPopup(f, r, filter) + } else { + nuForm(f, r, filter, '', '') + } } -function nuTranslate(obj) { - - if (Array.isArray(obj)) { - - let arr = obj; - arr.forEach(function(item, index) { - const l = nuLANGUAGE.find(elem => elem.english === item); - arr[index] = !l ? item : l.translation; - }) +// -- object for dragging dialog --// - return arr; +function nuCreateDialog (t) { + this.startX = 0 + this.startY = 0 + this.moveX = 0 + this.moveY = 0 + this.title = t + this.pos = {} - } else { - if (!obj) return ''; + this.move = function (event) { + this.moveX = event.clientX - this.startX + this.moveY = event.clientY - this.startY + this.startX = event.clientX + this.startY = event.clientY - str = String(obj); - if (str.charAt(0) == '|') return str.substring(1); + if (event.buttons == 1) { + this.moveDialog(event) + } - const l = nuLANGUAGE.find(elem => elem.english === str); - return !l ? str : l.translation; - } + const dir = event.target.parentElement.baseURI.includes('nureportdesigner') ? '' : 'core/' + if (event.target.id == 'dialogClose') { + $('#dialogClose').attr('src', dir + 'graphics/close_red.png') + } else { + $('#dialogClose').attr('src', dir + 'graphics/close.png') + } + } + + this.click = function (event) { + if (event.target.id == 'dialogClose') { + if ($('#nuWindow').contents().find('#nuSaveButton.nuSaveButtonEdited').length > 0) { + if (!confirm(nuTranslate('Leave this form without saving?'))) { + return false + } + } + $('#nuDragDialog').remove() + $('#nuModal').remove() + $('body').off('.popup') + } + } + + this.down = function (event) { + window.nuCurrentID = event.target.id + + if (event.target.id == 'dialogTitleWords') { + $('#nuDragDialog').append('
') + } + } + + this.moveDialog = function (e) { + if (window.nuCurrentID == 'nuModal') { return } + + const s = document.getElementById('nuDragDialog') + if (s === null) return + + const o = s.style + const l = parseInt(o.left, 10) + this.moveX + const t = parseInt(o.top, 10) + this.moveY + + if (e.target.classList == '' && e.target.id != 'nuSelectBox') { + o.left = l + 'px' + o.top = t + 'px' + } + } + + this.createDialog = function (l, t, w, h, title) { + const callerName = this.createDialog.caller.name + nuDialog.dialog = callerName + + const e = document.createElement('div') + + const translation = nuTranslate(title) + + e.setAttribute('id', 'nuDragDialog') + + const scrollHeight = Math.max( + document.body.scrollHeight, document.documentElement.scrollHeight, + document.body.offsetHeight, document.documentElement.offsetHeight, + document.body.clientHeight, document.documentElement.clientHeight + ) + + $('body').append('
') + .append(e) + + const subDir = callerName == 'nuPopup' || callerName == 'nuBuildLookup' ? 'core/' : '' + + $('#nuDragDialog').addClass('nuDragDialog nuDragNoSelect') + .css({ + left: l, + top: t, + width: w, + height: h, + 'background-color': '#fff', + 'z-index': 3000, + position: 'absolute', + visibility: 'hidden' + }) + .html('
        ' + translation + '
') + + $('body') + .on('mousemove.popup', function (event) { nuDialog.move(event) }) + .on('click.popup', function (event) { nuDialog.click(event) }) + .on('mousedown.popup', function (event) { nuDialog.down(event) }) + .on('mouseup.popup', function (event) { window.nuCurrentID = ''; $('#nuPopupModal').remove() }) + .on('dblclick.popup', function (event) { nuResizeWindow(event) }) + + this.startX = l + this.startY = t + } +} + +function nuReformat (t) { + function nuReapplyFormat (v, f) { + const r = nuFORM.removeFormatting(v, f) + return nuFORM.addFormatting(r, f) + } + + const o = $('#' + t.id) + const f = o.attr('data-nu-format') + const v = o.val() + + if (f == '' || v == '') { + return v + } + + if (f[0] == 'D') { + const a = nuReapplyFormat(v, f) + if (v != a) { + o.val('') + + if (window.nuFormatValueClearedGlobal) { + nuFormatValueClearedGlobal(o, v) + } + + if (window.nuFormatValueCleared) { + nuFormatValueCleared(o, v) + } + } + } + + if (f[0] == 'N') { + const a = nuReapplyFormat(v, f) + o.val(a) + } +} + +function nuOpenAce (lang, obj) { + const ts = new Date().getTime() + window.nuAce = [lang, obj] + + window.open('core/nuace.php?' + ts) +} + +function nuRunIt (t, email, type) { + const r = $('#' + t.id).attr('data-nu-row') + const c = '000' + const p = $('#' + r + c).html() + + if (arguments.length < 3) { // -- set type + var type = $('#' + r + '001').html() // -- report - PDF,or procedure - PHP + } + + if (arguments.length == 1) { // -- set email + var email = 0 + } + + const f = $('#' + t.id).attr('data-nu-primary-key') + const i = nuRecordId() + + if (email == 1) { + if (type == 'php') { + nuEmailPHP(i) + } + + if (type == 'pdf') { + nuEmailPDF(i) + } + } else { + if (type == 'php') { + nuGetPHP(f, p) + } + + if (type == 'pdf') { + nuGetReport(f, p) + } + } +} + +function nuBindCtrlEvents () { + const nuCtrlKeydownListener = function (e) { + if (e.key === 'F3' || ((nuIsMacintosh() ? e.metaKey : e.ctrlKey) && e.key === 'f')) { // exclude Ctrl + f + window.nuNEW = 0 + } else { + if (e.key == 'Control') { + window.nuNEW = 1 + } + } + } + + $(document).keydown(function (e) { + if ((e.key === 'PageDown' || e.key === 'PageUp') && nuFormType() == 'browse') { + const $nuRecord = $('#nuRECORD') + const scrollBy = e.key === 'PageDown' ? 400 : -400 + $nuRecord.scrollTop($nuRecord.scrollTop() + scrollBy) + } + + if (e.key == 'Escape') { + if (nuIsVisible('nuMessageDiv')) { + $('#nuMessageDiv').remove() + } else if (nuIsVisible('nuOptionsListBox')) { + $('#nuOptionsListBox').remove() + } else if (parent.$('#nuModal').length == 1) { + const ae = document.activeElement + $(ae).blur() + $(ae).focus() + if (nuFormsUnsaved() == 0) { + nuClosePopup() + } else { + if (confirm(nuTranslate('Leave this form without saving?'))) { + nuClosePopup() + } + } + } else if (nuFormType() == 'browse') { + nuSearchAction('') + } + } + + if ((nuIsMacintosh() ? e.metaKey : e.ctrlKey) && e.shiftKey) { + window.nuNEW = 0 + + e.preventDefault() + + const g = nuGlobalAccess() + const formId = window.nuFORM.getCurrent().form_id + + if (nuFormType() == 'browse' || nuFormType() == 'edit') { + if (e.code == 'KeyF' && g) { // -- f Form Properties + nuPopup('nuform', formId) + } else if (e.code == 'KeyO' && g) { // -- O Object List + nuPopup('nuobject', '', formId) + } else if (e.code == 'KeyM' && g) { // -- m Form Info + nuShowFormInfo() + } else if (e.code == 'KeyE' && g) { // -- e Database + nuVendorLogin('PMA') + } else if (e.code == 'KeyI' && g) { // -- i Sessions + nuForm('nusession', '', '', '', 2) + } else if (e.code == 'KeyQ' && g) { // -- e File Manager + nuVendorLogin('TFM') + } else if (e.code == 'KeyB' && g) { // -- b Backup + nuRunBackup() + } else if (e.code == 'KeyR') { // -- r Refresh + nuGetBreadcrumb() + } else if (e.code == 'KeyU' && g) { // -- u Setup + nuForm('nusetup', '1', '', '', 2) + } else if (e.code == 'KeyD' && g) { // -- d nuDebug Results + nuPopup('nudebug', '') + } else if (e.code == 'KeyY' && g) { // -- y Current Properties + nuPrettyPrintMessage(e, nuCurrentProperties()) + } else if (e.code == 'KeyL') { // -- l Log out + nuAskLogout() + } + } + + if (nuFormType() == 'browse') { + if (e.code == 'KeyC' && g) { // -- c Searchable Columns + nuGetSearchList() + } else if (e.code == 'KeyS') { // -- s Search + nuSearchAction() + } else if (e.code == 'KeyA' && g) { // -- a Add + nuAddAction() + } else if (e.code == 'KeyP' && g) { // -- p Print + nuPrintAction() + } + } + + if (nuFormType() == 'edit') { + if (e.code == 'KeyA' && g) { // -- a Arrange + nuPopup(formId, '-2') + } else if (e.code == 'KeyQ' && !g) { // -- q Change Password + nuPopup('nupassword', '5b6bb7108a75efc', '') + } else if (e.code == 'KeyH' && g) { // -- t Add Object + nuPopup('nuobject', '-1', '') + } else if (e.code == 'KeyG' && g) { // -- G Object Grid + nuForm('nuobjectgrid', formId, '', '', 2) + } else if (e.code == 'KeyS') { // -- s Save + $(':focus').blur() + nuSaveAction() + } else if (e.code == 'KeyC') { // -- c Clone + nuCloneAction() + } else if (e.code == 'KeyY') { // -- y Delete + nuDeleteAction() + } else if (e.code == 'ArrowRight') { // -- -> Select next tab + nuSelectNextTab(1) + } else if (e.code == 'ArrowLeft') { // -- <- Select previous tab + nuSelectNextTab(-1) + } + } + + const nosearch = window.nuFORM.getProperty('nosearch_columns') + let searchIndex = -1 + + // Numbers + const numberCode = e.code.replace('Digit', '') + if (numberCode >= '1' && numberCode <= '9') { + searchIndex = Number(numberCode) - 1 + } + + if (searchIndex != -1) { + if ($.inArray(searchIndex, nosearch) != '-1') { + nosearch.pop(searchIndex) + $('#nusort_' + searchIndex).removeClass('nuNoSearch') + } else { + nosearch.push(searchIndex) + $('#nusort_' + searchIndex).addClass('nuNoSearch') + } + } + + window.nuFORM.setProperty('nosearch_columns', nosearch) + } + }) + + const nuCtrlKeyupListener = function (e) { + window.nuNEW = 0 + } + + $(document).on('keydown.nubindctrl', nuCtrlKeydownListener) + + $(document).on('keyup.nubindctrl', nuCtrlKeyupListener) +} + +function nuUnbindDragEvents () { + $(document).off('.nubindctrl') +} + +function nuTranslate (obj) { + if (Array.isArray(obj)) { + const arr = obj + arr.forEach(function (item, index) { + const l = nuLANGUAGE.find(elem => elem.english === item) + arr[index] = !l ? item : l.translation + }) + + return arr + } else { + if (!obj) return '' + + str = String(obj) + if (str.charAt(0) == '|') return str.substring(1) + + const l = nuLANGUAGE.find(elem => elem.english === str) + return !l ? str : l.translation + } } -function nuTranslateToEnglish(str) { +function nuTranslateToEnglish (str) { + if (!str) return '' - if (!str) return ''; - - str = String(str); - if (str.charAt(0) === '|') return str.substring(1); - - const l = nuLANGUAGE.find(({translation}) => translation === str); - return l ? l.english : str; + str = String(str) + if (str.charAt(0) === '|') return str.substring(1) + const l = nuLANGUAGE.find(({ translation }) => translation === str) + return l ? l.english : str } -function nuIsOpener() { - return window.opener !== null; +function nuIsOpener () { + return window.opener !== null } -function nuPreview(a) { - - const r = nuRecordId(); - - if (r === '-1') { +function nuPreview (a) { + const r = nuRecordId() - alert(nuTranslate('Form must be saved first..')); - return; - - } - - const arg = a === undefined ? '-3' : ''; - nuPopup(r, arg); + if (r === '-1') { + alert(nuTranslate('Form must be saved first..')) + return + } + const arg = a === undefined ? '-3' : '' + nuPopup(r, arg) } -function nuPopPHP(e, nuE) { //-- used in database - - var i = nuRecordId(); +function nuPopPHP (e, nuE) { // -- used in database + const i = nuRecordId() - if (i == '') { - - alert(nuTranslate('Cannot create Event Until This Form Has Been Saved..')); - return; - - } - - nuPopup('nuphp', i + '_' + nuE, 'justphp'); + if (i == '') { + alert(nuTranslate('Cannot create Event Until This Form Has Been Saved..')) + return + } + nuPopup('nuphp', i + '_' + nuE, 'justphp') } +function nuPopSQL (e, nuE) { // -- used in database + const i = nuRecordId() -function nuPopSQL(e, nuE) { //-- used in database - - var i = nuRecordId(); - - if (i == '') { - - alert(nuTranslate('Cannot create SQL Until This Form Has Been Saved..')); - return; - - } - - nuPopup('nuselect', i + '_' + nuE, 'justsql'); + if (i == '') { + alert(nuTranslate('Cannot create SQL Until This Form Has Been Saved..')) + return + } + nuPopup('nuselect', i + '_' + nuE, 'justsql') } -function nuPopJS() { //-- used in database +function nuPopJS () { // -- used in database + const i = $('#sob_all_zzzzsys_form_id').val() - var i = $('#sob_all_zzzzsys_form_id').val(); - - if (i == '') { - - alert(nuTranslate('Cannot Create Event Until This Form Has Been Saved..')); - return; - - } - - nuPopup('nuform', i, 'justjs'); + if (i == '') { + alert(nuTranslate('Cannot Create Event Until This Form Has Been Saved..')) + return + } + nuPopup('nuform', i, 'justjs') } -function nuGetLookupFields(id) { +function nuGetLookupFields (id) { + const prefix = id.slice(0, -4) + const $id = $('#' + id) + const lookupFields = [] - const prefix = id.slice(0, -4); - const $id = $('#' + id); - const lookupFields = []; - - if ($id.length === 1) { - const type = $id.attr('data-nu-type'); - if (type === 'subform') { - lookupFields.push(prefix, id, prefix + 'description'); - } else { - lookupFields.push('nunosuchfield', id, 'nunosuchfield'); - } - } - - return lookupFields; + if ($id.length === 1) { + const type = $id.attr('data-nu-type') + if (type === 'subform') { + lookupFields.push(prefix, id, prefix + 'description') + } else { + lookupFields.push('nunosuchfield', id, 'nunosuchfield') + } + } + return lookupFields } -function nuObjectComponents(i) { - - let o = [i, 'label_' + i]; - const obj = $('#' + i); - if (obj.attr('data-nu-type') == 'lookup') o.push(i + 'code', i + 'button', i + 'description') - if (obj.hasClass('select2-hidden-accessible')) o.push(i + '_select2'); - - return o; +function nuObjectComponents (i) { + const o = [i, 'label_' + i] + const obj = $('#' + i) + if (obj.attr('data-nu-type') == 'lookup') o.push(i + 'code', i + 'button', i + 'description') + if (obj.hasClass('select2-hidden-accessible')) o.push(i + '_select2') + return o } -function nuEnable(i, enable) { - - if (enable === false) { - nuDisable(i); - return; - } - - const ids = Array.isArray(i) ? i : [i]; - - $.each(ids, function(index) { - - const id = ids[index]; - const components = nuObjectComponents(id); +function nuEnable (i, enable) { + if (enable === false) { + nuDisable(i) + return + } - for (let c = 0; c < components.length; c++) { + const ids = Array.isArray(i) ? i : [i] - if (c === 1) { - continue; - } // skip label + $.each(ids, function (index) { + const id = ids[index] + const components = nuObjectComponents(id) - let $current = $('#' + components[c]); + for (let c = 0; c < components.length; c++) { + if (c === 1) { + continue + } // skip label - $current - .removeClass('nuReadonly') - .prop('readonly', false) - .prop('disabled', false); + const $current = $('#' + components[c]) - if (c === 2) { //-- button - $current.on("click", () => nuBuildLookup(components[c], "")); - } + $current + .removeClass('nuReadonly') + .prop('readonly', false) + .prop('disabled', false) - } - - }); - + if (c === 2) { // -- button + $current.on('click', () => nuBuildLookup(components[c], '')) + } + } + }) } -function nuDisable(i) { //-- Disable Edit Form Object - - const ids = Array.isArray(i) ? i : [i]; - - $.each(ids, function(index) { - const id = ids[index]; - const components = nuObjectComponents(id); +function nuDisable (i) { // -- Disable Edit Form Object + const ids = Array.isArray(i) ? i : [i] - for (let c = 0; c < components.length; c++) { - if (c === 1) { - continue; - } // skip label + $.each(ids, function (index) { + const id = ids[index] + const components = nuObjectComponents(id) - let $current = $('#' + components[c]); - $current - .addClass('nuReadonly') - .prop('readonly', true) - .prop('disabled', true); + for (let c = 0; c < components.length; c++) { + if (c === 1) { + continue + } // skip label - if (c === 2) { //-- button - $current.off(); - } - } - }); + const $current = $('#' + components[c]) + $current + .addClass('nuReadonly') + .prop('readonly', true) + .prop('disabled', true) + if (c === 2) { // -- button + $current.off() + } + } + }) } -function nuReadonly(i) { - - const o = nuObjectComponents(i); - - o.forEach((component, index) => { - if (index === 1) return; // Skip label - $('#' + component) - .addClass('nuReadonly') - .attr('onclick', "return false") - .prop('readonly', true); - }); +function nuReadonly (i) { + const o = nuObjectComponents(i) + o.forEach((component, index) => { + if (index === 1) return // Skip label + $('#' + component) + .addClass('nuReadonly') + .attr('onclick', 'return false') + .prop('readonly', true) + }) } -function nuShow(i, visible, openTab) { - - var arr = []; - if (!$.isArray(i)) { - arr.push(i); - } else { - arr = i; - } - - let counter = 0; - for (var s = 0; s < arr.length; s++) { - - if (visible === false) { - nuHide(arr[s]); - } else { - - var o = nuObjectComponents(arr[s]); - - for (var c = 0; c < o.length; c++) { - - var t = String($('#' + o[c]).attr('data-nu-tab')); +function nuShow (i, visible, openTab) { + let arr = [] + if (!$.isArray(i)) { + arr.push(i) + } else { + arr = i + } - if (nuIsHidden(o[c])) { - if (t[0] == 'x') { + let counter = 0 + for (let s = 0; s < arr.length; s++) { + if (visible === false) { + nuHide(arr[s]) + } else { + const o = nuObjectComponents(arr[s]) - $('#' + o[c]) - .attr('data-nu-tab', t.substr(1)) - .show(); + for (let c = 0; c < o.length; c++) { + const t = String($('#' + o[c]).attr('data-nu-tab')) - } else { - - $('#' + o[c]).show(); - - } - counter++; - } - - } - - } - - if (openTab !== false && counter > 0) nuOpenTab($('.nuTabSelected')[0].id.substr(5)); - - } + if (nuIsHidden(o[c])) { + if (t[0] == 'x') { + $('#' + o[c]) + .attr('data-nu-tab', t.substr(1)) + .show() + } else { + $('#' + o[c]).show() + } + counter++ + } + } + } + if (openTab !== false && counter > 0) nuOpenTab($('.nuTabSelected')[0].id.substr(5)) + } } +function nuHide (i) { + let arr = [] + if (!$.isArray(i)) { + arr.push(i) + } else { + arr = i + } -function nuHide(i) { - - var arr = []; - if (!$.isArray(i)) { - arr.push(i); - } else { - arr = i; - } - - for (var s = 0; s < arr.length; s++) { - var o = nuObjectComponents(arr[s]); - - for (var c = 0; c < o.length; c++) { - - var t = String($('#' + o[c]).attr('data-nu-tab')); - - if (t[0] == 'x') { - - $('#' + o[c]) - .hide(); - - } else { - - $('#' + o[c]) - .attr('data-nu-tab', 'x' + t) - .hide(); - - } + for (let s = 0; s < arr.length; s++) { + const o = nuObjectComponents(arr[s]) - } - } + for (let c = 0; c < o.length; c++) { + const t = String($('#' + o[c]).attr('data-nu-tab')) + if (t[0] == 'x') { + $('#' + o[c]) + .hide() + } else { + $('#' + o[c]) + .attr('data-nu-tab', 'x' + t) + .hide() + } + } + } } +function nuRemove (i) { + const arr = Array.isArray(i) ? i : [i] -function nuRemove(i) { - - const arr = Array.isArray(i) ? i : [i]; - - for (const s of arr) { - - const o = nuObjectComponents(s); - - for (const c of o) { - $('#' + c).remove(); - } - } + for (const s of arr) { + const o = nuObjectComponents(s) + for (const c of o) { + $('#' + c).remove() + } + } } -function nuIsVisible(i) { - return $('#' + i).is(':visible'); +function nuIsVisible (i) { + return $('#' + i).is(':visible') } -function nuIsHidden(i) { - return !$('#' + i).is(':visible'); +function nuIsHidden (i) { + return !$('#' + i).is(':visible') } -function nuIsEnabled(i) { - let o = $('#' + i); - return !o.is(':disabled') && !o.hasClass('nuReadonly'); +function nuIsEnabled (i) { + const o = $('#' + i) + return !o.is(':disabled') && !o.hasClass('nuReadonly') } -function nuIsDisabled(i) { - let o = $('#' + i); - return o.is(':disabled') || o.hasClass('nuReadonly'); +function nuIsDisabled (i) { + const o = $('#' + i) + return o.is(':disabled') || o.hasClass('nuReadonly') } -function nuAddThousandSpaces(s, c) { - return s.replace(/\B(?=(\d{3})+(?!\d))/g, c) +function nuAddThousandSpaces (s, c) { + return s.replace(/\B(?=(\d{3})+(?!\d))/g, c) } -function nuDuplicates(arr) { - - var s = arr.slice().sort(); - var d = []; - - for (var i = 0; i < arr.length - 1; i++) { - - if (s[i + 1] == s[i]) { - d.push(s[i]); - } - - } +function nuDuplicates (arr) { + const s = arr.slice().sort() + const d = [] - return d; + for (let i = 0; i < arr.length - 1; i++) { + if (s[i + 1] == s[i]) { + d.push(s[i]) + } + } + return d } -function nuResizeWindow(e) { +function nuResizeWindow (e) { + if (e.target.id !== 'dialogTitleWords') return - if (e.target.id !== 'dialogTitleWords') return; + const dialog = $('#nuDragDialog') + const dialogLeft = parseInt(dialog.css('left'), 10) + const win = $('#nuWindow') + const dragOptionsBox = $('.nuDragOptionsBox') - const dialog = $('#nuDragDialog'); - const dialogLeft = parseInt(dialog.css('left'), 10); - const win = $('#nuWindow'); - const dragOptionsBox = $('.nuDragOptionsBox'); - - if (dialogLeft === 2) { - const contentWin = getNuDragDialogIframes[0].contentWindow; - dialog.css(contentWin.nuDialogSize); - win.css(contentWin.nuWindowSize); - } else { + if (dialogLeft === 2) { + const contentWin = getNuDragDialogIframes[0].contentWindow + dialog.css(contentWin.nuDialogSize) + win.css(contentWin.nuWindowSize) + } else { + dialog.css({ + top: 0, + left: 2, + width: window.innerWidth - 30, + height: window.innerHeight + }) - dialog.css({ - top: 0, - left: 2, - width: window.innerWidth - 30, - height: window.innerHeight - }); + const dialogWidth = dragOptionsBox.length ? parseInt(dragOptionsBox.css('width'), 10) : 0 - const dialogWidth = dragOptionsBox.length ? parseInt(dragOptionsBox.css('width'), 10) : 0; - - win.css({ - top: 30, - width: parseInt(dialog.css('width'), 10) - dialogWidth - 10, - height: parseInt(dialog.css('height'), 10) - 50 - }); - - } + win.css({ + top: 30, + width: parseInt(dialog.css('width'), 10) - dialogWidth - 10, + height: parseInt(dialog.css('height'), 10) - 50 + }) + } } -function nuGetFunctionList() { - - var f = ''; - - for (var k in window) { - - if (window.hasOwnProperty(k)) { - - if (String(k).substr(0, 2) === 'nu') { - f += k + "\n"; - } - - } +function nuGetFunctionList () { + let f = '' - } - - return f; + for (const k in window) { + if (window.hasOwnProperty(k)) { + if (String(k).substr(0, 2) === 'nu') { + f += k + '\n' + } + } + } + return f } -function nuID() { - - nuSetSuffix(); +function nuID () { + nuSetSuffix() - window.nuUniqueID = 'c' + String(Date.now()); - - return window.nuUniqueID + String(window.nuSuffix); + window.nuUniqueID = 'c' + String(Date.now()) + return window.nuUniqueID + String(window.nuSuffix) } -function nuSetSuffix(a) { - - if (arguments.length == 1) { - window.nuSuffix = a; - } - - if (window.nuSuffix == 9999) { - window.nuSuffix = 0 - } else { - window.nuSuffix++; - } - +function nuSetSuffix (a) { + if (arguments.length == 1) { + window.nuSuffix = a + } + if (window.nuSuffix == 9999) { + window.nuSuffix = 0 + } else { + window.nuSuffix++ + } } -function nuWhen(timestamp) { - - if (!timestamp) return; - - const secondsElapsed = Math.ceil((Date.now() / 1000) - timestamp); - const timeUnit = secondsElapsed === 1 ? 'second' : 'seconds'; - return `${secondsElapsed} ${timeUnit} ago`; +function nuWhen (timestamp) { + if (!timestamp) return + const secondsElapsed = Math.ceil((Date.now() / 1000) - timestamp) + const timeUnit = secondsElapsed === 1 ? 'second' : 'seconds' + return `${secondsElapsed} ${timeUnit} ago` } -function nuSpaces(s) { - return String(' ').repeat(s); +function nuSpaces (s) { + return String(' ').repeat(s) } -function nuAddEditFieldsToHash(w) { - - var d = nuFORM.data()[0]; - var f = d.fields; - var r = d.rows[0]; +function nuAddEditFieldsToHash (w) { + const d = nuFORM.data()[0] + const f = d.fields + const r = d.rows[0] - for (let i = 2; i < f.length; i++) { - w[f[i]] = r[i]; - } - - return w; + for (let i = 2; i < f.length; i++) { + w[f[i]] = r[i] + } + return w } -function nuOnFocus(e) { - $('.nuTabSelected').attr('nu-data-active-element', document.activeElement.id); +function nuOnFocus (e) { + $('.nuTabSelected').attr('nu-data-active-element', document.activeElement.id) } -function nuClick(e) { - - const t = $(e.target); - - if (t.parent().parent().attr('class') !== 'ctxmenu') { - nuContextMenuClose(); - } - - if (!t.hasClass('nuOptionsItem') && ! t.hasClass('nuSearchCheckbox') && ! t.hasClass('nuOptionsList') - && ! $(e.target.parentElement).hasClass('nuOptionsList')) { - $('#nuSearchList').remove(); - } +function nuClick (e) { + const t = $(e.target) - if (!t.hasClass('nuIcon') && ! t.hasClass('nuOptionsList') && ! t.hasClass('nuOptionsListTitle')) { - $('#nuOptionsListBox').remove(); - } + if (t.parent().parent().attr('class') !== 'ctxmenu') { + nuContextMenuClose() + } - if (e.target.id != 'nuMessageDiv' && t.attr('data-nu-option-title') != 'Help') { + if (!t.hasClass('nuOptionsItem') && !t.hasClass('nuSearchCheckbox') && !t.hasClass('nuOptionsList') && + !$(e.target.parentElement).hasClass('nuOptionsList')) { + $('#nuSearchList').remove() + } - if (window.nuHideMessage) { - $('#nuMessageDiv').remove(); - } + if (!t.hasClass('nuIcon') && !t.hasClass('nuOptionsList') && !t.hasClass('nuOptionsListTitle')) { + $('#nuOptionsListBox').remove() + } - window.nuHideMessage = true; + if (e.target.id != 'nuMessageDiv' && t.attr('data-nu-option-title') != 'Help') { + if (window.nuHideMessage) { + $('#nuMessageDiv').remove() + } - } - - if (t.attr('type') != 'nuDate' && !t.hasClass('nuCalendar')) { - $('#nuCalendar').remove(); - } + window.nuHideMessage = true + } + if (t.attr('type') != 'nuDate' && !t.hasClass('nuCalendar')) { + $('#nuCalendar').remove() + } } -function nuAddSlashes(s) { - return String(s).replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0'); +function nuAddSlashes (s) { + return String(s).replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0') } - -function nuOpenTab(i) { - $('#nuTab' + i).click(); +function nuOpenTab (i) { + $('#nuTab' + i).click() } -function nuSelectedTabNumber(parent = null) { - - const t = parent === null ? window.nuFORM.getProperty('tab_start') : window.parent.nuFORM.getProperty('tab_start'); - return t.length == 0 ? null : t[0].tabNumber; - +function nuSelectedTabNumber (parent = null) { + const t = parent === null ? window.nuFORM.getProperty('tab_start') : window.parent.nuFORM.getProperty('tab_start') + return t.length == 0 ? null : t[0].tabNumber } -function nuSelectedTabId(parent = null) { - - const n = nuSelectedTabNumber(parent); - if (n === null) return null; - return parent === null ? $('#nuTab' + n).attr('data-nu-tab-id') : parent.$('#nuTab' + n).attr('data-nu-tab-id'); - +function nuSelectedTabId (parent = null) { + const n = nuSelectedTabNumber(parent) + if (n === null) return null + return parent === null ? $('#nuTab' + n).attr('data-nu-tab-id') : parent.$('#nuTab' + n).attr('data-nu-tab-id') } -function nuSelectedTab(parent = null) { - - const n = nuSelectedTabNumber(parent); - if (n === null) return null; - return parent === null ? $('#nuTab' + n) : parent.$('#nuTab' + n); - +function nuSelectedTab (parent = null) { + const n = nuSelectedTabNumber(parent) + if (n === null) return null + return parent === null ? $('#nuTab' + n) : parent.$('#nuTab' + n) } -function nuSelectedTabTitle(parent = null) { - - const n = nuSelectedTabNumber(parent) - if (n === null) return null; - return parent === null ? $('#nuTab' + n).html() : parent.$('#nuTab' + n).html(); - +function nuSelectedTabTitle (parent = null) { + const n = nuSelectedTabNumber(parent) + if (n === null) return null + return parent === null ? $('#nuTab' + n).html() : parent.$('#nuTab' + n).html() } -function nuSelectNextTab(i) { - - const selectedTab = $('.nuTabSelected')[0]; - const selectedTabId = selectedTab.id.substring(5); - const nextTabId = parseInt(selectedTabId, 10) + i; - const e = document.getElementById('nuTab' + nextTabId); - if (e) { - nuSelectTab(e); - } - +function nuSelectNextTab (i) { + const selectedTab = $('.nuTabSelected')[0] + const selectedTabId = selectedTab.id.substring(5) + const nextTabId = parseInt(selectedTabId, 10) + i + const e = document.getElementById('nuTab' + nextTabId) + if (e) { + nuSelectTab(e) + } } -function nuHideHolders(h) { - - for (let i = 0; i < arguments.length; i++) { - - if (arguments[i] == 0) { $('#nuActionHolder').hide(); } - if (arguments[i] == 1) { $('#nuBreadcrumbHolder').hide(); } - if (arguments[i] == 2) { $('#nuTabHolder').hide(); } - - } - +function nuHideHolders (h) { + for (let i = 0; i < arguments.length; i++) { + if (arguments[i] == 0) { $('#nuActionHolder').hide() } + if (arguments[i] == 1) { $('#nuBreadcrumbHolder').hide() } + if (arguments[i] == 2) { $('#nuTabHolder').hide() } + } } -function nuRemoveHolders(h) { - - for (let i = 0; i < arguments.length; i++) { - - if (arguments[i] == 0) { $('#nuActionHolder').remove(); } - if (arguments[i] == 1) { $('#nuBreadcrumbHolder').remove(); } - if (arguments[i] == 2) { $('#nuTabHolder').remove(); } - - } - +function nuRemoveHolders (h) { + for (let i = 0; i < arguments.length; i++) { + if (arguments[i] == 0) { $('#nuActionHolder').remove() } + if (arguments[i] == 1) { $('#nuBreadcrumbHolder').remove() } + if (arguments[i] == 2) { $('#nuTabHolder').remove() } + } } -function nuAttachFontAwesome(i, c, s, after) { - - const size = nuDefine(s, 'medium'); - - let o = '#' + i; - if (i instanceof jQuery) { - o = i; - } +function nuAttachFontAwesome (i, c, s, after) { + const size = nuDefine(s, 'medium') - const html = ''; - let obj = $(o); - if (obj.length === 0) return; + let o = '#' + i + if (i instanceof jQuery) { + o = i + } - let h = obj.html().trim(); - let nbsp = h.length == 0 ? '' : ' '; + const html = '' + const obj = $(o) + if (obj.length === 0) return - if (after === true) { - obj.append(nbsp + html); - } else { - obj.prepend(html + nbsp); - } + const h = obj.html().trim() + const nbsp = h.length == 0 ? '' : ' ' + if (after === true) { + obj.append(nbsp + html) + } else { + obj.prepend(html + nbsp) + } } -function nuAttachHTML(i, text, after) { - - let o = '#' + i; - if (i instanceof jQuery) { - o = i; - } - - if (after === true) { - $(o).append(' ' + text); - } else { - $(o).prepend(text + ' '); - } +function nuAttachHTML (i, text, after) { + let o = '#' + i + if (i instanceof jQuery) { + o = i + } + if (after === true) { + $(o).append(' ' + text) + } else { + $(o).prepend(text + ' ') + } } -function nuAttachFile(j, c) { - - if (window.nuGraphics.indexOf(c + '.png') != -1) { //-- check filenames in graphics dir. - - $(j) - .css('background-image', 'url("graphics/' + c + '.png') - .css('background-repeat', 'no-repeat') - .css('padding', '0px 0px 0px 0px') - .css('text-align', 'left') +function nuAttachFile (j, c) { + if (window.nuGraphics.indexOf(c + '.png') != -1) { // -- check filenames in graphics dir. + $(j) + .css('background-image', 'url("graphics/' + c + '.png') + .css('background-repeat', 'no-repeat') + .css('padding', '0px 0px 0px 0px') + .css('text-align', 'left') - return; + return + } - } - - if (nuImages[c] !== undefined) { - - var p = JSON.parse(g); - var b = atob(p.file); - - $(j) - .css('background-image', 'url("' + b + '")') - .css('background-repeat', 'no-repeat') - .css('padding', '0px 0px 0px 0px') - .css('text-align', 'left') - - return; - - } + if (nuImages[c] !== undefined) { + const p = JSON.parse(g) + const b = atob(p.file) + $(j) + .css('background-image', 'url("' + b + '")') + .css('background-repeat', 'no-repeat') + .css('padding', '0px 0px 0px 0px') + .css('text-align', 'left') + } } -function nuButtonIcon(j) { - - $(j).css({ - 'text-align': 'left', - 'padding': '0px 0px 0px 35px', - 'background-size': '30px', - 'background-repeat': 'no-repeat' - }); - +function nuButtonIcon (j) { + $(j).css({ + 'text-align': 'left', + padding: '0px 0px 0px 35px', + 'background-size': '30px', + 'background-repeat': 'no-repeat' + }) } -function nuChart(i, t, a, h, x, y, st, is) { +function nuChart (i, t, a, h, x, y, st, is) { + const obj = document.getElementById(i) + if (obj === null) return - let obj = document.getElementById(i); - if (obj === null) return; + a = eval(a) - a = eval(a); + if (a === undefined || a === '' || a.length === 0) { return } - if (a === undefined || a === '' || a.length === 0) { return; } + try { + google.charts.load('current', { packages: ['corechart'] }) + } catch (error) { + return + } - try { - google.charts.load('current', { 'packages': ['corechart'] }); - } catch (error) { - return; - } + google.charts.setOnLoadCallback(drawVisualization) - google.charts.setOnLoadCallback(drawVisualization); + function drawVisualization () { + const data = google.visualization.arrayToDataTable(a) + const wrapper = new google.visualization.ChartWrapper({ - function drawVisualization() { + chartType: t, + dataTable: data, + containerId: i, - let data = google.visualization.arrayToDataTable(a); - let wrapper = new google.visualization.ChartWrapper({ + options: { + title: h, + vAxis: { title: y }, + hAxis: { title: x }, + seriesType: st, + isStacked: is + } - chartType: t, - dataTable: data, - containerId: i, + }) - options: { - title: h, - vAxis: { title: y }, - hAxis: { title: x }, - seriesType: st, - isStacked: is, - } + var readyListener = google.visualization.events.addListener(wrapper, 'ready', function () { + if (window.nuChartOnReady) { + google.visualization.events.removeListener(readyListener) + nuChartOnReady(i, wrapper) + } + }) - }); - - var readyListener = google.visualization.events.addListener(wrapper, 'ready', function () { - if (window.nuChartOnReady) { - google.visualization.events.removeListener(readyListener); - nuChartOnReady(i, wrapper); - } - }); - - wrapper.draw(); - - window[i + '_wrapper'] = wrapper; - - } + wrapper.draw() + window[i + '_wrapper'] = wrapper + } } -function nuEncode(s) { - return window.btoa(unescape(encodeURIComponent(s))) +function nuEncode (s) { + return window.btoa(unescape(encodeURIComponent(s))) } -function nuDecode(s) { - return decodeURIComponent(escape(window.atob(s))) +function nuDecode (s) { + return decodeURIComponent(escape(window.atob(s))) } -function nuAddRow(s) { +function nuAddRow (s) { + const o = nuSubformObject(s) + let i = s + nuPad3(o.rows.length - 1) + o.fields[1] + $('#' + i).change() - const o = nuSubformObject(s); - let i = s + nuPad3(o.rows.length - 1) + o.fields[1]; - $('#' + i).change(); - - i = s + nuPad3(o.rows.length) + o.fields[1]; - - $('#' + i).focus(); + i = s + nuPad3(o.rows.length) + o.fields[1] + $('#' + i).focus() } -function nuAccessLevelGroup() { - return nuSERVERRESPONSE.access_level_group; +function nuAccessLevelGroup () { + return nuSERVERRESPONSE.access_level_group } -function nuAccessLevelCode() { - return nuSERVERRESPONSE.access_level_code; +function nuAccessLevelCode () { + return nuSERVERRESPONSE.access_level_code } -function nuAccessLevelId() { - return nuSERVERRESPONSE.access_level_id; +function nuAccessLevelId () { + return nuSERVERRESPONSE.access_level_id } -function nuUserName() { - return nuSERVERRESPONSE.user_name; +function nuUserName () { + return nuSERVERRESPONSE.user_name } -function nuUserPosition() { - return nuSERVERRESPONSE.user_position; +function nuUserPosition () { + return nuSERVERRESPONSE.user_position } -function nuUserDepartment() { - return nuSERVERRESPONSE.user_department; +function nuUserDepartment () { + return nuSERVERRESPONSE.user_department } -function nuUserA11Y() { - return nuSERVERRESPONSE.user_a11y; +function nuUserA11Y () { + return nuSERVERRESPONSE.user_a11y } -function nuUserTeam() { - return nuSERVERRESPONSE.user_team; +function nuUserTeam () { + return nuSERVERRESPONSE.user_team } -function nuUserCode() { - return nuSERVERRESPONSE.user_code; +function nuUserCode () { + return nuSERVERRESPONSE.user_code } -function nuUserAdditional1() { - return nuSERVERRESPONSE.user_additional1; +function nuUserAdditional1 () { + return nuSERVERRESPONSE.user_additional1 } -function nuUserAdditional2() { - return nuSERVERRESPONSE.user_additional2; +function nuUserAdditional2 () { + return nuSERVERRESPONSE.user_additional2 } -function nuUserId() { - return nuSERVERRESPONSE.user_id; +function nuUserId () { + return nuSERVERRESPONSE.user_id } -function nuUserLogin() { - return nuSERVERRESPONSE.login_name; +function nuUserLogin () { + return nuSERVERRESPONSE.login_name } -function nuUserLanguage() { - const l = nuSERVERRESPONSE.language; - return l === null ? '' : l; +function nuUserLanguage () { + const l = nuSERVERRESPONSE.language + return l === null ? '' : l } -function nuDatabase() { - return nuSERVERRESPONSE.database; +function nuDatabase () { + return nuSERVERRESPONSE.database } -function nuClosePopup() { - - parent.$('#nuModal').remove(); - parent.$('#nuDragDialog').remove(); - +function nuClosePopup () { + parent.$('#nuModal').remove() + parent.$('#nuDragDialog').remove() } -function nuStopClick(e) { - - if (window.nuCLICKER != '' && ((nuIsMacintosh() ? e.metaKey : e.ctrlKey) == false)) { - $(e.target).prop('onclick', null).off('click'); - } +function nuStopClick (e) { + if (window.nuCLICKER != '' && ((nuIsMacintosh() ? e.metaKey : e.ctrlKey) == false)) { + $(e.target).prop('onclick', null).off('click') + } } -function nuIsSaved() { - - return window.nuSAVED; +function nuIsSaved () { + return window.nuSAVED } -function nuAscendingSortColumn(a, b) { - - if (a.value < b.value) { return -1; } - if (a.value > b.value) { return 1; } - - return 0; +function nuAscendingSortColumn (a, b) { + if (a.value < b.value) { return -1 } + if (a.value > b.value) { return 1 } + return 0 } -function nuDecendingSortColumn(b, a) { - - if (a.value < b.value) { return -1; } - if (a.value > b.value) { return 1; } - - return 0; +function nuDecendingSortColumn (b, a) { + if (a.value < b.value) { return -1 } + if (a.value > b.value) { return 1 } + return 0 } -function nuAscendingSortNumberColumn(a, b) { - - if (Number(a.value) < Number(b.value)) { return -1; } - if (Number(a.value) > Number(b.value)) { return 1; } - - return 0; +function nuAscendingSortNumberColumn (a, b) { + if (Number(a.value) < Number(b.value)) { return -1 } + if (Number(a.value) > Number(b.value)) { return 1 } + return 0 } -function nuDecendingSortNumberColumn(b, a) { - - if (Number(a.value) < Number(b.value)) { return -1; } - if (Number(a.value) > Number(b.value)) { return 1; } - - return 0; +function nuDecendingSortNumberColumn (b, a) { + if (Number(a.value) < Number(b.value)) { return -1 } + if (Number(a.value) > Number(b.value)) { return 1 } + return 0 } -function nuEmbedObject(f, d, w, h) { - - if (f == '') { return; } +function nuEmbedObject (f, d, w, h) { + if (f == '') { return } - w = nuDefine(w, 300); - h = nuDefine(h, 300); + w = nuDefine(w, 300) + h = nuDefine(h, 300) - const obj = JSON.parse(f); - const type = obj.type; - const url = atob(obj.file); + const obj = JSON.parse(f) + const type = obj.type + const url = atob(obj.file) - var el = document.createElement("EMBED"); - el.setAttribute("type", type); - el.setAttribute("src", url); + const el = document.createElement('EMBED') + el.setAttribute('type', type) + el.setAttribute('src', url) - if (w !== -1) el.setAttribute("width", w + "px"); - if (h !== -1) el.setAttribute("height", h + "px"); - - $('#' + d).html(''); - document.getElementById(d).appendChild(el); + if (w !== -1) el.setAttribute('width', w + 'px') + if (h !== -1) el.setAttribute('height', h + 'px') + $('#' + d).html('') + document.getElementById(d).appendChild(el) } -function nuVendorLogin(appId) { - window.open("core/nuvendorlogin.php?sessid=" + window.nuSESSION + "&appId=" + appId + "&table=" + nuSERVERRESPONSE.table); +function nuVendorLogin (appId) { + window.open('core/nuvendorlogin.php?sessid=' + window.nuSESSION + '&appId=' + appId + '&table=' + nuSERVERRESPONSE.table) } -function nuIsMobile() { - return navigator.userAgent.toLowerCase().split('mobile').length > 1; +function nuIsMobile () { + return navigator.userAgent.toLowerCase().split('mobile').length > 1 } -function nuIsMacintosh() { - return /mac/i.test(navigator.userAgentData ? navigator.userAgentData.platform : navigator.platform); +function nuIsMacintosh () { + return /mac/i.test(navigator.userAgentData ? navigator.userAgentData.platform : navigator.platform) } -function nuTransformScale() { - - if ($('body').css('transform') == 'none') { - return 1; - } - - return Number($('body').css('transform').split('(')[1].split(',')[0]); +function nuTransformScale () { + if ($('body').css('transform') == 'none') { + return 1 + } + return Number($('body').css('transform').split('(')[1].split(',')[0]) } -function nuStopBrowserResize() { - - if (nuFormType() == 'browse') { - nuFORM.breadcrumbs[nuFORM.breadcrumbs.length - 1].refreshed = 1; - } - +function nuStopBrowserResize () { + if (nuFormType() == 'browse') { + nuFORM.breadcrumbs[nuFORM.breadcrumbs.length - 1].refreshed = 1 + } } -function nuDisableBrowseResize() { - - if (nuFormType() == 'browse') { - $("div[id^='nuBrowseTitle']") - .off('mousedown.nuresizecolumn') - .off('touchstart.nuresizecolumn') - .off('touchmove.nuresizecolumn') - .off('touchstart.nuresizecolumn'); - } - +function nuDisableBrowseResize () { + if (nuFormType() == 'browse') { + $("div[id^='nuBrowseTitle']") + .off('mousedown.nuresizecolumn') + .off('touchstart.nuresizecolumn') + .off('touchmove.nuresizecolumn') + .off('touchstart.nuresizecolumn') + } } -function nuDragTitleEvents() { - - if (nuFormType() != 'browse') { return; } +function nuDragTitleEvents () { + if (nuFormType() != 'browse') { return } - const colWidths = nuFORM.getCurrent().column_widths == 0 ? nuGetColumWidths() : nuFORM.getCurrent().column_widths; - nuSetBrowseColumns(colWidths); + const colWidths = nuFORM.getCurrent().column_widths == 0 ? nuGetColumWidths() : nuFORM.getCurrent().column_widths + nuSetBrowseColumns(colWidths) - $('#nubody').on('mousemove.nuresizecolumn', function (event) { nuDragBrowseColumn(event, 'pointer'); }); + $('#nubody').on('mousemove.nuresizecolumn', function (event) { nuDragBrowseColumn(event, 'pointer') }) - $('.nuBrowseTitle').on('mousedown.nuresizecolumn', function (event) { nuDownBrowseResize(event, 'pointer') }); + $('.nuBrowseTitle').on('mousedown.nuresizecolumn', function (event) { nuDownBrowseResize(event, 'pointer') }) - $('#nubody').on('mouseup.nuresizecolumn', function (event) { nuEndBrowseResize(); }); + $('#nubody').on('mouseup.nuresizecolumn', function (event) { nuEndBrowseResize() }) - $('.nuBrowseTitle').on('touchstart.nuresizecolumn', function (event) { nuDownBrowseResize(event, 'finger_touch'); }); + $('.nuBrowseTitle').on('touchstart.nuresizecolumn', function (event) { nuDownBrowseResize(event, 'finger_touch') }) - $('.nuBrowseTitle').on('touchmove.nuresizecolumn', function (event) { nuDragBrowseColumn(event, 'finger_touch'); }); + $('.nuBrowseTitle').on('touchmove.nuresizecolumn', function (event) { nuDragBrowseColumn(event, 'finger_touch') }) - $('.nuBrowseTitle').on('touchend.nuresizecolumn', function (event) { nuEndBrowseResize(event); }); - - $('.nuBrowseTitle').on('touchcancel.nuresizecolumn', function (event) { nuEndBrowseResize(event); }); + $('.nuBrowseTitle').on('touchend.nuresizecolumn', function (event) { nuEndBrowseResize(event) }) + $('.nuBrowseTitle').on('touchcancel.nuresizecolumn', function (event) { nuEndBrowseResize(event) }) } -function nuRemovePX(s) { - return Number(String(s).split('px')[0]); +function nuRemovePX (s) { + return Number(String(s).split('px')[0]) } -function nuImportUsersFromCSV(file, delimiter) { - - file = nuDefine(file, 'user_import.csv'); - - nuSetProperty('NUIMPORTUSERS_file', file); - nuSetProperty('NUIMPORTUSERS_delimiter', delimiter); +function nuImportUsersFromCSV (file, delimiter) { + file = nuDefine(file, 'user_import.csv') - nuRunPHP('NUIMPORTUSERS', '', 0); + nuSetProperty('NUIMPORTUSERS_file', file) + nuSetProperty('NUIMPORTUSERS_delimiter', delimiter) + nuRunPHP('NUIMPORTUSERS', '', 0) } -function nuIsIframe() { - - return parent.window.nuDocumentID != window.nuDocumentID && parent.window.nuDocumentID !== undefined; - +function nuIsIframe () { + return parent.window.nuDocumentID != window.nuDocumentID && parent.window.nuDocumentID !== undefined } // After clicking a button (Save, Delete, Print, Clone etc.), disable it for 1.3 secs to prevent a user from double-clicking it. -function nuPreventButtonDblClick() { - - $('.nuActionButton, .nuButton, #nuLogout').not(".nuAllowDblClick").click(function () { - const button = $(this); - if (button.hasClass('nuReadonly') || button.hasClass('nuAllowDblClick')) { - return; - } - - const id = button.attr("id"); - nuDisable(id); - - setTimeout(function () { - nuEnable(id); - }, 1300); - }); - -} - -function nuAddBackButton() { +function nuPreventButtonDblClick () { + $('.nuActionButton, .nuButton, #nuLogout').not('.nuAllowDblClick').click(function () { + const button = $(this) + if (button.hasClass('nuReadonly') || button.hasClass('nuAllowDblClick')) { + return + } - var b = $('.nuBreadcrumb').length; - if (b > 0) { - nuAddActionButton('BackBtn', nuTranslate('Back'), 'if (!nuFORM.edited) { nuDisable(this.id) }; nuOpenPreviousBreadcrumb();'); - } + const id = button.attr('id') + nuDisable(id) + setTimeout(function () { + nuEnable(id) + }, 1300) + }) +} + +function nuAddBackButton () { + const b = $('.nuBreadcrumb').length + if (b > 0) { + nuAddActionButton('BackBtn', nuTranslate('Back'), 'if (!nuFORM.edited) { nuDisable(this.id) }; nuOpenPreviousBreadcrumb();') + } } -function nuEnableBrowserBackButton() { - - window.history.pushState({ page: 1 }, "", ""); - window.onpopstate = function (event) { - if (event) { - nuOpenPreviousBreadcrumb(); - } - } - +function nuEnableBrowserBackButton () { + window.history.pushState({ page: 1 }, '', '') + window.onpopstate = function (event) { + if (event) { + nuOpenPreviousBreadcrumb() + } + } } -function nuSetBrowserTabTitle(prefix) { - - var t = window.nuFORM.getProperty('title'); - if (t === '') { - t = "Properties"; - } - prefix = prefix === '' ? '' : prefix + ' - '; - document.title = prefix + t; - +function nuSetBrowserTabTitle (prefix) { + let t = window.nuFORM.getProperty('title') + if (t === '') { + t = 'Properties' + } + prefix = prefix === '' ? '' : prefix + ' - ' + document.title = prefix + t } -function nuSetPlaceholder(i, placeholder, translate) { - - var $i = $('#' + i); - - translate = nuDefine(translate, true); +function nuSetPlaceholder (i, placeholder, translate) { + const $i = $('#' + i) - if (!placeholder) { - placeholder = $i.attr('data-nu-format').substring(2); - } else { - placeholder = translate ? nuTranslate(placeholder) : placeholder; - } + translate = nuDefine(translate, true) - $i.attr("placeholder", placeholder); + if (!placeholder) { + placeholder = $i.attr('data-nu-format').substring(2) + } else { + placeholder = translate ? nuTranslate(placeholder) : placeholder + } + $i.attr('placeholder', placeholder) } -function nuSetToolTip(i, message, labelHover) { +function nuSetToolTip (i, message, labelHover) { + // Show tooltip on object hover + $('#' + i).hover(function () { + $(this).attr('title', message) + }) - // Show tooltip on object hover - $("#" + i).hover(function () { - $(this).attr("title", message); - }); - - if (labelHover === true) { - // Show tooltip on label hover - $("#label_" + i).hover(function () { - $(this).attr("title", message); - }); - } + if (labelHover === true) { + // Show tooltip on label hover + $('#label_' + i).hover(function () { + $(this).attr('title', message) + }) + } } -function nuAddDatalist(i, arr, showAllOnArrowClick) { - - if (!$.isArray(arr)) { - console.error('Argument #2 is not an array in nuAddDatalist() for object ' + i); - return; - } - - var id = i + "_datalist"; - var datalist = document.getElementById(id); - - if (!datalist) { - datalist = document.createElement('datalist'); - datalist.id = id; - document.body.appendChild(datalist); - if (showAllOnArrowClick !== false) nuDatalistShowAllOnArrowClick(i); - } else { - datalist.innerHTML = ''; - } +function nuAddDatalist (i, arr, showAllOnArrowClick) { + if (!$.isArray(arr)) { + console.error('Argument #2 is not an array in nuAddDatalist() for object ' + i) + return + } - arr.forEach(function (data) { + const id = i + '_datalist' + let datalist = document.getElementById(id) - var option = document.createElement('option'); - option.value = $.isArray(data) ? data[0] : data; - if (data.length == 2) option.text = $.isArray(data) ? data[1] : data; - datalist.appendChild(option); - }); + if (!datalist) { + datalist = document.createElement('datalist') + datalist.id = id + document.body.appendChild(datalist) + if (showAllOnArrowClick !== false) nuDatalistShowAllOnArrowClick(i) + } else { + datalist.innerHTML = '' + } - $('#' + i).attr('list', datalist.id).attr('autocomplete', 'off'); + arr.forEach(function (data) { + const option = document.createElement('option') + option.value = $.isArray(data) ? data[0] : data + if (data.length == 2) option.text = $.isArray(data) ? data[1] : data + datalist.appendChild(option) + }) + $('#' + i).attr('list', datalist.id).attr('autocomplete', 'off') } -function nuLabelOnTop(include, exclude, offsetTop = -18, offsetLeft = 0) { - - if (include === undefined) { - include = []; - for (var i = 0; i < nuSERVERRESPONSE.objects.length; i++) { - include.push(nuSERVERRESPONSE.objects[i].id); - } - } - - if (exclude === undefined) var exclude = []; - - for (var i = 0; i < include.length; i++) { - - if (jQuery.inArray(include[i], exclude) == -1) { +function nuLabelOnTop (include, exclude, offsetTop = -18, offsetLeft = 0) { + if (include === undefined) { + include = [] + for (var i = 0; i < nuSERVERRESPONSE.objects.length; i++) { + include.push(nuSERVERRESPONSE.objects[i].id) + } + } - $('#' + 'label_' + include[i]).css({ - 'top': $('#' + include[i]).cssNumber('top') + offsetTop - , 'left': $('#' + include[i]).cssNumber('left') + offsetLeft - , 'text-align': 'left' - }); + if (exclude === undefined) var exclude = [] - $('#' + include[i]).attr('data-nu-label-position', 'top'); - - } - } + for (var i = 0; i < include.length; i++) { + if (jQuery.inArray(include[i], exclude) == -1) { + $('#' + 'label_' + include[i]).css({ + top: $('#' + include[i]).cssNumber('top') + offsetTop, + left: $('#' + include[i]).cssNumber('left') + offsetLeft, + 'text-align': 'left' + }) + $('#' + include[i]).attr('data-nu-label-position', 'top') + } + } } jQuery.fn.nuLabelOnTop = function (offsetTop = -18, offsetLeft = 0) { + return this.each(function () { + $('#' + 'label_' + this.id).css({ + top: $(this).cssNumber('top') + offsetTop, + left: $(this).cssNumber('left') + offsetLeft, + 'text-align': 'left' + }) - return this.each(function () { - - $('#' + 'label_' + this.id).css({ - 'top': $(this).cssNumber("top") + offsetTop - , 'left': $(this).cssNumber("left") + offsetLeft - , 'text-align': 'left' - }); - - $(this).attr('data-nu-label-position', 'top'); - - }); - -}; + $(this).attr('data-nu-label-position', 'top') + }) +} jQuery.fn.cssNumber = function (prop) { - - var v = parseInt(this.css(prop), 10); - return isNaN(v) ? 0 : v; - -}; - -function nuEnableDisableAllObjects(v, excludeTypes, excludeIds) { - - excludeTypes = nuDefine(excludeTypes, []); - excludeIds = nuDefine(excludeIds, []); - - const r = JSON.parse(JSON.stringify(nuSERVERRESPONSE)); - for (let i = 0; i < r.objects.length; i++) { - const obj = r.objects[i]; - - if ($.inArray(obj.type, excludeTypes) == -1 && $.inArray(obj.id, excludeIds) == -1 && obj.type !== 'contentbox') { - nuEnable(obj.id, v); - } - } - + const v = parseInt(this.css(prop), 10) + return isNaN(v) ? 0 : v } -function nuEnableAllObjects(excludeTypes, excludeIds) { +function nuEnableDisableAllObjects (v, excludeTypes, excludeIds) { + excludeTypes = nuDefine(excludeTypes, []) + excludeIds = nuDefine(excludeIds, []) - nuEnableDisableAllObjects(true, excludeTypes, excludeIds); + const r = JSON.parse(JSON.stringify(nuSERVERRESPONSE)) + for (let i = 0; i < r.objects.length; i++) { + const obj = r.objects[i] + if ($.inArray(obj.type, excludeTypes) == -1 && $.inArray(obj.id, excludeIds) == -1 && obj.type !== 'contentbox') { + nuEnable(obj.id, v) + } + } } -function nuDisableAllObjects(excludeTypes, excludeIds) { - - nuEnableDisableAllObjects(false, excludeTypes, excludeIds); - +function nuEnableAllObjects (excludeTypes, excludeIds) { + nuEnableDisableAllObjects(true, excludeTypes, excludeIds) } -function nuInsertTextAtCaret(i, text) { - - var o = $('#' + i); +function nuDisableAllObjects (excludeTypes, excludeIds) { + nuEnableDisableAllObjects(false, excludeTypes, excludeIds) +} - const textarea = o[0]; +function nuInsertTextAtCaret (i, text) { + const o = $('#' + i) - textarea.setRangeText( - text, - textarea.selectionStart, - textarea.selectionEnd, - 'end' - ); + const textarea = o[0] - o.change(); + textarea.setRangeText( + text, + textarea.selectionStart, + textarea.selectionEnd, + 'end' + ) + o.change() } -function nuObjectIdFromId(i) { +function nuObjectIdFromId (i) { + if (i !== null) { + const f = window.nuSERVERRESPONSE + let objId + for (let o = 0; o < f.objects.length; o++) { + if (f.objects[o].id == i) { + objId = f.objects[o].object_id + return objId + } + } + } - if (i !== null) { - - var f = window.nuSERVERRESPONSE; - var objId; - for (var o = 0; o < f.objects.length; o++) { - if (f.objects[o].id == i) { - objId = f.objects[o].object_id; - return objId; - } - } - } - - return null; + return null } /* @@ -2179,145 +1877,122 @@ function nuObjectIdFromId(i) { * @param {int} column - Column number (first column = 0, second column = 1 etc.) * @param {int} size - Size in pixels */ -function nuSetBrowseColumnSize(column, size) { - - var cw = this; - if (nuIsIframe()) { - cw = parent.$("#" + window.frameElement.id)[0].contentWindow; - } - cw.nuFORM.breadcrumbs[cw.nuFORM.breadcrumbs.length - 1].column_widths[column] = size; - cw.nuSetBrowseColumns(cw.nuFORM.breadcrumbs[cw.nuFORM.breadcrumbs.length - 1].column_widths) - +function nuSetBrowseColumnSize (column, size) { + let cw = this + if (nuIsIframe()) { + cw = parent.$('#' + window.frameElement.id)[0].contentWindow + } + cw.nuFORM.breadcrumbs[cw.nuFORM.breadcrumbs.length - 1].column_widths[column] = size + cw.nuSetBrowseColumns(cw.nuFORM.breadcrumbs[cw.nuFORM.breadcrumbs.length - 1].column_widths) } -function nuCreateAppendHTML(htmlStr) { - - var df = document.createDocumentFragment() - , temp = document.createElement('div'); - temp.innerHTML = htmlStr; - while (temp.firstChild) { - df.appendChild(temp.firstChild); - } - return df; +function nuCreateAppendHTML (htmlStr) { + const df = document.createDocumentFragment() + const temp = document.createElement('div') + temp.innerHTML = htmlStr + while (temp.firstChild) { + df.appendChild(temp.firstChild) + } + return df } -function nuSelectMultiWithoutCtrl(i, active) { - - var id = i === undefined || i === null ? 'select' : '#' + i; - - if (active == false) { - $(id + "[multiple] option").off('mousedown.selectmultinoctrl'); - return; - } +function nuSelectMultiWithoutCtrl (i, active) { + const id = i === undefined || i === null ? 'select' : '#' + i - $(id + "[multiple] option").on('mousedown.selectmultinoctrl', function (event) { - if (event.shiftKey) return; - event.preventDefault(); - this.focus(); - var scroll = this.scrollTop; - event.target.selected = !event.target.selected; - this.scrollTop = scroll; - $(this).parent().change(); - }); + if (active == false) { + $(id + '[multiple] option').off('mousedown.selectmultinoctrl') + return + } + $(id + '[multiple] option').on('mousedown.selectmultinoctrl', function (event) { + if (event.shiftKey) return + event.preventDefault() + this.focus() + const scroll = this.scrollTop + event.target.selected = !event.target.selected + this.scrollTop = scroll + $(this).parent().change() + }) } -function nuSelectRemoveEmpty(i, setIndex) { +function nuSelectRemoveEmpty (i, setIndex) { + const id = i === undefined ? 'select' : '#' + i - let id = i === undefined ? 'select' : '#' + i; - - $(id + ' option').filter(function () { - return ($(this).val().trim() === "" && $(this).text().trim() === ""); - }).remove(); - - if (setIndex !== undefined) $('#' + i).prop('selectedIndex', setIndex); + $(id + ' option').filter(function () { + return ($(this).val().trim() === '' && $(this).text().trim() === '') + }).remove() + if (setIndex !== undefined) $('#' + i).prop('selectedIndex', setIndex) } -function nuSelectRemoveOption(i, value) { - - var o; - if (typeof i !== 'object') { - o = $('#' + i) || i; - } else { - o = i; - } - - o.find('[value="' + value + '"]').remove(); - return o; +function nuSelectRemoveOption (i, value) { + let o + if (typeof i !== 'object') { + o = $('#' + i) || i + } else { + o = i + } + o.find('[value="' + value + '"]').remove() + return o } -function nuSelectRemoveMultiple(i) { - - var id = i === undefined || i === null ? 'select' : '#' + i; - $(id + "[multiple]").removeAttr('multiple').attr('size', '5'); - +function nuSelectRemoveMultiple (i) { + const id = i === undefined || i === null ? 'select' : '#' + i + $(id + '[multiple]').removeAttr('multiple').attr('size', '5') } -function nuSelectSelectAll(id, value) { - - if (value === undefined) var value = true; - - $("#" + id).find('option:not(:empty)').prop('selected', value); - $("#" + id).change(); +function nuSelectSelectAll (id, value) { + if (value === undefined) var value = true + $('#' + id).find('option:not(:empty)').prop('selected', value) + $('#' + id).change() } -function nuSelectSelectedValueArray(id) { - - var a = []; - $('#' + id + ' option:selected').each(function (index) { - if ($(this).val() !== '') { - a.push($(this).val()) - } - }); - - return a; +function nuSelectSelectedValueArray (id) { + const a = [] + $('#' + id + ' option:selected').each(function (index) { + if ($(this).val() !== '') { + a.push($(this).val()) + } + }) + return a } -function nuSelectSelectedTextArray(id) { - - var a = []; - $('#' + id + ' option:selected').each(function (index) { - if ($(this).val() !== '') { - a.push($(this).text()) - } - }); - - return a; +function nuSelectSelectedTextArray (id) { + const a = [] + $('#' + id + ' option:selected').each(function (index) { + if ($(this).val() !== '') { + a.push($(this).text()) + } + }) + return a } -function nuPasteText(i) { - - navigator.clipboard.readText() - .then(text => { - $('#' + i).val(text); - }); - +function nuPasteText (i) { + navigator.clipboard.readText() + .then(text => { + $('#' + i).val(text) + }) } -function nuCopyText(i) { - return nuCopyToClipboard($('#' + i).val()); +function nuCopyText (i) { + return nuCopyToClipboard($('#' + i).val()) } -function nuCopyToClipboard(s) { - - navigator.clipboard.writeText(s).then(function () { - return true; - }, function () { - return false; - }); - +function nuCopyToClipboard (s) { + navigator.clipboard.writeText(s).then(function () { + return true + }, function () { + return false + }) } -function nuCursor(c) { - - document.documentElement.style.cursor = c; - parent.document.documentElement.style.cursor = c; - +function nuCursor (c) { + document.documentElement.style.cursor = c + parent.document.documentElement.style.cursor = c } /* *** Based on highlight v5: Highlights arbitrary terms. @@ -2328,358 +2003,320 @@ function nuCursor(c) { */ jQuery.fn.nuHighlight = function (pat) { - function innerHighlight(node, pat) { - var skip = 0; - if (node.nodeType == 3) { - var pos = node.data.toUpperCase().indexOf(pat); - pos -= (node.data.substr(0, pos).toUpperCase().length - node.data.substr(0, pos).length); - if (pos >= 0) { - let spannode = document.createElement('span'); - spannode.className = 'nuBrowseSearch'; - let middlebit = node.splitText(pos); - const middleclone = middlebit.cloneNode(true); - spannode.appendChild(middleclone); - middlebit.parentNode.replaceChild(spannode, middlebit); - skip = 1; - } - } else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) { - for (var i = 0; i < node.childNodes.length; ++i) { - i += innerHighlight(node.childNodes[i], pat); - } - } - return skip; - } - return this.length && pat && pat.length ? this.each(function () { - innerHighlight(this, pat.toUpperCase()); - }) : this; -}; - -function nuInputMaxLength(id, maxLength, labelId) { - - const $input = $('#' + id); - $input.attr('maxlength', maxLength); - - if (labelId) { - const $label = $('#' + labelId); - $label.html(`${maxLength}/${maxLength}`); - $input.on('input', function() { - const textLen = maxLength - this.value.length; - $label.html(`${textLen}/${maxLength}`); - }); - } - -} - -function nuDebugMode() { - return nuUXOptions["nuDebugMode"]; -} - -function nuDebugOut(obj, i) { - - if (nuDebugMode() && obj.length == 0) { - console.warn(nuTranslate('Object does not exist:'), i); - return true; - } - - return false; - -} - -function nuGetValue(i, method) { - - var obj = $('#' + i); - if (i === undefined || nuDebugOut(obj, i)) return null; - - if (obj.is(':checkbox')) return obj.is(":checked"); - if (obj.is('select') && method === 'text') return $("#" + i + " option:selected").text().fixNbsp(); - if (method === undefined && obj.is(':button')) return obj.text(); - - switch (method) { - case 'html': - return obj.html(); - case 'val': - return obj.val(); - case 'text': - return obj.text(); - default: - return obj.val(); - } - -} - -function nuGetText(i, method) { - return nuGetValue(i, 'text'); -} - -function nuSetValue(i, v, method, change) { - - var obj = $('#' + i); - - if (i === undefined || nuDebugOut(obj, i)) return false; - - change = (change || change === undefined); - - if (method === undefined && obj.is(':button')) { - obj.text(v); - } else if (obj.is(':checkbox')) { - if (change) obj.prop('checked', v).change(); - } else if (obj.is('select') && method === 'text') { - $('#' + i + ' option').each(function () { - if ($(this).text().fixNbsp() === v) { - $(this).prop("selected", "selected"); - if (change) obj.change(); - return true; - } - }); - - } else { - - switch (method) { - case 'html': - obj.html(v); - break; - case 'text': - obj.text(v); - break; - default: - obj.val(v); - if (change) obj.change(); - } - } - - return true; - -} - -function nuSetText(i, v) { - return nuSetValue(i, v, 'text'); -} - -function nuCurrentDate(format) { - - let d = new Date(); - let - yyyy = d.getFullYear(), - mm = nuPad2(d.getMonth() + 1), - dd = nuPad2(d.getDate()); - - let df = yyyy + '-' + mm + '-' + dd; - if (format !== undefined) { - df = nuFORM.addFormatting(df, 'D|' + format); - } - - return df; + function innerHighlight (node, pat) { + let skip = 0 + if (node.nodeType == 3) { + let pos = node.data.toUpperCase().indexOf(pat) + pos -= (node.data.substr(0, pos).toUpperCase().length - node.data.substr(0, pos).length) + if (pos >= 0) { + const spannode = document.createElement('span') + spannode.className = 'nuBrowseSearch' + const middlebit = node.splitText(pos) + const middleclone = middlebit.cloneNode(true) + spannode.appendChild(middleclone) + middlebit.parentNode.replaceChild(spannode, middlebit) + skip = 1 + } + } else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) { + for (let i = 0; i < node.childNodes.length; ++i) { + i += innerHighlight(node.childNodes[i], pat) + } + } + return skip + } + return this.length && pat && pat.length + ? this.each(function () { + innerHighlight(this, pat.toUpperCase()) + }) + : this +} + +function nuInputMaxLength (id, maxLength, labelId) { + const $input = $('#' + id) + $input.attr('maxlength', maxLength) + + if (labelId) { + const $label = $('#' + labelId) + $label.html(`${maxLength}/${maxLength}`) + $input.on('input', function () { + const textLen = maxLength - this.value.length + $label.html(`${textLen}/${maxLength}`) + }) + } +} + +function nuDebugMode () { + return nuUXOptions.nuDebugMode +} + +function nuDebugOut (obj, i) { + if (nuDebugMode() && obj.length == 0) { + console.warn(nuTranslate('Object does not exist:'), i) + return true + } + + return false +} + +function nuGetValue (i, method) { + const obj = $('#' + i) + if (i === undefined || nuDebugOut(obj, i)) return null + + if (obj.is(':checkbox')) return obj.is(':checked') + if (obj.is('select') && method === 'text') return $('#' + i + ' option:selected').text().fixNbsp() + if (method === undefined && obj.is(':button')) return obj.text() + + switch (method) { + case 'html': + return obj.html() + case 'val': + return obj.val() + case 'text': + return obj.text() + default: + return obj.val() + } +} + +function nuGetText (i, method) { + return nuGetValue(i, 'text') +} + +function nuSetValue (i, v, method, change) { + const obj = $('#' + i) + + if (i === undefined || nuDebugOut(obj, i)) return false + + change = (change || change === undefined) + + if (method === undefined && obj.is(':button')) { + obj.text(v) + } else if (obj.is(':checkbox')) { + if (change) obj.prop('checked', v).change() + } else if (obj.is('select') && method === 'text') { + $('#' + i + ' option').each(function () { + if ($(this).text().fixNbsp() === v) { + $(this).prop('selected', 'selected') + if (change) obj.change() + return true + } + }) + } else { + switch (method) { + case 'html': + obj.html(v) + break + case 'text': + obj.text(v) + break + default: + obj.val(v) + if (change) obj.change() + } + } + + return true +} + +function nuSetText (i, v) { + return nuSetValue(i, v, 'text') +} + +function nuCurrentDate (format) { + const d = new Date() + const + yyyy = d.getFullYear() + const mm = nuPad2(d.getMonth() + 1) + const dd = nuPad2(d.getDate()) + let df = yyyy + '-' + mm + '-' + dd + if (format !== undefined) { + df = nuFORM.addFormatting(df, 'D|' + format) + } + + return df }; -function nuCurrentDateTime(format) { - - let d = new Date(); - let - yyyy = d.getFullYear(), - mm = nuPad2(d.getMonth() + 1), - dd = nuPad2(d.getDate()), - hh = nuPad2(d.getHours()), - nn = nuPad2(d.getMinutes()), - ss = nuPad2(d.getSeconds()); - - let df = yyyy + '-' + mm + '-' + dd + ' ' + hh + ':' + nn + ':' + ss; - if (format !== undefined) { - df = nuFORM.addFormatting(df, 'D|' + format); - } - - return df; - +function nuCurrentDateTime (format) { + const d = new Date() + const + yyyy = d.getFullYear() + const mm = nuPad2(d.getMonth() + 1) + const dd = nuPad2(d.getDate()) + const hh = nuPad2(d.getHours()) + const nn = nuPad2(d.getMinutes()) + const ss = nuPad2(d.getSeconds()) + + let df = yyyy + '-' + mm + '-' + dd + ' ' + hh + ':' + nn + ':' + ss + if (format !== undefined) { + df = nuFORM.addFormatting(df, 'D|' + format) + } + + return df }; -function nuSetDateValue(i, d) { - - var obj = $('#' + i); +function nuSetDateValue (i, d) { + const obj = $('#' + i) - if (i === undefined || nuDebugOut(obj, i)) return false; + if (i === undefined || nuDebugOut(obj, i)) return false - if (d === undefined) { - var d = new Date(); - } + if (d === undefined) { + var d = new Date() + } - var df = d.getFullYear() + '-' + nuPad2(d.getMonth() + 1) + '-' + nuPad2(d.getDate()); + const df = d.getFullYear() + '-' + nuPad2(d.getMonth() + 1) + '-' + nuPad2(d.getDate()) - var format = obj.attr('data-nu-format'); - obj.val(nuFORM.addFormatting(df, format)).change(); - - return true; + const format = obj.attr('data-nu-format') + obj.val(nuFORM.addFormatting(df, format)).change() + return true } -function nuArrayIsUnique(arr) { - return arr.length === new Set(arr).size; +function nuArrayIsUnique (arr) { + return arr.length === new Set(arr).size } -function nuArrayColumn(arr, n) { - return arr.map(x => x[n]); +function nuArrayColumn (arr, n) { + return arr.map(x => x[n]) } -function nuBase64decode(str) { - - const text = atob(str); - const length = text.length; - const bytes = new Uint8Array(length); +function nuBase64decode (str) { + const text = atob(str) + const length = text.length + const bytes = new Uint8Array(length) - for (let i = 0; i < length; i++) { - bytes[i] = text.charCodeAt(i); - } - - const decoder = new TextDecoder(); // default is utf-8 - return decoder.decode(bytes); + for (let i = 0; i < length; i++) { + bytes[i] = text.charCodeAt(i) + } + const decoder = new TextDecoder() // default is utf-8 + return decoder.decode(bytes) } -function nuBase64encode(str) { - - let encode = encodeURIComponent(str).replace(/%([a-f0-9]{2})/gi, (m, $1) => String.fromCharCode(parseInt($1, 10))) - return btoa(encode); - +function nuBase64encode (str) { + const encode = encodeURIComponent(str).replace(/%([a-f0-9]{2})/gi, (m, $1) => String.fromCharCode(parseInt($1, 10))) + return btoa(encode) } -function nuOpenWiki(page) { - window.open('https://wiki.nubuilder.cloud/index.php' + page); +function nuOpenWiki (page) { + window.open('https://wiki.nubuilder.cloud/index.php' + page) } -function nuSetLabelText(i, str, translate) { - - if (translate === true) { str = nuTranslate(str); } +function nuSetLabelText (i, str, translate) { + if (translate === true) { str = nuTranslate(str) } - let label = $('#label_' + i); - let lwidth = nuGetWordWidth(str); + const label = $('#label_' + i) + const lwidth = nuGetWordWidth(str) - let obj = $('#' + i); - let left = obj.cssNumber('left'); - let top = obj.cssNumber('top'); + const obj = $('#' + i) + const left = obj.cssNumber('left') + const top = obj.cssNumber('top') - label.css({ - 'top': Number(top), - 'left': Number(left) - lwidth - 17, - 'width': Number(lwidth + 12) - }).html(str); - - if (obj.attr('data-nu-label-position') == 'top') { - obj.nuLabelOnTop(); - } + label.css({ + top: Number(top), + left: Number(left) - lwidth - 17, + width: Number(lwidth + 12) + }).html(str) + if (obj.attr('data-nu-label-position') == 'top') { + obj.nuLabelOnTop() + } } -function nuRunBackup() { - - if (! nuGlobalAccess()) return; - - const c = confirm(nuTranslate("Perform the Backup now?")); - if (c === true) { - nuMessage(nuTranslate("Backup is running") + "..."); - nuRunPHPHidden("NUBACKUP", 0); - } +function nuRunBackup () { + if (!nuGlobalAccess()) return + const c = confirm(nuTranslate('Perform the Backup now?')) + if (c === true) { + nuMessage(nuTranslate('Backup is running') + '...') + nuRunPHPHidden('NUBACKUP', 0) + } } -function nuAddCSSStyle(styleString, id) { - - let i = id === undefined ? 'nucssstyle' : id; - $('#' + i).remove(); - - let regex = /( |<([^>]+)>)/ig; - styleString = styleString.replace(regex, ""); +function nuAddCSSStyle (styleString, id) { + const i = id === undefined ? 'nucssstyle' : id + $('#' + i).remove() - if (styleString.trim() === '') return; + const regex = /( |<([^>]+)>)/ig + styleString = styleString.replace(regex, '') - let css = document.createElement('style'); - css.id = i; - css.appendChild(document.createTextNode(styleString)); - document.getElementsByTagName("head")[0].appendChild(css); + if (styleString.trim() === '') return + const css = document.createElement('style') + css.id = i + css.appendChild(document.createTextNode(styleString)) + document.getElementsByTagName('head')[0].appendChild(css) } -function nuObjectClassList(i) { - - let c = $('#' + i).attr('class'); - return c === undefined ? '' : c.split(/\s+/).join(' '); - +function nuObjectClassList (i) { + const c = $('#' + i).attr('class') + return c === undefined ? '' : c.split(/\s+/).join(' ') } -function nuGetStorageItem(key, storage) { - - var storage = storage === undefined || storage === 'session' ? window.sessionStorage : window.localStorage; - - const itemStr = storage.getItem(key) +function nuGetStorageItem (key, storage) { + var storage = storage === undefined || storage === 'session' ? window.sessionStorage : window.localStorage - if (!itemStr) { - return null - } + const itemStr = storage.getItem(key) - const item = JSON.parse(itemStr) - const now = new Date() + if (!itemStr) { + return null + } - if (now.getTime() > item.expiry && item.expiry !== null) { - storage.removeItem(key) - return null - } - return item.value; + const item = JSON.parse(itemStr) + const now = new Date() + if (now.getTime() > item.expiry && item.expiry !== null) { + storage.removeItem(key) + return null + } + return item.value } -function nuSetStorageItem(key, value, storage, ttl) { - - var storage = storage === undefined || storage === 'session' ? window.sessionStorage : window.localStorage; - - const now = new Date() - const item = { - value: value, - expiry: ttl === undefined ? null : now.getTime() + ttl * 1000, - } - storage.setItem(key, JSON.stringify(item)); +function nuSetStorageItem (key, value, storage, ttl) { + var storage = storage === undefined || storage === 'session' ? window.sessionStorage : window.localStorage + const now = new Date() + const item = { + value, + expiry: ttl === undefined ? null : now.getTime() + ttl * 1000 + } + storage.setItem(key, JSON.stringify(item)) } -function nuCtrlCmdShiftName(keyName) { - - if (keyName === '') return ''; - const modifier = nuIsMacintosh() ? 'Cmd' : 'Ctrl'; - return modifier + '+Shift+' + keyName; - +function nuCtrlCmdShiftName (keyName) { + if (keyName === '') return '' + const modifier = nuIsMacintosh() ? 'Cmd' : 'Ctrl' + return modifier + '+Shift+' + keyName } -function nuDateIsValid(date) { - - return ( - Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date) - ); - +function nuDateIsValid (date) { + return ( + Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date) + ) } -function nuEscapeHTML(string) { - - if (typeof string !== 'string') return ''; - - let replacements= {"<": "<", ">": ">","&": "&", '"': ""","'": "'"}; - return string.replace(/[<>&"]/g, function(character) { - return replacements[character]; - }); +function nuEscapeHTML (string) { + if (typeof string !== 'string') return '' + const replacements = { '<': '<', '>': '>', '&': '&', '"': '"', "'": ''' } + return string.replace(/[<>&"]/g, function (character) { + return replacements[character] + }) } -function nuDelay(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); +function nuDelay (ms) { + return new Promise(resolve => setTimeout(resolve, ms)) } -function nuInsertAtCaret(id, string) { - - const txt = $('#' + id); - const caretPos = txt[0].selectionStart; - const value = txt.val(); - - txt.val(value.substring(0, caretPos) + string + value.substring(caretPos)); - txt.focus(); +function nuInsertAtCaret (id, string) { + const txt = $('#' + id) + const caretPos = txt[0].selectionStart + const value = txt.val() - const endOfText = caretPos + string.length; - txt.prop('selectionStart', endOfText); - txt.prop('selectionEnd', endOfText); + txt.val(value.substring(0, caretPos) + string + value.substring(caretPos)) + txt.focus() + const endOfText = caretPos + string.length + txt.prop('selectionStart', endOfText) + txt.prop('selectionEnd', endOfText) } diff --git a/core/nuform.js b/core/nuform.js index 498241f..c9fdb55 100644 --- a/core/nuform.js +++ b/core/nuform.js @@ -1,6823 +1,5926 @@ -function nuInitJSOptions() { - - if (window.nuAdminButtons === undefined) { - - window.nuAdminButtons = - { - 'nuDebug': true, - 'nuPHP': true, - 'nuRefresh': true, - 'nuObjects': true, - 'nuProperties': true - }; - - } - - if (window.nuUXOptions === undefined) { - - window.nuUXOptions = - { - 'nuEnableBrowserBackButton': true, // Enable the browser's Back button - 'nuPreventButtonDblClick': true, // Disable a button for 1 5 s to prevent a double click - 'nuShowPropertiesOnMiddleClick': true, // Show the Object Properties on middle mouse click - 'nuAutosizeBrowseColumns': true, // Autosize columns to fit the document width - 'nuShowBackButton': false, // Show a Back Button - 'nuMobileView': false, // Optimise view for mobile devices - 'nuBrowsePaginationInfo': 'default', // Default Format is: '{StartRow} - {EndRow} ' + nuTranslate('of') + ' ' + '{TotalRows}' - 'nuShowNuBuilderLink': true, // Show the link to nubuilder com - 'nuShowLoggedInUser': false, // Show the logged in User - 'nuShowBrowserTabTitle': true, // Show the Form Title in the Browser Tab - 'nuDebugMode': true, // Debug Mode - 'nuBrowserTabTitlePrefix': 'nuBuilder', // Prefix in the Browser Tab - 'nuCalendarStartOfWeek': 'Sunday', // nuCalendar: Start of Week: Sunday (default) or Monday - 'nuSelect2Theme': 'default', // select2 theme (default, classic) Default: default - 'nuEditCloseAfterSave': 'None' // Close forms after saving. Values: None, All, User, System - }; - - } - -} - -nuInitJSOptions(); - -var promot; - -function nuBuildForm(f) { - - window.nuOnSetSelect2Options = null; - window.nuSERVERRESPONSE = f; // can be overwritten by nuAddJavaScript() - - if (f.record_id != '-2') { - nuAddJavaScript(f.javascript_bc); - } - - $('#nubody').off('.nuresizecolumn').css('transform', 'scale(1)'); - $('html,body').scrollTop(0).scrollLeft(0); - - nuSetProperty('CLONED_RECORD', 0); - nuSetProperty('NEW_RECORD', 0); - - const formType = nuFormType(); - - if (f.tableSchema === null) { //-- need to login again - - $('body').addClass('nuBrowseBody').removeClass('nuEditBody'); - - sessionStorage.logout = 'true'; - parent.parent.parent.parent.parent.location.reload(); - - nuCursor('default'); - return; - - } - - if (formType == 'edit' && nuCurrentProperties().form_type !== 'launch') { - - window.nuTimesSaved = window.nuTimesSaved + 1; - - if (window.nuLastForm != f.form_id || (nuLastRecordId != f.record_id && nuLastRecordId !== "-1")) { - window.nuTimesSaved = 0; - } - - } else { - window.nuTimesSaved = -1; - } - - window.nuLastForm = f.form_id; - window.nuLastRecordId = f.record_id; - window.nuSubformRow = -1; - window.nuBrowseNoData = false; - window.nuBrowseNoSearchResults = false; - window.nuBeforeSave = null; - window.nuAfterSave = null; - window.nuBeforeDelete = null; - window.nuAfterDelete = null; - window.nuOnSearchAction = null; - window.nuOnClone = null; - window.nuOnEditorLoad = null; - window.nuOnBeforeGetBreadcrumb = null; - window.nuOnSetSaved = null; - window.nuOnTabSelected = null; - window.nuOnSelectTab = null; - window.nuOnAddAction = false; - window.onSubformTitleClick = null; - window.nuOnMessage = null; - window.nuFormatValueCleared = null; - window.nuDisplayObjectRefreshed = null; - window.nuOnSetCalendarOptions = null; - window.nuOnLookupPopulated = null; - window.nuCalculated = null; - window.nuOnPropertySet = null; - window.nuEnableCalculation = null; - window.nuPortraitScreenShowTabTitles = true; - window.nuBrowseFunction = window.nuDefaultBrowseFunction; - window.nuCLONE = false; - window.nuSERVERRESPONSELU = []; - window.nuSESSION = f.session_id; - window.nuSUBFORMROW = []; - window.nuHASH = []; //-- remove any hash variables previously set. - window.nuTABHELP = []; - window.nuFORMHELP = []; - window.nuLOOKUPSTATE = []; - window.nuBROWSEROW = -1; - window.nuBROWSECLICKED = false; - window.nuUniqueID = 'c' + String(Date.now()); - window.global_access = f.global_access == '1'; - nuFORM.edited = false; - window.nuVerticalTabs = false; - - if (nuHasBeenSaved() >= 1 && nuGetProperty('nuEditCloseAfterSave') != '0') { - - const closeAfterSave = nuUXOptions.nuEditCloseAfterSave; - let doClose = false; - if (closeAfterSave || nuGetProperty('nuEditCloseAfterSave') == '1') { - if (closeAfterSave == 'AllForms') doClose = nuCloseAfterSave(); - if (closeAfterSave == 'UserForms' && !f.form_id.startsWith('nu')) nuCloseAfterSave(); - if (closeAfterSave == 'SystemForms' && !f.form_id.startsWith('nu')) nuCloseAfterSave(); - } - - if (doClose) return; - - } - - nuFORM.scroll = []; - nuSetSuffix(1000); - nuSetBody(f); - - nuRedefine_nuSelectBrowse(); - - nuFORM.tableSchema = f.tableSchema; - nuFORM.formSchema = f.formSchema; - window.nuLANGUAGE = f.translation; - - nuSetProperty('refreshed', nuGetProperty('refreshed') + 1); - - var b = window.nuFORM.getCurrent(); - - nuAddedByLookup(f); - - b.form_id = f.form_id; - b.record_id = f.record_id; - b.session_id = f.session_id; - b.user_id = f.user_id; - b.redirect_form_id = f.redirect_form_id; - b.redirect_other_form_id = f.redirect_other_form_id; - b.title = f.title; - b.row_height = f.row_height; - b.rows = f.rows; - b.browse_columns = f.browse_columns; - b.browse_sql = f.browse_sql; - b.browse_rows = f.browse_rows; - b.browse_table_id = f.browse_table_id; - b.browse_filtered_rows = f.browse_height; - b.browse_title_multiline = f.browse_title_multiline; - b.browse_autoresize_columns = f.browse_autoresize_columns; - b.mobile_view = f.mobile_view; - b.pages = f.pages; - b.form_code = f.form_code; - b.form_description = f.form_description; - b.form_type = f.form_type; - b.run_code = f.run_code; - b.run_description = f.run_description; - b.data_mode = f.data_mode; - - nuAddHolder('nuBreadcrumbHolder'); - nuAddHomeLogout(); - nuAddHolder('nuActionHolder'); - - if (formType == 'edit') { - nuAddHolder('nuTabHolder'); - } - - nuAddHolder('nuRECORD'); - $('#nuRECORD') - .attr('data-nu-table', f.table) - .attr('data-nu-primary-key-name', f.primary_key); - - nuAddBreadcrumbs(); - - nuAddEditTabs('', f); - - if (typeof window.nuBeforeAddActionButtons === 'function') { - nuBeforeAddActionButtons(); - } - - nuAddActionButtons(f); - nuRecordProperties(f, ''); - - let obj0 = null; - - if (formType == 'edit') { - - nuOptions('', f.form_id, 'form', f.global_access); - nuBuildEditObjects(f, '', '', f); - nuResizeFormDialogCoordinates(); - nuCalculateForm(false); - - obj0 = nuGetFirstObject(f.objects, -1); - - } - - nuGetStartingTab(); - - if (formType == 'edit' && nuIsNewRecord() && (obj0 !== null)) { - obj0.nuFocusWithoutScrolling(); - } - - if (f.record_id == '-2') { // Arrange Objects - nuCreateDragOptionsBox(f); - } else { - nuAddJavaScript(f.javascript); - } - - nuDragTitleEvents(); - - if (window.nuLoginH != '') { - - let bc = $('#nuBreadcrumb0').length > 0 ? $('#nuBreadcrumb0') : $('#nuHomeGap'); - bc - .html('') - .attr('title', nuTranslate('Home')) - .attr('onclick', '') - .attr('onclick', 'nuForm("' + window.nuLoginH + '", -1, "", "", 1);') - .css('cursor', 'pointer'); - - window.nuLoginH = ''; - - } - - if (window.nuOnEditorLoad) { - nuOnEditorLoad(); - } else { - $('.nuEditor').each((index, element) => { - nuInitTinyMCE(element.id); - }); - } - - nuEvalnuOnLoadEvents(); - - if (window.nuLoadEditGlobal && formType == 'edit') { - nuLoadEditGlobal(f.form_id, f.form_code); - } - - if (window.nuLoadBrowseGlobal && formType == 'browse') { - nuLoadBrowseGlobal(f.form_id, f.form_code); - } - - if (window.nuOnLoad) { - nuOnLoad(f.form_id, f.form_code); - } - - if (formType == 'edit') { - window.nuRESPONSIVE.getStartPositions(); - } else { - - if (b.browse_autoresize_columns !== '0' || nuDocumentID !== parent.nuDocumentID) { - - if (nuUXOptions.nuAutosizeBrowseColumns || b.browse_autoresize_columns === '1' || nuDocumentID !== parent.nuDocumentID) { - nuResizeBrowseColumns(); - } - - } - } - - if (nuUXOptions.nuShowBrowserTabTitle) { - nuSetBrowserTabTitle(nuUXOptions.nuBrowserTabTitlePrefix); - } else { - document.title = nuUXOptions.nuBrowserTabTitlePrefix; - } - - if (Object.keys(window.nuAdminButtons).length) { - nuAddAdminButtons(); - } - - if (nuUXOptions.nuEnableBrowserBackButton) { - nuEnableBrowserBackButton(); - } - - if (nuUXOptions.nuPreventButtonDblClick) { - nuPreventButtonDblClick(); - } - - if (nuUXOptions.nuShowBackButton) { - nuAddBackButton(); - } - - if (nuUXOptions.nuShowPropertiesOnMiddleClick) { - document.addEventListener("mousedown", nuOpenPropertiesOnMiddleClick, { passive: true }); - } - - if ((nuUXOptions.nuBrowsePaginationInfo) !== '') { - nuShowBrowsePaginationInfo((nuUXOptions.nuBrowsePaginationInfo)); - } - - if (nuUXOptions.nuShowLoggedInUser) { - nuDisplayLoggedInUser(); - } else - if (!nuUXOptions.nuShowNuBuilderLink) { - $('.nuBuilderLink').remove(); - } - - nuInitSetBrowseWidthHelper(); - - if (window.nuMESSAGES.length > 0) { - - let msgDiv = nuMessage(window.nuMESSAGES); - - if (window.nuOnMessage) { - nuOnMessage(msgDiv, window.nuMESSAGES); - } - - window.nuMESSAGES = []; - - } - - if (window.nuTimesSaved > 0) { - - if(window.nuAfterSaveGlobal) nuAfterSaveGlobal(); - if(window.nuAfterSave) nuAfterSave(); - - } - - nuAddFormStyle(f.style); - - const globalAccess = nuGlobalAccess(); - if (globalAccess) { - nuContextMenuUpdate(); - } - - nuSetSaved(true); - - nuCursor('default'); - - if (!nuIsMobile()) { - $('#nuSearchField').focus(); - } else { - nuMobileView(b.mobile_view); - } - - nuWindowPosition(); - - nuFormModification(); - - nuRestoreScrollPositions(); - - if ((nuSERVERRESPONSE.user_a11y || globalAccess) && window.nuSetAccessibility) { - nuSetAccessibility(formType, globalAccess); - } - -} - -function nuFormModification() { - - if (nuFormType() == 'browse') { - - if (!nuIsIframe()) { - - $record = $('#nuRECORD'); - $record.css({ - 'width': '99.7vw', - 'height': '80vh', - 'overflow-x': 'auto', - 'overflow-y': 'auto' - }); - - $('#nuBreadcrumbHolder').css({ - 'width': '100vw', - 'display': 'flex', - 'flex': '1', - 'flex-flow': 'row wrap', - 'align-items' : 'baseline' - }); - $('#nuActionHolder').css({ - 'width': '100vw' - }); - - $('.nuBrowseTitle, .nuBrowseTitleMultiline').wrapAll('
'); - - nuBrowseStickyColumns($record); - - document.body.style.overflow = 'hidden'; - } - } else { - document.body.style.overflow = 'visible'; - } - -} - -function nuCloseAfterSave() { - - nuDelay(100).then(() => { - nuHasNotBeenEdited(); - if (nuIsIframe()) { - nuClosePopup(); - } else { - nuOpenPreviousBreadcrumb(); - } - - }) - - return true; - -} - -function nuBrowseStickyColumns($record) { - - $record.bind("scroll", function () { - - const scrollLeft = $record.scrollLeft(); - const scrollTop = $record.scrollTop(); - - if (scrollTop >= 0 && scrollLeft >= 0) { - - $('#btitle').css({ - 'z-index': '95', - 'position': 'fixed', - 'left': 5 - scrollLeft + 'px' - }); - $('.nuBrowseTitle').css({ - 'top': '0', - 'height': '28px' - }); - $('.nuBrowseTitleMultiline').css({ - 'top': '0', - 'height': '48px' - }); - - } else { - - $('#btitle').css({ - 'z-index': '0', - 'position': 'absolute' - }); - $('.nuBrowseTitle,.nuBrowseTitleMultiline ').css({ - 'top': '3px' - }); - - } - - }); - -} - -function nuRestoreScrollPositions() { - - $(function () { - - $('textarea').each(function () { - $(this).scrollTop(window['nuScrollTop_' + this.id]); - }); - - }); - -} - -function nuSaveScrollPositions() { - - $('textarea:visible').each(function () { - window['nuScrollTop_' + this.id] = $(this).scrollTop(); - }); - -} - -function nuEvalnuOnLoadEvents() { - - const r = JSON.parse(JSON.stringify(nuSERVERRESPONSE)); - for (let i = 0; i < r.objects.length; i++) { - let obj = r.objects[i]; - if (obj.js.length > 0) { - - for (let j = 0; j < obj.js.length; j++) { - - if (obj.js[j].event == 'onnuload') { - let js = obj.js[j].js; - js = js.replaceAll('(this)', '("#' + obj.id + '")'); - js = js.replaceAll('this.', obj.id + '.'); - eval(js); - } - } - } - - } - -} - -function nuDisplayLoggedInUser() { - - let u = nuGlobalAccess() ? nuCurrentProperties().user_id : nuUserName(); - $('.nuBuilderLink').html(u).attr('href', '').css({ - 'cursor': 'pointer', - 'pointer-events': 'none' - }); - -} - -function nuAddHomeLogout() { - - if (nuMainForm()) { - - if (window.nuFORM.breadcrumbs.length > 1) { - - const div = nuCreateElementWithId('div', 'nuBreadcrumb0', 'nuBreadcrumbHolder'); - - $(div) - .addClass('nuBreadcrumb') - .css('cursor', "pointer") - .css('font-size', 16) - .attr('onclick', "nuGetBreadcrumb(0)") - .html('') - .attr('title', nuTranslate('Home')); - - } - - if (!nuIsMobile() || $('.nuBreadcrumb').length == 0) { - $('#nuBreadcrumbHolder').append('nuBuilder'); - nuAddIconToBreadCrumb('nuLogout', 'Log out', 16, 'nuAskLogout()', 'fas fa-sign-out-alt'); - } - - } - -} - -function nuAddIconToBreadCrumb(id, title, right, handler, iconClass) { - - const div = nuCreateElementWithId('div', 'nuBreadcrumb0', 'nuBreadcrumbHolder'); - - $(div) - .addClass('nuBreadcrumbIcon') - .attr('onclick', handler) - .css('right', right) - .html('') - .attr('title', nuTranslate(title)); - -} - -function nuAddedByLookup(f) { - - const isEdit = nuFormType() == 'edit'; - const isNewRecord = window.nuLASTRECORD == '-1'; - const isLookup = window.nuTARGET != ''; - - if (isEdit && isNewRecord && isLookup) { - window.parent.nuGetLookupId(nuRecordId(), window.nuTARGET); //-- called from parent window - } - -} - -function nuSetBody(f) { - - let $body = $('body'); - - $body.html(''); - $body.removeClass('nuBrowseBody nuEditBody'); - - if (nuFormType() == 'browse') { - $body.addClass('nuBrowseBody'); - } else { - - var height = f.dimensions === null ? 0 : f.dimensions.edit.height; - $body.addClass('nuEditBody') - .css('width', window.innerWidth - 1) - .css('height', height); - - } - -} - -function nuCSSPropertySum(id, arr) { - - let $id = $('#' + id); - if ($id.length == 0) { return 0; } - - let sum = 0; - arr.forEach(function(element){ - sum += parseInt($id.css(element), 10); - }); - - return sum; - -} - -function nuDialogHeadersHeight() { - - let height = 0; - const arr = ['nuBreadcrumbHolder','nuActionHolder','nuTabHolder','nuBrowseTitle0','nuBrowseFooter']; - arr.forEach(function(element){ - height += nuTotalHeight(element); - }); - - return height; - -} - -function nuTotalHeight(id) { - - const arrProperties = ['height','padding-top','padding-bottom','border-top-width','border-bottom-width','margin-top','margin-bottom']; - return nuCSSPropertySum(id, arrProperties); - -} - -function nuTotalWidth(id) { - - const arrProperties = ['width','padding-left','padding-right','border-left-width','border-right-width','margin-left','margin-right']; - return nuCSSPropertySum(id, arrProperties); - -} - -function nuTotalHolderWidth(id) { - - const arrProperties = ['padding-left','padding-right','border-left-width','border-right-width','margin-left','margin-right']; - return nuCSSPropertySum(id, arrProperties); - -} - -function nuDefine(v, defaultValue = '') { - - if (v === undefined) { - v = defaultValue; - } - - return v; - -} - -function nuSearchFieldSetSearchType(isMobile) { - - $("#nuSearchField") - .prop("type", "search") - .attr('autocomplete', 'off') - .on('search', function () { - nuSearchAction(); - }); - -} - -function nuAddActionButtons(form) { - - let draggable = 0; - const r = nuRecordId(); - - if (r == '-2') { - draggable = 1; - } - - var button = form.buttons; - - if (nuFormType() == 'browse') { - - var s = nuDefine(nuFORM.getProperty('search')); - var f = nuDefine(nuFORM.getProperty('filter')); - - const isMobile = nuIsMobile(); - - $('#nuActionHolder').append("") - .append(""); - - - const searchCaption = isMobile ? "" : " " + nuTranslate('Search'); - const printCaption = isMobile ? "" : nuTranslate('Print'); - const addCaption = isMobile ? "" : nuTranslate('Add'); - - nuAddActionButton("Search", "" + searchCaption, 'nuSearchAction()'); - - if (button.Add == 1) { - nuAddActionButton('Add', addCaption, 'nuAddAction()'); - } - - if (button.Print == 1 && nuFORM.getCurrent().browse_rows.length > 0) { - nuAddActionButton('Print', printCaption, 'nuPrintAction()'); - } - - nuSearchFieldSetSearchType(isMobile); - - } else { - - if (!draggable) { - - if (button.Save == 1 && form.form_type != 'launch') { - if ((nuIsNewRecord() && form.data_mode == 0) || form.data_mode != 0) { - nuAddActionButton('Save'); - } - } - - if (r != -1) { - - if (button.Delete == 1) { nuAddActionButton('Delete'); } - if (button.Clone == 1) { nuAddActionButton('Clone'); } - - } - - if (button.RunHidden != '') { nuAddActionButton('runhidden', 'Run', button.RunHidden); } - if (button.Run != '') { nuAddActionButton('run', 'Run', button.Run); } - - } - - } - -} - -function nuAddActionButton(id, value, func, text, e) { - - if (arguments.length == 1) { - value = id; - func = 'nu' + id + 'Action()'; - } - - if (typeof(value) == 'object') { - value = nuUXOptions.nuMobileView ? value['valueMobile'] : nuTranslate(nuDefine('value')); - } else { - value = nuTranslate(nuDefine(value)); - } - - text = nuTranslate(nuDefine(text)); - - let nuClass = "nuActionButton"; - if (id == 'Save' || id == 'Add' || id == 'Clone' || id == 'Delete') { - nuClass += " " + "nu" + id + "Button"; - } - - id = "nu" + id + "Button"; - let html = `"; - - if (e) { - $(html).insertAfter('#' + e); - } else { - $('#nuActionHolder').append(html); - } - - return $('#' + id); -} - -function nuAddActionButtonSaveClose(caption) { - - nuAddActionButton('SaveClose', nuTranslate(caption === undefined ? 'Save & Close' : caption), "nuSaveAction(true)", '', 'nuSaveButton'); - $('#nuSaveCloseButton').addClass('nuSaveButton'); - -} - -function nuBuildEditObjects(f, p, o, prop) { - - if (typeof (f.objects) != 'object') { return; } - - var l = 3; - - const draggable = nuRecordId() == '-2' ? 1 : 0; - - for (let i = 0; i < f.objects.length; i++) { - - if (!draggable) { - - var obj = prop.objects[i]; - var t = obj.type; - f.objects[i].parent_type = o == '' ? '' : o.subform_type; - - if (t == 'input' || t == 'display' || t == 'lookup' || t == 'textarea' || t == 'calc') { - l = l + nuINPUT(f, i, l, p, prop); - } else if (t == 'run') { - l = l + nuRUN(f, i, l, p, prop); - } else if (t == 'html') { - l = l + nuHTML(f, i, l, p, prop); - } else if (t == 'contentbox') { - l = l + nuCONTENTBOX(f, i, l, p, prop); - } else if (t == 'editor') { - l = l + nuEDITOR(f, i, l, p, prop); - } else if (t == 'image') { - l = l + nuIMAGE(f, i, l, p, prop); - } else if (t == 'select') { - l = l + nuSELECT(f, i, l, p, prop); - } else if (t == 'subform' && p == '') { - l = l + nuSUBFORM(f, i, l, p, prop); - } else if (t == 'word') { - l = l + nuWORD(f, i, l, p, prop); - } - - if (obj.labelOnTop) { - $('#' + obj.id).nuLabelOnTop(); - } - - if (obj.visible === false) { - nuHide(obj.id); - } - nuAddAttributes(p + obj.id, obj.attributes); - - l = l + 2; - - } else { - - $("body").css("overflow", "hidden"); - l = l + nuDRAG(f, i, l, p, prop); - - } - - } - -} - -function nuAddJSObjectEvents(i, j) { - - const o = document.getElementById(i); - - for (let J = 0; J < j.length; J++) { - - let code = o.getAttribute(j[J].event); - let ev = j[J].event; - - code = code === null ? '' : code + ';'; - - if (ev == 'beforeinsertrow' || ev == 'afterinsertrow' || ev == 'clickdelete') { - { ev = 'data-nu-' + ev; } - } - - if (o.classList.contains('nuLookupButton')) { - - if (ev == 'onclick') { - o.setAttribute(ev, code + j[J].js); - } else { - $('#' + o.id.slice(0, -6) + 'code')[0].setAttribute(ev, code + j[J].js); - } - - } else { - o.setAttribute(ev, code + j[J].js); - } - - } - -} - -function nuRecordProperties(w, p, l) { - - var del = p + 'nuDelete'; - var sf = p.substr(0, p.length - 3); - - const chk = nuCreateElementWithId('input', del); - - chk.setAttribute('title', nuTranslate('Delete This Row When Saved')); - chk.setAttribute('type', w.deletable == '0' ? 'text' : 'checkbox'); - chk.setAttribute('onclick', 'nuChange(event)'); - - $('#' + p + 'nuRECORD') - .append(chk) - .addClass('nuSection') - .attr('data-nu-form-id', w.id) - .attr('data-nu-table', w.table) - .attr('data-nu-primary-key', w.record_id) - .attr('data-nu-foreign-key', w.foreign_key) - .attr('data-nu-foreign-field', p == '' ? '' : w.foreign_key_name); - - var objDel = $('#' + del); - objDel - .attr('data-nu-data', '') - .addClass('nuSubformCheckbox') - .addClass(w.table); - - if (arguments.length == 3) { - - objDel - .prop('checked', w.record_id == -1) - .attr('data-nu-checkbox', w.deletable == '0' ? '' : sf) - .css({ - 'top': 3, - 'left': Number(l) + 2, - 'position': 'absolute', - 'visibility': 'visible' - }); - - if (w.deletable == '0') { - objDel.css({ 'width': 0, 'height': 0, 'left': -10, 'top': 10, 'tabindex': '-1' }); //-- allows tabbing when there is no checkbox. - } - - } else { - - objDel.css('visibility', 'hidden') - .prop('checked', false) - .attr('data-nu-checkbox', sf); - - } - -} - -function nuDRAG(w, i, l, p, prop) { - - const obj = prop.objects[i]; - const id = p + obj.id; - const nuObjectType = p + obj.type; - - let tagType = 'div'; - if (nuObjectType == 'textarea' || nuObjectType == 'input') { - tagType = nuObjectType; - } - - const drgDiv = nuCreateElementWithId(tagType, id, p + 'nuRECORD'); - let $id = $(drgDiv); - - nuSetObjectBounds($id, obj.top, obj.left, obj.width, obj.height) - .css({ - 'text-align': obj.align, - 'overflow': 'hidden', - 'display': 'flex', - 'align-items': 'center', - 'padding-left': '4px', - 'cursor': 'pointer', - 'caret-color' : 'transparent' - }).addClass('nu_' + nuObjectType); - - if (obj.read == '2') { // hidden - $id.addClass('nuDragHidden').css('visibility', 'hidden') - } - - $id.attr('data-drag', 1) - .attr('data-nu-object-id', obj.object_id); - - if (tagType == 'div') { - $id.text(id); - } else { - $id.val(id).attr('spellcheck','false').prop('readonly', true); - } - - if (obj.input == 'button' || nuObjectType == 'run') { - $id.attr('data-drag-button-label', obj.label); - } - - if (obj.input != 'button' && nuObjectType != 'run' && nuObjectType != 'contentbox' && prop.title !== 'Insert-Snippet') { //-- Input Object - let lab = nuLabel(w, i, p, prop); - $(lab).addClass('nuDragLabel').css('visibility', 'hidden'); - } - - nuAddDataTab(id, obj.tab, p); - - return Number(obj.width); - -} - - -function getDBColumnLengh(w, id) { - - const tableSchema = nuSERVERRESPONSE.tableSchema; - if (tableSchema === undefined || w.table == '' || tableSchema[w.table] === undefined) return 0; - - var len = 0; - const index = tableSchema[w.table].names.indexOf(id); - - if (index !== -1) { - - const datatype = tableSchema[w.table]["types"][index].toUpperCase(); - - switch (datatype) { - case "TINYTEXT": - len = 255; - break; - case "TEXT": - len = 65535; - break; - case "MEDIUMTEXT": - len = 16777215; - break; - default: - if (datatype.includes('CHAR')) { - len = parseInt(datatype.replace(/\D/g, ""), 10); - } - } - } - - return len; - -} - -function nuINPUTfileDatabase($fromId, obj, id, p) { - - const newElement = nuCreateElementWithId('textarea', id); - $fromId.append(newElement); - - const $id = $(newElement); - - $id - .css('visibility', 'hidden') - .attr('data-nu-field', id) - .attr('data-nu-prefix', p) - .attr('data-nu-data', '') - .attr('onchange', 'this.className = "nuEdited"'); - - if (!nuIsNewRecord()) { - $id.val(obj.value); - } - - return id + '_file'; - -} - -function nuINPUTfileFileSystem($fromId, w, i, l, p, prop, id) { - - var obj = prop.objects[i]; - id = id !== undefined ? id : p + obj.id; - - nuCreateElementWithId('div', 'nuBreadcrumb0', p + 'nuRECORD'); - - obj = nuLabelOrPosition(obj, w, i, l, p, prop); - - nuAddDataTab(id, obj.tab, p); - - let html = w.objects[i].html; - html = html.replaceAll('#uppy_div#', id + '_uppy_div'); - html = html.replaceAll('#this_object_id#', id); - html = html.replaceAll('nuInitUppy()','nuInitUppy' + '_' + id + '()'); - - nuSetObjectBounds($('#' + id), obj.top, obj.left, obj.width, obj.height) - .addClass('nuFileUppy').html(html); - - nuSetAccess(id, obj.read); - nuAddStyle(id, obj); - - return Number(obj.width); - -} - -function nuINPUTInput($id, inp, inputType, obj, objectType) { - - inp.setAttribute('type', inputType); - - const className = objectType == 'lookup' ? 'nuHiddenLookup' : 'input_' + inputType; - $id.addClass(className); - - if (obj.datalist !== null && obj.datalist !== '' && typeof obj.datalist !== "undefined") { - let dl = obj.datalist; - if (!$.isArray(dl)) dl = JSON.parse(dl); - if (!$.isArray(dl)) dl = eval(dl); - nuAddDatalist($id.attr('id'), dl); - } -} - -function nuINPUTnuScroll($id, wi) { - - const inputJS = 'nuFORM.scrollList(event, ' + wi.scroll + ')'; - - $id.addClass('nuScroll') - .attr('onkeydown', inputJS) - .attr("title", nuTranslate('Use the keyboard up and down arrows to scroll through the list or add text that is not in the list.')); - -} - -function nuINPUTnuDate($id, wi) { - - $id.addClass('nuDate') - .attr('data-nu-format', wi.format) - .attr('autocomplete', 'off'); - -} - -function nuINPUTnuNumber($id, wi) { - - $id.addClass('nuNumber') - .attr('data-nu-format', wi.format); - -} - -function nuINPUTCheckbox($id, obj, wi) { - - document.getElementById($id.attr('id')).checked = (wi.value == '1'); - - if (obj.parent_type == 'g') { - $id.css('margin-top', '1px'); - } - -} - -function nuINPUTDisplay($id) { - - $id.addClass('nuReadonly') - .prop('readonly', true); - -} - -function nuINPUTLookup(id, objId, wi, obj, $fromId, p, vis) { - - let $id = $('#' + id); - $id.hide(); - $id.attr('data-nu-lookup-id', ''); - - const luv = wi.values[0][1]; - if (!nuIsNewRecord() || luv !== '') { - $('#' + id).val(luv); - } - - const target = id; - id = target + 'code'; - var inp = document.createElement('input'); - inp.setAttribute('id', id); - $fromId.append(inp); - - nuAddDataTab(id, obj.tab, p); - - $id = $('#' + id); - nuSetObjectBounds($id, obj.top, obj.left, obj.width, obj.height) - .attr('data-nu-form-id', wi.form_id) - .attr('data-nu-object-id', wi.object_id) - .attr("data-nu-prefix", p) - .attr('data-nu-target', target) - .attr('data-nu-type', 'lookup') - .attr('data-nu-subform-sort', 1) - .attr('onchange', 'nuGetLookupCode(event)') - .attr('onfocus', 'nuLookupFocus(event)') - .css('visibility', vis) - .addClass('nuLookupCode'); - - nuAddJSObjectEvents(id, obj.js); - - if (Number(obj.width) == 0) nuHide(id); - - $id.enterKey(function () { - if ($(this).val().length == 0) { - let element = $('#' + target + 'button')[0]; - nuBuildLookup(element, ""); - } - }); - - wi.values[0][0] = p + obj.id; - wi.values[1][0] = p + obj.id + 'code'; - wi.values[2][0] = p + obj.id + 'description'; - - id = target + 'button'; - var div = document.createElement('div'); - - div.setAttribute('id', id); - - $fromId.append(div); - - nuAddDataTab(id, obj.tab, p); - - var luClass = obj.label === 'Insert-Snippet' ? 'fa fa-code' : 'fa fa-search'; - - nuAddJSObjectEvents(id, obj.js); - - $id = $('#' + id); - nuSetObjectBounds($id, obj.top, Number(obj.left) + Number(obj.width) + 6, 15, Number(obj.height - 2)) - .attr('type', 'button') - .attr("data-nu-prefix", p) - .attr('data-nu-form-id', wi.form_id) - .attr('data-nu-object-id', wi.object_id) - .attr('data-nu-target', target) - .attr('data-nu-subform-sort', 1) - .attr('onfocus', 'nuLookupFocus(event)') - .attr('onclick', 'nuBuildLookup(this,"")') - .addClass('nuLookupButton') - .html('') - .css('visibility', vis); - - if (obj.label === 'Insert-Snippet') $('#' + id).css('font-size', '18px'); - - id = p + obj.id + 'description'; - var desc = document.createElement('input'); - desc.setAttribute('id', id); - - $fromId.append(desc); - nuAddDataTab(id, obj.tab, p); - $('#' + id).css({ - 'top': obj.mobile ? Number(obj.top) + Number(obj.height) + 5 : Number(obj.top), - 'left': obj.mobile ? Number(obj.left) : Number(obj.left) + Number(obj.width) + 25, - 'width': obj.mobile ? Number(obj.width) : obj.description_width, - 'visibility': obj.description_width == 0 || obj.display == 0 ? 'hidden' : 'visible', - 'height': Number(obj.height) - }) - .attr('tabindex', '-1') - .attr("data-nu-prefix", p) - .addClass('nuLookupDescription') - .addClass('nuReadonly') - .prop('readonly', true); - - nuPopulateLookup3(wi.values, p); - - nuSetAccess(objId, obj.read); - - nuAddStyle(id, obj); - - return Number(obj.width) + Number(obj.description_width) + 30; - -} - -function nuINPUTnuAutoNumber($id, obj) { - - $id.prop('readonly', true) - .addClass('nuReadonly'); - - if (!nuIsNewRecord()) { - $id.val(obj.counter); - } - -} - -function nuINPUTCalc($id, wi, p) { - - const formula = String(wi.formula).nuReplaceAll("al('", "al('" + p); - - $id.addClass('nuCalculator') - .attr('data-nu-format', wi.format) - .attr('data-nu-calc-order', wi.calc_order) - .attr('data-nu-formula', formula) - .prop('readonly', true).prop('tabindex', -1); - - if (p != '') { - $id.addClass('nuSubformObject'); - } - -} - -function nuINPUTSetValue($id, wi, inputType) { - - if (inputType == 'button') { - $id.html(nuTranslate(wi.value)); - } else { - - if (inputType == 'datetime-local') { //-- replace ' ' between date and time with 'T' - wi.value = wi.value === null ? null : wi.value.replace(' ', 'T'); - } - - if (!nuIsNewRecord() || wi.value !== '') { - $id.val(nuFORM.addFormatting(wi.value, wi.format)); - } - - } - -} - -function nuIPUTNuChangeEvent(obj, inputType, objectType) { - - let change = 'nuChange(event)'; - - if (inputType == 'file' && obj.file_target == '1') { - change = ''; - } else if (inputType == 'file') { - change = 'nuChangeFile(event)'; - } else if (objectType == 'lookup') { - change = 'nuGetLookupId(this.value, this.id)'; - } - - return change; - -} - -function nuINPUTSetProperties($id, obj, inputType, objectType, wi, p) { - - const leftInc = inputType == 'button' && p != '' ? 3 : 0; - - $id.css({ - 'top': Number(obj.top), - 'left': Number(obj.left) + leftInc, - 'width': Number(obj.width), - 'height': Number(obj.height), - 'text-align': obj.align, - 'position': 'absolute' - }) - .attr('onchange', nuIPUTNuChangeEvent(obj, inputType, objectType)) - .attr('data-nu-field', inputType == 'button' || inputType == 'file' ? null : obj.id) - .attr('data-nu-object-id', wi.object_id) - .attr('data-nu-format', '') - .attr('data-nu-prefix', p) - .attr('data-nu-type', objectType) - .attr('data-nu-subform-sort', 1) - .attr('data-nu-label', wi.label) - .attr('onfocus', 'nuLookupFocus(event)'); - - if (inputType != 'button') { - $id.attr('data-nu-data', ''); - } else { - $id.addClass('nuButton'); - } - - if (wi.value != '' && nuRecordId() == '-1') { //== check for Cannot be left blank - $id.addClass('nuEdited'); - } - -} - -function nuINPUTSetMaxLength($id, inputType, objectType, w) { - - const types = ['text', 'url', 'telephone', 'search', 'password', 'month', 'email', 'color', 'nuScroll'].indexOf(inputType) !== -1; - if ((types && objectType == 'input') || objectType == 'textarea') { - - const field = $id.attr('data-nu-field'); - const len = getDBColumnLengh(w, field); - if (len !== 0) $id.attr('maxlength', len); - - } - -} - -function nuINPUT(w, i, l, p, prop) { - - var obj = prop.objects[i]; - var wi = w.objects[i]; - - const objId = p + obj.id; - var id = p + obj.id; - const $fromId = $('#' + p + 'nuRECORD'); //-- Edit Form Id - var type = 'textarea'; - var vis = obj.display == 0 ? 'hidden' : 'visible'; - var inputType = obj.input; - var objectType = obj.type; - - if (objectType != 'textarea') { //-- Input Object - type = 'input'; - } - - const inputSubType = inputType == 'file' && obj.file_target == '1' ? 'uppy' : ''; - - if (type == 'input' && inputSubType == 'uppy') { - type = 'div'; - } - - if (type == 'input' && inputType == 'file' && inputSubType != 'uppy') { - id = nuINPUTfileDatabase($fromId, obj, id, p); - } - - const inp = document.createElement(inputType == 'button' && objectType == 'input' ? 'button': type); - inp.setAttribute('id', id); - - let $id = $(inp); - - $fromId.append(inp); - - obj = nuLabelOrPosition(obj, w, i, l, p, prop); - - nuAddDataTab(id, obj.tab, p); - nuINPUTSetProperties($id, obj, inputType, objectType, wi, p); - - if (type == 'input' && inputSubType != 'uppy') { //-- Input Object - nuINPUTInput($id, inp, inputType, obj, objectType); - } - - if (inputSubType == 'uppy') { - nuINPUTfileFileSystem($fromId, w, i, l, p, prop, id); - } - - if (inputType == 'nuScroll') { - nuINPUTnuScroll($id, wi); - } else if (inputType == 'nuDate') { - nuINPUTnuDate($id, wi); - $id.attr('onclick', 'nuPopupCalendar(this);'); - } else if (inputType == 'nuNumber') { - nuINPUTnuNumber($id, wi); - } else if (wi.input == 'checkbox') { - nuINPUTCheckbox($id, obj, wi); - } else if (objectType == 'display') { - nuINPUTDisplay($id); - } else if (objectType == 'calc') { - nuINPUTCalc($id, wi, p); - } - - if (inputType != 'file') { - nuINPUTSetValue($id, wi, inputType); - } - - if (objectType == 'input' && inputType == 'nuAutoNumber') { - nuINPUTnuAutoNumber($id, obj); - } - - if (inputType == 'button' && objectType == 'input') { - nuAddInputIcon(id, obj.input_icon); - } - - if (objectType == 'lookup') { - - return nuINPUTLookup(id, objId, wi, obj, $fromId, p, vis); - - } else { - - nuINPUTSetMaxLength($id, inputType, objectType, w); - - nuAddJSObjectEvents(id, obj.js); - - nuSetAccess(objId, obj.read); - - nuAddStyle(id, obj); - - return Number(obj.width) + (obj.read == 2 ? -2 : 4); - - } - -} - -function nuAddAttributes(id, attr) { - - if (attr !== undefined && attr !== null && attr !== '') { - - attr.trim().replace(/\"/g, "").split(",").forEach(attr => { - - let arr = attr.split('='); - let key; - let value; - - if (arr.length == 2) { - [key, value] = arr; - } else if (arr.length == 1) { - key = attr; - value = ''; - } - - if (arr.length == 1 || arr.length == 2) { - $('#' + id)[0].setAttribute(key.trim(), value); - } - - }); - - } - -} - -function nuAddInputIcon(id, icon) { - - function addIcon(idIcon, string, after) { - if (string.startsWith('fa')) { - nuAttachFontAwesome(idIcon, string, 'normal', after); - } else { - nuAttachHTML(idIcon, string, after); - } - } - - if (icon !== undefined && icon !== null && icon !== '') { - - if (!icon.includes('|')) { - addIcon(id, icon, false); - } else { - let icons = icon.split('|'); - if (icons[0].trim() !== '') addIcon(id, icons[0], false); - if (icons[1].trim() !== '') addIcon(id, icons[1], true); - } - - } - -} - -function nuAddStyleFromArray(id, obj) { - - var arr = JSON.parse(obj.style); - - for (let key in arr) { - - if (Object.prototype.hasOwnProperty.call(arr, key)) { - - let obj2; - if (key == 'label') { - obj2 = $('#' + 'label' + '_' + id); - } else { - obj2 = $('#' + id + ' .' + key); - if (obj2.length === 0) { - obj2 = $('#' + id); - } - } - - if (obj.style_type == 'CSS') { - - let css = obj2[0].getAttribute("style"); - css = css === null ? arr[key] : css += ';' + arr[key]; - obj2[0].setAttribute("style", css); - - } else if (obj.style_type == 'Class') { - obj2.addClass(arr[key]); - } - - } - - } - -} - -function nuAddStyle(id, obj) { - - if (obj.style_type !== '' && obj.style !== '') { - - if (obj.style_type == 'CSS') { - - if (obj.style.startsWith('{')) { - nuAddStyleFromArray(id, obj); - } else { - let css = $('#' + id)[0].getAttribute("style"); - css = css === null ? obj.style : css += obj.style; - $('#' + id)[0].setAttribute("style", css); - } - } else if (obj.style_type == 'Class') { - - if (obj.style.startsWith('{')) { - nuAddStyleFromArray(id, obj); - } else { - $('#' + id).addClass(obj.style); - } - - } - } - -} - -function nuLookupFocus(e) { - - const objT = $(e.target); - const p = objT.attr('data-nu-prefix'); - const t = objT.attr('data-nu-type'); - - window.nuSubformRow = Number(p.substr(p.length - 3)); - - if (t != 'textarea') { - objT.select(); - } - -} - -function nuCurrentRow() { - return window.nuSubformRow; -} - -function nuSetAccess(i, r) { - - if (r == 2 || r == 3 || r == 4) { // hidden - - const o = [i, i + 'code', i + 'button', i + 'description', 'label_' + i]; - - for (let c = 0; c < o.length; c++) { - - if (r == 2 || ((r == 3 || r == 4) && !nuGlobalAccess())) { - $('#' + o[c]) - .attr('data-nu-tab', 'x') - .hide(); - } else if ((r == 3 || r == 4) && !(o[c].startsWith('label_') || o[c].endsWith('button'))) { - $('#' + o[c]).addClass('nuAccessHiddenUser'); - } - - } - - } - - if (r == 1 || r == 4) { // readonly - nuReadonly(i); - } - - $('#' + i).attr('data-nu-access', r); - -} - -function nuLabelOrPosition(obj, w, i, l, p, prop) { - - if (obj.parent_type == 'g') { - - obj.left = l; - obj.top = 3; - - } else { - - if (obj.input != 'button' && prop.title !== 'Insert-Snippet') { //-- Input Object - nuLabel(w, i, p, prop); - } - - } - - return obj; - -} - - -function nuSetObjectBounds(obj, top = null, left = null, width = null, height = null, absolute = null) { - - if (top) - obj.css('top', Number(top)); - if (left) - obj.css('left', Number(left)); - if (height) - obj.css('height', Number(height)); - if (width) - obj.css('width', Number(width)); - if (!absolute) - obj.css('position', 'absolute'); - - return obj; - -} - -function nuHTML(w, i, l, p, prop, id) { - - let obj = prop.objects[i]; - id = id !== undefined ? id : p + obj.id; - - const div = nuCreateElementWithId('div', id, p + 'nuRECORD'); - $div = $(div); - - obj = nuLabelOrPosition(obj, w, i, l, p, prop); - - nuAddDataTab(id, obj.tab, p); - - nuSetObjectBounds($div, obj.top, obj.left, obj.width, obj.height); - $div.addClass('nuHtml').html(w.objects[i].html); - - nuSetAccess(id, obj.read); - nuAddStyle(id, obj); - - return Number(obj.width); - -} - -function nuEDITOR(w, i, l, p, prop) { - - const obj = prop.objects[i]; - - prop.objects[i].type = 'textarea'; - nuINPUT(w, i, l, p, prop); - $('#' + obj.id).addClass('nuEditor'); - - const id = obj.id + '_parent_container'; - nuHTML(w, i, l, p, prop, id); - - $('#' + id).html('
'); - nuAddStyle(id, obj); - - return Number(obj.width); - -} - -function nuCONTENTBOX(w, i, l, p, prop) { - - const obj = prop.objects[i]; - const id = p + obj.id; - - const div = nuCreateElementWithId('div', id, p + 'nuRECORD'); - - nuAddDataTab(id, obj.tab, p); - - const $div = $(div); - nuSetObjectBounds($div, obj.top, obj.left, obj.width, obj.height).css('z-index', '-1'); - - $div.attr('data-nu-object-id', w.objects[i].object_id) - .attr('data-nu-prefix', p) - .addClass('nuContentBoxContainer').html(w.objects[i].html); - - if (nuGlobalAccess()) { - $('#label_' + id).attr('ondblclick', 'nuOptionsListAction("nuobject", "' + obj.object_id + '")'); - } - - nuSetAccess(id, obj.read); - nuAddStyle(id, obj); - - return Number($div.width()); - -} - -function nuIMAGE(w, i, l, p, prop) { - - let obj = prop.objects[i]; - const id = p + obj.id; - - const img = nuCreateElementWithId('img', id, p + 'nuRECORD'); - - obj = nuLabelOrPosition(obj, w, i, l, p, prop); - - nuAddDataTab(id, obj.tab, p); - - let $img = $(img); - nuSetObjectBounds($img, obj.top, obj.left, obj.width).addClass('nuImage'); - if (obj.height !== "-1" && obj.width !== "-1") { - nuSetObjectBounds($img, null, null, obj.width, obj.height) - } - - $img.attr('src', atob(w.objects[i].src)); - - nuSetAccess(id, obj.read); - nuAddJSObjectEvents(id, obj.js); - nuAddStyle(id, obj); - - return Number($img.width()); - -} - -function nuWORD(w, i, l, p, prop) { - - const obj = prop.objects[i]; - const id = p + obj.id; - - const div = nuCreateElementWithId('div', id, p + 'nuRECORD'); - - nuAddDataTab(id, obj.tab, p); - - let t = w.objects[i].word; - const r = /(.*?)<\/n>/g.exec(t); - t = r === null ? t : r[1]; - - let $div = $(div); - nuSetObjectBounds($div, obj.top, obj.left, obj.width, obj.height) - .css('text-align', obj.align) - .addClass('nuWord') - .html(nuTranslate(t)); - - if (nuGlobalAccess()) { - $div.attr('ondblclick', 'nuOptionsListAction("nuobject", "' + obj.object_id + '")'); - } - - if (r !== null) { - $div.css('font-weight', 'normal'); - } - - nuAddInputIcon(id, obj.input_icon); - nuSetAccess(id, obj.read); - nuAddStyle(id, obj); - - return Number(obj.width); - -} - -function nuRUNGetOnClickEvent(obj) { - - let result = ''; - const runTarget = obj.run_target || '0'; - - const stopClick = runTarget == '0' ? 'nuStopClick(event);' : ''; - const jsPopup = `nuPopup('${obj.form_id}','${obj.record_id}','${obj.filter}')`; - const jsForm = `nuForm('${obj.form_id}','${obj.record_id}','${obj.filter}', '','${runTarget}')`; - const runAction = runTarget == '3' ? jsPopup : jsForm; - - const runType = obj.run_type; - if (runType == 'F') { - result = stopClick + runAction; - } else - if (runType == 'R') { - result = "nuRunReport('" + obj.record_id + "')"; - } else - if (runType == 'P') { - - result = obj.run_hidden - ? `nuRunPHPHidden('${obj.record_id}')` - : `nuRunPHP('${obj.record_id}')`; - - } - - return result; - -} - -function nuRUN(w, i, l, p, prop) { - - let obj = prop.objects[i]; - let id = p + obj.id; - let tagName = 'button'; - - if (obj.parent_type == 'g') { - obj.left = l; - obj.top = 3; - } - - if (obj.run_method != 'b') { - tagName = 'iframe'; - if (obj.parent_type !== 'g') { - nuLabel(w, i, p, prop); - } - } - - const div = nuCreateElementWithId(tagName, id, p + 'nuRECORD'); - const $div = $(div); - - nuAddDataTab(id, obj.tab, p); - - nuSetObjectBounds($div, obj.top, obj.left, obj.width, obj.height).css('text-align', obj.align) - .attr('data-nu-object-id', w.objects[i].object_id) - .attr('data-nu-prefix', p); - - if (obj.run_method == 'b') { - - $div.attr({ - 'type': 'button', - 'value': nuTranslate(obj.label), - 'onclick': nuRUNGetOnClickEvent(obj) - }) - .html(nuTranslate(obj.label)) - .addClass('nuButton'); - - nuAddInputIcon(id, obj.input_icon); - - } else { - - window.nuOPENER.push(new nuOpener(obj.run_type, obj.form_id, obj.record_id, obj.filter, obj.parameters)); - - const open = window.nuOPENER[window.nuOPENER.length - 1]; - const url = window.location.pathname + '?i=2&opener=' + open.id; - - $div.attr('src', url).removeClass('').addClass('nuIframe'); - - } - - nuAddJSObjectEvents(id, obj.js); - nuSetAccess(id, obj.read); - nuAddStyle(id, obj); - - return Number(obj.width); - -} - -function nuSELECT(w, i, l, p, prop) { - - let obj = prop.objects[i]; - const id = p + obj.id; - - obj = nuLabelOrPosition(obj, w, i, l, p, prop); - - const sel = nuCreateElementWithId('select', id, p + 'nuRECORD'); - - $sel = $(sel); - - if (w.objects[i].value != '' && nuRecordId() == '-1') { - $sel.addClass('nuEdited'); - } - - nuAddDataTab(id, obj.tab, p); - - if (obj.multiple == 1) { - $sel.attr('multiple', 'multiple'); - } - - if (obj.select2 == 1) { - - let select2Id = nuSetSelect2(id, obj); - nuAddDataTab(select2Id, obj.tab, p); - - }; - - $sel.css({ - 'top': Number(obj.top), - 'left': Number(obj.left), - 'width': Number(obj.width), - 'position': 'absolute' - }) - .attr('onfocus', 'nuLookupFocus(event)') - .attr('onchange', 'nuChange(event)') - .attr('data-nu-field', obj.id) - .attr('data-nu-object-id', w.objects[i].object_id) - .attr('data-nu-format', '') - .attr('data-nu-subform-sort', 1) - .attr('data-nu-data', '') - .attr('data-nu-label', w.objects[i].label) - .attr('data-nu-prefix', p); - - - $sel.css('height', Number(obj.height)); - - var s = String(w.objects[i].value); - var a = []; - - if (w.objects[i].multiple == 0 || w.objects[i].multiple === null) { - a = [s]; - } - - if (s.substr(0, 1) + s.substr(-1) == '[]') { - eval('a = ' + s); - } - - $sel.append(''); - - let hasSelected = false; - if (obj.options !== null) { - - for (let n = 0; n < obj.options.length; n++) { - - const opt = String(obj.options[n][1]); // .replaceAll(' ', ' '); - - if (a.indexOf(String(obj.options[n][0])) == -1) { - $sel.append(''); - } else { - $sel.append(''); - hasSelected = true; - } - - } - - } - - nuAddJSObjectEvents(id, obj.js); - - nuSetAccess(id, obj.read); - - if (obj.read == 1) { - nuDisable(id); - } - - nuAddStyle(id, obj); - - return Number(obj.width); - -} - -function nuSUBFORMAddCSS(id, SF) { - - nuSetObjectBounds($('#' + id), SF.top, SF.left, SF.width, Number(SF.height) + 2) - .css({ - 'overflow-x': 'hidden', - 'overflow-y': 'hidden' - }) - .attr('data-nu-object-id', SF.object_id) - .attr('data-nu-foreign-key-name', SF.foreign_key_name) - .attr('data-nu-primary-key-name', SF.primary_key_name) - .attr('data-nu-subform', 'true') - .attr('data-nu-add', SF.add) - .attr('data-nu-delete', SF.delete) - .addClass('nuSubform'); - -} - -function nuSUBFORMScrollDivAddCSS(id, SF, scrId, rowTop, rowWidth) { - - nuSetObjectBounds($('#' + scrId), rowTop, 0, Number(rowWidth) + 1, Number(SF.height) - rowTop + 1) - .css({ - 'border-width': 10, - 'overflow-x': 'hidden', - 'overflow-y': 'scroll', - 'position': 'absolute' - }); - - if (rowWidth > Number(SF.width)) { - - $('#' + id).css('overflow-x', 'scroll'); - $('#' + scrId).css('height', SF.height - rowTop - 25); - - } - -} - -function nuSUBFORMnuTabHolderAddCSS(tabId, rowTop, rowWidth) { - - nuSetObjectBounds($('#' + tabId), 0, 0, rowWidth, rowTop) - .css({ - 'overflow-x': 'hidden', - 'overflow-y': 'hidden', - 'position': 'absolute', - 'padding': '12px 0px 0px 0px' - }) - .addClass('nuTabHolder') - .attr('data-nu-subform', tabId) - .prepend('   '); - -} - -function nuSUBFORMnuRECORDAddCSS(frmId, rowTop, rowWidth, rowHeight, even) { - - nuSetObjectBounds($('#' + frmId), rowTop, 0, rowWidth, rowHeight) - .addClass('nuSubform' + even); - -} - -function nuCreateElementWithId(tagName, id, parentElement) { - - const newElement = document.createElement(tagName); - newElement.setAttribute('id', id); - if (parentElement !== undefined) { - document.getElementById(parentElement).appendChild(newElement); - } - - return newElement; - -} - -function nuGetSubformDimensions(SF) { - - let sfTypeGrid = SF.subform_type == 'g'; - let sfType = sfTypeGrid ? 'grid' : 'edit'; - let rowHeight = Number(SF.dimensions[sfType].height + (sfTypeGrid ? 0 : 10)); - let rowWidth = Number(SF.dimensions[sfType].width + (sfTypeGrid ? 55 : 10)); - rowWidth = SF.delete == '1' ? rowWidth - 3 : rowWidth - 25; - rowTop = sfTypeGrid ? 52 : 33; - - return { rowHeight, rowWidth, rowTop }; - } - - function nuSUBFORM(w, i, l, p, prop) { - - var SF = prop.objects[i]; //-- First row - var subformRows = w.objects[i]; //-- All rows - - let id = p + SF.id; - nuCreateElementWithId('div', id, p + 'nuRECORD'); //-- Edit Form Id - - nuLabelOrPosition(SF, w, i, l, p, prop) - nuAddDataTab(id, SF.tab, p); - nuSUBFORMAddCSS(id, SF); - nuAddJSObjectEvents(id, SF.js); - - if (SF.forms[0] !== undefined) { - nuGetSubformRowSize(SF.forms[0].objects, SF, id); - } - - let sfDimensions = nuGetSubformDimensions(SF); - let rowHeight = sfDimensions.rowHeight; - let rowWidth = sfDimensions.rowWidth; - let rowTop = sfDimensions.rowTop; - - var tabId = id + 'nuTabHolder'; - var tabDiv = document.createElement('div'); - tabDiv.setAttribute('id', tabId); - $('#' + id).prepend(tabDiv); - - nuSUBFORMnuTabHolderAddCSS(tabId, rowTop, rowWidth); - - if (SF.subform_type == 'f') { - nuAddEditTabs(id, SF.forms[0]); - } else { - - if (subformRows.forms.length > 0) { - - let tab0 = subformRows.forms[0].tabs[0]; - nuTABHELP[tab0.id] = tab0.help; - nuFORMHELP[SF.id] = tab0.help; - - } - - } - - nuOptions(id, SF.sf_form_id, 'subform', w.global_access); - - var scrId = id + 'scrollDiv'; - let scrDiv = nuCreateElementWithId('div', scrId, id); - scrDiv.setAttribute('class', 'nuSubformScrollDiv'); - - nuSUBFORMScrollDivAddCSS(id, SF, scrId, rowTop, rowWidth); - - rowTop = 0; - let prefix; - - for (var c = 0; c < subformRows.forms.length; c++) { - - prefix = id + nuPad3(c); - const frmId = prefix + 'nuRECORD'; - nuCreateElementWithId('div', frmId, scrId); - - nuSUBFORMnuRECORDAddCSS(frmId, rowTop, rowWidth, rowHeight, c%2 == 0 ? '1' : '0'); - nuBuildEditObjects(subformRows.forms[c], prefix, SF, SF.forms[0]); - SF.forms[c].deletable = SF.delete == '1' ? '1' : '0'; - nuRecordProperties(SF.forms[c], prefix, rowWidth - 40); - - rowTop = Number(rowTop) + Number(rowHeight); - - } - - if (prefix != '') { - - if (SF.add == 1) { - nuNewRowObject(String(prefix)); - } else { - $('#' + prefix + 'nuRECORD').hide(); - - } - - } - - nuSetAccess(id, SF.read); - nuAddStyle(id, SF); - - return Number(SF.width); - -} - -function nuNewRowObject(p) { - - const sf = p.substr(0, p.length - 3); - if ($('#' + p + 'nuRECORD').length == 0) { - return; - } - - let html = document.getElementById(p + 'nuRECORD').outerHTML; - - window.nuSUBFORMROW[sf] = String(html.nuReplaceAll(p, '#nuSubformRowNumber#', true)); - - $("[id^='" + p + "']").addClass('nuEdit'); - -} - -function nuSubformObject(id) { - return nuFORM.subform(id); -} - -function nuSubformRowId(t) { - return $(t).parent().attr('data-nu-primary-key'); -} - -function nuSubformRowNumber(id) { - return $('#' + id).attr('data-nu-prefix').slice(-3); -} - -function nuSubformRowObject(id, column) { - - const formCode = $('#' + id).attr('data-nu-form'); - return $('#' + formCode + nuSubformRowNumber(id) + column); - -} - -function nuSubformValue(t, id) { - - const p = $(t).attr('data-nu-prefix'); - return $('#' + p + id).val(); - -} - -function nuSubformColumnArray(id, column, includeDeleted = false) { - - var a = []; - const sf = nuSubformObject(id); - const c = Number.isInteger(column) ? column : sf.fields.indexOf(column); - - for (let i = 0; i < sf.rows.length; i++) { - if (sf.deleted[i] == 0 || includeDeleted) { - var rv = sf.rows[i][c]; - a.push(rv); - } - } - - return a; - -} - -function nuSubformDisable(sf, ob) { - - if (ob === undefined || ob === '') { - $("[data-nu-form='" + sf + "']").nuDisable(); - return; - } - - for (let i = 0; i < nuSubformObject(sf).rows.length; i++) { - nuDisable(sf + nuPad3(i) + ob); - } - -} - -function nuSubformEnable(sf, ob, enable) { - - if (ob === undefined || ob === '') { - $("[data-nu-form='" + sf + "']").nuEnable(enable); - return; - } - - for (let i = 0; i < nuSubformObject(sf).rows.length; i++) { - nuEnable(sf + nuPad3(i) + ob, enable); - } - -} - -function nuSubformHide(sf, ob) { - - if (ob === undefined || ob === '') { - $("[data-nu-form='" + sf + "']").nuHide(); - return; - } - - for (let i = 0; i < nuSubformObject(sf).rows.length; i++) { - nuHide(sf + nuPad3(i) + ob); - } - -} - -function nuSubformShow(sf, ob, show) { - - if (ob === undefined || ob === '') { - $("[data-nu-form='" + sf + "']").nuShow(true, false); - return; - } - - for (let i = 0; i < nuSubformObject(sf).rows.length; i++) { - nuShow(sf + nuPad3(i) + ob, show, false); - } - -} - -function nuSubformHideHeader(id) { - const scrollDiv = $('#' + id + 'scrollDiv'); - scrollDiv.css({top: 0, height: $('#' + id).cssNumber('height')}); -} - -function nuSubformLastRow(t) { - - const i = String($('#' + t.id).parent().attr('id')); - const p = i.substr(0, i.length - 17); - const s = parseInt(i.substr(11, 3), 10) + 1; - const n = $('#' + p + nuPad3(s) + 'nuRECORD').length; - - return n == 0; - -} - -function nuSubformFocusLastRow(id, f) { - - const sf = nuSubformObject(id); - const c = f === undefined ? sf.fields[1] : sf.fields.indexOf(f); - const r = sf.rows.length - 1; - - $('#' + id + nuPad3(r) + c).focus(); - -} - -function nuSubformSetHeight(i, height, minHeight, maxHeight) { - - let div = $('#' + i + 'scrollDiv'); - let sf = $('#' + i); - - let h = sf.data('nu-org-height'); - if (h === undefined || h === null) { - - div.data('nu-org-height', div.height()); - sf.data('nu-org-height', sf.height()); - sf.data('nu-org-z-index', sf.css('z-index')); - - if (height === undefined || height === null) { - h = window.innerHeight - sf.cssNumber('Top') - nuDialogHeadersHeight() - 50; - } else { - h = height; - } - - if (maxHeight !== undefined && h > maxHeight) h = maxHeight; - if (minHeight !== undefined && h < minHeight) h = minHeight; - - sf.height(h); - let hh = $('#' + i + 'nuTabHolder').height() + 1; - div.height(h - hh); - - sf.css('z-index', 1); - - } else { - - sf.height(h); - div.height(div.data('nu-org-height')); - sf.data('nu-org-height', null); - sf.css('z-index', div.data('nu-org-z-index')); - - } - -} - -function nuSubformRearrangeColumns(sf, fields, row, maintainWidth) { - - function obj(p) { - return $("[id$='" + p + "']"); - } - - let width = 3; - let totalwidth = $('#' + sf).cssNumber('width'); - - if (row !== '') row = nuPad3(row); - - nuHide(sf); - - for (let i = 1; i < fields.length; i++) { - - let p = row + fields[i][0]; - let p0 = '000' + fields[i][0]; - - if (fields[i][1] == '0') { - let h0 = obj(p0); - if (!h0.is('[nu-subform-column-hidden]')) { - h0.attr('nu-subform-column-hidden', ''); - let h = obj(p); - totalwidth -= h.cssNumber('width'); - h.nuHide(); - } - } else { - - if (obj(p0).attr('data-nu-type') == 'lookup') { - obj(p + 'code').css('left', width); - width = obj('code').cssNumber('width') + width + 6; - obj(p + 'button').css('left', width); - width += 19; - obj(p + 'description').css('left', width); - width = obj('description').cssNumber('width') + width + 6; - } else { - obj(p).css('left', width); - width = obj(p0).cssNumber('width') + width + 6; - } - - } - } - - if (maintainWidth !== false) { - $('#' + sf + 'scrollDiv').css('width', totalwidth - 1); - $('#' + sf).css('width', totalwidth); - } - - nuShow(sf); - -} - -function nuSubformHideColumns(sfId, columns, maintainWidth) { - - let fields = []; - nuSubformObject(sfId).fields.forEach(function (col) { - fields.push([col, columns.indexOf(col) !== -1 ? '0' : '1']); - }); - - nuSubformRearrangeColumns(sfId, fields, '', maintainWidth); - -} - -function nuSubformColumnUnique(id, column, label) { - - let arr = nuSubformColumnArray(id, column); - - if (arr.includes('') || !nuArrayIsUnique(arr)) { - return nuTranslate(label) + ' ' + nuTranslate('must be both unique and not blank'); - } - - return true; - -} - -function nuSubformTitleArray(sfName) { - - return - $('#' + sfName).children().filter('.nuSubformTitle').map(function () { - return this.getAttribute("data-nu-field"); - }).get(); - -} - -function nuSubformMoveFocus(activeElement, d) { - - let row = activeElement.attr('data-nu-prefix').slice(-3); - let nextRow = $('#' + activeElement.attr('data-nu-form') + nuPad3(Number(row) + d) + activeElement.attr('id').substr(activeElement.attr('data-nu-form').length + 3)); - if (nextRow.length == 1 && !nextRow.prop('disabled')) nextRow.focus(); - - return true; - -} - -function nuSubformHandleArrowKeyEvent(e) { - - let activeElement = $(document.activeElement); - let nuScroll = activeElement.hasClass('nuScroll'); - - var result; - switch (e.key) { - case 'ArrowUp': - result = !nuScroll && nuSubformMoveFocus(activeElement, -1); - break; - case 'Enter': - result = nuSubformMoveFocus(activeElement, 1); - break; - case 'ArrowDown': - result = !nuScroll && nuSubformMoveFocus(activeElement, 1); - break; - default: - result = false; - } - - return result; - -} - - -// Subform filtering - -function nuSubformAddFilter(filter) { - - for (const sfName in filter) { - if (Object.prototype.hasOwnProperty.call(filter, sfName)) { - nuSubformFiltersAdd(sfName, filter[sfName]); - } - } - - function nuSubformFilterId(sfName, columnId) { - return sfName + columnId + '_filter'; - } - - function nuSubformFilterValue(sfName, columnId, type) { - let filterId = nuSubformFilterId(sfName, columnId); - return nuGetValue(filterId, type === 'select' ? 'text' : 'value'); - } - - function nuSubformFilterOptionAll(sfName, columnId) { - let filterId = nuSubformFilterId(sfName, columnId); - return $("#" + filterId + " option:selected").attr('data-nu-all') === 'true'; - } - - function nuSubformFilterArray(sfName, arrColumns) { - - let arr = {}; - let isArray = Array.isArray(arrColumns); - - for (let columnId in arrColumns) { - if (isArray) columnId = arrColumns[columnId]; - arr[columnId] = {}; - arr[columnId].type = isArray ? 'select' : arrColumns[columnId].type; - arr[columnId].value = nuSubformFilterValue(sfName, columnId, arr[columnId].type); - arr[columnId].all = nuSubformFilterOptionAll(sfName, columnId); - } - - return arr; - - } - - function nuSubformFilterSortOptions(sfName, columnId) { - - let filterId = nuSubformFilterId(sfName, columnId); - $(filterId).html($(filterId + " option:not('[data-nu-persistent]')").sort(function (a, b) { - return a.text == b.text ? 0 : a.text < b.text ? -1 : 1; - })); - - } - - function nuSubformFiltersAdd(sfName, arrColumns) { - - let isArray = Array.isArray(arrColumns); - for (let columnId in arrColumns) { - - if (Object.prototype.hasOwnProperty.call(arrColumns, columnId)) { - - if (isArray) - columnId = arrColumns[columnId]; - - const prop = arrColumns[columnId]; - const float = prop === undefined || prop.float === undefined ? 'center' : prop.float; - - let width = $('#' + sfName + '000' + columnId).width() - 3; - width = prop === undefined || prop.width === undefined ? width : prop.width; - - let style = { - 'width': width + 'px', - 'float': float - }; - - const columnTitle = '#title_' + sfName + columnId; - const filterId = nuSubformFilterId(sfName, columnId); - const type = prop === undefined || prop.type === undefined ? 'select' : prop.type; - let obj = nuSubformFilterAddObject(type, sfName, columnId, filterId, prop); - - $(columnTitle).append("
"); - - obj.appendTo(columnTitle).css(style); - if (prop !== undefined && prop.placeholder) obj.nuSetPlaceholder(prop.placeholder); - - } - - } - - } - - function nuSubformFilterAddObject(type, sfName, columnId, filterId, prop) { - - var obj; - if (type == 'select') { - obj = nuSubformFilterAddSelect(sfName, columnId, filterId, prop); - } else if (type === 'search') { - obj = nuSubformFilterAddSearch(sfName, columnId, filterId, prop); - } - - return obj; - - } - - function nuSubformFilterAddSelect(sfName, columnId, filterId, prop) { - - let propAll = prop === undefined || prop.all === undefined ? '(' + nuTranslate('All') + ')' : prop.all; - let optionAll = []; - if (propAll !== false) - optionAll = nuSubformFilterCreateSelectOption('', propAll, true, true, true); - - let propBlank = prop === undefined || prop.blank === undefined ? true : prop.blank; - let optionBlank = []; - if (propBlank !== false) - optionBlank = nuSubformFilterCreateSelectOption('', '', true, false, false); - - return $('", { - type: "search", - class: "nuSubformFilter", - on: { - input: function () { - nuSubformFilterRows(sfName, nuSubformFilterArray(sfName, filter[sfName])); - }, - focus: function () { - if (propDatalist === true) - nuSubformFilterAddValues(sfName, 'search', columnId); - }, - }, - id: filterId - }); - - } - - function nuSubformFilterCreateSelectOption(_value, _text, persistent, all, _selected) { - - return $('