LP#1329503 View Edit Reports
authorBill Erickson <berick@esilibrary.com>
Wed, 18 Jun 2014 14:08:14 +0000 (10:08 -0400)
committerBen Shum <bshum@biblio.org>
Fri, 8 Aug 2014 01:51:57 +0000 (21:51 -0400)
Alongside each report in the Reports folder view there are two new
links, one for viewing (read-only) and one for editing.  After changing
a report, the user has the option to save the modified report or create
a new report with the new values, in effect cloning the original report.

When saving a changed report, if a pending report run exists, the user
will be warned of this and asked if they would prefer to modify the
scheduled report or to instead save the changed values as a new report,
leaving the original report intact.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Signed-off-by: Ben Shum <bshum@biblio.org>
13 files changed:
Open-ILS/web/js/dojo/openils/reports/nls/reports.js
Open-ILS/web/opac/common/js/fm_table_conf.js
Open-ILS/web/opac/common/js/utils.js
Open-ILS/web/opac/locale/en-US/reports.dtd
Open-ILS/web/reports/oils_rpt.css
Open-ILS/web/reports/oils_rpt_editor.xhtml
Open-ILS/web/reports/oils_rpt_folder_window.js
Open-ILS/web/reports/oils_rpt_folder_window.xhtml
Open-ILS/web/reports/oils_rpt_folders.js
Open-ILS/web/reports/oils_rpt_param_editor.js
Open-ILS/web/reports/oils_rpt_report_editor.js
Open-ILS/web/reports/oils_rpt_utils.js
Open-ILS/web/reports/oils_rpt_widget.js

index 1ae57f6..17de210 100644 (file)
@@ -45,6 +45,7 @@
        "REPORT_EDITOR_OUTPUT_FOLDERS": "Output Folders",
        "REPORT_EDITOR_PROVIDE_FOLDER_ALERT": "Please provide a report folder",
        "REPORT_EDITOR_ENTER_NAME_ALERT": "Please enter a report name",
+       "REPORT_EDITOR_ENTER_NEW_NAME_ALERT": "Please change the report name",
        "REPORT_EDITOR_INVALID_DATE_ALERT": "invalid start date -  YYYY-MM-DD",
        "REPORT_EDITOR_PROVIDE_OUTPUT_ALERT": "Please provide an output folder",
        
index 41ab3f4..948fb65 100644 (file)
@@ -98,8 +98,26 @@ var FM_TABLE_DISPLAY = {
                        'recur',
                        'recurrence',
                        'owner',
+            'edit',
                ],
-               sortdata : [ 'name', 1 ]
+               sortdata : [ 'name', 1 ],
+        calculate : {
+            'edit' : function(r) {
+                // DOM pulled from oils_rpt_folder_window.xhtml
+                var node = dojo.byId(
+                    'oils_rpt_view_edit_report_links').cloneNode(true);
+                dojo.removeClass(node, 'hide_me');
+                var view = dojo.query('[name=view]', node)[0];
+                var edit = dojo.query('[name=edit]', node)[0];
+                view.onclick = function() {oilsRptViewReport(r); return false};
+                if (PERMS.RUN_REPORTS == -1) {
+                    node.removeChild(edit);
+                } else {
+                    edit.onclick = function() {oilsRptEditReport(r); return false};
+                }
+                return node;
+            }
+        }
        },
        'rt' : {
                name : 'name',
index dae8ef2..d2b2feb 100644 (file)
@@ -678,9 +678,9 @@ function debugFMObject(obj) {
                var key = keys[i];
                while( key.length < 12 ) key += ' ';
                var val = obj[keys[i]]();
-               if( typeof val == 'object' ) {
+               if( typeof val == 'object' && val !== null ) {
                        _debug(key+' :=\n');
-                       _debugFMObject(val);
+                       debugFMObject(val);
                } else {
                        _debug(key+' = ' +val);
                }
index 367e68c..85fc17d 100644 (file)
 <!ENTITY reports.oils_rpt_editor.noon "Noon">
 <!ENTITY reports.oils_rpt_editor.storage_folder_for_output "Choose a folder to store this report's output:">
 <!ENTITY reports.oils_rpt_editor.save_report "Save Report">
+<!ENTITY reports.oils_rpt_editor.apply_changes "Apply Changes">
+<!ENTITY reports.oils_rpt_editor.save_report_new "Save As New">
+<!ENTITY reports.oils_rpt_editor.confirm_sched "Changes will be applied to pending reports that have not yet run. Do you want to continue with modifying those pending reports?">
+<!ENTITY reports.oils_rpt_editor.cancel "Cancel">
+<!ENTITY reports.oils_rpt_editor.exit_report "Return">
 <!ENTITY reports.oils_rpt_editor.empty_parameter "One or more of the user-defined parameters has been left empty. Please fill in all fields.">
 <!ENTITY reports.oils_rpt_editor.same_name "There is already a report in this folder with the given name.">
 
 <!ENTITY reports.oils_rpt_folder_window.delete_template "Delete selected template(s)">
 <!ENTITY reports.oils_rpt_folder_window.clone_report "Clone report">
 <!ENTITY reports.oils_rpt_folder_window.schedule_report "Schedule report">
+<!ENTITY reports.oils_rpt_folder_window.view_report "View">
+<!ENTITY reports.oils_rpt_folder_window.edit_report "Edit">
 <!ENTITY reports.oils_rpt_folder_window.delete_reports "Delete selected report(s)">
 <!ENTITY reports.oils_rpt_folder_window.view_report_output "View report output">
 <!ENTITY reports.oils_rpt_folder_window.delete_output "Delete selected output(s)">
index 5120958..3fde850 100644 (file)
@@ -325,3 +325,12 @@ button:disabled {
     padding-left: 5px;
 }
 
+#oils_rpt_editor_sched_confirm {
+    margin-top: 10px;
+}
+#oils_rpt_editor_sched_confirm > div {
+    padding: 10px;
+}
+#oils_rpt_editor_sched_confirm:first-child {
+    font-size: 110%;
+}
index 2c0b911..c0e4449 100644 (file)
 
                        <tr>
                                <td colspan='2'>
