1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707
"use strict";
modulum('TableWidget', ['TableWidgetBase'],
function(context, cls) {
cls.TableWidget = context.oo.Class(cls.TableWidgetBase, function($super) {
return {
__name: "TableWidget",
_stylingContext: "widget",
$static: {
defaultRowHeight: 14
},
_lastClickDate: null,
_lastClickTarget: null,
_currentColumn: 0,
_orderedColumns: null,
_addOnlyVisibleColumnsToDom: true,
_layoutDone: false,
_hasFooter: false,
_firstDisplay: true,
_needToUpdateVerticalScroll: false,
_focusOnField: false,
_requestSynchronizeHeadersHeight: false,
_rowBoundColumnWidget: null,
_defaultItemSelection: false,
_firstItemSelected: null,
_itemSelectionInProgress: false,
_itemSelectionHasChanged: false,
_itemSelectionElement: null,
_leftContainerElement: null,
_rightContainerElement: null,
_columnsContainerElement: null,
_leftColumnsContainer: null,
_rightColumnsContainer: null,
_columnsHeaders: null,
_leftColumnsHeaders: null,
_rightColumnsHeaders: null,
_columnsFooter: null,
_rightScrollAreaElement: null,
_leftScrollAreaElement: null,
_replacerElement: null,
_aggregateGlobalTextElement: null,
_scrollAreaNoUserScroll: false,
_rightScrollAreaNoUserScroll: false,
_scrollAreaResetScrollTopFromPrevious: false,
_uniqueScrollUnbindId: 0,
_activeUniqueIdScrolls: null,
_frozenTable: false,
_leftFrozenColumns: 0,
_rightFrozenColumns: 0,
_previousScrollLeftValue: 0,
_previousScrollTopValue: 0,
lastSentOffset: null,
_dndItemEnabled: false,
_dndMode: null,
_dndMouseDragX: null,
_dndReorderingDragOverWidget: null,
_dndDraggedColumnWidget: null,
_noDrop: null,
_highlightCurrentCell: null,
_showGrid: null,
_headerAlignment: null,
_headerHidden: null,
_resizeFillsEmptySpace: false,
_columnResizeFillsEmptySpace: null,
_selectionSquareIdx: null,
constructor: function(opts) {
this._noDrop = {
"left": false,
"right": false,
"center": false
};
$super.constructor.call(this, opts);
},
_preventDefault: function(event) {
this._dndMouseDragX = event.clientX || event.screenX;
if (this._dndMode) {
event.preventCancelableDefault();
}
},
_whenParentActivated: function(opt) {
$super._whenParentActivated.call(this, opt);
var widgetActivated = opt.data.length > 0 && opt.data[0];
if (this.isChildOf(widgetActivated)) {
var contextScrollLeft = this._previousScrollLeftValue;
this._previousScrollLeftValue = 0;
this.afterDomMutator(function(contextScrollLeft) {
this.getScrollableArea().scrollLeft = contextScrollLeft;
}.bind(this, contextScrollLeft));
}
},
_initElement: function() {
$super._initElement.call(this);
this._resetItemsSelection();
this.setRowHeight(cls.TableWidget.defaultRowHeight);
this._activeUniqueIdScrolls = new Map();
this.getColumnsHeaders().on("dragover.TableWidget", this._preventDefault.bind(this));
this.getLeftColumnsHeaders().on("dragover.TableWidget", this._preventDefault.bind(this));
this.getRightColumnsHeaders().on("dragover.TableWidget", this._preventDefault.bind(this));
this.getLeftColumnsHeaders()
.on("drop.TableWidget", this._onHeaderDrop.bind(this))
.on("dragstart.TableWidget", this._onHeaderDragStart.bind(this))
.on("dragend.TableWidget", this._onHeaderDragEnd.bind(this))
.on("drag.TableWidget", this._onHeaderDrag.throttle(5).bind(this))
.on("dragover.TableWidget", this._onHeaderDragOver.bind(this))
.on("dragleave.TableWidget", this._onHeaderDragLeave.bind(this))
.onLongTouch('longTouch.TableWidget', this._onLongTouch.bind(this))
.onDoubleTap("TableWidget", this._onHeaderDoubleClick.bind(this));
this.getLeftColumnsContainer()
.onDoubleTap("TableWidget", this._onDoubleClick.bind(this));
this.getRightColumnsHeaders()
.on("drop.TableWidget", this._onHeaderDrop.bind(this))
.on("dragstart.TableWidget", this._onHeaderDragStart.bind(this))
.on("dragend.TableWidget", this._onHeaderDragEnd.bind(this))
.on("drag.TableWidget", this._onHeaderDrag.throttle(5).bind(this))
.on("dragover.TableWidget", this._onHeaderDragOver.bind(this))
.on("dragleave.TableWidget", this._onHeaderDragLeave.bind(this))
.onLongTouch('longTouch.TableWidget', this._onLongTouch.bind(this))
.onDoubleTap("TableWidget", this._onHeaderDoubleClick.bind(this));
this.getRightColumnsContainer()
.onDoubleTap("TableWidget", this._onDoubleClick.bind(this));
this.getColumnsHeaders()
.on("drop.TableWidget", this._onHeaderDrop.bind(this))
.on("dragstart.TableWidget", this._onHeaderDragStart.bind(this))
.on("dragend.TableWidget", this._onHeaderDragEnd.bind(this))
.on("drag.TableWidget", this._onHeaderDrag.throttle(5).bind(this))
.on("dragover.TableWidget", this._onHeaderDragOver.bind(this))
.on("dragleave.TableWidget", this._onHeaderDragLeave.bind(this))
.onLongTouch('longTouch.TableWidget', this._onLongTouch.bind(this))
.onDoubleTap("TableWidget", this._onHeaderDoubleClick.bind(this));
this.getColumnsContainer()
.onDoubleTap("TableWidget", this._onDoubleClick.bind(this));
this.getScrollableArea().on('scroll.TableWidget', this._onScroll.bind(this));
this.getLeftScrollableArea().on('scroll.TableWidget', this._onScrollOnLeftColumns.bind(this));
this.getRightScrollableArea().on('scroll.TableWidget', this._onScrollOnRightColumns.bind(this));
this.getElement()
.on("mousedown.TableWidget", this._onItemMouseDown.bind(this))
.on("mouseup.TableWidget", this._onItemMouseUp.bind(this))
.on("mouseleave.TableWidget", this._onItemMouseLeave.bind(this));
this.setStyle(".gbc_TableColumnsHeaders", {
"margin-right": window.scrollBarSize + "px"
});
this.setStyle(".gbc_TableColumnsFooter, .gbc_TableLeftColumnsFooter, .gbc_TableRightColumnsFooter", {
"margin-bottom": window.scrollBarSize + "px"
});
this._updateFooterWidth();
},
_initLayout: function() {
this._layoutInformation = new cls.LayoutInformation(this);
this._layoutInformation.shouldFillStack = true;
this._layoutEngine = new cls.TableLayoutEngine(this);
this._layoutEngine.onLayoutApplied(this._layoutApplied.bind(this));
this._layoutInformation.getStretched().setDefaultX(true);
this._layoutInformation.getStretched().setDefaultY(true);
var minPageSize = parseInt(context.ThemeService.getValue("gbc-TableWidget-min-page-size"), 10);
this._layoutEngine.setMinPageSize(isNaN(minPageSize) ? 1 : minPageSize);
var minWidth = parseInt(context.ThemeService.getValue("gbc-TableWidget-min-width"), 10);
this._layoutEngine.setMinWidth(isNaN(minWidth) ? 60 : minWidth);
},
resetMeasure: function() {
this.getLayoutEngine().forceMeasurement();
this.getLayoutEngine().invalidateMeasure();
if (this.getLayoutEngine().invalidatePreferredSize) {
this.getLayoutEngine().invalidatePreferredSize();
}
},
destroy: function() {
this.getColumnsHeaders().off("dragover.TableWidget");
this.getLeftColumnsHeaders().off("dragover.TableWidget");
this.getRightColumnsHeaders().off("dragover.TableWidget");
this.getLeftColumnsHeaders().off("drop.TableWidget");
this.getLeftColumnsHeaders().off("dragstart.TableWidget");
this.getLeftColumnsHeaders().off("dragend.TableWidget");
this.getLeftColumnsHeaders().off("drag.TableWidget");
this.getLeftColumnsHeaders().off("dragover.TableWidget");
this.getLeftColumnsHeaders().off("dragleave.TableWidget");
this.getLeftColumnsHeaders().offLongTouch('longTouch.TableWidget');
this.getLeftColumnsHeaders().offDoubleTap("TableWidget");
this.getLeftColumnsContainer().offDoubleTap("TableWidget");
this.getRightColumnsHeaders().off("drop.TableWidget");
this.getRightColumnsHeaders().off("dragstart.TableWidget");
this.getRightColumnsHeaders().off("dragend.TableWidget");
this.getRightColumnsHeaders().off("drag.TableWidget");
this.getRightColumnsHeaders().off("dragover.TableWidget");
this.getRightColumnsHeaders().off("dragleave.TableWidget");
this.getRightColumnsHeaders().offLongTouch('longTouch.TableWidget');
this.getRightColumnsHeaders().offDoubleTap("TableWidget");
this.getRightColumnsContainer().offDoubleTap("TableWidget");
this.getColumnsHeaders().off("drop.TableWidget");
this.getColumnsHeaders().off("dragstart.TableWidget");
this.getColumnsHeaders().off("dragend.TableWidget");
this.getColumnsHeaders().off("drag.TableWidget");
this.getColumnsHeaders().off("dragover.TableWidget");
this.getColumnsHeaders().off("dragleave.TableWidget");
this.getColumnsHeaders().offLongTouch('longTouch.TableWidget');
this.getColumnsHeaders().offDoubleTap("TableWidget");
this.getColumnsContainer().offDoubleTap("TableWidget");
this.getScrollableArea().off('scroll.TableWidget');
this.getLeftScrollableArea().off('scroll.TableWidget');
this.getRightScrollableArea().off('scroll.TableWidget');
if (this._activeUniqueIdScrolls) {
this._activeUniqueIdScrolls.forEach(function(domElement, id) {
domElement.off(id);
}, this);
this._activeUniqueIdScrolls.clear();
this._activeUniqueIdScrolls = null;
}
if (this._rowBoundColumnWidget) {
this._rowBoundColumnWidget.destroy();
this._rowBoundColumnWidget = null;
}
this.getElement().off("mousedown.TableWidget");
this.getElement().off("mouseup.TableWidget");
this.getElement().off("mousemove.TableWidget");
this.getElement().off("mouseleave.TableWidget");
if (this._dndItemEnabled) {
var columnsContainer = this.getColumnsContainer();
columnsContainer.off("dragstart.TableWidget");
columnsContainer.off("dragend.TableWidget");
columnsContainer.off("dragover.TableWidget");
columnsContainer.off("drop.TableWidget");
columnsContainer.off("dragleave.TableWidget");
columnsContainer.off("dragenter.TableWidget");
}
this._columnsHeaders = null;
this._leftContainerElement = null;
this._rightContainerElement = null;
this._columnsContainerElement = null;
this._leftColumnsContainer = null;
this._rightColumnsContainer = null;
this._leftColumnsHeaders = null;
this._rightColumnsHeaders = null;
this._columnsFooter = null;
this._leftColumnsFooter = null;
this._rightColumnsFooter = null;
this._rightScrollAreaElement = null;
this._leftScrollAreaElement = null;
this._aggregateGlobalTextElement = null;
this._orderedColumns = null;
this._lastClickDate = null;
this._lastClickTarget = null;
$super.destroy.call(this);
},
manageKeyDown: function(keyString, domKeyEvent, repeat) {
var keyProcessed = false;
if (this.isDisplayMode()) {
if (domKeyEvent) {
var key = cls.KeyboardApplicationService.keymap[domKeyEvent.which];
keyProcessed = true;
switch (key) {
case "down":
this.emit(context.constants.widgetEvents.keyArrowDown, domKeyEvent);
break;
case "up":
this.emit(context.constants.widgetEvents.keyArrowUp, domKeyEvent);
break;
case "left":
this.emit(context.constants.widgetEvents.keyArrowLeft, domKeyEvent);
break;
case "right":
this.emit(context.constants.widgetEvents.keyArrowRight, domKeyEvent);
break;
case "pageup":
this.emit(context.constants.widgetEvents.keyPageUp, domKeyEvent);
break;
case "pagedown":
this.emit(context.constants.widgetEvents.keyPageDown, domKeyEvent);
break;
case "home":
this.emit(context.constants.widgetEvents.keyHome, domKeyEvent);
break;
case "end":
this.emit(context.constants.widgetEvents.keyEnd, domKeyEvent);
break;
case "space":
this.emit(context.constants.widgetEvents.keySpace, domKeyEvent);
break;
default:
keyProcessed = false;
}
}
if (keyString === "ctrl+a" || keyString === "meta+a") {
this.emit(context.constants.widgetEvents.selectAll);
keyProcessed = true;
}
}
if (keyProcessed) {
return true;
} else {
return $super.manageKeyDown.call(this, keyString, domKeyEvent, repeat);
}
},
managePriorityKeyDown: function(keyString, domKeyEvent, repeat) {
var keyProcessed = false;
if (keyString === "ctrl+c" || keyString === "meta+c") {
if (this.hasItemsSelected()) {
this._copySelectionInClipboard();
keyProcessed = true;
} else if (this.isDisplayMode()) {
this.emit(context.constants.widgetEvents.copy);
keyProcessed = true;
}
}
if (keyProcessed) {
return true;
} else {
return $super.managePriorityKeyDown.call(this, keyString, domKeyEvent, repeat);
}
},
manageMouseClick: function(domEvent) {
if (!domEvent.target.parent("gbc_TableColumnWidget") || !this.isEnabled()) {
this.emit(context.constants.widgetEvents.requestFocus);
}
return true;
},
manageMouseDblClick: function(domEvent) {
var target = domEvent.target;
var isHeaderDblClick = target.isElementOrChildOf(this.getColumnsHeaders()) ||
target.isElementOrChildOf(this.getLeftColumnsHeaders()) || target.isElementOrChildOf(this.getRightColumnsHeaders());
if (isHeaderDblClick) {
this._onHeaderDoubleClick(domEvent);
return false;
}
var isColumnsContainerClick = target.isElementOrChildOf(this.getColumnsContainer()) ||
target.isElementOrChildOf(this.getLeftColumnsContainer()) || target.isElementOrChildOf(this.getRightColumnsContainer());
if (isColumnsContainerClick) {
this._onDoubleClick(domEvent);
return false;
}
return true;
},
setEnabled: function(enabled) {
if (this._enabled !== enabled) {
$super.setEnabled.call(this, enabled);
this._resetItemsSelection();
this.updateVerticalScroll(enabled);
}
},
setAriaSelection: function() {
},
setBackgroundColor: function(color) {
$super.setBackgroundColor.call(this, color);
this.setStyle('.gbc_TableColumnsHeaders, .gbc_TableLeftColumnsHeaders, .gbc_TableRightColumnsHeaders', {
"background-color": color && !this._ignoreBackgroundColor ? color : null
});
},
isElementVisible: function(element) {
if (!element) {
return false;
}
const {
top,
right,
bottom,
left
} = element.getBoundingClientRect(),
viewportWidth = window.innerWidth || document.documentElement.clientWidth,
viewportHeight = window.innerHeight || document.documentElement.clientHeight;
if (right < 0 || bottom < 0 || left > viewportWidth || top > viewportHeight) {
return false;
}
return element.contains(document.elementFromPoint(Math.ceil(left), Math.ceil(top))) ||
element.contains(document.elementFromPoint(Math.floor(right), Math.ceil(top))) ||
element.contains(document.elementFromPoint(Math.floor(right), Math.floor(bottom))) ||
element.contains(document.elementFromPoint(Math.ceil(left), Math.floor(bottom)));
},
setFocus: function(fromMouse) {
if (this.isElementInDOM()) {
this.domFocus(fromMouse || this.isElementVisible(this.getElement()));
this.domFocus(fromMouse);
} else {
const uiWidget = this.getUserInterfaceWidget();
if (uiWidget) {
uiWidget.getElement().domFocus();
}
}
$super.setFocus.call(this, fromMouse);
},
resetLayout: function() {
$super.resetLayout.call(this);
this._layoutDone = false;
},
_layoutApplied: function() {
if (this.isElementInDOM()) {
if (!this._layoutDone) {
this._layoutDone = true;
this.updateFrozenColumns();
this.updateAllAggregate();
}
this._updateVisibleColumnsInDom(0);
if (this._needToUpdateVerticalScroll) {
this.updateVerticalScroll(true);
}
this._needToUpdateVerticalScroll = false;
if (this.hasLeftFrozenColumns() && this.getLeftScrollableArea().scrollTop !== this.getScrollableArea().scrollTop) {
this.setLeftScrollableAreaScrollTop(this.getScrollableArea().scrollTop, false);
}
if (this.hasRightFrozenColumns() && this.getRightScrollableArea().scrollTop !== this.getScrollableArea().scrollTop) {
this.setRightScrollableAreaScrollTop(this.getScrollableArea().scrollTop, false, false);
}
if (this._requestSynchronizeHeadersHeight) {
this._requestSynchronizeHeadersHeight = false;
this.synchronizeHeadersHeight();
}
this.autoSetLastColumnWidthToFillEmptySpace();
}
},
requestFocusFromWidget: function(widget, event) {
var isDoubleClick = (new Date() - this._lastClickDate) < 350 && (this._lastClickTarget === event.target);
this._lastClickDate = new Date();
this._lastClickTarget = event.target;
var mustSendFocusRequest = !this.hasVMFocus() || (event.type !== "click");
mustSendFocusRequest = mustSendFocusRequest || (this._itemSelectionHasChanged === false);
if (isDoubleClick) {
this._lastClickDate = null;
this._lastClickTarget = null;
mustSendFocusRequest = false;
}
if (mustSendFocusRequest) {
$super.requestFocusFromWidget.call(this, widget, event);
}
},
autoSetLastColumnWidthToFillEmptySpace: function() {
if (this._resizeFillsEmptySpace) {
var lastVisibleColumn = this.getLastOrderedColumn(true);
if (this._columnResizeFillsEmptySpace && this._columnResizeFillsEmptySpace !== lastVisibleColumn) {
this._columnResizeFillsEmptySpace.resetWidth();
this._columnResizeFillsEmptySpace.setSizable(true);
}
this._columnResizeFillsEmptySpace = lastVisibleColumn;
this._columnResizeFillsEmptySpace.resetWidth();
this._columnResizeFillsEmptySpace.setSizable(false);
var visibleColumnsWidth = this.getVisibleColumnsWidth();
var tableWidth = this.getDataAreaWidth();
var emptySpaceWidth = tableWidth - visibleColumnsWidth;
if (emptySpaceWidth >= 0) {
this._columnResizeFillsEmptySpace.setWidth(this._columnResizeFillsEmptySpace.getWidth() + emptySpaceWidth, true);
}
}
},
_updateVisibleColumnsInDom: function(offset) {
if (!this._addOnlyVisibleColumnsToDom) {
return;
}
var isLayouted = this._layoutInformation && this._layoutDone;
if (!isLayouted) {
return;
}
var isVisible = this.isElementInDOM() && this.isVisibleRecursively();
if (!isVisible) {
return;
}
offset = typeof offset !== 'undefined' ? offset : this.getScrollableArea().scrollLeft;
if (offset === 0 && this._previousScrollLeftValue > 0) {
this.getScrollableArea().scrollLeft = this._previousScrollLeftValue;
offset = this._previousScrollLeftValue;
}
var columns = this.getOrderedColumns();
var tableWidth = this._layoutInformation.getAllocated().getWidth();
var currentWidth = 0;
var extraVisibleColumnAttached = false;
for (var i = 0; i < columns.length; i++) {
var col = columns[i];
if (col.isFrozen() === false && col.isHidden() === false) {
var colWidth = col.getWidth();
if (col.isCurrent()) {
col.attachItemsToDom();
}
else if (offset > (currentWidth + colWidth)) {
col.detachItemsFromDom();
}
else if ((currentWidth - offset) > tableWidth) {
if (extraVisibleColumnAttached) {
col.detachItemsFromDom();
} else {
extraVisibleColumnAttached = true;
col.attachItemsToDom();
}
} else {
col.attachItemsToDom();
}
currentWidth += colWidth;
} else {
if (col.isHidden()) {
col.detachItemsFromDom();
} else {
col.attachItemsToDom();
}
}
}
},
addChildWidget: function(widget, options) {
if (widget.isInstanceOf(cls.TableColumnWidget)) {
this._addChildTableColumn(widget, options);
} else if (widget.isInstanceOf(cls.ContextMenuWidget)) {
$super.addChildWidget.call(this, widget, options);
if (this._rowBoundColumnWidget === null) {
this._rowBoundColumnWidget = cls.WidgetFactory.createWidget("TableColumnRowBound", this.getBuildParameters());
this._addChildTableColumn(this._rowBoundColumnWidget, options);
}
this.setResizeFillsEmptySpace(true);
this._rowBoundColumnWidget.setHidden(false);
}
this.resetOrderedColumns();
this.updateFrozenColumns();
this._requestSynchronizeHeadersHeight = true;
},
_addChildTableColumn: function(columnWidget, options) {
columnWidget.setParentWidget(this, {
noLayoutInvalidation: true
});
this.getColumnsHeaders().appendChild(columnWidget.getTitleWidget().getElement());
columnWidget.setCurrentRow(this._currentRow);
columnWidget.setOrder(this.getColumns().length);
$super.addChildWidget.call(this, columnWidget, options);
},
removeChildWidget: function(widget) {
$super.removeChildWidget.call(this, widget);
if (widget.isInstanceOf(cls.ContextMenuWidget)) {
this.setResizeFillsEmptySpace(false);
if (this._rowBoundColumnWidget) {
this._rowBoundColumnWidget.setHidden(true);
}
}
this.resetOrderedColumns();
},
setSort: function(sortType, sortColumn) {
var columns = this.getColumns();
for (var i = 0; i < columns.length; i++) {
if (i === sortColumn) {
columns[i].getTitleWidget().setSortDecorator(sortType);
} else {
if (columns[i].getTitleWidget) {
columns[i].getTitleWidget().setSortDecorator("");
}
}
}
},
isTreeView: function() {
var firstColumn = this.getColumns()[0];
return firstColumn && firstColumn._isTreeView;
},
isCurrentRowVisible: function() {
return this._currentRow >= 0 && this._currentRow <= this._pageSize;
},
getColumns: function() {
return this.getChildren();
},
resetOrderedColumns: function() {
this._orderedColumns = null;
},
getOrderedColumns: function() {
var columns = this.getColumns();
if (this._orderedColumns === null || columns.length !== this._orderedColumns.length) {
var children = columns.slice();
children.sort(function(a, b) {
return a.getOrder() - b.getOrder();
});
this._orderedColumns = children;
}
return this._orderedColumns;
},
getLastOrderedColumn: function(visible) {
var columns = this.getOrderedColumns();
for (var i = columns.length - 1; i >= 0; i--) {
var currentColumn = columns[i];
if (!visible || !currentColumn.isHidden()) {
return currentColumn;
}
}
return null;
},
getVisibleColumnsWidth: function() {
var visibleColumnsWidth = 0;
var columns = this.getOrderedColumns();
for (var i = 0; i < columns.length; i++) {
var currentColumn = columns[i];
if (!currentColumn.isHidden()) {
visibleColumnsWidth += currentColumn.getWidth();
}
}
return visibleColumnsWidth;
},
setRowHeight: function(height) {
this._rowHeight = Math.round(height);
this.setStyle(" .gbc_TableColumnItemWidget", {
"height": this._rowHeight + "px"
});
this.setStyle(" .gbc_TableColumnItemWidget .gbc_TableItemImage", {
"width": this._rowHeight + "px",
"height": this._rowHeight + "px"
});
this.updateVerticalScroll(true);
},
setCurrentRow: function(row, ensureRowVisible) {
this._currentRow = row;
var columns = this.getColumns();
var scrollIntoView = (Boolean(ensureRowVisible) && this._layoutDone);
for (var i = 0; i < columns.length; i++) {
var col = columns[i];
col.setCurrentRow(row);
}
if (scrollIntoView) {
this._scrollAreaNoUserScroll = true;
this._rightScrollAreaNoUserScroll = true;
var id = "scroll.unbindScroll" + (++this._uniqueScrollUnbindId);
this._activeUniqueIdScrolls.set(id, this.getScrollableArea());
this.getScrollableArea().on(id, function(id) {
this._previousScrollTopValue = this.getScrollableArea().scrollTop;
this._previousScrollLeftValue = this.getScrollableArea().scrollLeft;
this.getScrollableArea().off(id);
this._activeUniqueIdScrolls.delete(id);
this._scrollAreaNoUserScroll = false;
this._rightScrollAreaNoUserScroll = false;
}.bind(this, id));
this.getScrollableArea().scrollTop = (this._offset * this.getRowHeight());
}
},
setCurrentColumn: function(col) {
this._currentColumn = col;
var columns = this.getColumns();
for (var i = 0; i < columns.length; i++) {
if (columns[i].setCurrent) {
columns[i].setCurrent(i === col);
}
}
},
getCurrentColumn: function() {
return this._currentColumn;
},
getCurrentWidget: function() {
if (this.isCurrentRowVisible()) {
return this.getWidgetAt(this._currentColumn, this._currentRow);
}
return null;
},
getWidgetAt: function(column, row) {
return this.getColumns()[column].getWidgetAt(row);
},
setVisibleRows: function(visibleRows) {
if (this._visibleRows !== visibleRows) {
this._visibleRows = visibleRows;
var columns = this.getColumns();
for (var i = 0; i < columns.length; i++) {
var tableColumn = columns[i];
if (tableColumn.updateRowsVisibility) {
tableColumn.updateRowsVisibility();
}
}
}
},
setMultiRowSelectionEnabled: function(enable) {
this._element.toggleClass("multiRowSelection", Boolean(enable));
},
isMultiRowSelectionEnabled: function() {
return this._element.hasClass("multiRowSelection");
},
setRowSelected: function(row, selected) {
var columns = this.getColumns();
for (var i = 0; i < columns.length; i++) {
var tableColumn = columns[i];
tableColumn.setRowSelected(row, selected);
}
},
isRowSelected: function(row) {
var columns = this.getColumns();
if (columns.length) {
return columns[row].isRowSelected(row);
}
return false;
},
setFocusOnField: function(focusOnField) {
this._focusOnField = focusOnField;
},
hasFocusOnField: function() {
return this._focusOnField;
},
synchronizeHeadersHeight: function() {
if (this._frozenTable && this._layoutDone) {
var height = -1;
var leftHeight = -1;
var rightHeight = -1;
if (this.hasLeftFrozenColumns() || this.hasRightFrozenColumns()) {
this.getColumnsHeaders().addClass("g_TableMeasuring");
height = this.getColumnsHeaders().clientHeight;
this.getColumnsHeaders().removeClass("g_TableMeasuring");
}
if (this.hasLeftFrozenColumns()) {
this.getLeftColumnsHeaders().addClass("g_TableMeasuring");
leftHeight = this.getLeftColumnsHeaders().clientHeight;
this.getLeftColumnsHeaders().removeClass("g_TableMeasuring");
}
if (this.hasRightFrozenColumns()) {
this.getRightColumnsHeaders().addClass("g_TableMeasuring");
rightHeight = this.getRightColumnsHeaders().clientHeight;
this.getRightColumnsHeaders().removeClass("g_TableMeasuring");
}
var headerHeight = Math.max(height, leftHeight, rightHeight);
if (headerHeight > 0) {
this.setStyle(".gbc_TableColumnsHeaders", {
"height": headerHeight + "px"
});
if (this.hasLeftFrozenColumns()) {
this.setStyle(".gbc_TableLeftColumnsHeaders", {
"height": headerHeight + "px"
});
}
if (this.hasRightFrozenColumns()) {
this.setStyle(".gbc_TableRightColumnsHeaders", {
"height": headerHeight + "px"
});
}
}
this.getLayoutEngine().forceMeasurement();
this.getLayoutEngine().invalidateMeasure();
}
},
buildExtraContextMenuActions: function(contextMenu) {
var copyFunction = null;
if (this._selectionSquareIdx.left.x !== null) {
copyFunction = function(contextMenu) {
contextMenu.hide();
this._copySelectionInClipboard();
}.bind(this);
contextMenu.addAction("copy", i18next.t("gwc.clipboard.copy"), null, "Control+C", {
clickCallback: copyFunction.bind(this, contextMenu)
}, true);
}
if (this.canShowCopyCellAndRow()) {
contextMenu.addAction("copyRow", i18next.t("gwc.contextMenu.copyRow"), null,
null, {
clickCallback: function() {
contextMenu.hide();
this._copyCurrentRowInClipboard();
}.bind(this)
}, true);
}
if (this.isMultiRowSelectionEnabled()) {
contextMenu.addAction("selectAll", i18next.t("gwc.contextMenu.selectAll"), "font:FontAwesome.ttf:f0ea", "Ctrl+A", {
clickCallback: function() {
contextMenu.hide();
this.emit(context.constants.widgetEvents.selectAll);
}.bind(this)
}, true);
}
},
flash: function() {
this.addClass("flash");
this._registerTimeout(function() {
this.removeClass("flash");
}.bind(this), 50);
},
autoFitAllColumns: function() {
var columns = this.getColumns();
for (var i = 0; i < columns.length; i++) {
var tc = columns[i];
tc.autoSetWidth();
}
},
fitToViewAllColumns: function() {
var columns = this.getColumns();
var totalAvail = this.getDataAreaWidth();
var totalCurrent = 0;
var tc = null,
i = 0;
for (i = 0; i < columns.length; i++) {
tc = columns[i];
if (!tc.isHidden()) {
if (tc.isSizable()) {
totalCurrent = totalCurrent + tc.getWidth();
} else {
totalAvail = totalAvail - tc.getWidth();
}
}
}
var newTotal = 0;
if (totalCurrent > 0) {
for (i = 0; i < columns.length; i++) {
tc = columns[i];
if (!tc.isHidden() && tc.isSizable()) {
var w = Math.round(tc.getWidth() * (totalAvail / totalCurrent));
newTotal = newTotal + w;
if (newTotal > totalAvail) {
w = w - (newTotal - totalAvail);
}
tc.setWidthFromUserInteraction(w);
}
}
}
},
setHasFooter: function(b) {
if (this._hasFooter !== b) {
this._hasFooter = b;
this.getColumnsFooter().toggleClass("hidden", !b);
if (b) {
this.updateAllAggregate();
}
this.getLayoutEngine().forceMeasurement();
this.getLayoutEngine().invalidateMeasure();
}
},
hasFooter: function() {
return this._hasFooter;
},
updateAllAggregate: function() {
if (this.hasFooter() && this._layoutDone) {
this.resetOrderedColumns();
var columns = this.getOrderedColumns();
var firstAggregate = null;
var aggregateWidth = 0;
var frozenIndex = null;
for (var i = 0; i < columns.length; i++) {
var col = columns[i];
if (frozenIndex === null) {
frozenIndex = col.getFrozenIndex();
}
var agg = col.getAggregateWidget();
if (col.getFrozenIndex() !== frozenIndex) {
frozenIndex = col.getFrozenIndex();
aggregateWidth = 0;
}
if (!col.isHidden()) {
aggregateWidth += col.getWidth();
if (agg) {
if (aggregateWidth) {
this.afterDomMutator(function(col, aggregateWidth) {
col.setAggregate(col.getAggregateWidget().getText(), aggregateWidth);
}.bind(this, col,
aggregateWidth));
}
aggregateWidth = 0;
if (!firstAggregate) {
firstAggregate = agg;
}
}
}
}
if (firstAggregate) {
this.getAggregateGlobalTextElement().remove();
firstAggregate.getElement().prependChild(this.getAggregateGlobalTextElement());
}
}
},
setAggregateGlobalText: function(text) {
if (!this._aggregateGlobalTextElement) {
this._aggregateGlobalTextElement = document.createElement("div");
this._aggregateGlobalTextElement.addClass("gbc_TableAggregateGlobalText");
}
this._aggregateGlobalTextElement.textContent = text;
},
isVerticalScrollAtEnd: function() {
var scrollArea = this.getScrollableArea();
return (scrollArea.scrollTop + scrollArea.clientHeight) === scrollArea.scrollHeight;
},
doScroll: function(value, delta, force) {
var isTableVisible = this.isVisibleRecursively();
if (isTableVisible) {
var top = value;
if (delta) {
top = (this.getScrollableArea().scrollTop + value);
}
if (this.hasRightFrozenColumns()) {
this.setRightScrollableAreaScrollTop(top, force);
} else {
this.setScrollableAreaScrollTop(top, force);
}
} else {
this._needToUpdateVerticalScroll = true;
}
},
doHorizontalScroll: function(direction) {
var scrollArea = this.getScrollableArea();
var scrollPos = scrollArea.scrollLeft;
var columns = this.getOrderedColumns();
var width = 0;
for (var i = 0; i < columns.length; i++) {
var col = columns[i];
if (col.isFrozen() === false && col.isHidden() === false) {
var colWidth = col.getWidth();
var isScrollAtStartColumn = (Math.abs(scrollPos - width) <= 2);
var isScrollAtEndColumn = (Math.abs(scrollPos - (width + colWidth)) <= 2);
if ((isScrollAtStartColumn || scrollPos > width) && (isScrollAtEndColumn || scrollPos < width + colWidth)) {
if (isScrollAtStartColumn && direction === "right") {
scrollPos = width + colWidth;
direction = "left";
} else if (isScrollAtEndColumn && direction === "right") {
scrollPos = width + colWidth;
} else {
scrollArea.scrollLeft = direction === "right" ? width + colWidth : width;
break;
}
}
width += colWidth;
}
}
},
_onMouseWheel: function(event) {
if (this.isEnabled()) {
this.doScroll(event.deltaY, true, true);
}
},
_onScroll: function(event) {
var targetScrollTop = event.target.scrollTop;
var targetScrollLeft = event.target.scrollLeft;
if (this._previousScrollLeftValue !== targetScrollLeft) {
this._previousScrollLeftValue = targetScrollLeft;
this.afterDomMutator(function() {
if (this._throttleUpdateVisibleColumnsInDom) {
this._clearTimeout(this._throttleUpdateVisibleColumnsInDom);
}
this._throttleUpdateVisibleColumnsInDom = this._registerTimeout(function() {
this._throttleUpdateVisibleColumnsInDom = null;
this._scrollAreaNoUserScroll = true;
this._scrollAreaResetScrollTopFromPrevious = true;
this._updateVisibleColumnsInDom();
this.afterDomMutator(function() {
this.afterDomMutator(function() {
this._scrollAreaNoUserScroll = false;
this._scrollAreaResetScrollTopFromPrevious = false;
}.bind(this));
}.bind(this));
}.bind(this), 10);
var scrollLeft = this.getScrollableArea().scrollLeft;
this.getColumnsHeaders().scrollLeft = scrollLeft;
if (this.hasFooter()) {
this.getColumnsFooter().scrollLeft = scrollLeft;
}
}.bind(this));
}
this._resetItemsSelection();
if (this._scrollAreaNoUserScroll) {
this._scrollAreaNoUserScroll = false;
if (this._scrollAreaResetScrollTopFromPrevious) {
this._scrollAreaResetScrollTopFromPrevious = false;
this.getScrollableArea().scrollTop = this._previousScrollTopValue;
}
return true;
}
if (this._previousScrollTopValue !== targetScrollTop) {
this._previousScrollTopValue = targetScrollTop;
this.afterDomMutator(function() {
if (!this.hasRightFrozenColumns()) {
this.emit(context.constants.widgetEvents.scroll, event, this.getRowHeight());
var scrollTop = this.getScrollableArea().scrollTop;
this.setLeftScrollableAreaScrollTop(scrollTop);
this.setRightScrollableAreaScrollTop(scrollTop);
}
}.bind(this));
}
},
_onScrollOnLeftColumns: function(event) {
this.afterDomMutator(function() {
if (event.target) {
this.getLeftColumnsHeaders().scrollLeft = event.target.scrollLeft;
if (this.hasFooter()) {
this.getLeftColumnsFooter().scrollLeft = event.target.scrollLeft;
}
}
}.bind(this));
},
_onScrollOnRightColumns: function(event) {
this.afterDomMutator(function() {
if (event.target) {
this.getRightColumnsHeaders().scrollLeft = event.target.scrollLeft;
if (this.hasFooter()) {
this.getRightColumnsFooter().scrollLeft = event.target.scrollLeft;
}
if (this.hasRightFrozenColumns()) {
this.emit(context.constants.widgetEvents.scroll, event, this.getRowHeight());
var scrollTop = event.target.scrollTop;
this.setLeftScrollableAreaScrollTop(scrollTop);
this.setScrollableAreaScrollTop(scrollTop);
}
}
}.bind(this));
if (this._rightScrollAreaNoUserScroll) {
this._rightScrollAreaNoUserScroll = false;
return true;
}
if (this.hasRightFrozenColumns()) {
this.afterDomMutator(function() {
if (event.target) {
this.emit(context.constants.widgetEvents.scroll, event, this.getRowHeight());
var scrollTop = event.target.scrollTop;
this.setLeftScrollableAreaScrollTop(scrollTop);
this.setScrollableAreaScrollTop(scrollTop);
}
}.bind(this));
}
},
updateContentPosition: function(size, pageSize, offset, forceScroll) {
if (size !== null) {
this.setSize(size);
if (this._pageSize !== pageSize) {
this._pageSize = pageSize;
this._resetItemsSelection();
}
var top = offset * this.getRowHeight();
var rowCount = (size - offset + (this.isInputMode() ? 1 :
0));
var height = rowCount * this.getRowHeight() + (this.hasFooter() ? this.getColumnsFooter().clientHeight : 0);
if (size <
pageSize) {
height = Math.max(Math.floor(this.getDataAreaHeight() - 2),
height);
}
this.setStyle({
selector: ".gbc_TableColumnsContainer"
}, {
"margin-top": top + "px",
"height": height + "px"
});
if (this.hasLeftFrozenColumns()) {
this.setStyle({
preSelector: ".g_measured ",
selector: ".gbc_TableLeftColumnsContainer"
}, {
"margin-top": top + "px",
"height": height + "px"
});
}
if (this.hasRightFrozenColumns()) {
this.setStyle({
preSelector: ".g_measured ",
selector: ".gbc_TableRightColumnsContainer"
}, {
"margin-top": top + "px",
"height": height + "px"
});
}
if (this._layoutDone && (forceScroll || (this.lastSentOffset === null || this.lastSentOffset === offset) && offset !== this
._offset)) {
this._offset = offset;
this.afterDomMutator(function() {
this.doScroll(top, false);
}.bind(this));
}
this.lastSentOffset = null;
}
},
setScrollableAreaScrollTop: function(top, force, synchronizing) {
if (this.getScrollableArea().scrollTop !== top) {
var id = "scroll.unbindScroll" + (++this._uniqueScrollUnbindId);
this._activeUniqueIdScrolls.set(id, this.getScrollableArea());
this._scrollAreaNoUserScroll = !force;
this.getScrollableArea().on(id, function(id) {
this._previousScrollTopValue = this.getScrollableArea().scrollTop;
this._previousScrollLeftValue = this.getScrollableArea().scrollLeft;
this.getScrollableArea().off(id);
this._activeUniqueIdScrolls.delete(id);
this._scrollAreaNoUserScroll = false;
}.bind(this, id));
this.getScrollableArea().scrollTop = top;
if (!synchronizing) {
this.setLeftScrollableAreaScrollTop(top, true);
this.setRightScrollableAreaScrollTop(top, false, true);
}
}
},
setLeftScrollableAreaScrollTop: function(top, synchronizing) {
if (this.getLeftScrollableArea().scrollTop !== top) {
this.getLeftScrollableArea().scrollTop = top;
if (!synchronizing) {
this.setScrollableAreaScrollTop(top, false, true);
this.setRightScrollableAreaScrollTop(top, false, true);
}
}
},
setRightScrollableAreaScrollTop: function(top, force, synchronizing) {
if (this.getRightScrollableArea().scrollTop !== top) {
var id = "scroll.unbindScroll" + (++this._uniqueScrollUnbindId);
this._activeUniqueIdScrolls.set(id, this.getRightScrollableArea());
this._rightScrollAreaNoUserScroll = !force;
this.getRightScrollableArea().on(id, function(id) {
this.getRightScrollableArea().off(id);
this._activeUniqueIdScrolls.delete(id);
this._rightScrollAreaNoUserScroll = false;
}.bind(this, id));
this.getRightScrollableArea().scrollTop = top;
if (!synchronizing) {
this.setLeftScrollableAreaScrollTop(top, true);
this.setScrollableAreaScrollTop(top, false, true);
}
}
},
updateFrozenColumns: function() {
if (this._frozenTable) {
this._renderFrozenColumns();
this.getScrollableArea().off('wheel.TableWidget');
this.getLeftScrollableArea().off('wheel.TableWidget');
this.getRightScrollableArea().off('wheel.TableWidget');
if (this.hasLeftFrozenColumns()) {
this.getLeftScrollableArea().on('wheel.TableWidget', this._onMouseWheel.bind(this));
}
if (this.hasRightFrozenColumns()) {
this.getScrollableArea().on('wheel.TableWidget', this._onMouseWheel.bind(this));
this.setStyle(".gbc_TableColumnsHeaders", {
"margin-right": 0
});
this.setStyle(".gbc_TableRightColumnsHeaders", {
"margin-right": window.scrollBarSize + "px"
});
this.setStyle(".gbc_TableScrollArea", {
"overflow-y": "hidden"
});
} else {
this.setStyle(".gbc_TableRightColumnsHeaders", {
"margin-right": 0
});
this.setStyle(".gbc_TableColumnsHeaders", {
"margin-right": window.scrollBarSize + "px"
});
this.setStyle(".gbc_TableScrollArea", {
"overflow-y": "scroll"
});
}
this.getLeftContainer().toggleClass("hidden", !this.hasLeftFrozenColumns());
this.getRightContainer().toggleClass("hidden", !this.hasRightFrozenColumns());
this._updateFooterWidth();
this.updateVerticalScroll();
this.domAttributesMutator(function() {
this.afterDomMutator(function() {
var scrollTop = this.getScrollableArea().scrollTop;
this.setLeftScrollableAreaScrollTop(scrollTop);
this.setRightScrollableAreaScrollTop(scrollTop);
}.bind(this));
}.bind(this));
this.synchronizeHeadersHeight();
this.updateAllAggregate();
}
},
_updateFooterWidth: function() {
if (this.hasRightFrozenColumns()) {
this.setStyle(".gbc_TableRightColumnsFooter", {
"width": "calc(100% - " + window.scrollBarSize + "px)"
});
this.setStyle(".gbc_TableColumnsFooter", {
"width": "100%"
});
} else {
this.setStyle(".gbc_TableColumnsFooter", {
"width": "calc(100% - " + window.scrollBarSize + "px)"
});
this.setStyle(".gbc_TableRightColumnsFooter", {
"width": "100%"
});
}
},
hasLeftFrozenColumns: function() {
return (this._leftFrozenColumns > 0);
},
hasRightFrozenColumns: function() {
return (this._rightFrozenColumns > 0);
},
_renderFrozenColumns: function() {
if (this._frozenTable) {
var columns = this.getOrderedColumns();
for (var i = 0; i < columns.length; i++) {
var currentColumn = columns[i];
if (i < this._leftFrozenColumns) {
currentColumn._isLeftFrozen = true;
currentColumn._isRightFrozen = false;
this.getLeftColumnsContainer().appendChild(currentColumn.getElement());
this.getLeftColumnsHeaders().appendChild(currentColumn.getTitleWidget().getElement());
if (currentColumn._aggregate) {
this.getLeftColumnsFooter().appendChild(currentColumn._aggregate.getElement());
}
} else if (columns.length - i <= this._rightFrozenColumns) {
currentColumn._isRightFrozen = true;
currentColumn._isLeftFrozen = false;
this.getRightColumnsContainer().appendChild(currentColumn.getElement());
this.getRightColumnsHeaders().appendChild(currentColumn.getTitleWidget().getElement());
if (currentColumn._aggregate) {
this.getRightColumnsFooter().appendChild(currentColumn._aggregate.getElement());
}
} else {
currentColumn._isLeftFrozen = false;
currentColumn._isRightFrozen = false;
this.getColumnsContainer().appendChild(currentColumn.getElement());
this.getColumnsHeaders().appendChild(currentColumn.getTitleWidget().getElement());
if (currentColumn._aggregate) {
this.getColumnsFooter().appendChild(currentColumn._aggregate.getElement());
}
}
}
this._updateVisibleColumnsInDom();
}
},
isFrozenTable: function() {
return this._frozenTable;
},
setFrozenTable: function(frozen) {
if (this._frozenTable !== frozen) {
this._frozenTable = frozen;
this.updateFrozenColumns();
}
},
setLeftFrozenColumns: function(n) {
if (this._leftFrozenColumns !== n) {
this._leftFrozenColumns = n;
this.updateFrozenColumns();
}
},
setRightFrozenColumns: function(n) {
if (this._rightFrozenColumns !== n) {
this._rightFrozenColumns = n;
this.updateFrozenColumns();
}
},
getLeftFrozenColumns: function() {
return this._leftFrozenColumns;
},
getRightFrozenColumns: function() {
return this._rightFrozenColumns;
},
setHeaderHidden: function(hidden) {
if (this._headerHidden !== hidden) {
this._headerHidden = hidden;
this.getColumnsHeaders().toggleClass("hidden", Boolean(hidden));
this.getLeftColumnsHeaders().toggleClass("hidden", Boolean(hidden));
this.getRightColumnsHeaders().toggleClass("hidden", Boolean(hidden));
}
},
setShowGrid: function(showGrid) {
if (this._showGrid !== showGrid) {
this._showGrid = showGrid;
this._element.toggleClass("showGrid", Boolean(showGrid));
}
},
setHeaderAlignment: function(alignment) {
if (this._headerAlignment !== alignment) {
this._headerAlignment = alignment;
var columns = this.getColumns();
for (var i = 0; i < columns.length; i++) {
var col = columns[i];
col.getTitleWidget().setTextAlign(alignment);
}
}
},
setHighlightColor: function(color) {
if (this._highlightColor !== color) {
this._highlightColor = color;
color = (color === null ? null : color + " !important");
this.setStyle({
selector: ":not(.disabled) .highlight .gbc_TableColumnItemWidget.currentRow",
appliesOnRoot: true
}, {
"background-color": color
});
}
},
setHighlightTextColor: function(color) {
if (this._highlightTextColor !== color) {
this._highlightTextColor = color;
this.setStyle({
selector: ":not(.disabled) .highlight .gbc_TableColumnItemWidget.currentRow",
appliesOnRoot: true
}, {
"color": color === null ? null : color + " !important",
"fill": color === null ? null : color + " !important"
});
}
},
setHighlightCurrentCell: function(b) {
this._highlightCurrentCell = b;
},
isHighlightCurrentCell: function() {
return this._highlightCurrentCell;
},
updateHighlight: function() {
this.setCurrentRow(this._currentRow);
this.setCurrentColumn(this._currentColumn);
},
setResizeFillsEmptySpace: function(b) {
this._resizeFillsEmptySpace = b || this
.hasRowBound();
if (!this._resizeFillsEmptySpace) {
this._columnResizeFillsEmptySpace = null;
}
},
isResizeFillsEmptySpace: function() {
return this._resizeFillsEmptySpace;
},
_onHeaderDoubleClick: function(evt) {
if (evt.target.hasClass("resizer")) {
var columnTitleWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnTitleWidget");
if (columnTitleWidget) {
columnTitleWidget.onResizerDoubleClick(evt);
}
}
},
_onHeaderDrop: function(evt) {
var columnTitleWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnTitleWidget");
if (columnTitleWidget) {
columnTitleWidget.onReorderingDrop(evt);
} else if (this._dndMode === "columnReordering") {
if (this._dndReorderingDragOverWidget === null) {
var orderedColumns = this.getOrderedColumns();
this._dndDraggedColumnWidget.getTitleWidget().reorderColumns(this._dndDraggedColumnWidget, orderedColumns[
orderedColumns.length - 1]);
}
}
},
_onHeaderDragStart: function(evt) {
var columnTitleWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnTitleWidget");
if (!columnTitleWidget) {
return;
}
if (evt.target.hasClass("resizer")) {
columnTitleWidget.onResizerDragStart(evt);
} else if (evt.target.hasClass("headerText")) {
columnTitleWidget.onReorderingDragStart(evt);
}
},
_onHeaderDragEnd: function(evt) {
var columnTitleWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnTitleWidget");
if (!columnTitleWidget || !evt.target.hasClass) {
return;
}
if (evt.target.hasClass("resizer")) {
columnTitleWidget.onResizerDragEnd(evt);
} else if (evt.target.hasClass("headerText")) {
columnTitleWidget.onReorderingDragEnd(evt);
}
},
_onHeaderDragOver: function(evt) {
var columnTitleWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnTitleWidget");
if (!columnTitleWidget) {
return;
}
columnTitleWidget.onReorderingDragOver(evt);
},
_onHeaderDragLeave: function(evt) {
var columnTitleWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnTitleWidget");
if (!columnTitleWidget) {
return;
}
columnTitleWidget.onReorderingDragLeave(evt);
},
_onHeaderDrag: function(evt) {
if (evt.target.hasClass && evt.target.hasClass("resizer")) {
var columnTitleWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnTitleWidget");
if (columnTitleWidget) {
columnTitleWidget.onResizerDrag(evt);
}
}
},
setDefaultItemSelection: function(b) {
this._defaultItemSelection = b;
if (b === true) {
this.setDndItemEnabled(false);
}
},
_isEventAllowItemSelection: function(evt) {
return (this.isDisplayMode() && (evt.ctrlKey || evt.metaKey || this._defaultItemSelection)) || (this.isInputMode() && (
evt.ctrlKey ||
evt.metaKey || (this._defaultItemSelection &&
!this._enabled)));
},
hasItemsSelected: function() {
if (this._itemSelectionElement === null) {
return false;
}
return !(this._itemSelectionElement.hasClass("hidden"));
},
_resetItemsSelection: function() {
this._selectionSquareIdx = {
left: {
x: null,
y: null
},
right: {
x: null,
y: null
}
};
if (this._firstItemSelected !== null) {
this._itemSelectionInProgress = false;
this._firstItemSelected = null;
if (this._itemSelectionElement) {
this._itemSelectionElement.addClass("hidden");
}
this._setItemSelection(false);
}
},
_itemSelectionMouseMovePrevX: 0,
_itemSelectionMouseMovePrevY: 0,
_onItemMouseDown: function(evt) {
if (evt.which !== 1) {
return;
}
this._itemSelectionMouseMovePrevX = evt.screenX;
this._itemSelectionMouseMovePrevY = evt.screenY;
var itemWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnItemWidget");
this._resetItemsSelection();
if (itemWidget && this._isEventAllowItemSelection(evt)) {
evt.stopPropagation();
evt.preventCancelableDefault();
if (this._itemSelectionElement === null) {
this._itemSelectionElement = document.createElement("span");
this._itemSelectionElement.addClass("gbc_TableItemSelectionArea");
this._itemSelectionElement.addClass("hidden");
this._element.appendChild(this._itemSelectionElement);
}
this._itemSelectionInProgress = true;
this._firstItemSelected = itemWidget;
this.getElement().on("mousemove.TableWidget", this._onItemMouseMove.bind(this));
this._temporaryEnabledDndOnItem(false, this._firstItemSelected);
}
},
_stopInProgressItemSelection: function(evt) {
this._itemSelectionInProgress = false;
if (this._isEventAllowItemSelection(evt)) {
this._temporaryEnabledDndOnItem(this._dndItemEnabled, this._firstItemSelected);
}
},
_onItemMouseUp: function(evt) {
this.getElement().off("mousemove.TableWidget");
this._itemSelectionMouseMovePrevX = 0;
this._itemSelectionMouseMovePrevY = 0;
this._stopInProgressItemSelection(evt);
},
_onItemMouseLeave: function(evt) {
this._stopInProgressItemSelection(evt);
},
_onItemMouseMove: function(evt) {
var movementX = (this._itemSelectionMouseMovePrevX ? evt.screenX - this._itemSelectionMouseMovePrevX : 0);
var movementY = (this._itemSelectionMouseMovePrevY ? evt.screenY - this._itemSelectionMouseMovePrevY : 0);
if (Math.abs(movementX) > 1 || Math.abs(movementY) > 1) {
if (this._itemSelectionInProgress && this._isEventAllowItemSelection(evt)) {
var itemWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnItemWidget");
if (itemWidget) {
if (this._firstItemSelected !== null) {
this._setItemSelection(true, this._firstItemSelected, itemWidget);
}
}
}
}
this._itemSelectionMouseMovePrevX = evt.screenX;
this._itemSelectionMouseMovePrevY = evt.screenY;
},
_copySelectionInClipboard: function() {
var rows = [];
var rowIndex;
var orderedColumns = this.getOrderedColumns();
for (var i = 0; i < orderedColumns.length; i++) {
var col = orderedColumns[i];
rowIndex = 0;
for (var j = 0; j < col.getChildren().length; j++) {
var item = col.getChildren()[j];
if (item.isClientSelected()) {
var text = item.getChildren()[0].getClipboardValue(true) + "\t";
if (rows.length <= rowIndex) {
rows.push(text);
} else {
rows[rowIndex] += text;
}
rowIndex++;
}
}
}
for (i = 0; i < rows.length; ++i) {
rows[i] = rows[i].substring(0, rows[i].length - 1);
}
cls.ClipboardHelper.copyTo(rows.join("\r\n"), this._element);
},
_copyCurrentRowInClipboard: function() {
var row = "";
var orderedColumns = this.getOrderedColumns();
for (var i = 0; i < orderedColumns.length; i++) {
var col = orderedColumns[i];
if (!col.isHidden()) {
if (this._currentRow >= 0 && this._currentRow < col.getChildren().length) {
var item = col.getChildren()[this._currentRow];
row += item.getChildren()[0].getClipboardValue(true);
if (i < orderedColumns.length - 1) {
row += '\t';
}
}
}
}
cls.ClipboardHelper.copyTo(row, this._element);
},
_copyCurrentCellInClipboard: function() {
var cell = "";
var col = this.getColumns()[this._currentColumn];
if (this._currentRow >= 0 && this._currentRow < col.getChildren().length) {
var item = col.getChildren()[this._currentRow];
cell = item.getChildren()[0].getClipboardValue(true);
}
cls.ClipboardHelper.copyTo(cell, this._element);
},
_setItemSelection: function(b, startSelectedItem, endSelectedItem) {
var realStartRow = -1;
var realEndRow = -1;
var realStartCol = -1;
var realEndCol = -1;
this._itemSelectionHasChanged = false;
if (b && startSelectedItem && endSelectedItem) {
var startCol = startSelectedItem.getParentWidget().getOrderedColumnIndex();
var startRow = startSelectedItem.getItemIndex();
var endCol = !endSelectedItem ? startCol : endSelectedItem.getParentWidget().getOrderedColumnIndex();
var endRow = !endSelectedItem ? startRow : endSelectedItem.getItemIndex();
this._selectionSquareIdx.left.x = realStartRow = (startRow < endRow) ? startRow : endRow;
this._selectionSquareIdx.right.x = realEndRow = (startRow < endRow) ? endRow : startRow;
this._selectionSquareIdx.left.y = realStartCol = (startCol < endCol) ? startCol : endCol;
this._selectionSquareIdx.right.y = realEndCol = (startCol < endCol) ? endCol : startCol;
var mostLeftItem = (realStartCol === startCol) ? startSelectedItem : endSelectedItem;
var mostRightItem = (realStartCol === startCol) ? endSelectedItem : startSelectedItem;
var left = mostLeftItem.getElement().getBoundingClientRect().left;
var right = mostRightItem.getElement().getBoundingClientRect().right;
var mostTopItem = (realStartRow === startRow) ? startSelectedItem : endSelectedItem;
var mostBottomItem = (realStartRow === startRow) ? endSelectedItem : startSelectedItem;
var top = mostTopItem.getElement().getBoundingClientRect().top;
var bottom = mostBottomItem.getElement().getBoundingClientRect().bottom;
var tableTop = this.getElement().getBoundingClientRect().top;
var tableLeft = this.getElement().getBoundingClientRect().left;
this.setStyle(".gbc_TableItemSelectionArea", {
"left": (left - tableLeft) + "px",
"top": (top - tableTop) + "px",
"width": (right - left) + "px",
"height": (bottom - top) + "px"
});
this._itemSelectionElement.removeClass("hidden");
this._itemSelectionHasChanged = true;
}
for (var i = 0; i < this.getOrderedColumns().length; i++) {
var col = this.getOrderedColumns()[i];
for (var j = 0; j < col.getChildren().length; j++) {
var item = col.getChildren()[j];
var select = (b && i >= realStartCol && i <= realEndCol && j >= realStartRow && j <= realEndRow);
item.setClientSelected(select);
}
}
},
_temporaryEnabledDndOnItem: function(b, item) {
if (item) {
item.setDndEnabled(b);
if (b) {
this.getColumnsContainer().setAttribute("draggable", "true");
} else {
this.getColumnsContainer().removeAttribute("draggable");
}
}
},
setDndItemEnabled: function(b) {
if (b && this._defaultItemSelection) {
return;
}
if (this._dndItemEnabled !== b) {
this._dndItemEnabled = b;
var columns = this.getColumns();
for (var i = 0; i < columns.length; i++) {
columns[i].setDndItemEnabled(b);
}
var columnsContainer = this.getColumnsContainer();
if (b) {
columnsContainer.setAttribute("draggable", "true");
columnsContainer.on("dragstart.TableWidget", this._onItemDragStart.bind(this));
columnsContainer.on("dragend.TableWidget", this._onItemDragEnd.bind(this));
columnsContainer.on("dragover.TableWidget", this._onItemDragOver.bind(this));
columnsContainer.on("drop.TableWidget", this._onItemDrop.bind(this));
columnsContainer.on("dragleave.TableWidget", this._onItemDragLeave.bind(this));
columnsContainer.on("dragenter.TableWidget", this._onItemDragEnter.bind(this));
} else {
columnsContainer.removeAttribute("draggable");
columnsContainer.off("dragstart.TableWidget");
columnsContainer.off("dragend.TableWidget");
columnsContainer.off("dragover.TableWidget");
columnsContainer.off("drop.TableWidget");
columnsContainer.off("dragleave.TableWidget");
columnsContainer.off("dragenter.TableWidget");
}
}
},
_onItemDragStart: function(evt) {
var itemWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnItemWidget");
if (itemWidget) {
itemWidget.onDragStart(evt);
}
},
_onItemDragEnd: function(evt) {
var itemWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnItemWidget");
if (itemWidget) {
itemWidget.onDragEnd(evt);
}
},
_onItemDragOver: function(evt) {
var itemWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnItemWidget");
if (itemWidget) {
itemWidget.onDragOver(evt);
} else {
if (evt.target.hasClass("gbc_TableAfterLastItemZone")) {
var columnWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnWidget");
columnWidget.onDragOverAfterLastItem(evt);
}
}
},
_onItemDrop: function(evt) {
var itemWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnItemWidget");
if (itemWidget) {
itemWidget.onDrop(evt);
} else {
if (evt.target.hasClass("gbc_TableAfterLastItemZone")) {
var columnWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnWidget");
columnWidget.onDropAfterLastItem(evt);
}
}
},
_onItemDragLeave: function(evt) {
var itemWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnItemWidget");
if (itemWidget) {
itemWidget.onDragLeave(evt);
}
},
_onItemDragEnter: function(evt) {
var itemWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnItemWidget");
if (itemWidget) {
itemWidget.onDragEnter(evt);
}
},
_onDoubleClick: function(evt) {
var columnWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnWidget");
if (!columnWidget) {
return;
}
if (this.isRowActionTriggerByDoubleClick()) {
columnWidget.emit(context.constants.widgetEvents.rowAction);
}
},
_onLongTouch: function(evt) {
var columnTitleWidget = gbc.WidgetService.getWidgetFromElement(evt.target, "gbc_TableColumnTitleWidget");
if (columnTitleWidget) {
columnTitleWidget.manageMouseRightClick(evt);
} else {
$super.manageMouseRightClick.call(this, evt);
}
},
getLeftContainer: function() {
if (!this._leftContainerElement) {
this._leftContainerElement = this._element.getElementsByClassName("gbc_TableLeftContainer")[0];
}
return this._leftContainerElement;
},
getRightContainer: function() {
if (!this._rightContainerElement) {
this._rightContainerElement = this._element.getElementsByClassName("gbc_TableRightContainer")[0];
}
return this._rightContainerElement;
},
getColumnsContainer: function() {
if (!this._columnsContainerElement) {
this._columnsContainerElement = this._element.getElementsByClassName("gbc_TableColumnsContainer")[0];
}
return this._columnsContainerElement;
},
getLeftColumnsContainer: function() {
if (!this._leftColumnsContainer) {
this._leftColumnsContainer = this._element.getElementsByClassName("gbc_TableLeftColumnsContainer")[0];
}
return this._leftColumnsContainer;
},
getRightColumnsContainer: function() {
if (!this._rightColumnsContainer) {
this._rightColumnsContainer = this._element.getElementsByClassName("gbc_TableRightColumnsContainer")[0];
}
return this._rightColumnsContainer;
},
getColumnsHeaders: function() {
if (!this._columnsHeaders) {
this._columnsHeaders = this._element.getElementsByClassName("gbc_TableColumnsHeaders")[0];
}
return this._columnsHeaders;
},
getLeftColumnsHeaders: function() {
if (!this._leftColumnsHeaders) {
this._leftColumnsHeaders = this._element.getElementsByClassName("gbc_TableLeftColumnsHeaders")[0];
}
return this._leftColumnsHeaders;
},
getRightColumnsHeaders: function() {
if (!this._rightColumnsHeaders) {
this._rightColumnsHeaders = this._element.getElementsByClassName("gbc_TableRightColumnsHeaders")[0];
}
return this._rightColumnsHeaders;
},
getColumnsFooter: function() {
if (!this._columnsFooter) {
this._columnsFooter = this.getElement().getElementsByClassName("gbc_TableColumnsFooter")[0];
}
return this._columnsFooter;
},
getLeftColumnsFooter: function() {
if (!this._leftColumnsFooter) {
this._leftColumnsFooter = this.getElement().getElementsByClassName("gbc_TableLeftColumnsFooter")[0];
}
return this._leftColumnsFooter;
},
getRightColumnsFooter: function() {
if (!this._rightColumnsFooter) {
this._rightColumnsFooter = this.getElement().getElementsByClassName("gbc_TableRightColumnsFooter")[0];
}
return this._rightColumnsFooter;
},
getScrollableArea: function() {
if (!this._scrollAreaElement) {
this._scrollAreaElement = this._element.getElementsByClassName("gbc_TableScrollArea")[0];
}
return this._scrollAreaElement;
},
getRightScrollableArea: function() {
if (!this._rightScrollAreaElement) {
this._rightScrollAreaElement = this._element.getElementsByClassName("gbc_TableRightScrollArea")[0];
}
return this._rightScrollAreaElement;
},
getLeftScrollableArea: function() {
if (!this._leftScrollAreaElement) {
this._leftScrollAreaElement = this._element.getElementsByClassName("gbc_TableLeftScrollArea")[0];
}
return this._leftScrollAreaElement;
},
getAggregateGlobalTextElement: function() {
return this._aggregateGlobalTextElement;
},
canShowCopyCellAndRow: function() {
return this._currentRow >= 0 && this._selectionSquareIdx.left.x === null;
}
};
});
cls.WidgetFactory.registerBuilder('Table', cls.TableWidget);
});