]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/print_list_template_editor.js
print list template editor, in progress
[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' ];
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: %COPY_BARCODE% Due: %DUE_D%\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: %COPY_BARCODE% Due: %DUE_D%\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: %COPY_BARCODE%\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                                                 'template_name_menu_placeholder' : [
84                                                         ['render'],
85                                                         function(e) {
86                                                                 return function() {
87                                                                         JSAN.use('util.widgets'); JSAN.use('util.functional');
88                                                                         util.widgets.remove_children(e);
89                                                                         var ml = util.widgets.make_menulist(
90                                                                                 util.functional.map_object_to_list(
91                                                                                         obj.data.print_list_templates,
92                                                                                         function(o,i) { return [i,i]; }
93                                                                                 )
94                                                                         );
95                                                                         ml.setAttribute('id','template_name_menu');
96                                                                         ml.setAttribute('editable','true');
97                                                                         ml.setAttribute('flex','1');
98                                                                         e.appendChild(ml);
99                                                                         obj.controller.view.template_name_menu = ml;
100                                                                         ml.addEventListener(
101                                                                                 'command',
102                                                                                 function(ev) {
103                                                                                         var tmp = obj.data.print_list_templates[ ev.target.value ];
104                                                                                         obj.controller.view.template_type_menu.value = tmp.type;
105                                                                                         obj.controller.view.header.value = tmp.header;
106                                                                                         obj.controller.view.line_item.value = tmp.line_item;
107                                                                                         obj.controller.view.footer.value = tmp.footer;
108                                                                                 },
109                                                                                 false
110                                                                         );
111                                                                         setTimeout(
112                                                                                 function() {
113                                                                                         var tmp = obj.data.print_list_templates[ ml.value ];
114                                                                                         obj.controller.view.template_type_menu.value = tmp.type;
115                                                                                         obj.controller.view.header.value = tmp.header;
116                                                                                         obj.controller.view.line_item.value = tmp.line_item;
117                                                                                         obj.controller.view.footer.value = tmp.footer;
118                                                                                 }, 0
119                                                                         );
120                                                                 }
121                                                         }
122                                                 ],
123                                                 'template_type_menu_placeholder' : [
124                                                         ['render'],
125                                                         function(e) {
126                                                                 return function() {
127                                                                         JSAN.use('util.widgets'); JSAN.use('util.functional');
128                                                                         util.widgets.remove_children(e);
129                                                                         var ml = util.widgets.make_menulist(
130                                                                                 util.functional.map_list(
131                                                                                         obj.data.print_list_types,
132                                                                                         function(o) { return [o,o]; }
133                                                                                 )
134                                                                         );
135                                                                         ml.setAttribute('id','template_types_menu');
136                                                                         e.appendChild(ml);
137                                                                         obj.controller.view.template_type_menu = ml;
138                                                                         ml.addEventListener(
139                                                                                 'command',
140                                                                                 function(ev) {
141                                                                                         alert(ev.target.value);
142                                                                                 },
143                                                                                 false
144                                                                         );
145                                                                 }
146                                                         }
147                                                 ],
148
149                                         }
150                                 }
151                         );
152                         obj.controller.render(); obj.controller.view.template_name_menu.focus();
153
154                 } catch(E) {
155                         this.error.sdump('D_ERROR','print_list.init: ' + E + '\n');
156                 }
157         },
158
159         'test_template' : function (name) { 
160                 var params = { 
161                         'au' : test_patron, 
162                         'lib' : obj.data.list.au[0].home_ou(),
163                         'staff' : obj.data.list.au[0],
164                         'header' : document.getElementById(name + '_header_tb').value,
165                         'line_item' : document.getElementById(name + '_line_item_tb').value,
166                         'footer' : document.getElementById(name + '_footer_tb').value
167                 };
168                 this.print.print_list( params, sample_view );
169         },
170
171         'save_template' : function(name) {
172                 this.data.print_list_templates[name].header = this.controller.view.header.value;
173                 this.data.print_list_templates[name].line_item = this.controller.view.line_item.value;
174                 this.data.print_list_templates[name].footer = this.controller.view.footer.value;
175                 this.data.stash( 'print_list_templates' );
176                 alert('Template Saved');
177         },
178 }
179
180 dump('exiting print_list_template_editor.js\n');