UNPKG

nscomponentsreact

Version:

React Wrapper Components for NSComponents

1,522 lines (1,401 loc) 50.3 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 __nsGlobal = (function () { if (typeof globalThis !== "undefined") return globalThis; if (typeof self !== "undefined") return self; if (typeof window !== "undefined") return window; if (typeof global !== "undefined") return global; return Function("return this")(); })();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 NSCalendar = (function() { function NSCalendar(component,setting) { this.__setting = setting; this.__context = window; this.__inputDateFormat = "MM/dd/yyyy"; this.__minDate = null; this.__maxDate = null; this.__selectedDate = null; this.__buttonSetting = {prev:{html:null,cssClass:null},next:{html:null,cssClass:null}, savetime: {html:null,cssClass:null}, canceltime: {html:null,cssClass:null}}; this.__customClass = {container:null,headerContainer:null,prevButton:null,nextButton:null,monthDropdown:null,yearDropdown:null,weekContainer:null,week:null,dayContainer:null,day:null,footerContainer:null}; this.__monthValueName = null; this.__monthTextName = null; this.__weekName = null; this.__markDayDisabled = null; this.__showFooter = false; this.__footerContent = null; this.__width = null; this.__cellWidth = null; this.__divContainer = null; this.__divHeaderContainer = null; this.__cmbMonth = null; this.__cmbYear = null; this.__divWeekContainer = null; this.__divDayContainer = null; this.__divDayBody = null; this.__divTimeContainer = null; this.__divFooterContainer = null; this.__arrYear = []; this.__lastSelectedCell = null; this.__arrDayCells = []; this.__minWidth = 240; this.__minCellWidth = 32; this.__showTime = false; this.__timeSetting = {minHour: 0, maxHour: 23, minMinute: 0, maxMinute: 59, showSeconds: false, minSecond: 0, maxSecond: 59}; this.__dayClickHandlerRef = null; this.base.__setBaseComponent.call(this,component); }; nsExtendPrototype(NSContainerBase,NSCalendar); NSCalendar.prototype.varructor = NSCalendar; NSCalendar.prototype.initializeComponent = function() { this.base.initializeComponent.call(this); this.__setSetting(); this.__initDefault(); this.__injectClass(); this.__createComponent(); }; NSCalendar.prototype.setComponentProperties = function() { this.base.setComponentProperties.call(this); }; NSCalendar.prototype.propertyChange = function(attrName, oldVal, newVal, setProperty) { var attributeName = attrName.toLowerCase(); this.base.propertyChange.call(this,attrName, oldVal, newVal, setProperty); }; NSCalendar.prototype.removeComponent = function() { this.base.removeComponent.call(this); }; NSCalendar.prototype.componentResized = function(event) { this.base.componentResized.call(this,event); }; NSCalendar.prototype.getSelectedDate = function() { return this.__selectedDate; }; NSCalendar.prototype.getSelectedDateAsString = function(format) { if(this.__selectedDate) { var nsDateUtil = new NSDateUtil(); return nsDateUtil.format(this.__selectedDate,format); } return null; }; NSCalendar.prototype.setSelectedDate = function(date,format,fireEvent) { this.__selectedDate = this.__formatInputDate(date,format); this.__updateDaysInControl(this.__selectedDate); if(this.util.isUndefinedOrNull(fireEvent) || fireEvent) { this.util.dispatchEvent(this.__baseComponent,NSCalendar.DATE_SELECTED,this.__selectedDate,{date:this.__selectedDate}); } }; NSCalendar.prototype.setYear = function(year) { this.__setYearDropdown(year); this.__dropDownChangeHandler(); this.__cmbMonth.selectedIndex = monthDate.getMonth(); }; NSCalendar.prototype.setMonth = function(month) { this.__cmbMonth.selectedIndex = month; this.__dropDownChangeHandler(); }; NSCalendar.prototype.reset = function() { this.__selectedDate = null; var todayDate = new Date(); var date = this.__maxDate < todayDate ? this.__maxDate : todayDate; this.__updateDaysInControl(date); this.__resetTimeInControl(); }; NSCalendar.prototype.setTodayDate = function(fireEvent) { this.__selectedDate = new Date(); this.__updateDaysInControl(this.__selectedDate); if(this.util.isUndefinedOrNull(fireEvent) || fireEvent) { //for some reason __selectedDate time part is getting reset mostly in this.__updateDayCell function that is why resetting the date back if(this.__showTime) { this.__selectedDate = this.__setTimePartInDate(this.__selectedDate); } this.util.dispatchEvent(this.__baseComponent,NSCalendar.DATE_SELECTED,this.__selectedDate,{date:this.__selectedDate}); } }; NSCalendar.prototype.__initDefault = function() { if(!this.__minDate) { this.__minDate = new Date(); this.__minDate = this.__getDateObject(this.__minDate.getFullYear() - 15,0,1); } if(!this.__maxDate) { this.__maxDate = new Date(); this.__maxDate = this.__getDateObject(this.__maxDate.getFullYear() + 15,0,1); } if(!this.__monthValueName || this.__monthValueName.length === 0) { this.__monthValueName = ["January","Febuary","March","April","May","June","July","August","September","October","November","December"]; } if(!this.__monthTextName || this.__monthTextName.length === 0) { this.__monthTextName = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; } if(!this.__weekName || this.__weekName.length === 0) { this.__weekName = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]; } }; NSCalendar.prototype.__injectClass = function() { if(this.__width && this.__width > this.__minWidth) { this.util.addCSSClassInDOM(["#" + this.getID() + ".nsCalendar"],["width:" + this.__width + "px;"]); if(!this.__cellWidth) { this.__cellWidth = Math.floor(this.__width / 7); } } if(this.__cellWidth && this.__cellWidth > this.__minCellWidth) { this.util.addCSSClassInDOM(["#" + this.getID() + ".nsCalendar .nsCalendarWeek"],["width:" + this.__cellWidth + "px;"]); this.util.addCSSClassInDOM(["#" + this.getID() + ".nsCalendar .nsCalendarDayContainerCell"],["width:" + this.__cellWidth + "px;"]); } }; NSCalendar.prototype.__setSetting = function() { if(!this.__setting) { this.__setting = {}; } var setting = this.__setting; if(setting) { if(setting.hasOwnProperty("context")) { this.__context = setting["context"]; } if(setting.hasOwnProperty("inputDateFormat")) { this.__inputDateFormat = setting["inputDateFormat"]; } if(setting.hasOwnProperty("minDate")) { this.__minDate = this.__formatInputDate(setting["minDate"]); } if(setting.hasOwnProperty("maxDate")) { this.__maxDate = this.__formatInputDate(setting["maxDate"]); } if(setting.hasOwnProperty("selectedDate")) { this.__selectedDate = this.__formatInputDate(setting["selectedDate"]); } if(setting.hasOwnProperty("monthValueName")) { this.__monthValueName = setting["monthValueName"]; } if(setting.hasOwnProperty("monthTextName")) { this.__monthTextName = setting["monthTextName"]; } if(setting.hasOwnProperty("weekName")) { this.__weekName = setting["weekName"]; } if(setting.hasOwnProperty("markDayDisabled")) { this.__markDayDisabled = setting["markDayDisabled"]; this.__markDayDisabled = this.util.getFunction(this.__markDayDisabled,this.__context); } if(setting.hasOwnProperty("width")) { this.__width = Number(setting["width"]); if(isNaN(this.__width)) { this.__width = null; } } if(setting.hasOwnProperty("cellWidth")) { this.__cellWidth = Number(setting["cellWidth"]); if(isNaN(this.__cellWidth)) { this.__cellWidth = null; } } if(setting.hasOwnProperty("showFooter")) { this.__showFooter = Boolean.parse(setting["showFooter"]); } if(setting.hasOwnProperty("showTime")) { this.__showTime = Boolean.parse(setting["showTime"]); // or simply: this.__showTime = !!setting["showTime"]; } if(setting.hasOwnProperty("timeSetting") && setting["timeSetting"]) { this.__timeSetting = {...this.__timeSetting, ...setting["timeSetting"]}; } if(setting.hasOwnProperty("footerContent")) { this.__footerContent = setting["footerContent"]; } if(this.__showFooter) { this.__createFooter(); this.__baseComponent.appendChild(this.__divFooterContainer); } if(setting.hasOwnProperty("theme")) { this.__theme = setting["theme"]; } var buttonSetting = {}; if(setting.hasOwnProperty("buttonSetting")) { buttonSetting = setting["buttonSetting"]; } if(!buttonSetting) { buttonSetting = {}; } if(!buttonSetting.prev) { buttonSetting.prev = {html:null,cssClass:null}; } if(!buttonSetting.prev.html) { buttonSetting.prev.html = "<svg height=\"24\" version=\"1.1\" viewbox=\"0 0 24 24\" width=\"24\" xmlns=\"http://www.w3.org/2000/svg\" class=\"nsCalendarIcon nsCalendarHeaderButtonSvg\">\r\n" + "<path d=\"M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z\"></path>\r\n" + "</svg>"; } if(!buttonSetting.next) { buttonSetting.next = {html:null,cssClass:null}; } if(!buttonSetting.next.html) { buttonSetting.next.html = "<svg height=\"24\" version=\"1.1\" viewbox=\"0 0 24 24\" width=\"24\" xmlns=\"http://www.w3.org/2000/svg\" class=\"nsCalendarIcon nsCalendarHeaderButtonSvg\">\r\n" + "<path d=\"M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z\"></path>\r\n" + "</svg>"; } if(!buttonSetting.savetime) { buttonSetting.savetime = {html:null,cssClass:null}; } if(!buttonSetting.savetime.html) { buttonSetting.savetime.html = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="nsCalendarIcon nsCalendarIconTime nsCalendarIconTimeSave" > <!-- Circle --> <circle cx="12" cy="12" r="10"></circle> <!-- Checkmark --> <path d="M9 12l2 2 4-4"></path> </svg>`; } if(!buttonSetting.canceltime) { buttonSetting.canceltime = {html:null,cssClass:null}; } if(!buttonSetting.canceltime.html) { buttonSetting.canceltime.html = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="nsCalendarIcon nsCalendarIconTime nsCalendarIconTimeCancel" > <!-- Circle --> <circle cx="12" cy="12" r="10"></circle> <!-- Cross (X) --> <line x1="9" y1="9" x2="15" y2="15"></line> <line x1="15" y1="9" x2="9" y2="15"></line> </svg>`; } this.__buttonSetting = {prev:{html:buttonSetting.prev.html,cssClass:buttonSetting.prev.cssClass}, next:{html:buttonSetting.next.html,cssClass:buttonSetting.next.cssClass}, savetime: {html:buttonSetting.savetime.html,cssClass:buttonSetting.savetime.cssClass}, canceltime: {html:buttonSetting.canceltime.html,cssClass:buttonSetting.canceltime.cssClass} }; var customClass = {}; if(setting.hasOwnProperty("customClass")) { customClass = setting["customClass"]; } if(!customClass) { customClass = {}; } for(var prop in this.__customClass) { this.__customClass[prop] = (customClass[prop] || null); } } }; NSCalendar.prototype.__createComponent = function() { this.util.addStyleClass(this.__baseComponent,"nsCalendar"); this.__applyTheme(this.__baseComponent,"nsCalendar"); this.__divContainer = this.util.createDiv(this.getID() + "container","nsCalendarContainer"); this.__applyCustomClass(this.__divContainer,"container"); this.__createHeader(); this.__divContainer.appendChild(this.__divHeaderContainer); this.__createWeek(); this.__divContainer.appendChild(this.__divWeekContainer); this.__createDays(); this.__divContainer.appendChild(this.__divDayContainer); if(this.__showTime) { this.__createTimePart(); this.__divContainer.appendChild(this.__divTimeContainer); } this.__baseComponent.appendChild(this.__divContainer); if(this.__showFooter) { this.__createFooter(); this.__baseComponent.appendChild(this.__divFooterContainer); } var todayDate = new Date(); var date = this.__maxDate < todayDate ? this.__maxDate : todayDate; this.__updateDaysInControl(date); }; NSCalendar.prototype.__createHeader = function() { if(!this.__divHeaderContainer) { var self = this; var initButton = function(strID,cssClass,buttonSettingKey,customClassKey,handler) { var btn = self.util.createElement("button",self.getID() + "btn" + strID,cssClass); btn.innerHTML = self.__buttonSetting[buttonSettingKey].html; self.util.addStyleClass(btn,self.__buttonSetting[buttonSettingKey].cssClass); self.__applyCustomClass(btn,customClassKey); self.util.addEvent(btn,"click",handler); self.__divHeaderContainer.appendChild(btn); }; var createSelect = function(parent,id,cssClass,customClassKey,arrText,arrValue) { var select = self.util.createElement("select",self.getID() + "select" + id,cssClass); self.__applyCustomClass(select,customClassKey); self.util.addEvent(select,"change",self.__dropDownChangeHandler.bind(self)); self.util.addEvent(select,"click",self.__dropDownClickHandler.bind(self)); for (var count = 0; count < arrValue.length; count++) { var option = document.createElement("option"); option.text = arrText[count]; option.value = arrValue[count]; select.appendChild(option); } parent.appendChild(select); return select; }; this.__divHeaderContainer = this.util.createDiv(this.getID() + "header","nsCalendarHeader"); this.__applyCustomClass(this.__divHeaderContainer,"headerContainer"); initButton("previous","nsCalendarButton","prev","prevButton",this.__prevClickHandler.bind(this)); var divNavigation = this.util.createDiv(this.getID() + "headerNavigation","nsCalendarHeaderNav"); if(this.__monthValueName.length !== this.__monthTextName.length) { this.__monthValueName = this.__monthTextName; } this.__cmbMonth = createSelect(divNavigation,"month","nsCalendarSelect","monthDropdown",this.__monthTextName,this.__monthValueName); var minYear = this.__minDate.getFullYear(); var maxYear = this.__maxDate.getFullYear(); this.__arrYear = []; for(var count = minYear;count <= maxYear;count++) { this.__arrYear.push(count); } this.__cmbYear = createSelect(divNavigation,"year","nsCalendarSelect","yearDropdown",this.__arrYear,this.__arrYear); this.__divHeaderContainer.appendChild(divNavigation); initButton("next","nsCalendarButton","next","nextButton",this.__nextClickHandler.bind(this)); } }; NSCalendar.prototype.__createWeek = function() { if(!this.__divWeekContainer) { this.__divWeekContainer = this.util.createDiv(this.getID() + "week","nsCalendarWeekContainer"); this.__applyCustomClass(this.__divWeekContainer,"weekContainer"); for(var count = 0;count < this.__weekName.length;count++) { var divWeek = this.util.createDiv(null,"nsCalendarWeek"); this.__applyCustomClass(divWeek,"week"); divWeek.appendChild(document.createTextNode(this.__weekName[count])); this.__divWeekContainer.appendChild(divWeek); } } }; NSCalendar.prototype.__createDays = function() { if(!this.__divDayContainer) { this.__divDayContainer = this.util.createDiv(this.getID() + "day","nsCalendarDayContainer"); this.__applyCustomClass(this.__divDayContainer,"dayContainer"); this.__divDayBody = this.util.createDiv(this.getID() + "dayBody","nsCalendarDayContainerBody"); var handler = this.__dayClickHandler.bind(this); for (var rowCount = 0;rowCount < 6;rowCount++) { var row = this.__createDayRow(this.__divDayBody); for (var count = 0;count < 7;count++) { var cell = this.__createDayCell(row,handler); var item = {row:row,cell:cell}; this.__arrDayCells.push(item); } } this.__divDayContainer.appendChild(this.__divDayBody); } }; NSCalendar.prototype.__createDayRow = function(parent) { var divDayRow = this.util.createDiv(null,"nsCalendarDayContainerRow"); parent.appendChild(divDayRow); return divDayRow; }; NSCalendar.prototype.__createDayCell = function(parent,handler) { var divDay = this.util.createDiv(null,"nsCalendarDayContainerCell"); this.util.addEvent(divDay,"click",handler); parent.appendChild(divDay); return divDay; }; NSCalendar.prototype.__createTimePart = function() { if (this.__showTime) { this.__divTimeContainer = this.util.createDiv(this.getID() + "Time","nsCalendarTimeContainer"); this.__applyCustomClass(this.__divTimeContainer,"timeContainer"); var timePartContainer = this.util.createDiv(this.getID() + "TimePartCon","nsCalendarTimePartContainer"); var timeLabelSpan = this.util.createElement("span", null, "nsCalendarTimeLabel"); timeLabelSpan.appendChild(document.createTextNode("Time: ")); timePartContainer.appendChild(timeLabelSpan); var timeSetting = this.__timeSetting; var hourInput = this.__createTimeInput("hour", "nsCalendarHourInput", timeSetting.minHour, timeSetting.maxHour); timePartContainer.appendChild(hourInput); timePartContainer.appendChild(this.__createTimeSeparator()); var minuteInput = this.__createTimeInput("minute", "nsCalendarMinuteInput", timeSetting.minMinute, timeSetting.maxMinute); timePartContainer.appendChild(minuteInput); if(timeSetting.showSeconds) { timePartContainer.appendChild(this.__createTimeSeparator()); var secondInput = this.__createTimeInput("second", "nsCalendarSecondInput", timeSetting.minSecond, timeSetting.maxSecond); timePartContainer.appendChild(secondInput); } this.__divTimeContainer.appendChild(timePartContainer); var timeSaveContainer = this.util.createDiv(this.getID() + "TimePartSave","nsCalendarTimeSaveContainer"); timeSaveContainer.appendChild(this.__createTimeButton("Save", null, "savetime", "savetimebutton", this.__savetimeClickHandler.bind(this))); timeSaveContainer.appendChild(this.__createTimeButton("Cancel", null, "canceltime", "canceltimebutton", this.__canceltimeClickHandler.bind(this))); this.__divTimeContainer.appendChild(timeSaveContainer); } } NSCalendar.prototype.__savetimeClickHandler = function(event) { this.__selectedDate = this.__setTimePartInDate(this.__selectedDate); this.util.dispatchEvent(this.__baseComponent,NSCalendar.DATE_SELECTED,this.__selectedDate,{date:this.__selectedDate}); }; NSCalendar.prototype.__canceltimeClickHandler = function(event) { this.util.dispatchEvent(this.__baseComponent,NSCalendar.DATE_SELECTION_CANCELLED); }; NSCalendar.prototype.__createTimeInput = function(timePart,cssClass, minVal, maxVal) { var timeInput = this.util.createElement("input",this.getID() + "_input_" + timePart, "nsCalendarTimeInput " + cssClass); timeInput.type = "number"; timeInput.min = minVal; timeInput.max = maxVal; timeInput.value = "0"; timeInput.size = 2; // Keep it small timeInput.addEventListener("change", this.__timeInputChangeHandler.bind(this)); timeInput.addEventListener("input", this.__timeInputEnterInputHandler.bind(this)); return timeInput; } NSCalendar.prototype.__createTimeButton = function(strID, cssClass, buttonSettingKey, customClassKey, handler) { var btn = this.util.createElement("button",this.getID() + "btn" + strID,"nsCalendarIconButton" + (cssClass ? " " + cssClass : "")); btn.innerHTML = this.__buttonSetting[buttonSettingKey].html; if(this.__timeSetting && this.__timeSetting.showSeconds) { var child = btn.children[0]; if(child) { this.util.addStyleClass(child,"nsCalendarIconTimeSmall"); } } this.util.addStyleClass(btn,this.__buttonSetting[buttonSettingKey].cssClass); this.__applyCustomClass(btn,customClassKey); this.util.addEvent(btn,"click",handler); return btn; } NSCalendar.prototype.__createTimeSeparator = function() { var timeSeparatorSpan = this.util.createElement("span", null, "nsCalendarTimeSeparator"); timeSeparatorSpan.appendChild(document.createTextNode(" : ")); return timeSeparatorSpan; } NSCalendar.prototype.__timeInputEnterInputHandler = function(event) { var input = event.target; var min = parseInt(input.min, 10); var max = parseInt(input.max, 10); var value = parseInt(input.value, 10); if (isNaN(value)) { value = 0; } if (value > max) { value = max; } else if (value < min) { value = min; } input.value = this.__padTimeValue(value); } NSCalendar.prototype.__timeInputChangeHandler = function(event) { if (!this.__selectedDate) { this.__selectedDate = new Date(); } //this.__timeInputEnterInputHandler(event); this.__selectedDate = this.__setTimePartInDate(this.__selectedDate); // Optionally fire an event or update the UI // This is up to you. E.g., if you want dateSelected to fire whenever time changes: // this.util.dispatchEvent(this.__baseComponent, NSCalendar.DATE_SELECTED, this.__selectedDate, { date: this.__selectedDate }); }; NSCalendar.prototype.__updateTimeInControl = function(date) { if (!this.__divTimeContainer) return; var hourInput = this.__divTimeContainer.querySelector(".nsCalendarHourInput"); var minuteInput = this.__divTimeContainer.querySelector(".nsCalendarMinuteInput"); var secondInput = this.__divTimeContainer.querySelector(".nsCalendarSecondInput"); if(hourInput) { hourInput.value = this.__padTimeValue(date.getHours()); } if(minuteInput) { minuteInput.value = this.__padTimeValue(date.getMinutes()); } if(secondInput) { secondInput.value = this.__padTimeValue(date.getSeconds()); } }; NSCalendar.prototype.__resetTimeInControl = function() { var date = new Date(); date.setHours(0, 0, 0, 0); this.__updateTimeInControl(date); } NSCalendar.prototype.__padTimeValue = function(value) { var retVal = String(value).padStart(2, '0'); return retVal; } NSCalendar.prototype.__setTimePartInDate = function(date) { var timeContainer = this.__divTimeContainer; if (!timeContainer || !date) { return date; } var hourInput = timeContainer.querySelector(".nsCalendarHourInput"); var minuteInput = timeContainer.querySelector(".nsCalendarMinuteInput"); var secondInput = timeContainer.querySelector(".nsCalendarSecondInput"); var newHour = parseInt(hourInput.value, 10) || 0; var newMinute = minuteInput ? (parseInt(minuteInput.value, 10) || 0) : 0; var newSecond = secondInput ? (parseInt(secondInput.value, 10) || 0) : 0; newHour = Math.max(0, Math.min(this.__timeSetting.maxHour, newHour)); newMinute = Math.max(0, Math.min(this.__timeSetting.maxMinute, newMinute)); newSecond = Math.max(0, Math.min(this.__timeSetting.maxSecond, newSecond)); date.setHours(newHour, newMinute, newSecond, 0); return date; } NSCalendar.prototype.__createFooter = function() { if(!this.__divFooterContainer) { this.__divFooterContainer = this.util.createDiv(this.getID() + "footer","nsCalendarFooterContainer"); this.__applyCustomClass(this.__divFooterContainer,"footerContainer"); if(this.__footerContent) { if(this.util.isString(this.__footerContent)) { var compSpan = document.createElement("span"); compSpan.innerHTML = this.__footerContent; this.__divFooterContainer.appendChild(compSpan); } else { this.__divFooterContainer.appendChild(this.__footerContent); } } } }; NSCalendar.prototype.__updateDaysInControl = function(monthDate) { if(this.__isDateValidForNavigation(monthDate)) { this.__setYearDropdown(monthDate.getFullYear()); this.__cmbMonth.selectedIndex = monthDate.getMonth(); var today = new Date(); var date = new Date(monthDate.getFullYear(),monthDate.getMonth(),1,0,0,0,0); // Starting at the 1st of the month var extras = (date.getDay() + 6) % 7; // How many days of the last month do we need to include? date.setDate(date.getDate() - extras); var item = null; for(var count = 0;count < this.__arrDayCells.length;count++) { item = this.__arrDayCells[count]; this.__updateDayCell(item.cell,date,monthDate,today,count); item.date = new Date(date.getTime()); item.index = count; date.setDate(date.getDate() + 1); } if (this.__showTime) { this.__updateTimeInControl(monthDate); } } }; NSCalendar.prototype.__resetDayCell = function(cell) { if(cell) { cell.setAttribute("class",""); this.util.addStyleClass(cell,"nsCalendarDayContainerCell"); this.__applyCustomClass(cell,"day"); cell.innerHTML = ""; } }; NSCalendar.prototype.__updateDayCell = function(cell,dateToSet,currentMonthDate,todayDate,index) { if(cell) { this.__resetDayCell(cell); cell.appendChild(document.createTextNode(dateToSet.getDate())); cell.setAttribute("data-ns-cal-index",index); if(this.__isDateSelectable(dateToSet)) { if (dateToSet.getMonth() != currentMonthDate.getMonth()) { this.util.addStyleClass(cell,"nsCalendarOtherMonth"); } if (this.__dateCompare(dateToSet,todayDate) === 0) { this.util.addStyleClass(cell,"nsCalendarToday"); } if (this.__dateCompare(dateToSet,this.__selectedDate) === 0) { //dont fire event as it is just to update the cell this.__setCellSelection(dateToSet,cell,false); } } else { this.util.addStyleClass(cell,"nsCalendarDayDisabled"); } } }; NSCalendar.prototype.__prevClickHandler = function(event) { event = this.util.getEvent(event); event.stopPropagation(); var month = this.__cmbMonth.selectedIndex; var year = this.__cmbYear.options[this.__cmbYear.selectedIndex].value; var date = this.__getDateObject(year,month,1); date.setMonth(date.getMonth() - 1); this.__updateDaysInControl(date); }; NSCalendar.prototype.__nextClickHandler = function(event) { event = this.util.getEvent(event); event.stopPropagation(); var month = this.__cmbMonth.selectedIndex; var year = this.__cmbYear.options[this.__cmbYear.selectedIndex].value; var date = this.__getDateObject(year,month,1); date.setMonth(date.getMonth() + 1); this.__updateDaysInControl(date); }; NSCalendar.prototype.__dayClickHandler = function(event) { var target = this.util.getTarget(event); if(!this.util.hasStyleClass(target,"nsCalendarDayContainerCell")) { target = this.util.findParentBySelector(target,".nsCalendarDayContainerCell"); } if(target) { if(this.__lastSelectedCell) { this.util.removeStyleClass(this.__lastSelectedCell,"nsCalendarSelected"); } var index = parseInt(target.getAttribute("data-ns-cal-index")); if(this.util.hasStyleClass(target,"nsCalendarOtherMonth")) { this.__lastSelectedCell = null; var item = this.__getItemByIndex(index); if(item && this.__isDateSelectable(item.date)) { this.__selectedDate = item.date; this.__setTimePartInDate(this.__selectedDate); this.__updateDaysInControl(this.__selectedDate); this.util.dispatchEvent(this.__baseComponent,NSCalendar.DATE_SELECTED,this.__selectedDate,{date:this.__selectedDate}); } } else { this.__selectCellForIndex(index); } } event.stopPropagation(); }; NSCalendar.prototype.__dropDownChangeHandler = function(event) { event = this.util.getEvent(event); var month = this.__cmbMonth.selectedIndex; var year = this.__cmbYear.options[this.__cmbYear.selectedIndex].value; var date = this.__getDateObject(year,month,1); this.__updateDaysInControl(date); event.stopPropagation(); }; NSCalendar.prototype.__dropDownClickHandler = function(event) { event = this.util.getEvent(event); event.stopPropagation(); }; NSCalendar.prototype.__selectCellForIndex = function(index) { this.__selectedDate = null; var item = this.__getItemByIndex(index); if(item) { item.date = this.__setTimePartInDate(item.date); this.__setCellSelection(item.date,item.cell,true); } }; NSCalendar.prototype.__setCellSelection = function(date,cell,fireEvent) { if(this.__isDateSelectable(date)) { this.__selectedDate = this.__cloneDateObject(date); if(fireEvent && !this.__showTime) { this.util.dispatchEvent(this.__baseComponent,NSCalendar.DATE_SELECTED,this.__selectedDate,{date:this.__selectedDate}); } if(cell) { this.util.addStyleClass(cell,"nsCalendarSelected"); this.__lastSelectedCell = cell; } } }; NSCalendar.prototype.__clearCellSelectionExceptSelected = function() { if(this.__arrDayCells && this.__arrDayCells.length > 0) { for(var count = 0;count < this.__arrDayCells.length;count++) { var item = this.__arrDayCells[count]; if(this.__lastSelectedCell != item.cell) { this.util.removeStyleClass(item.cell,"nsCalendarSelected"); } } } }; NSCalendar.prototype.__getItemByIndex = function(index) { if(index > -1) { var item = {}; for(var count = 0;count < this.__arrDayCells.length;count++) { item = this.__arrDayCells[count]; if(item.index === index) { return item; } } } return null; }; NSCalendar.prototype.__dateCompare = function(date1,date2) { if(!date1 && !date2) { return 0; } if(!date1) { return -1; } if(!date2) { return 1; } if (date1.getDate() == date2.getDate() && date1.getMonth() == date2.getMonth() && date1.getFullYear() == date2.getFullYear()) { return 0; } var tempDate1 = this.__dateWithoutTime(this.__cloneDateObject(date1)); var tempDate2 = this.__dateWithoutTime(this.__cloneDateObject(date2)); return (tempDate1.getTime() > tempDate2.getTime()); }; NSCalendar.prototype.__cloneDateObject = function(date) { return this.__getDateObject(date.getFullYear(),date.getMonth(),date.getDate()); }; NSCalendar.prototype.__getDateObject = function(year,month,day) { var date = new Date(year,month,day); return date; }; NSCalendar.prototype.__isDateSelectable = function(date) { if(date) { var tempDate = this.__dateWithoutTime(date); var tempMinDate = this.__dateWithoutTime(this.__minDate); var tempMaxDate = this.__dateWithoutTime(this.__maxDate); var isMinCond = tempDate >= tempMinDate; var isMaxCond = tempDate <= tempMaxDate; if(isMinCond && isMaxCond) { if(this.__markDayDisabled) { return this.__markDayDisabled(date); } else { return true; } } } return false; }; NSCalendar.prototype.__dateWithoutTime = function(date) { var tempDate = new Date(date); tempDate.setHours(0, 0, 0, 0); return tempDate; }; NSCalendar.prototype.__isDateValidForNavigation = function(date) { if(date && date.getFullYear() >= this.__minDate.getFullYear() && date.getFullYear() <= this.__maxDate.getFullYear()) { return true; } return false; }; NSCalendar.prototype.__applyCustomClass = function(element,type) { if(element && type && this.__customClass[type]) { this.util.addStyleClass(element,this.__customClass[type]); } }; NSCalendar.prototype.__formatInputDate = function(inputValue,format) { format = format ? format : this.__inputDateFormat; if(inputValue) { if(Object.prototype.toString.call(inputValue) === '[object Date]') { return inputValue; } else { var nsDateUtil = new NSDateUtil(); return nsDateUtil.parseString(inputValue,format); } } return null; }; //IE issue NSCalendar.prototype.__setYearDropdown = function(year) { //this.__cmbYear.selectedIndex = this.__cmbYear.querySelector('option[value="'+ monthDate.getFullYear() +'"]').index; this.__cmbYear.querySelector('option[value="'+ year +'"]').selected = "selected"; }; NSCalendar.DATE_SELECTED = "dateSelected"; NSCalendar.DATE_SELECTION_CANCELLED = "dateSelectionCancelled"; return NSCalendar; })(); nsModuleExport(__nsGlobal,"NSCalendar",NSCalendar);var NSDatePicker = (function() { function NSDatePicker(component,setting) { this.__setting = setting; this.__context = window; this.__dateOutputFormat = "MM/dd/yyyy"; this.__placeHolder = null; this.__buttonHtml = null; this.__enableTextBoxDisabled = false; this.__customClass = {container:null,textInput:null,button:null,calContainer:null,calHeaderContainer:null,calPrevButton:null,calNextButton:null,calMonthDropdown:null,calYearDropdown:null,calWeekContainer:null,calWeek:null,calDayContainer:null,calDay:null,calFooterContainer:null}; this.__calendarPos = null; this.__calendarWidth = null; this.__calendarCellWidth = null; this.__isAbsolutePosition = true; this.__divContainer = null; this.__txtBox = null; this.__btnActivate = null; this.__divCalContainer = null; this.__nsPopUp = null; this.__maxZIndex = 0; this.__nsCalendar = null; this.__documentMouseDownRef = null; this.base.__setBaseComponent.call(this,component); }; nsExtendPrototype(NSContainerBase,NSDatePicker); NSDatePicker.prototype.constructor = NSDatePicker; NSDatePicker.prototype.initializeComponent = function() { this.base.initializeComponent.call(this); this.__setSetting(); this.__initDefault(); this.__createComponent(); this.__maxZIndex = this.util.getMaxZIndex(); }; NSDatePicker.prototype.setComponentProperties = function() { this.base.setComponentProperties.call(this); }; NSDatePicker.prototype.propertyChange = function(attrName, oldVal, newVal, setProperty) { var attributeName = attrName.toLowerCase(); this.base.propertyChange.call(this,attrName, oldVal, newVal, setProperty); }; NSDatePicker.prototype.removeComponent = function() { this.__removeDocumentMosueHandler(); this.__removePopUp(); this.base.removeComponent.call(this); }; NSDatePicker.prototype.componentResized = function(event) { this.__hideCalendar(); this.base.componentResized.call(this,event); }; NSDatePicker.prototype.getSelectedDate = function() { if(this.__nsCalendar) { return this.__nsCalendar.getSelectedDate(); } return null; }; NSDatePicker.prototype.getSelectedDateAsString = function(format) { if(this.__nsCalendar) { return this.__nsCalendar.getSelectedDateAsString(format); } return null; }; NSDatePicker.prototype.setSelectedDate = function(date,format,fireEvent) { if(this.__nsCalendar) { this.__nsCalendar.setSelectedDate(date,format,fireEvent); } if(date) { this.__setTextInput(this.getSelectedDate()); } else { this.__txtBox.value = ""; } }; NSDatePicker.prototype.setYear = function(year) { if(this.__nsCalendar) { this.__nsCalendar.setYear(year); } }; NSDatePicker.prototype.setMonth = function(month) { if(this.__nsCalendar) { this.__nsCalendar.setMonth(month); } }; NSDatePicker.prototype.reset = function() { if(this.__nsCalendar) { this.__nsCalendar.reset(); } this.__setTextInput(); }; NSDatePicker.prototype.setTodayDate = function() { if(this.__nsCalendar) { this.__nsCalendar.setTodayDate(); } //this.__setTextInput(new Date()); }; NSDatePicker.prototype.showCalendar = function(isAbsolutePosition) { this.__showCalendar(null, isAbsolutePosition); }; NSDatePicker.prototype.closeCalendar = function() { this.__hideCalendar(); }; NSDatePicker.prototype.toggleCalendarVisibility = function() { this.__toggleCalendarVisibility(); }; NSDatePicker.prototype.getCalendar = function() { return this.__nsCalendar; }; NSDatePicker.prototype.getTextBox = function() { return this.__txtBox; }; NSDatePicker.prototype.getText = function() { return this.__txtBox.value; }; NSDatePicker.prototype.__setSetting = function() { if(!this.__setting) { this.__setting = {}; } var setting = this.__setting; if(setting) { if(setting.hasOwnProperty("context")) { this.__context = setting["context"]; } if(setting.hasOwnProperty("dateOutputFormat")) { this.__dateOutputFormat = setting["dateOutputFormat"]; } else if(setting.hasOwnProperty("showTime") && Boolean.parse(setting["showTime"])) { this.__dateOutputFormat += " HH:mm"; if(setting.hasOwnProperty("timeSetting") && setting["timeSetting"].showSeconds) { this.__dateOutputFormat += ":ss"; } } if(setting.hasOwnProperty("placeHolder")) { this.__placeHolder = setting["placeHolder"]; } if(setting.hasOwnProperty("buttonHtml")) { this.__buttonHtml = setting["buttonHtml"]; } if(setting.hasOwnProperty("enableTextBoxDisabled")) { this.__enableTextBoxDisabled = Boolean.parse(setting["enableTextBoxDisabled"]); } if(setting.hasOwnProperty("calendarPos")) { this.__calendarPos = setting["calendarPos"]; } else { this.__calendarPos = this.util.POS_BOTTOMRIGHT; } if(setting.hasOwnProperty("calendarWidth")) { this.__calendarWidth = setting["calendarWidth"]; } if(setting.hasOwnProperty("calendarCellWidth")) { this.__calendarCellWidth = setting["calendarCellWidth"]; } if(setting.hasOwnProperty("isAbsolutePosition")) { this.__isAbsolutePosition = Boolean.parse(setting["isAbsolutePosition"]); } else { this.__isAbsolutePosition = true; } if(setting.hasOwnProperty("theme")) { this.__theme = setting["theme"]; } var customClass = {}; if(setting.hasOwnProperty("customClass")) { customClass = setting["customClass"]; } if(!customClass) { customClass = {}; } for(var prop in this.__customClass) { this.__customClass[prop] = (customClass[prop] || null); } } }; NSDatePicker.prototype.__initDefault = function() { if(!this.__buttonHtml) { this.__buttonHtml = "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" \r\n" + " width=\"16px\" height=\"16px\" viewBox=\"0 0 36.447 36.447\" >\r\n" + "<g>\r\n" + " <g>\r\n" + " <path d=\"M30.224,3.948h-1.098V2.75c0-1.517-1.197-2.75-2.67-2.75c-1.474,0-2.67,1.233-2.67,2.75v1.197h-2.74V2.75\r\n" + " c0-1.517-1.197-2.75-2.67-2.75c-1.473,0-2.67,1.233-2.67,2.75v1.197h-2.74V2.75c0-1.517-1.197-2.75-2.67-2.75\r\n" + " c-1.473,0-2.67,1.233-2.67,2.75v1.197H6.224c-2.343,0-4.25,1.907-4.25,4.25v24c0,2.343,1.907,4.25,4.25,4.25h24\r\n" + " c2.344,0,4.25-1.907,4.25-4.25v-24C34.474,5.855,32.567,3.948,30.224,3.948z M25.286,2.75c0-0.689,0.525-1.25,1.17-1.25\r\n" + " c0.646,0,1.17,0.561,1.17,1.25v4.896c0,0.689-0.524,1.25-1.17,1.25c-0.645,0-1.17-0.561-1.17-1.25V2.75z M17.206,2.75\r\n" + " c0-0.689,0.525-1.25,1.17-1.25s1.17,0.561,1.17,1.25v4.896c0,0.689-0.525,1.25-1.17,1.25s-1.17-0.561-1.17-1.25V2.75z M9.125,2.75\r\n" + " c0-0.689,0.525-1.25,1.17-1.25s1.17,0.561,1.17,1.25v4.896c0,0.689-0.525,1.25-1.17,1.25s-1.17-0.561-1.17-1.25V2.75z\r\n" + " M31.974,32.198c0,0.965-0.785,1.75-1.75,1.75h-24c-0.965,0-1.75-0.785-1.75-1.75v-22h27.5V32.198z\"/>\r\n" + " <rect x=\"6.724\" y=\"14.626\" width=\"4.595\" height=\"4.089\"/>\r\n" + " <rect x=\"12.857\" y=\"14.626\" width=\"4.596\" height=\"4.089\"/>\r\n" + " <rect x=\"18.995\" y=\"14.626\" width=\"4.595\" height=\"4.089\"/>\r\n" + " <rect x=\"25.128\" y=\"14.626\" width=\"4.596\" height=\"4.089\"/>\r\n" + " <rect x=\"6.724\" y=\"20.084\" width=\"4.595\" height=\"4.086\"/>\r\n" + " <rect x=\"12.857\" y=\"20.084\" width=\"4.596\" height=\"4.086\"/>\r\n" + " <rect x=\"18.995\" y=\"20.084\" width=\"4.595\" height=\"4.086\"/>\r\n" + " <rect x=\"25.128\" y=\"20.084\" width=\"4.596\" height=\"4.086\"/>\r\n" + " <rect x=\"6.724\" y=\"25.54\" width=\"4.595\" height=\"4.086\"/>\r\n" + " <rect x=\"12.857\" y=\"25.54\" width=\"4.596\" height=\"4.086\"/>\r\n" + " <rect x=\"18.995\" y=\"25.54\" width=\"4.595\" height=\"4.086\"/>\r\n" + " <rect x=\"25.128\" y=\"25.54\" width=\"4.596\" height=\"4.086\"/>\r\n" + " </g>\r\n" + "</g>\r\n" + "</svg>"; } }; NSDatePicker.prototype.__createComponent = function() { this.util.addStyleClass(this.__baseComponent,"nsDatePicker"); this.__applyTheme(this.__baseComponent,"nsDatePicker"); this.__divContainer = this.util.createDiv(this.getID() + "container","nsDatePickerContainer"); this.__applyCustomClass(this.__divContainer,"container"); this.__baseComponent.appendChild(this.__divContainer); this.__txtBox = this.util.createElement("input",this.getID() + "input","nsDatePickerTextBox"); this.__txtBox.setAttribute("type","search"); this.__applyCustomClass(this.__txtBox,"textInput"); if(this.__placeHolder) { this.__txtBox.setAttribute("placeholder",this.__placeHolder); } if(this.__enableTextBoxDisabled) { this.__txtBox.setAttribute("readOnly",true); this.util.addStyleClass(this.__txtBox,"nsDatePickerTextBoxDisabled"); } else { this.util.addEvent(this.__txtBox,"input",this.__txtBoxKeyHandler.bind(this)); } this.__divContainer.appendChild(this.__txtBox); this.__btnActivate = this.util.createElement("button",this.getID() + "button","nsDatePickerButton"); this.__applyCustomClass(this.__txtBox,"button"); this.__btnActivate.innerHTML = this.__buttonHtml; this.util.addEvent(this.__btnActivate,"click",this.__btnActivateClickHandler.bind(this)); this.__divContainer.appendChild(this.__btnActivate); var popUpSetting = {type:"div",width:null,position:this.__calendarPos,closeOnOutsideClick:false}; this.__nsPopUp = new this.util.nsPopUp(popUpSetting); this.__nsPopUp.create(); this.__divCalContainer = this.__nsPopUp.getPopUp(); /*this.__divCalContainer = this.util.createDiv(this.getID() + "calContainer","nsDatePickerCalContainer"); this.__divContainer.appendChild(this.__divCalContainer);*/ this.__createCalendar(this.__divCalContainer); if(this.getSelectedDate()) { this.__setTextInput(this.getSelectedDate()); } }; NSDatePicker.prototype.__createCalendar = function(parent) { if(!this.__nsCalendar) { var setting = this.util.cloneObject(this.__setting); setting.customClass = {}; for(var prop in this.__customClass) { if(prop.startsWith("cal")) { var tempProp = prop.substring(3); tempProp = tempProp.charAt(0).toLowerCase() + tempProp.slice(1); setting.customClass[tempProp] = this.__customClass[prop]; } } setting["width"] = this.__calendarWidth; setting["cellWidth"] = this.__calendarCellWidth; this.__nsCalendar = new NSCalendar(parent,setting); this.util.addEvent(parent,NSCalendar.DATE_SELECTED,this.__dateSelectedHandler.bind(this)); this.util.addEvent(parent,NSCalendar.DATE_SELECTION_CANCELLED,this.__dateCancelSelectedHandler.bind(this)); } }; NSDatePicker.prototype.__btnActivateClickHandler = function(event) { //to stop refresh of page event = this.util.getEvent(event); event.preventDefault(); event.stopPropagation(); this.__toggleCalendarVisibility(event); }; NSDatePicker.prototype.__txtBoxKeyHandler = function(event) { var strDate = this.__txtBox.value; var nsDateUtil = new NSDateUtil(); var date = nsDateUtil.parseString(strDate,this.__dateOutputFormat); if(date) { this.__nsCalendar.setSelectedDate(date); } else { this.__nsCalendar.setSelectedDate(null,null,false); } this.util.dispatchEvent(this.__baseComponent,NSDatePicker.INPUT_CHANGE,strDate,{date:date,value:strDate}); }; NSDatePicker.prototype.__documentMouseDownHandler = function(event) { var target = this.util.getTarget(event); var parent = this.util.findParentBySelector(target,".nsDatePickerContainer") || this.util.findParentBySelector(target,".nsCalendar"); if(!parent) { this.__hideCalendar(); } }; NSDatePicker.prototype.__dateSelectedHandler = function(event) { event.stopImmediatePropagation(); event.stopPropagation(); var selectedDate = event.detail; this.__setTextInput(selectedDate); this.__hideCalendar(); this.util.dispatchEvent(this.__baseComponent,NSDatePicker.DATE_SELECTED,selectedDate,{date:selectedDate}); }; NSDatePicker.prototype.__dateCancelSelectedHandler = function(event) { event.stopImmediatePropagation(); event.stopPropagation(); this.__hideCalendar(); }; NSDatePicker.prototype.__setTextInput = function(date) { if(date) { var nsDateUtil = new NSDateUtil(); this.__txtBox.value = nsDateUtil.format(date,this.__dateOutputFormat); } else { this.__txtBox.value = ""; } }; NSDatePicker.prototype.__toggleCalendarVisibility = function(event) { if(this.__isCalendarVisible()) { this.__hideCalendar(event); } else { this.__showCalendar(event); } }; NSDatePicker.prototype.__showCalendar = function(event,isAbsolutePosition) { if(this.util.isUndefinedOrNull(isAbsolutePosition)) { isAbsolutePosition = this.__isAbsolutePosition; } this.__nsCalendar.__clearCellSelectionExceptSelected(); //this.util.addStyleClass(this.__divCalContainer,"nsDatePickerCalContainerVisible"); this.__nsPopUp.show(); this.__nsPopUp.placePopUp(this.__divContainer,isAbsolutePosition); this.__addDocumentMosueHandler(); this.__divCalContainer.style.zIndex = (this.__maxZIndex > 0) ? (this.__maxZIndex + 1) : 9999; this.util.dispatchEvent(this.__baseComponent,NSDatePicker.CALENDAR_OPENED); }; NSDatePicker.prototype.__hideCalendar = function(event) { //this.util.removeStyleClass(this.__divCalContainer,"nsDatePickerCalContainerVisible"); this.__nsPopUp.hide(); this.__removeDocumentMosueHandler(); this.util.dispatchEvent(this.__baseComponent,NSDatePicker.CALENDAR_CLOSED); }; NSDatePicker.prototype.__addDocumentMosueHandler = function() { if(!this.__documentMouseDownRef) { this.__documentMouseDownRef = this.__documentMouseDownHandler.bind(this); this.util.addEvent(document,"mousedown",this.__documentMouseDownRef); } }; NSDatePicker.prototype.__removeDocumentMosueHandler = function() { if(this.__documentMouseDownRef) { this.util.removeEvent(document,"mousedown",this.__documentMouseDownRef); this.__documentMouseDownRef = null; } }; NSDatePicker.prototype.__isCalendarVisible = function() { return this.util.hasStyleClass(this.__divCalContainer,"nsDatePickerCalContainerVisible"); }; NSDatePicker.prototype.__applyCustomClass = function(element,type) { if(element && type && this.__customClass[type]) { this.util.addStyleClass(element,this.__customClass[type]); } }; NSDatePicker.prototype.__removePopUp = function() { if(this.__nsPopUp) { this.__nsPopUp.remove