2 # ---------------------------------------------------------------------------
3 # Copyright (C) 2008 Georgia Public Library Service / Equinox Software, Inc
4 # Mike Rylander <miker@esilibrary.com>
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 # ---------------------------------------------------------------------------
18 dojo.require('fieldmapper.dojoData');
19 dojo.require('openils.widget.TranslatorPopup');
20 dojo.require('dojo.cookie');
21 dojo.require('dojo.parser');
22 dojo.require('dojo.string');
23 dojo.require('dojo.data.ItemFileWriteStore');
24 dojo.require('dijit.form.TextBox');
25 dojo.require('dijit.form.ValidationTextBox');
26 dojo.require('dijit.form.Textarea');
27 dojo.require('dijit.layout.TabContainer');
28 dojo.require('dijit.layout.ContentPane');
29 dojo.require('dijit.layout.LayoutContainer');
30 dojo.require('dijit.layout.BorderContainer');
31 dojo.require('dojox.widget.Toaster');
32 dojo.require('dojox.fx');
33 dojo.require('dojox.grid.Grid');
34 dojo.require('dojox.grid._data.model');
35 dojo.require("dojox.grid.editors");
39 var ses = dojo.cookie('ses') || cgi.param('ses');
40 var pCRUD = new OpenSRF.ClientSession('open-ils.permacrud');
43 var current_item = {};
45 green : dojox.fx.highlight( { color : '#B4FFB4', node : 'grid_container', duration : 500 } ),
46 red : dojox.fx.highlight( { color : '#FF2018', node : 'grid_container', duration : 500 } )
51 function status_update (markup) {
52 if (parent !== window && parent.status_update) parent.status_update( markup );
55 function save_code (classname) {
57 var item = current_item[classname];
58 var obj = new fieldmapper[classname]().fromStoreItem( item );
61 obj.code( dojo.string.trim( obj.code() ) );
62 obj.value( dojo.string.trim( obj.value() ) );
63 if(classname == 'cam' || classname == 'clfm')
64 obj.description( dojo.string.trim( obj.description() ) );
67 method : 'open-ils.permacrud.update.' + classname,
69 params : [ ses, modified_ppl ],
70 onerror : function (r) {
71 highlighter.red.play();
72 status_update( 'Problem saving data for ' + classname + ' ' + obj.code() );
74 oncomplete : function (r) {
76 if ( res && res.content() ) {
77 stores[classname].setValue( current_item, 'ischanged', 0 );
78 highlighter.green.play();
79 status_update( 'Saved changes to ' + stores[classname].getValue( item, 'code' ) );
81 highlighter.red.play();
82 status_update( 'Problem saving data for ' + classname + ' ' + stores[classname].getValue( item, 'code' ) );
88 function save_them_all (event) {
90 for (var classname in stores) {
92 var store = stores[classname];
94 query : { ischanged : 1 },
95 onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
99 var confirmation = true;
101 if (event && dirtyStore.length > 0) {
102 confirmation = confirm(
103 'There are unsaved modified ' + classname + ' codes! '+
104 'OK to save these changes, Cancel to abandon them.'
110 for (var i in dirtyStore) {
111 current_item[classname] = dirtyStore[i];
112 save_object(classname);
120 dojo.addOnUnload( save_them_all );
122 function delete_grid_selection(classname, grid ) {
124 var selected_rows = grid.selection.getSelected();
126 var selected_items = [];
127 for (var i in selected_rows) {
129 grid.model.getRow( selected_rows[i] ).__dojo_data_item
133 grid.selection.clear();
135 for (var i in selected_items) {
136 var item = selected_items[i];
138 if ( confirm('Are you sure you want to delete ' + grid.model.store.getValue( item, 'value' ) + '?')) {
140 grid.model.store.setValue( item, 'isdeleted', 1 );
142 var obj = new fieldmapper[classname]().fromStoreItem( item );
146 method : 'open-ils.permacrud.delete.' + classname,
148 params : [ ses, obj ],
149 onerror : function (r) {
150 highlighter.red.play();
151 status_update( 'Problem deleting ' + grid.model.store.getValue( item, 'value' ) );
153 oncomplete : function (r) {
155 var old_name = grid.model.store.getValue( item, 'value' );
156 if ( res && res.content() ) {
158 grid.model.store.fetch({
159 query : { code : grid.model.store.getValue( item, 'code' ) },
160 onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } },
161 scope : grid.model.store
164 highlighter.green.play();
165 status_update( old_name + ' deleted' );
167 highlighter.red.play();
168 status_update( 'Problem deleting ' + old_name );
177 function create_marc_code (data) {
179 var cl = data.classname;
180 if (!cl) return false;
182 data.code = dojo.string.trim( data.code );
183 data.value = dojo.string.trim( data.value );
185 if(!data.code || !data.value) return false;
187 if(cl == 'cam' || cl == 'clfm')
188 data.description = dojo.string.trim( data.description );
190 var new_fm_obj = new fieldmapper[cl]().fromHash( data )
195 method : 'open-ils.permacrud.create.' + cl,
197 params : [ ses, new_fm_obj ],
198 onerror : function (r) {
199 highlighter.red.play();
200 status_update( 'Problem calling method to create new ' + cl );
203 oncomplete : function (r) {
205 if ( res && res.content() ) {
206 var new_item_hash = res.content().toHash();
207 stores[cl].newItem( new_item_hash );
208 status_update( 'New ' + new_item_hash.code + ' ' + cl + ' created' );
209 highlighter.green.play();
211 highlighter.red.play();
212 status_update( 'Problem creating new Permission' );