]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/print_list_template_editor.js
47a6414d8364b4f831cc94f77d0382b613c4e4b9
[Evergreen.git] / Open-ILS / xul / staff_client / server / circ / print_list_template_editor.js
1 dump('entering print_list_template_editor.js\n');
2
3 if (typeof circ == 'undefined') circ = {};
4 circ.print_list_template_editor = function (params) {
5         try {
6                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
7                 JSAN.use('util.error'); this.error = new util.error();
8         } catch(E) {
9                 dump('print_list: ' + E + '\n');
10         }
11 }
12
13 circ.print_list_template_editor.prototype = {
14
15         'init' : function( params ) {
16
17                 try {
18                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
19
20                         var obj = this;
21
22                         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
23                         this.test_patron = new au();
24                         this.test_patron.family_name('Doe');
25                         this.test_patron.first_given_name('John');
26                         this.test_card = new ac();
27                         this.test_card.barcode('123456789');
28                         this.test_patron.card( this.test_card );
29
30                         this.test_data = {
31                                 'payment' : {
32                                         'original_balance' : '7.40',
33                                         'payment_type' : 'Cash',
34                                         'payment_received' : '10.00',
35                                         'payment_applied' : '7.40',
36                                         'voided_balance' : '0.00',
37                                         'change_given' : '2.60',
38                                         'credit_given' : '0.00',
39                                         'note' : "The patron's child paid this",
40                                         'new_balance' : '0.00',
41                                 },
42                         }
43
44                         this.test_list = {
45                         
46                                 'items' : [["7608453","???","1497190","31033007616786","J 551.48 ARATO R","MGRL-RC","1","Stacks","Short","MGRL-RC","Low","Yes","Yes","Yes","No","No","0","19.95","","","???","???","???","???","World of water ","Arato, Rona.","","0778714160 (rlb : alk. paper)","c2005","Crabtree Pub. Co.","ocm55600795 ","???","???","Available","???","???","3",""],["7136201","???","1424085","31001000224056","YA ROWLING","ARL-ATH","3","Stacks","Short","ARL-ATH","Low","Yes","Yes","Yes","No","No","0","7.99","","","???","???","???","???","Harry Potter and the prisoner of Azkaban ","Rowling, J. K.","","0439136350 (hc)","1999","Arthur A. Levine Books","ocm41266045 ","???","???","Available","???","???","2","alert message here"],["6577928","???","1301532","31041005919235","975.8784 HAG","OHOOP-LADS","1","Stacks","Short","OHOOP-LADS","Low","Yes","Yes","Yes","No","No","0","10","","","???","???","???","???","Georgia genealogical sources series marriages 1869-1879, Appling County Georgia","Hageness, MariLee Beatty.","","","c1998","MLH Research","ocm49507123 ","???","???","Available","???","???","15","high use item"]],
47                                 'holds' : [["2006-05-13","2006-05-18 16:37:47.062916-04","","T","Athens-Clarke County Library","ARL-ATH","33207004749414","No","","","","7","999-999-9999","2006-05-15 00:37:28.269456-04","3","0","818781","3","Harry Potter and the goblet of fire ","Rowling, J. K.","Large print ed.","0786229276 (lg. print : hc : alk. paper)","2000","Thorndike Press","i0786229276"],["2006-05-16","2006-05-18 20:07:04.474747-04","","T","Athens-Clarke County Library","ARL-ATH","33207004347359","Yes","","","","8","777-777-7777","2006-05-18 16:52:23.866001-04","1000000","0","551071","1000524","Cats ","Arnold, Caroline.","","0822530325 (alk. paper)","1999","Lerner Publications","i0822530325"],["2006-05-17","2006-05-18 20:08:32.882203-04","","T","Athens-Clarke County Library","ARL-ATH","33207002398776","Yes","","","","28","999-999-9999","2006-05-18 16:52:58.020117-04","1000000","0","1274439","3","Tortilla Flat ","Steinbeck, John","","0140042407 (pbk.) :","1986, c1935","Penguin Books","a2095783"],["2006-05-10","2006-05-20 21:02:57.318012-04","","T","Athens-Clarke County Library","ARL-ATH","33207003330208","No","","","","4","222-333-4444","2006-05-18 16:52:23.362607-04","3","0","315900","3","Spreadin\' rhythm around Black popular songwriters, 1880-1930","Jasen, David A.","","0028647424","c1998","Schirmer Books","i0028647424"],["2006-05-20","2006-05-20 21:11:42.124176-04","","T","Athens-Clarke County Library","ARL-ATH","33207001049453","Yes","","","","54","218-233-3757","2006-05-20 19:48:12.101796-04","1000000","0","323269","1000567","Foundation and empire ","Asimov, Isaac","","0893402109","1979","J. Curley","i0893402109"],["2006-05-20","2006-05-20 21:19:15.209143-04","","T","Athens-Clarke County Library","ARL-ATH","33207001502782","Yes","","","","63","218-233-3757","2006-05-20 19:48:37.645795-04","1000567","0","427831","1000567","The  Caine mutiny :  a novel of World War II","Wouk, Herman","","","1952 [c1951]","Doubleday","PIN24075557"],["2006-06-03","2006-06-07 17:03:32.676709-04","","V","Athens-Clarke County Library","ARL-ATH","No Copy","No","","","","135","999-999-9999","2006-06-05 23:45:18.078505-04","3","0","6592393","3","No Title?","No Author?","???","???","???","???","???"]],
48                                 'bills' : [["248","Id = 3","grocery","-2.00","0.00","2.00","","Fee for copies","2006-05-27 22:56","","cash_payment","2006-06-10 17:01","2006-05-27",""],["239","Id = 3","circulation","17.00","17.00","0.00","SYSTEM GENERATED","Lost Materials Processing Fee","2006-05-27 22:07","",""," ","2006-05-26",""],["173","Id = 3","grocery","1.00","17.25","16.25","","Lost materials","2006-05-20 16:36","","cash_payment","2006-05-27 01:31","2006-05-20",""]],
49                                 'payment' : [ [333, '2.23'], [367, '5.17' ] ],
50                                 'patrons' : [],
51                                 'offline_checkout' : [],
52                                 'offline_checkin' : [],
53                                 'offline_renew' : [],
54                                 'offline_inhouse_use' : [],
55                         }
56
57                         obj.controller_init();
58                         obj.controller.render(); obj.controller.view.template_name_menu.focus();
59
60                         obj.post_init();
61
62                 } catch(E) {
63                         alert('init: ' + E);
64                         this.error.sdump('D_ERROR','print_list.init: ' + E + '\n');
65                 }
66         },
67
68         'post_init' : function() {
69                 var obj = this;
70                 setTimeout(
71                         function() {
72                                 var tmp = obj.data.print_list_templates[ obj.controller.view.template_name_menu.value ];
73                                 obj.controller.view.template_type_menu.value = tmp.type;
74                                 obj.controller.view.header.value = tmp.header;
75                                 obj.controller.view.line_item.value = tmp.line_item;
76                                 obj.controller.view.footer.value = tmp.footer;
77                                 obj.preview();
78                         }, 0
79                 );
80         },
81
82         'controller_init' : function() {
83                 try {
84                         var obj = this;
85                         JSAN.use('util.controller'); obj.controller = new util.controller();
86                         obj.controller.init(
87                                 {
88                                         control_map : {
89                                                 'sample' : [ ['command'], function() { } ],
90                                                 'header' : [ ['change'], function() { obj.preview(); } ],
91                                                 'line_item' : [ ['change'], function() { obj.preview(); } ],
92                                                 'footer' : [ ['change'], function() { obj.preview(); } ],
93                                                 'preview' : [
94                                                         ['command'],
95                                                         function() {
96                                                                 obj.preview();
97                                                         }
98                                                 ],
99                                                 'save' : [
100                                                         ['command'],
101                                                         function() {
102                                                                 obj.save_template( obj.controller.view.template_name_menu.value );
103                                                         }
104                                                 ],
105                                                 'default' : [
106                                                         ['command'],
107                                                         function() {
108                                                                 obj.data.print_list_defaults();
109                                                                 obj.post_init();
110                                                         }
111                                                 ],
112                                                 'macros' : [
113                                                         ['command'],
114                                                         function() {
115                                                                 try {
116                                                                         JSAN.use('util.functional');
117                                                                         var template_type = obj.controller.view.template_type_menu.value;
118                                                                         var macros;
119                                                                         switch(template_type) {
120                                                                                 case 'items':
121                                                                                         JSAN.use('circ.util');
122                                                                                         macros = util.functional.map_list(
123                                                                                                 circ.util.columns( {} ),
124                                                                                                 function(o) {
125                                                                                                         return '%' + o.id + '%';
126                                                                                                 }
127                                                                                         );
128                                                                                 break;
129                                                                                 case 'holds':
130                                                                                         JSAN.use('circ.util');
131                                                                                         macros = util.functional.map_list(
132                                                                                                 circ.util.hold_columns( {} ),
133                                                                                                 function(o) {
134                                                                                                         return '%' + o.id + '%';
135                                                                                                 }
136                                                                                         );
137                                                                                 break;
138                                                                                 case 'bills':
139                                                                                         JSAN.use('patron.util');
140                                                                                         macros = util.functional.map_list(
141                                                                                                 patron.util.mbts_columns( {} ),
142                                                                                                 function(o) {
143                                                                                                         return '%' + o.id + '%';
144                                                                                                 }
145                                                                                         );
146                                                                                 break;
147                                                                                 case 'patrons':
148                                                                                         JSAN.use('patron.util');
149                                                                                         macros = util.functional.map_list(
150                                                                                                 patron.util.columns( {} ),
151                                                                                                 function(o) {
152                                                                                                         return '%' + o.id + '%';
153                                                                                                 }
154                                                                                         );
155                                                                                 break;
156                                                                                 case 'payment' : 
157                                                                                         macros = [ '%original_balance%', '%payment_received%', '%payment_applied%', '%payment_type%', '%voided_balance%', '%change_given%', '%new_balance%', '%note%', '%bill_id%', '%payment%' ];
158                                                                                 break;
159                                                                         }
160                                                                         var macro_string = macros.join(', ');
161                                                                         JSAN.use('util.window');
162                                                                         var win = new util.window();
163                                                                         win.open('data:text/html,'
164                                                                                 + window.escape(
165                                                                                         '<html style="width: 600; height: 400;">'
166                                                                                         + '<head><title>Template Macros</title></head>'
167                                                                                         + '<body onload="document.getElementById(\'btn\').focus()">'
168                                                                                         + '<h1>General:</h1>'
169                                                                                         + '<p>%PINES_CODE%, %TODAY%, %STAFF_FIRSTNAME%, %STAFF_LASTNAME%, '
170                                                                                         + '%PATRON_FIRSTNAME%, %LIBRARY%</p>'
171                                                                                         + '<h1>For type: '
172                                                                                         + template_type + '</h1>'
173                                                                                         + '<p>' + macro_string + '</p>'
174                                                                                         + '<button id="btn" onclick="window.close()">Close Window</button>'
175                                                                                         + '</body></html>'
176                                                                                 ), 'title', 'chrome,resizable');
177                                                                 } catch(E) {
178                                                                         alert(E);
179                                                                 }
180                                                         }
181                                                 ],
182                                                 'template_name_menu_placeholder' : [
183                                                         ['render'],
184                                                         function(e) {
185                                                                 return function() {
186                                                                         JSAN.use('util.widgets'); JSAN.use('util.functional');
187                                                                         util.widgets.remove_children(e);
188                                                                         var ml = util.widgets.make_menulist(
189                                                                                 util.functional.map_object_to_list(
190                                                                                         obj.data.print_list_templates,
191                                                                                         function(o,i) { return [i,i]; }
192                                                                                 )
193                                                                         );
194                                                                         ml.setAttribute('id','template_name_menu');
195                                                                         //ml.setAttribute('editable','true');
196                                                                         ml.setAttribute('flex','1');
197                                                                         e.appendChild(ml);
198                                                                         obj.controller.view.template_name_menu = ml;
199                                                                         ml.addEventListener(
200                                                                                 'command',
201                                                                                 function(ev) {
202                                                                                         var tmp = obj.data.print_list_templates[ ev.target.value ];
203                                                                                         obj.controller.view.template_type_menu.value = tmp.type;
204                                                                                         obj.controller.view.header.value = tmp.header;
205                                                                                         obj.controller.view.line_item.value = tmp.line_item;
206                                                                                         obj.controller.view.footer.value = tmp.footer;
207                                                                                         obj.preview();
208                                                                                 },
209                                                                                 false
210                                                                         );
211                                                                 }
212                                                         }
213                                                 ],
214                                                 'template_type_menu_placeholder' : [
215                                                         ['render'],
216                                                         function(e) {
217                                                                 return function() {
218                                                                         JSAN.use('util.widgets'); JSAN.use('util.functional');
219                                                                         util.widgets.remove_children(e);
220                                                                         var ml = util.widgets.make_menulist(
221                                                                                 util.functional.map_list(
222                                                                                         obj.data.print_list_types,
223                                                                                         function(o) { return [o,o]; }
224                                                                                 )
225                                                                         );
226                                                                         ml.setAttribute('id','template_types_menu');
227                                                                         ml.setAttribute('disabled','true');
228                                                                         e.appendChild(ml);
229                                                                         obj.controller.view.template_type_menu = ml;
230                                                                 }
231                                                         }
232                                                 ],
233
234                                         }
235                                 }
236                         );
237                 } catch(E) {
238                         alert('controller_init: ' + E );
239                 }
240         },
241
242         'preview' : function () { 
243                 try {
244                         var list = this.test_list[ this.controller.view.template_type_menu.value ];
245                         if (typeof list == 'undefined') list = [];
246                         var data = this.test_data[ this.controller.view.template_type_menu.value ];
247                         if (typeof data == 'undefined') data = {};
248
249                         var params = { 
250                                 'patron' : this.test_patron, 
251                                 'lib' : this.data.hash.aou[ this.data.list.au[0].ws_ou() ],
252                                 'staff' : this.data.list.au[0],
253                                 'header' : this.controller.view.header.value,
254                                 'line_item' : this.controller.view.line_item.value,
255                                 'footer' : this.controller.view.footer.value,
256                                 'type' : this.controller.view.template_type_menu.value,
257                                 'list' : list,
258                                 'data' : data,
259                                 'sample_frame' : this.controller.view.sample,
260                         };
261                         JSAN.use('util.print'); var print = new util.print();
262                         print.tree_list( params );
263                 } catch(E) {
264                         this.error.sdump('D_ERROR','preview: ' + E);
265                         alert('preview: ' + E);
266                 }
267         },
268
269         'save_template' : function(name) {
270                 var obj = this;
271                 obj.data.print_list_templates[name].header = obj.controller.view.header.value;
272                 obj.data.print_list_templates[name].line_item = obj.controller.view.line_item.value;
273                 obj.data.print_list_templates[name].footer = obj.controller.view.footer.value;
274                 obj.data.print_list_templates[name].type = obj.controller.view.template_type_menu.value;
275                 obj.data.stash( 'print_list_templates' );
276                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
277                 JSAN.use('util.file'); var file = new util.file('print_list_templates');
278                 file.set_object(obj.data.print_list_templates); file.close();
279                 alert('Template Saved\n' + js2JSON(obj.data.print_list_templates[name]));
280         },
281
282 }
283
284 dump('exiting print_list_template_editor.js\n');