From 588ccb0213b0f30f751cf4309c07e058efcdaf91 Mon Sep 17 00:00:00 2001 From: senator Date: Mon, 18 Oct 2010 21:53:44 +0000 Subject: [PATCH] Make editing of asset.copy_template a little more friendly (AutoGrid w/ pcrud can't deal with editor/creator fields for you). Incidentally add createPaneOnSubmit and editPaneOnSubmit attributes to AutoGrid that take a function name as their values, specifying an alternate callback function to use instead of pcrud.create/update git-svn-id: svn://svn.open-ils.org/ILS/trunk@18386 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/Application/Cat.pm | 31 ++++++++++++++++++++++ Open-ILS/web/js/dojo/openils/widget/AutoGrid.js | 6 +++++ Open-ILS/web/js/dojo/openils/widget/EditPane.js | 3 ++- .../default/conify/global/asset/copy_template.js | 15 +++++++++++ .../default/conify/global/asset/copy_template.tt2 | 5 +++- 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm index df16b4e0ed..dad96eed8b 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm @@ -1191,4 +1191,35 @@ HERE return $mfhd->id; } +__PACKAGE__->register_method( + method => "create_update_asset_copy_template", + api_name => "open-ils.cat.asset.copy_template.create_or_update" +); + +sub create_update_asset_copy_template { + my ($self, $client, $authtoken, $act) = @_; + + my $e = new_editor("xact" => 1, "authtoken" => $authtoken); + return $e->die_event unless $e->checkauth; + return $e->die_event unless $e->allowed( + "ADMIN_ASSET_COPY_TEMPLATE", $act->owning_lib + ); + + $act->editor($e->requestor->id); + $act->edit_date("now"); + + my $retval; + if (!$act->id) { + $act->creator($e->requestor->id); + $act->create_date("now"); + + $e->create_asset_copy_template($act) or return $e->die_event; + $retval = $e->data; + } else { + $e->update_asset_copy_template($act) or return $e->die_event; + $retval = $e->retrieve_asset_copy_template($e->data); + } + $e->commit and return $retval; +} + 1; diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js index 4495e1cf58..aceff7e2c2 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js @@ -15,6 +15,8 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { { /* if true, pop up an edit dialog when user hits Enter on a give row */ + editPaneOnSubmit : null, + createPaneOnSubmit : null, editOnEnter : false, defaultCellWidth : null, editStyle : 'dialog', @@ -404,6 +406,8 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { } }); + if (typeof this.editPaneOnSubmit == "function") + pane.onSubmit = this.editPaneOnSubmit; pane.fieldOrder = this.fieldOrder; pane.mode = 'update'; return pane; @@ -438,6 +442,8 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { if(onCancel) onCancel(); } }); + if (typeof this.createPaneOnSubmit == "function") + pane.onSubmit = this.createPaneOnSubmit; pane.fieldOrder = this.fieldOrder; pane.mode = 'create'; return pane; diff --git a/Open-ILS/web/js/dojo/openils/widget/EditPane.js b/Open-ILS/web/js/dojo/openils/widget/EditPane.js index 4e98b04fa5..79386954f2 100644 --- a/Open-ILS/web/js/dojo/openils/widget/EditPane.js +++ b/Open-ILS/web/js/dojo/openils/widget/EditPane.js @@ -213,6 +213,7 @@ if(!dojo._hasResource['openils.widget.EditPane']) { }, performEditAction : function(opts) { + var self = this; var fields = this.getFields(); if(this.mode == 'create') this.fmObject = new fieldmapper[this.fmClass](); @@ -221,7 +222,7 @@ if(!dojo._hasResource['openils.widget.EditPane']) { if(this.mode == 'create' && this.fmIDL.pkey_sequence) this.fmObject[this.fmIDL.pkey](null); if (typeof(this.onSubmit) == "function") { - this.onSubmit(this.fmObject); + this.onSubmit(this.fmObject, opts, self); } else { (new openils.PermaCrud())[this.mode](this.fmObject, opts); } diff --git a/Open-ILS/web/js/ui/default/conify/global/asset/copy_template.js b/Open-ILS/web/js/ui/default/conify/global/asset/copy_template.js index 70d3812bf7..37fbf7cc00 100644 --- a/Open-ILS/web/js/ui/default/conify/global/asset/copy_template.js +++ b/Open-ILS/web/js/ui/default/conify/global/asset/copy_template.js @@ -9,6 +9,21 @@ var pcrud; var actOwner; var actList; +function create_or_update_act(obj, opts, edit_pane) { + fieldmapper.standardRequest( + ["open-ils.cat", "open-ils.cat.asset.copy_template.create_or_update"], { + "params": [openils.User.authtoken, obj], + "async": true, + "oncomplete": function(r) { + if (r = openils.Util.readResponse(r)) { + if (edit_pane.onPostSubmit) + edit_pane.onPostSubmit(); + } + } + } + ); +} + function actInit() { pcrud = new openils.PermaCrud(); diff --git a/Open-ILS/web/templates/default/conify/global/asset/copy_template.tt2 b/Open-ILS/web/templates/default/conify/global/asset/copy_template.tt2 index 0da053796b..fc5ef343d7 100644 --- a/Open-ILS/web/templates/default/conify/global/asset/copy_template.tt2 +++ b/Open-ILS/web/templates/default/conify/global/asset/copy_template.tt2 @@ -23,11 +23,14 @@
-- 2.11.0