Make EditPane objects built of AutoFieldWidget objects (such as those used
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 18 Jan 2011 18:35:04 +0000 (18:35 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 18 Jan 2011 18:35:04 +0000 (18:35 +0000)
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

Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
Open-ILS/web/js/dojo/openils/widget/EditPane.js
Open-ILS/web/templates/default/serial/subscription/distribution.tt2

index c4b4856..ba05bc1 100644 (file)
@@ -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)
index 7938695..e3262de 100644 (file)
@@ -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") {
index 7d3a318..d8f4b0d 100644 (file)
@@ -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"