nscomponentsreact
Version:
React Wrapper Components for NSComponents
1,520 lines (1,431 loc) • 698 kB
JavaScript
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;
}
"use strict";
var NSMenu = (function()
{
function NSMenu(setting)
{
this.util = new NSUtil();
this.DEFAULT_POSITION = this.util.POS_BOTTOMRIGHT;
this.__setting = setting;
this.__config = null;
this.__id = null;
this.__popUp = null;
this.__nsPopUp = null;
this.__fieldItem = null;
this.__fieldItemChild = null;
this.__fieldChild = "children";
this.__isInternalCall = false;
this.__suppressDocumentHandler = false;
this.__documentClickRef = null;
this.__documentKeyUpRef = null;
this.__lastSelectedTarget = null;
this.__initialize();
}
NSMenu.prototype.create = function (dataSource)
{
if(dataSource && (this.__config.createRunTime || this.__isInternalCall))
{
if(this.__popUp)
{
this.remove();
}
this.__isInternalCall = false;
this.__config.dataSource = dataSource;
this.__popUp = this.__createElement(true,this.__config.dataSource);
this.util.addStyleClass(this.__nsPopUp,"nsMainMenu");
}
};
NSMenu.prototype.remove = function ()
{
if(this.__config.createRunTime || this.__isInternalCall)
{
this.__isInternalCall = false;
this.__nsPopUp.remove();
this.__popUp = null;
}
};
NSMenu.prototype.show = function (event)
{
event = this.util.getEvent(event);
this.__nsPopUp.hideOtherNSPopUp();
if(this.__config.createRunTime)
{
this.__isInternalCall = true;
var dataSource = null;
if(this.__config.sourceProvider)
{
dataSource = this.__config.sourceProvider(this.__lastSelectedTarget);
}
if(dataSource && dataSource.length > 0)
{
this.create(dataSource);
}
else
{
this.util.preventDefault(event);
return;
}
}
this.__nsPopUp.show();
this.__nsPopUp.placePopUp(event);
if(!this.__documentClickRef)
{
this.__documentClickRef = this.__documentClickHandler.bind(this);
this.util.addEvent(document.documentElement,"click", this.__documentClickRef);
}
if(!this.__documentKeyUpRef)
{
this.__documentKeyUpRef = this.__documentKeyUpHandler.bind(this);
this.util.addEvent(document.documentElement,"keyup", this.__documentKeyUpRef);
}
this.util.preventDefault(event);
};
NSMenu.prototype.hide = function()
{
this.__lastSelectedTarget = null;
this.__hideAllSubMenus();
if(this.__config.createRunTime)
{
this.__isInternalCall = true;
this.remove();
}
else
{
this.__nsPopUp.hide();
}
if(this.__documentClickRef)
{
this.util.removeEvent(document.documentElement,"click", this.__documentClickRef, false);
this.__documentClickRef = null;
}
if(this.__documentKeyUpRef)
{
this.util.removeEvent(document.documentElement,"keyup", this.__documentKeyUpRef, false);
this.__documentKeyUpRef = null;
}
};
NSMenu.prototype.__initialize = function ()
{
if(this.__setting)
{
//eventHandler:extra eventHandler which developer wants to execute on the event i.e. click,customEvent etc
this.__config = {
parent: this.__setting["parent"] || null,
dataSource: this.__setting["dataSource"] || null,
isContextMenu: (this.util.isUndefined(this.__setting["isContextMenu"]) || this.__setting["isContextMenu"] === null) ? true : Boolean.parse(this.__setting["isContextMenu"]),
eventType: this.__setting["eventType"] || "click",
createRunTime: (this.util.isUndefined(this.__setting["createRunTime"]) || this.__setting["createRunTime"] === null) ? false : Boolean.parse(this.__setting["createRunTime"]),
sourceProvider: this.__setting["sourceProvider"] || null,
targetType: this.__setting["targetType"] || null,
defaultHandler: (this.__setting["defaultHandler"] ? this.util.getFunction(this.__setting["defaultHandler"]) : null),
eventHandler: (this.__setting["eventHandler"] ? this.util.getFunction(this.__setting["eventHandler"]) : null),
position: this.__setting["position"] || this.DEFAULT_POSITION,
width: parseInt(this.__setting["width"]) || -1
};
if(this.__config.parent)
{
var popUpSetting = {id:this.__getID() + "menu",type:"ul",width:this.__config.width,position:this.__config.position};
this.__nsPopUp = new this.util.nsPopUp(popUpSetting);
this.__fieldItem = this.__getID() + "_item";
this.__fieldItemChild = this.__getID() + "_child";
if(!this.__config.createRunTime)
{
this.__isInternalCall = true;
this.create(this.__config.dataSource);
}
if(this.__config.isContextMenu)
{
this.util.addEvent(this.__config.parent,"contextmenu", this.__parentContextMenuHandler.bind(this));
}
else
{
this.util.addEvent(this.__config.parent,this.__config.eventType, this.__parentClickHandler.bind(this),false);
}
}
}
};
NSMenu.prototype.__createElement = function(isRoot,dataSource)
{
var parentNode = null;
if(dataSource && dataSource.length > 0)
{
if(isRoot)
{
parentNode = this.__nsPopUp.create();
}
else
{
parentNode = document.createElement("ul");
this.util.addStyleClass(parentNode,"nsMenu");
if(this.__config.width > -1)
{
parentNode.style.width = this.__config.width + "px";
}
}
for (var count = 0; count < dataSource.length; count++)
{
var item = dataSource[count];
this.__createItem(item,parentNode);
}
}
return parentNode;
};
NSMenu.prototype.__createItem = function(item,parent)
{
var menuItem = null;
if(item)
{
menuItem = document.createElement("li");
this.util.addStyleClass(menuItem,"nsMenuItem");
if(item["header"])
{
this.util.addStyleClass(menuItem,"nsHeader");
}
if(item["disabled"])
{
this.util.addStyleClass(menuItem,"nsDisabled");
}
var button = document.createElement("BUTTON");
this.util.addStyleClass(button,"nsMenuButton");
if(item["iconHTML"])
{
var spanIcon = document.createElement("span");
this.util.addStyleClass(spanIcon,"nsMenuAlign");
spanIcon.innerHTML = item["iconHTML"];
button.appendChild(spanIcon);
}
var spanText = document.createElement("span");
this.util.addStyleClass(spanText,"nsMenuText");
spanText.appendChild(document.createTextNode(item["title"]));
button.appendChild(spanText);
menuItem.appendChild(button);
this.util.addEvent(menuItem,"click",this.__itemClickHandler.bind(this));
this.util.addEvent(menuItem,"mouseenter",this.__itemMouseOverHandler.bind(this));
this.util.addEvent(menuItem,"mouseleave",this.__itemMouseOutHandler.bind(this));
if(item[this.__fieldChild])
{
this.util.addStyleClass(menuItem,"nsSubMenu");
var subMenu = this.__createElement(false,item[this.__fieldChild]);
if(subMenu)
{
this.util.addStyleClass(subMenu,"nsSubMenuContainer");
menuItem.appendChild(subMenu);
item[this.__fieldItemChild] = subMenu;
menuItem.setAttribute("hasChild",true);
}
}
else
{
menuItem.setAttribute("hasChild",false);
}
if(parent)
{
parent.appendChild(menuItem);
if(item["separatorBelow"])
{
var lineMenuItem = document.createElement("li");
this.util.addStyleClass(lineMenuItem,"nsMenuSeparator");
parent.appendChild(lineMenuItem);
}
}
item[this.__fieldItem] = menuItem;
}
return menuItem;
};
NSMenu.prototype.__itemClickHandler = function(event)
{
event = this.util.getEvent(event);
var target = this.util.getTarget(event);
target = this.util.findParent(target,"LI");
var item = this.__getItem(target,this.__config.dataSource);
if(item)
{
var handler = null;
if(item["handler"])
{
handler = this.util.getFunction(item["handler"]);
}
if(!handler)
{
handler = this.__config.defaultHandler;
}
if(handler)
{
handler(this.__lastSelectedTarget,item);
}
}
this.hide();
event.stopImmediatePropagation();
};
NSMenu.prototype.__itemMouseOverHandler = function(event)
{
var target = this.util.getTarget(event);
target = this.util.findParent(target,"LI");
if(target.getAttribute("hasChild") === "true")
{
var item = this.__getItem(target,this.__config.dataSource);
if(item && item[this.__fieldItemChild])
{
var childMenu = item[this.__fieldItemChild];
this.util.addStyleClass(childMenu,"nsShowMenu");
}
}
};
NSMenu.prototype.__itemMouseOutHandler = function(event)
{
var target = this.util.getTarget(event);
target = this.util.findParent(target,"LI");
if(target.getAttribute("hasChild") === "true")
{
var item = this.__getItem(target,this.__config.dataSource);
if(item && item[this.__fieldItemChild])
{
var childMenu = item[this.__fieldItemChild];
this.util.removeStyleClass(childMenu,"nsShowMenu");
}
}
};
NSMenu.prototype.__documentClickHandler = function(event)
{
event = this.util.getEvent(event);
/*if(!this.__config.isContextMenu && this.__isParentPresent(event.target,this.__config.parent))
{
return;
}*/
//commenting this so that menu closes on click in Grid
/*if(this.__suppressDocumentHandler)
{
this.__suppressDocumentHandler = false;
return;
}*/
this.hide();
};
NSMenu.prototype.__documentKeyUpHandler = function(event)
{
event = this.util.getEvent(event);
if(event.keyCode === this.util.KEYCODE.ESC)
{
this.hide();
}
};
NSMenu.prototype.__parentContextMenuHandler = function(event)
{
if(this.__config.eventHandler)
{
this.__config.eventHandler(event);
}
this.__setLastSelectedTarget(this.util.getTarget(event));
this.show(event);
};
NSMenu.prototype.__parentClickHandler = function(event)
{
if(this.__config.eventHandler)
{
this.__config.eventHandler(event);
}
this.__setLastSelectedTarget(this.util.getTarget(event));
//below condition to make documentClickhandler aware that do not hide the menu,hence put only for click handler
if(this.__config.eventType === "click")
{
this.__suppressDocumentHandler = true;
event.stopPropagation();
}
this.show(event);
};
NSMenu.prototype.__getItem = function(objItem,dataSource)
{
if(objItem)
{
for (var count = 0; count < dataSource.length; count++)
{
var item = dataSource[count];
if(item[this.__fieldItem] == objItem)
{
return item;
}
if(item.hasOwnProperty(this.__fieldChild))
{
var childItem = this.__getItem(objItem,item[this.__fieldChild]);
if(childItem)
{
return childItem;
}
}
}
}
return null;
};
NSMenu.prototype.__hideAllSubMenus = function()
{
var arrSubMenus = this.__popUp.querySelectorAll("ul");
if(arrSubMenus && arrSubMenus.length > 0)
{
var subMenu = null;
for(var count = 0;count < arrSubMenus.length;count++)
{
subMenu = arrSubMenus[count];
this.util.removeStyleClass(subMenu,"nsShowMenu");
}
}
};
NSMenu.prototype.__setLastSelectedTarget = function(target)
{
if(target && this.__config.targetType)
{
target = this.util.findParent(target,this.__config.targetType);
}
this.__lastSelectedTarget = target;
};
NSMenu.prototype.__getID = function()
{
if(!this.__id)
{
if(this.__config.parent.hasAttribute("id"))
{
this.__id = this.__config.parent.getAttribute("id");
}
else if(this.__config.parent.hasAttribute("name"))
{
this.__id = this.__config.parent.getAttribute("name");
}
else
{
this.__id = "comp" + this.util.getUniqueId();
}
}
return this.__id;
};
NSMenu.prototype.__isParentPresent = function(node,parentNode)
{
while (node && node!== document.body)
{
if(node.id === parentNode.id)
{
return true;
}
node = node.parentNode;
}
return false;
};
return NSMenu;
})();
nsModuleExport(this,"NSMenu",NSMenu); "use strict";
var NSPagination = (function()
{
function NSPagination(setting)
{
this.PAGE_CLICK = "pageClick";
this.PAGE_CHANGE = "pageChange";
this.util = new NSUtil();
this.__setting = setting;
this.__config = null;
this.__id = null;
this.__container = null;
this.__itemFirst = null;
this.__itemLast = null;
this.__itemPrev = null;
this.__itemNext = null;
this.__arrItemPage = [];
this.__pageCount = 0;
this.__selectedPage = -1;
this.__initialize();
}
NSPagination.prototype.__initialize = function ()
{
if(this.__setting)
{
this.__config = {
parent: this.__setting["parent"] || null,
totalRecords: parseInt(this.__setting["totalRecords"]) || 0,
pageSize: parseInt(this.__setting["pageSize"]) || 0,
totalPageCount: parseInt(this.__setting["totalPageCount"]) || 0,
visiblePages: parseInt(this.__setting["visiblePages"]) || 5,
containerStyle: this.__setting["containerStyle"] || "nsPaginationContainer",
activeStyle: this.__setting["activeStyle"] || "nsPageActive",
disabledStyle: this.__setting["disabledStyle"] || "nsPageDisabled",
textFirst : this.__setting["textFirst"] || "«",
textLast : this.__setting["textLast"] || "»",
textNext : this.__setting["textNext"] || "›",
textPrev : this.__setting["textPrev"] || "‹",
textTitlePagePrefix: this.__setting["textTitlePagePrefix"] || "Page",
textTitleFirst : this.__setting["textTitleFirst"] || 'First Page',
textTitleLast : this.__setting["textTitleLast"] || 'Last Page',
textTitleNext : this.__setting["textTitleNext"] || 'Next Page',
textTitlePrev : this.__setting["textTitlePrev"] || 'Previous Page',
showPrevNext : (!this.util.isUndefined(this.__setting["showPrevNext"]) && this.__setting["showPrevNext"] != null) ? Boolean.parse(this.__setting["showPrevNext"]) : true,
showFirstLast : (!this.util.isUndefined(this.__setting["showFirstLast"]) && this.__setting["showFirstLast"] != null) ? Boolean.parse(this.__setting["showFirstLast"]) : false
};
this.__create();
}
};
NSPagination.prototype.changePageSize = function(pageSize)
{
if(pageSize > 0 && this.__config)
{
this.__config.pageSize = pageSize;
this.__create();
}
};
NSPagination.prototype.setSelectedPage = function(pageNumber)
{
this.__update(pageNumber);
};
NSPagination.prototype.getSelectedPage = function(pageNumber)
{
return this.__selectedPage;
};
NSPagination.prototype.__create = function()
{
if(this.__config.parent)
{
if(this.__container)
{
this.__container.parentNode.removeChild(this.__container);
this.__arrItemPage = [];
this.__selectedPage = -1;
}
if(this.__config.totalPageCount > 0)
{
this.__pageCount = this.__config.totalPageCount;
}
else if(this.__config.pageSize > 0)
{
this.__pageCount = Math.ceil(this.__config.totalRecords / this.__config.pageSize);
}
this.__container = this.util.createElement("ul",this.__getID() + "container",this.__config.containerStyle);
this.__config.parent.appendChild(this.__container);
if(this.__config.showFirstLast)
{
this.__itemFirst = this.__createItem("-4",this.__config["textFirst"],this.__config.textTitleFirst,this.__controlItemClickHandler);
}
if(this.__config.showPrevNext)
{
this.__itemPrev = this.__createItem("-3",this.__config["textPrev"],this.__config.textTitlePrev,this.__controlItemClickHandler);
}
var createdNumber = Math.min(this.__pageCount,this.__config.visiblePages);
for(var count = 1;count <= createdNumber;count++)
{
var pageItem = this.__createItem(count,count,this.__config.textTitlePagePrefix + " " + count,this.__pageItemClickHandler);
this.__arrItemPage.push(pageItem);
}
if(this.__config.showPrevNext)
{
this.__itemNext = this.__createItem("-2",this.__config["textNext"],this.__config.textTitleNext,this.__controlItemClickHandler);
}
if(this.__config.showFirstLast)
{
this.__itemLast = this.__createItem("-1",this.__config["textLast"],this.__config.textTitleLast,this.__controlItemClickHandler);
}
//this.__selectPage(1);
this.__updateControlState(1);
}
};
NSPagination.prototype.__controlItemClickHandler = function(event)
{
var target = this.util.getTarget(event);
target = this.util.findParent(target,"li");
var index = parseInt(target.getAttribute("pageNum"));
var pageSelected = -1;
switch(index)
{
case -4:
pageSelected = 1;
break;
case -3:
pageSelected = this.__selectedPage - 1;
break;
case -2:
pageSelected = this.__selectedPage + 1;
break;
case -1:
pageSelected = this.__pageCount;
break;
}
this.__update(pageSelected);
};
NSPagination.prototype.__pageItemClickHandler = function(event)
{
var target = this.util.getTarget(event);
target = this.util.findParent(target,"li");
var index = parseInt(target.getAttribute("pageNum"));
this.__update(index);
};
NSPagination.prototype.__createItem = function(pageNumber,htmlText,titleText,clickHandler)
{
var pageItem = this.util.createElement("li",this.__getID() + "Page" + pageNumber,null);
pageItem.setAttribute("pageNum",pageNumber);
pageItem.setAttribute("title",titleText);
this.util.addEvent(pageItem,"click",clickHandler.bind(this));
var pageText = this.util.createElement("a",null,null);
pageText.setAttribute("href","javascript:void(0);");
pageText.innerHTML = htmlText;
pageItem.appendChild(pageText);
this.__container.appendChild(pageItem);
return pageItem;
};
NSPagination.prototype.__update = function(pageNumber)
{
if(pageNumber <= 0)
{
pageNumber = 1;
}
else if(pageNumber > this.__pageCount)
{
pageNumber = this.__pageCount;
}
var range = this.__calculateRange(this.__pageCount,Math.min(this.__pageCount,this.__config.visiblePages),pageNumber);
this.__updateItem(range[0],range[1]);
this.__selectPage(pageNumber);
this.__updateControlState(pageNumber);
};
NSPagination.prototype.__updateItem = function(fromPage,toPage)
{
var firstNumber = parseInt(this.__arrItemPage[0].getAttribute("pageNum"));
var lastNumber = parseInt(this.__arrItemPage[this.__arrItemPage.length - 1].getAttribute("pageNum"));
if(!(firstNumber === fromPage && lastNumber === toPage))
{
for(var count = 0;count < this.__arrItemPage.length;count++)
{
var pageItem = this.__arrItemPage[count];
var index = count + fromPage;
pageItem.setAttribute("pageNum",index);
pageItem.setAttribute("title",this.__config.textTitlePagePrefix + " " + index);
var pageText = pageItem.firstChild;
pageText.innerHTML = index;
}
}
};
NSPagination.prototype.__updateControlState = function(pageNumber)
{
if(pageNumber === 1)
{
this.__itemFirst ? this.util.addStyleClass(this.__itemFirst,this.__config.disabledStyle) : "";
this.__itemPrev ? this.util.addStyleClass(this.__itemPrev,this.__config.disabledStyle) : "";
}
else
{
this.__itemFirst ? this.util.removeStyleClass(this.__itemFirst,this.__config.disabledStyle) : "";
this.__itemPrev ? this.util.removeStyleClass(this.__itemPrev,this.__config.disabledStyle) : "";
}
if(pageNumber === this.__pageCount)
{
this.__itemNext ? this.util.addStyleClass(this.__itemNext,this.__config.disabledStyle) : "";
this.__itemLast ? this.util.addStyleClass(this.__itemLast,this.__config.disabledStyle) : "";
}
else
{
this.__itemNext ? this.util.removeStyleClass(this.__itemNext,this.__config.disabledStyle) : "";
this.__itemLast ? this.util.removeStyleClass(this.__itemLast,this.__config.disabledStyle) : "";
};
};
NSPagination.prototype.__calculateRange = function(totalPages,visiblePages,pageToBeSelected)
{
var renderPage = [1,totalPages];
var limit = Math.floor(visiblePages/2);
if(visiblePages > 0)
{
renderPage[0] = Math.max(pageToBeSelected - limit, 1);
renderPage[1] = Math.min(pageToBeSelected + limit, totalPages);
var difference = renderPage[1] - renderPage[0];
if(renderPage[0] === 1 && difference < visiblePages)
{
renderPage[1] = visiblePages;
}
else if(renderPage[1] === totalPages && difference < visiblePages)
{
renderPage[0] = renderPage[1] - visiblePages + 1;
}
}
return renderPage;
};
NSPagination.prototype.__selectPage = function(pageIndex)
{
var selectedIndex = -1;
for(var count = 0;count < this.__arrItemPage.length;count++)
{
var pageItem = this.__arrItemPage[count];
this.util.removeStyleClass(pageItem,this.__config.activeStyle);
var index = parseInt(pageItem.getAttribute("pageNum"));
if(index === pageIndex)
{
selectedIndex = count;
}
}
if(selectedIndex > -1)
{
var oldPage = this.__selectedPage;
this.util.addStyleClass(this.__arrItemPage[selectedIndex],this.__config.activeStyle);
this.__selectedPage = pageIndex;
var fromRecord = (pageIndex - 1) * this.__config.pageSize;
var toRecord = fromRecord + this.__config.pageSize - 1;
toRecord = (toRecord < this.__config.totalRecords) ? toRecord : ((toRecord === this.__config.totalRecords) ? this.__config.totalRecords - 1 : this.__config.totalRecords);
var item = {oldIndex:oldPage,newIndex:this.__selectedPage,fromRecord:fromRecord,toRecord:toRecord};
this.util.dispatchEvent(this.__config.parent,this.PAGE_CLICK,item,item);
if(oldPage !== this.__selectedPage)
{
this.util.dispatchEvent(this.__config.parent,this.PAGE_CHANGE,item,item);
}
}
};
NSPagination.prototype.__getID = function()
{
if(!this.__id)
{
if(this.__config.parent.hasAttribute("id"))
{
this.__id = this.__config.parent.getAttribute("id");
}
else if(this.__config.parent.hasAttribute("name"))
{
this.__id = this.__config.parent.getAttribute("name");
}
else
{
this.__id = "comp" + this.util.getUniqueId();
}
}
return this.__id;
};
return NSPagination;
})();
nsModuleExport(this,"NSPagination",NSPagination);
var NSExport = (function()
{
//DONOT REMOVE: taken from https://gist.github.com/sevir/3946819
if (window && !window.atob && !window.btoa)
{
( function( window ) {
var _PADCHAR = "=",
_ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
function _getbyte64( s, i ) {
var idx = _ALPHA.indexOf( s.charAt( i ) );
if ( idx === -1 ) {
throw "Cannot decode base64";
}
return idx;
}
function _decode( s ) {
var pads = 0,
i,
b10,
imax = s.length,
x = [];
s = String( s );
if ( imax === 0 ) {
return s;
}
if ( imax % 4 !== 0 ) {
throw "Cannot decode base64";
}
if ( s.charAt( imax - 1 ) === _PADCHAR ) {
pads = 1;
if ( s.charAt( imax - 2 ) === _PADCHAR ) {
pads = 2;
}
// either way, we want to ignore this last block
imax -= 4;
}
for ( i = 0; i < imax; i += 4 ) {
b10 = ( _getbyte64( s, i ) << 18 ) | ( _getbyte64( s, i + 1 ) << 12 ) | ( _getbyte64( s, i + 2 ) << 6 ) | _getbyte64( s, i + 3 );
x.push( String.fromCharCode( b10 >> 16, ( b10 >> 8 ) & 0xff, b10 & 0xff ) );
}
switch ( pads ) {
case 1:
b10 = ( _getbyte64( s, i ) << 18 ) | ( _getbyte64( s, i + 1 ) << 12 ) | ( _getbyte64( s, i + 2 ) << 6 );
x.push( String.fromCharCode( b10 >> 16, ( b10 >> 8 ) & 0xff ) );
break;
case 2:
b10 = ( _getbyte64( s, i ) << 18) | ( _getbyte64( s, i + 1 ) << 12 );
x.push( String.fromCharCode( b10 >> 16 ) );
break;
}
return x.join( "" );
}
function _getbyte( s, i ) {
var x = s.charCodeAt( i );
if ( x > 255 ) {
throw "INVALID_CHARACTER_ERR: DOM Exception 5";
}
return x;
}
function _encode( s ) {
if ( arguments.length !== 1 ) {
throw "SyntaxError: exactly one argument required";
}
s = String( s );
var i,
b10,
x = [],
imax = s.length - s.length % 3;
if ( s.length === 0 ) {
return s;
}
for ( i = 0; i < imax; i += 3 ) {
b10 = ( _getbyte( s, i ) << 16 ) | ( _getbyte( s, i + 1 ) << 8 ) | _getbyte( s, i + 2 );
x.push( _ALPHA.charAt( b10 >> 18 ) );
x.push( _ALPHA.charAt( ( b10 >> 12 ) & 0x3F ) );
x.push( _ALPHA.charAt( ( b10 >> 6 ) & 0x3f ) );
x.push( _ALPHA.charAt( b10 & 0x3f ) );
}
switch ( s.length - imax ) {
case 1:
b10 = _getbyte( s, i ) << 16;
x.push( _ALPHA.charAt( b10 >> 18 ) + _ALPHA.charAt( ( b10 >> 12 ) & 0x3F ) + _PADCHAR + _PADCHAR );
break;
case 2:
b10 = ( _getbyte( s, i ) << 16 ) | ( _getbyte( s, i + 1 ) << 8 );
x.push( _ALPHA.charAt( b10 >> 18 ) + _ALPHA.charAt( ( b10 >> 12 ) & 0x3F ) + _ALPHA.charAt( ( b10 >> 6 ) & 0x3f ) + _PADCHAR );
break;
}
return x.join("");
}
window.btoa = _encode;
window.atoa = _decode;
})( window );
}
"use strict";
function NSExport(grid,fileName,extPath,ignoreColumn)
{
this.__grid = grid;
this.__fileName = fileName;
this.__ignoreColumn = ignoreColumn;
this.__extFilePath = extPath ? extPath : "../lib/com/ext";
this.util = new NSUtil();
this.__defaultDelimiter = ",";
this.__defaultNewLine = "\r\n";
this.__externalScriptLoad = {jspdf:false,html2canvas:false};
}
//Orientation: portrait or landscape
NSExport.prototype.word = function(setting)
{
if(setting)
{
if(setting.type === "doc")
{
var docSetting = {appType:"doc",extension:"doc",event:setting.event,orientation:setting.orientation,element:setting.element,pageBreakTag:setting.pageBreakTag,headerFooterCss:"",startHtml:"",endHtml:""};
if(setting.hasHeaderOrFooter)
{
docSetting.headerFooterCss = setting.headerFooterCss || "";
docSetting.startHtml = setting.startHtml || "";
docSetting.endHtml = setting.endHtml || "";
}
if(setting.enablePageNumber)
{
docSetting.headerFooterCss += "p.MsoHeader, li.MsoHeader, div.MsoHeader{ margin:0in; margin-top:.0001pt; mso-pagination:widow-orphan; tab-stops:center 3.0in right 6.0in; } p.MsoFooter, li.MsoFooter, div.MsoFooter{ margin:0in 0in 1in 0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; tab-stops:center 3.0in right 6.0in; } .footer { font-size: 9pt; } @page Section1{ size:8.5in 11.0in; margin:0.5in 0.5in 0.5in 0.5in; mso-header-margin:0.5in; mso-header:h1; mso-footer:f1; mso-footer-margin:0.5in; mso-paper-source:0; } div.Section1{ page:Section1; } table#hrdftrtbl{ margin:0in 0in 0in 9in; }";
docSetting.startHtml = "<div class=\"Section1\">" + docSetting.startHtml;
docSetting.endHtml += "<table id=\"hrdftrtbl\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td> <div style=\"mso-element:footer\" id=\"f1\"> <p class=\"MsoFooter\"> <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td align=\"center\" class=\"footer\"> <g:message code=\"offer.letter.page.label\"/> <span style=\"mso-field-code: PAGE \"></span> of <span style=\"mso-field-code: NUMPAGES \"></span> </td> </tr> </table> </p> </div> </td> </tr> </table> </div>";;
}
this.__exportOfficeTypes(docSetting);
}
else
{
if(!setting.orientation || (setting.orientation !== "portrait" && setting.orientation !== "landscape"))
{
this.util.warning("NSExport","Docx type value was either not valid or not in the correct format.Hence defaulting to portrait");
setting.orientation = "portrait";
}
var docSetting = {appType:"doc",element:setting.element,pageBreakTag:setting.pageBreakTag,headerFooterCss:"",startHtml:"",endHtml:""};
if(setting.hasHeaderOrFooter)
{
docSetting.headerFooterCss = setting.headerFooterCss;
docSetting.startHtml = setting.startHtml;
docSetting.endHtml = setting.endHtml;
}
var htmlText = this.__getHTMLTextForOffice(docSetting);
if(htmlText && htmlText.length > 0)
{
var fileName = this.__getFileName("docx");
var exportSetting = {fileName:fileName,htmlSetting:{html:htmlText,htmlStyle: setting.extraStyle,loopNodesCallback: setting.loopNodesCallback},printSetting:{orientation: setting.orientation}};
var docxExport = new NSDocxExport(exportSetting);
docxExport.process();
}
}
}
};
NSExport.prototype.powerpoint = function(setting)
{
if(setting)
{
var docSetting = {appType:"powerpoint",extension:"ppt",event:setting.event,element:setting.element};
this.__exportOfficeTypes(docSetting);
}
};
NSExport.prototype.excel = function(setting)
{
if(setting)
{
if(setting.type === "xls")
{
var docSetting = {appType:"excel",extension:"xls",sheetName:setting.sheetName,event:setting.event,element:setting.element,properties:setting.properties};
this.__exportOfficeTypes(docSetting);
}
else
{
var objXslxExport = new this.xslxExport(this,setting.sheetName,setting.event,setting.properties);
objXslxExport.exportToxlsx();
}
}
};
NSExport.prototype.csv = function(event)
{
var csvText = this.__getTableAsString(this.__defaultDelimiter,this.__defaultNewLine);
if(csvText)
{
var uri = "application/csv";
this.__downloadFile(csvText,uri,"csv",event);
}
};
NSExport.prototype.xml = function(event)
{
var xmlText = this.__getTableAsXML();
if(xmlText)
{
var uri = "application/xml";
this.__downloadFile(xmlText,uri,"xml",event);
}
};
NSExport.prototype.text = function(event)
{
var csvText = this.__getTableAsString(this.__defaultDelimiter,this.__defaultNewLine,"-");
if(csvText)
{
var uri = "application/txt";
this.__downloadFile(csvText,uri,"txt",event);
}
};
NSExport.prototype.json = function(event)
{
var jsonText = this.__getTableAsJson();
if(jsonText)
{
var uri = "application/json";
this.__downloadFile(jsonText,uri,"json",event);
}
};
NSExport.prototype.pdf = function(event,setting)
{
this.__processPDF = function()
{
this.__externalScriptLoad.jspdf = true;
if(!setting)
{
setting = {};
}
var config = {
fontSize: setting["fontSize"] || 14,
width: setting["width"] || 1200,
topMargin: setting["topMargin"] || 30,
bottomMargin: setting["bottomMargin"] || 60,
leftMargin: setting["leftMargin"] || 60,
maxWidth: setting["maxWidth"] || 550
};
var divSource = this.__getStructureForPDF(config.width,config.fontSize);
document.body.appendChild(divSource);
var pdf = new jsPDF("p", "pt", "ledger");
// we support special element handlers. Register them with jQuery-style
// ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
// There is no support for any other type of selectors
// (class, of compound) at this time.
specialElementHandlers =
{
// element with id of "bypass" - jQuery style selector
'#bypassme' : function(element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true;
}
};
margins = {
top : config.topMargin,
bottom : config.bottomMargin,
left : config.leftMargin,
width : config.maxWidth
};
var self = this;
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
pdf.fromHTML(divSource, // HTML string or DOM elem ref.
margins.left, // x coord
margins.top, { // y coord
'width' : margins.width, // max width of content on PDF
'elementHandlers' : specialElementHandlers
},
function(dispose) {
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
pdf.save(self.__getFileName("pdf"));
document.body.removeChild(divSource);
}, margins);
};
if(!this.__externalScriptLoad.jspdf)
{
this.__includeJavaScriptFile(this.__extFilePath + "/jspdf/jspdf.min.js",this.__processPDF.bind(this));
}
else
{
this.__processPDF.bind(this)();
}
};
NSExport.prototype.image = function(setting)
{
if(!setting)
{
setting = {};
}
this.__processImage = function()
{
this.__externalScriptLoad.html2canvas = true;
if(!setting.type || (setting.type !== "png" && setting.type !== "jpeg"))
{
this.util.warning("NSExport","Image type value was either not valid or not in the correct format.Hence defaulting to png");
setting.type = "png";
}
var imageType = "image/" + setting.type;
var divParent = this.__getStructureForImage();
if(divParent)
{
var nsExport = this;
html2canvas(divParent,{
onrendered: function(canvas) {
//document.body.appendChild(canvas);
var data = canvas.toDataURL(imageType);
if(!data || data === "data:,")
{
nsExport.util.throwNSError("NSExport","Please give table some width and height");
}
else
{
nsExport.__downloadFile(data,imageType,setting.type);
}
}
});
}
else
{
this.util.throwNSError("NSExport","Please add the table inside a parent Element");
}
};
if(!this.__externalScriptLoad.html2canvas)
{
this.__includeJavaScriptFile(this.__extFilePath + "/html2canvas/html2canvas.min.js",this.__processImage.bind(this));
}
else
{
this.__processImage.bind(this)();
}
};
NSExport.prototype.__exportOfficeTypes = function(setting)
{
var htmlText = this.__getHTMLTextForOffice(setting);
if(htmlText && htmlText.length > 0)
{
var uri = "application/vnd.ms-" + setting.appType;
if(setting.extension === "doc")
{
uri = "application/msword";
}
this.__downloadFile(htmlText,uri,setting.extension,setting.event);
}
};
NSExport.prototype.__getHTMLTextForOffice = function(setting)
{
var appType = setting.appType;
var element = setting.element;
var headerFooterCss = setting.headerFooterCss ? setting.headerFooterCss : "";
var startHtml = setting.startHtml ? setting.startHtml : "";
var endHtml = setting.endHtml ? setting.endHtml : "";
var htmlText = "";
var outerHTML = null;
var isTable = false;
if(element)
{
outerHTML = element.outerHTML;
}
else
{
var table = this.__getTable();
if(table)
{
outerHTML = table.outerHTML;
}
isTable = true;
}
var objValue = {};
switch(appType)
{
case "doc":
objValue = this.__getHTMLTextForWord(setting,outerHTML,isTable);
break;
case "excel":
objValue = this.__getHTMLTextForExcel(setting,outerHTML,isTable);
break;
case "powerpoint":
objValue = this.__getHTMLTextForPpt(setting,outerHTML,isTable);
break;
}
if(outerHTML)
{
objValue.style = (objValue.style) ? objValue.style : "";
htmlText = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:' + appType +'" xmlns="http://www.w3.org/TR/REC-html40">';
htmlText += '<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
htmlText +='<!--[if gte mso 9]><xml>';
htmlText += objValue.header;
htmlText += '</xml><![endif]-->';
//htmlText +="<o:shapedefaults v:ext=\"edit\" spidmax=\"1026\"/>";
htmlText += '<style>' + objValue.style + headerFooterCss + '.header{mso-style-parent:style0;color:white;font-size:10.0pt;font-weight:700;font-family:Tahoma, sans-serif;mso-font-charset:0;text-align:center;background:gray;mso-pattern:black none;}</style>';
htmlText += '</head>';
htmlText += '<body link="blue" vlink="purple">';
htmlText += startHtml + objValue.html + endHtml;
htmlText += '</body></html>';
}
return htmlText;
};
NSExport.prototype.__getHTMLTextForWord = function(setting,html,isTable)
{
var objReturn = {header:null,style:null,html:html};
objReturn.header = "<w:WordDocument><w:View>Print</w:View><w:Zoom>100</w:Zoom><w:DoNotOptimizeForBrowser/></w:WordDocument>";
if(isTable)
{
objReturn.style = 'table{border-collapse: collapse;} table, th, td {border: 1px solid black;} ';
}
if(setting["pageBreakTag"])
{
objReturn.html = objReturn.html.replaceAll(setting["pageBreakTag"],"<br clear=all style='mso-special-character:line-break;page-break-before:always'>");
}
return objReturn;
};
NSExport.prototype.__getHTMLTextForExcel = function(setting,html,isTable)
{
var objReturn = {header:null,style:null,html:html};
objReturn.header = "<x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>";
objReturn.header += (setting["sheetName"] ? setting["sheetName"]: ((this.__fileName ? this.__fileName : "Sheet 1")));
objReturn.header += '</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook>';
return objReturn;
};
NSExport.prototype.__getHTMLTextForPpt = function(setting,html,isTable)
{
var objReturn = {header:null,style:null,html:html};
objReturn.header = "<x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>";
objReturn.header += (setting["sheetName"] ? setting["sheetName"]: ((this.__fileName ? this.__fileName : "Sheet 1")));
objReturn.header += '</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook>';
return objReturn;
};
NSExport.prototype.__downloadFile = function(text,uri,fileType,event)
{
if(text && fileType)
{
if ("Blob" in window)
{
var fileName = this.__getFileName(fileType);
if ("msSaveOrOpenBlob" in window.navigator)
{
var blobObject = null;
if(text instanceof Blob)
{
blobObject = text;
}
else if(!(text instanceof ArrayBuffer) && text.indexOf("base64") > -1)
{
blobObject = this.__dataURItoBlob(text);
}
else
{
blobObject = new Blob([text], { type: uri});
}
window.navigator.msSaveOrOpenBlob(blobObject,fileName);
}
else
{
var hrefvalue = null;
if(text instanceof ArrayBuffer)
{
var blobObject = new Blob([text], {type: uri});
hrefvalue = URL.createObjectURL(blobObject);
}
else if(text instanceof Blob)
{
hrefvalue = URL.createObjectURL(text);
}
else
{
if(text.indexOf("data:") === -1)
{
uri = "data:" + uri;
}
if(text.indexOf(";base64,") === -1)
{
var base64String = ";base64," + window.btoa(window.unescape(encodeURIComponent(text)));
hrefvalue = uri + base64String;
}
else
{
hrefvalue = text;
}
}
var anchor = document.createElement("a");
if ("webkitURL" in window)
{
// Chrome allows the link to be clicked without actually adding it to the DOM.
//hrefvalue = window.webkitURL.createObjectURL([hrefvalue]);
}
else
{
//hrefvalue = window.URL.createObjectURL([hrefvalue]);
anchor.style.display = 'none';
document.body.appendChild(anchor);
this.util.addEvent(anchor,"click",function(event){
document.body.removeChild(event.target);
});
}
anchor.setAttribute("href",hrefvalue);
anchor.setAttribute("download",this.__getFileName(fileType));
anchor.setAttribute("target","_blank");
anchor.innerHTML = "Download File";
/*if(window.URL && window.URL.revokeObjectURL)
{
window.URL.revokeObjectURL(hrefvalue);
}*/
anchor.click();
if(event)
{
this.util.preventDefault(event);
}
}
}
}
};
NSExport.prototype.__getTable = function()
{
var tblResult = null;
if(this.__grid)
{
var grid = this.__getPrototype(this.__grid);
if(grid && this.__isTypeNSGrid(grid))
{
var tblHeader = grid.__tblCenterHeader;
var tblBody = grid.__tblCenterBody;
tblResult = document.createElement("TABLE");
tblResult.style.width = tblHeader.style.width;
if(tblHeader && tblHeader.tBodies && tblHeader.tBodies.length > 0 && tblHeader.tBodies[0].rows && tblHeader.tBodies[0].rows.length > 0)
{
var arrColumns = grid.__columns;
if(grid.gridType === grid.GRID_TYPE_GROUP)
{
arrColumns = grid.util.cloneObject(arrColumns);
arrColumns.splice(0, 1);
}
var header = tblResult.createTHead();
var headerRow = header.insertRow(-1);
var rowIndex = 0;
var colIndex = 0;
for(colIndex = 0; colIndex < arrColumns.length; colIndex++)
{
var colItem = arrColumns[colIndex];
if(colItem && (!colItem.hasOwnProperty(grid.__fieldColVisible) || colItem[grid.__fieldColVisible]) && (!colItem.hasOwnProperty("isExportable") || Boolean.parse(colItem["isExportable"])))
{
var headerCell = headerRow.insertCell(-1);
this.util.addStyleClass(headerCell,"header");
headerCell.style.width = colItem["width"];
var headerText = colItem["headerText"];
headerCell.appendChild(document.createTextNode(headerText));
}
}
if(tblBody && tblBody.tBodies && tblBody.tBodies.length > 0 && tblBody.tBodies[0].rows && tblBody.tBodies[0].rows.length > 0)
{
var arrItems = grid.__getAllItems();
var body = document.createElement("tbody");
tblResult.appendChild(body);
var colText = "";
var row = null;
for(rowIndex = 0;rowIndex < arrItems.length;rowIndex++)
{
var item = arrItems[rowIndex];
if(!item.hasOwnProperty(grid.__fieldRowVisible) || item[grid.__fieldRowVisible])
{
var bodyRow = body.insertRow(-1);
for(colIndex = 0;colIndex < arrColumns.length;colIndex++)
{
var colItem = arrColumns[colIndex];
if(colItem && (!colItem.hasOwnProperty(grid.__fieldColVisible) || colItem[grid.__fieldColVisible]) && (!colItem.hasOwnProperty("isExportable") || Boolean.parse(colItem["isExportable"])))
{
colText = item[colItem["dataField"]];
if(colItem.hasOwnProperty("exportRenderer"))
{
colText = colItem["exportRenderer"](item,colItem["dataField"],item[grid.__fieldIndex],count);
}
var bodyCell = bodyRow.insertCell(-1);
bodyCell.style.width = colItem["width"];
bodyCell.innerHTML = colText;
}
}
}
}
}
}
}
else
{
tblResult = this.__grid.cloneNode(true);
if(tblResult.tHead && tblResult.tHead.rows && tblResult.tHead.rows.length > 0)
{
var headerRow = tblResult.tHead.rows[0];
if(headerRow)
{
var arrCells = [];
var arrTempCells = [];
if(headerRow.getElementsByTagName("th").length > 0)
{
arrTempCells = headerRow.getElementsByTagName("th");
}
else if(headerRow.getElementsByTagName("td").length > 0)
{
arrTempCells = headerRow.getElementsByTagName("td");
}
arrCells = Array.prototype.slice.call(arrTempCells).slice(0);
var colIndex = 0;
var cell = null;
for(colIndex = arrCells.length - 1; colIndex >= 0; colIndex--)
{
headerRow.deleteCell(colIndex);
}
for(colIndex = 0; colIndex < arrCells.length; colIndex++)
{
cell = arrCells[colIndex];
var headerCell = headerRow.insertCell(-1);
headerCell.style.width = cell.offsetWidth + "px";
headerCell.color = "red";
headerCell.appendChild(document.createTextNode(cell.textContent.trim()));
this.util.addStyleClass(headerCell,"header");
}
}
}
}
if(tblResult)
{
tblResult.setAttribute("border",0);
tblResult.setAttribute("cellpadding",0);
tblResult.setAttribute("cellspacing",0);
tblResult.setAttribute("style","border-collapse:collapse;table-layout:fixed;");
}
}
return tblResult;
};
NSExport.prototype.__getTableAsString = function(delimiter,newLine,headerSeparator)
{
var strResult = "";
if(this.__grid)
{
var grid = this.__getPrototype(this.__grid);
if(grid && this.__isTypeNSGrid(grid))
{
var tblHeader = grid.__tblCenterHeader;
var tblBody = grid.__tblCenterBody;
if(tblHeader && tblHeader.tBodies && tblHeader.tBodies.length > 0 && tblHeader.tBodies[0].rows && tblHeader.tBodies[0].rows.length > 0)
{
var arrColumns = grid.__columns;
if(grid.gridType === grid.GRID_TYPE_GROUP)
{
arrColumns = grid.util.cloneObject(arrColumns);
arrColumns.splice(0, 1);
}
var rowIndex = 0;
var colIndex = 0;
var cell = null;
var arrCollItem = [];
for(colIndex = 0; colIndex < arrColumns.length; colIndex++)
{
var colItem = arrColumns[colIndex];
if(colItem && (!colItem.hasOwnProperty(grid.__fieldColVisible) || colItem[grid.__fieldColVisible]) && (!colItem.hasOwnProperty("isExportable") || Boolean.parse(colItem["isExportable"])))
{
var headerText = colItem["headerText"];
if(colIndex > 0)
{
strResult += delimiter;
}
strResult += this.__getFieldValue(headerText,delimiter);
}
}
strResult += newLine;
if(headerSeparator)
{
var separatorLength = strResult.length + 20;
for(var count = 0;count < separatorLength;count++)
{
strResult += headerSeparator;
}
strResult += newLine;
}
if(tblBody && tblBody.tBodies && tblBody.tBodies.length > 0 && tblBody.tBodies[0].rows && tblBody.tBodies[0].rows.length > 0)
{
var arrItems = grid.__getAllItems();
var colText = "";
for(rowIndex = 0;rowIndex < arrItems.length;rowIndex++)
{
var item = arrItems[rowIndex];
if(!item.hasOwnProperty(grid.__fieldRowVisible) || item[grid.__fieldRowVisible])
{
for(colIndex = 0;colIndex < arrColumns.length;colIndex++)
{
var colItem = arrColumns[colIndex];
if(colItem && (!colItem.hasOwnProperty(grid.__fieldColVisible) || colItem[grid.__fieldColVisible]) && (!colItem.hasOwnProperty("isExportable") || Boolean.parse(colItem["isExportable"])))
{
if(colIndex > 0)
{
strResult += delimiter;
}
colText = item[colItem["dataField"]];
if(colItem.hasOwnProperty("exportRenderer"))
{
colText = colItem["exportRende