]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/hold_details.js
code clean up--removed some leftover testing strings
[Evergreen.git] / Open-ILS / xul / staff_client / server / patron / hold_details.js
1
2 function $(id) { return document.getElementById(id); }
3
4 function my_init() {
5     try {
6         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
7         if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
8         JSAN.errorLevel = "die"; // none, warn, or die
9         JSAN.addRepository('/xul/server/');
10
11
12         dojo.require('openils.PermaCrud');
13         JSAN.use('util.error'); g.error = new util.error();
14         JSAN.use('util.network'); g.network = new util.network();
15         JSAN.use('util.date'); JSAN.use('util.money'); JSAN.use('patron.util');
16         JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
17
18         g.error.sdump('D_TRACE','my_init() for hold_notices.xul');
19
20         g.ahr_id = xul_param('ahr_id');
21
22         g.ahr = g.network.simple_request('FM_AHR_RETRIEVE',[ ses(), g.ahr_id ]);
23         if (typeof g.ahr.ilsevent != 'undefined') { throw(g.ahr); }
24         g.ahr = g.ahr[0];
25
26         render_patron();
27
28         a_list_of_one();
29
30         var x = document.getElementById('bib_brief_box'); while (x.firstChild) x.removeChild(x.lastChild);
31         var bib_brief = document.createElement('iframe'); x.appendChild(bib_brief);
32         bib_brief.setAttribute('flex',1);
33         bib_brief.setAttribute('src',urls.XUL_BIB_BRIEF);
34         get_contentWindow(bib_brief).xulG = { 'docid' : g.ahr.target() };
35
36         refresh();
37
38     } catch(E) {
39         try { g.error.standard_unexpected_error_alert('/xul/server/patron/hold_notices.xul',E); } catch(E) { alert('FIXME: ' + js2JSON(E)); }
40     }
41 }
42
43 function render_patron() {
44     if (g.ahr.usr()) {
45         JSAN.use('patron.util');
46         var au_obj = patron.util.retrieve_fleshed_au_via_id( ses(), g.ahr.usr() );
47
48         $('patron_name').setAttribute('value',
49                                       ( au_obj.prefix() ? au_obj.prefix() + ' ' : '') +
50                                       au_obj.family_name() + ', ' +
51                                       au_obj.first_given_name() + ' ' +
52                                       ( au_obj.second_given_name() ? au_obj.second_given_name() + ' ' : '' ) +
53                                       ( au_obj.suffix() ? au_obj.suffix() : '')
54                                       + ' : ' + au_obj.card().barcode()
55                                       );
56     }
57 }
58
59 function a_list_of_one() {
60     JSAN.use('circ.util');
61     var columns = circ.util.hold_columns(
62                                          {
63                                              'status' : { 'hidden' : true },
64                                              'request_time' : { 'hidden' : false },
65                                              'pickup_lib_shortname' : { 'hidden' : false },
66                                              'current_copy' : { 'hidden' : false },
67                                              'phone_notify' : { 'hidden' : false },
68                                              'email_notify' : { 'hidden' : false },
69                                          }
70                                           );
71     JSAN.use('util.list'); g.list = new util.list('holds_list');
72     g.list.init(
73                 {
74                     'columns' : columns,
75                         'map_row_to_columns' : circ.util.std_map_row_to_columns(),
76                         'retrieve_row' : function(params) {
77                         var row = params.row;
78                         try {
79                             switch(row.my.ahr.hold_type()) {
80                             case 'M' :
81                                 row.my.mvr = g.network.request(
82                                                                api.MODS_SLIM_METARECORD_RETRIEVE.app,
83                                                                api.MODS_SLIM_METARECORD_RETRIEVE.method,
84                                                                [ row.my.ahr.target() ]
85                                                                );
86                                 break;
87                             default:
88                                 row.my.mvr = g.network.simple_request(
89                                                                       'MODS_SLIM_RECORD_RETRIEVE.authoritative',
90                                                                       [ row.my.ahr.target() ]
91                                                                       );
92                                 if (row.my.ahr.current_copy()) {
93                                     row.my.acp = g.network.simple_request( 'FM_ACP_RETRIEVE', [ row.my.ahr.current_copy() ]);
94                                 }
95                                 break;
96                             }
97                         } catch(E) {
98                             g.error.sdump('D_ERROR','retrieve_row: ' + E );
99                         }
100                         if (typeof params.on_retrieve == 'function') {
101                             params.on_retrieve(row);
102                         }
103                         return row;
104                     },
105                         }
106                 );
107     g.list.append(
108                   {
109                       'row' : {
110                           'my' : {
111                               'ahr' : g.ahr,
112                                   }
113                       },
114                           'no_auto_select' : true,
115                               }
116                   );
117 }
118
119 function refresh() {
120     retrieve_notifications(); render_notifications(); retrieve_notes(); render_notes();
121 }
122
123 function retrieve_notifications() {
124     g.notifications = g.network.simple_request('FM_AHN_RETRIEVE_VIA_AHR',[ ses(), g.ahr_id ]).reverse();
125 }
126
127 function retrieve_notes() {
128     try{
129         g.ahr_id = xul_param('ahr_id');
130
131         g.notes = new openils.PermaCrud(
132                                       {
133                                           authtoken :ses()
134                                       }
135                                        ).search('ahrn', {hold:g.ahr_id});
136     }
137     catch(E){alert(E);}
138
139 }
140
141 function apply(node,field,value) {
142     util.widgets.apply(
143                        node,'name',field,
144                        function(n) {
145                            switch(n.nodeName) {
146                            case 'description' : n.appendChild( document.createTextNode( value ) ); break;
147                            case 'label' : n.value = value; break;
148                            default : n.value = value; break;
149                            }
150                        }
151                        );
152 }
153
154 function render_notifications() {
155     JSAN.use('util.widgets'); util.widgets.remove_children('notifications_panel');
156     var np = $('notifications_panel');
157
158     for (var i = 0; i < g.notifications.length; i++) {
159
160         /* template */
161         var node = $('notification_template').cloneNode(true); np.appendChild(node); node.hidden = false;
162         util.widgets.apply(node,'name','notify_time',
163                            function(n){
164                                n.setAttribute(
165                                               "tooltiptext",
166                                               $("patronStrings").getFormattedString('staff.patron.hold_notices.tooltiptext',[g.notifications[i].id(), g.notifications[i].hold(), g.notifications[i].notify_staff()])
167                                               );
168                            }
169                            );
170         apply(node,'method',g.notifications[i].method() ? g.notifications[i].method() : '');
171         apply(node,'note',g.notifications[i].note() ? g.notifications[i].note() : '');
172         apply(node,'notify_time',g.notifications[i].notify_time() ? g.notifications[i].notify_time().toString().substr(0,10) : '');
173     }
174
175 }
176
177 function render_notes() {
178
179     JSAN.use('util.widgets'); util.widgets.remove_children('notes_panel');
180     var notep = $('notes_panel');
181
182     for (var i = 0; i < g.notes.length; i++) {
183
184         // template
185         var notenode = $('note_template').cloneNode(true); notep.appendChild(notenode); notenode.hidden = false;
186
187         /* alert('notenode = '
188               + notenode + ' title = ' + g.notes[i].title() + ' note = ' +
189               g.notes[i].body() + ' pub = ' + g.notes[i].pub() + ' slip = ' +
190               g.notes[i].slip() );*/
191
192         apply(notenode,'title',g.notes[i].title() ? g.notes[i].title() : '');
193         apply(notenode,'note',g.notes[i].body() ? g.notes[i].body() : '');
194         apply(notenode,'pub',g.notes[i].pub() ? g.notes[i].pub() : '');
195         apply(notenode,'slip',g.notes[i].slip() ? g.notes[i].slip() : '');
196     }
197 }
198 function new_notification() {
199     try {
200         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalBrowserWrite");
201         var xml = '<groupbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1">';
202         xml += '<caption label="' + $("patronStrings").getString('staff.patron.hold_notices.new_notification_record') + '"/><grid flex="1"><columns><column/><column flex="1"/></columns><rows>';
203         xml += '<row><label value="' + $("patronStrings").getString('staff.patron.hold_notices.method') + '"/><textbox id="method" name="fancy_data" context="clipboard"/></row>';
204         xml += '<row><label value="' + $("patronStrings").getString('staff.patron.hold_notices.note') + '"/><textbox multiline="true" id="note" name="fancy_data" context="clipboard"/></row>';
205         xml += '<row><spacer/><hbox><button label="' + $("patronStrings").getString('staff.patron.hold_notices.cancel') + '" name="fancy_cancel" ';
206         xml += 'accesskey="' + $("patronStrings").getString('staff.patron.hold_notices.cancel_accesskey') + '"/>';
207         xml += '<button label="' + $("patronStrings").getString('staff.patron.hold_notices.add_notif_record') + '" ';
208         xml += 'accesskey="' + $("patronStrings").getString('staff.patron.hold_notices.add_notif_record_accesskey') + '" name="fancy_submit"/></hbox></row></rows></grid></groupbox>';
209         JSAN.use('util.window'); var win = new util.window();
210         var fancy_prompt_data = win.open(
211                                          urls.XUL_FANCY_PROMPT,
212                                          'fancy_prompt', 'chrome,resizable,modal,width=700,height=500',
213                                          { 'xml' : xml, 'focus' : 'method', 'title' : $("patronStrings").getString('staff.patron.hold_notices.add_notif_record') }
214                                          );
215         if (fancy_prompt_data.fancy_status == 'complete') {
216             var notification = new ahn();
217             notification.isnew(1);
218             notification.hold(g.ahr_id);
219             notification.method( fancy_prompt_data.method );
220             notification.note( fancy_prompt_data.note );
221             var r = g.network.simple_request('FM_AHN_CREATE',[ ses(), notification ]); if (typeof r.ilsevent != 'undefined') throw(r);
222             setTimeout(function(){refresh();},0);
223         }
224     } catch(E) {
225         g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.hold_notices.new_notification.not_created'),E);
226         setTimeout(function(){refresh();},0);
227     }
228 }
229
230 function new_note() {
231      try{
232      var newNote = new fieldmapper.ahrn();
233      newNote.isnew("t");
234      newNote.body(document.getElementById('hold_note_text').value);
235      newNote.hold(g.ahr_id);
236      newNote.title(document.getElementById('hold_note_title').value);
237
238      if($('pub_bool').checked){
239          newNote.pub("t");
240      }else {
241          newNote.pub("f");
242      }
243      if($('print_bool').checked){
244          newNote.slip("t");
245      }else{
246          newNote.slip("f");
247      }
248      newNote.staff("t");
249
250      new openils.PermaCrud({authtoken :ses()}).create(newNote);
251
252      }
253      catch(E) {
254          alert('new_note FAILED');
255      }
256      refresh();
257 }