From be5876214f2b8adc4aa9131ab6b25a8ca330647b Mon Sep 17 00:00:00 2001 From: phasefx Date: Wed, 4 Nov 2009 22:04:57 +0000 Subject: [PATCH] Generic date/timestamp dialog and a change to Shelf Expire Time as an example of how to use it. Need to start plugging it into places like Edit Due Date, etc git-svn-id: svn://svn.open-ils.org/ILS/trunk@14779 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/opac/locale/en-US/lang.dtd | 11 ++ .../staff_client/chrome/content/main/constants.js | 1 + .../staff_client/chrome/content/util/timestamp.js | 136 +++++++++++++++++++++ .../staff_client/chrome/content/util/timestamp.xul | 49 ++++++++ .../server/locale/en-US/circ.properties | 5 +- .../server/locale/en-US/common.properties | 4 + Open-ILS/xul/staff_client/server/patron/holds.js | 38 +++--- 7 files changed, 220 insertions(+), 24 deletions(-) create mode 100644 Open-ILS/xul/staff_client/chrome/content/util/timestamp.js create mode 100644 Open-ILS/xul/staff_client/chrome/content/util/timestamp.xul diff --git a/Open-ILS/web/opac/locale/en-US/lang.dtd b/Open-ILS/web/opac/locale/en-US/lang.dtd index 68792ccfdf..07c1f8af24 100644 --- a/Open-ILS/web/opac/locale/en-US/lang.dtd +++ b/Open-ILS/web/opac/locale/en-US/lang.dtd @@ -2958,3 +2958,14 @@ + + + + + + + + + + + diff --git a/Open-ILS/xul/staff_client/chrome/content/main/constants.js b/Open-ILS/xul/staff_client/chrome/content/main/constants.js index d2911e2a8a..1620d33bd6 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/constants.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/constants.js @@ -361,6 +361,7 @@ const urls = { 'XUL_EDIT_STANDING_PENALTY' : '/xul/server/patron/edit_standing_penalty.xul', 'XUL_STAT_CAT_EDIT' : '/xul/server/admin/stat_cat_editor.xhtml', 'XUL_SURVEY_WIZARD' : 'chrome://open_ils_staff_client/content/admin/survey_wizard.xul', + 'XUL_TIMESTAMP_DIALOG' : '/xul/server/util/timestamp.xul', 'XUL_USER_BUCKETS' : '/xul/server/patron/user_buckets.xul', 'XUL_VERIFY_CREDENTIALS' : '/xul/server/main/verify_credentials.xul', 'XUL_VOLUME_BUCKETS' : '/xul/server/cat/volume_buckets.xul', diff --git a/Open-ILS/xul/staff_client/chrome/content/util/timestamp.js b/Open-ILS/xul/staff_client/chrome/content/util/timestamp.js new file mode 100644 index 0000000000..5b87e5bc5d --- /dev/null +++ b/Open-ILS/xul/staff_client/chrome/content/util/timestamp.js @@ -0,0 +1,136 @@ +var data; var error; var network; var sound; + +function $(id) { return document.getElementById(id); } + +function default_focus() { $('cancel_btn').focus(); } // parent interfaces often call this + +function timestamp_init() { + try { + + commonStrings = $('commonStrings'); + + if (typeof JSAN == 'undefined') { + throw( + commonStrings.getString('common.jsan.missing') + ); + } + + JSAN.errorLevel = "die"; // none, warn, or die + JSAN.addRepository('..'); + + JSAN.use('util.error'); error = new util.error(); + JSAN.use('util.sound'); sound = new util.sound(); + JSAN.use('util.date'); + + $('datepicker').value = xul_param('default_date',{'modal_xulG':true}) || util.date.formatted_date(new Date(),'%F'); + + if (xul_param('title',{'modal_xulG':true})) { $('dialogheader').setAttribute('title',xul_param('title',{'modal_xulG':true})); } + if (xul_param('description',{'modal_xulG':true})) { $('dialogheader').setAttribute('description',xul_param('description',{'modal_xulG':true})); } + + var x = $('msg_area'); + if (x && xul_param('msg',{'modal_xulG':true})) { + var d = document.createElement('description'); + var t = document.createTextNode( xul_param('msg',{'modal_xulG':true}) ); + x.appendChild( d ); + d.appendChild( t ); + } + + if (xul_param('allow_unset',{'modal_xulG':true})) { $('remove_btn').hidden = false; } + + /* set widget behavior */ + $('cancel_btn').addEventListener( + 'command', function() { window.close(); }, false + ); + $('apply_btn').addEventListener( + 'command', + gen_handle_apply(), + false + ); + $('remove_btn').addEventListener( + 'command', + gen_handle_apply({'remove':true}), + false + ); + + $('datepicker').addEventListener( + 'change', + function(ev) { + try { + var check = check_date( ev.target.value ); + if ( ! check.allowed ) { throw( check.reason ); } + $('apply_btn').disabled = false; + } catch(E) { + JSAN.use('util.sound'); var sound = new util.sound(); sound.bad(); + var x = $('err_msg'); + if (x) { + x.setAttribute('value', check.reason); + } + $('apply_btn').disabled = true; + } + dump('util.timestamp.js:date: ' + E + '\n'); + }, + false + ); + + default_focus(); + + } catch(E) { + var err_prefix = 'timestamp.js -> timestamp_init() : '; + if (error) error.standard_unexpected_error_alert(err_prefix,E); else alert(err_prefix + E); + } +} + +function check_date(value) { + if (xul_param('disallow_future_dates',{'modal_xulG':true})) { + if ( ev.target.dateValue > new Date() ) { return { 'allowed' : false, 'reason' : $('commonStrings').getString('staff.util.timestamp_dialog.future_date_disallowed') }; } + } + if (xul_param('disallow_past_dates',{'modal_xulG':true})) { + if ( util.date.check_past('YYYY-MM-DD', ev.target.value) ) { return { 'allowed' : false, 'reason' : $('commonStrings').getString('staff.util.timestamp_dialog.past_date_disallowed') }; } + } + if (xul_param('disallow_today',{'modal_xulG':true})) { + if ( util.date.formatted_date(new Date(),'%F') == value) { return { 'allowed' : false, 'reason' : $('commonStrings').getString('staff.util.timestamp_dialog.today_disallowed') }; } + } + return { 'allowed' : true }; +} + +function gen_handle_apply(params) { + return function handle_apply(ev) { + try { + + if (!params) { params = {}; } + if (params.remove) { + update_modal_xulG( + { + 'timestamp' : null, + 'complete' : 1 + } + ) + window.close(); + } else { + + var dp = $('datepicker'); + var tp = $('timepicker'); + + var check = check_date( dp.value ); + if ( ! check.allowed ) { alert( check.reason ); $('apply_btn').disabled = true; return; } + + var tp_date = tp.dateValue; + var dp_date = dp.dateValue; + tp_date.setFullYear( dp_date.getFullYear() ); + tp_date.setMonth( dp_date.getMonth() ); + tp_date.setDate( dp_date.getDate() ); + + update_modal_xulG( + { + 'timestamp' : util.date.formatted_date(tp_date,'%{iso8601}'), + 'complete' : 1 + } + ) + window.close(); + } + + } catch(E) { + alert('Error in backdate.js, handle_apply(): ' + E); + } + }; +} diff --git a/Open-ILS/xul/staff_client/chrome/content/util/timestamp.xul b/Open-ILS/xul/staff_client/chrome/content/util/timestamp.xul new file mode 100644 index 0000000000..722f76baac --- /dev/null +++ b/Open-ILS/xul/staff_client/chrome/content/util/timestamp.xul @@ -0,0 +1,49 @@ + + + + + + + + + + + + +]> + + + + + + + + + + + + +