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('openils.PermaCrud');
22 dojo.require('dojo.cookie');
23 dojo.require('dojo.parser');
24 dojo.require('dojo.string');
25 dojo.require('dojo.data.ItemFileWriteStore');
26 dojo.require('dijit.form.Form');
27 dojo.require('dijit.form.TextBox');
28 dojo.require('dijit.form.ValidationTextBox');
29 dojo.require('dijit.form.Textarea');
30 dojo.require('dijit.layout.TabContainer');
31 dojo.require('dijit.layout.ContentPane');
32 dojo.require('dijit.layout.LayoutContainer');
33 dojo.require('dijit.layout.BorderContainer');
34 dojo.require('dojox.widget.Toaster');
35 dojo.require('dojox.fx');
36 dojo.require('dojox.grid.Grid');
37 dojo.require('openils.XUL');
38 dojo.requireLocalization("openils.conify", "conify");
40 console.log('loading marc_code_maps.js');
44 var ses = dojo.cookie('ses') || cgi.param('ses');
45 if(!ses && openils.XUL.isXUL()) {
46 var stash = openils.XUL.getStash();
47 ses = stash.session.key;
49 var pCRUD = new openils.PermaCrud({authtoken:ses});
51 console.log('initialized pcrud session');
54 var current_item = {};
56 var cam_strings = dojo.i18n.getLocalization('openils.conify', 'conify');
60 green : dojox.fx.highlight( { color : '#B4FFB4', node : 'grid_container', duration : 500 } ),
61 red : dojox.fx.highlight( { color : '#FF2018', node : 'grid_container', duration : 500 } )
64 console.log('highlighters set up');
69 function status_update (markup) {
70 if (parent !== window && parent.status_update) parent.status_update( markup );
73 console.log('local status function built');
75 function save_code (classname) {
77 var item = current_item[classname];
78 var obj = new fieldmapper[classname]().fromStoreItem( item );
81 obj.code( dojo.string.trim( obj.code() ) );
82 obj.value( dojo.string.trim( obj.value() ) );
83 if(classname == 'cam' || classname == 'clfm')
84 obj.description( dojo.string.trim( obj.description() ) );
87 onerror : function (r) {
88 //highlighter.red.play();
89 status_update( dojo.string.substitute(cam_strings.ERROR_SAVING_DATA_CAM, [classname, obj.code()]) );
91 oncomplete : function (r) {
92 stores[classname].setValue( current_item, 'ischanged', 0 );
93 status_update( dojo.string.substitute(cam_strings.SUCCESS_SAVE, stores[classname].getValue( item, 'code' )) );
98 function save_them_all (event) {
100 for (var classname in stores) {
102 var store = stores[classname];
104 query : { ischanged : 1 },
105 onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
109 var confirmation = true;
111 if (event && dirtyStore.length > 0) {
112 confirmation = confirm( cam_strings.CONFIRM_EXIT_CAM );
117 for (var i in dirtyStore) {
118 current_item[classname] = dirtyStore[i];
119 save_object(classname);
127 dojo.addOnUnload( save_them_all );
129 function delete_grid_selection(classname, grid ) {
131 var selected_rows = grid.selection.getSelected();
133 var selected_items = [];
134 for (var i in selected_rows) {
136 grid.model.getRow( selected_rows[i] ).__dojo_data_item
140 grid.selection.clear();
142 for (var i in selected_items) {
143 var item = selected_items[i];
145 if ( confirm( dojo.string.substitute( cam_strings.CONFIRM_DELETE, [grid.model.store.getValue( item, 'value' )] ) ) ) {
147 grid.model.store.setValue( item, 'isdeleted', 1 );
149 var obj = new fieldmapper[classname]().fromStoreItem( item );
152 pCRUD.eliminate(obj, {
153 onerror : function (r) {
154 //highlighter.red.play();
155 status_update( dojo.string.substitute( cam_strings.ERROR_DELETING, [grid.model.store.getValue( item, 'value' )] ) );
157 oncomplete : function (r) {
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 status_update( dojo.string.substitute( cam_strings.STATUS_DELETED, [old_name] ) );
172 function create_marc_code (data) {
174 var cl = data.classname;
175 if (!cl) return false;
177 data.code = dojo.string.trim( data.code );
178 data.value = dojo.string.trim( data.value );
180 if(!data.code || !data.value) return false;
182 if(cl == 'cam' || cl == 'clfm')
183 data.description = dojo.string.trim( data.description );
185 var new_fm_obj = new fieldmapper[cl]().fromHash( data )
189 pCRUD.create(new_fm_obj, {
190 onerror : function (r) {
191 //highlighter.red.play();
192 status_update( dojo.string.substitute( cam_strings.ERROR_CALLING_METHOD_CAM, [cl] ) );
195 oncomplete : function (r, list) {
196 var new_item_hash = list[0].toHash();
197 stores[cl].newItem( new_item_hash );
198 status_update( dojo.string.substitute( cam_strings.SUCCESS_CREATING_CODE, [new_item_hash.code, cl] ) );
199 //highlighter.green.play();