return new Date(y,mo-1,d,h,mi,s);
}
-util.date.formatted_date = function (date,format) {
+util.date.formatted_date = function (orig_date,format) {
+
+ var _date = orig_date;
+
+ try {
+
// pass in a Date object or epoch seconds or a postgres style date string (2005-07-19 10:38:25.211964-04)
- if (typeof(date) == 'string') {
- if (date.match(/:/) || date.match(/-/)) {
- date = util.date.db_date2Date(date);
+ if (typeof(_date) == 'string') {
+ if (_date.match(/:/) || _date.match(/-/)) {
+ _date = util.date.db_date2Date(_date);
} else {
- date = new Date( Number( date + '000' ) );
+ _date = new Date( Number( _date + '000' ) );
}
- } else if (typeof(date) == 'undefined') {
- date = new Date( Number( date + '000' ) );
- } else if (date == null) {
+ } else if (typeof(_date) == 'number') {
+ _date = new Date( _date * 1000 );
+ }
+
+ if (_date == null) {
return '';
}
- var mm = date.getMonth() + 1; mm = mm.toString(); if (mm.length == 1) mm = '0' +mm;
- var dd = date.getDate().toString(); if (dd.length == 1) dd = '0' +dd;
- var yyyy = date.getFullYear().toString();
+ var mm = _date.getMonth() + 1; mm = mm.toString(); if (mm.length == 1) mm = '0' +mm;
+ var dd = _date.getDate().toString(); if (dd.length == 1) dd = '0' +dd;
+ var yyyy = _date.getFullYear().toString();
var yy = yyyy.substr(2);
- var H = date.getHours(); H = H.toString(); if (H.length == 1) H = '0' + H;
- var I = date.getHours(); if (I > 12) I -= 12; I = I.toString();
- var M = date.getMinutes(); M = M.toString(); if (M.length == 1) M = '0' + M;
- var sec = date.getSeconds(); sec = sec.toString(); if (sec.length == 1) sec = '0' + sec;
+ var H = _date.getHours(); H = H.toString(); if (H.length == 1) H = '0' + H;
+ var I = _date.getHours(); if (I > 12) I -= 12; I = I.toString();
+ var M = _date.getMinutes(); M = M.toString(); if (M.length == 1) M = '0' + M;
+ var sec = _date.getSeconds(); sec = sec.toString(); if (sec.length == 1) sec = '0' + sec;
var s = format;
if (s == '') { s = '%F %H:%M'; }
- if (typeof date.iso8601Format != 'function') {
+ if (typeof _date.iso8601Format != 'function') {
var js = JSAN._loadJSFromUrl( urls.isodate_lib );
try { eval( js ); } catch(E) { alert('Problem loading ISO8601 date extension:' + E); }
}
- if (typeof date.iso8601Format == 'function') {
- s = s.replace( /%\{iso8601\}/g, date.iso8601Format("YMDHMS") );
+ if (typeof _date.iso8601Format == 'function') {
+ s = s.replace( /%\{iso8601\}/g, _date.iso8601Format("YMDHMS") );
}
s = s.replace( /%m/g, mm );
s = s.replace( /%d/g, dd );
s = s.replace( /%M/g, M );
s = s.replace( /%s/g, sec );
return s;
+
+ } catch(E) {
+ alert('Error in util.date.formatted_date:\ntypeof orig_date = ' + typeof orig_date + ' orig_date = ' + orig_date + '\ntypeof _date = ' + typeof _date + ' _date = ' + _date + '\nformat = ' + format + '\n' + E);
+ }
}
util.date.interval_to_seconds = function ( $interval ) {
return $amount;
}
+/*
+ Lifted from /opac/common/js/util.js
+
+ builds a JS date object with the given info. The given data
+ has to be valid (e.g. months == 30 is not valid). Returns NULL on
+ invalid date
+ Months are 1-12 (unlike the JS date object)
+*/
+
+util.date.buildDate = function ( year, month, day, hours, minutes, seconds ) {
+
+ if(!year) year = 0;
+ if(!month) month = 1;
+ if(!day) day = 1;
+ if(!hours) hours = 0;
+ if(!minutes) minutes = 0;
+ if(!seconds) seconds = 0;
+
+ var d = new Date(year, month - 1, day, hours, minutes, seconds);
+ //alert('util.date.buildDate\nyear='+year+' month='+month+' day='+day+' hours='+hours+' minutes='+minutes+' seconds='+seconds+'\nd = ' + d);
+
+ if(
+ (d.getYear() + 1900) == year &&
+ d.getMonth() == (month - 1) &&
+ d.getDate() == new Number(day) &&
+ d.getHours() == new Number(hours) &&
+ d.getMinutes() == new Number(minutes) &&
+ d.getSeconds() == new Number(seconds) ) {
+ return d;
+ }
+
+ return null;
+}
+
+
dump('exiting util/date.js\n');
admin.transit_list = function (params) {
JSAN.use('util.error'); this.error = new util.error();
- JSAN.use('util.network'); this.network = new util.network();
- JSAN.use('util.date');
+ JSAN.use('util.network'); this.network = new util.network(); JSAN.use('util.file');
+ JSAN.use('util.date'); JSAN.use('util.widgets'); JSAN.use('util.fm_utils'); JSAN.use('util.functional');
JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
}
var obj = this;
+ var x = document.getElementById('libmenu_placeholder');
+ util.widgets.remove_children( x );
+
+ var file; var list_data; var ml;
+
+ file = new util.file('offline_ou_list');
+ if (file._file.exists()) {
+ list_data = file.get_object(); file.close();
+ ml = util.widgets.make_menulist( list_data[0], list_data[1] );
+ ml.setAttribute('id','libmenu'); document.getElementById('libmenu_placeholder').appendChild(ml);
+ ml.addEventListener(
+ 'command',
+ function(ev) {
+ var file = new util.file('transit_list_prefs.'+obj.data.server_unadorned);
+ util.widgets.save_attributes(file, { 'libmenu' : [ 'value' ] });
+ },
+ false
+ );
+ } else {
+ throw('Missing library list.\n');
+ }
+
+ file = new util.file('transit_list_prefs.'+obj.data.server_unadorned);
+ util.widgets.load_attributes(file);
+ ml.value = ml.getAttribute('value');
+ if (! ml.value) {
+ ml.value = obj.data.list.au[0].ws_ou();
+ ml.setAttribute('value',ml.value);
+ }
+
+ x.appendChild( ml );
+
obj.list_init();
obj.controller_init();
- obj.kick_off();
+ //obj.kick_off();
+
+ },
+
+ 'sdate' : null,
+ 'edate' : null,
+
+ 'handle_date' : function(value,end_of_day) {
+ try {
+ var _date = null;
+
+ /* The Beginning */
+ if (value.match(/The Beginning/)) {
+ _date = new Date(); _date.setTime( 0 );
+ }
+
+ /* Today */
+ if (value.match(/^Today$/i)) {
+ _date = new Date(); _date = util.date.buildDate( _date.getFullYear(), _date.getMonth()+1, _date.getDate(), 0, 0, 0); // morning
+ }
+
+ /* handle YYYY-MM-DD */
+ var _string = value.match(/(\d\d\d\d)[\-\/](\d\d?)[\-\/](\d\d?)/);
+ if (_string) {
+ if (util.date.check('YYYY-MM-DD',_string[1]+'-'+_string[2]+'-'+_string[3])) {
+ _date = util.date.buildDate( _string[1], _string[2], _string[3], 0, 0, 0);
+ } else {
+ alert('Invalid Date (' + _string + '), setting to Today');
+ _date = new Date(); _date = util.date.buildDate( _date.getFullYear(), _date.getMonth()+1, _date.getDate(), 0, 0, 0); // morning
+ }
+ }
+ /* handle relative dates */
+ var interval = value.match(/Today \- (.+)/);
+ if (interval) {
+ _date = new Date(); _date = util.date.buildDate( _date.getFullYear(), _date.getMonth()+1, _date.getDate(), 0, 0, 0); // morning
+ _date.setTime( _date.getTime() - util.date.interval_to_seconds(interval[1])*1000 );
+ }
+
+ if (! util.date.check('YYYY-MM-DD',util.date.formatted_date(_date,"%F")) ) {
+ alert('Invalid Date (' + _date + ',' + util.date.formatted_date(_date,"%F") + '), setting to Today');
+ _date = new Date(); _date = util.date.buildDate( _date.getFullYear(), _date.getMonth()+1, _date.getDate(), 0, 0, 0); // morning
+ }
+
+ if (end_of_day) { // This just handles calendar days.. if we wanted to support (Today-1 month,Today-1 month), I'll need a better library, or a query to postgres
+ _date.setTime( _date.getTime() + util.date.interval_to_seconds('1 day')*1000 - util.date.interval_to_seconds('1 second')*1000 );
+ }
+
+ return util.date.formatted_date(_date,'%{iso8601}');
+ } catch(E) {
+ try { obj.error.standard_unexpected_error_alert('processing date',E); } catch(F) { alert(E); }
+ _date = new Date(); _date = util.date.buildDate( _date.getFullYear(), _date.getMonth()+1, _date.getDate(), 0, 0, 0); // morning
+ return util.date.formatted_date(_date,'%{iso8601}');
+ }
},
'kick_off' : function() {
var obj = this;
try {
- obj.network.simple_request('FM_ATC_RETRIEVE_VIA_AOU',[ ses(), obj.data.list.au[ 0 ].ws_ou() ],
+ obj.list.clear();
+ obj.sdate = obj.handle_date( document.getElementById('sdate').value, false );
+ obj.edate = obj.handle_date( document.getElementById('edate').value, true );
+ var sdate; var edate;
+ if (obj.sdate < obj.edate) {
+ sdate = obj.sdate; edate = obj.edate;
+ } else {
+ sdate = obj.edate; edate = obj.sdate;
+ }
+ obj.network.simple_request('FM_ATC_RETRIEVE_VIA_AOU',[ ses(), /*obj.data.list.au[ 0 ].ws_ou()*/ document.getElementById('libmenu').value, sdate, edate ],
function(req) {
try {
var robj = req.getResultObject();
return function() {
switch(which_list) {
case 0: obj.list.append( { 'row' : { 'my' : { 'transit_id' : id } }, 'no_auto_select' : true } ); break;
- case 1: obj.list2.append( { 'row' : { 'my' : { 'transit_id' : id } }, 'no_auto_select' : true } ); break;
+ case 1: obj.list.append( { 'row' : { 'my' : { 'transit_id' : id } }, 'no_auto_select' : true } ); break;
}
};
}
- var rows = []; var rows2 = [];
+ var rows = [];
- for (var i = 0; i < robj.from.length; i++) {
+ if (document.getElementById('transit_direction').value=='transit_from') for (var i = 0; i < robj.from.length; i++) {
//get_transit(robj.from[i], 0);
rows.push( gen_list_append(robj.from[i],0) );
}
- for (var i = 0; i < robj.to.length; i++) {
+ if (document.getElementById('transit_direction').value=='transit_to') for (var i = 0; i < robj.to.length; i++) {
//get_transit(robj.to[i], 1);
- rows2.push( gen_list_append(robj.to[i],1) );
+ rows.push( gen_list_append(robj.to[i],1) );
}
- exec.chain( rows );
- exec2.chain( rows2 );
+ if (rows.length > 0) {
+ exec.chain( rows );
+ } else {
+ alert('No matching transits.');
+ }
} catch(E) {
try { obj.error.standard_unexpected_error_alert('retrieving transits',E); } catch(F) { alert(E); }
var obj = this;
obj.selection_list = [];
- obj.selection_list2 = [];
JSAN.use('circ.util');
var columns = circ.util.transit_columns(
);
JSAN.use('util.list');
- obj.list = new util.list('transit_from');
+ obj.list = new util.list('transit_list');
obj.list.init(
{
'columns' : columns,
},
}
);
- obj.list2 = new util.list('transit_to');
- obj.list2.init(
- {
- 'columns' : columns,
- 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
- 'retrieve_row' : function(params) {
- var row = params.row;
- try {
- obj.get_transit_and_hold_and_run_func(
- row.my.transit_id,
- function(transit,hold) { return obj.get_rest_of_row_given_transit_and_hold(params,transit,hold); }
- );
- } catch(E) {
- try { obj.error.standard_unexpected_error_alert('retrieving row',E); } catch(F) { alert(E); }
- }
- },
- 'on_select' : function(ev) {
- try {
- JSAN.use('util.functional');
- var sel = obj.list2.retrieve_selection();
- obj.selection_list2 = util.functional.map_list(
- sel,
- function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
- );
- obj.error.sdump('D_TRACE','admin.transit_list: selection list2 = ' + js2JSON(obj.selection_list2) );
- if (obj.selection_list2.length == 0) {
- obj.controller.view.sel_edit2.setAttribute('disabled','true');
- obj.controller.view.sel_opac2.setAttribute('disabled','true');
- obj.controller.view.sel_bucket2.setAttribute('disabled','true');
- obj.controller.view.sel_copy_details2.setAttribute('disabled','true');
- obj.controller.view.sel_patron2.setAttribute('disabled','true');
- obj.controller.view.sel_transit_abort2.setAttribute('disabled','true');
- obj.controller.view.sel_clip2.setAttribute('disabled','true');
- } else {
- obj.controller.view.sel_edit2.setAttribute('disabled','false');
- obj.controller.view.sel_opac2.setAttribute('disabled','false');
- obj.controller.view.sel_patron2.setAttribute('disabled','false');
- obj.controller.view.sel_bucket2.setAttribute('disabled','false');
- obj.controller.view.sel_copy_details2.setAttribute('disabled','false');
- obj.controller.view.sel_transit_abort2.setAttribute('disabled','false');
- obj.controller.view.sel_clip2.setAttribute('disabled','false');
- }
- } catch(E) {
- alert('FIXME: ' + E);
- }
- },
- }
- );
-
},
'get_transit_and_hold_and_run_func' : function (transit_id,do_this) {
try {
var r_ahr = req3.getResultObject();
if (typeof r_ahr.ilsevent != 'undefined') throw(r_ahr);
- if (instanceOf(r_ahr[0],ahr)) {
- do_this(r_atc,r_ahr[0]);
+ if (r_ahr.length == 0) {
+ try { obj.error.standard_unexpected_error_alert('Empty array returned by hold retrieve. retrieving hold id = ' + r_atc.hold() + ' for transit id = ' + transit_id,E); } catch(F) { alert(E); }
+ do_this(r_atc,null);
} else {
- throw(r_ahr);
+ if (instanceOf(r_ahr[0],ahr)) {
+ do_this(r_atc,r_ahr[0]);
+ } else {
+ throw(r_ahr);
+ }
}
} catch(E) {
try { obj.error.standard_unexpected_error_alert('retrieving hold id = ' + r_atc.hold() + ' for transit id = ' + transit_id,E); } catch(F) { alert(E); }
+ do_this(r_atc,null);
}
}
);
{
'control_map' : {
'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
- 'save_columns2' : [ [ 'command' ], function() { obj.list2.save_columns(); } ],
'sel_clip' : [ ['command'], function() { obj.list.clipboard(); } ],
- 'sel_clip2' : [ ['command'], function() { obj.list2.clipboard(); } ],
'sel_edit' : [ ['command'], function() { try { obj.spawn_copy_editor(0); } catch(E) { alert(E); } } ],
- 'sel_edit2' : [ ['command'], function() { try { obj.spawn_copy_editor(1); } catch(E) { alert(E); } } ],
'sel_opac' : [ ['command'], function() { JSAN.use('cat.util'); cat.util.show_in_opac(obj.selection_list); } ],
- 'sel_opac2' : [ ['command'], function() { JSAN.use('cat.util'); cat.util.show_in_opac(obj.selection_list2); } ],
'sel_transit_abort' : [ ['command'], function() { JSAN.use('circ.util'); circ.util.abort_transits(obj.selection_list); } ],
- 'sel_transit_abort2' : [ ['command'], function() { JSAN.use('circ.util'); circ.util.abort_transits(obj.selection_list2); } ],
'sel_patron' : [ ['command'], function() { JSAN.use('circ.util'); circ.util.show_last_few_circs(obj.selection_list); } ],
- 'sel_patron2' : [ ['command'], function() { JSAN.use('circ.util'); circ.util.show_last_few_circs(obj.selection_list2); } ],
'sel_copy_details' : [ ['command'], function() { JSAN.use('circ.util'); for (var i = 0; i < obj.selection_list.length; i++) { circ.util.show_copy_details( obj.selection_list[i].copy_id ); } } ],
- 'sel_copy_details2' : [ ['command'], function() { JSAN.use('circ.util'); for (var i = 0; i < obj.selection_list2.length; i++) { circ.util.show_copy_details( obj.selection_list2[i].copy_id ); } } ],
'sel_bucket' : [ ['command'], function() { JSAN.use('cat.util'); cat.util.add_copies_to_bucket(obj.selection_list); } ],
- 'sel_bucket2' : [ ['command'], function() { JSAN.use('cat.util'); cat.util.add_copies_to_bucket(obj.selection_list2); } ],
'cmd_print_list' : [ ['command'], function() { obj.print_list(0); } ],
- 'cmd_print_list2' : [ ['command'], function() { obj.print_list(1); } ],
+ 'cmd_kick_off' : [ ['command'], function(ev) { ev.target.disabled = true; obj.kick_off(); } ],
+ 'sdate' : [ ['change'], function(ev) { ev.target.value = obj.handle_date(ev.target.value,false); obj.sdate = ev.target.value; /*alert('obj.sdate='+obj.sdate);*/ } ],
+ 'edate' : [ ['change'], function(ev) { ev.target.value = obj.handle_date(ev.target.value,true); obj.edate = ev.target.value; /*alert('obj.edate='+obj.edate);*/ } ],
}
}
);
</script>
<vbox flex="1" class="my_overflow">
+ <hbox>
+ <groupbox id="lib_hbox">
+ <caption label="Transit Library"/>
+ <hbox>
+ <menulist id="transit_direction">
+ <menupopup>
+ <menuitem label="Transit to" value="transit_to" selected="true"/>
+ <menuitem label="Transit from" value="transit_from" />
+ </menupopup>
+ </menulist>
+ <hbox id="libmenu_placeholder"/>
+ </hbox>
+ </groupbox>
+ <groupbox id="date_hbox">
+ <caption label="Transit Date falls between"/>
+ <hbox>
+ <menulist id="sdate" editable="true">
+ <menupopup>
+ <menuitem label="Today" selected="true"/>
+ <menuitem label="Today - 7 days" />
+ <menuitem label="Today - 14 days" />
+ <menuitem label="Today - 21 days" />
+ <menuitem label="Today - 30 days" />
+ <menuitem label="The Beginning" />
+ </menupopup>
+ </menulist>
+ <menulist id="edate" editable="true">
+ <menupopup>
+ <menuitem label="Today" selected="true"/>
+ <menuitem label="Today - 7 days" />
+ <menuitem label="Today - 14 days" />
+ <menuitem label="Today - 21 days" />
+ <menuitem label="Today - 30 days" />
+ </menupopup>
+ </menulist>
+ </hbox>
+ </groupbox>
+ <spacer flex="1"/>
+ <button label="Retrieve Transits" accesskey="T" command="cmd_kick_off"/>
+ </hbox>
+
<groupbox flex="1">
- <caption label="Outgoing Transits" class="shrinkable_groupbox"/>
+ <caption label="Transits" />
<hbox>
<button label="Print Transits" command="cmd_print_list" />
<spacer flex="1"/>
<menubar>
- <menu label="Actions for Selected Items" accesskey="S">
+ <menu label="Actions for Selected Transits" accesskey="S">
<menupopup>
<menuitem command="sel_clip" label="Copy to Clipboard" accesskey="C" />
<menuitem command="sel_bucket" label="Add to Item Bucket" accesskey="A"/>
</menu>
</menubar>
</hbox>
- <tree id="transit_from" flex="1" enableColumnDrag="true" context="transit_list_actions"/>
- </groupbox>
- <splitter><grippy/></splitter>
- <groupbox flex="1">
- <caption label="Incoming Transits" class="shrinkable_groupbox"/>
- <hbox>
- <button label="Print Transits" command="cmd_print_list2" />
- <spacer flex="1"/>
- <menubar>
- <menu label="Actions for Selected Items" accesskey="S">
- <menupopup>
- <menuitem command="sel_clip2" label="Copy to Clipboard" accesskey="C" />
- <menuitem command="sel_bucket2" label="Add to Item Bucket" accesskey="A"/>
- <menuitem command="sel_opac2" label="Show in Catalog" accesskey="S" />
- <menuitem command="sel_copy_details2" label="Show Item Details" accesskey="I" />
- <menuitem command="sel_patron2" label="Show Last Few Circulations" accesskey="L"/>
- <menuseparator />
- <menuitem command="sel_edit2" label="Edit Item Attributes" accesskey="E" />
- <menuseparator />
- <menuitem command="save_columns2" label="Save Columns"/>
- </menupopup>
- </menu>
- </menubar>
- </hbox>
-
- <tree id="transit_to" flex="1" enableColumnDrag="true" context="transit_list_actions2"/>
+ <tree id="transit_list" flex="1" enableColumnDrag="true" context="transit_list_actions"/>
</groupbox>
</vbox>
<menuseparator/>
<menuitem command="save_columns" label="Save Columns"/>
</popup>
- <popup id="transit_list_actions2" position="at_pointer">
- <menuitem command="sel_clip2" label="Copy to Clipboard" accesskey="C" />
- <menuitem command="sel_bucket2" label="Add to Item Bucket" accesskey="A"/>
- <menuitem command="sel_opac2" label="Show in Catalog" accesskey="S" />
- <menuitem command="sel_copy_details2" label="Show Item Details" accesskey="I" />
- <menuitem command="sel_patron2" label="Show Last Few Circulations" accesskey="L"/>
- <menuseparator/>
- <menuitem command="sel_edit2" label="Edit Item Attributes" accesskey="E" />
- <menuseparator/>
- <menuitem command="save_columns2" label="Save Columns"/>
- </popup>
-
</popupset>
<commandset id="transit_list_cmds">
- <command id="cmd_print_list" /> <command id="cmd_print_list2" />
- <command id="save_columns" /> <command id="save_columns2" />
- <command id="sel_copy_details" disabled="true"/> <command id="sel_copy_details2" disabled="true"/>
- <command id="sel_patron" disabled="true"/> <command id="sel_patron2" disabled="true"/>
- <command id="sel_edit" disabled="true"/> <command id="sel_edit2" disabled="true"/>
- <command id="sel_opac" disabled="true"/> <command id="sel_opac2" disabled="true"/>
- <command id="sel_bucket" disabled="true"/> <command id="sel_bucket2" disabled="true"/>
- <command id="sel_transit_abort" disabled="true"/> <command id="sel_transit_abort2" disabled="true"/>
- <command id="sel_clip" disabled="true"/> <command id="sel_clip2" disabled="true"/>
+ <command id="cmd_print_list" />
+ <command id="save_columns" />
+ <command id="sel_copy_details" disabled="true"/>
+ <command id="sel_patron" disabled="true"/>
+ <command id="sel_edit" disabled="true"/>
+ <command id="sel_opac" disabled="true"/>
+ <command id="sel_bucket" disabled="true"/>
+ <command id="sel_transit_abort" disabled="true"/>
+ <command id="sel_clip" disabled="true"/>
+ <command id="cmd_kick_off"/>
</commandset>
</window>