]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/print_list_template_editor.js
a8324e90aee89d1095487103efd3107a4869e676
[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                         obj.session = params['session'];
23
24                         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
25                         this.test_patron = new au();
26                         this.test_patron.family_name('Doe');
27                         this.test_patron.first_given_name('John');
28                         this.test_card = new ac();
29                         this.test_card.barcode('123456789');
30                         this.test_patron.card( this.test_card );
31
32                         this.test_list = {
33                         
34                                 'items' : { 'dump' : function() { return JSON2js('[["1858348","421","268297","31001000418112","AC KRENTZ","1","Stacks","Normal","ARL-ATH","Normal","Yes","Yes","Yes","No","No","0","18","","","2006-02-13 15:31:30.730986-05","","2006-02-27","Deep waters ","Krentz, Jayne Ann.","","0671575236 :","p1997","Simon & Schuster Audio","PIN01074166   ","1","Checked out","???","???"]]'); } },
35                                 'holds' : { 'dump' : function() { return; } },
36                                 'patrons' : { 'dump' : function() { return; } },
37
38                         }
39
40                         if (typeof obj.data.print_list_templates == 'undefined') {
41                                 obj.data.print_list_types = [ 'items', 'holds', 'patrons' ];
42                                 obj.data.print_list_templates = { 
43                                         'item_status' : {
44                                                 'type' : 'items',
45                                                 'header' : 'You following items were checked:<hr/><ol>',
46                                                 'line_item' : '<li>%title%\r\nBarcode: %barcode%\r\n',
47                                                 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\n',
48                                         }, 
49                                         'items_out' : {
50                                                 'type' : 'items',
51                                                 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou have the following items:<hr/><ol>',
52                                                 'line_item' : '<li>%title%\r\nBarcode: %barcode% Due: %due_date%\r\n',
53                                                 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%',
54                                         }, 
55                                         'checkout' : {
56                                                 'type' : 'items',
57                                                 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou checked out the following items:<hr/><ol>',
58                                                 'line_item' : '<li>%title%\r\nBarcode: %barcode% Due: %due_date%\r\n',
59                                                 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%',
60                                         }, 
61                                         'checkin' : {
62                                                 'type' : 'items',
63                                                 'header' : 'You checked in the following items:<hr/><ol>',
64                                                 'line_item' : '<li>%title%\r\nBarcode: %barcode%  Call Number: %call_number%\r\n',
65                                                 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\n',
66                                         }, 
67                                         'holds' : {
68                                                 'type' : 'holds',
69                                                 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou have the following titles on hold:<hr/><ol>',
70                                                 'line_item' : '<li>%title%\r\n',
71                                                 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%',
72                                         } 
73                                 }; 
74
75                                 obj.data.stash( 'print_list_templates', 'print_list_types' );
76                         }
77
78                         obj.controller_init();
79                         obj.controller.render(); obj.controller.view.template_name_menu.focus();
80
81                 } catch(E) {
82                         alert('init: ' + E);
83                         this.error.sdump('D_ERROR','print_list.init: ' + E + '\n');
84                 }
85         },
86
87         'controller_init' : function() {
88                 try {
89                         var obj = this;
90                         JSAN.use('util.controller'); obj.controller = new util.controller();
91                         obj.controller.init(
92                                 {
93                                         control_map : {
94                                                 'sample' : [ ['command'], function() { } ],
95                                                 'header' : [ ['change'], function() { obj.preview(); } ],
96                                                 'line_item' : [ ['change'], function() { obj.preview(); } ],
97                                                 'footer' : [ ['change'], function() { obj.preview(); } ],
98                                                 'preview' : [
99                                                         ['command'],
100                                                         function() {
101                                                                 obj.preview();
102                                                         }
103                                                 ],
104                                                 'save' : [
105                                                         ['command'],
106                                                         function() {
107                                                                 obj.save_template( obj.controller.view.template_name_menu.value );
108                                                         }
109                                                 ],
110                                                 'delete' : [
111                                                         ['command'],
112                                                         function() {
113                                                                 alert( 'not yet implemented' );
114                                                         }
115                                                 ],
116                                                 'macros' : [
117                                                         ['command'],
118                                                         function() {
119                                                                 try {
120                                                                         JSAN.use('util.functional');
121                                                                         var template_type = obj.controller.view.template_type_menu.value;
122                                                                         var macros;
123                                                                         switch(template_type) {
124                                                                                 case 'items':
125                                                                                         JSAN.use('circ.util');
126                                                                                         macros = util.functional.map_list(
127                                                                                                 circ.util.columns( {} ),
128                                                                                                 function(o) {
129                                                                                                         return '%' + o.id + '%';
130                                                                                                 }
131                                                                                         );
132                                                                                 break;
133                                                                                 case 'holds':
134                                                                                         JSAN.use('circ.util');
135                                                                                         macros = util.functional.map_list(
136                                                                                                 circ.util.hold_columns( {} ),
137                                                                                                 function(o) {
138                                                                                                         return '%' + o.id + '%';
139                                                                                                 }
140                                                                                         );
141                                                                                 break;
142                                                                                 case 'patrons':
143                                                                                         JSAN.use('patron.util');
144                                                                                         macros = util.functional.map_list(
145                                                                                                 patron.util.columns( {} ),
146                                                                                                 function(o) {
147                                                                                                         return '%' + o.id + '%';
148                                                                                                 }
149                                                                                         );
150                                                                                 break;
151                                                                         }
152                                                                         var macro_string = macros.join(', ');
153                                                                         JSAN.use('util.window');
154                                                                         var win = new util.window();
155                                                                         win.open('data:text/html,'
156                                                                                 + window.escape(
157                                                                                         '<html style="width: 600; height: 400;">'
158                                                                                         + '<head><title>Template Macros</title></head>'
159                                                                                         + '<body onload="document.getElementById(\'btn\').focus()">'
160                                                                                         + '<h1>General:</h1>'
161                                                                                         + '<p>%PINES_CODE%, %TODAY%, %STAFF_FIRSTNAME%, %STAFF_LASTNAME%, '
162                                                                                         + '%PATRON_FIRSTNAME%, %LIBRARY%</p>'
163                                                                                         + '<h1>For type: '
164                                                                                         + template_type + '</h1>'
165                                                                                         + '<p>' + macro_string + '</p>'
166                                                                                         + '<button id="btn" onclick="window.close()">Close Window</button>'
167                                                                                         + '</body></html>'
168                                                                                 ), 'title', 'chrome,resizable');
169                                                                 } catch(E) {
170                                                                         alert(E);
171                                                                 }
172                                                         }
173                                                 ],
174                                                 'template_name_menu_placeholder' : [
175                                                         ['render'],
176                                                         function(e) {
177                                                                 return function() {
178                                                                         JSAN.use('util.widgets'); JSAN.use('util.functional');
179                                                                         util.widgets.remove_children(e);
180                                                                         var ml = util.widgets.make_menulist(
181                                                                                 util.functional.map_object_to_list(
182                                                                                         obj.data.print_list_templates,
183                                                                                         function(o,i) { return [i,i]; }
184                                                                                 )
185                                                                         );
186                                                                         ml.setAttribute('id','template_name_menu');
187                                                                         ml.setAttribute('editable','true');
188                                                                         ml.setAttribute('flex','1');
189                                                                         e.appendChild(ml);
190                                                                         obj.controller.view.template_name_menu = ml;
191                                                                         ml.addEventListener(
192                                                                                 'command',
193                                                                                 function(ev) {
194                                                                                         var tmp = obj.data.print_list_templates[ ev.target.value ];
195                                                                                         obj.controller.view.template_type_menu.value = tmp.type;
196                                                                                         obj.controller.view.header.value = tmp.header;
197                                                                                         obj.controller.view.line_item.value = tmp.line_item;
198                                                                                         obj.controller.view.footer.value = tmp.footer;
199                                                                                 },
200                                                                                 false
201                                                                         );
202                                                                         setTimeout(
203                                                                                 function() {
204                                                                                         var tmp = obj.data.print_list_templates[ ml.value ];
205                                                                                         obj.controller.view.template_type_menu.value = tmp.type;
206                                                                                         obj.controller.view.header.value = tmp.header;
207                                                                                         obj.controller.view.line_item.value = tmp.line_item;
208                                                                                         obj.controller.view.footer.value = tmp.footer;
209                                                                                 }, 0
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                                                                         e.appendChild(ml);
228                                                                         obj.controller.view.template_type_menu = ml;
229                                                                 }
230                                                         }
231                                                 ],
232
233                                         }
234                                 }
235                         );
236                 } catch(E) {
237                         alert('controller_init: ' + E );
238                 }
239         },
240
241         'preview' : function () { 
242                 try {
243                         var params = { 
244                                 'patron' : this.test_patron, 
245                                 'lib' : this.data.hash.aou[ this.data.list.au[0].ws_ou() ],
246                                 'staff' : this.data.list.au[0],
247                                 'header' : this.controller.view.header.value,
248                                 'line_item' : this.controller.view.line_item.value,
249                                 'footer' : this.controller.view.footer.value,
250                                 'type' : this.controller.view.template_type_menu.value,
251                                 'list' : this.test_list[ this.controller.view.template_type_menu.value ].dump(),
252                                 'sample_frame' : this.controller.view.sample,
253                         };
254                         JSAN.use('util.print'); var print = new util.print();
255                         print.tree_list( params );
256                 } catch(E) {
257                         this.error.sdump('D_ERROR','preview: ' + E);
258                         alert('preview: ' + E);
259                 }
260         },
261
262         'save_template' : function(name) {
263                 var obj = this;
264                 this.data.print_list_templates[name].header = this.controller.view.header.value;
265                 this.data.print_list_templates[name].line_item = this.controller.view.line_item.value;
266                 this.data.print_list_templates[name].footer = this.controller.view.footer.value;
267                 this.data.print_list_templates[name].type = this.controller.view.template_type_menu.value;
268                 this.data.stash( 'print_list_templates' );
269                 alert('Template Saved\n' + js2JSON(obj.data.print_list_templates[name]));
270         },
271
272 }
273
274 dump('exiting print_list_template_editor.js\n');