Viewing File: /usr/local/cpanel/base/sharedjs/yui2_datatable_row_expansion_optimized.js

(function(){var Dom=YAHOO.util.Dom,STRING_STATENAME="yui_dt_state",CLASS_EXPANDED="yui-dt-expanded",CLASS_COLLAPSED="yui-dt-collapsed",CLASS_EXPANSION="yui-dt-expansion",CLASS_LINER="yui-dt-liner",indexOf=function(a,val){for(var i=0;i<a.length;i=i+1){if(a[i]===val){return i}}return-1};YAHOO.widget.RowExpansionDataTable=function(elContainer,aColumnDefs,oDataSource,oConfigs){YAHOO.widget.RowExpansionDataTable.superclass.constructor.call(this,elContainer,aColumnDefs,oDataSource,oConfigs)};YAHOO.lang.extend(YAHOO.widget.RowExpansionDataTable,YAHOO.widget.DataTable,{_getRecordState:function(record_id,key){var row_data=this.getRecord(record_id),row_state=row_data?row_data.getData(STRING_STATENAME):null,state_data=row_state&&key?row_state[key]:row_state;return state_data||{}},_setRecordState:function(record_id,key,value){var row_data=this.getRecord(record_id).getData(),merged_data=row_data[STRING_STATENAME]||{};merged_data[key]=value;this.getRecord(record_id).setData(STRING_STATENAME,merged_data);return merged_data},onPaginatorChangeRequest:function(){if(this.get("dynamicData")){this.collapseAllRows()}YAHOO.widget.RowExpansionDataTable.superclass.onPaginatorChangeRequest.apply(this,arguments)},sortColumn:function(){if(this.get("dynamicData")){this.collapseAllRows()}YAHOO.widget.RowExpansionDataTable.superclass.sortColumn.apply(this,arguments)},_setColumnWidth:function(){var save;if(this.a_rowExpansions&&YAHOO.widget.DataTable._bDynStylesFallback){save=this.a_rowExpansions.slice(0);this.collapseAllRows()}YAHOO.widget.RowExpansionDataTable.superclass._setColumnWidth.apply(this,arguments);if(save){this.a_rowExpansions=save;this.restoreExpandedRows()}},getAboveTdEl:function(cell){var elCell=this.getTdEl(cell);if(elCell){var elPreviousRow=this.getPreviousTrEl(elCell);while(Dom.hasClass(elPreviousRow,CLASS_EXPANSION)){elPreviousRow=this.getPreviousTrEl(elPreviousRow)}if(elPreviousRow){return elPreviousRow.cells[elCell.cellIndex]}}return null},getBelowTdEl:function(cell){var elCell=this.getTdEl(cell);if(elCell){var elNextRow=this.getNextTrEl(elCell);while(Dom.hasClass(elNextRow,CLASS_EXPANSION)){elNextRow=this.getNextTrEl(elNextRow)}if(elNextRow){return elNextRow.cells[elCell.cellIndex]}}return null},initAttributes:function(oConfigs){oConfigs=oConfigs||{};YAHOO.widget.RowExpansionDataTable.superclass.initAttributes.call(this,oConfigs);this.setAttributeConfig("rowExpansionTemplate",{value:"",validator:function(template){return YAHOO.lang.isString(template)||YAHOO.lang.isFunction(template)},method:this.initRowExpansion})},initRowExpansion:function(template){this.subscribe("postRenderEvent",this.onEventRestoreRowExpansion);this.rowExpansionTemplate=template;this.a_rowExpansions=[]},toggleRowExpansion:function(record_id){var state=this._getRecordState(record_id);if(state&&state.expanded){this.collapseRow(record_id)}else{this.expandRow(record_id)}},expandRow:function(record_id,restore){var state=this._getRecordState(record_id);if(state.expanded&&!restore){return false}var row_data=this.getRecord(record_id);if(!row_data){return false}var row=this.getTrEl(row_data);if(!row||Dom.hasClass(this.getNextTrEl(row),CLASS_EXPANSION)){return false}var new_row=document.createElement("tr"),column_length=this.getFirstTrEl().childNodes.length,expanded_data=row_data.getData(),expanded_content=null,template=this.rowExpansionTemplate,next_sibling=Dom.getNextSibling(row);new_row.className=CLASS_EXPANSION;var new_column=document.createElement("td");new_column.colSpan=column_length;new_column.innerHTML='<div class="'+CLASS_LINER+'"></div>';new_row.appendChild(new_column);var liner_element=new_row.firstChild.firstChild;if(YAHOO.lang.isString(template)){liner_element.innerHTML=YAHOO.lang.substitute(template,expanded_data)}else if(YAHOO.lang.isFunction(template)){template({row_element:new_row,liner_element:liner_element,data:row_data,state:state})}else{return false}newRow=Dom.insertAfter(new_row,row);if(newRow.innerHTML.length){this._setRecordState(record_id,"expanded",true);if(!restore){this.a_rowExpansions.push(this.getRecord(record_id).getId())}Dom.removeClass(row,CLASS_COLLAPSED);Dom.addClass(row,CLASS_EXPANDED);this.fireEvent("rowExpandEvent",{record_id:row_data.getId()});return true}else{return false}},collapseRow:function(record_id){var row_data=this.getRecord(record_id),row=Dom.get(row_data.getId()),state=row_data.getData(STRING_STATENAME);if(state&&state.expanded){var next_sibling=Dom.getNextSibling(row),hash_index=indexOf(this.a_rowExpansions,this.getRecord(record_id).getId());if(Dom.hasClass(next_sibling,CLASS_EXPANSION)){next_sibling.parentNode.removeChild(next_sibling);this.a_rowExpansions.splice(hash_index,1);this._setRecordState(record_id,"expanded",false);Dom.addClass(row,CLASS_COLLAPSED);Dom.removeClass(row,CLASS_EXPANDED);this.fireEvent("rowCollapseEvent",{record_id:row_data.getId()});return true}else{return false}}},collapseAllRows:function(){var rows=this.a_rowExpansions;if(rows&&rows.length>0){for(var i=0,l=rows.length;l>i;i++){this.collapseRow(rows[0])}}this.a_rowExpansions=[]},restoreExpandedRows:function(){var expanded_rows=this.a_rowExpansions;if(!expanded_rows.length){return}if(this.a_rowExpansions.length){for(var i=0,l=expanded_rows.length;l>i;i++){this.expandRow(expanded_rows[i],true)}}},onEventRestoreRowExpansion:function(oArgs){this.restoreExpandedRows()},onEventToggleRowExpansion:function(oArgs){if(YAHOO.util.Dom.hasClass(oArgs.target,"yui-dt-expandablerow-trigger")){this.toggleRowExpansion(oArgs.target)}}});YAHOO.widget.RowExpansionDataTable.formatRowExpansion=function(el,oRecord,oColumn,oData){Dom.addClass(el.parentNode,"yui-dt-expandablerow-trigger");el.innerHTML='<a class="yui-dt-expandablerow-trigger-inner" href="javascript:void(0);"></a>'}})();
Back to Directory File Manager