LP#1332138 Report template / field docs repairs
authorBill Erickson <berick@esilibrary.com>
Wed, 18 Jun 2014 21:59:49 +0000 (17:59 -0400)
committerBen Shum <bshum@biblio.org>
Fri, 8 Aug 2014 01:51:57 +0000 (21:51 -0400)
* Various sanity checks and misc. repairs
* Add missing strings
* oils_rpt_editor.xhtml XML repair; XMLENT is strict
* links to external resources open XUL tabs (to avoid HTTP dialogs)
* avoid displaying bare HTML in labels
* show hints for display fields

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Signed-off-by: Ben Shum <bshum@biblio.org>
12 files changed:
Open-ILS/web/opac/common/js/fm_table.js
Open-ILS/web/opac/common/js/fm_table_conf.js
Open-ILS/web/opac/locale/en-US/reports.dtd
Open-ILS/web/reports/oils_rpt.css
Open-ILS/web/reports/oils_rpt.js
Open-ILS/web/reports/oils_rpt.xhtml
Open-ILS/web/reports/oils_rpt_editor.xhtml
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/xul/template-config.js
Open-ILS/web/reports/xul/template_builder.xul

index 11602db..7f33ef2 100644 (file)
@@ -198,12 +198,13 @@ FMObjectBuilder.prototype.buildObjectRow = function(obj) {
        for( var i = 0; i < this.keys.length; i++ ) {
                var td = elem('td');    
         var data = '';
-        if (this.caclulate[i]) { // fake data! pass the object
-            td.appendChild(this.calculate[i](obj);
+        var key = this.keys[i];
+        if (this.calculate && this.calculate[key]) { // fake data! pass the object
+            td.appendChild(this.calculate[key](obj));
         } else {
-                   data = obj[this.keys[i]]();
+                   data = obj[key]();
                data = this.munge(data);
-               this.fleshData(td, data, this.keys[i]);
+               this.fleshData(td, data, key);
         }
 
                row.appendChild(td);
index b7f2887..41ab3f4 100644 (file)
@@ -114,11 +114,15 @@ var FM_TABLE_DISPLAY = {
             docs : function (t) {
                 var d = JSON2js(t.data());
                 if (d.version >= 4 && d.doc_url) {
-                    return elem(
-                        'a',
-                        { href : d.doc_url, target : '_blank'},
-                        'External Documentation'
-                    );
+                    var args = {};
+                    if (typeof xulG == 'undefined') {
+                        args.href = d.doc_url;
+                        args.target = '_blank';
+                    } else {
+                        args.href = '';
+                        args.onclick = "xulG.new_tab('" + d.doc_url + "'); return false"
+                    }
+                    return elem('a', args, 'External Documentation')
                 }
                 return text('');
             }
index 2c9e8f9..367e68c 100644 (file)
 <!ENTITY reports.xul.template_builder.table_name.label "Table Name">
 <!ENTITY reports.xul.template_builder.sql_alias.label "SQL Alias">
 <!ENTITY reports.xul.template_builder.relationship.label "Relationship">
+<!ENTITY reports.xul.template_builder.field_doc.label "Field Hint">
index d4db1f2..5120958 100644 (file)
@@ -319,3 +319,9 @@ button:disabled {
        border-left: 1px solid #808080;
 }
 
+.oils_rpt_field_hint {
+    font-weight: bold;
+    text-decoration:underline;
+    padding-left: 5px;
+}
+
index 67d6654..3d212de 100644 (file)
@@ -135,7 +135,8 @@ oilsReport.prototype._gatherParams = function(params, arr, type, field) {
                        path            : obj.path,
                        type            : type, 
                        relation : obj.relation,
-                       field           : field
+                       field           : field,
+            field_doc : obj.field_doc
                });
        }
 }
index 9aa70a5..f3ceac5 100644 (file)
@@ -26,6 +26,7 @@
        </head>
 
        <body>
+
                <div class='welcome_box'>
                        <span>&reports.common.logged_in_as;</span><b><span id='oils_rpt_user'></span></b>
                </div>
index c2cf708..2c0b911 100644 (file)
                                <td><span id='oils_rpt_report_editor_template_description'></span></td>
                        </tr>
                        <tr id='oils_rpt_report_editor_template_doc_url_row'>
-                               <th colspan=2><a target="_blank" href="" id='oils_rpt_report_editor_template_doc_url'>&reports.oils_rpt_editor.doc_url;</a></th>
+                               <th colspan="2">
+                    &reports.oils_rpt_editor.doc_url; 
+                    <a href="" id='oils_rpt_report_editor_template_doc_url'></a>
+                </th>
                        </tr>
 
                        <tr>
index 947f064..a4302f0 100644 (file)
@@ -37,7 +37,14 @@ oilsRptParamEditor.prototype.draw = function() {
                var par = params[p];
                var row = oilsRptParamEditor.row.cloneNode(true);
                this.tbody.appendChild(row);
-               $n(row, 'column').appendChild(text(oilsRptMakeLabel(par.path, par.field_doc)));
+               $n(row, 'column').appendChild(text(oilsRptMakeLabel(par.path)));
+
+        if (par.field_doc) {
+                   $n(row, 'column').appendChild(
+                elem('div', {'class':'oils_rpt_field_hint'}, par.field_doc));
+        }
+            
+               //$n(row, 'column').appendChild(text(oilsRptMakeLabel(par.path, par.field_doc)));
                $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'));
@@ -52,7 +59,11 @@ oilsRptParamEditor.prototype.draw = function() {
                var par = tparams[p];
                var row = oilsRptParamEditor.row.cloneNode(true);
                this.tbody.appendChild(row);
-               $n(row, 'column').appendChild(text(oilsRptMakeLabel(par.path, par.field_doc)));
+               $n(row, 'column').appendChild(text(oilsRptMakeLabel(par.path)));
+        if (par.field_doc) {
+                   $n(row, 'column').appendChild(
+                elem('div', {'class':'oils_rpt_field_hint'}, par.field_doc));
+        }
                $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'));
index 41c8db4..a36a820 100644 (file)
@@ -18,7 +18,16 @@ function oilsRptReportEditor(rptObject, folderWindow) {
        appendClear(DOM.oils_rpt_report_editor_template_description, tmpl.description());
 
     if (rptObject.def.version >= 4) {
-           DOM.oils_rpt_report_editor_template_doc_url.setAttribute( 'href', rptObject.def.doc_url );
+        if (URL = rptObject.def.doc_url) {
+            var link = DOM.oils_rpt_report_editor_template_doc_url;
+            link.innerHTML = URL;
+            if (typeof xulG == 'undefined') {
+                link.setAttribute('href', URL);
+                link.setAttribute('target', '_blank');
+            } else {
+                link.onclick = function() {xulG.new_tab(URL); return false}
+            }
+        }
     } else {
         hideMe(DOM.oils_rpt_report_editor_template_doc_url_row);
     }
@@ -28,6 +37,10 @@ function oilsRptReportEditor(rptObject, folderWindow) {
                function(i) {
                        if(i)
                                DOM.oils_rpt_report_editor_cols.appendChild(text(i.alias));
+                if (i.field_doc) {
+                                   DOM.oils_rpt_report_editor_cols.appendChild(
+                        elem('span', {'class':'oils_rpt_field_hint'}, i.field_doc));
+                }
                                DOM.oils_rpt_report_editor_cols.appendChild(document.createElement('br'));
                }
        );
index 3d7602d..dfde0fc 100644 (file)
@@ -89,7 +89,7 @@ function oilsRptPathRel(path) {
 }
 
 /* creates a label "path" based on the column path */
-function oilsRptMakeLabel(path, hint) {
+function oilsRptMakeLabel(path) {
        var parts = path.split(/-/);
        var str = '';
        for( var i = 0; i < parts.length; i++ ) {
@@ -104,10 +104,6 @@ function oilsRptMakeLabel(path, hint) {
                }
        }
 
-    if (hint) {
-        str += '<br/><b><i>' + hint + '</i></b>'
-    }
-
        return str;
 }
 
index 69f70d2..a1cb3a2 100644 (file)
@@ -80,7 +80,7 @@ function addReportAtoms () {
                var colname = item.getAttribute('idlfield');
                var jointype = item.getAttribute('join');
                var field_label = item.firstChild.firstChild.getAttribute('label');
-               var field_doc = item.firstChild.lastChild.getAttribute('label');
+               var field_doc = '';
 
                var table_name = getSourceDefinition(field_class);
 
@@ -708,6 +708,14 @@ function renderSources (selected) {
                        fieldtree = tabpanel.getElementsByTagName('treechildren')[0];
 
                        for (var colname in rpt_rel_cache[relation_alias].fields[tabname]) {
+
+                // TODO: code would be clearer if we could access the loaded template
+                // version from here.  Not sure how... it's not in rpt_rel_cache.
+                // Existing templates (e.g. from cloning) will not have a field_doc 
+                // attribute.  with() is not tolerant of  nonexistent attributes.
+                if (!rpt_rel_cache[relation_alias].fields[tabname][colname].field_doc)
+                    rpt_rel_cache[relation_alias].fields[tabname][colname].field_doc = '';
+
                                with (rpt_rel_cache[relation_alias].fields[tabname][colname]) {
                                        fieldtree.appendChild(
                                                createTreeItem(
@@ -737,9 +745,9 @@ function renderSources (selected) {
                                                );
                     }
 
-                                       fieldtree.lastChild.firstChild.appendChild(
-                                               createTreeCell({ label : field_doc })
-                                       );
+                                   fieldtree.lastChild.firstChild.appendChild(
+                                           createTreeCell({ label : field_doc })
+                                   );
                                }
                        }
                }
@@ -760,6 +768,11 @@ function renderSources (selected) {
                        ) continue;
                }
 
+        // Existing templates (e.g. from cloning) will not have a field_doc 
+        // attribute.  with() is not tolerant of  nonexistent attributes.
+        if (!rpt_rel_cache[order.relation].fields.dis_tab[order.field].field_doc)
+            rpt_rel_cache[order.relation].fields.dis_tab[order.field].field_doc = '';
+
                with (rpt_rel_cache[order.relation].fields.dis_tab[order.field]) {
                        fieldtree.appendChild(
                                createTreeItem(
index 5b27102..8997692 100644 (file)
                        <hbox>
                        <vbox>
                                <label control="template-name" value="&reports.xul.template_builder.name.label;" style="height:2em"/>
-                               <label control="template-description" value="&reports.xul.template_builder.description.label;"/>
+                               <label control="template-description" value="&reports.xul.template_builder.description.label;" style="height:3em"/>
                                <label control="template-doc-url" value="&reports.xul.template_builder.doc_url.label;"/>
                        </vbox>
                        <vbox flex="1">