JBoss Rich Faces SVN: r993 - trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid.
by richfaces-svn-commitsï¼ lists.jboss.org
Author: abelevich
Date: 2007-06-04 09:59:26 -0400 (Mon, 04 Jun 2007)
New Revision: 993
Removed:
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Grid2.js
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody2.js
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridFooter2.js
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridHeader2.js
Modified:
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody.js
Log:
Deleted: trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Grid2.js
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Grid2.js 2007-06-04 13:59:14 UTC (rev 992)
+++ trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Grid2.js 2007-06-04 13:59:26 UTC (rev 993)
@@ -1,196 +0,0 @@
-/**
- * Grid.js Date created: 6.04.2007
- * Copyright (c) 2007 Exadel Inc.
- * @author Denis Morozov <dmorozov(a)exadel.com>
- */
-ClientUILib.declarePackage("ClientUI.controls.grid.Grid");
-
-ClientUILib.requireClass("ClientUI.common.box.Box");
-ClientUILib.requireClass("ClientUI.controls.grid.GridHeader");
-ClientUILib.requireClass("ClientUI.controls.grid.GridBody");
-ClientUILib.requireClass("ClientUI.controls.grid.GridFooter");
-
-/*
- * grid.js - Grid library on top of Prototype
- * by Denis Morozov <dmorozov(a)exadel.com> distributed under the BSD license.
- *
- * TODO: description of control
- *
- * TODO: usage description
- * Usage:
- * <script src="/javascripts/prototype.js" type="text/javascript"></script>
- * <script src="/javascripts/extend.js" type="text/javascript"></script>
- * <script src="/javascripts/grid.js" type="text/javascript"></script>
- * <script type="text/javascript">
- * // with valid DOM id
- * var grid = new ClientUI.controls.grid.Grid('id_of_trigger_element', 'id_of_tooltip_to_show_element')
- *
- * // with text
- * var grid = new ClientUI.controls.grid.Grid('id_of_trigger_element', 'a nice description')
- * </script>
- */
-ClientUI.controls.grid.Grid = Class.create({
- CLASSDEF: {
- name: 'ClientUI.controls.grid.Grid',
- parent: ClientUI.common.box.Box
- }
-
-});
-
-Object.extend(ClientUI.controls.grid.Grid.prototype, {
- // Custom events
- /**
- * Occured when content header clicked
- */
- eventOnSort: {},
- /**
- * Occured when column width adjusted
- */
- eventOnResizeColumn: {},
-
- initialize: function(element, dataModel, templates) {
- ClientUI.controls.grid.Grid.parentClass.constructor().call(this, element);
- if(!element || !element.id)
- this.element.id = "ClientUI_Grid" + ClientUI_controls_grid_Grid_idGenerator++;
-
- this.dataModel = dataModel;
- this.templates = $A(templates);
-
- this.eventOnSort = new ClientUI.common.utils.CustomEvent('OnSort');
- this.eventOnResizeColumn = new ClientUI.common.utils.CustomEvent('OnResizeColumn');
-
- this.createControl();
- },
- createControl: function() {
- //TODO: delete
- document.gridStartTime = (new Date()).getTime();
-
- var grid = this;
- var layout = new ClientUI.layouts.GridLayoutManager(null, this.getElement());
- this.layout = layout;
-
- this.templates.each(function(item) {
- switch(item.pane) {
- case GridLayout_Enum.HEADER: {
- //TODO: delete
- document.headerStartTime = (new Date()).getTime();
-
- var header = new ClientUI.controls.grid.GridHeader($(item.ref), grid);
- layout.addPane(GridLayout_Enum.HEADER, header);
-
- //TODO: delete
- document.headerStopTime = (new Date()).getTime();
-
- break;
- }
- case GridLayout_Enum.BODY: {
- //TODO: delete
- document.bodyStartTime = (new Date()).getTime();
-
- var body = new ClientUI.controls.grid.GridBody($(item.ref), grid);
- layout.addPane(GridLayout_Enum.BODY, body);
-
- //TODO: delete
- document.bodyStopTime = (new Date()).getTime();
-
- break;
- }
- case GridLayout_Enum.FOOTER: {
- //TODO: delete
- document.footerStartTime = (new Date()).getTime();
-
- var footer = new ClientUI.controls.grid.GridFooter($(item.ref), grid);
- layout.addPane(GridLayout_Enum.FOOTER, footer);
-
- //TODO: delete
- document.footerStopTime = (new Date()).getTime();
-
- break;
- }
- }
- });
-
- //TODO: delete
- document.gridParseTime = (new Date()).getTime();
-
- this.currentScrollPos = 0;
- this.controlCreated = true;
- this.updateLayout();
-
- //TODO: delete
- document.gridEndTime = (new Date()).getTime();
- },
- updateLayout: function() {
- if(!this.controlCreated) {
- return;
- }
- ClientUI.controls.grid.Grid.parentClass.method("updateLayout").call(this);
- if(this.layout) {
- this.layout.updateLayout();
- }
- },
- getHeader: function() {
- return this.layout.getPane(GridLayout_Enum.HEADER);
- },
- getFooter: function() {
- return this.layout.getPane(GridLayout_Enum.FOOTER);
- },
- getBody: function() {
- return this.layout.getPane(GridLayout_Enum.BODY);
- },
- adjustColumnWidth: function(index, width) {
- this.getHeader().adjustColumnWidth(index, width);
- this.getBody().adjustColumnWidth(index, width);
- this.getFooter().adjustColumnWidth(index, width);
- this.updateLayout();
- this.eventOnResizeColumn.fire(index, width);
- },
- adjustScrollPosition: function(pos) {
- if(pos<0) {pos = 0;}
- this.currentScrollPos = pos;
- this.getHeader().adjustScrollPosition(pos);
- this.getBody().adjustScrollPosition(pos);
- if(this.getFooter()) {this.getFooter().adjustScrollPosition(pos);}
- },
- getScrollOffset: function() {
- return this.currentScrollPos;
- },
- setColumnMinWidth: function(index, width) {
- if(index<0 || index>=this.getHeader().getColumns().length)
- return false;
- this.getHeader().getColumns()[index].minWidth = width;
- return true;
- },
- getColumnsTotalWidth: function() {
- var totalWidth = 0;
- var columns = this.getHeader().getColumns();
- for(var i=0; i<columns.length; i++) {
- totalWidth += columns[i].width;
- }
- return totalWidth;
- },
- getColumnsFrozenWidth: function() {
- var totalWidth = 0;
- var columns = this.getHeader().getColumns();
- var i = 0;
- while(i<columns.length && columns[i].frozen) {
- totalWidth += columns[i++].width;
- }
- return totalWidth;
- },
- invalidate: function(params) {
- this.getBody().invalidate(params);
- },
- adjustColumnsWidth: function() {
- var columns = this.getHeader().getColumns();
- for(var i=0; i<columns.length; i++) {
- this.adjustColumnWidth(i, columns[i].width);
- }
- },
- setProgressCtrl: function(ctrl) {
- this.getBody().setProgressCtrl(ctrl);
- }
-})
-
-var ClientUI_controls_grid_Grid_idGenerator = 0;
-
Modified: trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody.js
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody.js 2007-06-04 13:59:14 UTC (rev 992)
+++ trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody.js 2007-06-04 13:59:26 UTC (rev 993)
@@ -476,7 +476,17 @@
this.splash.setSize(this.scrollBox.getViewportWidth(), this.scrollBox.getViewportHeight());
this.splash.updateLayout();
},
-
+ forceReRender: function() {
+ if(ClientUILib.isIE && !ClientUILib.isIE7) {
+ var frozenTbl = this.templFrozen.getElement();
+ var normalTbl = this.templNormal.getElement();
+ // force to rerender table !!!
+ var tr = frozenTbl.insertRow();
+ frozenTbl.deleteRow(tr.rowIndex);
+ tr = normalTbl.insertRow();
+ normalTbl.deleteRow(tr.rowIndex);
+ }
+ },
rearrangeRows: function(options, updateCash, showContainer) {
var frozenTbl = this.templFrozen.getElement();
var normalTbl = this.templNormal.getElement();
@@ -498,6 +508,8 @@
cash.setRow(index+i, {f: frows[i].innerHTML, n: nrows[i].innerHTML});
}
}
+
+ this.forceReRender();
}
else if(options.switchType === 1 || options.switchType === 2) {
// store visible row pos to restore after rows reerrange
Deleted: trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody2.js
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody2.js 2007-06-04 13:59:14 UTC (rev 992)
+++ trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody2.js 2007-06-04 13:59:26 UTC (rev 993)
@@ -1,715 +0,0 @@
-/*
- * TODO: Copyright (c) 2007 Denis Morozov <dmorozov(a)exadel.com>
- *
- * ...
- */
-ClientUILib.declarePackage("ClientUI.controls.grid.GridBody");
-
-ClientUILib.requireClass("ClientUI.common.box.Box");
-ClientUILib.requireClass("ClientUI.common.box.SplashBox");
-ClientUILib.requireClass("ClientUI.controls.grid.DataCash");
-
-/*
- * GridHeader.js - Grid control header pane
- * TODO: add comments
- */
-ClientUI.controls.grid.GridBody = Class.create({
- CLASSDEF: {
- name: 'ClientUI.controls.grid.GridBody',
- parent: ClientUI.common.box.Box
- }
-
-});
-
-Object.extend(ClientUI.controls.grid.GridBody.prototype, {
- /**
- * Count of rows can be viewed in the same time in grid
- */
- dataVisible: 50,
-
- /**
- * Count of rows loaded additianally to dataVisible rows
- */
- dataDelta: 5,
-
- /**
- * Current data position
- */
- currentPos: 0,
-
- /**
- * Constructor
- * @param {Object} template for Grid body row
- * @param {Object} grid parent grid object
- */
- initialize: function(template, grid) {
- this.grid = grid;
- ClientUI.controls.grid.GridBody.parentClass.constructor().call(this, template);
-
- // declare event listeners
- this._eventOnHScroll = this._onContentHScroll.bind(this);
- this._eventOnVScroll = this._onContentVScroll.bind(this);
- this._eventOnDataReady = this._onDataReady.bind(this);
-
- this.createControl(template);
- this.registerEvents();
- this.updateLayout();
- },
- registerEvents: function() {
- Event.observe(this.scrollBox.eventHScroll, "grid body hscroll", this._eventOnHScroll);
- Event.observe(this.scrollBox.eventVScroll, "grid body vscroll", this._eventOnVScroll);
- Event.observe(this.grid.dataModel.eventDataReady, "grid data is loaded", this._eventOnDataReady);
- },
- destroy: function() {
- Event.stopObserving(this.scrollBox.eventHScroll, "grid body hscroll", this._eventOnHScroll);
- Event.stopObserving(this.scrollBox.eventVScroll, "grid body vscroll", this._eventOnVScroll);
- Event.stopObserving(this.grid.dataModel.eventDataReady, "grid data is loaded", this._eventOnDataReady);
- },
- // event listeners
- _onContentHScroll: function(xpos) {
- this.grid.adjustScrollPosition(xpos);
- },
- _onDataReady: function(options) {
- // load rows data
- var currTime = (new Date()).getTime();
-
- this.invalidate(options);
-
- var loadTime = (new Date()).getTime();
-
- ClientUILib.log(ClientUILogger.ERROR, "Total time of data loading of "+options.count+" rows is: " + (loadTime - this.taskDefineTime) + " miliseconds.");
- ClientUILib.log(ClientUILogger.WARNING, "start index: " + options.index + ", and startRow: " + options.startRow);
- ClientUILib.log(ClientUILogger.WARNING, "data prepare time: " + (this.taskStartLoadingTime - this.taskStartTime));
-
- ClientUILib.log(ClientUILogger.WARNING, "data load time: " + (currTime - document.cntStart));
- ClientUILib.log(ClientUILogger.WARNING, "invalidation time: " + (loadTime - currTime));
- },
- _onContentVScroll: function(ypos) {
- this.helpObject1.moveToY(this.sizeBox.getHeight()+ this.defaultRowHeight + 5);
- this.helpObject2.moveToY(this.sizeBox.getHeight()+ this.defaultRowHeight + 5);
- this.setScrollPos(ypos);
- this.adjustDataPosition(ypos);
- },
- createControl: function(template) {
-
- var childs = template.childNodes;
- for(var i=0; i<childs.length; i++) {
- if(childs[i].tagName && childs[i].tagName.toLowerCase() == "div") {
- this.container = new ClientUI.common.box.Box(childs[i], null, true);
- break;
- }
- }
-
- // create scroll box
- this.scrollBox = new ClientUI.common.box.ScrollableBox(null, this.getElement());
- this.scrollBox.makeAbsolute();
- this.scrollBox.setWidth(this.getWidth());
- this.scrollBox.setHeight(this.getHeight());
- this.sizeBox = new ClientUI.common.box.Box(null, this.scrollBox.getElement());
- this.sizeBox.makeAbsolute();
-
- var normal = null, frozen = null;
- var childs = this.container.getElement().childNodes;
- for(var i=0; i<childs.length; i++) {
- if(childs[i].id && childs[i].id.indexOf("FrozenBox")>=0) {
- frozen = childs[i];
- }
- else if(childs[i].id && childs[i].id.indexOf("NormalBox")>=0){
- normal = childs[i];
- }
- }
-
- if(!normal || !frozen) {
- errMsg = "Unable to parse template for GridBody. Unable to find FrozenBox or NormalBox.";
- ClientUILib.log(ClientUILogger.ERROR, errMsg);
- throw(errMsg);
- }
- this.contentBox = new ClientUI.common.box.Box(normal);
- this.contentBox.makeAbsolute();
- this.frozenContentBox = new ClientUI.common.box.Box(frozen);
- this.frozenContentBox.makeAbsolute();
-
- this.helpObject1 = new ClientUI.common.box.Box($(document.createElement("img")), this.contentBox.getElement());
- this.helpObject1.setWidth(10);
- this.helpObject1.setHeight(10);
- this.helpObject1.makeAbsolute();
- this.helpObject2 = new ClientUI.common.box.Box($(document.createElement("img")), this.frozenContentBox.getElement());
- this.helpObject2.setWidth(10);
- this.helpObject2.setHeight(10);
- this.helpObject2.makeAbsolute();
-
- // create row template
- var ch = this.frozenContentBox.getElement().firstChild;
- while(ch) {
- if(ch.tagName && ch.tagName.toLowerCase()=="table") {
- this.templFrozen = new ClientUI.common.box.Box($(ch), null, true);
- this.templFrozen.makeAbsolute();
- break;
- }
- ch = ch.nextSibling;
- }
- ch = this.contentBox.getElement().firstChild;
- while(ch) {
- if(ch.tagName && ch.tagName.toLowerCase()=="table") {
- this.templNormal = new ClientUI.common.box.Box($(ch), null, true);
- this.templNormal.makeAbsolute();
- break;
- }
- ch = ch.nextSibling;
- }
-
- this.parseTemplate(this.templFrozen.getElement(), this.templNormal.getElement());
-
- // init cash with initial data
- var cash = this.getCash();
- var frows = this.templFrozen.getElement().rows;
- var nrows = this.templNormal.getElement().rows;
- var count = this.rowsCount;
- for(var i=0; i<count; i++) {
- cash.setRow(i, {f: frows[i].innerHTML, n: nrows[i].innerHTML});
- }
-
- this.controlCreated = true;
- },
- parseTemplate: function(templFrozen, templNormal) {
- if(!templNormal || !templNormal.rows || templNormal.rows.length===0) {
- return false;
- }
-
- this.rowsCount = templNormal.rows.length;
- this.defaultRowHeight = Element.getHeight(templNormal.rows[0].cells[0]);
- if(ClientUILib.isGecko) {
- this.defaultRowHeight -= this.getBorderWidth("tb") + this.getPadding("tb");
- }
- this.helpObj = new ClientUI.common.box.Box(templFrozen, null, true);
- this.countToLoad = 0;
- this.startRow = 0;
- this.startIndex = 0;
- this.currRange = $R(0, this.rowsCount);
-
- return true;
- },
- setScrollPos: function(pos) {
- ClientUILib.log(ClientUILogger.ERROR, "setScrollPos: " + pos);
- this.contentBox.getElement().scrollTop = pos;
- this.frozenContentBox.getElement().scrollTop = pos;
- if(ClientUILib.isIE && !ClientUILib.isIE7) {
- this.contentBox.getElement().scrollTop = pos;
- this.frozenContentBox.getElement().scrollTop = pos;
- }
- },
- updateLayout: function() {
- if(!this.controlCreated || !this.grid.controlCreated) {
- return;
- }
- ClientUI.controls.grid.GridBody.parentClass.method("updateLayout").call(this);
- if(!this.scrollBox || !this.contentBox || !this.sizeBox) {
- return;
- }
-
- var totalWidth = this.grid.getColumnsTotalWidth();
- this.scrollBox.moveTo(0, 0);
- this.scrollBox.setWidth(this.getWidth());
- this.scrollBox.setHeight(this.getHeight());
-
- var scrollLeft = this.contentBox.getElement().scrollLeft;
- var height = this.scrollBox.getViewportHeight();
- var fixH = this.grid.getFooter() ? this.grid.getFooter().getHeight() : 0;
- if(fixH > height) fixH = 0;
-
- var frozenContentWidth = this.grid.getColumnsFrozenWidth();
-
- this.frozenContentBox.moveTo(0, 0);
- this.contentBox.moveTo(frozenContentWidth, 0);
- this.sizeBox.moveTo(0, 0);
- this.sizeBox.setWidth(totalWidth);
- this.sizeBox.setHeight(this.defaultRowHeight * this.grid.dataModel.getCount() + fixH);
- this.helpObject1.moveToY(this.sizeBox.getHeight()+ this.defaultRowHeight + 5);
- this.helpObject2.moveToY(this.sizeBox.getHeight()+ this.defaultRowHeight + 5);
-
- this.container.setWidth(totalWidth + 100);
- this.contentBox.setWidth(this.scrollBox.getViewportWidth()-frozenContentWidth);
- this.contentBox.setHeight(height - fixH);
- this.frozenContentBox.setWidth(frozenContentWidth);
- this.frozenContentBox.setHeight(height - fixH);
-
- this.scrollBox.setWidth(this.getWidth()+1);
- this.scrollBox.setHeight(this.getHeight()+1);
- this.scrollBox.setWidth(this.getWidth());
- this.scrollBox.setHeight(this.getHeight());
-
- var scrollPos = Math.min(totalWidth - frozenContentWidth - this.contentBox.getWidth(), scrollLeft);
- this.grid.adjustScrollPosition(scrollPos);
-
- this.dataVisible = parseInt(this.contentBox.getHeight() / this.defaultRowHeight, 10) + 1;
- this.dataVisible = Math.min(this.dataVisible, this.rowsCount);
- if(height > 0) {
- this.adjustDataPosition(this.currentPos);
- }
- },
- adjustScrollPosition: function(pos) {
- this.contentBox.getElement().scrollLeft = pos;
- },
- getScrollYPosition: function() {
- return this.contentBox.getElement().scrollTop;
- },
- adjustDataPosition: function (pos) {
- if(this.currentPos == pos) {
- return;
- }
-
- // 1. calculate direction and range to load next data
- this.processedPos = pos;
- var forwardDir = (this.currentPos <= pos) ? true : false;
-
- // first visible row index
- var first = parseInt(pos / this.defaultRowHeight) - 1;
- if(first < 0) first = 0;
-
- // check direction and predict some next rows
- var from = Math.max(first - (forwardDir ? 1 : (this.rowsCount - this.dataVisible - 1)), 0);
- var to = Math.min(first + (forwardDir ? this.rowsCount-1 : this.dataVisible + 1), this.grid.dataModel.getCount());
-
- if(from == 0) {
- to = this.rowsCount;
- }
- else if(to == this.grid.dataModel.getCount()) {
- from = to - this.rowsCount;
- }
-
- var range = $R(from, to);
-
- if(this.currRange.start == from && this.currRange.end == to) {
- return;
- }
-
- if(from >= to) {
- ClientUILib.log(ClientUILogger.WARNING, "!!! GridBody: adjustDataPosition. Pos: " + pos + ", From:" + from + ", To:" + to);
- return;
- }
-
- var task = this._getPendingTask();
- if(to - from > 0) {
- task.timer = null;
- task.from = from;
- task.to = to;
- task.first = first;
- task.pos = pos;
- this._setPendingTask(task);
- }
- },
- _getPendingTask: function() {
- if(!this.pendingTask) {
- this.pendingTask = {
- timer: null,
- rowsToLoad: [],
- rowsToLoadIdx: [],
- from: 0,
- to: 0,
- first: 0,
- pos: 0
- };
- }
- return this.pendingTask;
- },
- _setPendingTask: function(task) {
- clearTimeout(this.pendingTask.timer);
- this.pendingTask.timer = null;
- this.pendingTask = task;
-
- // and plan other agjusting over the time
- task.timer = setTimeout(function() {
- this.startLoadData();
- }.bind(this), this.grid.dataModel.getRequestDelay());
- },
- adjustColumnWidth: function(column, width) {
- var frozenColumns = this.grid.getHeader().headerFrozenRow.getElement().rows[0].cells.length;
- var realColumn = column;
- var table = null;
- if(column < frozenColumns) {
- table = this.frozenContentBox.getElement();
- }
- else {
- table = this.contentBox.getElement();
- realColumn -= frozenColumns;
- }
-
- var helpObj = this.helpObj;
- var id = "bc_" + column;
- var spans = $A(table.getElementsByTagName("span"));
- spans.each(function(cell) {
- if(cell.id.indexOf(id)>=0) {
- helpObj.element = $(cell);
- helpObj.setWidth(width);
- }
- });
- },
- startLoadData: function() {
- if(this.updateStarted) {
- this._setPendingTask(this._getPendingTask());
- return;
- }
-
- this.updateStarted = true;
- this.taskStartTime = (new Date()).getTime();
-
- var task = this._getPendingTask();
- var range = $R(task.from, task.to);
- var switchType = 5;
- var startIndex = 0;
- var startRowIndx = 0;
- var countToLoad = 0;
-
- // if we have intersepted ranges than rearrange rows
- // in other case just move rows table to first position
- if(this.currRange.end < range.start
- || this.currRange.start > range.end) {
- switchType = 0;
- }
-
- if(switchType === 0) {
- startRowIndx = this._getRowIndex(this.templFrozen.getElement().rows[0].id);
- startIndex = range.start;
- countToLoad = range.end - range.start;
- }
- else {
- var i, row, rownew, cloned;
- countToLoad = 0;
- var frozenTbl = this.templFrozen.getElement();
- var normalTbl = this.templNormal.getElement();
- if(range.start > this.currRange.start
- && range.start < this.currRange.end) {
- switchType = 1;
- countToLoad = range.start - this.currRange.start;
- if(countToLoad > 0) {
- startRowIndx = this._getRowIndex(frozenTbl.rows[0].id);
- startIndex = this.currRange.end;
- }
- }
- else if(range.start == this.currRange.start) {
- switchType = 3;
- countToLoad = range.end - this.currRange.end;
- if(countToLoad > 0) {
- startIndex = this.currRange.end;
- var restCount = this.rowsCount - countToLoad;
- startRowIndx = this._getRowIndex(frozenTbl.rows[restCount].id);
- }
- }
- else {
- switchType = 2;
- countToLoad = this.currRange.start - range.start;
- if(countToLoad > 0) {
- startIndex = range.start;
- var restCount = this.rowsCount - countToLoad;
- startRowIndx = this._getRowIndex(frozenTbl.rows[restCount].id);
- }
- }
- }
-
- this.taskStartLoadingTime = (new Date()).getTime();
-
- var process = true;
- if(startIndex > (task.first + this.dataVisible) ||
- (startIndex + countToLoad) < task.first) {
- process = false;
- }
- if(countToLoad > 0 && process) {
- this.updateStarted = true;
- ClientUILib.log(ClientUILogger.WARNING, "Start loading...");
- ClientUILib.log(ClientUILogger.WARNING, "start index: " + startIndex + ", and startRow: " + startRowIndx + ", and count: " + countToLoad);
- this.currRange = range;
- this.currentPos = task.pos;
-
- this.taskDefineTime = (new Date()).getTime();
-
- this.showSplash();
- this.container.hide();
-
- var options = {
- index: startIndex,
- count: countToLoad,
- startRow: startRowIndx,
- switchType: switchType
- };
- var opt = {
- index: options.index,
- count: options.count,
- startRow: options.startRow,
- switchType: options.switchType
- };
- options = this.processCashedValues(options);
- if(options.count > 0) {
- // Make timer to handle quick clicks on scrollbar arrows
- setTimeout(function() {
-
- // 4. start data loading
- this.updateInterval = screen.updateInterval;
- screen.updateInterval = 1000;
-
- this.grid.dataModel.loadRows(options);
- }.bind(this), 10);
- }
- else {
- this.invalidate(opt);
- this.updateStarted = false;
- }
- }
- else {
- this.updateStarted = false;
- }
- },
-
- setProgressCtrl: function(ctrl) {
- this.splash = ctrl;
- this.splash.setParent(this.getElement());
- this.splash.moveTo(0, 0);
- },
- showSplash: function () {
- if(!this.splash) {
- this.setProgressCtrl(new ClientUI.common.box.SplashBox(null, this.getElement(), 300));
- }
- this.splash.show();
- this.splash.setSize(this.scrollBox.getViewportWidth(), this.scrollBox.getViewportHeight());
- this.splash.updateLayout();
- },
-
- rearrangeRows: function(options, updateCash, showContainer) {
- var frozenTbl = this.templFrozen.getElement();
- var normalTbl = this.templNormal.getElement();
- var cash = this.getCash();
-
- if(options.switchType === 0) {
- var visibleRowPos = this.defaultRowHeight * options.index;
- var test = this.contentBox.getElement().scrollTop;
- if(showContainer) this._showContainer();
- this.templFrozen.moveToY(visibleRowPos);
- this.templNormal.moveToY(visibleRowPos);
-
- if(updateCash) {
- var frows = frozenTbl.rows;
- var nrows = normalTbl.rows;
- var count = frows.length;
- var index = options.index;
- for(var i=0; i<count; i++) {
- cash.setRow(index+i, {f: frows[i].innerHTML, n: nrows[i].innerHTML});
- }
- }
- }
- else if(options.switchType === 1 || options.switchType === 2) {
- // store visible row pos to restore after rows reerrange
- var count = frozenTbl.rows.length;
- var frows = new Array(count), nrows = new Array(count);
- var j = 0, i;
- var index = options.index;
-
- if(options.switchType === 1) {
- for(i=options.count; i<this.rowsCount; i++) {
- frows[j] = frozenTbl.rows[i];
- nrows[j] = normalTbl.rows[i];
- j++;
- }
- for(i=0; i<options.count; i++) {
- frows[j] = frozenTbl.rows[i];
- nrows[j] = normalTbl.rows[i];
- if(updateCash) {
- cash.setRow(index+i, {f: frows[j].innerHTML, n: nrows[j].innerHTML});
- }
- j++;
- }
- }
- else {
- for(i=this.rowsCount - options.count; i<this.rowsCount; i++) {
- frows[j] = frozenTbl.rows[i];
- nrows[j] = normalTbl.rows[i];
- if(updateCash) {
- cash.setRow(index+j, {f: frows[j].innerHTML, n: nrows[j].innerHTML});
- }
- j++;
- }
- for(i=0; i<this.rowsCount - options.count; i++) {
- frows[j] = frozenTbl.rows[i];
- nrows[j] = normalTbl.rows[i];
- j++;
- }
- }
-
-
- // Mozilla is faster when doing the DOM manipulations on
- // an orphaned element. MSIE is not
- var removeChilds = navigator.product == "Gecko";
- var fbody = frozenTbl.tBodies[0];
- var nbody = normalTbl.tBodies[0];
- var fnextSibling = fbody.nextSibling;
- var nnextSibling = nbody.nextSibling;
-
- if (removeChilds) { // remove all rows
- fp = fbody.parentNode;
- fp.removeChild(fbody);
- np = nbody.parentNode;
- np.removeChild(nbody);
- }
-
- // insert in the new order
- for (i = 0; i < count; i++) {
- fbody.appendChild(frows[i]);
- nbody.appendChild(nrows[i]);
- }
-
- if(removeChilds) {
- fp.insertBefore(fbody, fnextSibling);
- np.insertBefore(nbody, nnextSibling);
- }
-
- var visibleRowPos = (options.switchType == 1) ? this.currRange.start * this.defaultRowHeight : options.index * this.defaultRowHeight;
- if(showContainer) this._showContainer();
- this.templFrozen.moveToY(visibleRowPos);
- this.templNormal.moveToY(visibleRowPos);
- }
- else {
- if(updateCash) {
- var frows = frozenTbl.rows;
- var nrows = normalTbl.rows;
- var count = frows.length;
- var index = options.index;
- for(var i=0; i<count; i++) {
- cash.setRow(index+i, {f: frows[i].innerHTML, n: nrows[i].innerHTML});
- }
- }
- var visibleRowPos = this.currRange.start * this.defaultRowHeight;
- if(showContainer) this._showContainer();
- this.templFrozen.moveToY(visibleRowPos);
- this.templNormal.moveToY(visibleRowPos);
- }
- },
- _showContainer: function() {
- this.container.show();
- this.setScrollPos(this.currentPos);
- },
- /**
- * show hiden rows after loading them from datasource
- * @param {Object} options
- */
- invalidate: function(options) {
-
- ClientUILib.log(ClientUILogger.WARNING, "Stop loading.");
- screen.updateInterval = this.updateInterval;
-
- setTimeout(function () {
- this.rearrangeRows(options, true, true);
- this.container.show();
- this.splash.hide();
- this.updateStarted = false;
-
- }.bind(this), 10);
-
- /*if(this.processedPos != this.currentPos) {
- this.currentPos = this.processedPos;
- setTimeout(function (){
- this.pendedUpdate();
- }.bind(this), this.grid.dataModel.getRequestDelay());
- }*/
- },
- /*pendedUpdate: function() {
- if(this.processedPos != this.currentPos) {
- this.currentPos = this.processedPos;
- setTimeout(function (){
- this.pendedUpdate();
- }.bind(this), this.grid.dataModel.getRequestDelay());
- }
- else {
- this.adjustDataPosition(this.processedPos);
- }
- },*/
- getCash: function() {
- if(!this.cash) {
- this.cash = new ClientUI.controls.grid.DataCash(this.grid.dataModel.getCount());
- }
- return this.cash;
- },
- _restoreFromCash: function(options) {
- var count = options.count;
- var index = options.index;
- var startRow = options.startRow;
- var cash = this.getCash();
- var frows = this.templFrozen.getElement().rows;
- var nrows = this.templNormal.getElement().rows;
-
- var row, rowU, i=0;
- var rowC = cash.getRow(index);
- do {
- row = frows[startRow];
- rowU = row.cloneNode(true);
- rowU.innerHTML = rowC.f;
- row.parentNode.replaceChild(rowU, row);
-
- row = nrows[startRow];
- rowU = row.cloneNode(true);
- rowU.innerHTML = rowC.n;
- row.parentNode.replaceChild(rowU, row);
-
- i++;
- startRow++;
- if(startRow >= this.rowsCount) startRow = 0;
- rowC = cash.getRow(index + i);
- } while(i<count && rowC);
-
- setTimeout(function () {
- this.rearrangeRows(options);
- this.container.show();
- this.splash.hide();
- this.updateStarted = false;
-
- }.bind(this), 10);
- },
- processCashedValues: function(options) {
- return options;
-
- var opt = {switchType: options.switchType };
- var cash = this.getCash();
- var count = options.count;
- var index = options.index;
- var startRow = options.startRow;
-
- var i = 0;
- var rowC;
-
- while(i<count && (rowC = cash.getRow(index + i))!=null) i++;
- if(i>0) { // there are cashed rows from start
- opt.count = i;
- opt.index = index;
- opt.startRow = startRow;
- this._restoreFromCash(opt);
-
- options.count -= i;
- options.index = index+i;
- options.startRow = startRow+i;
- if(options.startRow >= this.rowsCount) options.startRow -= this.rowsCount;
- }
-
- var cnt = 0;
- while(i<count && !(rowC = cash.getRow(index + i))) { i++; cnt++; }
- if(i<count) { // there are cashed rows at the end of range
- opt.count = options.count - cnt;
- opt.index = index+i;
- opt.startRow = startRow+i;
- if(opt.startRow >= this.rowsCount) opt.startRow -= this.rowsCount;
- this._restoreFromCash(opt);
-
- options.count = cnt;
- options.index = index+(i-cnt);
- options.startRow = startRow+(i-cnt);
- if(options.startRow >= this.rowsCount) options.startRow -= this.rowsCount;
- }
-
- return options;
- },
- _getRowIndex: function(rowId) {
- // prefix:row_2
- var index = -1;
- var match, pattern = /\:row_(\d*)/i;
- if (match = rowId.match(pattern)) {
- index = parseFloat(match[1]);
- }
- return index;
- }
-});
Deleted: trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridFooter2.js
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridFooter2.js 2007-06-04 13:59:14 UTC (rev 992)
+++ trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridFooter2.js 2007-06-04 13:59:26 UTC (rev 993)
@@ -1,163 +0,0 @@
-/*
- * TODO: Copyright (c) 2007 Denis Morozov <dmorozov(a)exadel.com>
- *
- * ...
- */
-ClientUILib.declarePackage("ClientUI.controls.grid.GridFooter");
-
-ClientUILib.requireClass("ClientUI.common.box.Box");
-
-/*
-/* GridHeader.js - Grid control header pane
- * TODO: add comments
- */
-ClientUI.controls.grid.GridFooter = Class.create({
- CLASSDEF: {
- name: 'ClientUI.controls.grid.GridFooter',
- parent: ClientUI.common.box.Box
- }
-
-});
-
-Object.extend(ClientUI.controls.grid.GridFooter.prototype, {
- initialize: function(template, grid) {
- this.grid = grid;
- ClientUI.controls.grid.GridFooter.parentClass.constructor().call(this, template);
- this.createControl(template);
- },
- createControl: function(template) {
- var errMsg = "";
- if(!template) {
- errMsg = "Invalid template specified for GridFooter.";
- ClientUILib.log(ClientUILogger.ERROR, errMsg);
- throw(errMsg);
- }
-
- if(!this.parseTemplate(template)) {
- errMsg = "Unable to parse template. GridFooter requires template specified over table element with one row.";
- ClientUILib.log(ClientUILogger.ERROR, errMsg);
- throw(errMsg);
- }
-
- // Set dimensions
- this.setHeight(this.defaultHeight);
- this.setWidth(this.defaultWidth);
- this.controlCreated = true;
- this.updateLayout();
- },
- parseTemplate: function(template) {
- if(!template) {
- return false;
- }
-
- var childs = template.childNodes;
- for(var i=0; i<childs.length; i++) {
- if(childs[i].tagName && childs[i].tagName.toLowerCase() == "div") {
- this.container = $(childs[i]);
- break;
- }
- }
-
- var normal = null, frozen = null;
- var childs = this.container.childNodes;
- for(var i=0; i<childs.length; i++) {
- if(childs[i].id && childs[i].id.indexOf("FrozenBox")>=0) {
- frozen = childs[i];
- }
- else if(childs[i].id && childs[i].id.indexOf("NormalBox")>=0){
- normal = childs[i];
- }
- }
-
- if(!normal || !frozen) {
- errMsg = "Unable to parse template for GridFooter. Unable to find FrozenBox or NormalBox.";
- ClientUILib.log(ClientUILogger.ERROR, errMsg);
- throw(errMsg);
- }
- this.contentBox = new ClientUI.common.box.Box(normal);
- this.contentBox.makeAbsolute();
- this.frozenContentBox = new ClientUI.common.box.Box(frozen);
- this.frozenContentBox.makeAbsolute();
-
- // create row template
- var ch = this.contentBox.getElement().firstChild;
- while(ch) {
- if(ch.tagName && ch.tagName.toLowerCase()=="table") {
- this.headerRow = new ClientUI.common.box.Box($(ch), null, true);
- break;
- }
- ch = ch.nextSibling;
- }
- ch = this.frozenContentBox.getElement().firstChild;
- while(ch) {
- if(ch.tagName && ch.tagName.toLowerCase()=="table") {
- this.headerFrozenRow = new ClientUI.common.box.Box($(ch), null, true);
- break;
- }
- ch = ch.nextSibling;
- }
-
- this.helpObj = new ClientUI.common.box.Box(this.frozenContentBox.getElement(), null, true);
- this.defaultWidth = this.grid.getHeader().defaultWidth;
- this.defaultHeight = Element.getHeight(this.headerRow.getElement().rows[0].cells[0]);
- if(ClientUILib.isGecko) {
- this.defaultHeight -= this.getBorderWidth("tb") + this.getPadding("tb");
- //this.defaultWidth -= this.getBorderWidth("lr") + this.getPadding("lr");
- }
-
- if(ClientUILib.isIE) {
- this.frozenSubstrate = new ClientUI.common.box.Substrate(null, this.getElement());
- this.frozenSubstrate.getElement().name = this.getElement().id + "FRFrm";
- Element.addClassName(this.frozenSubstrate.getElement(), "ClientUI_HRFrm");
- this.frozenSubstrate.setHeight(this.defaultHeight);
- }
- return true;
- },
- updateLayout: function() {
- if(!this.controlCreated || !this.grid.controlCreated) {
- return;
- }
- ClientUI.controls.grid.GridFooter.parentClass.method("updateLayout").call(this);
-
- var height = this.getViewportHeight();
- var totalWidth = this.grid.getColumnsTotalWidth();
- var frozenContentWidth = this.grid.getColumnsFrozenWidth();
-
- this.contentBox.setWidth(Math.max(this.getWidth(), totalWidth));
- this.contentBox.setHeight(height);
- this.contentBox.moveTo(frozenContentWidth, 0);
- this.frozenContentBox.setWidth(frozenContentWidth);
- this.frozenContentBox.setHeight(height);
- this.frozenContentBox.moveTo(0, 0);
- var frozenContentWidth = this.grid.getBody().frozenContentBox.getWidth();
- var width = frozenContentWidth+this.grid.getBody().contentBox.getWidth();
- this.setWidth(width);
- if(ClientUILib.isIE)
- this.frozenSubstrate.setWidth(frozenContentWidth);
- },
- adjustScrollPosition: function(pos) {
- this.contentBox.moveToX(this.grid.getColumnsFrozenWidth()-pos);
- },
- adjustColumnWidth: function(column, width) {
- var frozenColumns = this.headerFrozenRow.getElement().rows[0].cells.length;
- var realColumn = column;
- var table = null;
- if(column < frozenColumns) {
- table = this.headerFrozenRow.getElement();
- }
- else {
- table = this.headerRow.getElement();
- realColumn -= frozenColumns;
- }
-
- var helpObj = this.helpObj;
- var id = "fc_" + column;
- var spans = $A(table.getElementsByTagName("span"));
- spans.each(function(cell) {
- if(cell.id.indexOf(id)>=0) {
- helpObj.element = $(cell);
- helpObj.setWidth(width);
- }
- });
- }
-})
Deleted: trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridHeader2.js
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridHeader2.js 2007-06-04 13:59:14 UTC (rev 992)
+++ trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridHeader2.js 2007-06-04 13:59:26 UTC (rev 993)
@@ -1,437 +0,0 @@
-/*
- * TODO: Copyright (c) 2007 Denis Morozov <dmorozov(a)exadel.com>
- *
- * ...
- */
-ClientUILib.declarePackage("ClientUI.controls.grid.GridHeader");
-
-ClientUILib.requireClass("ClientUI.common.box.Box");
-ClientUILib.requireClass("ClientUI.common.box.InlineBox");
-
-/*
- * GridHeader.js - Grid control header pane
- * TODO: add comments
- */
-ClientUI.controls.grid.GridHeader = Class.create({
- CLASSDEF: {
- name: 'ClientUI.controls.grid.GridHeader',
- parent: ClientUI.common.box.Box,
- sepStyleClass: "ClientUI_Grid_HSep"
- }
-
-});
-
-Object.extend(ClientUI.controls.grid.GridHeader.prototype, {
- // internal variables
- _columns: [],
-
- // constructor
- initialize: function(template, grid) {
- this.grid = grid;
-
- ClientUI.controls.grid.GridHeader.parentClass.constructor().call(this, template);
-
- // register event handlers
- this.eventSepDblClick = this.OnSepDblClick.bindAsEventListener(this);
- this.eventSepMouseDown = this.OnSepMouseDown.bindAsEventListener(this);
- this.eventSepMouseUp = this.OnSepMouseUp.bindAsEventListener(this);
- this.eventSepMouseMove = this.OnSepMouseMove.bindAsEventListener(this);
- this.eventCellMouseDown = this.OnCellMouseDown.bindAsEventListener(this);
- Event.observe(document, 'mousemove', this.eventSepMouseMove, true);
- Event.observe(document, 'mouseup', this.eventSepMouseUp, true);
-
- this.createControl(template);
- },
-
- // create grid header control
- createControl: function(template) {
- var errMsg = "";
- if(!template) {
- errMsg = "Invalid template specified for GridHeader.";
- ClientUILib.log(ClientUILogger.ERROR, errMsg);
- throw(errMsg);
- }
-
- if(!this.parseTemplate(template)) {
- errMsg = "Unable to parse template. GridHeader requires template specified over table element with one row.";
- ClientUILib.log(ClientUILogger.ERROR, errMsg);
- throw(errMsg);
- }
-
- // Set dimensions
- this.setHeight(this.defaultHeight);
- this.setWidth(this.defaultWidth);
- this.controlCreated = true;
- this.updateLayout();
- this.hide();
- this.show();
- },
- parseTemplate: function(template) {
- if(!template) {
- return false;
- }
-
- var childs = template.childNodes;
- for(var i=0; i<childs.length; i++) {
- if(childs[i].tagName && childs[i].tagName.toLowerCase() == "div") {
- this.container = $(childs[i]);
- break;
- }
- }
-
- var normal = null, frozen = null;
- var childs = this.container.childNodes;
- for(var i=0; i<childs.length; i++) {
- if(childs[i].id && childs[i].id.indexOf("FrozenBox")>=0) {
- frozen = childs[i];
- }
- else if(childs[i].id && childs[i].id.indexOf("NormalBox")>=0){
- normal = childs[i];
- }
- }
-
- if(!normal || !frozen) {
- errMsg = "Unable to parse template for GridHeader. Unable to find FrozenBox or NormalBox.";
- ClientUILib.log(ClientUILogger.ERROR, errMsg);
- throw(errMsg);
- }
- this.contentBox = new ClientUI.common.box.Box(normal);
- this.contentBox.makeAbsolute();
- this.frozenContentBox = new ClientUI.common.box.Box(frozen);
- this.frozenContentBox.makeAbsolute();
-
- // create row template
- var ch = this.contentBox.getElement().firstChild;
- while(ch) {
- if(ch.tagName && ch.tagName.toLowerCase()=="table") {
- this.headerRow = new ClientUI.common.box.Box($(ch), null, true);
- break;
- }
- ch = ch.nextSibling;
- }
- ch = this.frozenContentBox.getElement().firstChild;
- while(ch) {
- if(ch.tagName && ch.tagName.toLowerCase()=="table") {
- this.headerFrozenRow = new ClientUI.common.box.Box($(ch), null, true);
- break;
- }
- ch = ch.nextSibling;
- }
-
- this.helpObj = new ClientUI.common.box.Box(this.frozenContentBox.getElement(), null, true);
-
- var columns = [];
- var defaultWidth = 0;
- var defaultHeight = 0;
-
- var eventCellMouseDown = this.eventCellMouseDown.bind(this);
-
- // Get columns information
- var i = 0, h;
- var cells = $A(this.headerFrozenRow.getElement().rows[0].cells);
- cells.each(function(cell) {
- columns[i] = {
- width: Element.getWidth(cell),
- innerHTML: cell.innerHTML,
- styleClass: cell.className,
- id: cell.id,
- align: cell.align,
- valign: cell.vAlign,
- title: cell.title,
- minWidth: 10,
- frozen: true,
- fixedWidth: Validators.getBoolean(cell.getAttribute("fixedWidth"), false),
- sortable: Validators.getBoolean(cell.getAttribute("sortable"), false),
- sorted: Validators.getBoolean(cell.getAttribute("sorted"), "desc")
- };
-
- if(columns[i].sortable)
- Event.observe(cell, 'click', eventCellMouseDown);
- h = Element.getHeight(cell);
- if(h > defaultHeight) defaultHeight = h;
- defaultWidth += columns[i].width;
- columns[i].object = new ClientUI.common.box.InlineBox(cell, null, true);
- columns[i].sortDesc = document.getElementsByClassName("sort-desc", cell)[0];
- columns[i].sortAsc = document.getElementsByClassName("sort-asc", cell)[0];
- if(ClientUILib.isIE && columns[i].sortDesc) {
- Element.setStyle(columns[i].sortDesc, {left: "-10px"});
- Element.setStyle(columns[i].sortAsc, {left: "-10px"});
- }
- i++;
- });
-
- cells = $A(this.headerRow.getElement().rows[0].cells);
- cells.each(function(cell) {
- columns[i] = {
- width: Element.getWidth(cell),
- innerHTML: cell.innerHTML,
- styleClass: cell.className,
- id: cell.id,
- align: cell.align,
- valign: cell.vAlign,
- title: cell.title,
- minWidth: 10,
- frozen: false,
- fixedWidth: Validators.getBoolean(cell.getAttribute("fixedWidth"), false),
- sortable: Validators.getBoolean(cell.getAttribute("sortable"), false),
- sorted: Validators.getBoolean(cell.getAttribute("sorted"), "desc")
- };
-
- if(columns[i].sortable)
- Event.observe(cell, 'click', eventCellMouseDown);
- h = Element.getHeight(cell);
- if(h > defaultHeight) defaultHeight = h;
- defaultWidth += columns[i].width;
- columns[i].object = new ClientUI.common.box.InlineBox(cell, null, true);
- columns[i].sortDesc = document.getElementsByClassName("sort-desc", cell)[0];
- columns[i].sortAsc = document.getElementsByClassName("sort-asc", cell)[0];
- if(ClientUILib.isIE && columns[i].sortDesc) {
- Element.setStyle(columns[i].sortDesc, {left: "-10px"});
- Element.setStyle(columns[i].sortAsc, {left: "-10px"});
- }
- i++;
- });
-
- columns.pop(); // remove last fake column
- this._columns = columns;
- this.defaultHeight = defaultHeight;
- this.defaultWidth = defaultWidth;
- if(ClientUILib.isGecko) {
- this.defaultWidth -= this.getBorderWidth("lr") + this.getPadding("lr");
- this.defaultHeight -= this.getBorderWidth("tb") + this.getPadding("tb");
- }
-
- var sep, column;
- var seps = document.getElementsByClassName("ClientUI_Grid_HSep", this.getElement());
- for(i = 0; i<seps.length; i++) {
- sep = seps[i];
- column = parseInt(sep.getAttribute("column"));
- this._columns[column].sep = new ClientUI.common.box.InlineBox(sep, null, true);
- sep.columnIndex = column;
- if(!this._columns[column].fixedWidth) {
- Event.observe(sep, 'dblclick', this.eventSepDblClick);
- Event.observe(sep, 'mousedown', this.eventSepMouseDown);
- }
- else {
- sep.setStyle({cursor: 'auto'});
- }
- }
- this.agjustSeparators();
-
- if(ClientUILib.isIE) {
- this.frozenSubstrate = new ClientUI.common.box.Substrate(null, this.getElement());
- this.frozenSubstrate.getElement().name = this.getElement().id + "HRFrm";
- Element.addClassName(this.frozenSubstrate.getElement(), "ClientUI_HRFrm");
- this.frozenSubstrate.setHeight(this.headerRow.getViewportHeight());
- }
-
- return true;
- },
- agjustSeparators: function() {
- var offset = 0;
- var fcnt = this.headerFrozenRow.getElement().rows[0].cells.length;
- for(var i=0; i<this._columns.length; i++) {
- if(i == fcnt) offset = 0;
- offset += this._columns[i].width;
- this._columns[i].sep.moveToX(offset - 4);
- }
- },
- updateLayout: function() {
- if(!this.controlCreated || !this.grid.controlCreated) {
- return;
- }
- ClientUI.controls.grid.GridHeader.parentClass.method("updateLayout").call(this);
- var height = this.getViewportHeight();
- var totalWidth = this.grid.getColumnsTotalWidth();
- var frozenContentWidth = this.grid.getColumnsFrozenWidth();
-
- this.contentBox.setWidth(Math.max(this.getWidth(), totalWidth));
- this.contentBox.setHeight(height);
- this.contentBox.moveTo(frozenContentWidth, 0);
- this.frozenContentBox.setWidth(frozenContentWidth);
- this.frozenContentBox.setHeight(height);
- this.frozenContentBox.moveTo(0, 0);
- if(ClientUILib.isIE)
- this.frozenSubstrate.setWidth(frozenContentWidth);
- },
- getColumns: function() {
- return this._columns;
- },
- // lets implement column resizer
- OnSepMouseDown: function(event) {
- this.dragColumnInfo = {
- srcElement: Event.element(event),
- dragStarted: false,
- mouseDown: true,
- startX: Event.pointerX(event),
- originalX: 0
- };
- this.dragColumnInfo.object = this.getColumns()[this.dragColumnInfo.srcElement.columnIndex].object;
- this.dragColumnInfo.sep = this.getColumns()[this.dragColumnInfo.srcElement.columnIndex].sep;
- this.dragColumnInfo.minWidth = this.getColumns()[this.dragColumnInfo.srcElement.columnIndex].minWidth;
-
- Event.stop(event);
- },
- OnSepMouseUp: function(event) {
- if(this.dragColumnInfo && this.dragColumnInfo.dragStarted) {
- this.dragColumnInfo.dragStarted = false;
- this.dragColumnInfo.mouseDown = false;
- var delta = Event.pointerX(event) - this.dragColumnInfo.startX;
- var newWidth = this.dragColumnInfo.object.getWidth() + delta;
- setTimeout(function() {
- this.grid.adjustColumnWidth(this.dragColumnInfo.srcElement.columnIndex, newWidth);
- }.bind(this), 10);
- }
- this._hideSplitter();
- },
- OnSepMouseMove: function(event) {
- if(this.dragColumnInfo && this.dragColumnInfo.mouseDown) {
- if(!this.dragColumnInfo.dragStarted) {
- this.dragColumnInfo.dragStarted = true;
- this._showSplitter(this.dragColumnInfo.srcElement.columnIndex);
- }
- else {
- var delta = Event.pointerX(event) - this.dragColumnInfo.startX;
- var minColumnWidth = this.dragColumnInfo.object.getWidth() - this.dragColumnInfo.minWidth;
- if(delta >= -minColumnWidth) {
- var x = this.dragColumnInfo.originalX + delta;
- this.columnSplitter.moveToX(x - 6);
- }
- }
- Event.stop(event);
- }
- },
- OnSepDblClick: function(event) {
- ClientUILib.log(ClientUILogger.INFO, "OnSepDblClick");
- },
- _showSplitter: function(index) {
- if(!this.columnSplitter) {
- this._createSplitter();
- }
-
- var pos = this.dragColumnInfo.sep.getX();
- if(!this.getColumns()[index].frozen) {
- pos += this.grid.getColumnsFrozenWidth() - this.grid.getScrollOffset();
- }
- this.dragColumnInfo.originalX = pos;
- this.columnSplitter.show();
- this.columnSplitter.setHeight(this.defaultHeight + this.grid.getBody().contentBox.getHeight());
- this.columnSplitter.moveTo(pos, 0);
- },
- _hideSplitter: function() {
- if(this.columnSplitter) {
- this.columnSplitter.hide();
- }
- },
- _createSplitter: function() {
- this.columnSplitter = new ClientUI.common.box.Box(null, this.grid.getElement());
- this.columnSplitter.makeAbsolute();
- this.columnSplitter.getElement().addClassName("ClientUI_Grid_HSplit");
- this.columnSplitter.setWidth(10);
- this.columnSplitter.getElement().setStyle({backgroundColor: ''});
- this.columnSplitter.getElement().setStyle({zIndex: '100'});
- this.columnSplitter.hide();
- },
- adjustScrollPosition: function(pos) {
- this.contentBox.moveToX(this.grid.getColumnsFrozenWidth()-pos);
- },
- OnCellMouseDown: function(event) {
- var el = Event.element(event);
- while(el && !Element.hasClassName(el, "ClientUI_Grid_HC")) {
- el = el.parentNode;
- }
-
- if(el) {
- var index = parseInt(el.getAttribute("columnIndex"));
- if(index>=0) {
- var dir = this.getColumns()[index].sorted;
- dir = (dir == "asc") ? "desc" : "asc";
- this.getColumns()[index].sorted = dir;
-
- for(var i = 0, len = this.getColumns().length; i < len; i++) {
- var h = this.getColumns()[i];
- if(i != index) {
- Element.setStyle(h.sortDesc, {display: 'none'});
- Element.setStyle(h.sortAsc, {display: 'none'});
- } else{
- Element.setStyle(h.sortDesc, {display: (dir == 'desc' ? 'block' : 'none')});
- Element.setStyle(h.sortAsc, {display: (dir == 'asc' ? 'block' : 'none')});
- }
- }
-
- this.grid.eventOnSort.fire({
- column: index,
- order: dir,
- startRow: this.grid.getBody().templFrozen.getElement().rows[0].index,
- index: this.grid.getBody().currRange.start
- });
- Event.stop(event);
- }
- }
- },
- _getVisibleHeaderControls: function() {
- var controls = [];
- var columns = this.getColumns();
- columns.each(function(column){
- var ctrls = column.object.getElement().getElementsByTagName("select");
- if(ctrls && ctrls.length>0) {
- ctrls = $A(ctrls);
- ctrls.each(function(ctrl){
- if(Element.visible(ctrl)) {
- controls.push(ctrl);
- }
- });
- }
- });
- return controls;
- },
- adjustColumnWidth: function(column, width) {
- var w = width, ch;
- var frozenColumns = this.headerFrozenRow.getElement().rows[0].cells.length;
- var realColumn = column;
- var table = null;
- if(column < frozenColumns) {
- table = this.headerFrozenRow.getElement();
- }
- else {
- table = this.headerRow.getElement();
- realColumn -= frozenColumns;
- }
-
- // Hide controls in IE that flipped in other case
- var ctrlsIE = [];
- if(ClientUILib.isIE) {
- ctrlsIE = this._getVisibleHeaderControls();
- ctrlsIE.each(function(ctrl){
- Element.hide(ctrl);
- });
- }
-
- var childs = table.rows[0].cells[realColumn].childNodes;
- this.helpObj.element = $(table.rows[0].cells[realColumn]);
- var delta = 0;
- if(ClientUILib.isGecko) {
- delta = this.helpObj.getBorderWidth("lr") + this.helpObj.getPadding("lr");
- }
- this.helpObj.setWidth(width - delta);
- delta *= 2;
-
- for (var j=0; j<childs.length; j++) {
- ch = childs[j];
- if(ch.tagName && ch.tagName.toLowerCase() == "span") {
- this.helpObj.element = $(ch);
- this.helpObj.setWidth(width - delta);
- break;
- }
- }
-
- if(ClientUILib.isIE) {
- ctrlsIE.each(function(ctrl){
- Element.show(ctrl);
- });
- }
-
- this._columns[column].width = width;
- this.agjustSeparators();
- }
-});