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.AutoIDL');
19 dojo.require('fieldmapper.dojoData');
20 dojo.require('openils.widget.TranslatorPopup');
21 dojo.require('dojo.cookie');
22 dojo.require('dojo.parser');
23 dojo.require('dojo.string');
24 dojo.require('dojo.data.ItemFileWriteStore');
25 dojo.require('dijit.form.Form');
26 dojo.require('dijit.form.TextBox');
27 dojo.require('dijit.form.ValidationTextBox');
28 dojo.require('dijit.form.Textarea');
29 dojo.require('dijit.layout.TabContainer');
30 dojo.require('dijit.layout.ContentPane');
31 dojo.require('dijit.layout.LayoutContainer');
32 dojo.require('dijit.layout.BorderContainer');
33 dojo.require('dojox.widget.Toaster');
34 dojo.require('dojox.fx');
35 dojo.require('dojox.grid.Grid');
36 dojo.requireLocalization("openils.conify", "conify");
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 = {};
50 var cam_strings = dojo.i18n.getLocalization('openils.conify', 'conify');
54 green : dojox.fx.highlight( { color : '#B4FFB4', node : 'grid_container', duration : 500 } ),
55 red : dojox.fx.highlight( { color : '#FF2018', node : 'grid_container', duration : 500 } )
58 console.log('highlighters set up');
63 function status_update (markup) {
64 if (parent !== window && parent.status_update) parent.status_update( markup );
67 console.log('local status function built');
69 function save_code (classname) {
71 var item = current_item[classname];
72 var obj = new fieldmapper[classname]().fromStoreItem( item );
75 obj.code( dojo.string.trim( obj.code() ) );
76 obj.value( dojo.string.trim( obj.value() ) );
77 if(classname == 'cam' || classname == 'clfm')
78 obj.description( dojo.string.trim( obj.description() ) );
81 method : 'open-ils.permacrud.update.' + classname,
83 params : [ ses, modified_ppl ],
84 onerror : function (r) {
85 //highlighter.red.play();
86 status_update( dojo.string.substitute(cam_strings.ERROR_SAVING_DATA_CAM, [classname, obj.code()]) );
88 oncomplete : function (r) {
90 if ( res && res.content() ) {
91 stores[classname].setValue( current_item, 'ischanged', 0 );
92 //highlighter.green.play();
93 status_update( dojo.string.substitute(cam_strings.SUCCESS_SAVE, stores[classname].getValue( item, 'code' )) );
95 //highlighter.red.play();
96 status_update( dojo.string.substitute( cam_strings.ERROR_SAVING_DATA_CAM, [classname, stores[classname].getValue( item, 'code' )] ) );
102 function save_them_all (event) {
104 for (var classname in stores) {
106 var store = stores[classname];
108 query : { ischanged : 1 },
109 onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
113 var confirmation = true;
115 if (event && dirtyStore.length > 0) {
116 confirmation = confirm( cam_strings.CONFIRM_EXIT_CAM );
121 for (var i in dirtyStore) {
122 current_item[classname] = dirtyStore[i];
123 save_object(classname);
131 dojo.addOnUnload( save_them_all );
133 function delete_grid_selection(classname, grid ) {
135 var selected_rows = grid.selection.getSelected();
137 var selected_items = [];
138 for (var i in selected_rows) {
140 grid.model.getRow( selected_rows[i] ).__dojo_data_item
144 grid.selection.clear();
146 for (var i in selected_items) {
147 var item = selected_items[i];
149 if ( confirm( dojo.string.substitute( cam_strings.CONFIRM_DELETE, [grid.model.store.getValue( item, 'value' )] ) ) ) {
151 grid.model.store.setValue( item, 'isdeleted', 1 );
153 var obj = new fieldmapper[classname]().fromStoreItem( item );
157 method : 'open-ils.permacrud.delete.' + classname,
159 params : [ ses, obj ],
160 onerror : function (r) {
161 //highlighter.red.play();
162 status_update( dojo.string.substitute( cam_strings.ERROR_DELETING, [grid.model.store.getValue( item, 'value' )] ) );
164 oncomplete : function (r) {
166 var old_name = grid.model.store.getValue( item, 'value' );
167 if ( res && res.content() ) {
169 grid.model.store.fetch({
170 query : { code : grid.model.store.getValue( item, 'code' ) },
171 onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } },
172 scope : grid.model.store
175 //highlighter.green.play();
176 status_update( dojo.string.substitute( cam_strings.STATUS_DELETED, [old_name] ) );
178 //highlighter.red.play();
179 status_update( dojo.string.substitute( cam_strings.ERROR_DELETING, [old_name] ) );
188 function create_marc_code (data) {
190 var cl = data.classname;
191 if (!cl) return false;
193 data.code = dojo.string.trim( data.code );
194 data.value = dojo.string.trim( data.value );
196 if(!data.code || !data.value) return false;
198 if(cl == 'cam' || cl == 'clfm')
199 data.description = dojo.string.trim( data.description );
201 var new_fm_obj = new fieldmapper[cl]().fromHash( data )
206 method : 'open-ils.permacrud.create.' + cl,
208 params : [ ses, new_fm_obj ],
209 onerror : function (r) {
210 //highlighter.red.play();
211 status_update( dojo.string.substitute( cam_strings.ERROR_CALLING_METHOD_CAM, [cl] ) );
214 oncomplete : function (r) {
216 if ( res && res.content() ) {
217 var new_item_hash = res.content().toHash();
218 stores[cl].newItem( new_item_hash );
219 status_update( dojo.string.substitute( cam_strings.SUCCESS_CREATING_CODE, [new_item_hash.code, cl] ) );
220 //highlighter.green.play();
222 //highlighter.red.play();
223 status_update( cam_strings.ERROR_CREATING_PERMISSION );