]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/print_list_template_editor.js
toward template previews
[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                         obj.controller_init();
59                         obj.controller.render(); obj.controller.view.template_name_menu.focus();
60
61                 } catch(E) {
62                         alert('init: ' + E);
63                         this.error.sdump('D_ERROR','print_list.init: ' + E + '\n');
64                 }
65         },
66
67         'controller_init' : function() {
68                 try {
69                         var obj = this;
70                         JSAN.use('util.controller'); obj.controller = new util.controller();
71                         obj.controller.init(
72                                 {
73                                         control_map : {
74                                                 'sample' : [ ['command'], function() { } ],
75                                                 'header' : [ ['change'], function() { obj.preview(); } ],
76                                                 'line_item' : [ ['change'], function() { obj.preview(); } ],
77                                                 'footer' : [ ['change'], function() { obj.preview(); } ],
78                                                 'preview' : [
79                                                         ['command'],
80                                                         function() {
81                                                         }
82                                                 ],
83                                                 'save' : [
84                                                         ['command'],
85                                                         function() {
86                                                                 obj.save_template( obj.controller.view.template_name_menu.value );
87                                                         }
88                                                 ],
89                                                 'delete' : [
90                                                         ['command'],
91                                                         function() {
92                                                                 alert( 'not yet implemented' );
93                                                         }
94                                                 ],
95                                                 'macros' : [
96                                                         ['command'],
97                                                         function() {
98                                                                 try {
99                                                                         JSAN.use('util.functional');
100                                                                         var template_type = obj.controller.view.template_type_menu.value;
101                                                                         var macros;
102                                                                         switch(template_type) {
103                                                                                 case 'items':
104                                                                                         JSAN.use('circ.util');
105                                                                                         macros = util.functional.map_list(
106                                                                                                 circ.util.columns( {} ),
107                                                                                                 function(o) {
108                                                                                                         return '%' + o.id + '%';
109                                                                                                 }
110                                                                                         );
111                                                                                 break;
112                                                                                 case 'holds':
113                                                                                         JSAN.use('circ.util');
114                                                                                         macros = util.functional.map_list(
115                                                                                                 circ.util.hold_columns( {} ),
116                                                                                                 function(o) {
117                                                                                                         return '%' + o.id + '%';
118                                                                                                 }
119                                                                                         );
120                                                                                 break;
121                                                                                 case 'patrons':
122                                                                                         JSAN.use('patron.util');
123                                                                                         macros = util.functional.map_list(
124                                                                                                 patron.util.columns( {} ),
125                                                                                                 function(o) {
126                                                                                                         return '%' + o.id + '%';
127                                                                                                 }
128                                                                                         );
129                                                                                 break;
130                                                                         }
131                                                                         var macro_string = macros.join(', ');
132                                                                         JSAN.use('util.window');
133                                                                         var win = new util.window();
134                                                                         win.open('data:text/html,'
135                                                                                 + window.escape(
136                                                                                         '<html style="width: 600; height: 400;">'
137                                                                                         + '<head><title>Template Macros</title></head>'
138                                                                                         + '<body onload="document.getElementById(\'btn\').focus()">'
139                                                                                         + '<h1>General:</h1>'
140                                                                                         + '<p>%PINES_CODE%, %TODAY%, %STAFF_FIRSTNAME%, %STAFF_LASTNAME%, '
141                                                                                         + '%PATRON_FIRSTNAME%, %LIBRARY%</p>'
142                                                                                         + '<h1>For type: '
143                                                                                         + template_type + '</h1>'
144                                                                                         + '<p>' + macro_string + '</p>'
145                                                                                         + '<button id="btn" onclick="window.close()">Close Window</button>'
146                                                                                         + '</body></html>'
147                                                                                 ), 'title', 'chrome,resizable');
148                                                                 } catch(E) {
149                                                                         alert(E);
150                                                                 }
151                                                         }
152                                                 ],
153                                                 'template_name_menu_placeholder' : [
154                                                         ['render'],
155                                                         function(e) {
156                                                                 return function() {
157                                                                         JSAN.use('util.widgets'); JSAN.use('util.functional');
158                                                                         util.widgets.remove_children(e);
159                                                                         var ml = util.widgets.make_menulist(
160                                                                                 util.functional.map_object_to_list(
161                                                                                         obj.data.print_list_templates,
162                                                                                         function(o,i) { return [i,i]; }
163                                                                                 )
164                                                                         );
165                                                                         ml.setAttribute('id','template_name_menu');
166                                                                         ml.setAttribute('editable','true');
167                                                                         ml.setAttribute('flex','1');
168                                                                         e.appendChild(ml);
169                                                                         obj.controller.view.template_name_menu = ml;
170                                                                         ml.addEventListener(
171                                                                                 'command',
172                                                                                 function(ev) {
173                                                                                         var tmp = obj.data.print_list_templates[ ev.target.value ];
174                                                                                         obj.controller.view.template_type_menu.value = tmp.type;
175                                                                                         obj.controller.view.header.value = tmp.header;
176                                                                                         obj.controller.view.line_item.value = tmp.line_item;
177                                                                                         obj.controller.view.footer.value = tmp.footer;
178                                                                                 },
179                                                                                 false
180                                                                         );
181                                                                         setTimeout(
182                                                                                 function() {
183                                                                                         var tmp = obj.data.print_list_templates[ ml.value ];
184                                                                                         obj.controller.view.template_type_menu.value = tmp.type;
185                                                                                         obj.controller.view.header.value = tmp.header;
186                                                                                         obj.controller.view.line_item.value = tmp.line_item;
187                                                                                         obj.controller.view.footer.value = tmp.footer;
188                                                                                 }, 0
189                                                                         );
190                                                                 }
191                                                         }
192                                                 ],
193                                                 'template_type_menu_placeholder' : [
194                                                         ['render'],
195                                                         function(e) {
196                                                                 return function() {
197                                                                         JSAN.use('util.widgets'); JSAN.use('util.functional');
198                                                                         util.widgets.remove_children(e);
199                                                                         var ml = util.widgets.make_menulist(
200                                                                                 util.functional.map_list(
201                                                                                         obj.data.print_list_types,
202                                                                                         function(o) { return [o,o]; }
203                                                                                 )
204                                                                         );
205                                                                         ml.setAttribute('id','template_types_menu');
206                                                                         e.appendChild(ml);
207                                                                         obj.controller.view.template_type_menu = ml;
208                                                                 }
209                                                         }
210                                                 ],
211
212                                         }
213                                 }
214                         );
215                 } catch(E) {
216                         alert('controller_init: ' + E );
217                 }
218         },
219
220         'preview' : function (name) { 
221                 var params = { 
222                         'au' : new au(), 
223                         'lib' : this.data.list.au[0].home_ou(),
224                         'staff' : this.data.list.au[0],
225                         'header' : this.controller.view.header.value,
226                         'line_item' : this.controller.view.line_item.value,
227                         'footer' : this.controller.view.footer.value,
228                         'type' : this.controller.view.template_type_menu.value,
229                         'list' : this.test_list[ this.controller.view.template_type_menu.value ].dump(),
230                         'sample_view' : this.controller.view.sample,
231                 };
232                 this.print( params );
233         },
234
235         'save_template' : function(name) {
236                 this.data.print_list_templates[name].header = this.controller.view.header.value;
237                 this.data.print_list_templates[name].line_item = this.controller.view.line_item.value;
238                 this.data.print_list_templates[name].footer = this.controller.view.footer.value;
239                 this.data.print_list_templates[name].type = this.controller.view.template_type_menu.value;
240                 this.data.stash( 'print_list_templates' );
241                 alert('Template Saved');
242         },
243
244         'print' : function(params) {
245         },
246 }
247
248 dump('exiting print_list_template_editor.js\n');