diff --git a/apps/dashboard/app/controllers/scripts_controller.rb b/apps/dashboard/app/controllers/scripts_controller.rb index 0746925c89..fe93fdaae0 100644 --- a/apps/dashboard/app/controllers/scripts_controller.rb +++ b/apps/dashboard/app/controllers/scripts_controller.rb @@ -7,8 +7,10 @@ class ScriptsController < ApplicationController before_action :find_script, only: [:show, :edit, :destroy, :submit, :save] SAVE_SCRIPT_KEYS = [ - :cluster, :auto_accounts, :auto_accounts_exclude, :auto_accounts_fixed, :auto_scripts, :auto_scripts_exclude, :auto_scripts_fixed, - :auto_queues, :auto_queues_exclude, :auto_queues_fixed, :auto_batch_clusters, :auto_batch_clusters_exclude, :auto_batch_clusters_fixed, + :cluster, :auto_accounts, :auto_accounts_exclude, :auto_accounts_fixed, + :auto_scripts, :auto_scripts_exclude, :auto_scripts_fixed, + :auto_queues, :auto_queues_exclude, :auto_queues_fixed, + :auto_batch_clusters, :auto_batch_clusters_exclude, :auto_batch_clusters_fixed, :bc_num_slots, :bc_num_slots_fixed, :bc_num_slots_min, :bc_num_slots_max, :bc_num_hours, :bc_num_hours_fixed, :bc_num_hours_min, :bc_num_hours_max ].freeze diff --git a/apps/dashboard/app/javascript/packs/script_edit.js b/apps/dashboard/app/javascript/packs/script_edit.js index 861551c9cd..8c9a0f9c8c 100644 --- a/apps/dashboard/app/javascript/packs/script_edit.js +++ b/apps/dashboard/app/javascript/packs/script_edit.js @@ -125,11 +125,33 @@ function addInProgressField(event) { entireDiv.remove(); } +function fixedFieldEnabled(checkbox, dataElement) { + dataElement.disabled = true; + const input = $('').attr('type','hidden').attr('name', dataElement.name).attr('value', dataElement.value); + $(checkbox).after(input); +} + +function toggleFixed(event) { + const dataElement = document.getElementById(event.target.dataset.selectId); + if (event.target.checked) { + fixedFieldEnabled(event.target, dataElement) + } else { + dataElement.disabled = false; + $(`input[type=hidden][name="${dataElement.name}"]`).remove(); + } +} + function enableOrDisableSelectOption(event) { const toggleAction = event.target.dataset.selectToggler; const li = event.target.parentElement; event.target.disabled = true; + if(toggleAction == 'fixed') { + toggleFixed(event) + event.target.disabled = false; + return + } + const inputId = event.target.dataset.target; const choice = $(li).find('[data-select-value]')[0].textContent; @@ -197,6 +219,15 @@ function initSelectFields(){ optionToToggle.disabled = true; optionToToggle.selected = false; }); + + // find all the enabled 'fixed' checkboxes + allButtons.filter((fixedFieldCheckbox) => { + return fixedFieldCheckbox.checked; + // now disable the select field + }).map((fixedFieldCheckbox) => { + const dataElement = document.getElementById(fixedFieldCheckbox.dataset.selectId); + fixedFieldEnabled(fixedFieldCheckbox, dataElement) + }); } jQuery(() => { diff --git a/apps/dashboard/app/models/script.rb b/apps/dashboard/app/models/script.rb index 1a2edde3c5..15e678c295 100644 --- a/apps/dashboard/app/models/script.rb +++ b/apps/dashboard/app/models/script.rb @@ -201,7 +201,7 @@ def self.script_form_file(script_path) # parameters you got from the controller that affect the attributes, not form. # i.e., mins & maxes you set in the form but get serialized to the 'attributes' section. def attribute_parameter?(name) - name.end_with?('_min') || name.end_with?('_max') || name.end_with?('_exclude') || name.end_with?('_fixed') + ['min', 'max', 'exclude', 'fixed'].any? { |postfix| name && name.end_with?("_#{postfix}") } end # update the 'form' portion of the yaml file given 'params' from the controller. diff --git a/apps/dashboard/app/views/scripts/editable_form_fields/_edit_fixed_field.html.erb b/apps/dashboard/app/views/scripts/editable_form_fields/_edit_fixed_field.html.erb new file mode 100644 index 0000000000..172885e721 --- /dev/null +++ b/apps/dashboard/app/views/scripts/editable_form_fields/_edit_fixed_field.html.erb @@ -0,0 +1,12 @@ +<%- + field_id = "#{form.object_name}_#{attrib.id}" + + fixed_id = "#{field_id}_fixed" + fixed_name = "#{form.object_name}[#{attrib.id}_fixed]" +-%> +