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