From fd4c4c1af5c7cdadba50aad5d8a7f425beab2714 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 28 Feb 2024 00:38:18 -0500 Subject: [PATCH] Module combobox provided. change handler not implemented yet. --- .../javascript/ui/panel/AutoRunModuleForm.js | 53 ++++++++++--------- .../javascript/ui/panel/AutoRunRuleForm.js | 4 +- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/extensions/admin_ui/media/javascript/ui/panel/AutoRunModuleForm.js b/extensions/admin_ui/media/javascript/ui/panel/AutoRunModuleForm.js index ccbd90c18..09f6b5d81 100644 --- a/extensions/admin_ui/media/javascript/ui/panel/AutoRunModuleForm.js +++ b/extensions/admin_ui/media/javascript/ui/panel/AutoRunModuleForm.js @@ -7,22 +7,19 @@ loadModuleInfo = async function(token, moduleName) { throw new Error(`Getting auto run rules failed with status ${searchResponse.status}`); } const searchData = await searchResponse.json(); - console.log("Search data:"); - console.log(searchData); if (typeof searchData.id === 'number') { moduleId = searchData.id; } else { throw new Error("Searching module name failed."); } - // DEBUG log - console.log(`Successfully retrieved module id for ${moduleName} = ${moduleId}`); - const infoResponse = await fetch(`/api/modules/${moduleId}?token=${token}`); const infoData = await infoResponse.json(); if (!infoData) { throw new Error(`Module with name ${moduleName} and ID ${moduleId} couldn't be retrived.`); } + // Set the module Id incase we need it later. + infoData.id = moduleId; return infoData; } catch(error) { @@ -41,36 +38,40 @@ loadModuleInfo = async function(token, moduleName) { * moveUp: moves the module up one spot in the Auto Run execution order. * moveDown: moves the module down one spot in the Auto Run exection order. */ -AutoRunModuleForm = function(moduleData, deleteFn, moveUp, moveDown, ruleId, index) { +AutoRunModuleForm = function(moduleData, deleteFn, moveUp, moveDown, ruleId, index, moduleList) { const moduleTextAreaId = `rule-${ruleId}-module-textarea-${index}`; const chainModeComboId = `rule-${ruleId}-module-combo-${index}`; const token = BeefWUI.get_rest_token(); - // TODO: Change the module. - /* + const comboStore = new Ext.data.Store({ + data: moduleList, + reader: new Ext.data.JsonReader({ + fields: ['id', 'name'], + }), + proxy: new Ext.data.MemoryProxy(moduleList) + }); + const moduleSelect = new Ext.form.ComboBox({ - fieldLabel: 'Command Module', - store: [{name: 'hi', id: 1}], - queryMode: 'local', // Set the queryMode to 'remote' + fieldLabel: 'Change Module', + store: comboStore, + queryMode: 'local', displayField: 'name', valueField: 'id', editable: false, // Disable manual editing of the field forceSelection: true, // Force selection from the list - //listeners: { - // render: function (combo) { - // combo.setValue(moduleData.name); - // }, - // select: function(combo, newValue, oldValue) { - // if (newValue) { - // console.log("Combo value selected."); - // } - // } - //} + triggerAction: 'all', + typeAhead: true, + listeners: { + select: function(combo, newValue, oldValue) { + if (newValue) { + console.log(`Combo value selected ${newValue.name}.`); + } + } + } }); - */ const moduleOptionsContainer = new Ext.Panel({ - title: `${moduleData.name}`, + title: moduleData.name, padding: '10 10 10 10', layout: 'form', border: false, @@ -98,6 +99,10 @@ AutoRunModuleForm = function(moduleData, deleteFn, moveUp, moveDown, ruleId, ind return; } + // Update the combobox default value to be this module. + // Can't use the moduleData name since it doesn't match the ID. + moduleSelect.setValue(moduleInfo.id); + for (let i = 0; i < moduleInfo.options.length; i++) { const inputField = generate_form_input_field( moduleOptionsContainer, @@ -144,7 +149,7 @@ AutoRunModuleForm = function(moduleData, deleteFn, moveUp, moveDown, ruleId, ind AutoRunModuleForm.superclass.constructor.call(this, { items: [ - //moduleSelect, + moduleSelect, moduleOptionsContainer, buttonContainer ] diff --git a/extensions/admin_ui/media/javascript/ui/panel/AutoRunRuleForm.js b/extensions/admin_ui/media/javascript/ui/panel/AutoRunRuleForm.js index f5be4569d..6486d842e 100644 --- a/extensions/admin_ui/media/javascript/ui/panel/AutoRunRuleForm.js +++ b/extensions/admin_ui/media/javascript/ui/panel/AutoRunRuleForm.js @@ -87,13 +87,13 @@ AutoRunRuleForm = function(rule, modules, deleteFn, updateFn) { isFirstModule ? undefined : function() {reorderModule(i, 'forward')}, isLastModule ? undefined : function() {reorderModule(i, 'back')}, rule.id, - i + i, + modules )); } } function handleUpdateRule() { - // TODO: Check if inputs are valid. // TODO: Need to overwrite module order. const form = self.getForm(); const formValues = form.getValues();