]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/print_list_template_editor.js
receipts
[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","???","Normal","???","Normal","0","0","18","","","2006-02-13 15:31:30.730986-05","","2006-02-27","Deep waters","Krentz, Jayne Ann.","1","???","???","???"],["3524184","462","???","nc10","Not Cataloged","","???","Normal","???","Normal","0","0","0","","","2006-02-16 01:00:44.84216-05","","2006-03-01","temp title","temp author","2","???","???","???"],["3524178","487","???","nc1","Not Cataloged","","???","Normal","???","Normal","0","0","0","","","2006-02-16 11:52:51.065944-05","","2006-03-02","title1","author1","2","???","???","???"]]'); } },
35                                 'holds' : { 'dump' : function() { return JSON2js('[["2005-11-18","","","T","Athens-Clarke County Library","ARL-ATH","???","demo@demoland.tv","","","","18","111-222-3344","2006-02-16 03:33:24.90493-05","3","0","183324","3","WATER GARDENS (FOR YOUR GARDEN) PB","Spier, Carol."],["2005-11-22","","","T","Athens-Clarke County Library","ARL-ATH","33207004527158","demo@demoland.tv","","","","25","111-222-3344","2006-02-16 03:33:27.754555-05","3","0","278434","3","Harry Potter and the sorcerer\'s stone","Rowling, J. K."],["2005-11-22","2006-02-09 21:29:09.575124-05","","T","Athens-Clarke County Library","ARL-ATH","33207000946790","demo@demoland.tv","","","","26","111-222-3344","2006-02-09 21:03:11.938293-05","3","0","352139","3","Shakespeare the man","Rowse, A. L. "],["2005-11-22","","","T","Athens-Clarke County Library","ARL-ATH","???","demo@demoland.tv","","","","27","111-222-3344","2006-02-16 03:33:39.35158-05","3","0","277202","3","Costa Rica","Morrison, Marion."],["2005-11-22","","","T","Bogart Branch Library","ARL-BOG","???","demo@demoland.tv","","","","29","111-222-3344","2006-02-16 03:33:41.297713-05","3","0","366540","3","On leaving Charleston","Ripley, Alexandra."],["2005-11-24","","","T","Athens-Clarke County Library","ARL-ATH","???","demo@demoland.tv","","","","30","111-222-3344","2006-02-16 03:33:41.697186-05","3","0","216351","3","Cats! Cats! Cats!","Wiseman, Bernard."],["2005-12-09","","","T","Athens-Clarke County Library","ARL-ATH","???","demo@demoland.tv","","","","32","111-222-3344","2006-02-16 03:33:41.970716-05","3","0","313569","3","Water","Cooper, Jason"],["2006-02-16","2006-02-16 06:23:19.602866-05","","T","Athens-Clarke County Library","ARL-ATH","a1115b1","demo@demoland.tv","","","","65","111-222-3345","2006-02-16 06:22:11.49379-05","14","0","200839","3","Water all around","Pine, Tillie S."]]'); } },
36                                 'patrons' : { 'dump' : function() { return JSON2js('[["090909090","demo3","Good","Users","Yes","6","Airman","Demo3","Demo3","D","III","","0","2005-11-22","2008-11-22","ECGR-MIDVL","0","","","","demo2@open-ils.org","1980-04-03","Drivers Licence","9898888777","???","","1"],["123321123321123","miker2","Good","Patrons","Yes","21","mr","Rylander","Mike","E","IIX","","0","2006-02-16","2006-01-01","ARL-BOG","0","770-222-5555","","","miker@example.com","1979-01-22","State ID","0987654321","???","","1"],["123456789","demo","Good","Staff","Yes","3","Mr.","Joe","Demo","J","","test","0","2005-11-15","2008-11-15","ARL-ATH","978.38","111-222-3345","222-333-4455","","demo@demoland.tv","1976-10-24","Drivers Licence","888888","???","","1"],["user2","user2","Good","Patrons","Yes","17","","User","Jim","","","","0","2006-02-13","2009-02-13","ARL-BOG","0","404","","","","2005-12-12","Drivers Licence","1234","???","","1"],["18009999999","animalmother","Good","Patrons","Yes","12","","Mother","Animal","","","","0","2006-02-13","2008-02-15","ARL-BOG","0","444-333-2222","","","animalmother@fullmetaljacket.net","1969-01-02","SSN","123456789","???","","1"],["staff3","staff3","Good","Circulators","Yes","15","","staff","circ","","","","0","2006-02-13","2009-02-13","ARL-BKM","0","777","","","","2005-12-12","Drivers Licence","n/a","???","","1"],["staff2","staff2","Good","Circulators","Yes","14","","Staff","Circ","","","","0","2006-02-13","2009-02-13","ARL-BOG","0","777","","","","2005-12-12","Drivers Licence","n/a","???","","1"],["11223344","miker","Good","Patrons","Yes","8","Mr","rylander","mike","","","","0","2005-12-19","2008-12-19","ARL-EAST","0","12123412","","","mrylander@example.com","1979-01-22","Voter Card","123456","???","","1"],["987654321","erickson","Good","Operations Manager","Yes","4","","Erickson","Bill","S","","","1","2005-11-18","2008-11-18","ARL-ATH","5","111-444-7777","1-800-999-9998","","bill@mastashake.org","1976-10-24","Voter Card","999999999999","???","","1"],["user4","user4","Good","Patrons","Yes","34","","Nimble","Jack","B","","","0","2006-02-16","2009-02-16","ARL-ATH","0","404","","","","2000-10-10","Drivers Licence","123","???","","1"],["user3","user3","Good","Patrons","Yes","18","","User","Jane","","","","0","2006-02-13","2009-02-13","ARL-BKM","0","404","","","","2005-12-12","Drivers Licence","12345","???","","1"],["user1","user1","Good","Patrons","Yes","16","","User","Joe","","","","0","2006-02-13","2009-02-13","ARL-ATH","0","404","404","","","2005-12-12","Drivers Licence","123","???","","1"],["staff1","staff1","Good","Circulators","Yes","13","","Staff","Circ","","","","0","2006-02-13","2009-02-13","ARL-ATH","0","777","","","","2005-12-12","Drivers Licence","n/a","???","","1"],["1122332211","demo2","Good","Users","Yes","5","Advisor","Jones","Demo2","D","","","0","2005-11-22","2008-11-22","CPRL-R","0","111-222-3333","","","demo2@open-ils.org","1980-05-02","Drivers Licence","0009990000","???","","1"]]'); } },
37
38                         }
39
40                         if (typeof obj.data.print_list_templates == 'undefined') {
41                                 obj.data.print_list_types = [ 'items', 'holds', 'patrons' ];
42                                 obj.data.print_list_templates = { 
43                                         'items_out' : {
44                                                 'type' : 'items',
45                                                 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou have the following items:<hr/><ol>',
46                                                 'line_item' : '<li>%title%\r\nBarcode: %barcode% Due: %due_date%\r\n',
47                                                 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%',
48                                         }, 
49                                         'checkout' : {
50                                                 'type' : 'items',
51                                                 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou checked out the following items:<hr/><ol>',
52                                                 'line_item' : '<li>%title%\r\nBarcode: %barcode% Due: %due_date%\r\n',
53                                                 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%',
54                                         }, 
55                                         'checkin' : {
56                                                 'type' : 'items',
57                                                 'header' : 'You checked in the following items:<hr/><ol>',
58                                                 'line_item' : '<li>%title%\r\nBarcode: %barcode%  Call Number: %call_number%\r\n',
59                                                 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\n',
60                                         }, 
61                                         'holds' : {
62                                                 'type' : 'holds',
63                                                 'header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou have the following titles on hold:<hr/><ol>',
64                                                 'line_item' : '<li>%title%\r\n',
65                                                 'footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%',
66                                         } 
67                                 }; 
68
69                                 obj.data.stash( 'print_list_templates', 'print_list_types' );
70                         }
71
72                         obj.controller_init();
73                         obj.controller.render(); obj.controller.view.template_name_menu.focus();
74
75                 } catch(E) {
76                         alert('init: ' + E);
77                         this.error.sdump('D_ERROR','print_list.init: ' + E + '\n');
78                 }
79         },
80
81         'controller_init' : function() {
82                 try {
83                         var obj = this;
84                         JSAN.use('util.controller'); obj.controller = new util.controller();
85                         obj.controller.init(
86                                 {
87                                         control_map : {
88                                                 'sample' : [ ['command'], function() { } ],
89                                                 'header' : [ ['change'], function() { obj.preview(); } ],
90                                                 'line_item' : [ ['change'], function() { obj.preview(); } ],
91                                                 'footer' : [ ['change'], function() { obj.preview(); } ],
92                                                 'preview' : [
93                                                         ['command'],
94                                                         function() {
95                                                                 obj.preview();
96                                                         }
97                                                 ],
98                                                 'save' : [
99                                                         ['command'],
100                                                         function() {
101                                                                 obj.save_template( obj.controller.view.template_name_menu.value );
102                                                         }
103                                                 ],
104                                                 'delete' : [
105                                                         ['command'],
106                                                         function() {
107                                                                 alert( 'not yet implemented' );
108                                                         }
109                                                 ],
110                                                 'macros' : [
111                                                         ['command'],
112                                                         function() {
113                                                                 try {
114                                                                         JSAN.use('util.functional');
115                                                                         var template_type = obj.controller.view.template_type_menu.value;
116                                                                         var macros;
117                                                                         switch(template_type) {
118                                                                                 case 'items':
119                                                                                         JSAN.use('circ.util');
120                                                                                         macros = util.functional.map_list(
121                                                                                                 circ.util.columns( {} ),
122                                                                                                 function(o) {
123                                                                                                         return '%' + o.id + '%';
124                                                                                                 }
125                                                                                         );
126                                                                                 break;
127                                                                                 case 'holds':
128                                                                                         JSAN.use('circ.util');
129                                                                                         macros = util.functional.map_list(
130                                                                                                 circ.util.hold_columns( {} ),
131                                                                                                 function(o) {
132                                                                                                         return '%' + o.id + '%';
133                                                                                                 }
134                                                                                         );
135                                                                                 break;
136                                                                                 case 'patrons':
137                                                                                         JSAN.use('patron.util');
138                                                                                         macros = util.functional.map_list(
139                                                                                                 patron.util.columns( {} ),
140                                                                                                 function(o) {
141                                                                                                         return '%' + o.id + '%';
142                                                                                                 }
143                                                                                         );
144                                                                                 break;
145                                                                         }
146                                                                         var macro_string = macros.join(', ');
147                                                                         JSAN.use('util.window');
148                                                                         var win = new util.window();
149                                                                         win.open('data:text/html,'
150                                                                                 + window.escape(
151                                                                                         '<html style="width: 600; height: 400;">'
152                                                                                         + '<head><title>Template Macros</title></head>'
153                                                                                         + '<body onload="document.getElementById(\'btn\').focus()">'
154                                                                                         + '<h1>General:</h1>'
155                                                                                         + '<p>%PINES_CODE%, %TODAY%, %STAFF_FIRSTNAME%, %STAFF_LASTNAME%, '
156                                                                                         + '%PATRON_FIRSTNAME%, %LIBRARY%</p>'
157                                                                                         + '<h1>For type: '
158                                                                                         + template_type + '</h1>'
159                                                                                         + '<p>' + macro_string + '</p>'
160                                                                                         + '<button id="btn" onclick="window.close()">Close Window</button>'
161                                                                                         + '</body></html>'
162                                                                                 ), 'title', 'chrome,resizable');
163                                                                 } catch(E) {
164                                                                         alert(E);
165                                                                 }
166                                                         }
167                                                 ],
168                                                 'template_name_menu_placeholder' : [
169                                                         ['render'],
170                                                         function(e) {
171                                                                 return function() {
172                                                                         JSAN.use('util.widgets'); JSAN.use('util.functional');
173                                                                         util.widgets.remove_children(e);
174                                                                         var ml = util.widgets.make_menulist(
175                                                                                 util.functional.map_object_to_list(
176                                                                                         obj.data.print_list_templates,
177                                                                                         function(o,i) { return [i,i]; }
178                                                                                 )
179                                                                         );
180                                                                         ml.setAttribute('id','template_name_menu');
181                                                                         ml.setAttribute('editable','true');
182                                                                         ml.setAttribute('flex','1');
183                                                                         e.appendChild(ml);
184                                                                         obj.controller.view.template_name_menu = ml;
185                                                                         ml.addEventListener(
186                                                                                 'command',
187                                                                                 function(ev) {
188                                                                                         var tmp = obj.data.print_list_templates[ ev.target.value ];
189                                                                                         obj.controller.view.template_type_menu.value = tmp.type;
190                                                                                         obj.controller.view.header.value = tmp.header;
191                                                                                         obj.controller.view.line_item.value = tmp.line_item;
192                                                                                         obj.controller.view.footer.value = tmp.footer;
193                                                                                 },
194                                                                                 false
195                                                                         );
196                                                                         setTimeout(
197                                                                                 function() {
198                                                                                         var tmp = obj.data.print_list_templates[ ml.value ];
199                                                                                         obj.controller.view.template_type_menu.value = tmp.type;
200                                                                                         obj.controller.view.header.value = tmp.header;
201                                                                                         obj.controller.view.line_item.value = tmp.line_item;
202                                                                                         obj.controller.view.footer.value = tmp.footer;
203                                                                                 }, 0
204                                                                         );
205                                                                 }
206                                                         }
207                                                 ],
208                                                 'template_type_menu_placeholder' : [
209                                                         ['render'],
210                                                         function(e) {
211                                                                 return function() {
212                                                                         JSAN.use('util.widgets'); JSAN.use('util.functional');
213                                                                         util.widgets.remove_children(e);
214                                                                         var ml = util.widgets.make_menulist(
215                                                                                 util.functional.map_list(
216                                                                                         obj.data.print_list_types,
217                                                                                         function(o) { return [o,o]; }
218                                                                                 )
219                                                                         );
220                                                                         ml.setAttribute('id','template_types_menu');
221                                                                         e.appendChild(ml);
222                                                                         obj.controller.view.template_type_menu = ml;
223                                                                 }
224                                                         }
225                                                 ],
226
227                                         }
228                                 }
229                         );
230                 } catch(E) {
231                         alert('controller_init: ' + E );
232                 }
233         },
234
235         'preview' : function () { 
236                 try {
237                         var params = { 
238                                 'patron' : this.test_patron, 
239                                 'lib' : this.data.hash.aou[ this.data.list.au[0].home_ou() ],
240                                 'staff' : this.data.list.au[0],
241                                 'header' : this.controller.view.header.value,
242                                 'line_item' : this.controller.view.line_item.value,
243                                 'footer' : this.controller.view.footer.value,
244                                 'type' : this.controller.view.template_type_menu.value,
245                                 'list' : this.test_list[ this.controller.view.template_type_menu.value ].dump(),
246                                 'sample_frame' : this.controller.view.sample,
247                         };
248                         JSAN.use('util.print'); var print = new util.print();
249                         print.tree_list( params );
250                 } catch(E) {
251                         this.error.sdump('D_ERROR','preview: ' + E);
252                         alert('preview: ' + E);
253                 }
254         },
255
256         'save_template' : function(name) {
257                 this.data.print_list_templates[name].header = this.controller.view.header.value;
258                 this.data.print_list_templates[name].line_item = this.controller.view.line_item.value;
259                 this.data.print_list_templates[name].footer = this.controller.view.footer.value;
260                 this.data.print_list_templates[name].type = this.controller.view.template_type_menu.value;
261                 this.data.stash( 'print_list_templates' );
262                 alert('Template Saved');
263         },
264
265 }
266
267 dump('exiting print_list_template_editor.js\n');