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.compat._data.model');
35 dojo.require("dojox.grid.compat._data.editors");
39 console.log('loading marc_code_maps.js');
43 var ses = dojo.cookie('ses') || cgi.param('ses');
44 var pCRUD = new OpenSRF.ClientSession('open-ils.permacrud');
46 console.log('initialized pcrud session');
49 var current_item = {};
53 green : dojox.fx.highlight( { color : '#B4FFB4', node : 'grid_container', duration : 500 } ),
54 red : dojox.fx.highlight( { color : '#FF2018', node : 'grid_container', duration : 500 } )
57 console.log('highlighters set up');
62 function status_update (markup) {
63 if (parent !== window && parent.status_update) parent.status_update( markup );
66 console.log('local status function built');
68 function save_code (classname) {
70 var item = current_item[classname];
71 var obj = new fieldmapper[classname]().fromStoreItem( item );
74 obj.code( dojo.string.trim( obj.code() ) );
75 obj.value( dojo.string.trim( obj.value() ) );
76 if(classname == 'cam' || classname == 'clfm')
77 obj.description( dojo.string.trim( obj.description() ) );
80 method : 'open-ils.permacrud.update.' + classname,
82 params : [ ses, modified_ppl ],
83 onerror : function (r) {
84 //highlighter.red.play();
85 status_update( 'Problem saving data for ' + classname + ' ' + obj.code() );
87 oncomplete : function (r) {
89 if ( res && res.content() ) {
90 stores[classname].setValue( current_item, 'ischanged', 0 );
91 //highlighter.green.play();
92 status_update( 'Saved changes to ' + stores[classname].getValue( item, 'code' ) );
94 //highlighter.red.play();
95 status_update( 'Problem saving data for ' + classname + ' ' + stores[classname].getValue( item, 'code' ) );
101 function save_them_all (event) {
103 for (var classname in stores) {
105 var store = stores[classname];
107 query : { ischanged : 1 },
108 onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
112 var confirmation = true;
114 if (event && dirtyStore.length > 0) {
115 confirmation = confirm(
116 'There are unsaved modified ' + classname + ' codes! '+
117 'OK to save these changes, Cancel to abandon them.'
123 for (var i in dirtyStore) {
124 current_item[classname] = dirtyStore[i];
125 save_object(classname);
133 dojo.addOnUnload( save_them_all );
135 function delete_grid_selection(classname, grid ) {
137 var selected_rows = grid.selection.getSelected();
139 var selected_items = [];
140 for (var i in selected_rows) {
142 grid.model.getRow( selected_rows[i] ).__dojo_data_item
146 grid.selection.clear();
148 for (var i in selected_items) {
149 var item = selected_items[i];
151 if ( confirm('Are you sure you want to delete ' + grid.model.store.getValue( item, 'value' ) + '?')) {
153 grid.model.store.setValue( item, 'isdeleted', 1 );
155 var obj = new fieldmapper[classname]().fromStoreItem( item );
159 method : 'open-ils.permacrud.delete.' + classname,
161 params : [ ses, obj ],
162 onerror : function (r) {
163 //highlighter.red.play();
164 status_update( 'Problem deleting ' + grid.model.store.getValue( item, 'value' ) );
166 oncomplete : function (r) {
168 var old_name = grid.model.store.getValue( item, 'value' );
169 if ( res && res.content() ) {
171 grid.model.store.fetch({
172 query : { code : grid.model.store.getValue( item, 'code' ) },
173 onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } },
174 scope : grid.model.store
177 //highlighter.green.play();
178 status_update( old_name + ' deleted' );
180 //highlighter.red.play();
181 status_update( 'Problem deleting ' + old_name );
190 function create_marc_code (data) {
192 var cl = data.classname;
193 if (!cl) return false;
195 data.code = dojo.string.trim( data.code );
196 data.value = dojo.string.trim( data.value );
198 if(!data.code || !data.value) return false;
200 if(cl == 'cam' || cl == 'clfm')
201 data.description = dojo.string.trim( data.description );
203 var new_fm_obj = new fieldmapper[cl]().fromHash( data )
208 method : 'open-ils.permacrud.create.' + cl,
210 params : [ ses, new_fm_obj ],
211 onerror : function (r) {
212 //highlighter.red.play();
213 status_update( 'Problem calling method to create new ' + cl );
216 oncomplete : function (r) {
218 if ( res && res.content() ) {
219 var new_item_hash = res.content().toHash();
220 stores[cl].newItem( new_item_hash );
221 status_update( 'New ' + new_item_hash.code + ' ' + cl + ' created' );
222 //highlighter.green.play();
224 //highlighter.red.play();
225 status_update( 'Problem creating new Permission' );