added option to launch creation dialog from auto grid. passing final pcrud response...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 5 Feb 2009 14:36:42 +0000 (14:36 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 5 Feb 2009 14:36:42 +0000 (14:36 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@12077 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/widget/AutoGrid.js
Open-ILS/web/js/dojo/openils/widget/EditDialog.js
Open-ILS/web/js/dojo/openils/widget/EditPane.js
Open-ILS/web/templates/default/conify/global/acq/exchange_rate.tt2

index 441f6fc..4c44d1e 100644 (file)
@@ -26,7 +26,8 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) {
                 for(var f in this.sortedFieldList) {
                     var field = this.sortedFieldList[f];
                     if(!field || field.virtual) continue;
-                    var entry = existing.filter(function(i){return (i.field == field.name)})[0];
+                    var entry = existing.filter(
+                        function(i){return (i.field == field.name)})[0];
                     if(entry) entry.name = field.label;
                     else entry = {field:field.name, name:field.label};
                     fields.push(entry);
@@ -67,7 +68,7 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) {
                 var idents = grid.store.getIdentityAttributes();
                 var dialog = new openils.widget.EditDialog({
                     fmObject:fmObject,
-                    onPostApply : function() {
+                    onPostSubmit : function() {
                         for(var i in fmObject._fields) {
                             var field = fmObject._fields[i];
                             if(idents.filter(function(j){return (j == field)})[0])
@@ -79,10 +80,30 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) {
                     }
                 });
                 dialog.editPane.fieldOrder = this.fieldOrder;
+                dialog.editPane.mode = 'update';
+                dialog.startup();
+                dialog.show();
+            },
+
+            showCreateDialog : function() {
+                var grid = this;
+                var dialog = new openils.widget.EditDialog({
+                    fmClass : this.fmClass,
+                    onPostSubmit : function(r) {
+                        var fmObject = openils.Util.readResponse(r);
+                        if(fmObject) {
+                            grid.store.newItem(fmObject.toStoreItem());
+                            grid.update();
+                        }
+                        dialog.destroy();
+                    }
+                });
+                dialog.editPane.fieldOrder = this.fieldOrder;
+                dialog.editPane.mode = 'create';
                 dialog.startup();
                 dialog.show();
             }
-        }
+        } 
     );
     openils.widget.AutoGrid.markupFactory = dojox.grid.DataGrid.markupFactory;
 
index 734c185..3db5a13 100644 (file)
@@ -34,10 +34,10 @@ if(!dojo._hasResource['openils.widget.EditDialog']) {
                     self.hide(); 
                 }
 
-                this.editPane.onPostApply = function() { 
+                this.editPane.onPostSubmit = function(r) { 
                     self.hide(); 
-                    if(args.onPostApply)
-                        args.onPostApply();
+                    if(args.onPostSubmit)
+                        args.onPostSubmit(r);
                 }
             },
 
index 3c4e712..9069b29 100644 (file)
@@ -12,7 +12,7 @@ if(!dojo._hasResource['openils.widget.EditPane']) {
         [dijit.layout.ContentPane, openils.widget.AutoWidget],
         {
             mode : 'update',
-            onPostApply : null, // apply callback
+            onPostSubmit : null, // apply callback
             onCancel : null, // cancel callback
             hideActionButtons : false,
 
@@ -58,6 +58,7 @@ if(!dojo._hasResource['openils.widget.EditPane']) {
                         parentNode : valTd,
                         orgLimitPerms : this.limitPerms
                     });
+
                     widget.build();
                     this.fieldList.push({name:field.name, widget:widget});
                     this.applySaveOnEnter(widget);
@@ -112,9 +113,9 @@ if(!dojo._hasResource['openils.widget.EditPane']) {
             performAutoEditAction : function() {
                 var self = this;
                 self.performEditAction({
-                    oncomplete:function() {
-                        if(self.onPostApply)
-                            self.onPostApply();
+                    oncomplete:function(r) {
+                        if(self.onPostSubmit)
+                            self.onPostSubmit(r);
                     }
                 });
             },
@@ -126,6 +127,8 @@ if(!dojo._hasResource['openils.widget.EditPane']) {
                     this.fmObject = new fieldmapper[this.fmClass]();
                 for(var idx in fields)  
                     this.fmObject[fields[idx]](this.getFieldValue(fields[idx]));
+                if(this.mode == 'create')
+                    this.fmObject[fieldmapper[this.fmClass].Identifier](null);
                 pcrud[this.mode](this.fmObject, opts);
             }
         }
index 2d3a52c..0e5042a 100644 (file)
@@ -23,6 +23,7 @@
     }
     openils.Util.addOnLoad(renderGrid);
 </script>
+<button dojoType='dijit.form.Button' onClick='erGrid.showCreateDialog()'>Create</button>
 <div dojoType="dijit.layout.ContentPane" layoutAlign="top" style='height:600px;'>
     <table jsId="erGrid" dojoType="openils.widget.AutoGrid" 
             fieldOrder="['id', 'from_currency', 'to_currency', 'ratio']"