mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-05 09:41:56 -07:00
FE: None❌ value fixes and overrides of setting values
Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
@@ -339,7 +339,7 @@ function getDeviceData() {
|
|||||||
</i>
|
</i>
|
||||||
</label>
|
</label>
|
||||||
<div class="${obj.inputClasses}">
|
<div class="${obj.inputClasses}">
|
||||||
${generateFormHtml(settingsData, setting, fieldData.toString(), fieldOptionsOverride, null)}
|
${generateFormHtml(settingsData, setting, fieldData.toString(), fieldOptionsOverride, null, mac == "new")}
|
||||||
${inlineControl}
|
${inlineControl}
|
||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ function getSettingOptions (key) {
|
|||||||
|
|
||||||
if (result == "")
|
if (result == "")
|
||||||
{
|
{
|
||||||
console.log(`Setting options with key "${key}" not found`)
|
// console.log(`Setting options with key "${key}" not found`)
|
||||||
result = []
|
result = []
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,10 +197,10 @@ function getSetting (key) {
|
|||||||
|
|
||||||
result = getCache(`nax_set_${key}`, true);
|
result = getCache(`nax_set_${key}`, true);
|
||||||
|
|
||||||
if (result == "")
|
// if (result == "")
|
||||||
{
|
// {
|
||||||
console.log(`Setting with key "${key}" not found`)
|
// console.log(`Setting with key "${key}" not found`)
|
||||||
}
|
// }
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,7 +170,8 @@ function showModalPopupForm(
|
|||||||
curValue = null,
|
curValue = null,
|
||||||
popupFormJson = null,
|
popupFormJson = null,
|
||||||
parentSettingKey = null,
|
parentSettingKey = null,
|
||||||
triggeredBy = null
|
triggeredBy = null,
|
||||||
|
populateFromOverrides = true
|
||||||
) {
|
) {
|
||||||
// set captions
|
// set captions
|
||||||
prefix = "modal-form";
|
prefix = "modal-form";
|
||||||
@@ -229,7 +230,8 @@ function showModalPopupForm(
|
|||||||
setObj,
|
setObj,
|
||||||
null,
|
null,
|
||||||
fieldOptionsOverride,
|
fieldOptionsOverride,
|
||||||
null
|
null,
|
||||||
|
populateFromOverrides // is new entry
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -321,7 +321,8 @@ function addViaPopupForm(element) {
|
|||||||
null, // curValue
|
null, // curValue
|
||||||
popupFormJson, // popupform
|
popupFormJson, // popupform
|
||||||
toId, // parentSettingKey
|
toId, // parentSettingKey
|
||||||
element // triggeredBy
|
element, // triggeredBy
|
||||||
|
true // initialize defaut values
|
||||||
);
|
);
|
||||||
|
|
||||||
// flag something changes to prevent navigating from page
|
// flag something changes to prevent navigating from page
|
||||||
@@ -475,7 +476,8 @@ function initListInteractionOptions(element) {
|
|||||||
curValue, // curValue
|
curValue, // curValue
|
||||||
popupFormJson, // popupform
|
popupFormJson, // popupform
|
||||||
toId, // parentSettingKey
|
toId, // parentSettingKey
|
||||||
this // triggeredBy
|
this, // triggeredBy
|
||||||
|
true // populate overrides
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Fallback to normal field input
|
// Fallback to normal field input
|
||||||
@@ -1132,24 +1134,44 @@ function collectSetting(prefix, setCodeName, setType, settingsArray) {
|
|||||||
|
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
// Generate the form control for setting
|
// Generate the form control for setting
|
||||||
function generateFormHtml(settingsData, set, overrideValue, overrideOptions, originalSetKey) {
|
/**
|
||||||
|
* Generates the HTML string for form controls based on setting configurations.
|
||||||
|
* Supports various element types including select, input, button, textarea, span, and recursive datatables.
|
||||||
|
* * @param {Object} settingsData - The global settings object containing configuration for all available settings.
|
||||||
|
* @param {Object} set - The specific configuration object for the current setting.
|
||||||
|
* @param {string} set.setKey - Unique identifier for the setting.
|
||||||
|
* @param {string} set.setType - JSON string defining the UI components (dataType, elements, etc.).
|
||||||
|
* @param {string} [set.setValue] - The default value for the setting.
|
||||||
|
* @param {Array|string} [set.setEvents] - List of event triggers to be rendered as clickable icons.
|
||||||
|
* @param {any} overrideValue - The current value to be displayed in the form control.
|
||||||
|
* @param {any} overrideOptions - Custom options to override the default setting options (used primarily for dropdowns).
|
||||||
|
* @param {string} originalSetKey - The base key name (used to maintain reference when keys are modified for uniqueness in tables).
|
||||||
|
* @param {boolean} populateFromOverrides - Flag to determine if the value should be pulled from `set['setValue']` (true) or `overrideValue` (false).
|
||||||
|
* * @returns {string} A string of HTML containing the form elements and any associated event action icons.
|
||||||
|
* * @example
|
||||||
|
* const html = generateFormHtml(allSettings, currentSet, "DefaultVal", null, "my_key", false);
|
||||||
|
* $('#container').html(html);
|
||||||
|
*/
|
||||||
|
function generateFormHtml(settingsData, set, overrideValue, overrideOptions, originalSetKey, populateFromOverrides) {
|
||||||
let inputHtml = '';
|
let inputHtml = '';
|
||||||
|
|
||||||
|
|
||||||
// if override value is considered empty initialize from setting defaults
|
// if override value is considered empty initialize from setting defaults
|
||||||
overrideValue == null || overrideValue == undefined ? inVal = set['setValue'] : inVal = overrideValue
|
populateFromOverrides ? inVal = set['setValue'] : inVal = overrideValue;
|
||||||
|
|
||||||
const setKey = set['setKey'];
|
const setKey = set['setKey'];
|
||||||
const setType = set['setType'];
|
const setType = set['setType'];
|
||||||
|
|
||||||
// if (setKey == 'NEWDEV_devParentMAC') {
|
// if (setKey == 'UNIFIAPI_site_name') {
|
||||||
|
|
||||||
// console.log("==== DEBUG OUTPUT BELOW 1 ====");
|
// console.log("==== DEBUG OUTPUT BELOW 1 ====");
|
||||||
// console.log(setType);
|
// console.log("populateFromOverrides: " + populateFromOverrides);
|
||||||
// console.log(setKey);
|
// console.log(setType);
|
||||||
// console.log(overrideValue);
|
// console.log(setKey);
|
||||||
// console.log(inVal);
|
// console.log("overrideValue:" + overrideValue);
|
||||||
|
// console.log("inVal:" + inVal);
|
||||||
// }
|
// console.log("set['setValue']:" + set['setValue']);
|
||||||
|
// }
|
||||||
|
|
||||||
// Parse the setType JSON string
|
// Parse the setType JSON string
|
||||||
// console.log(processQuotes(setType));
|
// console.log(processQuotes(setType));
|
||||||
@@ -1189,15 +1211,14 @@ function generateFormHtml(settingsData, set, overrideValue, overrideOptions, ori
|
|||||||
// Override value
|
// Override value
|
||||||
let val = valRes;
|
let val = valRes;
|
||||||
|
|
||||||
// if (setKey == 'NEWDEV_devParentMAC') {
|
// if (setKey == 'UNIFIAPI_site_name') {
|
||||||
|
|
||||||
// console.log("==== DEBUG OUTPUT BELOW 2 ====");
|
// console.log("==== DEBUG OUTPUT BELOW 2 ====");
|
||||||
// console.log(setType);
|
// console.log(setType);
|
||||||
// console.log(setKey);
|
// console.log(setKey);
|
||||||
// console.log(overrideValue);
|
// console.log("overrideValue:" + overrideValue);
|
||||||
// console.log(inVal);
|
// console.log("inVal:" + inVal);
|
||||||
// console.log(val);
|
// console.log("val:" + val);
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Generate HTML based on elementType
|
// Generate HTML based on elementType
|
||||||
@@ -1227,7 +1248,7 @@ function generateFormHtml(settingsData, set, overrideValue, overrideOptions, ori
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'input':
|
case 'input':
|
||||||
const checked = val === 'True' || val === 'true' || val === '1' ? 'checked' : '';
|
const checked = val === 'True' || val === 'true' || val === '1' || val == true ? 'checked' : '';
|
||||||
const inputClass = inputType === 'checkbox' ? 'checkbox' : 'form-control';
|
const inputClass = inputType === 'checkbox' ? 'checkbox' : 'form-control';
|
||||||
|
|
||||||
inputHtml += `<input
|
inputHtml += `<input
|
||||||
@@ -1347,22 +1368,23 @@ function generateFormHtml(settingsData, set, overrideValue, overrideOptions, ori
|
|||||||
// Extract the value for the current column
|
// Extract the value for the current column
|
||||||
let columnOverrideValue = rowData[j] && Object.values(rowData[j])[0];
|
let columnOverrideValue = rowData[j] && Object.values(rowData[j])[0];
|
||||||
|
|
||||||
if(columnOverrideValue == undefined)
|
|
||||||
{
|
|
||||||
columnOverrideValue = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create unique key to prevent dropdown data duplication
|
// Create unique key to prevent dropdown data duplication
|
||||||
const oldKey = set["setKey"];
|
const oldKey = set["setKey"];
|
||||||
set["setKey"] = oldKey + "_" + index;
|
set["setKey"] = oldKey + "_" + index;
|
||||||
|
|
||||||
|
// console.log("settingsData");
|
||||||
|
// console.log(settingsData);
|
||||||
|
// console.log(set);
|
||||||
|
|
||||||
|
|
||||||
// Generate the cell HTML using the extracted value
|
// Generate the cell HTML using the extracted value
|
||||||
const cellHtml = generateFormHtml(
|
const cellHtml = generateFormHtml(
|
||||||
settingsData,
|
settingsData,
|
||||||
set,
|
set,
|
||||||
columnOverrideValue.toString(),
|
columnOverrideValue,
|
||||||
set["setOptions"],
|
set["setOptions"],
|
||||||
oldKey
|
oldKey,
|
||||||
|
false
|
||||||
);
|
);
|
||||||
datatableHtml += `<td> <div class="input-group"> ${cellHtml} </div></td>`;
|
datatableHtml += `<td> <div class="input-group"> ${cellHtml} </div></td>`;
|
||||||
|
|
||||||
|
|||||||
@@ -511,10 +511,10 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX
|
|||||||
}
|
}
|
||||||
|
|
||||||
// INPUT
|
// INPUT
|
||||||
inputFormHtml = generateFormHtml(settingsData, set, valIn, null, null);
|
inputFormHtml = generateFormHtml(settingsData, set, valIn, null, null, false);
|
||||||
|
|
||||||
// construct final HTML for the setting
|
// construct final HTML for the setting
|
||||||
setHtml += inputFormHtml + overrideHtml + `
|
setHtml += inputFormHtml + overrideHtml + `
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
|
|||||||
Reference in New Issue
Block a user