Your IP : 18.219.40.177
/**
* resize cols in table
* @param {object} window global object
* @param {object|function} $ jQuery
* @param {object} EventMgr Event manager
* @param {object} App Application
*/
App.TableRowResize = function(window, $, EventMgr, App) {
'use strict';
var init = function() {
EventMgr.on('#content', '.content .rowHandler',
'mousedown', tableResizeHandler);
},
shiftX = 0,
self = '',
left = '',
lastPos,
cWidth = '',
pcWidth = '',
prevCol = '',
curCol = '',
// min width of col (2% of table width)
minWidth = '',
tabId,
tableResizeHandler = function(e) {
e = e || window.event;
shiftX = e.clientX;
document.onmousemove = move;
document.onmouseup = drop;
this.style.position = 'absolute';
calcBounds(this);
var actTab = $('.tab-content_st_active .content'),
h = actTab.height();
tabId = actTab.attr('data-tabid');
this.style.height = h + 'px';
left = this.offsetLeft;
self = this;
blockEvent(e);
},
move = function(e) {
e = e || window.event;
var newpos = e.clientX - shiftX;
if (checkBounds(newpos)) {
lastPos = newpos;
}
self.style.left = left + lastPos + 'px';
blockEvent(e);
},
drop = function(e) {
var param = setNewWidths();
self.style.height = '100%';
self.style.left = '';
self.style.position = '';
document.onmouseup = null;
document.onmousemove = null;
self = '';
if (!param) { return; }
param.func = 'colwidth';
param.out = 'xml';
param.elid = App.Tabs.tabs[tabId].func;
EventMgr.trigger('ajaxRequest', {
param: param,
trfunc: 'DoNothing',
queue: 'noqueue'});
},
calcBounds = function(self) {
//width all table
var twidth = $('.tab-content_st_active .list_table').width(),
per;
curCol = self.parentNode;
//width cur col
cWidth = curCol.offsetWidth;
prevCol = App.Common.getPreviousNode(curCol);
// width prev col
pcWidth = prevCol.offsetWidth;
// one percent of width table in pixel
per = twidth / 100;
minWidth = 2 * per;
},
checkBounds = function(newpos) {
if (newpos >= 0) {
if ((cWidth - newpos) < minWidth) {
return false;
}
} else {
if ((pcWidth + newpos) < minWidth) {
return false;
}
}
return true;
},
//set new width for cols when drag
setNewWidths = function() {
if (!lastPos) { return undefined; }
var curColWidth = parseInt(curCol.style.width, 10),
curPrevColWidth = parseInt(prevCol.style.width, 10),
sumWidth = curColWidth + curPrevColWidth,
newWidth,
otherWidth;
if (lastPos > 0) {
newWidth = 2 * (cWidth - lastPos) / minWidth;
newWidth = (newWidth > 2) ? newWidth : 2;
curCol.style.width = Math.round(newWidth) + '%';
otherWidth = sumWidth - newWidth;
otherWidth = (otherWidth > 2) ? otherWidth : 2;
prevCol.style.width = Math.round(otherWidth) + '%';
} else {
newWidth = 2 * (pcWidth + lastPos) / minWidth;
newWidth = (newWidth > 2) ? newWidth : 2;
prevCol.style.width = Math.round(newWidth) + '%';
otherWidth = sumWidth - newWidth;
otherWidth = (otherWidth > 2) ? otherWidth : 2;
curCol.style.width = Math.round(otherWidth) + '%';
}
lastPos = undefined;
return syncCols();
},
//sync col width on list table
syncCols = function() {
var colWidth = {};
$('.tab-content_st_active .sort_table td').each(function(index) {
var name = this.getAttribute('data-colname'),
width = parseInt(this.style.width, 10),
id = 'lt-' + ($(this).parents('.sort_table')
.attr('id')).replace('sort_table-', '');
// set width in pixel
this.firstChild.style.width = width * (minWidth / 2) + 'px';
colWidth[name] = width;
//for body table
$('.tab-content_st_active .list_table#' + id +
' tbody tr:first td:eq(' + index + ')').width(width + '%');
//for head table
$('.tab-content_st_active .list_table#' + id +
' th[data-colname="' + name + '"]').width(width + '%');
//for statusbar table
$('.tab-content_st_active .statusbar td[data-colname="' +
name + '"]').width(width + '%');
});
return colWidth;
};
return {
init: init
};
}(window, $, EventMgr, App);