-                                       <input id='oils_rpt_report_editor_save' type='submit' value='&reports.oils_rpt_editor.save_report;'/>
+                                       <input id='oils_rpt_report_editor_save' style='margin-right:10px;'
+                        type='submit' value='&reports.oils_rpt_editor.save_report;'/>
+
+                                       <input id='oils_rpt_report_editor_save_new' style='margin-right:10px;'
+                        type='submit' value='&reports.oils_rpt_editor.save_report_new;'/>
+
+                    <!-- use input/submit instead of <button> for consistent styling -->
+                                       <input id='oils_rpt_report_editor_exit' style='margin-right:10px;'
+                        type='submit' value='&reports.oils_rpt_editor.exit_report;'/>
+
+                                       <input id='oils_rpt_report_editor_cancel' style='margin-right:10px;'
+                        type='submit' value='&reports.oils_rpt_editor.cancel;'/>
                                </td>
                        </tr>
 
                </tbody>
        </table>
 
+    <div id='oils_rpt_editor_sched_confirm' style='width:100%' class='hide_me'>
+        <div>&reports.oils_rpt_editor.confirm_sched;</div>
+        <div>
+            <!-- use input/submit instead of <button> for consistent styling -->
+            <input id='oils_rpt_report_editor_sched_apply' style='margin-right:10px;'
+                type='submit' value='&reports.oils_rpt_editor.apply_changes;'/>
+
+            <input id='oils_rpt_report_editor_sched_asnew' style='margin-right:10px;'
+                type='submit' value='&reports.oils_rpt_editor.save_report_new;'/>
+
+            <input id='oils_rpt_report_editor_sched_cancel' style='margin-right:10px;'
+                type='submit' value='&reports.oils_rpt_editor.cancel;'/>
+        </div>
+    </div>
+
        <span id='oils_rpt_empty_param' class='hide_me'>
                &reports.oils_rpt_editor.empty_parameter;
        </span>
index dc6a7d0..42a53d5 100644 (file)
@@ -13,8 +13,12 @@ function oilsRptFolderWindow(type, folderId) {
        this.selector = DOM.oils_rpt_folder_contents_selector;
        this.folderNode = node;
        this.type = type;
+    this.folderId = folderId;
+    oilsRptFolderWindow.folderIdMap[folderId] = this;
 }
 
+// maps folder IDs to their containing oilsRptFolderWindow objects
+oilsRptFolderWindow.folderIdMap = {};
 
 oilsRptFolderWindow.prototype.draw = function() {
 
@@ -698,4 +702,37 @@ oilsRptFolderWindow.prototype.doFolderDelete = function() {
        );
 }
 
+function oilsRptViewEditReport(report, readonly) {
+
+
+    var folderWindow = oilsRptFolderWindow.folderIdMap[report.folder()];
+
+    var req = new Request(
+        'open-ils.reporter:open-ils.reporter.report.fleshed.retrieve',
+        SESSION, report.id()
+    );
+
+    req.callback(function(r) {
+
+        hideMe(DOM.oils_rpt_folder_table_right_td);
+        unHideMe(DOM.oils_rpt_folder_table_alt_td);
+        unHideMe(DOM.oils_rpt_editor_div);
+
+        report = r.getResultObject();
+
+        new oilsRptReportEditor(
+            new oilsReport(report.template(), report), folderWindow, readonly);
+    });
+
+    req.send();
+}
+
+function oilsRptViewReport(report) {
+    oilsRptViewEditReport(report, true);
+}
+
+function oilsRptEditReport(report) {
+    oilsRptViewEditReport(report);
+}
+
 
