UNPKG

nscomponentsreact

Version:

React Wrapper Components for NSComponents

1,748 lines (1,650 loc) 162 kB
var nsModuleExport = function(root,name,prototype) { if(typeof exports === 'object' && typeof module === 'object') { module.exports[name] = prototype; } else if (typeof define === "function" && define.amd) { define(name,[], function () {return prototype;}); } else if(typeof exports === 'object') { exports[name] = prototype; } else { root[name] = prototype; } };var nsIsWeb = function(root) { if(typeof exports === 'object' && typeof module === 'object') { return false; } else if (typeof define === "function" && define.amd) { return false; } else if(typeof exports === 'object') { return false; } else { return true; } };if(!nsIsWeb()) { var nsutilRef = require('./nsUtil.min.js'); var NSUtil = nsutilRef.NSUtil; var nscontainerbaseRef = require('./nsContainerBase.min.js'); var nsExtendPrototype = nscontainerbaseRef.nsExtendPrototype; var NSContainerBase = nscontainerbaseRef.NSContainerBase; var svgRef = require('./nsSVG.min.js'); var NSSvg = svgRef.NSSvg; var NSSvgShapes = svgRef.NSSvgShapes; var plugginsRef = require('./nsPluggins.min.js'); var nsTextEditor = plugginsRef.nsTextEditor; var nsTextAreaEditor = plugginsRef.nsTextAreaEditor; var NSCellSelection = plugginsRef.NSCellSelection; var NSTableCellNavigator = plugginsRef.NSTableCellNavigator; var dateutilRef = require('./nsDateUtil.min.js'); var NSDateUtil = dateutilRef.NSDateUtil; var gridRef = require('./nsGrid.min.js'); var NSGrid = gridRef.NSGrid; } var NSList = (function() { function NSList(component,setting) { //this.base.call(this); this.ITEM_SELECTED = "itemSelected"; this.ITEM_UNSELECTED = "itemUnselected"; this.ITEM_NAVIGATED = "itemNavigated"; this.NAVIGATION_UP = "up"; this.NAVIGATION_DOWN = "down"; this.ITEM_DROPPING = "itemDropping"; this.ITEM_DROPPED = "itemDropped"; this.DRAG_STARTED = "dragStarted"; this.DRAGGING = "dragging"; this.DRAG_END = "dragEnd"; this.__setting = setting; this.__dataSource = null; this.__labelField = "label"; this.__itemRenderer = null; this.__templateID = null; this.__setData = null; this.__labelFunction = null; this.__enableHierarchical = false; this.__enableMouseHover = false; this.__enableMouseHoverAnimation = false; this.__disableHoverField = null; this.__disableHoverFunction = null; this.__enableKeyboardNavigation = false; this.__enableMultipleSelection = false; this.__enableCustomScrollBar = false; this.__enableVirtualScroll = false; this.__isDraggable = true; this.__isDroppable = true; this.__enableDragByHandle = false; this.__dragHandlerClass = null; this.__enableDragAfterHold = false; this.__holdTime = 500; this.__enableCloneMode = false; this.__rowHeight = -1; this.__noDataMessage = "No matching records found"; this.__enableContextMenu = false; this.__enableVariableRowHeight = false; this.__contextMenuProvider = null; this.__contextMenuSetting = null; this.__enableTruncateToFit = false; this.__toolTipField = null; this.__enableToolTipForTruncateText = false; this.__toolTipRenderer = null; this.__arrWrapper = null; this.__arrInternalSource = null; this.__arrFlatHierarchicalSource = []; this.__divOuterContainer = null; this.__divParentContainer = null; this.__listContainer = null; this.__scroller = null; this.__scrollerSetting = {}; this.__customScrollBarSetting = {}; this.__customScrollBarTooltip = null; this.__template = null; this.__currentIndex = -1; this.__selectedIndex = -1; this.__navigationIndex = -1; this.__selectedItem = null; this.__selectedItems = []; this.__selectedIndexes = []; this.__lastNavigationDirection = null; this.__orignalItemKey = []; //for keyboard navigation this.__pageSize = 0; this.__scrollTarget = null; this.__startArrayElement = -1; this.__listItemHeight = 0; //for Virtual Scroll this.__virtualScrollSetting = {}; this.__nsVirtualScroll = null; this.__virtualRowHeight = 0; this.__childField = "children"; this.__CLASS_GROUP_CELL = "nsListGroupCell"; this.__CLASS_CELL_CHILD = "nsListCellChild"; //removing this.getID() as prefix as move functionality from one list to another would have different fields. this.__fieldPrefix = "ns_field"; this.__fieldIndex = this.__fieldPrefix + "_item_index"; this.__fieldVisibleIndex = this.__fieldPrefix + "_item_visible_index"; this.__fieldItem = this.__fieldPrefix + "_item"; this.__fieldDisableHover = this.__fieldPrefix + "_disableHover"; this.__fieldSelected = this.__fieldPrefix + "_selected"; this.__fieldHover = this.__fieldPrefix + "_hover"; this.__fieldItemLevel = this.__fieldPrefix + "_item_level"; this.__fieldItemVisible = this.__fieldPrefix + "_item_visible"; this.__fieldParentIndex = this.__fieldPrefix + "_parent_index"; this.__fieldHasChild = this.__fieldPrefix + "_item_hasChild"; this.__fieldHasParent = this.__fieldPrefix + "_item_hasParent"; this.__fieldIsCollapsed = this.__fieldPrefix + "_item_isCollapsed"; this.__fieldItemArrow = this.__fieldPrefix + "_item_arrow"; this.__isShiftPressed = false; this.__isCtrlPressed = false; this.__objGrid = null; this.__nsListFilter = null; this.__nsListDragDrop = null; this.__nsToolTipInElement = null; this.__keyDownRef = null; this.__keyUpRef = null; this.base.__setBaseComponent.call(this,component); }; nsExtendPrototype(NSContainerBase,NSList); NSList.prototype.constructor = NSList; NSList.prototype.initializeComponent = function() { this.base.initializeComponent.call(this); this.__setSetting(); this.__initializePluggins(); }; NSList.prototype.setComponentProperties = function() { this.base.setComponentProperties.call(this); this.__objGrid.__addSVGInPage(); this.__setTemplate(); this.__objGrid.__initialize(); this.__addListenerForBody(); if(this.__dataSource) { this.dataSource(this.__dataSource); } if(!window["nsListMap"]) { window["nsListMap"] = {}; } window["nsListMap"][this.getID()] = this; }; NSList.prototype.propertyChange = function(attrName, oldVal, newVal, setProperty) { var attributeName = attrName.toLowerCase(); this.base.propertyChange.call(this,attrName, oldVal, newVal, setProperty); }; NSList.prototype.removeComponent = function() { if(this.__keyDownRef) { this.util.removeEvent(document,"keydown",this.__keyDownRef); this.__keyDownRef = null; } if(this.__keyUpRef) { this.util.removeEvent(document,"keyup",this.__keyUpRef); this.__keyUpRef = null; } if(this.__scroller) { this.__scroller.__destroyElements(); this.__scroller = null; } this.base.removeComponent.call(this); }; NSList.prototype.componentResized = function(event) { this.base.componentResized.call(this,event); }; NSList.prototype.expandAll = function() { if(this.__enableHierarchical) { this.__expandCollapseAll(false); } }; NSList.prototype.collapseAll = function() { if(this.__enableHierarchical) { this.__expandCollapseAll(true); } }; NSList.prototype.setContextMenuSetting = function(contextMenuSetting) { this.__contextMenuSetting = contextMenuSetting; }; NSList.prototype.__setSetting = function() { var setting = this.__setting; if(setting) { if(setting.hasOwnProperty("enableHierarchical")) { this.__enableHierarchical = Boolean.parse(setting["enableHierarchical"]); } if(setting.hasOwnProperty("enableVirtualScroll")) { this.__enableVirtualScroll = Boolean.parse(setting["enableVirtualScroll"]); } if(setting.hasOwnProperty("enableDragDrop")) { if(!this.__enableVirtualScroll) { this.__enableDragDrop = Boolean.parse(setting["enableDragDrop"]); } } if(setting.hasOwnProperty("isDraggable")) { this.__isDraggable = Boolean.parse(setting["isDraggable"]); } if(setting.hasOwnProperty("isDroppable")) { this.__isDroppable = Boolean.parse(setting["isDroppable"]); } if(setting.hasOwnProperty("enableDragByHandle")) { this.__enableDragByHandle = Boolean.parse(setting["enableDragByHandle"]); } if(setting.hasOwnProperty("dragHandlerClass")) { this.__dragHandlerClass = setting["dragHandlerClass"]; } if(setting.hasOwnProperty("enableDragAfterHold")) { this.__enableDragAfterHold = Boolean.parse(setting["enableDragAfterHold"]); } if(setting.hasOwnProperty("holdTime")) { this.__holdTime = parseInt(setting["holdTime"]); } if(setting.hasOwnProperty("enableCloneMode")) { this.__enableCloneMode = Boolean.parse(setting["enableCloneMode"]); } if(setting.hasOwnProperty("labelField")) { this.__labelField = setting["labelField"]; } if(setting.hasOwnProperty("itemRenderer")) { this.__itemRenderer = setting["itemRenderer"]; this.__itemRenderer = this.util.getFunction(this.__itemRenderer); } if(setting.hasOwnProperty("template")) { this.__templateID = setting["template"]; } if(setting.hasOwnProperty("setData")) { this.__setData = setting["setData"]; } if(setting.hasOwnProperty("labelFunction")) { this.__labelFunction = setting["labelFunction"]; this.__labelFunction = this.util.getFunction(this.__labelFunction); } if(setting.hasOwnProperty("enableMultipleSelection")) { this.__enableMultipleSelection = Boolean.parse(setting["enableMultipleSelection"]); } if(setting.hasOwnProperty("enableCustomScrollBar")) { this.__enableCustomScrollBar = Boolean.parse(setting["enableCustomScrollBar"]); } if(setting.hasOwnProperty("enableKeyboardNavigation")) { this.__enableKeyboardNavigation = Boolean.parse(setting["enableKeyboardNavigation"]); } if(setting.hasOwnProperty("enableMouseHover")) { this.__enableMouseHover = Boolean.parse(setting["enableMouseHover"]); } if(setting.hasOwnProperty("enableMouseHoverAnimation")) { this.__enableMouseHoverAnimation = Boolean.parse(setting["enableMouseHoverAnimation"]); } if(setting.hasOwnProperty("disableHoverField")) { this.__disableHoverField = setting["disableHoverField"]; } if(setting.hasOwnProperty("disableHoverFunction")) { this.__disableHoverFunction = setting["disableHoverFunction"]; this.__disableHoverFunction = this.util.getFunction(this.__disableHoverFunction); } if(setting.hasOwnProperty("rowHeight")) { this.__rowHeight = parseInt(setting["rowHeight"]); } if(setting.hasOwnProperty("noDataMessage")) { this.__noDataMessage = setting["noDataMessage"]; } if(setting.hasOwnProperty("dataSource")) { this.__dataSource = setting["dataSource"]; } if(setting.hasOwnProperty("childField")) { this.__childField = setting["childField"]; } if(setting.hasOwnProperty("enableContextMenu")) { this.__enableContextMenu = Boolean.parse(setting["enableContextMenu"]); } if(setting.hasOwnProperty("contextMenuProvider")) { this.__contextMenuProvider = setting["contextMenuProvider"]; this.__contextMenuProvider = this.util.getFunction(this.__contextMenuProvider); } if(setting.hasOwnProperty("enableVariableRowHeight")) { this.__enableVariableRowHeight = Boolean.parse(setting["enableVariableRowHeight"]); } if(setting.hasOwnProperty("customScrollBarSetting")) { this.__customScrollBarSetting = setting["customScrollBarSetting"]; } else { this.__customScrollBarSetting = {enableTooltip: false,toolTipLabelFunction: null,verticalScrollButtons: {enable: false},horizontalScrollButtons:{enable: false}}; } if(setting.hasOwnProperty("virtualScrollSetting")) { this.__virtualScrollSetting = setting["virtualScrollSetting"]; } else { this.__virtualScrollSetting = {pageSize: null,pagesRendered: null,enableScrollDelay: false,scrollInterval: null,resizeInterval: null,enableLoader: false,getLoaderComponent: null}; } } }; NSList.prototype.dataSource = function(source) { this.__dataSource = source; if(this.__listContainer) { this.util.removeAllChildren(this.__listContainer); } else { this.__createStructure(); } if(this.__dataSource && this.__dataSource.length > 0) { this.__orignalItemKey = Object.keys(this.__dataSource[0]); this.__objGrid.dataSource(); } else { this.__arrWrapper = []; this.__arrInternalSource = []; this.__updateTotalRecords(0); } this.__renderBody(); }; NSList.prototype.getOrignalItem = function(item) { if(item && this.__orignalItemKey && this.__orignalItemKey.length > 0) { var retItem = {}; var key = null; for(var count = 0;count < this.__orignalItemKey.length;count++) { key = this.__orignalItemKey[count]; retItem[key] = item[key]; } return retItem; } return item; }; NSList.prototype.addItems = function(arrItem) { this.__addItem(arrItem); }; NSList.prototype.addItemsAsChildren = function(item,arrChildren) { this.__objGrid.addItemsAsChildren(item,arrChildren); }; NSList.prototype.removeItems = function(arrObject) { if(arrObject && arrObject.length > 0) { var arrIndex = []; if(this.util.isNumber(arrObject[0])) { arrIndex = arrObject; } else { for (var count = 0;count < arrObject.length;count++) { var item = arrObject[count]; if(item && item[this.__fieldIndex]) { arrIndex.push(item[this.__fieldIndex]); } } } arrIndex.sort(); for (var rowIndex = arrIndex.length - 1; rowIndex >= 0; rowIndex--) { var index = arrIndex[rowIndex]; if(index > 0 && index < this.__arrInternalSource.length) { //if virtual scroll or Pagination of type Page is enabled then do not remove rows if(!this.__enableVirtualScroll) { this.__listContainer.removeChild(this.__listContainer.childNodes[index]); } this.__arrInternalSource.splice(index, 1); this.__arrWrapper.splice(index, 1); } } this.__updateTotalRecords(); } }; NSList.prototype.scrollToIndex = function(selectedIndex,animationRequired) { selectedIndex = parseInt(selectedIndex); var source = this.__objGrid.__getFlatSource(); if(selectedIndex > -1 && source && selectedIndex < source.length) { var item = this.__getItemByIndex(selectedIndex); if(item) { if(this.__enableVirtualScroll) { if(this.__enableCustomScrollBar) { var targetDimension = this.__virtualRowHeight * (selectedIndex - 1); this.__setVirtualScroll_ScrollTop(targetDimension); } else { //var item = this.__getVisibleItemByIndex(this.__arrInternalSource,selectedIndex); if(this.__nsVirtualScroll) { //because in list index is index+1 this.__nsVirtualScroll.scrollToIndex(selectedIndex - 1,animationRequired); } } } else { if(item[this.__fieldItem]) { var targetDimension = item[this.__fieldItem].offsetTop; var scrollTarget = this.__divOuterContainer; if(animationRequired) { var animation = new this.util.animation(scrollTarget,[ { time: 500, property:"scrollTop", target: targetDimension, } ]); animation.animate(); } else { scrollTarget.scrollTop = targetDimension; } } } } } }; NSList.prototype.setSelectedItems = function(arrItems) { if(arrItems && arrItems.length > 0) { var source = this.__objGrid.__getFlatSource(); if(source) { this.__clearAllRowSelection(false); var length = arrItems.length; var item = null; var index = -1; for(var count = 0;count < length;count++) { item = arrItems[count]; index = this.__getIndexByItem(item); if(index > -1 && source && index < source.length) { this.__setIndex(index,true); } } } } }; NSList.prototype.setSelectedItem = function(arrItems) { this.setSelectedItems([arrItems]); }; NSList.prototype.setSelectedIndexes = function(arrSelectedIndex) { if(arrSelectedIndex && arrSelectedIndex.length > 0) { var source = this.__objGrid.__getFlatSource(); if(source) { var length = arrSelectedIndex.length; var index = -1; for(var count = 0;count < length;count++) { index = arrSelectedIndex[count]; if(index > -1 && source && index < source.length) { this.__setIndex(index,true); } } } } }; NSList.prototype.setSelectedIndex = function(selectedIndex) { this.setSelectedIndexes([selectedIndex]); }; NSList.prototype.unSelectItems = function(arrItems) { }; NSList.prototype.unSelectItem = function(arrItems) { this.unSelectItems([arrItems]); }; NSList.prototype.unSelectIndexes = function(arrSelectedIndex) { }; NSList.prototype.unSelectIndex = function(selectedIndex) { this.unSelectIndexes([selectedIndex]); }; NSList.prototype.getSelectedIndex = function() { return this.__selectedIndex; }; NSList.prototype.getSelectedItem = function() { return this.__selectedItem; }; NSList.prototype.getSelectedIndexes = function() { return this.__selectedIndexes; }; NSList.prototype.getSelectedItems = function() { return this.__selectedItems; }; NSList.prototype.deselectAll = function() { this.__clearAllRowSelection(true); }; NSList.prototype.filter = function(strData,setting,enableHighlighting,recordLimit) { this.__nsListFilter.filter(strData,setting,enableHighlighting,recordLimit); }; NSList.prototype.resetFilter = function() { this.__nsListFilter.reset(); }; NSList.prototype.updateListItemByIndex = function(index) { var item = this.__getItemByIndex(index); if(item) { var listItem = this.__getListItemFromItem(item); if(listItem) { var index = this.__getIndexByItem(item); this.__updateListItemText(listItem,item,index); } } }; NSList.prototype.__highlightDiv = function(divText) { this.__nsListFilter.__highlightDiv(divText); }; NSList.prototype.__initializePluggins = function() { if(!this.__objGrid) { if(this.__enableHierarchical) { this.__objGrid = new NSHierarchicalList(this); } else { this.__objGrid = new NSFlatList(this); } } if(!this.__nsListFilter) { this.__nsListFilter = new NSListFilter(this); if(this.__enableDragDrop) { this.__nsListDragDrop = new NSListDragDrop(this); } } this.__nsToolTipInElement = new this.util.nsToolTipInElement(); }; NSList.prototype.__createStructure = function() { if(!this.__divOuterContainer) { this.__divOuterContainer = this.util.createDiv(this.getID() + "container","nsListOuterContainer"); if(this.__enableHierarchical) { this.util.addStyleClass(this.__divOuterContainer,"nsListOuterContainerHierarchical") } this.__divOuterContainer.style.width = this.util.getStyleValue(this.__baseComponent,"width"); //this.__divOuterContainer.style.height = this.util.getStyleValue(this.__baseComponent,"height"); this.addChild(this.__divOuterContainer); this.__divParentContainer = this.util.createDiv(this.getID() + "parentContainer","nsListParentContainer"); this.__divOuterContainer.appendChild(this.__divParentContainer); this.__listContainer = this.util.createElement("ul",this.getID() + "list","nsListContainer"); this.__listContainer.style.minHeight = (this.__divOuterContainer.clientHeight - 10) + "px"; this.__divParentContainer.appendChild(this.__listContainer); if(this.__enableVirtualScroll) { this.util.addStyleClass(this.__divParentContainer,"nsListBodyContainerVirtual"); } this.__createCustomScroller(); } }; NSList.prototype.__renderBody = function() { this.__navigationIndex = -1; if(this.__enableContextMenu) { this.__initializeContextMenu(); } if(this.__enableVirtualScroll) { this.__setNSVirtualScroll(this.__arrInternalSource); } else { this.util.removeAllChildren(this.__listContainer); this.__createList(this.__arrInternalSource,0,this.__arrInternalSource.length); //5 is offset for number of rows var listItem = this.__getListItemByIndex(0); if(listItem) { this.__listItemHeight = listItem.clientHeight; } this.__pageSize = (this.__divOuterContainer.clientHeight/this.__listItemHeight) - 5; this.__startArrayElement = 0; } //this.__listContainer.scrollTop = 0; if(this.__nsListDragDrop) { this.__nsListDragDrop.initialize(); } }; NSList.prototype.__setNSVirtualScroll = function(source) { var length = 0; if(source && source.length) { for(var count = 0;count < source.length;count++) { if(source[count][this.__fieldItemVisible]) { length++; } } } if(this.__nsVirtualScroll) { this.__nsVirtualScroll.dataSource(length); } else { if(length > 0) { if(this.__rowHeight > 0) { this.__virtualRowHeight = this.__rowHeight; } else { this.__createList(this.__arrInternalSource,0,1); var item = this.__arrInternalSource[0]; var listItem = item[this.__fieldItem]; this.__virtualRowHeight = listItem.offsetHeight; listItem.parentNode.removeChild(listItem); } var setting = {scrollElement: this.__divOuterContainer,contentElement: this.__listContainer,itemTag: "li",totalLength: length,getItemComponent:this.__getItemComponentForVirtual.call(this),getEmptyItemComponent:this.__getEmptyItemComponentForVirtual.call(this)}; var virtualScrollSetting = this.__virtualScrollSetting; var arrCopyFields = ["pageSize","pagesRendered","enableScrollDelay","scrollInterval","resizeInterval","enableLoader","getLoaderComponent"]; var field = null; for(var count = 0;count < arrCopyFields.length;count++) { field = arrCopyFields[count]; if(!this.util.isUndefinedOrNull(virtualScrollSetting[field])) { setting[field] = virtualScrollSetting[field]; } } this.__nsVirtualScroll = new NSVirtualScroll(setting); } } }; NSList.prototype.__getItemComponentForVirtual = function() { var list = this; var CreateListItem = function(index) { this.__index = index; this.__list = list; this.__item = null; this.__listItem = null; }; CreateListItem.prototype.getElement = function() { if(!this.__listItem) { if(this.__list.__enableHierarchical) { this.__item = this.__list.__getVisibleItemByIndex(null,this.__index); } else { this.__item = this.__list.__arrInternalSource[this.__index]; } this.__listItem = this.__list.__createListItem(this.__item,false); } return this.__listItem; }; return CreateListItem; }; NSList.prototype.__getEmptyItemComponentForVirtual = function() { var list = this; var CreateEmptyListItem = function() { this.__list = list; this.__listItem = null; }; CreateEmptyListItem.prototype.getElement = function() { if(!this.__listItem) { this.__listItem = this.__list.__createNoDataRow.call(this.__list); } return this.__listItem; }; return CreateEmptyListItem; }; NSList.prototype.__createCustomScroller = function() { if(this.__enableCustomScrollBar && !this.__scroller) { var setting = {element: this.__divOuterContainer,enableCustomHandler: true,verticalScrollButtons:this.__customScrollBarSetting.verticalScrollButtons,horizontalScrollButtons:this.__customScrollBarSetting.horizontalScrollButtons}; for (var key in setting) { this.__scrollerSetting[key] = setting[key]; } this.__scroller = new NSScroller(this.__scrollerSetting); this.util.addEvent(this.__scrollerSetting.element,NSScroller.SCROLLING,this.__customScrollHandler.bind(this)); this.util.addEvent(this.__scrollerSetting.element,NSScroller.SCROLL_END,this.__customScrollEndHandler.bind(this)); } }; NSList.prototype.__customScrollHandler = function(event) { var self = this; var virtualVerHandler = function() { //todo Virtual Scroll impl for Custom Scroll Bar }; var dataRefreshVerHandler = function() { }; var asyncLoadVerHandler = function() { }; var paginationVerHandler = function() { }; var normalVerHandler = function() { self.__divOuterContainer.scrollTop = scrollPos; var first,last; var arrRows = self.__listContainer.querySelectorAll("li"); for(var count = 0;count < arrRows.length;count++) { var li = arrRows[count]; if(isInViewport(li)) { first = li; break; } } for(;count < arrRows.length;count++) { var li = arrRows[count]; if(!isInViewport(li)) { break; } last = li; } console.log(first,last); }; var normalHorHandler = function() { self.__divOuterContainer.scrollLeft = scrollPos; }; var isInViewport = function (elem) { if(elem) { /*var distance = elem.getBoundingClientRect(); return ( distance.top >= 0 && distance.left >= 0 && distance.bottom <= (window.innerHeight || document.documentElement.clientHeight) && distance.right <= (window.innerWidth || document.documentElement.clientWidth) );*/ const rect = elem.getBoundingClientRect(); const windowHeight = (window.innerHeight || document.documentElement.clientHeight); const windowWidth = (window.innerWidth || document.documentElement.clientWidth); const vertInView = (rect.top <= windowHeight) && ((rect.top + rect.height) >= 0); const horInView = (rect.left <= windowWidth) && ((rect.left + rect.width) >= 0); return (vertInView && horInView); } return false; }; var objCondition = {virtualScroll:{eligible:this.__enableVirtualScroll,verHandler:virtualVerHandler,horHandler:normalHorHandler}, dataRefreshOnEnd:{eligible:this.__enableDataRefreshOnScrollEnd,verHandler:dataRefreshVerHandler,horHandler:normalHorHandler}, asyncLoad:{eligible:this.__enableAsyncLoadPagination,verHandler:asyncLoadVerHandler,horHandler:normalHorHandler}, pagination:{eligible:(this.__enablePagination && this.__isPaginationTypeScroll),verHandler:paginationVerHandler,horHandler:normalHorHandler}, normal:{eligible:true,verHandler:normalVerHandler,horHandler:normalHorHandler} }; var eventItem = event; var direction = eventItem.direction; var scrollPos = eventItem.scrollPos; var oldScrollPos = eventItem.oldScrollPos; var orignalEvent = eventItem.orignalEvent; var scrollBar = eventItem.scrollBar; var position = eventItem.absoluteScrollBarPos; for(var key in objCondition) { var item = objCondition[key]; if(item.eligible) { if(direction == "vertical") { if(item.verHandler) { if(this.__customScrollBarSetting["enableTooltip"] && !this.__customScrollBarTooltip) { this.__customScrollBarTooltip = this.util.createElement("span",null,"tooltiptext tooltip-left"); document.body.appendChild(this.__customScrollBarTooltip); } item.verHandler(); } } else { if(item.horHandler) { item.horHandler(); } } break; } } }; NSList.prototype.__customScrollEndHandler = function(event) { if(this.__customScrollBarTooltip) { document.body.removeChild(this.__customScrollBarTooltip); this.__customScrollBarTooltip = null; } }; NSList.prototype.__customScrollTooltipPos = function(scrollbar,position,itemFrom,itemTo) { if(this.__customScrollBarTooltip) { var toolTip = this.__customScrollBarTooltip; var css = {}; //5 for the triangle css.left = (position.x - toolTip.offsetWidth - 5) + "px"; css.top = position.y + "px"; this.util.css(toolTip,css); if(this.__customScrollBarSetting.toolTipLabelFunction) { toolTip.innerHTML = this.__customScrollBarSetting.toolTipLabelFunction(itemFrom,itemTo); } else { toolTip.innerHTML = "Showing Record from index " + itemFrom + " to " + itemTo; } } }; NSList.prototype.__virtualRowSelection = function() { if(this.__listContainer.children && this.__listContainer.children.length > 0 && this.__arrInternalSource) { var listItem = null; var index = null; var item = null; for(var count = 0; count < this.__listContainer.children.length; count++) { listItem = this.__listContainer.children[count]; index = this.__getIndexFromTarget(listItem); item = this.__getItemByIndex(index); if(item && this.__isMouseHoverAllowed(index)) { if(item[this.__fieldSelected]) { //DONOT REPLACE WITH __markRowSelected this.util.addStyleClass(listItem,"nsListItemSelected"); } else { //DONOT REPLACE WITH __markRowUnselected this.util.removeStyleClass(listItem,"nsListItemSelected"); } } } } }; NSList.prototype.__virtualRowHover = function() { if(this.__listContainer.children && this.__listContainer.children.length > 0 && this.__arrInternalSource) { var listItem = null; var index = null; var item = null; for(var count = 0; count < this.__listContainer.children.length; count++) { listItem = this.__listContainer.children[count]; index = this.__getIndexFromTarget(listItem); item = this.__getItemByIndex(index); (item && item[this.__fieldHover]) ? this.util.addStyleClass(listItem,"nsListItemHover") : this.util.removeStyleClass(listItem,"nsListItemHover"); } } }; NSList.prototype.__setVirtualRowHoverField = function(indexToSet) { if(this.util.isUndefinedOrNull(indexToSet)) { indexToSet = -1; } var source = this.__objGrid.__getFlatSource(); if(source) { var item = null; for(var count = 0; count < source.length; count++) { var item = source[count]; if(item) { item[this.__fieldHover] = (item[this.__fieldIndex] === indexToSet); } } } }; NSList.prototype.__setVirtualRowHover = function(indexToSet) { if(this.__enableVirtualScroll) { if(this.util.isUndefinedOrNull(indexToSet)) { indexToSet = 0; } var item = this.__getVisibleItemByIndex(null,indexToSet); if(item) { this.__navigationIndex = indexToSet; var index = item[this.__fieldIndex]; this.__setVirtualRowHoverField(index); this.__virtualRowHover(); } } }; NSList.prototype.__setRowHover = function(indexToSet) { if(this.util.isUndefinedOrNull(indexToSet)) { indexToSet = 0; } if(this.__enableVirtualScroll) { this.__setVirtualRowHover(indexToSet); } else { if(this.util.isUndefinedOrNull(indexToSet)) { indexToSet = 0; } this.__navigationIndex = indexToSet; var listItem = this.__getListItemFromContainer(this.__navigationIndex); this.util.addStyleClass(listItem,"nsListItemHover"); } }; NSList.prototype.__createNoDataRow = function() { var listItem = this.util.createElement("li",null,"nsListNoRecordsFound"); listItem.setAttribute("nsNoData","true"); var textNode = document.createTextNode(this.__noDataMessage); listItem.appendChild(textNode); return listItem; }; NSList.prototype.__addListenerForBody = function() { if(!this.__keyDownRef) { this.__keyDownRef = this.__keyDownHandler.bind(this); this.util.addEvent(document,"keydown",this.__keyDownRef); } if(!this.__keyUpRef) { this.__keyUpRef = this.__keyUpHandler.bind(this); this.util.addEvent(document,"keyup",this.__keyUpRef); } }; NSList.prototype.__createList = function(dataSet,startIndex,endIndex) { if(dataSet && dataSet.length > 0) { this.__objGrid.__createList(dataSet,startIndex,endIndex); } else { this.__listContainer.appendChild(this.__createNoDataRow()); } }; NSList.prototype.__createListAt = function(item,index,isResetIndex) { if(item && index > -1) { this.__updateItem(item,index,true,isResetIndex); var listItem = this.__createListItem(item,false); this.__listContainer.insertBefore(listItem, this.__listContainer.childNodes[index]); return listItem; } return null; }; NSList.prototype.__updateItem = function(item,index,isReset,isResetIndex) { if(item) { if(isResetIndex || !item.hasOwnProperty(this.__fieldIndex)) { item[this.__fieldIndex] = index; } if(isReset || !item.hasOwnProperty(this.__fieldDisableHover)) { item[this.__fieldDisableHover] = this.__isHoverDisabled(item); } if(isReset || !item.hasOwnProperty(this.__fieldSelected)) { item[this.__fieldSelected] = false; } } }; NSList.prototype.__createListItem = function(item,isAdd) { if(item) { if(this.util.isUndefined(isAdd) || isAdd === null) { isAdd = true; } var listItem = this.util.createElement("li",null,"nsListItem"); this.__objGrid.__createListItem(listItem,item); if(this.__enableMouseHover) { this.util.addEvent(listItem,"mouseover",this.__itemMouseOverHandler.bind(this)); this.util.addEvent(listItem,"mouseout",this.__itemMouseOutHandler.bind(this)); if(this.__enableMouseHoverAnimation) { this.util.addStyleClass(listItem,"nsListItemAnimated"); } else { this.util.addStyleClass(listItem,"nsListItemNormal"); } } this.util.addEvent(listItem,"click",this.__itemClickHandler.bind(this)); this.__setListItemProperties(listItem,item); if(isAdd) { this.__listContainer.appendChild(listItem); } return listItem; } return null; }; NSList.prototype.__setListItemProperties = function(listItem,item) { this.__objGrid.__setListItemProperties(listItem,item); }; NSList.prototype.__addCellText = function(listItem,item,div) { var toolTipText = null; if(listItem && item && div) { if(this.__itemRenderer) { var objRenderer = this.__itemRenderer(item,this.__labelField,item[this.__fieldIndex],item[this.__fieldDisableHover],listItem); if(objRenderer) { if(this.util.isString(objRenderer)) { var compBodySpan = document.createElement("span"); compBodySpan.innerHTML = objRenderer; div.appendChild(compBodySpan); } else { div.appendChild(objRenderer); } } } else if(this.__template) { div.appendChild(this.__template.cloneNode(true)); this.__setDataInTemplateRenderer(div,item,listItem); } else if(this.__labelFunction) { var text = this.__labelFunction(item,this.__labelField); div.appendChild(document.createTextNode(text)); } else if(item.hasOwnProperty(this.__labelField) && !this.util.isUndefined(item[this.__labelField]) && item[this.__labelField] != null) { var text = item[this.__labelField]; div.appendChild(document.createTextNode(text)); } this.__highlightDiv(div); if(this.__toolTipField) { toolTipText = item[this.__toolTipField]; } else if(this.__toolTipRenderer) { toolTipText = this.__toolTipRenderer(item,this.__labelField,item[this.__fieldIndex],item[this.__fieldDisableHover],listItem); } if(this.__enableTruncateToFit) { this.util.addStyleClass(div,"nsListTruncateToFit"); //This condition is above so that toolTip and title are not set togeather if(!toolTipText || toolTipText === "") { if(this.__enableToolTipForTruncateText) { toolTipText = div.textContent; } else { div.setAttribute("title",div.textContent); } } } if(toolTipText && toolTipText !== "") { this.__nsToolTipInElement.addToolTip(div,toolTipText); } } }; NSList.prototype.__setDataInTemplateRenderer = function(cellItem,data,listItem) { if(cellItem && this.__setData) { this.__setRendererProperties(cellItem); this.__setRendererInData(cellItem,data,listItem); //IE bug cellItem.data = data; if(this.util.isFunction(this.__setData)) { var strParam = "(cellItem,data,dataField,isDisabled,listItem)"; if(this.util.isString(this.__setData)) { var base = this; this.util.callFunctionFromString(this.__setData + strParam,function(paramValue){ if(paramValue === "cellItem") { return cellItem; } if(paramValue === "data") { return data; } if(paramValue === "dataField") { return base.__labelField; } if(paramValue === "isDisabled") { return data[base.__fieldDisableHover]; } if(paramValue === "listItem") { return listItem; } return paramValue; }); } else { this.__setData(cellItem,data,this.__labelField,data[this.__fieldDisableHover],listItem); } } } }; NSList.prototype.__setRendererInData = function(cellItem,data,listItem) { if(cellItem) { var compChild = null; for(var count = 0; count < cellItem.children.length; count++) { compChild = cellItem.children[count]; if(compChild) { compChild.data = data; compChild.listItem = listItem; } //IE 9 Bug,you got to assign it back //listItem.children[count] = compChild; this.__setRendererInData(compChild,data,listItem); } } }; NSList.prototype.__setRendererProperties = function(cellItem) { if(cellItem) { var compChild = null; for(var count = 0; count < cellItem.children.length; count++) { compChild = cellItem.children[count]; var grid = this; Array.prototype.slice.call(compChild.attributes).forEach(function(attribute) { if(grid.util.isFunction(attribute.value)) { var newValue = attribute.value + "(this)"; compChild.removeAttribute(attribute.name); compChild.setAttribute(attribute.name,newValue); } }); if(compChild) { if(compChild.hasAttribute("accessor-name")) { cellItem[compChild.getAttribute("accessor-name")] = compChild; } } this.__setRendererProperties(compChild); } } }; NSList.prototype.__setTemplate = function() { if(this.__templateID) { this.__template = this.util.getTemplate(this.__templateID); } }; NSList.prototype.__isHoverDisabled = function(item) { if(this.__disableHoverField) { return Boolean.parse(item[this.__disableHoverField]); } if(this.__disableHoverFunction) { return Boolean.parse(this.__disableHoverFunction(item,this.__fieldIndex)); } return false; }; NSList.prototype.__itemClickHandler = function(event) { event = this.util.getEvent(event); var target = this.util.getTarget(event); target = this.util.findParent(target,"li"); var index = this.__getIndexFromTarget(target); this.__setIndex(index,false); this.__lastNavigationDirection = null; }; NSList.prototype.__setIndex = function(index,isMultiSelect) { if(index > -1) { isMultiSelect = Boolean.parse(isMultiSelect); if (this.__isShiftPressed && this.__enableMultipleSelection) { this.__multiSectionHandler(index); } else if(isMultiSelect || (this.__isCtrlPressed && this.__enableMultipleSelection)) { if(this.__isRowSelected(index)) { this.__markRowUnselected(index); } else { this.__markRowSelected(index); } } else { this.__clearAllRowSelection(false); this.__markRowSelected(index); } } }; NSList.prototype.__itemMouseOverHandler = function(event) { var target = this.util.getTarget(event); target = this.util.findParent(target,"li"); var index = this.__getIndexFromTarget(target); var item = this.__getItemByIndex(index); if(target && index > -1 && this.__isMouseHoverAllowed(index)) { this.util.addStyleClass(target,"nsListItemHover"); this.__navigationIndex = index; this.util.dispatchEvent(this.__baseComponent,this.ITEM_NAVIGATED,item,{index:this.__navigationIndex}); } }; NSList.prototype.__itemMouseOutHandler = function(event) { var target = this.util.getTarget(event); target = this.util.findParent(target,"li"); if(target) { this.util.removeStyleClass(target,"nsListItemHover"); } }; NSList.prototype.__keyDownHandler = function(event) { event = this.util.getEvent(event); if(this.hasFocus()) { this.__isShiftPressed = event.shiftKey; this.__isCtrlPressed = event.ctrlKey; var isShiftCtrlPressed = this.__isShiftPressed || this.__isCtrlPressed; var keyCode = this.util.getKeyUnicode(event); if(this.__enableKeyboardNavigation) { var source = this.__objGrid.__getFlatSource(); //key Up if(keyCode === this.util.KEYCODE.UP && isShiftCtrlPressed && this.__enableMultipleSelection) { if(this.__lastNavigationDirection && this.__lastNavigationDirection === this.NAVIGATION_DOWN) { return this.__keyBoardSelectionHandler(event,this.NAVIGATION_UP); } if(this.__selectedIndex != 0) { this.__selectedIndex--; this.__navigationIndex--; while(!this.__isMouseHoverAllowed(this.__selectedIndex)) { this.__selectedIndex--; this.__navigationIndex--; } return this.__keyBoardSelectionHandler(event,this.NAVIGATION_UP); } } //key down else if(keyCode === this.util.KEYCODE.DOWN && isShiftCtrlPressed && this.__enableMultipleSelection) { if(this.__lastNavigationDirection && this.__lastNavigationDirection === this.NAVIGATION_UP) { return this.__keyBoardSelectionHandler(event,this.NAVIGATION_DOWN); } if(source && this.__selectedIndex != source.length - 1) { this.__selectedIndex++; this.__navigationIndex++; while(!this.__isMouseHoverAllowed(this.__selectedIndex)) { this.__selectedIndex++; this.__navigationIndex++; } return this.__keyBoardSelectionHandler(event,this.NAVIGATION_DOWN); } } else if(keyCode === this.util.KEYCODE.UP) { if(source && this.__navigationIndex === -1) { this.__navigationIndex = source.length - 1; } if(this.__navigationIndex > 0) { return this.__keyBoardNavigationHandler(event,this.NAVIGATION_UP); } } else if(keyCode === this.util.KEYCODE.DOWN) { /*if(this.__navigationIndex === -1) { this.__navigationIndex = 0; }*/ if(source)//&& this.__navigationIndex < source.length { return this.__keyBoardNavigationHandler(event,this.NAVIGATION_DOWN); } } else if(keyCode === this.util.KEYCODE.ENTER) { this.__clearAllRowSelection(false); var listItem = this.__getkeyboardNavigationListItem(); if(listItem) { this.__markRowSelected(this.__getIndexFromTarget(listItem)); } } } if(keyCode === this.util.KEYCODE.SHIFT) { this.util.makeBodyUnselectable(); } } }; NSList.prototype.__keyUpHandler = function(event) { if(this.util.getKeyUnicode(event) === this.util.KEYCODE.CTRL) { this.__isCtrlPressed = false; } if(this.util.getKeyUnicode(event) === this.util.KEYCODE.SHIFT) { this.__isShiftPressed = false; this.util.makeBodySelectable(); } }; NSList.prototype.__keyBoardNavigationHandler = function(event,direction) { var self = this; var lastIndex = this.__navigationIndex; var currentIndex = this.__navigationIndex; (direction === this.NAVIGATION_UP) ? currentIndex--:currentIndex++; while(!this.__isMouseHoverAllowed(currentIndex)) { (direction === this.NAVIGATION_UP) ? currentIndex--:currentIndex++; } var endHandler = function() { self.__navigationIndex = currentIndex; var listItem = self.__getkeyboardNavigationListItem(); var index = -1; var item = null; if(listItem) { var source = self.__objGrid.__getFlatSource(); index = self.__getIndexFromTarget(listItem); item = self.__getItemByIndex(index, source); } self.util.dispatchEvent(self.__baseComponent,self.ITEM_NAVIGATED,item,{index:index}); self.__lastNavigationDirection = null; }; if(this.__enableVirtualScroll) { var virtualHandler = function() { //self.__setVirtualRowHover.call(self,index); var item = self.__getVisibleItemByIndex.call(self,null,currentIndex); if(item) { var index = item[self.__fieldIndex]; self.__setVirtualRowHoverField.call(self,index); self.__virtualRowHover.call(self); endHandler(); } }; this.scrollToIndex(currentIndex,false); setTimeout(function() { virtualHandler(); },0); //this.__setVirtualRowHover(currentIndex); } else { var listItem = this.__getListItemFromContainer(lastIndex - this.__startArrayElement); var currentListItem = this.__getListItemFromContainer(currentIndex - this.__startArrayElement); //var listItem = this.__getListItemByIndex(lastIndex - this.__startArrayElement); //var currentListItem = this.__getListItemByIndex(currentIndex - this.__startArrayElement); if(currentListItem) { this.util.removeStyleClass(listItem,"nsListItemHover"); this.util.addStyleClass(currentListItem,"nsListItemHover"); this.__refreshScrollPosition(currentListItem,direction); endHandler(); } } event.preventDefault(); return false; }; NSList.prototype.__keyBoardSelectionHandler = function(event,direction) { if(this.__isRowSelected(this.__selectedIndex)) { this.__markRowUnselected(this.__selectedIndex); } else { this.__markRowSelected(this.__selectedIndex); } if(direction === this.NAVIGATION_DOWN) { if(this.__enableVirtualScroll) { this.scrollToIndex(this.__selectedIndex,false); } else if(Math.floor(this.__selectedIndex % this.__pageSize) === 0) { var listItem = this.__getListItemByIndex(this.__selectedIndex); this.__refreshScrollPosition(listItem,this.NAVIGATION_DOWN); } } else if(direction === this.NAVIGATION_UP) { if(this.__enableVirtualScroll) { this.scrollToIndex(this.__selectedIndex,false); } else { var listItem = this.__getListItemByIndex(this.__selectedIndex); this.__refreshScrollPosition(listItem,this.NAVIGATION_UP); } } this.__lastNavigationDirection = direction; event.preventDefault(); return false; }; NSList.prototype.__refreshScrollPosition = function(listItem,direction) { if(!this.__isElementInView(listItem)) { this.__scrollToListItem(listItem); } }; NSList.prototype.__isElementInView = function(listItem) { var cellBottom = 0; var parentBottom = 0; var cellTop = 0; var parentTop = 0; if(listItem) { var scrollParent = this.__divOuterContainer; var listChild = listItem.querySelector(".nsListChild"); if(scrollParent && listChild) { var cellRect = listChild.getBoundingClientRect(); parentTop = 0; var rectScrollParent = scrollParent.getBoundingClientRect(); parentBottom = rectScrollParent.height; cellTop = cellRect.top - rectScrollParent.top; cellBottom = cellTop + cellRect.height; } } return cellBottom <= parentBottom && cellTop >= parentTop; }; NSList.prototype.__scrollToListItem = function(listItem) { if(listItem) { var rectCell = listItem.getBoundingClientRect(); var rectParentContainer = this.__divParentContainer.getBoundingClientRect(); var scrollTop = rectCell.top - rectParentContainer.top; this.__divOuterContainer.scrollTop = scrollTop; } }; NSList.prototype.__getkeyboardNavigationListItem = function() { var listItem = null; if(this.__enableVirtualScroll) { listItem = this.__listContainer.querySelector(".nsListItemHover"); } else { listItem = this.__getListItemFromContainer(this.__navigationIndex); } return listItem; }; NSList.prototype.__isMouseHoverAllowed = function(index) { var item = this.__getItemByIndex(index); if(item) { return !item[this.__fieldDisableHover]; } return true; }; NSList.prototype.__markRowSelected= function(index) { if(index > -1) { if(!this._