From 32bb3a12a177fb1cfdd5fdcc41f26a9f4cec3c02 Mon Sep 17 00:00:00 2001 From: senator Date: Tue, 18 Jan 2011 18:35:04 +0000 Subject: [PATCH] Make EditPane objects built of AutoFieldWidget objects (such as those used for create/edit dialogs with AutoGrid) enforce required fields more forcefully. Before, if a field was marked required either in the IDL or by the requirdFields attribute of an AutoGrid, you'd get a yellow widget with a caution sign for that field, but you could still click save and the system would attempt to save your object. Sometimes this is stopped when pcrud can't save the object due to required="true" in the IDL and/or a "not null" constraint in the schema, but there may be cases where a given interface wants to require a value in a given field even though that's not necessarily enforced at lower levels. Serials: Specifically use this new feature in the distribution pane of the Alternate Serial Control view, to prevent the creation of issues without a "receive unit template" field, as you can't receive items in the Batch Receive interface without one. git-svn-id: svn://svn.open-ils.org/ILS/trunk@19192 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../web/js/dojo/openils/widget/AutoFieldWidget.js | 12 +++++++++++ Open-ILS/web/js/dojo/openils/widget/EditPane.js | 24 ++++++++++++++++++---- .../default/serial/subscription/distribution.tt2 | 1 + 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js index c4b4856f17..ba05bc1b97 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js @@ -174,6 +174,18 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) { } }, + isRequired : function() { + return ( + !this.readOnly && ( + this.idlField.required || ( + this.dijitArgs && ( + this.dijitArgs.required || this.dijitArgs.regExp + ) + ) + ) + ); + }, + build : function(onload) { if(this.widgetValue == null) diff --git a/Open-ILS/web/js/dojo/openils/widget/EditPane.js b/Open-ILS/web/js/dojo/openils/widget/EditPane.js index 79386954f2..e3262defc9 100644 --- a/Open-ILS/web/js/dojo/openils/widget/EditPane.js +++ b/Open-ILS/web/js/dojo/openils/widget/EditPane.js @@ -197,8 +197,14 @@ if(!dojo._hasResource['openils.widget.EditPane']) { getFieldValue : function(field) { for(var i in this.fieldList) { - if(field == this.fieldList[i].name) - return this.fieldList[i].widget.getFormattedValue(); + if(field == this.fieldList[i].name) { + var val = this.fieldList[i].widget.getFormattedValue(); + if (val == null && /* XXX stricter check needed? */ + this.fieldList[i].widget.isRequired()) { + throw new Error("req"); + } + return val; + } } }, @@ -217,8 +223,18 @@ if(!dojo._hasResource['openils.widget.EditPane']) { var fields = this.getFields(); if(this.mode == 'create') this.fmObject = new fieldmapper[this.fmClass](); - for(var idx in fields) - this.fmObject[fields[idx]](this.getFieldValue(fields[idx])); + try { + for(var idx in fields) { + this.fmObject[fields[idx]]( + this.getFieldValue(fields[idx]) + ); + } + } catch (E) { + if (E.message == "req") /* req'd field set to null. bail. */ + return; + else /* something else went wrong? */ + throw E; + } if(this.mode == 'create' && this.fmIDL.pkey_sequence) this.fmObject[this.fmIDL.pkey](null); if (typeof(this.onSubmit) == "function") { diff --git a/Open-ILS/web/templates/default/serial/subscription/distribution.tt2 b/Open-ILS/web/templates/default/serial/subscription/distribution.tt2 index 7d3a318ecb..d8f4b0d549 100644 --- a/Open-ILS/web/templates/default/serial/subscription/distribution.tt2 +++ b/Open-ILS/web/templates/default/serial/subscription/distribution.tt2 @@ -22,6 +22,7 @@ fieldOrder="['subscription','label','holding_lib']" suppressFields="['record_entry','subscription','receive_call_number','bind_call_number','bind_unit_template']" suppressEditFields="['record_entry','receive_call_number','bind_call_number','bind_unit_template']" + requiredFields="['receive_unit_template']" fmClass="sdist" query="{id: '*'}" editOnEnter="true" -- 2.11.0