index cfed104..34090bc 100644 (file)
                &reports.oils_rpt_folder_window.delete_all_attached_outputs;
        </span>
 
+       <span class='hide_me' id='oils_rpt_view_edit_report_links'>
+        <a href='' name='view'>&reports.oils_rpt_folder_window.view_report;</a> / 
+        <a href='' name='edit'>&reports.oils_rpt_folder_window.edit_report;</a>
+       </span>
 
 </div>
 
index 40c6465..2c2b3ff 100644 (file)
@@ -321,9 +321,13 @@ oilsRptFolderManager.prototype.findNode = function(type, id) {
 
 /* this only works if the initial folder tree has been drawn 
        if defined, "action" must be a function pointer that takes the
-       folder node as the param */
+       folder node as the param 
+
+    eachFolder - optional callback called with each folder
+    node after its added to the folder list.
+*/
 var __someid;
-function oilsRptBuildFolder(type, node, treeVar, rootName, action, shared) {
+function oilsRptBuildFolder(type, node, treeVar, rootName, action, shared, eachFolder) {
        removeChildren(node);
        var tree = new SlimTree(node, treeVar);
        this.treeId = oilsNextId();
@@ -347,6 +351,8 @@ function oilsRptBuildFolder(type, node, treeVar, rootName, action, shared) {
                }
 
                tree.addNode(tid, pid, f.name(), __setFolderCB(tree, tid, action, cache[c]));
+
+        if (eachFolder) eachFolder(cache[c]);
        }
        eval(treeVar +' = tree;');
 }
index a4302f0..40acd1b 100644 (file)
@@ -1,7 +1,8 @@
 oilsRptSetSubClass('oilsRptParamEditor','oilsRptObject');
-function oilsRptParamEditor(report, tbody) {
+function oilsRptParamEditor(report, tbody, readonly) {
        this.tbody = tbody;
        this.report = report;
+    this.readonly = readonly;
 }
 
 
@@ -66,12 +67,12 @@ oilsRptParamEditor.prototype.draw = function() {
         }
                $n(row, 'transform').appendChild(text(OILS_RPT_TRANSFORMS[par.column.transform].label));
                $n(row, 'action').appendChild(text(OILS_RPT_FILTERS[par.op].label));
-               par.widget = this.buildWidget(par, $n(row, 'widget'));
+               par.widget = this.buildWidget(par, $n(row, 'widget'), true);
                par.widget.draw();
        }
 }
 
