added link style option to slimtree
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 21 Sep 2006 16:46:39 +0000 (16:46 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 21 Sep 2006 16:46:39 +0000 (16:46 +0000)
added support for building the "from" clause on newly inserted fields
added basic framework for displaying transform options
some style updates

git-svn-id: svn://svn.open-ils.org/ILS/trunk@6179 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/opac/common/js/slimtree.js
Open-ILS/web/reports/oils_rpt.css
Open-ILS/web/reports/oils_rpt.js
Open-ILS/web/reports/oils_rpt_builder.js
Open-ILS/web/reports/oils_rpt_builder.xhtml
Open-ILS/web/reports/oils_rpt_tree.js
Open-ILS/web/reports/oils_rpt_utils.js

index e1fff89..4a4e9d2 100644 (file)
@@ -2,12 +2,12 @@
 var stpicopen  = '../../../../images/slimtree/folder.gif';
 var stpicclose = '../../../../images/slimtree/folderopen.gif';
 */
-var stpicopen  = '../../../../images/slimtree/folder2.gif';
-var stpicclose = '../../../../images/slimtree/folderopen2.gif';
-var stpicblank = '../../../../images/slimtree/page.gif';
-var stpicline  = '../../../../images/slimtree/line.gif';
-var stpicjoin  = '../../../../images/slimtree/join.gif';
-var stpicjoinb = '../../../../images/slimtree/joinbottom.gif';
+var stpicopen  = '../opac/images/slimtree/folder2.gif';
+var stpicclose = '../opac/images/slimtree/folderopen2.gif';
+var stpicblank = '../opac/images/slimtree/page.gif';
+var stpicline  = '../opac/images/slimtree/line.gif';
+var stpicjoin  = '../opac/images/slimtree/join.gif';
+var stpicjoinb = '../opac/images/slimtree/joinbottom.gif';
 
 
 var stimgopen  = elem('img',{src:stpicopen,border:0});
@@ -35,7 +35,7 @@ SlimTree.prototype.addCachedChildren = function(pid) {
        this.cache[pid] = null;
 }
 
-SlimTree.prototype.addNode = function( id, pid, name, action, title ) {
+SlimTree.prototype.addNode = function( id, pid, name, action, title, cls ) {
 
        if( pid != -1 && !$(pid)) {
                if(!this.cache[pid]) this.cache[pid] = new Array();
@@ -53,6 +53,8 @@ SlimTree.prototype.addNode = function( id, pid, name, action, title ) {
        var actionref   = elem('a',{href:action}, name);
        var contdiv             = elem('div',{id:'stcont_' + id});
 
+       if(cls) addCSSClass(actionref, cls);
+
        actionref.setAttribute('href',action);
        if(title) actionref.setAttribute('title',title);
        else actionref.setAttribute('title',name);
index e202ea9..78a5cbc 100644 (file)
@@ -1,4 +1,4 @@
-body { font-size: 9pt; }
+body { font-size: 9pt; font-family: Helvetica, Arial, Tahoma, sans-serif; font-size: 9pt;} 
 .hide_me { display: none; visibility: hidden; }
 .welcome_box { position:absolute; top: 5px; right: 5px; }
 
@@ -118,4 +118,16 @@ button {
        border-top: 2px solid #E0E0E0;
 }
 
+.oils_rpt_tform_window {
+       margin: 5px;    
+       text-align: left;
+       padding: 5px;
+       padding-left: 20px;
+}
+
+.oils_rpt_tree_link_ref {
+       color: #A52A2A;
+       font-family: courier; 
+}
+
 
index bdce9bf..dd3f9de 100644 (file)
@@ -22,7 +22,9 @@ function oilsReport() {
        this.def = {
                select  : [],
                from            : {},
-               where           : []
+               where           : [],
+               having  : [],
+               order_by : []
        };
        this.params     = {};
        this.name       = ""
index 3ce92b4..3fc3f44 100644 (file)
@@ -1,3 +1,6 @@
+/** initializes reports, some basid display settings, 
+  * grabs and builds the IDL tree
+  */
 function oilsInitReportBuilder() {
        oilsInitReports();
        oilsRpt = new oilsReport();
@@ -11,14 +14,27 @@ function oilsInitReportBuilder() {
        );
 }
 
+/* returns just the column name */
+function oilsRptPathCol(path) {
+       var parts = path.split(/-/);
+       return parts.pop();
+}
 
+/* returns the IDL class of the selected column */
+function oilsRptPathClass(path) {
+       var parts = path.split(/-/);
+       parts.pop();
+       return parts.pop();
+}
 
-function oilsRptSplitPath(path) {
+/* returns everything prior to the column name */
+function oilsRptPathRel(path) {
        var parts = path.split(/-/);
-       var column = parts.pop();
-       return [ parts.join('-'), column ];
+       parts.pop();
+       return parts.join('-');
 }
 
+/* creates a label "path" based on the column path */
 function oilsRptMakeLabel(path) {
        var parts = path.split(/-/);
        var str = '';
@@ -29,7 +45,8 @@ function oilsRptMakeLabel(path) {
                } else {
                        var column = parts[i];
                        var data = oilsIDL[parts[i-1]];
-                       var f = grep(data.fields, function(j){return (j.name == column); })[0];
+                       var f = grep(data.fields, 
+                               function(j){return (j.name == column); })[0];
                        str += ":"+f.label;
                }
        }
@@ -38,19 +55,60 @@ function oilsRptMakeLabel(path) {
 
 
 /* adds an item to the display window */
-function oilsAddRptDisplayItem(val, name) {
-       if( ! oilsAddSelectorItem(oilsRptDisplaySelector, val, name) ) 
+function oilsAddRptDisplayItem(path, name) {
+       if( ! oilsAddSelectorItem(oilsRptDisplaySelector, path, name) ) 
                return;
 
        /* add the selected columns to the report output */
-       var splitp = oilsRptSplitPath(val);
-       name = (name) ? name : splitp[1];
+       name = (name) ? name : oilsRptPathCol(path);
        var param = oilsRptNextParam();
-       oilsRpt.def.select.push( {relation:splitp[0], column:splitp[1], alias:param} );
+
+       /* add this item to the select blob */
+       oilsRpt.def.select.push( {
+               relation:oilsRptPathRel(path), 
+               column:oilsRptPathCol(path), 
+               alias:param
+       });
+
+       mergeObjects( oilsRpt.def.from, oilsRptBuildFromClause(path));
        oilsRpt.params[param] = name;
        oilsRptDebug();
 }
 
+/* takes a column path and builds a from-clause object for the path */
+function oilsRptBuildFromClause(path) {
+       var parts = path.split(/-/);
+       //var obj = {from : {}};
+       var obj = {};
+       var tobj = obj;
+       var newpath = "";
+       for( var i = 0; i < parts.length; i += 2 ) {
+               var cls = parts[i];
+               var col = parts[i+1];
+               var node = oilsIDL[parts[i]];
+               var field = oilsRptFindField(node, col);
+               newpath = (newpath) ? newpath + '-'+ cls : cls;
+
+               tobj.table = node.table;
+               tobj.alias = newpath;
+               _debug('field type is ' + field.type);
+               if( i == (parts.length - 2) ) break;
+
+               tobj.join = {};
+               tobj = tobj.join;
+               tobj[col] = {};
+               tobj = tobj[col];
+               if( field.type == 'link' )
+                       tobj.key = field.key;
+
+               newpath = newpath + '-'+ col;
+       }
+
+       _debug("built 'from' clause: path="+path+"\n"+formatJSON(js2JSON(obj)));
+       return obj;
+}
+
+
 /* removes a specific item from the display window */
 function oilsDelDisplayItem(val) {
        oilsDelSelectorItem(oilsRptDisplaySelector, val);
@@ -65,8 +123,8 @@ function oilsDelSelectedDisplayItems() {
                function(i) {
                        for( var j = 0; j < list.length; j++ ) {
                                var d = list[j];
-                               var arr = oilsRptSplitPath(d);
-                               if( arr[0] == i.relation && arr[1] == i.column ) {
+                               if( oilsRptPathRel(d) == i.relation 
+                                               && oilsRptPathCol(d) == i.column ) {
                                        var param = (i.alias) ? i.alias.match(/::PARAM\d*/) : null;
                                        if( param ) delete oilsRpt.params[param];
                                        return false;
@@ -76,9 +134,17 @@ function oilsDelSelectedDisplayItems() {
                }
        );
        if(!oilsRpt.def.select) oilsRpt.def.select = [];
+
+       for( var j = 0; j < list.length; j++ ) 
+               oilsRptPruneFromClause(list[j]);
+
        oilsRptDebug();
 }
 
+/* for each item in the path list, remove the associated data
+from the "from" clause */
+function oilsRptPruneFromClause(pathlist) {
+}
 
 /* adds an item to the display window */
 function oilsAddRptFilterItem(val) {
@@ -108,6 +174,7 @@ function oilsAddSelectorItem(sel, val, name) {
        return true;
 }
 
+
 /* removes a specific item from the display window */
 function oilsDelSelectorItem(sel, val) {
        _debug("deleting selector item "+val);
@@ -131,6 +198,8 @@ function oilsDelSelectedItems(sel) {
        return list;
 }
 
+
+/* hides the different field editor tabs */
 function oilsRptHideEditorDivs() {
        hideMe($('oils_rpt_tform_div'));
        hideMe($('oils_rpt_filter_div'));
@@ -143,10 +212,8 @@ function oilsRptHideEditorDivs() {
   filter, and aggregate filter picker window
   */
 function oilsRptDrawDataWindow(path) {
-
-       var parts = path.split(/-/);
-       var col = parts.pop();
-       var cls = parts.pop();
+       var col = oilsRptPathCol(path);
+       var cls = oilsRptPathClass(path);
        var field = grep(oilsIDL[cls].fields, function(f){return (f.name==col);})[0];
        _debug("setting update data window for column "+col+' on class '+cls);
 
@@ -184,6 +251,9 @@ function oilsRptDrawTransformWindow(path, col, cls, field) {
 
        $('oils_rpt_tform_label_input').focus();
        $('oils_rpt_tform_label_input').select();
+
+       if( field.datatype == 'timestamp' )
+               unHideMe($('oils_rpt_tform_date_div'));
 }
 
 
index afd2af8..729c5a6 100644 (file)
@@ -40,6 +40,8 @@
 
                <link rel="stylesheet" type="text/css" href="oils_rpt.css"> </link>
 
+               <script>function _l(l) { location.href = l + location.search; }</script>
+
        </head>
 
        <body onload='oilsInitReportBuilder();' onunload='oilsCleanupReports();'>
                        <span>You are logged in as </span><b><span id='oils_rpt_user'/></b>
                </div>
 
+               <div>
+                       <a class='oils_rpt_main_link' href='javascript:_l("oils_rpt.xhtml");'>Reports Home</a>
+               </div>
+
+
                <div id='oils_rpt_tree_loading'>
                        Loading...
                </div>
                        <div id='oils_rpt_tform_div'>
                                <b style='padding-right: 15px;' id='oils_rpt_tform_label'/>
                                <input size='28' id='oils_rpt_tform_label_input'/>
+                               <div class='oils_rpt_tform_window'>
+                                       <div style='margin-bottom: 10px;'>Select how this field should be displayed:</div>
+                                       <!--#include virtual="oils_rpt_tform_string.xhtml"-->
+                                       <!--#include virtual="oils_rpt_tform_date.xhtml"-->
+                               </div>
                                <br/><br/>
                                <button id='oils_rpt_tform_submit'>Add Item</button>
                        </div>
                        </div>
                </div>
 
+
        </body>
 </html>
 
index b913cee..27e5a56 100644 (file)
@@ -17,6 +17,14 @@ function oilsLoadRptTree(callback) {
        r.send(null);
 }
 
+function oilsRptFindField(node, field) {
+       return grep( node.fields, 
+               function(f) {
+                       return (f.name == field);
+               }
+       )[0];
+}
+
 
 /* turns the IDL into a js object */
 function oilsParseRptTree(IDL, callback) {
@@ -66,6 +74,7 @@ function oilsRptParseFields( node ) {
                        field : fields[i],
                        name    : name,
                        label : field.getAttributeNS(oilsIDLReportsNS,'label'),
+                       datatype : field.getAttributeNS(oilsIDLReportsNS,'datatype'),
                        type    : 'field'
                }
 
@@ -79,23 +88,25 @@ function oilsRptParseFields( node ) {
 
                if( link ) {
                        obj.type = 'link';
-                       obj.reltype = link.getAttribute('reltype');
                        obj.key = link.getAttribute('key');
                        obj['class'] = link.getAttribute('class');
+                       obj.reltype = link.getAttribute('reltype');
+                       if( obj.reltype == 'might_have' ) continue;
                } else {
                        if( fields[i].getAttributeNS(oilsIDLPersistNS, 'virtual') == 'true' ) 
                                continue;
                }
 
                obj.label = (obj.label) ? obj.label : obj.name;
+               obj.datatype = (obj.datatype) ? obj.datatype : 'string';
                data.push(obj);
        }
 
        /* sort by field name */
        data = data.sort(
                function(a,b) {
-                       if( a.name > b.name ) return 1;
-                       if( a.name < b.name ) return -1;
+                       if( a.label > b.label ) return 1;
+                       if( a.label < b.name ) return -1;
                        return 0;
                }
        );
@@ -141,7 +152,8 @@ function oilsRenderSubTree( data, subTreeId, rootName, path ) {
                        action = 'javascript:oilsAddLinkTree("' +
                                dataId+'","'+field['class']+'","'+fullpath+'");';
 
-               oilsRptTree.addNode( dataId, subTreeId, field.label, action );
+               oilsRptTree.addNode( dataId, subTreeId, field.label, action, field.label,
+                       (field.type == 'link') ? 'oils_rpt_tree_link_ref' : null );
        }
 }
 
index d5bcb31..8fc2d7b 100644 (file)
@@ -91,4 +91,21 @@ function buildFloatingDiv(div, width) {
 }
 
 
+function mergeObjects( src, obj ) {
+       for( var i in obj ) {
+               _debug("merging object element: "+i + ' : ' + src[i]);
+               if( i =='from' ) {
+                       _debug('------------------------------');
+                       _debug(formatJSON(js2JSON(src[i])));
+                       _debug(formatJSON(js2JSON(obj[i])));
+                       _debug('------------------------------');
+               }
+               if( typeof obj[i] == 'string' ) {
+                       src[i] = obj[i];
+               } else {
+                       if(src[i]) mergeObjects(src[i], obj[i]);
+                       else src[i] = obj[i];
+               }
+       }
+}