From a66e257f791c550a00f3b927c2d34abf34a920e7 Mon Sep 17 00:00:00 2001 From: Dan Wells Date: Tue, 7 Jun 2011 12:06:57 -0400 Subject: [PATCH] Support for required fields in Serial Control editors Adds a basic check for any fields marked as 'required', and alerts and prevents submitting if they are blank. Signed-off-by: Dan Wells --- .../staff_client/server/locale/en-US/serial.properties | 1 + Open-ILS/xul/staff_client/server/serial/editor_base.js | 17 ++++++++++++++++- Open-ILS/xul/staff_client/server/serial/scap_editor.js | 6 ++++-- Open-ILS/xul/staff_client/server/serial/sdist_editor.js | 4 +++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Open-ILS/xul/staff_client/server/locale/en-US/serial.properties b/Open-ILS/xul/staff_client/server/locale/en-US/serial.properties index 12463fe7ab..603cfb1303 100644 --- a/Open-ILS/xul/staff_client/server/locale/en-US/serial.properties +++ b/Open-ILS/xul/staff_client/server/locale/en-US/serial.properties @@ -83,6 +83,7 @@ staff.serial.manage_subs.delete_ssub.confirm=Are you sure you would like to dele staff.serial.manage_subs.delete_ssub.confirm.plural=Are you sure you would like to delete these %1$s subscriptions? staff.serial.manage_subs.delete_ssub.title=Delete Subscriptions? staff.serial.manage_subs.delete_ssub.override=Override Delete Failure? Doing so will delete all related data as well! +staff.serial.required_fields_alert=These fields are required: batch_receive.bib_lookup.empty=Enter a search term. batch_receive.bib_lookup.multiple=Multiple matching records found. Please use a more specific identifier, or use the catalog to find the exact record you want. batch_receive.bib_lookup.not_found=No matching records found with any subscriptions attached. diff --git a/Open-ILS/xul/staff_client/server/serial/editor_base.js b/Open-ILS/xul/staff_client/server/serial/editor_base.js index efc08fd75f..2d5ae08251 100644 --- a/Open-ILS/xul/staff_client/server/serial/editor_base.js +++ b/Open-ILS/xul/staff_client/server/serial/editor_base.js @@ -249,6 +249,7 @@ serial.editor_base = { 'editor_base_summarize' : function(my_fms) { var obj = this; + var fm_type = obj.fm_type; /******************************************************************************************************/ /* Setup */ @@ -262,6 +263,8 @@ serial.editor_base = { /******************************************************************************************************/ /* Loop through the field names */ + obj.missing_required = []; + for (var i = 0; i < obj.field_names.length; i++) { var field_name = obj.field_names[i][0]; @@ -269,6 +272,7 @@ serial.editor_base = { var attr = obj.field_names[i][1].attr; var value_key = obj.field_names[i][1].value_key; var dropdown_key = obj.field_names[i][1].dropdown_key; + var required = obj.field_names[i][1].required; obj.summary[ field_name ] = {}; /******************************************************************************************************/ @@ -293,9 +297,14 @@ serial.editor_base = { } else if (value_key) { obj.editor_values[value_key] = value; } + if (required && value == "") { + obj.missing_required.push(fieldmapper.IDL.fmclasses[fm_type].field_map[field_name].label); //TODO: consider applying a style + } + if (value == "") { value = $('serialStrings').getString('serial.editor_base.unset'); } + } catch(E) { obj.error.sdump('D_ERROR','Attempted ' + cmd + '\n' + E + '\n'); } @@ -313,6 +322,7 @@ serial.editor_base = { } } } + obj.error.sdump('D_TRACE','summary = ' + js2JSON(obj.summary) + '\n'); }, @@ -540,11 +550,16 @@ serial.editor_base = { 'editor_base_save' : function(update_method) { var obj = this; var fm_type_plural = obj.fm_type_plural; - var fm_type= obj.fm_type; + var fm_type = obj.fm_type; try { if (obj.handle_update) { try { + if (obj.missing_required.length > 0) { + alert($('serialStrings').getString('staff.serial.required_fields_alert') + obj.missing_required.join(', ')); + return; //stop submission + } + //send fms to the update function var r = obj.network.request( 'open-ils.serial', diff --git a/Open-ILS/xul/staff_client/server/serial/scap_editor.js b/Open-ILS/xul/staff_client/server/serial/scap_editor.js index 44f4627f0d..d61d99daf4 100644 --- a/Open-ILS/xul/staff_client/server/serial/scap_editor.js +++ b/Open-ILS/xul/staff_client/server/serial/scap_editor.js @@ -83,7 +83,8 @@ serial.scap_editor.prototype = { 'type', { input: 'c = function(v){ obj.apply("type",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ ["basic", "basic"], ["index", "index"], ["supplement", "supplement"] ] ); x.setAttribute("value",obj.editor_values.type); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);', - value_key: 'type' + value_key: 'type', + required: true } ], [ @@ -99,7 +100,8 @@ serial.scap_editor.prototype = { 'pattern_code', { input: 'c = function(v){ obj.apply("pattern_code",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.setAttribute("multiline",true); x.setAttribute("cols",40); x.setAttribute("value",obj.editor_values.pattern_code); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);', - value_key: 'pattern_code' + value_key: 'pattern_code', + required: true } ] ] diff --git a/Open-ILS/xul/staff_client/server/serial/sdist_editor.js b/Open-ILS/xul/staff_client/server/serial/sdist_editor.js index 0045f46d3b..908a90e55d 100644 --- a/Open-ILS/xul/staff_client/server/serial/sdist_editor.js +++ b/Open-ILS/xul/staff_client/server/serial/sdist_editor.js @@ -155,7 +155,8 @@ serial.sdist_editor.prototype = { 'label', { input: 'c = function(v){ obj.apply("label",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.setAttribute("value",obj.editor_values.label); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);', - value_key: 'label' + value_key: 'label', + required: true } ], [ @@ -248,6 +249,7 @@ serial.sdist_editor.prototype = { }; for (i in obj.panes_and_field_names) { obj.panes_and_field_names[obj.xul_id_prefix + i] = obj.panes_and_field_names[i]; + delete obj.panes_and_field_names[i]; } }, -- 2.11.0