function nuInitJSOptions() { const defaults = { '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, // Optimize 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 'nuCalendarWeekNumbers': 'None', // nuCalendar: 0 = None, 1 = ISO 8601, 2 = Western traditional, 3 = Middle Eastern 'nuSelect2Theme': 'default', // select2 theme (default, classic) Default: default 'nuEditCloseAfterSave': 'None', // Close forms after saving. Values: none, All, User, System 'nuShowJSErrors': 'None', // Show JS errors in alert message 'nuHideTabTitleIfOnlyOne': 'None', // Hide tab title if only one tab. Values: none, globeadmin, user, everyone 'nuShowURLPermaLink': false, // Show URL permalink 'nuPrintButton': false, // Show Print Button 'nuDebugIcon': true, // Show Debug Icon 'nuPHPIcon': true, // Show PHP Icon 'nuRefreshIcon': true, // Show Refresh Icon 'nuObjectsIcon': true, // Show Objects Icon 'nuPropertiesIcon': true, // Show Properties Icon 'nuStickyHeaders': true // Sticky Headers in Edit Forms }; if (typeof window.nuUXOptions === "undefined") { window.nuUXOptions = defaults; } else { // Merge defaults only if the property is not already defined for (var key in defaults) { if (defaults.hasOwnProperty(key) && typeof window.nuUXOptions[key] === "undefined") { window.nuUXOptions[key] = defaults[key]; } } } } function nuBuildForm(formObj) { $('.nuSearchablePopup, .nuSearchableMultiPopup').remove(); nuInitJSOptions(); window.nuOnSetSelect2Options = null; // can be overwritten by nuAddJavaScript() window.nuSERVERRESPONSE = formObj; if (nuArrangingObjects(formObj.record_id)) { nuAddJavaScript(formObj.javascript_bc); } $('#nubody').off('.nuresizecolumn').css('transform', 'scale(1)'); $('html,body').scrollTop(0).scrollLeft(0); if (nuNeedToLoginAgain(formObj)) return; if (window.nuInfoBarHideOnFormClose) { $.nuInfoBar.closeAll({ animationType: 'none', animationDuration: 0 }); } const formType = nuFormType(); nuSetDefaultWindowProperties(formObj, formType); nuInitShowJSErrors(); nuFORM.edited = false; if (nuEditDoCloseAfterSave(formObj)) { return; } nuFORM.scroll = []; nuSetSuffix(1000); nuSetBody(formObj); nuRedefineNuSelectBrowse(); nuFORM.tableSchema = formObj.tableSchema; nuFORM.formSchema = formObj.formSchema; window.nuLANGUAGE = formObj.translation; nuSetProperty('refreshed', nuGetProperty('refreshed') + 1); nuAddedByLookup(formObj); var currentForm = nuSetFormProperties(formObj); nuAddHolder('nuBreadcrumbHolder'); nuAddHomeLogout(); nuAddHolder('nuActionHolder'); if (formType == 'edit') { nuAddHolder('nuTabHolder'); } // const nuRecordDiv = nuAddHolder('nuRECORD') .attr('data-nu-table', formObj.table) .attr('data-nu-primary-key-name', formObj.primary_key); // DEV: nuWrapWithForm(nuRecordDiv[0], '#', ''); nuAddBreadcrumbs(); nuAddEditTabs('', formObj); nuSetHideTabIfOnlyOne(); nuCallWindowFunction("nuBeforeAddActionButtons"); nuAddActionButtons(formObj); nuRecordProperties(formObj, ''); let firstObject = null; if (formType == 'edit') { nuOptions(formObj.form_id, '', 'form', formObj.global_access); nuBuildEditObjects(formObj, '', '', formObj); nuResizeFormDialogCoordinates(); nuCalculateForm(false); firstObject = nuGetFirstObject(formObj.objects, -1); } nuGetStartingTab(); if (nuGlobalAccess()) { nuAddAdminButtons(); } if (formType == 'edit' && nuIsNewRecord() && (firstObject !== null)) { firstObject.nuFocusWithoutScrolling(); } nuDragTitleEvents(); if (nuArrangingObjects(formObj.record_id)) { nuCreateDragOptionsBox(formObj); } else { nuAddJavaScript(formObj.javascript); } nuAddHome(); nuShowLastUpdatedMessage(); nuShowMessages(); if (window.nuOnEditorLoad) { nuOnEditorLoad(); } else { $('.nuEditor').each((index, element) => { nuInitTinyMCE(element.id); }); } nuEvaluateOnLoadEvents(formType); if (window.nuLoadEditGlobal && formType == 'edit') { nuLoadEditGlobal(formObj.form_id, formObj.form_code); } if (window.nuLoadBrowseGlobal && formType == 'browse') { nuLoadBrowseGlobal(formObj.form_id, formObj.form_code); } if (window.nuOnLoad) { nuOnLoad(formObj.form_id, formObj.form_code); } if (formType == 'edit') { window.nuRESPONSIVE.getStartPositions(); } else { if (currentForm.browse_autoresize_columns !== '0' || nuDocumentID !== parent.nuDocumentID) { if (nuUXOptions.nuAutosizeBrowseColumns || currentForm.browse_autoresize_columns === '1' || nuDocumentID !== parent.nuDocumentID) { nuResizeBrowseColumns(true); } } nuActionButtonsToggleVisibility(); } if (nuUXOptions.nuShowBrowserTabTitle) { nuSetBrowserTabTitle(nuUXOptions.nuBrowserTabTitlePrefix); } else { document.title = nuUXOptions.nuBrowserTabTitlePrefix; } if (nuUXOptions.nuEnableBrowserBackButton) { nuEnableBrowserBackButton(); } if (nuUXOptions.nuPreventButtonDblClick) { nuPreventButtonDblClick(); } if (nuUXOptions.nuShowBackButton) { nuAddBackButton(); } if (nuUXOptions.nuShowURLPermaLink) { nuSetURLPermaLink(); } if (nuUXOptions.nuShowPropertiesOnMiddleClick) { document.addEventListener("mousedown", nuOpenPropertiesOnMiddleClick, { passive: true }); } if ((nuUXOptions.nuBrowsePaginationInfo) !== '') { nuShowBrowsePaginationInfo((nuUXOptions.nuBrowsePaginationInfo)); } if (nuUXOptions.nuStickyHeaders) { nuStickyHeaders(); } 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 = []; } nuProcessAfterSave(); nuAddFormStyle(formObj.style); nuAddObjectFunctions(formType); nuSetBrowseHeight(); const globalAccess = nuGlobalAccess(); if (globalAccess) { nuContextMenuUpdate(); nuUpdateDebugButtonTitle(); } nuSetSaved(true); nuCursor('default'); window.nuPORTRAITSCREEN = false; if (!nuIsMobile() && formType == 'browse') { $('#nuSearchField').nuSetFocus(); } else { if (nuUXOptions.nuDevMobileView2) { nuInitMobileView(); } else { nuSetMobileView1(); } } nuWindowPosition(); nuFormModification(); nuRestoreScrollPositions(); if ((nuSERVERRESPONSE.user_a11y || globalAccess) && window.nuSetAccessibility) { nuSetAccessibility(formType, globalAccess); } } function nuProcessAfterSave() { if (window.nuTimesSaved > 0) { if (window.nuAfterSaveGlobal) nuAfterSaveGlobal(); if (window.nuAfterSave) nuAfterSave(); } } function nuSetFormProperties(formObj) { const properties = ['form_id', 'record_id', 'session_id', 'user_id', 'redirect_form_id', 'browse_target', 'redirect_other_form_id', 'title', 'row_height', 'rows', 'browse_columns', 'browse_sql', 'browse_rows', 'browse_table_id', 'browse_filtered_rows', 'browse_title_multiline', 'browse_autoresize_columns', 'mobile_view', 'pages', 'form_code', 'form_description', 'form_group', 'form_type', 'run_code', 'run_description', 'data_mode' ]; var currentForm = window.nuFORM.getCurrent(); properties.forEach(prop => { currentForm[prop] = formObj[prop]; }); return currentForm; } function nuEditDoCloseAfterSave(formObj) { if (nuHasBeenSaved() < 1 || nuGetProperty('nuEditCloseAfterSave') == '0') { return false; } const closeAfterSave = window.nuUXOptions.nuEditCloseAfterSave.toLowerCase() const isUserForm = !formObj.form_id.startsWith('nu'); const shouldCloseAllForms = closeAfterSave === 'allforms'; const shouldCloseUserForms = closeAfterSave === 'userforms' && isUserForm; const shouldCloseSystemForms = closeAfterSave === 'systemforms' && !isUserForm; if (shouldCloseAllForms || shouldCloseUserForms || shouldCloseSystemForms) { return nuCloseAfterSave(); } return false; } function nuDebugLastMessages() { if (!nuSERVERRESPONSE || !nuSERVERRESPONSE.nu_debug_last) { return ''; } const debugMessages = JSON.parse(nuSERVERRESPONSE.nu_debug_last); return debugMessages.map(item => `User: ${item.user}\nTimestamp: ${item.timestamp_from_message}\nWhere: ${item.where}\nMessage: ${item.message}` ).join('\n\n'); } function nuUpdateDebugButtonTitle() { if (!nuGlobalAccess()) return; const debugMessages = nuSERVERRESPONSE?.nu_debug; const lastMessages = nuDebugLastMessages(); let titleParts = []; if (Array.isArray(debugMessages) && debugMessages.length > 0) { titleParts.push(debugMessages.join(" ")); } if (lastMessages) { titleParts.push(lastMessages); } let title = titleParts.join('\n').trim(); if (!title) { title = "No messages"; } $("#nuDebugButton") .toggleClass("nuDebugButtonHighlight", Array.isArray(debugMessages) && debugMessages.length > 0) .attr("title", title); } function nuInitShowJSErrors() { if (window.nuUXOptions.nuShowJSErrors) { const nuShowJSErrors = window.nuUXOptions.nuShowJSErrors; let enableShowJSErrors = false; switch (nuShowJSErrors.toLowerCase()) { case "globeadmin": enableShowJSErrors = nuGlobalAccess() break; case "everyone": enableShowJSErrors = true; break; } if (enableShowJSErrors) { nuConsoleErrorsToMessage(); } } } function nuSetHideTabIfOnlyOne() { if (window.nuUXOptions.nuHideTabTitleIfOnlyOne && $('.nuTab:visible').length === 1) { const nuHideTabTitleIfOnlyOne = window.nuUXOptions.nuHideTabTitleIfOnlyOne; let hideTab = false; switch (nuHideTabTitleIfOnlyOne.toLowerCase()) { case "globeadmin": hideTab = nuGlobalAccess() break; case "user": hideTab = !nuGlobalAccess(); break; case "everyone": hideTab = true; break; } if (hideTab) { $('.nuTab').hide(); $('.nuTabHolder').hide(); } } } function nuAddHome() { if (window.nuLoginH != '') { let breadCrumb = $('#nuBreadcrumb0').length > 0 ? $('#nuBreadcrumb0') : $('#nuHomeGap'); breadCrumb .html('') .attr('title', nuTranslate('Home')) .attr('onclick', '') .attr('onclick', 'nuForm("' + window.nuLoginH + '", -1, "", "", 1);') .css('cursor', 'pointer'); window.nuLoginH = ''; } } function nuNeedToLoginAgain(f) { let result = f.tableSchema === null; if (result) { $('body').addClass('nuBrowseBody').removeClass('nuEditBody'); sessionStorage.logout = 'true'; window.top.location.reload(); nuCursor('default'); } return result; } function nuSetDefaultWindowProperties(f, formType) { if (formType == 'edit' && nuCurrentProperties().form_type !== 'launch') { window.nuTimesSaved++; if (window.nuLastForm != f.form_id || (window.nuLastRecordId != f.record_id && window.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.nuOnToolTipIconClick = null; window.nuOnAdvancedToolTip = null; window.nuOnToolTipIcon = 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'; window.nuVerticalTabs = false; window.nuOnMobileVievLoaded = false; } function nuFormModification() { if (nuFormType() == 'browse') { if (window['nuBrowseNoData'] || window['nuBrowseNoSearchResults']) $('.nuBrowseFooter').hide(); if (!nuIsIframe()) { $record = $('#nuRECORD'); $record.css({ 'width': '99.7vw', 'height': '80vh', 'overflow-x': 'auto', 'overflow-y': 'auto' }); $('#nuActionHolder').css({ 'width': '100vw' }); $('.nuBrowseTitle, .nuBrowseTitleMultiline').wrapAll('
'); nuBrowseStickyColumns($record); document.body.style.overflow = 'hidden'; } } else { document.body.style.overflow = 'visible'; } } function nuCloseAfterSave() { if (window.nuCloseAfterSaveGlobal) { if (!window.nuCloseAfterSaveGlobal(doClose)) { return false; } } nuDelay(100).then(() => { nuHasNotBeenEdited(); if (nuIsPopup()) { nuClosePopup(); } else { if (!nuOpenPreviousBreadcrumb()) { window.close(); } } }) return true; } function nuBrowseStickyColumns($record) { $record.on("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 nuStickyHeaders(opts = {}) { const apply = () => { const crumbH = nuTotalHeight('nuBreadcrumbHolder'); const actionH = nuTotalHeight('nuActionHolder'); const { actionTop = crumbH, stickyTabs = true, tabsTop = actionTop + actionH, important = true, clear = false, } = opts; const set = (el, prop, val) => el && el.style.setProperty(prop, val, important ? 'important' : ''); const remove = el => { el?.style.removeProperty('position'); el?.style.removeProperty('top'); el?.style.removeProperty('z-index'); }; const all = document.querySelectorAll('.nuBreadcrumbHolder, .nuActionHolder, .nuTabHolder'); if (clear) { all.forEach(remove); return; } all.forEach(el => set(el, 'margin-top', '0')); document.querySelectorAll('.nuBreadcrumbHolder').forEach(el => { set(el, 'position', 'sticky'); set(el, 'top', `0px`); set(el, 'z-index', '100'); }); document.querySelectorAll('.nuActionHolder').forEach(el => { set(el, 'position', 'sticky'); set(el, 'top', `${actionTop}px`); set(el, 'z-index', '99'); }); const tabs = document.querySelectorAll('.nuTabHolder'); if (stickyTabs) { tabs.forEach(el => { set(el, 'position', 'sticky'); set(el, 'top', `${tabsTop}px`); set(el, 'z-index', '98'); }); } else { tabs.forEach(remove); } }; apply(); addEventListener('resize', apply, { passive: true }); if (document.fonts?.ready) document.fonts.ready.then(apply); } function nuBrowseStyleBadge(column) { function createBadgeHtml(text) { return ` ${text} `; } nuBrowseLoop([column], function (cell) { const $cell = $(cell); const cellText = $cell.text().trim(); if (cellText && cellText.length > 0) { $cell.html(createBadgeHtml(cellText)); } }); } function nuBrowseStyleStatusColumn(column) { const statusConfig = { active: { color: '#28a745', bgColor: '#d4edda', icon: '✓', text: 'Active' }, draft: { color: '#6c757d', bgColor: '#e2e3e5', icon: '✎', text: 'Draft', italic: true }, archived: { color: '#6c757d', bgColor: '#f1f3f5', icon: '📦', text: 'Archived' } }; function createStatusHtml(config) { return ` ${config.icon} ${config.text} `; } nuBrowseLoop([column], function (cell) { const $cell = $(cell); const cellText = $cell.text().trim().toLowerCase(); for (const [status, config] of Object.entries(statusConfig)) { if (cellText.includes(status)) { $cell.html(createStatusHtml(config)); break; } } }); } function nuBrowseRowsPerPageFilter(rowsPerPageOptions, insertBeforeTarget = '#nuFirst', customStyle) { if (nuFormType() !== 'browse') return; const defaultOptions = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 150, 200]; const options = rowsPerPageOptions ?? defaultOptions; const isDefaultPosition = insertBeforeTarget === '#nuFirst'; const defaultMarginLeft = isDefaultPosition ? '0px' : '20px'; const defaultMarginRight = isDefaultPosition ? '10px' : '0px'; const defaultStyle = `margin-left: ${defaultMarginLeft}; margin-right: ${defaultMarginRight}; width: 50px; height: 22px; text-align: left`; const style = customStyle ?? defaultStyle; const selectId = 'nuBrowseRowsPerPage'; const hashCookie = 'ROWS_PER_PAGE'; const selectElement = $( `` ); selectElement .attr('title', nuTranslate('Number of Rows')) .append(``); for (let val of options) { selectElement.append(``); } const $target = insertBeforeTarget instanceof jQuery ? insertBeforeTarget : $(insertBeforeTarget); selectElement.insertBefore($target); selectElement.on('change', function () { nuSetProperty('page_number', 0); nuSetProperty(hashCookie, this.value); nuSearchAction(); }); selectElement.val(nuGetProperty(hashCookie) ?? ''); } function nuPrintIncludeColumns(arr) { nuSetProperty('nuPrintIncludedColumns', nuEncode(arr)); } function nuPrintExcludeColumns(arr) { nuSetProperty('nuPrintExcludedColumns', nuEncode(arr)); } function nuPrintIncludeHiddenColumns(include) { nuSetProperty('nuPrintIncludeHiddenColumns', include ? '1' : '0'); } function nuPrintUseBrowseFormats(value) { nuSetProperty('nuPrintUseBrowseFormats', value ? '1' : '0'); } function nuPrintCSVExportOptions(options) { nuSetProperty('nuPrintCSVExportOptions', nuEncode(JSON.stringify(options))); } function nuRestoreScrollPositions() { $(function () { $('textarea').each(function () { const position = window['nuScrollTop_' + this.id] || 0; $(this).scrollTop(position); }); }); } function nuSaveScrollPositions() { $('textarea:visible').each(function () { window['nuScrollTop_' + this.id] = $(this).scrollTop(); }); } function nuEvaluateOnLoadEvents(formType) { if (formType === 'browse') return; for (const { id, js } of JSON.parse(JSON.stringify(nuSERVERRESPONSE)).objects) { js.filter(e => e.event === 'onnuload').forEach(e => { let modifiedJS = e.js.replaceAll('(this)', `("#${id}")`).replaceAll('this.', `${id}.`); eval(modifiedJS); }); } } function nuDisplayLoggedInUser() { let u = nuGlobalAccess() ? nuCurrentProperties().user_id : nuUserName(); $('.nuBuilderLink').html(u).attr('href', '').css({ 'cursor': 'pointer', 'pointer-events': 'none' }); } function nuAddHomeLogout() { if (nuMainForm(true)) { if (window.nuFORM.breadcrumbs.length > 1) { const div = nuCreateElementWithId('div', 'nuBreadcrumb0', 'nuBreadcrumbHolder'); $(div) .addClass('nuBreadcrumb') .css('cursor', "pointer") .css('font-size', '16px') .attr('onclick', "nuGetBreadcrumb(0)") .html('') .attr('title', nuTranslate('Home')); } if (!nuIsMobile() || $('.nuBreadcrumb').length == 0) { $('#nuBreadcrumbHolder').append('nuBuilder'); nuAddIconToBreadCrumb2('nuLogout', 'Log out', 16, 'nuAskLogout()', 'fa-solid fa-sign-out-alt'); } } } function nuAddIconToBreadCrumb2(id, title, right, handler, iconClass) { const div = nuCreateElementWithId('div', id, 'nuBreadcrumbHolder'); $(div) .addClass('nuBreadcrumbIcon2') .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 elem = document.getElementById(id); if (!elem) { return 0; } let sum = 0; arr.forEach(function (property) { sum += parseInt(getComputedStyle(elem).getPropertyValue(property), 10); }); return sum; } function nuDialogHeadersHeight() { let height = 0; const arr = [ "nuBreadcrumbHolder", "nuActionHolder", "nuTabHolder", "nuBrowseTitle0", "nuBrowseFooter", ]; arr.forEach(function (elem) { height += nuTotalHeight(elem); }); return height; } function nuTotalHeight(id) { const elem = document.getElementById(id); if (!elem) return 0; const style = getComputedStyle(elem); return elem.getBoundingClientRect().height + parseFloat(style.marginTop) + parseFloat(style.marginBottom); } function nuTotalWidth(id) { const elem = document.getElementById(id); if (!elem) return 0; const style = getComputedStyle(elem); return elem.getBoundingClientRect().width + parseFloat(style.marginLeft) + parseFloat(style.marginRight); } function nuDefine(v, defaultValue = '') { if (v === undefined) { v = defaultValue; } return v; } function nuSearchFieldSetSearchType(isMobile) { const $searchField = $("#nuSearchField"); $searchField .prop("type", "search") .attr('autocomplete', 'off') .on('search', function () { nuSearchAction(); }); if (isMobile) { $searchField.css('height', '32px'); } } function nuAddActionButtons(form) { const recordId = nuRecordId(); const arrangingObjects = nuArrangingObjects(recordId); const button = form.buttons; const isMobile = nuIsMobile(); if (nuFormType() == 'browse') { const searchValue = nuDefine(nuFORM.getProperty('search')); const filter = nuDefine(nuFORM.getProperty('filter')); $('#nuActionHolder').append( '
' + '' + '' + '
' ).append( "" ); $('#nuSearchBtn').on('click', function () { nuSearchAction(); }); if (button.Add == 1) { nuAddActionButton('Add', undefined, undefined, 'Add New Record'); } if (button.Print == 1 && nuFORM.getCurrent().browse_rows.length > 0 && !isMobile) { nuAddActionButton('Print'); } nuSearchFieldSetSearchType(isMobile); } else { if (!arrangingObjects) { if (button.Save == 1 && form.form_type != 'launch') { if ((nuIsNewRecord() && form.data_mode == 0) || form.data_mode != 0) { nuAddActionButton('Save'); } } if (recordId != -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); } } } if (isMobile) { $('#nuSearchButton #nuSaveButton #nuAddButton').addClass('nuActionButtonIcon'); } } function nuAddActionButton(id, value, func, title, icon, insertAfterElement) { const DEFAULT_ICON_BASE = 'fa-regular'; const ICON_SIZE_CLASSES = 'fa-width-auto fa-lg'; const defaults = { Save: { value: 'Save', func: 'nuSaveAction()', text: '', iconSuffix: 'fa-floppy-disk', iconBaseClass: DEFAULT_ICON_BASE }, SaveClose: { value: 'Save & Close', func: 'nuSaveAction(true)', text: '', iconSuffix: 'fa-floppy-disk', iconBaseClass: DEFAULT_ICON_BASE }, Delete: { value: 'Delete', func: 'nuDeleteAction()', text: '', iconSuffix: 'fa-square-minus', iconBaseClass: DEFAULT_ICON_BASE }, Add: { value: '', func: 'nuAddAction()', text: '', iconSuffix: 'fa-plus', iconBaseClass: 'fa-solid' }, Print: { value: '', func: 'nuPrintAction()', text: '', iconSuffix: 'fa-list-ul', iconBaseClass: 'fa-solid' }, Back: { value: 'Back', func: 'nuBackAction(this)', text: '', iconSuffix: 'fa-chevron-left', iconBaseClass: 'fa-solid' }, Clone: { value: 'Clone', func: 'nuCloneAction()', text: '', iconSuffix: 'fa-clone', iconBaseClass: DEFAULT_ICON_BASE }, BuildFastForm: { value: 'Build Fast Form', func: 'nuRunPHPHidden("nu_run_fast_form", true)', text: '', iconSuffix: 'fa-bolt', iconBaseClass: 'fa-solid' }, BuildFastReport: { value: 'Build Fast Report', func: 'nuRunPHPHidden("nu_run_fast_report", true)', text: '', iconSuffix: 'fa-bolt', iconBaseClass: 'fa-solid' }, RunHidden: { value: 'Run', func: 'nuRunHiddenAction()', text: '', iconSuffix: 'fa-circle-play', iconBaseClass: DEFAULT_ICON_BASE }, Run: { value: 'Run', func: 'nuRunAction()', text: '', iconSuffix: 'fa-circle-play', iconBaseClass: DEFAULT_ICON_BASE } }; if (['Save', 'SaveClose', 'Delete', 'Clone', 'Add', 'Print', 'Run', 'Back', 'RunHidden', 'BuildFastForm', 'BuildFastReport'].includes(id)) { const def = defaults[id] || { value: id, func: `nu${id}Action()`, text: id, iconSuffix: null, iconBaseClass: DEFAULT_ICON_BASE }; value = value ?? def.value; func = func ?? def.func; title = title ?? def.text; const baseClass = def.iconBaseClass ?? DEFAULT_ICON_BASE; icon = icon ?? ( def.iconSuffix ? `${baseClass} ${ICON_SIZE_CLASSES} ${def.iconSuffix}` : null ); } if (nuSERVERRESPONSE.form_type === 'launch' && $('.nuActionButton').length === 0) { const hasAdminButtons = $('.nuAdminButton').length > 0; const actionHolderHeight = nuTotalHeight('nuActionHolder'); if (actionHolderHeight < 72 && hasAdminButtons) { $('.nuActionHolder').css('height', '72') } else if (actionHolderHeight < 45 && !hasAdminButtons) { $('.nuActionHolder').css('height', '45') } } if (typeof value === 'object') { value = nuUseMobileView() ? value.valueMobile : nuTranslate(nuDefine('value')); } else { value = nuTranslate(nuDefine(value)); } title = nuTranslate(nuDefine(title)); let nuClass = "nuActionButton"; if (['Save', 'Add', 'Clone', 'Delete'].includes(id)) { nuClass += " nu" + id + "Button"; } const elementId = "nu" + id + "Button"; let html = ``; if (insertAfterElement) { $(html).insertAfter('#' + insertAfterElement); } else { $('#nuActionHolder').append(html); } if (icon) { nuAddInputIcon(elementId, icon); } if (nuIsMobile()) { $('.nuActionButton').css('height', '35px'); } if (func) { $('#' + elementId).off('click').on('click', function () { if (typeof func === 'string') { try { new Function(func)(); } catch (e) { console.error('Error executing button action:', e); } } else { nuCallWindowFunction(func); } }); } return $('#' + elementId); } function nuAddActionButtonSaveClose(caption) { caption = nuDefine(caption, 'Save & Close'); nuAddActionButton('SaveClose', caption); $('#nuSaveCloseButton').addClass('nuSaveButton'); } (function ($) { $.fn.nuActionCheckbox = function (options) { const settings = $.extend({ id: nuID(), text: 'Checkbox', checked: false, storage: 'property', // 'property' | 'session' | 'local' onChecked: function (checked) { } }, options); function getStorageValue(key) { switch (settings.storage) { case 'session': return nuGetStorageItem(key, 'session'); case 'local': return nuGetStorageItem(key, 'local'); default: return nuGetProperty(key); } } function setStorageValue(key, value) { switch (settings.storage) { case 'session': nuSetStorageItem(key, value, 'session'); break; case 'local': nuSetStorageItem(key, value, 'local'); break; default: nuSetProperty(key, value); } } return this.each(function () { const key = settings.id + '_filter'; const initial = getStorageValue(key) === '1' || settings.checked; const $label = $('