From baa86efd15a880bd65d22db09fbf2147928b9e17 Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 23 Jan 2009 16:40:58 +0000 Subject: [PATCH] plugged in option to build cancel and 'apply' buttons. next steps are 1. i18n for buttons, 2. use widget template instead of manual element creation git-svn-id: svn://svn.open-ils.org/ILS/trunk@11936 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/dojo/openils/widget/AutoWidget.js | 2 +- Open-ILS/web/js/dojo/openils/widget/EditDialog.js | 3 ++ Open-ILS/web/js/dojo/openils/widget/EditPane.js | 46 +++++++++++++++++------ 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoWidget.js b/Open-ILS/web/js/dojo/openils/widget/AutoWidget.js index 9b05657301..ad9df60cc0 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoWidget.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoWidget.js @@ -112,7 +112,7 @@ if(!dojo._hasResource['openils.widget.AutoWidget']) { this.widget.searchAttr = 'shortname'; this.widget.labelAttr = 'shortname'; this.widget.parentField = 'parent_ou'; - // + // if we have a limit perm, find the relevent orgs (async) if(this.orgLimitPerms && this.orgLimitPerms.length > 0) { this.async = true; diff --git a/Open-ILS/web/js/dojo/openils/widget/EditDialog.js b/Open-ILS/web/js/dojo/openils/widget/EditDialog.js index 68b5fb9fdd..9fc5bfc9dd 100644 --- a/Open-ILS/web/js/dojo/openils/widget/EditDialog.js +++ b/Open-ILS/web/js/dojo/openils/widget/EditDialog.js @@ -16,6 +16,9 @@ if(!dojo._hasResource['openils.widget.EditDialog']) { constructor : function() { this.editPane = new openils.widget.EditPane(); + var self = this; + this.editPane.onCancel = function() { self.hide(); } + this.editPane.onPostApply = function() { self.hide(); } }, /** diff --git a/Open-ILS/web/js/dojo/openils/widget/EditPane.js b/Open-ILS/web/js/dojo/openils/widget/EditPane.js index 875a30826c..1e9f56597e 100644 --- a/Open-ILS/web/js/dojo/openils/widget/EditPane.js +++ b/Open-ILS/web/js/dojo/openils/widget/EditPane.js @@ -18,6 +18,9 @@ if(!dojo._hasResource['openils.widget.EditPane']) { fieldOrder : null, // ordered list of field names, optional. fieldList : [], // holds the field name + associated widget sortedFieldList : [], // holds the sorted IDL defs for our fields + onPostApply : null, // apply callback + onCancel : null, // cancel callback + hideActionButtons : false, /** * Builds a basic table of key / value pairs. Keys are IDL display labels. @@ -61,10 +64,39 @@ if(!dojo._hasResource['openils.widget.EditPane']) { widget.build(); this.fieldList.push({name:field.name, widget:widget}); } - + if(!this.hideActionButtons) + this.buildActionButtons(tbody); + openils.Util.addCSSClass(table, 'oils-fm-edit-dialog'); }, + buildActionButtons : function(tbody) { + var row = document.createElement('tr'); + var cancelTd = document.createElement('td'); + var applyTd = document.createElement('td'); + row.appendChild(cancelTd); + row.appendChild(applyTd); + tbody.appendChild(row); + + var self = this; + new dijit.form.Button({ + label:'Cancel', // XXX + onClick : this.onCancel + }, cancelTd); + + new dijit.form.Button({ + label:'Save', // XXX + onClick: function() { + self.performEditAction({ + oncomplete:function() { + if(self.onPostApply) + self.onPostApply(); + } + }); + } + }, applyTd); + }, + getFields : function() { return this.fieldList.map(function(a) { return a.name }); }, @@ -128,21 +160,13 @@ if(!dojo._hasResource['openils.widget.EditPane']) { }, performEditAction : function(opts) { - var pcrud = new openils.PermaCrud(); 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])); - - if(opts.async) { - opts.oncomplete = function(r) { - pcrud.disconnect() - opts.oncomplete(r); - }; - } - pcrud[this.mode](this.fmObject, opts); - if(!opts.async) pcrud.disconnect(); } } ); -- 2.11.0