9edfc8bc43592ec05b474f4105624f1ec8c90904
[Evergreen.git] / Evergreen / staff_client / chrome / content / evergreen / circ / hold_capture.js
1 sdump('D_TRACE','Loading hold_capture.js\n');
2
3 function hold_capture_init(p) {
4         sdump('D_HOLD_CAPTURE',"TESTING: hold_capture.js: " + mw.G['main_test_variable'] + '\n');
5         sdump('D_CONSTRUCTOR',arg_dump(arguments));
6
7
8         // gives: p.clamshell, p.right_panel, p.left_panel, p.inner_left_clamshell, p.inner_top_panel, p.inner_bottom_panel
9         hold_capture_clamshell_init(p);
10
11         // gives: p.hold_capture_items, p.redraw_hold_capture_items
12         hold_capture_hold_capture_items_init(p);
13
14         p.refresh = function() {
15         }
16
17         p.retrieve_button = p.w.document.getElementById('PatronSearch_retrieve_button');
18         p.retrieve_button.addEventListener(
19                 'command',
20                 function (ev) {
21                         spawn_patron_display(
22                                 p.w.app_shell,'new_tab','main_tabbox',
23                                 {
24                                         'patron' : retrieve_patron_by_id(
25                                                 p._patron.id()
26                                         )
27                                 }
28                         );
29                 }
30                 ,false
31         );
32
33
34         sdump('D_TRACE_EXIT',arg_dump(arguments));
35         return p;
36 }
37
38 function hold_capture_clamshell_init(p) {
39         p.clamshell = clam_shell_init( { 'w' : p.w, 'node' : p.clamshell_node, 'debug' : p.app } );
40         p.left_panel = p.clamshell.first_deck;
41         p.right_panel = p.clamshell.second_deck;
42 }
43
44 function hold_capture_hold_capture_items_init(p) {
45         p.hold_capture_items = hold_capture_items_init( { 'w' : p.w, 'node' : p.hold_capture_items_node, 'debug' : p.app } );
46
47         var hold_captures = [];
48         var tb = p.hold_capture_items_node.getElementsByAttribute('id','hold_capture_barcode_entry_textbox')[0];
49         var submit_button = p.hold_capture_items_node.getElementsByAttribute('id','hold_capture_submit_barcode_button')[0];
50
51         p.attempt_hold_capture = function(barcode) {
52                 try {
53                         //if (! is_barcode_valid(barcode) ) throw('Invalid Barcode');
54                         var check = hold_capture_by_copy_barcode( barcode, true );  // barcode, flesh
55                         if (check) {
56                                 sdump('D_HOLD_CAPTURE','check = ' + check + '\n' + pretty_print( js2JSON( check ) ) + '\n');
57
58                                 check.status = 0;
59                                 check.text = 'Captured for Hold Request';
60
61                                 hold_captures.push( check );
62                                 p.hold_capture_items.add_hold_capture_items( [ hold_captures.length - 1 ] );
63
64                                 var patron = retrieve_patron_by_id( check.hold.usr() );
65
66                                 sPrint(check.text + '<br />\r\n' + 'Barcode: ' + barcode + '  Title: ' + check.record.title() + 
67                                         '  Author: ' + check.record.author() + '<br />\r\n' +
68                                         'Route To: ' + check.route_to + 
69                                         '  Patron: ' + patron.card().barcode() + ' ' + patron.family_name() + ', ' + patron.first_given_name() + 
70                                         '<br />\r\n'
71                                 );
72                                 tb.value = ''; 
73                         }
74                 } catch(E) {
75                         handle_error(E);
76                 }
77                 tb.select(); tb.focus();
78         }
79
80         tb.addEventListener(
81                 'keypress',
82                 function(ev) {
83                         if (ev.keyCode == 13 || ev.keyCode == 77 ) { p.attempt_hold_capture( tb.value ); }
84                 },
85                 false
86         );
87         submit_button.addEventListener(
88                 'command',
89                 function(ev) {
90                         p.attempt_hold_capture( tb.value );
91                 },
92                 false
93         );
94
95         p.redraw_hold_capture_items = function() {
96                 p.hold_capture_items.clear_hold_capture_items();
97                 for (var i = 0; i < hold_captures.length; i++) {
98                         p.hold_capture_items.add_hold_capture_items( [ i ] );
99                 }
100         }
101
102         p.hold_capture_items.register_hold_capture_items_select_callback(
103                 function (ev) {
104                         sdump('D_HOLD_CAPTURE','Firing hold_capture_items_select_callback\n');
105                         var hold_capture_items = get_list_from_tree_selection( p.hold_capture_items.paged_tree.tree );
106                         /* grab cover art for selected item? */
107                 }
108         );
109         p.hold_capture_items.register_flesh_hold_capture_items_function(
110                 function (treeitem) {
111                         sdump('D_HOLD_CAPTURE','Firing flesh_hold_capture_items_function\n');
112                         var record_id = treeitem.getAttribute('record_id'); 
113                         p.hold_capture_items.map_hold_capture_items_to_cols( hold_captures[ record_id ], treeitem );
114                 }
115         );
116         p.hold_capture_items.register_context_builder(
117                 function (ev) {
118                         sdump('D_HOLD_CAPTURE','Firing context_builder\n');
119                         empty_widget(p.hold_capture_items.paged_tree.popup);
120                         var hold_capture_items = get_list_from_tree_selection( p.hold_capture_items.paged_tree.tree );
121                         var menuitem;
122
123                         /*** COPY EDITOR ***/
124                         menuitem = p.hold_capture_items.paged_tree.w.document.createElement('menuitem');
125                         p.hold_capture_items.paged_tree.popup.appendChild( menuitem );
126                         menuitem.setAttribute('label',getString('circ.context_edit'));
127                         menuitem.addEventListener(
128                                 'command',
129                                 function (ev) {
130                                         alert('Not Yet Implemented');
131                                         for (var i = 0; i < hold_capture_items.length; i++) {
132                                                 var idx = hold_capture_items[i].getAttribute('record_id');
133                                                 sdump('D_HOLD_CAPTURE','Firing copy edit context\n');
134                                         }
135                                 },
136                                 false
137                         );
138
139                         /*** OPAC ***/
140                         menuitem = p.hold_capture_items.paged_tree.w.document.createElement('menuitem');
141                         p.hold_capture_items.paged_tree.popup.appendChild( menuitem );
142                         menuitem.setAttribute('label',getString('circ.context_opac'));
143                         menuitem.addEventListener(
144                                 'command',
145                                 function (ev) {
146                                         alert('Not Yet Implemented');
147                                         for (var i = 0; i < hold_capture_items.length; i++) {
148                                                 var idx = hold_capture_items[i].getAttribute('record_id');
149                                                 sdump('D_HOLD_CAPTURE','Firing opac context\n');
150                                         }
151                                 },
152                                 false
153                         );
154                         
155                 }
156         );
157 }
158
159