Serials: In the holding code mini wizard of the alt serials controls, pre-
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 12 Jan 2011 22:50:16 +0000 (22:50 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 12 Jan 2011 22:50:16 +0000 (22:50 +0000)
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

Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
Open-ILS/web/js/dojo/openils/widget/HoldingCode.js
Open-ILS/web/js/ui/default/serial/subscription/issuance.js
Open-ILS/web/templates/default/serial/subscription/issuance.tt2

index 98b702e..c4b4856 100644 (file)
@@ -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();
index f786460..4722cba 100644 (file)
@@ -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
         }
     );
 }
index d715fb4..75484c5 100644 (file)
@@ -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;
             }
         }
     );
index 1db2ef0..b74df6e 100644 (file)
@@ -5,7 +5,7 @@
         <span dojoType="dijit.form.Button"
             onclick="iss_grid.refresh();">Refresh Grid</span>
         <span dojoType="dijit.form.Button"
-            onclick="iss_grid.showCreateDialog();">New Issuance</span>
+            onclick="iss_grid.showCreatePane();">New Issuance</span>
         <span dojoType="dijit.form.Button"
             onclick="iss_grid.deleteSelected();">Delete Selected</span>
     </div>