1 dump('entering print_list_template_editor.js\n');
3 if (typeof circ == 'undefined') circ = {};
4 circ.print_list_template_editor = function (params) {
6 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
7 JSAN.use('util.error'); this.error = new util.error();
9 dump('print_list: ' + E + '\n');
13 circ.print_list_template_editor.prototype = {
15 'init' : function( params ) {
18 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
22 obj.session = params['session'];
24 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
26 if (typeof obj.data.print_list_templates == 'undefined') {
27 obj.data.print_list_types = [ 'items', 'holds', 'patrons' ];
28 obj.data.print_list_templates = {
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%',
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%',
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',
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%',
55 obj.data.stash( 'print_list_templates', 'print_list_types' );
58 obj.controller_init();
59 obj.controller.render(); obj.controller.view.template_name_menu.focus();
63 this.error.sdump('D_ERROR','print_list.init: ' + E + '\n');
67 'controller_init' : function() {
70 JSAN.use('util.controller'); obj.controller = new util.controller();
74 'sample' : [ ['command'], function() { } ],
75 'header' : [ ['change'], function() { obj.preview(); } ],
76 'line_item' : [ ['change'], function() { obj.preview(); } ],
77 'footer' : [ ['change'], function() { obj.preview(); } ],
86 obj.save_template( obj.controller.view.template_name_menu.value );
92 alert( 'not yet implemented' );
99 JSAN.use('util.functional');
100 var template_type = obj.controller.view.template_type_menu.value;
102 switch(template_type) {
104 JSAN.use('circ.util');
105 macros = util.functional.map_list(
106 circ.util.columns( {} ),
108 return '%' + o.id + '%';
113 JSAN.use('circ.util');
114 macros = util.functional.map_list(
115 circ.util.hold_columns( {} ),
117 return '%' + o.id + '%';
122 JSAN.use('patron.util');
123 macros = util.functional.map_list(
124 patron.util.columns( {} ),
126 return '%' + o.id + '%';
131 var macro_string = macros.join(', ');
132 JSAN.use('util.window');
133 var win = new util.window();
134 win.open('data:text/html,'
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>'
143 + template_type + '</h1>'
144 + '<p>' + macro_string + '</p>'
145 + '<button id="btn" onclick="window.close()">Close Window</button>'
147 ), 'title', 'chrome,resizable');
153 'template_name_menu_placeholder' : [
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]; }
165 ml.setAttribute('id','template_name_menu');
166 ml.setAttribute('editable','true');
167 ml.setAttribute('flex','1');
169 obj.controller.view.template_name_menu = ml;
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;
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;
193 'template_type_menu_placeholder' : [
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]; }
205 ml.setAttribute('id','template_types_menu');
207 obj.controller.view.template_type_menu = ml;
216 alert('controller_init: ' + E );
220 'preview' : function (name) {
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,
232 this.print( params );
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');
244 'print' : function(params) {
248 dump('exiting print_list_template_editor.js\n');