[open-ils-commits] r19192 - in trunk/Open-ILS/web: js/dojo/openils/widget templates/default/serial/subscription (senator)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Jan 18 13:35:08 EST 2011


Author: senator
Date: 2011-01-18 13:35:04 -0500 (Tue, 18 Jan 2011)
New Revision: 19192

Modified:
   trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
   trunk/Open-ILS/web/js/dojo/openils/widget/EditPane.js
   trunk/Open-ILS/web/templates/default/serial/subscription/distribution.tt2
Log:
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.


Modified: trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js	2011-01-18 18:15:29 UTC (rev 19191)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js	2011-01-18 18:35:04 UTC (rev 19192)
@@ -174,6 +174,18 @@
             }
         },
 
+        isRequired : function() {
+            return (
+                !this.readOnly && (
+                    this.idlField.required || (
+                        this.dijitArgs && (
+                            this.dijitArgs.required || this.dijitArgs.regExp
+                        )
+                    )
+                )
+            );
+        },
+
         build : function(onload) {
 
             if(this.widgetValue == null)

Modified: trunk/Open-ILS/web/js/dojo/openils/widget/EditPane.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/EditPane.js	2011-01-18 18:15:29 UTC (rev 19191)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/EditPane.js	2011-01-18 18:35:04 UTC (rev 19192)
@@ -197,8 +197,14 @@
 
             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 @@
                 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") {

Modified: trunk/Open-ILS/web/templates/default/serial/subscription/distribution.tt2
===================================================================
--- trunk/Open-ILS/web/templates/default/serial/subscription/distribution.tt2	2011-01-18 18:15:29 UTC (rev 19191)
+++ trunk/Open-ILS/web/templates/default/serial/subscription/distribution.tt2	2011-01-18 18:35:04 UTC (rev 19192)
@@ -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"



More information about the open-ils-commits mailing list