edit copy context commands
[Evergreen.git] / Evergreen / staff_client / chrome / content / evergreen / circ / checkin.js
1 sdump('D_TRACE','Loading checkin.js\n');
2
3 function checkin_init(p) {
4         sdump('D_CHECKIN',"TESTING: checkin.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         checkin_clamshell_init(p);
10
11         // gives: p.checkin_items, p.redraw_checkin_items
12         checkin_checkin_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 checkin_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 checkin_checkin_items_init(p) {
45         p.checkin_items = checkin_items_init( { 'w' : p.w, 'node' : p.checkin_items_node, 'debug' : p.app } );
46
47         var checkins = [];
48
49         var backdate_tb = p.checkin_items_node.getElementsByAttribute('id','checkin_effective_date_textbox')[0];
50         backdate_tb.value = formatted_date( new Date(), '%Y-%m-%d');
51         backdate_tb.addEventListener(
52                 'change',
53                 function () {
54                         var flag = false;
55                         var darray = backdate_tb.value.split('-');
56                         var year = darray[0]; if ( (!year) || (year.length != 4) || (!parseInt(year)) ) flag = true;
57                         var month = darray[1]; if ( (!month) || (month.length !=2) || (!parseInt(month)) ) flag = true;
58                         var day = darray[2]; if ( (!day) || (day.length !=2) || (!parseInt(day)) ) flag = true;
59                         if (flag) {
60                                 snd_bad();
61                                 backdate_tb.value = formatted_date( new Date(), '%Y-%m-%d');
62                         }
63                 },
64                 false
65         );
66
67         var tb = p.checkin_items_node.getElementsByAttribute('id','checkin_barcode_entry_textbox')[0];
68         var submit_button = p.checkin_items_node.getElementsByAttribute('id','checkin_submit_barcode_button')[0];
69
70         p.attempt_checkin = function(barcode) {
71                 try {
72                         //if (! is_barcode_valid(barcode) ) throw('Invalid Barcode');
73                         var check = checkin_by_copy_barcode( barcode, backdate_tb.value );
74                         if (check) {
75                                 sdump('D_CHECKIN','check = ' + check + '\n' + pretty_print( js2JSON( check ) ) + '\n');
76
77                                 if (check.status > -1) {
78                                         checkins.push( check );
79                                         p.checkin_items.add_checkin_items( [ checkins.length - 1 ] );
80                                 } else {
81                                         // should be handled already
82                                 }
83
84                                 tb.value = '';
85                         }
86                 } catch(E) {
87                         handle_error(E);
88                 }
89                 tb.select(); tb.focus();
90         }
91
92         tb.addEventListener(
93                 'keypress',
94                 function(ev) {
95                         if (ev.keyCode == 13 || ev.keyCode == 77 ) { p.attempt_checkin( tb.value ); }
96                 },
97                 false
98         );
99         submit_button.addEventListener(
100                 'command',
101                 function(ev) {
102                         p.attempt_checkin( tb.value );
103                 },
104                 false
105         );
106
107         p.redraw_checkin_items = function() {
108                 p.checkin_items.clear_checkin_items();
109                 for (var i = 0; i < checkins.length; i++) {
110                         p.checkin_items.add_checkin_items( [ i ] );
111                 }
112         }
113
114         p.checkin_items.register_checkin_items_select_callback(
115                 function (ev) {
116                         sdump('D_CHECKIN','Firing checkin_items_select_callback\n');
117                         var checkin_items = get_list_from_tree_selection( p.checkin_items.paged_tree.tree );
118                         /* grab cover art for selected item? */
119                 }
120         );
121         p.checkin_items.register_flesh_checkin_items_function(
122                 function (treeitem) {
123                         sdump('D_CHECKIN','Firing flesh_checkin_items_function\n');
124                         var record_id = treeitem.getAttribute('record_id'); 
125                         p.checkin_items.map_checkin_items_to_cols( checkins[ record_id ], treeitem );
126                 }
127         );
128         p.checkin_items.register_context_builder(
129                 function (ev) {
130                         sdump('D_CHECKIN','Firing context_builder\n');
131                         empty_widget(p.checkin_items.paged_tree.popup);
132                         var checkin_items = get_list_from_tree_selection( p.checkin_items.paged_tree.tree );
133                         var menuitem;
134
135                         /*** COPY EDITOR ***/
136                         menuitem = p.checkin_items.paged_tree.w.document.createElement('menuitem');
137                         p.checkin_items.paged_tree.popup.appendChild( menuitem );
138                         menuitem.setAttribute('label',getString('circ.context_edit'));
139                         menuitem.addEventListener(
140                                 'command',
141                                 function (ev) {
142                                         for (var i = 0; i < checkin_items.length; i++) {
143                                                 var idx = checkin_items[i].getAttribute('record_id');
144                                                 var copy = checkins[idx].copy;
145                                                 sdump('D_CHECKIN','Firing copy edit context\n');
146                                                 spawn_batch_copy_editor(
147                                                         p.w.app_shell,'new_tab','main_tabbox',{ 
148                                                                 'copy_ids' : [ copy.id() ]
149                                                         }
150                                                 );
151                                         }
152                                 },
153                                 false
154                         );
155
156                         /*** OPAC ***/
157                         menuitem = p.checkin_items.paged_tree.w.document.createElement('menuitem');
158                         p.checkin_items.paged_tree.popup.appendChild( menuitem );
159                         menuitem.setAttribute('label',getString('circ.context_opac'));
160                         menuitem.addEventListener(
161                                 'command',
162                                 function (ev) {
163                                         alert('Not Yet Implemented');
164                                         for (var i = 0; i < checkin_items.length; i++) {
165                                                 var idx = checkin_items[i].getAttribute('record_id');
166                                                 sdump('D_CHECKIN','Firing opac context\n');
167                                         }
168                                 },
169                                 false
170                         );
171                         
172                 }
173         );
174 }
175
176