-oilsRptParamEditor.prototype.buildWidget = function(param, node) {
+oilsRptParamEditor.prototype.buildWidget = function(param, node, fromTemplate) {
        var transform = param.column.transform;
        var cls = oilsRptPathClass(param.path);
        var field = oilsRptFindField(oilsIDL[cls], oilsRptPathCol(param.path));
@@ -86,6 +87,7 @@ oilsRptParamEditor.prototype.buildWidget = function(param, node) {
        widgetArgs.inputSize = OILS_RPT_TRANSFORMS[transform].input_size;
        widgetArgs.regex = OILS_RPT_TRANSFORMS[transform].regex;
     widgetArgs.value = param.value;
+    widgetArgs.readonly = this.readonly;
 
        switch(transform) {
                case 'date':
@@ -194,7 +196,8 @@ oilsRptParamEditor.prototype.buildWidget = function(param, node) {
             break;
        }
 
-    if(widgetArgs.value != undefined) 
+    // oilsRptTemplateWidget's are pre-set read-only values
+    if(fromTemplate && widgetArgs.value != undefined) 
         return new oilsRptTemplateWidget(widgetArgs);
 
 
index 7f714d1..405846e 100644 (file)
@@ -5,14 +5,18 @@ var rpt_strings = dojo.i18n.getLocalization("openils.reports", "reports");
 oilsRptSetSubClass('oilsRptReportEditor', 'oilsRptObject');
 var oilsRptReportEditorFolderTree;
 
-function oilsRptReportEditor(rptObject, folderWindow) {
+function oilsRptReportEditor(rptObject, folderWindow, readonly) {
        var tmpl = rptObject.templateObject;
        var rpt = rptObject.reportObject;
        this.folderWindow = folderWindow;
+    this.readonly = readonly;
 
        this.template = tmpl;
        this.report = rpt;
 
+    if (rpt && rpt.runs() && rpt.runs().length)
+        this.last_run = rpt.runs()[rpt.runs().length - 1];
+
        appendClear(DOM.oils_rpt_report_editor_template_name, tmpl.name());
        appendClear(DOM.oils_rpt_report_editor_template_creator, tmpl.owner().usrname());
        appendClear(DOM.oils_rpt_report_editor_template_description, tmpl.description());
@@ -83,12 +87,80 @@ oils_rpt_editor_pivot_data
  
 
        if( rpt ) {
+        // populate the report edit form w/ report data
+
+        this.orig_rpt_name = rpt.name();
+
                DOM.oils_rpt_report_editor_name.value = rpt.name();
-               DOM.oils_rpt_report_editor_description.value = rpt.description();
+               DOM.oils_rpt_report_editor_name.onchange(); // validation
+               DOM.oils_rpt_report_editor_desc.value = rpt.description();
+
+        if (rpt.recur() == 't') {
+            DOM.oils_rpt_recur.checked = true;
+            DOM.oils_rpt_recur.onclick(); // enable recurrance selector
+        }
+
+        if (rpt.recurrence()) {
+            var parts = rpt.recurrence().split(/ /);
+            setSelector(DOM.oils_rpt_recur_count, parts[0]);
+            setSelector(DOM.oils_rpt_recur_interval_type, parts[1]);
+        }
+
+        if (run = this.last_run) {
+                   DOM.oils_rpt_report_editor_name.disabled = true;
+                   DOM.oils_rpt_report_editor_desc.disabled = true;
+            DOM.oils_rpt_format_csv.checked = run.csv_format() == 't';
+            DOM.oils_rpt_format_excel.checked = run.excel_format() == 't';
+            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';
+        }
        }
 
+    if (this.readonly) {
+        DOM.oils_rpt_report_editor_name.disabled = true;
+        DOM.oils_rpt_report_editor_desc.disabled = true;
+        DOM.oils_rpt_recur.disabled = true;
+        DOM.oils_rpt_recur_count.disabled = true;
+        DOM.oils_rpt_recur_interval_type.disabled = true;
+        DOM.oils_rpt_report_editor_run_now.disabled = true;
+        DOM.oils_rpt_format_csv.disabled = true;
+        DOM.oils_rpt_format_excel.disabled = true;
+        DOM.oils_rpt_format_html.disabled = true;
+        DOM.oils_rpt_format_chart_bar.disabled = true;
+        DOM.oils_rpt_format_chart_line.disabled = true;
+        DOM.oils_rpt_param_editor_sched_email.disabled = true;
+
+        hideMe(DOM.oils_rpt_report_editor_save);
+        hideMe(DOM.oils_rpt_report_editor_save_new);
+        hideMe(DOM.oils_rpt_report_editor_cancel);
+        unHideMe(DOM.oils_rpt_report_editor_exit);
+
+    } else {
+        // these DOM elements are shared across instances
+        // of the UI.  Re-enable everything.
+        DOM.oils_rpt_report_editor_name.disabled = false;
+        DOM.oils_rpt_report_editor_desc.disabled = false;
+        DOM.oils_rpt_recur.disabled = false;
+        DOM.oils_rpt_recur_count.disabled = false;
+        DOM.oils_rpt_recur_interval_type.disabled = false;
+        DOM.oils_rpt_report_editor_run_now.disabled = false;
+        DOM.oils_rpt_format_csv.disabled = false;
+        DOM.oils_rpt_format_excel.disabled = false;
+        DOM.oils_rpt_format_html.disabled = false;
+        DOM.oils_rpt_format_chart_bar.disabled = false;
+        DOM.oils_rpt_format_chart_line.disabled = false;
+        DOM.oils_rpt_param_editor_sched_email.disabled = false;
+        DOM.oils_rpt_report_editor_save.disabled = false;
+
+        unHideMe(DOM.oils_rpt_report_editor_save);
+        unHideMe(DOM.oils_rpt_report_editor_save_new);
+        unHideMe(DOM.oils_rpt_report_editor_cancel);
+        hideMe(DOM.oils_rpt_report_editor_exit);
+    }
+
        this.paramEditor = new oilsRptParamEditor(
-               rptObject, DOM.oils_rpt_param_editor_tbody);
+               rptObject, DOM.oils_rpt_param_editor_tbody, this.readonly);
        this.paramEditor.draw();
 
        removeChildren(DOM.oils_rpt_report_editor_selected_folder);
@@ -102,8 +174,17 @@ oils_rpt_editor_pivot_data
                rpt_strings.REPORT_EDITOR_REPORT_FOLDERS,
                function(node) { 
                        appendClear(DOM.oils_rpt_report_editor_selected_folder, node.folder.name());
-                       obj.selectedFolder = node; });
-
+                       obj.selectedFolder = node; 
+        },
+        null,
+        function(node) {
+            // apply the previously selected report folder
+            if (rpt && rpt.folder() == node.folder.id()) {
+                           appendClear(DOM.oils_rpt_report_editor_selected_folder, node.folder.name());
+                           obj.selectedFolder = node; 
+            }
+        }
+    );
 
        oilsRptBuildFolder(
                'output',
@@ -112,20 +193,41 @@ oils_rpt_editor_pivot_data
                rpt_strings.REPORT_EDITOR_OUTPUT_FOLDERS,
                function(node) { 
                        appendClear(DOM.oils_rpt_output_selected_folder, node.folder.name());
-                       obj.selectedOutputFolder = node; });
+                       obj.selectedOutputFolder = node; 
+        },
+        null,
+        function(node) {
+            // apply the previously selected output folder
+            if (obj.last_run && obj.last_run.folder() == node.folder.id()) {
+                           appendClear(DOM.oils_rpt_output_selected_folder, node.folder.name());
+                           obj.selectedOutputFolder = node; 
+            }
+        }
+    );
 
 
        var obj = this;
        DOM.oils_rpt_report_editor_save.onclick = function(){obj.save();}
