]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/print_list_template_editor.js
show available macros for each print list type
[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
26                         if (typeof obj.data.print_list_templates == 'undefined') {
27                                 obj.data.print_list_types = [ 'items', 'holds', 'patrons' ];
28                                 obj.data.print_list_templates = { 
29                                         'items_out' : {
30                                                 'type' : 'items',
31                                                 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou have the following items:<hr/><ol>',
32                                                 'line_item' : '<li>%title: 50%\r\nBarcode: %barcode% Due: %due_date%\r\n',
33                                                 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%',
34                                         }, 
35                                         'checkout' : {
36                                                 'type' : 'items',
37                                                 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou checked out the following items:<hr/><ol>',
38                                                 'line_item' : '<li>%title%\r\nBarcode: %barcode% Due: %due_date%\r\n',
39                                                 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%',
40                                         }, 
41                                         'checkin' : {
42                                                 'type' : 'items',
43                                                 'header' : 'You checked in the following items:<hr/><ol>',
44                                                 'line_item' : '<li>%title%\r\nBarcode: %barcode%  Call Number: %call_number%\r\n',
45                                                 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\n',
46                                         }, 
47                                         'holds' : {
48                                                 'type' : 'holds',
49                                                 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou have the following titles on hold:<hr/><ol>',
50                                                 'line_item' : '<li>%title%\r\n',
51                                                 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%',
52                                         } 
53                                 }; 
54
55                                 obj.data.stash( 'print_list_templates', 'print_list_types' );
56                         }
57
58                         JSAN.use('util.controller'); obj.controller = new util.controller();
59                         obj.controller.init(
60                                 {
61                                         control_map : {
62                                                 'header' : [ ['command'], function() {} ],
63                                                 'line_item' : [ ['command'], function() {} ],
64                                                 'footer' : [ ['command'], function() {} ],
65                                                 'preview' : [
66                                                         ['command'],
67                                                         function() {
68                                                                 alert( 'preview: ' + obj.controller.view.template_name_menu.value );
69                                                         }
70                                                 ],
71                                                 'save' : [
72                                                         ['command'],
73                                                         function() {
74                                                                 obj.save_template( obj.controller.view.template_name_menu.value );
75                                                         }
76                                                 ],
77                                                 'delete' : [
78                                                         ['command'],
79                                                         function() {
80                                                                 alert( 'not yet implemented' );
81                                                         }
82                                                 ],
83                                                 'macros' : [
84                                                         ['command'],
85                                                         function() {
86                                                                 try {
87                                                                         JSAN.use('util.functional');
88                                                                         var template_type = obj.controller.view.template_type_menu.value;
89                                                                         var macros;
90                                                                         switch(template_type) {
91                                                                                 case 'items':
92                                                                                         JSAN.use('circ.util');
93                                                                                         macros = util.functional.map_list(
94                                                                                                 circ.util.columns( {} ),
95                                                                                                 function(o) {
96                                                                                                         return '%' + o.id + '%';
97                                                                                                 }
98                                                                                         );
99                                                                                 break;
100                                                                                 case 'holds':
101                                                                                         JSAN.use('circ.util');
102                                                                                         macros = util.functional.map_list(
103                                                                                                 circ.util.hold_columns( {} ),
104                                                                                                 function(o) {
105                                                                                                         return '%' + o.id + '%';
106                                                                                                 }
107                                                                                         );
108                                                                                 break;
109                                                                                 case 'patrons':
110                                                                                         JSAN.use('patron.util');
111                                                                                         macros = util.functional.map_list(
112                                                                                                 patron.util.columns( {} ),
113                                                                                                 function(o) {
114                                                                                                         return '%' + o.id + '%';
115                                                                                                 }
116                                                                                         );
117                                                                                 break;
118                                                                         }
119                                                                         var macro_string = macros.join(', ');
120                                                                         JSAN.use('util.window');
121                                                                         var win = new util.window();
122                                                                         win.open('data:text/html,'
123                                                                                 + window.escape(
124                                                                                         '<html style="width: 600; height: 400;">'
125                                                                                         + '<head><title>Template Macros</title></head>'
126                                                                                         + '<body onload="document.getElementById(\'btn\').focus()">'
127                                                                                         + '<h1>General:</h1>'
128                                                                                         + '<p>%PINES_CODE%, %TODAY%, %STAFF_FIRSTNAME%, %STAFF_LASTNAME%, '
129                                                                                         + '%PATRON_FIRSTNAME%, %LIBRARY%</p>'
130                                                                                         + '<h1>For type: '
131                                                                                         + template_type + '</h1>'
132                                                                                         + '<p>' + macro_string + '</p>'
133                                                                                         + '<button id="btn" onclick="window.close()">Close Window</button>'
134                                                                                         + '</body></html>'
135                                                                                 ), 'title', 'chrome,resizable');
136                                                                 } catch(E) {
137                                                                         alert(E);
138                                                                 }
139                                                         }
140                                                 ],
141                                                 'template_name_menu_placeholder' : [
142                                                         ['render'],
143                                                         function(e) {
144                                                                 return function() {
145                                                                         JSAN.use('util.widgets'); JSAN.use('util.functional');
146                                                                         util.widgets.remove_children(e);
147                                                                         var ml = util.widgets.make_menulist(
148                                                                                 util.functional.map_object_to_list(
149                                                                                         obj.data.print_list_templates,
150                                                                                         function(o,i) { return [i,i]; }
151                                                                                 )
152                                                                         );
153                                                                         ml.setAttribute('id','template_name_menu');
154                                                                         ml.setAttribute('editable','true');
155                                                                         ml.setAttribute('flex','1');
156                                                                         e.appendChild(ml);
157                                                                         obj.controller.view.template_name_menu = ml;
158                                                                         ml.addEventListener(
159                                                                                 'command',
160                                                                                 function(ev) {
161                                                                                         var tmp = obj.data.print_list_templates[ ev.target.value ];
162                                                                                         obj.controller.view.template_type_menu.value = tmp.type;
163                                                                                         obj.controller.view.header.value = tmp.header;
164                                                                                         obj.controller.view.line_item.value = tmp.line_item;
165                                                                                         obj.controller.view.footer.value = tmp.footer;
166                                                                                 },
167                                                                                 false
168                                                                         );
169                                                                         setTimeout(
170                                                                                 function() {
171                                                                                         var tmp = obj.data.print_list_templates[ ml.value ];
172                                                                                         obj.controller.view.template_type_menu.value = tmp.type;
173                                                                                         obj.controller.view.header.value = tmp.header;
174                                                                                         obj.controller.view.line_item.value = tmp.line_item;
175                                                                                         obj.controller.view.footer.value = tmp.footer;
176                                                                                 }, 0
177                                                                         );
178                                                                 }
179                                                         }
180                                                 ],
181                                                 'template_type_menu_placeholder' : [
182                                                         ['render'],
183                                                         function(e) {
184                                                                 return function() {
185                                                                         JSAN.use('util.widgets'); JSAN.use('util.functional');
186                                                                         util.widgets.remove_children(e);
187                                                                         var ml = util.widgets.make_menulist(
188                                                                                 util.functional.map_list(
189                                                                                         obj.data.print_list_types,
190                                                                                         function(o) { return [o,o]; }
191                                                                                 )
192                                                                         );
193                                                                         ml.setAttribute('id','template_types_menu');
194                                                                         e.appendChild(ml);
195                                                                         obj.controller.view.template_type_menu = ml;
196                                                                         ml.addEventListener(
197                                                                                 'command',
198                                                                                 function(ev) {
199                                                                                         alert(ev.target.value);
200                                                                                 },
201                                                                                 false
202                                                                         );
203                                                                 }
204                                                         }
205                                                 ],
206
207                                         }
208                                 }
209                         );
210                         obj.controller.render(); obj.controller.view.template_name_menu.focus();
211
212                 } catch(E) {
213                         this.error.sdump('D_ERROR','print_list.init: ' + E + '\n');
214                 }
215         },
216
217         'test_template' : function (name) { 
218                 var params = { 
219                         'au' : test_patron, 
220                         'lib' : obj.data.list.au[0].home_ou(),
221                         'staff' : obj.data.list.au[0],
222                         'header' : document.getElementById(name + '_header_tb').value,
223                         'line_item' : document.getElementById(name + '_line_item_tb').value,
224                         'footer' : document.getElementById(name + '_footer_tb').value
225                 };
226                 this.print.print_list( params, sample_view );
227         },
228
229         'save_template' : function(name) {
230                 this.data.print_list_templates[name].header = this.controller.view.header.value;
231                 this.data.print_list_templates[name].line_item = this.controller.view.line_item.value;
232                 this.data.print_list_templates[name].footer = this.controller.view.footer.value;
233                 this.data.stash( 'print_list_templates' );
234                 alert('Template Saved');
235         },
236 }
237
238 dump('exiting print_list_template_editor.js\n');