LP#1329503 propagate 'in list' values for editing
authorBill Erickson <berick@esilibrary.com>
Thu, 7 Aug 2014 17:16:36 +0000 (13:16 -0400)
committerBen Shum <bshum@biblio.org>
Fri, 8 Aug 2014 01:51:58 +0000 (21:51 -0400)
For example, ensure a previously selected list of copy locations are
propagated into the selected values list during report editing.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/web/reports/oils_rpt_param_editor.js
Open-ILS/web/reports/oils_rpt_report_editor.js
Open-ILS/web/reports/oils_rpt_widget.js

index 40acd1b..e66a986 100644 (file)
@@ -178,6 +178,7 @@ oilsRptParamEditor.prototype.buildWidget = function(param, node, fromTemplate) {
                widgetArgs.class = cls;
                widgetArgs.field = field;
                widgetArgs.column = param.column.colname;
+        widgetArgs.async = true;
        }
 
        switch(cls) {
index 4cbebcf..5bc5e89 100644 (file)
@@ -122,7 +122,7 @@ oils_rpt_editor_pivot_data
             DOM.oils_rpt_format_html.checked = run.html_format() == 't';
             DOM.oils_rpt_format_chart_bar.checked = run.chart_bar() == 't';
             DOM.oils_rpt_format_chart_line.checked = run.chart_line() == 't';
-            DOM.oils_rpt_param_editor_sched_email = run.email();
+            DOM.oils_rpt_param_editor_sched_email.value = run.email();
 
             if (run.run_time()) {
                 DOM.oils_rpt_report_editor_schedule.checked = true;
index f4f5263..2d617ef 100644 (file)
@@ -4,8 +4,10 @@
        --------------------------------------------------------------------- */
 function oilsRptSetWidget(args) {
        this.node = args.node;
+    this.seedValue = args.value;
        this.inputWidget = new args.inputWidget(args);
     this.readonly = Boolean(args.readonly);
+    this.asyncInput = args.async;
        this.dest = elem('select',
                {multiple:'multiple','class':'oils_rpt_small_info_selector'});
     this.dest.disabled = this.readonly;
@@ -26,16 +28,23 @@ oilsRptSetWidget.prototype.draw = function() {
        this.delButton.onclick = function(){obj.removeSelected()};
 
        removeChildren(this.node);
-       this.inputWidget.draw();
+
+    var this_ = this;
+    var post_draw = function() {
+        // propagate the values from the input widget into the our display.
+        if (this_.inputWidget.seedValue)
+            this_.addButton.onclick();
+    }
+
+       this.inputWidget.draw(post_draw);
        this.node.appendChild(elem('br'))
        this.node.appendChild(this.addButton);
        this.node.appendChild(this.delButton);
        this.node.appendChild(elem('br'))
        this.node.appendChild(this.dest);
 
-    // propagate the values from the input widget into the our display.
-    if (this.inputWidget.seedValue)
-           this.addButton.onclick();
+    if (!this.asyncInput) post_draw();
+
 }
 
 oilsRptSetWidget.prototype.addDisplayItems = function(list) {
@@ -574,12 +583,13 @@ function oilsRptRemoteWidget(args) {
        this.class      = args.class;
        this.field      = args.field;
        this.column = args.column;
+    this.seedValue = args.value;
        this.source = elem('select',
                {multiple:'multiple','class':'oils_rpt_small_info_selector'});
     this.source.disabled = Boolean(args.readonly);
 }
 
-oilsRptRemoteWidget.prototype.draw = function() {
+oilsRptRemoteWidget.prototype.draw = function(callback) {
        var orgcol;
        iterate(oilsIDL[this.class].fields,
                function(i) {
@@ -600,7 +610,20 @@ oilsRptRemoteWidget.prototype.draw = function() {
 
        var obj = this;
        this.node.appendChild(this.source);
-       req.callback(function(r){obj.render(r.getResultObject())});
+       req.callback(function(r){
+        // render selects values from seed data if necessary
+        obj.render(r.getResultObject());
+        if (callback) {
+            // presence of a callback suggests there is a container widget
+            // (e.g. SetWidget) for tracking our values.  Callback lets 
+            // the container extract the selected values, then we deselect
+            // in the input widget (us) since it's redundant.
+            callback();
+            dojo.forEach(obj.source.options, function(o) {
+                o.selected = false;
+            });
+        }
+    });
        req.send();
 }
 
@@ -618,7 +641,13 @@ oilsRptRemoteWidget.prototype.render = function(objs) {
                var label = obj[this.field.selector]();
                var value = obj[this.column]();
                _debug("inserted remote object "+label + ' : ' + value);
-               insertSelectorVal(this.source, -1, label, value);
+               var opt = insertSelectorVal(this.source, -1, label, value);
+        if (this.seedValue && (
+                this.seedValue.indexOf(Number(value)) > -1 
+                || this.seedValue.indexOf(''+value) > -1
+            )) {
+            opt.selected = true;
+        }
        }
 }