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");
38 console.log('loading marc_code_maps.js');
42 var ses = dojo.cookie('ses') || cgi.param('ses');
43 var pCRUD = new OpenSRF.ClientSession('open-ils.permacrud');
45 console.log('initialized pcrud session');
48 var current_item = {};
52 green : dojox.fx.highlight( { color : '#B4FFB4', node : 'grid_container', duration : 500 } ),
53 red : dojox.fx.highlight( { color : '#FF2018', node : 'grid_container', duration : 500 } )
56 console.log('highlighters set up');
61 function status_update (markup) {
62 if (parent !== window && parent.status_update) parent.status_update( markup );
65 console.log('local status function built');
67 function save_code (classname) {
69 var item = current_item[classname];
70 var obj = new fieldmapper[classname]().fromStoreItem( item );
73 obj.code( dojo.string.trim( obj.code() ) );
74 obj.value( dojo.string.trim( obj.value() ) );
75 if(classname == 'cam' || classname == 'clfm')
76 obj.description( dojo.string.trim( obj.description() ) );
79 method : 'open-ils.permacrud.update.' + classname,
81 params : [ ses, modified_ppl ],
82 onerror : function (r) {
83 //highlighter.red.play();
84 status_update( 'Problem saving data for ' + classname + ' ' + obj.code() );
86 oncomplete : function (r) {
88 if ( res && res.content() ) {
89 stores[classname].setValue( current_item, 'ischanged', 0 );
90 //highlighter.green.play();
91 status_update( 'Saved changes to ' + stores[classname].getValue( item, 'code' ) );
93 //highlighter.red.play();
94 status_update( 'Problem saving data for ' + classname + ' ' + stores[classname].getValue( item, 'code' ) );
100 function save_them_all (event) {
102 for (var classname in stores) {
104 var store = stores[classname];
106 query : { ischanged : 1 },
107 onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
111 var confirmation = true;
113 if (event && dirtyStore.length > 0) {
114 confirmation = confirm(
115 'There are unsaved modified ' + classname + ' codes! '+
116 'OK to save these changes, Cancel to abandon them.'
122 for (var i in dirtyStore) {
123 current_item[classname] = dirtyStore[i];
124 save_object(classname);
132 dojo.addOnUnload( save_them_all );
134 function delete_grid_selection(classname, grid ) {
136 var selected_rows = grid.selection.getSelected();
138 var selected_items = [];
139 for (var i in selected_rows) {
141 grid.model.getRow( selected_rows[i] ).__dojo_data_item
145 grid.selection.clear();
147 for (var i in selected_items) {
148 var item = selected_items[i];
150 if ( confirm('Are you sure you want to delete ' + grid.model.store.getValue( item, 'value' ) + '?')) {
152 grid.model.store.setValue( item, 'isdeleted', 1 );
154 var obj = new fieldmapper[classname]().fromStoreItem( item );
158 method : 'open-ils.permacrud.delete.' + classname,
160 params : [ ses, obj ],
161 onerror : function (r) {
162 //highlighter.red.play();
163 status_update( 'Problem deleting ' + grid.model.store.getValue( item, 'value' ) );
165 oncomplete : function (r) {
167 var old_name = grid.model.store.getValue( item, 'value' );
168 if ( res && res.content() ) {
170 grid.model.store.fetch({
171 query : { code : grid.model.store.getValue( item, 'code' ) },
172 onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } },
173 scope : grid.model.store
176 //highlighter.green.play();
177 status_update( old_name + ' deleted' );
179 //highlighter.red.play();
180 status_update( 'Problem deleting ' + old_name );
189 function create_marc_code (data) {
191 var cl = data.classname;
192 if (!cl) return false;
194 data.code = dojo.string.trim( data.code );
195 data.value = dojo.string.trim( data.value );
197 if(!data.code || !data.value) return false;
199 if(cl == 'cam' || cl == 'clfm')
200 data.description = dojo.string.trim( data.description );
202 var new_fm_obj = new fieldmapper[cl]().fromHash( data )
207 method : 'open-ils.permacrud.create.' + cl,
209 params : [ ses, new_fm_obj ],
210 onerror : function (r) {
211 //highlighter.red.play();
212 status_update( 'Problem calling method to create new ' + cl );
215 oncomplete : function (r) {
217 if ( res && res.content() ) {
218 var new_item_hash = res.content().toHash();
219 stores[cl].newItem( new_item_hash );
220 status_update( 'New ' + new_item_hash.code + ' ' + cl + ' created' );
221 //highlighter.green.play();
223 //highlighter.red.play();
224 status_update( 'Problem creating new Permission' );