From c8c30a7ce0e260fa4816575345229640a3d46ffd Mon Sep 17 00:00:00 2001 From: senator Date: Wed, 12 Jan 2011 22:50:16 +0000 Subject: [PATCH] Serials: In the holding code mini wizard of the alt serials controls, pre- populate any Year, Season, Month or Day fields based on issuance.date_published to reduce the need for redundant user input. git-svn-id: svn://svn.open-ils.org/ILS/trunk@19173 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../web/js/dojo/openils/widget/AutoFieldWidget.js | 10 +++-- Open-ILS/web/js/dojo/openils/widget/HoldingCode.js | 51 +++++++++++++++++++++- .../js/ui/default/serial/subscription/issuance.js | 6 +++ .../default/serial/subscription/issuance.tt2 | 2 +- 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js index 98b702eae..c4b4856f1 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js @@ -184,10 +184,14 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) { if(this.parentNode) // may already be in the "right" place this.parentNode.appendChild(this.widget.domNode); if (this.shove) { - if (this.shove.mode == "update") - this.widget.attr("value", this.widgetValue); - else + if (this.shove.mode == "update") { + if (this.idlField.datatype == "timestamp") + this.widgetValue = openils.Util.timeStampAsDateObj( + this.widgetValue + ); + } else { this.widgetValue = this.shove.create; + } this._widgetLoaded(); } else if (this.widget.attr("value") == null) { this._widgetLoaded(); diff --git a/Open-ILS/web/js/dojo/openils/widget/HoldingCode.js b/Open-ILS/web/js/dojo/openils/widget/HoldingCode.js index f786460d5..4722cba00 100644 --- a/Open-ILS/web/js/dojo/openils/widget/HoldingCode.js +++ b/Open-ILS/web/js/dojo/openils/widget/HoldingCode.js @@ -77,6 +77,7 @@ if (!dojo._hasResource["openils.widget.HoldingCode"]) { dojo.create("td", null, tr) ); input.startup(); + wizard.preset_input_by_date(input, field.caption.toLowerCase()); inputs.push({"subfield": field.subfield, "input": input}); } ); @@ -111,6 +112,30 @@ if (!dojo._hasResource["openils.widget.HoldingCode"]) { dojo.place(table, div, "only"); } + /* Approximate a season value given a date using the same logic as + * OpenILS::Utils::MFHD::Holding::chron_to_date(). + */ + function _loose_season(D) { + var m = D.getMonth() + 1; + var d = D.getDate(); + + if ( + (m == 1 || m == 2) || (m == 12 && d >= 21) || (m == 3 && d < 20) + ) { + return 24; /* MFHD winter */ + } else if ( + (m == 4 || m == 5) || (m == 3 && d >= 20) || (m == 6 && d < 21) + ) { + return 21; /* spring */ + } else if ( + (m == 7 || m == 8) || (m == 6 && d >= 21) || (m == 9 && d < 22) + ) { + return 22; /* summer */ + } else { + return 23; /* autumn */ + } + } + dojo.declare( "openils.widget.HoldingCode", dijit.layout.ContentPane, { "constructor": function(args) { @@ -161,7 +186,31 @@ if (!dojo._hasResource["openils.widget.HoldingCode"]) { "update_scap_selector": function(selector) { this.args.scap_selector = selector; this.attr("value", ""); - } + }, + + "preset_input_by_date": function(input, chron_part) { + try { + input.attr("value", { + /* NOTE: week is specifically not covered. I'm + * not sure there's an acceptably standard way + * to number the weeks in a year. Do we count + * from the week of January 1? Or the first week + * with a day of the week matching our example + * date? Do weeks run Mon-Sun or Sun-Sat? + */ + "year": function(d) { return d.getFullYear(); }, + "season": function(d) { return _loose_season(d); }, + "month": function(d) { return d.getMonth() + 1; }, + "day": function(d) { return d.getDate(); }, + "hour": function(d) { return d.getHours(); }, + }[chron_part](this.date_widget.attr("value")) + ); + } catch (E) { + ; /* Oh well; can't win them all. */ + } + }, + + "date_widget": null } ); } diff --git a/Open-ILS/web/js/ui/default/serial/subscription/issuance.js b/Open-ILS/web/js/ui/default/serial/subscription/issuance.js index d715fb471..75484c52d 100644 --- a/Open-ILS/web/js/ui/default/serial/subscription/issuance.js +++ b/Open-ILS/web/js/ui/default/serial/subscription/issuance.js @@ -41,6 +41,12 @@ function fresh_scap_selector(grid) { }; grid.overrideEditWidgets.holding_code.startup(); } + + grid.overrideEditWidgets.date_published = + new dijit.form.DateTextBox(); + grid.overrideEditWidgets.date_published.shove = {}; + grid.overrideEditWidgets.holding_code.date_widget = + grid.overrideEditWidgets.date_published; } } ); diff --git a/Open-ILS/web/templates/default/serial/subscription/issuance.tt2 b/Open-ILS/web/templates/default/serial/subscription/issuance.tt2 index 1db2ef0e3..b74df6e4b 100644 --- a/Open-ILS/web/templates/default/serial/subscription/issuance.tt2 +++ b/Open-ILS/web/templates/default/serial/subscription/issuance.tt2 @@ -5,7 +5,7 @@ Refresh Grid New Issuance + onclick="iss_grid.showCreatePane();">New Issuance Delete Selected -- 2.11.0