adding generic table drawer for fm objects
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 16 Aug 2006 16:09:41 +0000 (16:09 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 16 Aug 2006 16:09:41 +0000 (16:09 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5532 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/opac/common/css/fm_table.css [new file with mode: 0644]
Open-ILS/web/opac/common/js/fm_table.js [new file with mode: 0644]
Open-ILS/web/opac/common/js/fm_table_conf.js [new file with mode: 0644]

diff --git a/Open-ILS/web/opac/common/css/fm_table.css b/Open-ILS/web/opac/common/css/fm_table.css
new file mode 100644 (file)
index 0000000..a593ba1
--- /dev/null
@@ -0,0 +1,8 @@
+.fm_table { border-collapse: collapse; text-align: center; width: 100%; background: white;}
+.fm_table thead tr { background: #E0F0E0; color: #000000; font-weight: bold;}
+.fm_table thead td { border: 1px solid #808080; padding-right: 5px; padding-left: 5px;}
+.fm_table tbody td { border: 1px solid #E0E0E0; padding: 2px; }
+.fm_table tbody td a { font-weight: bold; }
+.fm_selected { background: #F0E0E0; }
+.fm_selected thead td { padding: 1px; border: 1px solid #909090; }
+.fm_selected tbody td { padding: 1px; border: 1px solid #909090; }
diff --git a/Open-ILS/web/opac/common/js/fm_table.js b/Open-ILS/web/opac/common/js/fm_table.js
new file mode 100644 (file)
index 0000000..24455fe
--- /dev/null
@@ -0,0 +1,187 @@
+/* 
+       Fieldmapper object table
+*/
+
+
+
+function drawFMObjectTable( args ) {
+
+       var destination = args.dest;
+       var obj = args.obj;
+
+       if( typeof destination == 'string' ) 
+               destination = $(destination);
+       var builder = new FMObjectBuilder(obj, args.display);
+       destination.appendChild(builder.build());
+       return builder;
+}
+
+
+/* Constructor for the builder object */
+function FMObjectBuilder( obj, display, styleToggle ) {
+       this.obj                = obj;
+       this.table      = elem('table');
+       this.thead      = elem('thead');
+       this.tbody      = elem('tbody');
+       this.thead_tr = elem('tr');
+       this.subtables = [];
+       this.display = display;
+       this.styleToggle = styleToggle;
+       if(!this.display) this.display = {};
+
+       this.table.appendChild(this.thead);
+       this.table.appendChild(this.tbody);
+       this.thead.appendChild(this.thead_tr)
+
+       addCSSClass(this.table, 'fm_table');
+}
+
+
+/* Builds the table */
+FMObjectBuilder.prototype.build = function() {
+       var o = this.obj;
+
+       if( instanceOf(this.obj, Array) ) 
+               o = this.obj[0];
+       else this.obj = [this.obj];
+
+       if( o ) {
+
+               this.setKeys(o);
+               for( var i = 0; i < this.keys.length; i++ ) 
+                       this.thead_tr.appendChild(elem('td',null,this.keys[i]));
+       
+               for( var i = 0; i < this.obj.length; i++ ) 
+                       this.buildObjectRow(this.obj[i]);
+       }
+
+       return this.table;
+}
+
+
+/* */
+FMObjectBuilder.prototype.setKeys = function(o) {
+       if( this.display[o.classname] ) 
+               this.keys = this.display[o.classname].fields;
+
+       if(!this.keys && FM_TABLE_DISPLAY[o.classname])
+               this.keys = FM_TABLE_DISPLAY[o.classname].fields;
+
+       if(!this.keys)
+               this.keys = fmclasses[o.classname];
+
+       this.keys = this.keys.sort();
+}
+
+/* Inserts one row into the table to represent a single object */
+FMObjectBuilder.prototype.buildObjectRow = function(obj) {
+       var row = elem('tr');
+       for( var i = 0; i < this.keys.length; i++ ) {
+               var td = elem('td');    
+               var data = obj[this.keys[i]]();
+               this.fleshData(td, data, this.keys[i]);
+               row.appendChild(td);
+       }
+       this.tbody.appendChild(row);
+}
+
+FMObjectBuilder.prototype.dataName = function(data) {
+       var name;
+       if( this.display[data.classname] ) 
+               name = this.display[data.classname].name;
+
+       if(!name && FM_TABLE_DISPLAY[data.classname])
+               name = FM_TABLE_DISPLAY[data.classname].name;
+
+       if(!name) name = 'id';
+
+       return data[name]();
+       return name;
+}
+
+
+FMObjectBuilder.prototype.fleshData = function(td, data, key) {
+       if(data == null) data = '';
+
+       if( typeof data == 'object' ) {
+               var atext;
+
+               if( data._isfieldmapper ) 
+                       atext = this.dataName(data);
+
+               else if (instanceOf(data, Array) )
+                       atext = data.length;
+
+               if( atext ) {
+
+                       var master = this;
+                       var expand = function () { 
+                               var buildme = true;
+                               var row = td.parentNode.nextSibling;
+                               if( row && row.getAttribute('subrow') == key) buildme = false;
+                               master.hideSubTables();
+                               if(buildme) master.buildSubTable(td, data, key);
+                       };
+
+                       var a = elem('a',{href:'javascript:void(0);'});
+                       a.onclick = expand;
+                       a.appendChild(text(atext));
+                       td.appendChild(a);
+
+               } else {
+                       td.appendChild(text(''));
+               }
+
+       } else {
+               td.appendChild(text( data ));
+       }
+}
+
+FMObjectBuilder.prototype.hideSubTables = function() {
+
+       /* clear out any existing subrows */
+       for( var i = 0; i < this.tbody.childNodes.length; i++ ) {
+               var r = this.tbody.childNodes[i];
+               if( r.getAttribute('subrow') )
+                       this.tbody.removeChild(r);
+       }
+
+       /* un-style any selected tds */
+       var tds = this.tbody.getElementsByTagName('td');
+       for( i = 0; i < tds.length; i++ )
+               removeCSSClass( tds[i], 'fm_selected' );
+}
+
+FMObjectBuilder.prototype.buildSubTable = function(td, obj, key) {
+
+       var left = td.offsetLeft;
+       var div = elem('div');
+       var row = elem('tr');
+       var subtd= elem('td');
+
+       if( td.parentNode.nextSibling ) 
+               this.tbody.insertBefore(row, td.parentNode.nextSibling);
+       else
+               this.tbody.appendChild(row);
+
+       row.appendChild(subtd);
+       row.setAttribute('subrow', key);
+       subtd.appendChild(div);
+
+       addCSSClass(td, 'fm_selected');
+       subtd.setAttribute('colspan',this.keys.length);
+
+       subtd.setAttribute('style', 'width: 100%; padding-left:'+left+';');
+       var builder = drawFMObjectTable({dest:div, obj:obj, display:this.display});
+       builder.table.setAttribute('style', 'width: auto;');
+       addCSSClass(builder.table, 'fm_selected');
+
+       var style = subtd.getAttribute('style');
+       var newleft = left - (builder.table.clientWidth / 2) + (td.clientWidth / 2);
+       style = style.replace(new RegExp(left), newleft);
+       subtd.setAttribute('style', style);
+}
+
+
+
+
diff --git a/Open-ILS/web/opac/common/js/fm_table_conf.js b/Open-ILS/web/opac/common/js/fm_table_conf.js
new file mode 100644 (file)
index 0000000..9e9773f
--- /dev/null
@@ -0,0 +1,49 @@
+var FM_TABLE_DISPLAY = {
+       acp : {
+               name : 'barcode',       
+               fields : [
+                       'barcode',
+                       'call_number',
+                       'circ_modifier',
+                       'create_date',
+                       'edit_date',
+                       'fine_level',
+                       'holdable',
+                       'loan_duration',
+                       'location',
+                       'notes',
+                       'stat_cat_entry_copy_maps',
+                       'status' ],
+               },
+       acpn : {
+               name : 'title',
+               fields : [
+                       'pub',
+                       'title',
+                       'value'
+               ]
+       },
+       asc : {
+               name : 'name',
+               fields : [
+                       'owner',
+                       'opac_visible',
+                       'name'
+               ]
+       },
+       ascecm : {
+               fields : [ 'stat_cat', 'stat_cat_entry' ]
+       },
+       ccs : {
+               name : 'name'
+       },
+       acpl : {
+               name : 'name',
+               fields : [
+                       'circulate',
+                       'holdable',
+                       'owning_lib',
+                       'opac_visible'
+               ]
+       }
+}