-       DOM.oils_rpt_param_editor_sched_email.value = USER.email();
+       DOM.oils_rpt_report_editor_save_new.onclick = function(){obj.save({save_new : true});}
+       DOM.oils_rpt_report_editor_exit.onclick = function(){obj.exit();}
+       DOM.oils_rpt_report_editor_cancel.onclick = function(){obj.exit();}
+
+       DOM.oils_rpt_param_editor_sched_email.value = 
+        this.last_run ? this.last_run.email() : USER.email();
+
        DOM.oils_rpt_param_editor_sched_start_date.value = mkYearMonDay();
 
        _debug("fleshing template:\n" + tmpl.name() + '\n' + formatJSON(tmpl.data()));
 }
 
 
-oilsRptReportEditor.prototype.save = function() {
-       var report = new rr();
+// options.save_new : save as a new report, even if we
+// were editing an exitingn report.
+//
+// options.modify_schedule : update the pending schedule
+// object instead of creating a new one.
+oilsRptReportEditor.prototype.save = function(options) {
+    if (!options) options = {};
 
        if(!this.selectedFolder) 
                return alert(rpt_strings.REPORT_EDITOR_PROVIDE_FOLDER_ALERT);
@@ -133,15 +235,33 @@ oilsRptReportEditor.prototype.save = function() {
        if(!DOM.oils_rpt_report_editor_name.value)
                return alert(rpt_strings.REPORT_EDITOR_ENTER_NAME_ALERT);
 
-       report.owner( USER.id() );
-       report.template( this.template.id() );
+       if(!this.selectedOutputFolder) 
+               return alert(rpt_strings.REPORT_EDITOR_PROVIDE_OUTPUT_ALERT);
+
+       var report = this.report;
+
+    if (report && options.save_new) {
+        // user is saving an existing report as a new report.
+        // The new report must have a different name.
+        if (DOM.oils_rpt_report_editor_name.value == this.orig_rpt_name) 
+            return alert(rpt_strings.REPORT_EDITOR_ENTER_NEW_NAME_ALERT);
+
+        report = null;
+    }
+
+    if (!report) {
+        report = new rr();
+        report.isnew(true);
+           report.owner( USER.id() );
+           report.template( this.template.id() );
+    }
+
        report.folder( this.selectedFolder.folder.id() );
        report.name( DOM.oils_rpt_report_editor_name.value );
        report.description( DOM.oils_rpt_report_editor_desc.value );
        report.recur(this.paramEditor.recur());
        report.recurrence(this.paramEditor.recurInterval());
 
-
        /* collect the param data */
        var data = {};
        for( var p in this.paramEditor.params ) {
@@ -194,10 +314,23 @@ oilsRptReportEditor.prototype.save = function() {
                _debug("built run_time "+time);
        }
 
-       if(!this.selectedOutputFolder) 
-               return alert(rpt_strings.REPORT_EDITOR_PROVIDE_OUTPUT_ALERT);
+    // if the last run has yet to actually start, then we update it
+    // instead of creating a new one.
+    var schedule = options.save_new ? null : this.last_run;
+
+    if (schedule && !schedule.start_time()) {
+        if (!options.modify_schedule) {
+            // warn the user that this action will modify an existing
+            // schedule object if they continue
+            return this.showPendingScheduleDialog();
+        }
+    } else {
+        // no schedules exist or the most recent one has already
+        // started.  Create a new one.
+           schedule = new rs();
+        schedule.isnew(true);
+    }
 
-       var schedule = new rs();
        schedule.folder(this.selectedOutputFolder.folder.id());
        schedule.email(DOM.oils_rpt_param_editor_sched_email.value);
        schedule.run_time(time);
@@ -210,12 +343,51 @@ oilsRptReportEditor.prototype.save = function() {
        schedule.chart_bar((DOM.oils_rpt_format_chart_bar.checked) ? 't' : 'f');
        schedule.chart_line((DOM.oils_rpt_format_chart_line.checked) ? 't' : 'f');
 
-
        debugFMObject(report);
        debugFMObject(schedule);
 
-       //return;
+    if (report.isnew()) {
+        this.createReport(report, schedule);
+    } else {
+        this.updateReport(report, schedule);
+    }
+}
+
+// Modify an existing report.
+// Modify or create the schedule depending on isnew()
+oilsRptReportEditor.prototype.updateReport = function(report, schedule) {
 
+    var this_ = this;
+    function success() {
+        oilsRptAlertSuccess();
+        this_.exit();
+    }
+
+    oilsRptUpdateReport(report, function(ok) {
+        if (!ok) return oilsRptAlertFailure();
+
+        if (schedule.isnew()) {
+
+            var req = new Request(OILS_RPT_CREATE_SCHEDULE, SESSION, schedule);
+            req.callback(function(res) {
+                if(checkILSEvent(res)) 
+                    return alertILSEvent(res);
+                success();
+            });
+            req.send()
+
+        } else {
+
+            oilsRptUpdateSchedule(schedule, function(ok2) {
+                if (ok2) return success();
+                _debug("schedule update failed " + js2JSON(schedule));
+                oilsRptAlertFailure();
+            });
+        }
+    });
+}
+
+oilsRptReportEditor.prototype.createReport = function(report, schedule) {
        var obj = this;
     var folderReq = new Request(OILS_RPT_REPORT_EXISTS, SESSION, report);
     folderReq.callback(
@@ -233,8 +405,7 @@ oilsRptReportEditor.prototype.save = function() {
                         } else {
                             if( res && res != '0' ) {
                                 oilsRptAlertSuccess();
-                                oilsRptCurrentFolderManager.draw();
-                                obj.folderWindow.draw();
+                                obj.exit();
                             }
                         }
                     }
@@ -246,4 +417,50 @@ oilsRptReportEditor.prototype.save = function() {
     folderReq.send();
 }
 
+oilsRptReportEditor.prototype.showPendingScheduleDialog = function() {
+    hideMe(DOM.oils_rpt_editor_table);
+    unHideMe(DOM.oils_rpt_editor_sched_confirm);
+
+    function close() {
+        unHideMe(DOM.oils_rpt_editor_table);
+        hideMe(DOM.oils_rpt_editor_sched_confirm);
+    }
+
+    var this_ = this;
+    DOM.oils_rpt_report_editor_sched_apply.onclick = function() {
+        close();
+        this_.save({modify_schedule : true});
+    }
+
+    DOM.oils_rpt_report_editor_sched_asnew.onclick = function() {
+
+        if (DOM.oils_rpt_report_editor_name.value == this_.orig_rpt_name) {
+            // user is saving as new but has not yet modified the name
+            // Prompt for a new name, then udpate the name entry so save() 
+            // will see it.  Don't let them escape until they comply.
+            var new_name;
+            while (true) { 
+
+                new_name = prompt(
+                    rpt_strings.REPORT_EDITOR_ENTER_NEW_NAME_ALERT, 
+                    this_.orig_rpt_name
+                );
+                
+                if (new_name && new_name != this_.orig_rpt_name)
+                    break;
+            }
+
+            DOM.oils_rpt_report_editor_name.value = new_name;
+        } 
+
+        close();
+        this_.save({save_new : true})
+    }
+    DOM.oils_rpt_report_editor_sched_cancel.onclick = close;
+}
+
 
+oilsRptReportEditor.prototype.exit = function() {
+    oilsRptCurrentFolderManager.draw();
+    this.folderWindow.draw();
+}
index dfde0fc..d7017ec 100644 (file)
@@ -327,7 +327,6 @@ function oilsRptFetchTemplate(id, callback) {
        r.send();
 }
 
-
 function oilsRptAlertSuccess() { alertId('oils_rpt_generic_success'); }
 function oilsRptAlertFailure() { alertId('oils_rpt_generic_failure'); }
 
index 28123d2..97c7e61 100644 (file)
@@ -5,14 +5,18 @@
 function oilsRptSetWidget(args) {
        this.node = args.node;
        this.inputWidget = new args.inputWidget(args);
+    this.readonly = Boolean(args.readonly);
        this.dest = elem('select',
                {multiple:'multiple','class':'oils_rpt_small_info_selector'});
+    this.dest.disabled = this.readonly;
 }
 
 oilsRptSetWidget.prototype.draw = function() {
 
        this.addButton = elem('input',{type:'submit',value:"Add"})
        this.delButton = elem('input',{type:'submit',value:"Del"})
+       this.addButton.disabled = this.readonly;
+       this.delButton.disabled = this.readonly;
 
        var obj = this;
        this.addButton.onclick = function() {
@@ -28,6 +32,10 @@ oilsRptSetWidget.prototype.draw = function() {
        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();
 }
 
 oilsRptSetWidget.prototype.addDisplayItems = function(list) {
@@ -120,11 +128,18 @@ oilsRptBetweenWidget.prototype.getValue = function() {
        --------------------------------------------------------------------- */
 function oilsRptTextWidget(args) {
        this.node = args.node;
+    this.seedValue = args.value;
        this.dest = elem('input',{type:'text',size:12});
+    this.dest.disabled = Boolean(args.readonly);
        oilsRptMonitorWidget(this.dest);
 }
 oilsRptTextWidget.prototype.draw = function() {
        this.node.appendChild(this.dest);
+    // TODO: untested
+    if (this.seedValue) {
+        this.dest.value = this.seedValue;
+        this.dest.onchange(); // validation
+    }
 }
 
 /* returns the "real" value for the widget */
@@ -144,13 +159,17 @@ oilsRptTextWidget.prototype.getDisplayValue = function() {
        --------------------------------------------------------------------- */
 function oilsRptBoolWidget(args) {
        this.node = args.node;
+    this.seedValue = arg.value;
        this.selector = elem('select');
        insertSelectorVal(this.selector, -1,'True','t');
        insertSelectorVal(this.selector, -1,'False','f');
+    this.selector.disabled = Boolean(args.readonly);
 }
 
 oilsRptBoolWidget.prototype.draw = function() {
        this.node.appendChild(this.selector);
+    if (this.seedValue)  // TODO: untested
+        setSelector(this.selector, this.seedValue);
 }
 
 /* returns the "real" value for the widget */
@@ -204,6 +223,8 @@ function oilsRptCalWidget(args) {
        this.node = args.node;
        this.calFormat = args.calFormat;
        this.input = elem('input',{type:'text',size:12});
+    this.seedValue = args.value;
+    this.input.disabled = Boolean(args.readonly);
 
        oilsRptMonitorWidget(this.input, args.regex);
 
@@ -231,6 +252,11 @@ oilsRptCalWidget.prototype.draw = function() {
                align                   : "Tl", 
                singleClick     : true
        });
+
+    if (this.seedValue) {
+        this.input.value = this.seedValue;
+        this.input.onchange(); // validation
+    }
 }
 
 oilsRptCalWidget.prototype.getValue = function() {
@@ -247,8 +273,10 @@ oilsRptCalWidget.prototype.getDisplayValue = function() {
        --------------------------------------------------------------------- */
 function oilsRptOrgSelector(args) {
        this.node = args.node;
+    this.seedValue = args.value;
        this.selector = elem('select',
                {multiple:'multiple','class':'oils_rpt_small_info_selector'});
+    this.selector.disabled = Boolean(args.readonly);
 }
 
 oilsRptOrgSelector.prototype.draw = function(org) {
@@ -268,6 +296,18 @@ oilsRptOrgSelector.prototype.draw = function(org) {
                        this.draw(org.children()[c]);
        }
        this.node.appendChild(this.selector);
+
+    if (this.seedValue) {
+        if (dojo.isArray(this.seedValue)) {
+            for (var i = 0; i < this.selector.options.length; i++) {
+                var opt = this.selector.options[i];
+                if (this.seedValue.indexOf(opt.value) > -1)
+                    opt.selected = true;
+            }
+        } else {
+            setSelector(this.selector, this.seedValue);
+        }
+    }
 }
 
 oilsRptOrgSelector.prototype.getValue = function() {
@@ -298,8 +338,11 @@ oilsRptOrgSelector.prototype.getDisplayValue = function() {
        --------------------------------------------------------------------- */
 function oilsRptAgeWidget(args) {
        this.node = args.node;
+    this.seedValue = args.value;
        this.count = elem('select');
        this.type = elem('select');
+    this.count.disabled = Boolean(args.readonly);
+    this.type.disabled = Boolean(args.readonly);
 }
 
 oilsRptAgeWidget.prototype.draw = function() {
@@ -314,6 +357,12 @@ oilsRptAgeWidget.prototype.draw = function() {
        insertSelectorVal(this.type, -1, rpt_strings.WIDGET_YEARS, 'years');
        this.node.appendChild(this.count);
        this.node.appendChild(this.type);
+
+    if (this.seedValue) { // TODO: test me
+        var parts = this.seedValue.split(/ /);
+        setSelector(this.count, parts[0]);
+        setSelector(this.type, parts[1]);
+    }
 }
 
 oilsRptAgeWidget.prototype.getValue = function() {
@@ -341,9 +390,12 @@ oilsRptAgeWidget.prototype.getDisplayValue = function() {
        --------------------------------------------------------------------- */
 function oilsRptSubstrWidget(args) {
        this.node = args.node
+    this.seedValue = args.value;
        this.data = elem('input',{type:'text',size:12})
        this.offset = elem('input',{type:'text',size:5})
        this.length = elem('input',{type:'text',size:5})
+    this.offset.disabled = Boolean(args.readonly);
+    this.length.disabled = Boolean(args.readonly);
 }
 
 oilsRptSubstrWidget.prototype.draw = function() {
@@ -355,6 +407,13 @@ oilsRptSubstrWidget.prototype.draw = function() {
        this.node.appendChild(elem('br'));
        this.node.appendChild(text('length: '))
        this.node.appendChild(this.length);
+
+    if (this.seedValue) { 
+        // TODO: unested; substring currently not supported.
+        this.data.value = this.seedValue[0];
+        this.offset.value = this.seedValue[1];
+        this.length.value = this.seedValue[2];
+    }
 }
 
 oilsRptSubstrWidget.prototype.getValue = function() {
@@ -377,9 +436,11 @@ oilsRptSubstrWidget.prototype.getDisplayValue = function() {
        --------------------------------------------------------------------- */
 function oilsRptNumberWidget(args) {
        this.node = args.node;
+    this.seedValue = args.value;
        this.size = args.size || 32;
        this.start = args.start;
        this.selector = elem('select');
+    this.selector.disabled = Boolean(args.readonly);
 }
 oilsRptNumberWidget.prototype.draw = function() {
        //insertSelectorVal(this.selector, -1, ' -- Select One -- ', '');
@@ -387,6 +448,9 @@ oilsRptNumberWidget.prototype.draw = function() {
                insertSelectorVal(this.selector, -1, i, i);
        this.node.appendChild(this.selector);
        var obj = this;
+
+    if (this.seedValue) // TODO: test me
+        setSelector(this.selector, this.seedValue);
 }
 
 oilsRptNumberWidget.prototype.getValue = function() {
@@ -397,11 +461,6 @@ oilsRptNumberWidget.prototype.getDisplayValue = function() {
        return { label : this.getValue(), value : this.getValue() };
 }
 
-
-/* --------------------------------------------------------------------- 
-       Relative dates widget
-       -------------------------------------------------------------------- */
-
 function oilsRptNullWidget(args) {
     this.node = args.node;
     this.type = args.type;
@@ -425,6 +484,7 @@ oilsRptTemplateWidget.prototype.draw = function() {
 function oilsRptTruncPicker(args) {
        this.node = args.node;
        this.type = args.type;
+    this.seedValue = args.value; // TODO: FINISH
        this.realSpan = elem('span');
        this.relSpan = elem('span');
        hideMe(this.relSpan);
@@ -435,9 +495,11 @@ function oilsRptTruncPicker(args) {
        this.selector = elem('select');
        insertSelectorVal(this.selector,-1,rpt_strings.WIDGET_REAL_DATE,1);
        insertSelectorVal(this.selector,-1,rpt_strings.WIDGET_RELATIVE_DATE,2);
+    this.selector.disabled = Boolean(args.readonly);
 
        this.numberPicker = 
-               new oilsRptNumberWidget({node:this.relSpan,size:90,start:1});
+               new oilsRptNumberWidget(
+            {node:this.relSpan,size:90,start:1,readonly:args.readonly});
 
        this.label = 'Day(s)';
        if(this.type == 'month') this.label = rpt_strings.WIDGET_MONTHS;
@@ -495,6 +557,7 @@ function oilsRptRemoteWidget(args) {
        this.column = args.column;
        this.source = elem('select',
                {multiple:'multiple','class':'oils_rpt_small_info_selector'});
+    this.source.disabled = Boolean(args.readonly);
 }
 
 oilsRptRemoteWidget.prototype.draw = function() {