+function($){"use strict";if($.wn===undefined)$.wn={} if($.oc===undefined)$.oc=$.wn if($.wn.table===undefined)$.wn.table={} var Table=function(element,options){this.el=element this.$el=$(element) this.options=options this.disposed=false this.dataSource=null this.cellProcessors={} this.activeCellProcessor=null this.activeCell=null this.tableContainer=null this.dataTableContainer=null this.editedRowKey=null this.dataTable=null this.headerTable=null this.toolbar=null this.clickHandler=this.onClick.bind(this) this.keydownHandler=this.onKeydown.bind(this) this.documentClickHandler=this.onDocumentClick.bind(this) this.toolbarClickHandler=this.onToolbarClick.bind(this) if(this.options.postback&&this.options.clientDataSourceClass=='client'){if(!this.options.postbackHandlerName.length){var formHandler=this.$el.closest('form').data('request') this.options.postbackHandlerName=[formHandler||'onSave']}else if(typeof this.options.postbackHandlerName==='string'){this.options.postbackHandlerName=this.options.postbackHandlerName.split(',')}this.formSubmitHandler=this.onFormSubmit.bind(this)}this.navigation=null this.search=null this.recordsAddedOrDeleted=0 this.disposeBound=this.dispose.bind(this) this.init() $.wn.foundation.controlUtils.markDisposable(element)} Table.prototype.init=function(){this.createDataSource() this.initCellProcessors() this.navigation=new $.wn.table.helper.navigation(this) this.search=new $.wn.table.helper.search(this) this.buildUi() this.registerHandlers()} Table.prototype.disposeCellProcessors=function(){for(var i=0,len=this.options.columns.length;i-1){this.unfocusTable() if(!this.validate()){ev.preventDefault() return}data.options.data[this.options.fieldName]=this.dataSource.getAllData()}} Table.prototype.onToolbarClick=function(ev){var target=this.getEventTarget(ev),cmd=target.getAttribute('data-cmd') if(!cmd){return}switch(cmd){case'record-add':case'record-add-below':this.addRecord('below') break case'record-add-above':this.addRecord('above') break case'record-delete':this.deleteRecord() break}this.stopEvent(ev)} Table.prototype.onDocumentClick=function(ev){var target=this.getEventTarget(ev) if(this.parentContainsElement(this.el,target))return if(this.activeCellProcessor&&this.activeCellProcessor.elementBelongsToProcessor(target))return this.unfocusTable()} Table.prototype.dispose=function(){if(this.disposed){return}this.disposed=true this.disposeBound=true this.unfocusTable() this.dataSource.dispose() this.dataSource=null this.unregisterHandlers() this.dataTable=null this.headerTable=null this.toolbar=null this.disposeCellProcessors() this.navigation.dispose() this.navigation=null this.disposeScrollbar() this.el=null this.tableContainer=null this.$el=null this.dataTableContainer=null this.activeCell=null} Table.prototype.setRowValues=function(rowIndex,rowValues){var row=this.findRowByIndex(rowIndex) if(!row){return false}var dataUpdated=false for(var i=0,len=row.children.length;i0;} Navigation.prototype.getPageFirstRowOffset=function(){return this.pageIndex*this.tableObj.options.recordsPerPage} Navigation.prototype.buildPagination=function(recordCount){if(!this.paginationEnabled())return var paginationContainer=this.tableObj.getElement().querySelector('.pagination'),newPaginationContainer=false,curRecordCount=0 this.pageCount=this.calculatePageCount(recordCount,this.tableObj.options.recordsPerPage) if(!paginationContainer){paginationContainer=document.createElement('div') paginationContainer.setAttribute('class','pagination') newPaginationContainer=true}else{curRecordCount=this.getRecordCount(paginationContainer)}if(newPaginationContainer||curRecordCount!=recordCount){paginationContainer.setAttribute('data-record-count',recordCount) var pageList=this.buildPaginationLinkList(recordCount,this.tableObj.options.recordsPerPage,this.pageIndex) if(!newPaginationContainer){paginationContainer.replaceChild(pageList,paginationContainer.children[0])}else{paginationContainer.appendChild(pageList) this.tableObj.getElement().appendChild(paginationContainer)}}else{this.markActiveLinkItem(paginationContainer,this.pageIndex)}} Navigation.prototype.calculatePageCount=function(recordCount,recordsPerPage){var pageCount=Math.ceil(recordCount/recordsPerPage) if(!pageCount)pageCount=1 return pageCount} Navigation.prototype.getRecordCount=function(paginationContainer){var container=paginationContainer?paginationContainer:this.tableObj.getElement().querySelector('.pagination') return parseInt(container.getAttribute('data-record-count'))} Navigation.prototype.buildPaginationLinkList=function(recordCount,recordsPerPage,pageIndex){var pageCount=this.calculatePageCount(recordCount,recordsPerPage),pageList=document.createElement('ul') for(var i=0;i0){var self=this this.gotoPage(this.pageIndex-1,function navUpPageSuccess(){self.focusCell('bottom',cellIndex) self=null})}}} Navigation.prototype.navigateLeft=function(ev,isTab){if(!this.tableObj.activeCell)return if(!isTab&&this.tableObj.activeCellProcessor&&!this.tableObj.activeCellProcessor.keyNavigationAllowed(ev,'left'))return var row=this.tableObj.activeCell.parentNode,newIndex=(!ev.shiftKey||isTab)?this.tableObj.activeCell.cellIndex-1:0 var cell=row.children[newIndex] if(cell){this.tableObj.focusCell(cell)}else{this.navigateUp(ev,row.children.length-1,isTab)}} Navigation.prototype.navigateRight=function(ev,isTab){if(!this.tableObj.activeCell)return if(!isTab&&this.tableObj.activeCellProcessor&&!this.tableObj.activeCellProcessor.keyNavigationAllowed(ev,'right'))return var row=this.tableObj.activeCell.parentNode,newIndex=!ev.shiftKey?this.tableObj.activeCell.cellIndex+1:row.children.length-1 var cell=row.children[newIndex] if(cell){this.tableObj.focusCell(cell)}else{this.navigateDown(ev,0)}} Navigation.prototype.navigateNext=function(ev){if(!this.tableObj.activeCell)return if(this.tableObj.activeCellProcessor&&!this.tableObj.activeCellProcessor.keyNavigationAllowed(ev,'tab'))return if(!ev.shiftKey)this.navigateRight(ev,true) else this.navigateLeft(ev,true) this.tableObj.stopEvent(ev)} Navigation.prototype.focusCell=function(rowReference,cellIndex){var row=null,tbody=this.tableObj.getDataTableBody() if(typeof rowReference==='object'){row=rowReference}else{if(rowReference=='bottom'){row=tbody.children[tbody.children.length-1]}else if(rowReference=='top'){row=tbody.children[0]}}if(!row)return var cell=row.children[cellIndex] if(cell)this.tableObj.focusCell(cell)} Navigation.prototype.focusCellInReplacedRow=function(rowIndex,cellIndex){if(rowIndex==0){this.focusCell('top',cellIndex)}else{var focusRow=this.tableObj.findRowByIndex(rowIndex) if(!focusRow)focusRow=this.tableObj.findRowByIndex(rowIndex-1) if(focusRow)this.focusCell(focusRow,cellIndex) else this.focusCell('top',cellIndex)}} Navigation.prototype.onKeydown=function(ev){if(ev.key==='ArrowDown')return this.navigateDown(ev) else if(ev.key==='ArrowUp')return this.navigateUp(ev) else if(ev.key==='ArrowLeft')return this.navigateLeft(ev) if(ev.key==='ArrowRight')return this.navigateRight(ev) if(ev.key==='Tab')return this.navigateNext(ev)} Navigation.prototype.onClick=function(ev){var target=this.tableObj.getEventTarget(ev,'A') if(!target||!$(target).hasClass('pagination-link'))return var pageIndex=parseInt(target.getAttribute('data-page-index')) if(pageIndex===null)return this.gotoPage(pageIndex) this.tableObj.stopEvent(ev) return false} $.wn.table.helper.navigation=Navigation;}(window.jQuery);+function($){"use strict";if($.wn.table===undefined)throw new Error("The $.wn.table namespace is not defined. Make sure that the table.js script is loaded.");if($.wn.table.helper===undefined)$.wn.table.helper={} var Search=function(tableObj){this.tableObj=tableObj this.searchForm=null this.searchInput=null this.inputTrackTimer=null this.activeQuery=null this.isActive=false this.init()};Search.prototype.init=function(){} Search.prototype.dispose=function(){this.tableObj=null this.searchForm=null this.searchInput=null} Search.prototype.buildSearchForm=function(){if(!this.searchEnabled())return var el=this.tableObj.getElement(),toolbar=this.tableObj.getToolbar(),searchForm=toolbar.querySelector('.table-search') if(!searchForm){this.searchForm=$($('[data-table-toolbar-search]',el).html()).appendTo(toolbar).get(0) this.searchInput=$('.table-search-input',this.searchForm).get(0)}} Search.prototype.getQuery=function(){return $.trim(this.activeQuery)} Search.prototype.hasQuery=function(){return this.searchEnabled()&&$.trim(this.activeQuery).length>0} Search.prototype.searchEnabled=function(){return this.tableObj.options.searching} Search.prototype.getSearchableColumns=function(){const columns=[];this.tableObj.options.columns.forEach(function(column){if(column.type==='checkbox'){return;}if(!column.searchable){return;}columns.push(column.key);});return columns;} Search.prototype.performSearch=function(query,onSuccess){var isDirty=this.activeQuery!=query this.activeQuery=query if(isDirty){this.tableObj.updateDataTable(onSuccess)}} Search.prototype.onKeydown=function(ev){if(ev.key==='Tab'){this.onClick(ev) return}if(!this.isActive){return}var self=this this.inputTrackTimer=window.setTimeout(function(){self.performSearch(self.searchInput.value)},300)} Search.prototype.onClick=function(ev){var target=this.tableObj.getEventTarget(ev,'INPUT') this.isActive=target&&$(target).hasClass('table-search-input')} $.wn.table.helper.search=Search;}(window.jQuery);+function($){"use strict";if($.wn.table===undefined)throw new Error("The $.wn.table namespace is not defined. Make sure that the table.js script is loaded.");if($.wn.table.datasource===undefined)$.wn.table.datasource={} var Base=function(tableObj){this.tableObj=tableObj} Base.prototype.dispose=function(){this.tableObj=null} Base.prototype.getRecords=function(offset,count,onSuccess){onSuccess([])} Base.prototype.searchRecords=function(query,offset,count,onSuccess){onSuccess([])} Base.prototype.createRecord=function(recordData,placement,relativeToKey,offset,count,onSuccess){onSuccess([],0)} Base.prototype.updateRecord=function(key,recordData){} Base.prototype.deleteRecord=function(key,newRecordData,offset,count,onSuccess){onSuccess([],0)} $.wn.table.datasource.base=Base;}(window.jQuery);+function($){"use strict";if($.wn.table===undefined)throw new Error("The $.wn.table namespace is not defined. Make sure that the table.js script is loaded.");if($.wn.table.datasource===undefined)throw new Error("The $.wn.table.datasource namespace is not defined. Make sure that the table.datasource.base.js script is loaded.");var Base=$.wn.table.datasource.base,BaseProto=Base.prototype var Client=function(tableObj){Base.call(this,tableObj) var dataString=tableObj.getElement().getAttribute('data-data') if(dataString===null||dataString===undefined)throw new Error('The required data-data attribute is not found on the table control element.') this.data=JSON.parse(dataString)};Client.prototype=Object.create(BaseProto) Client.prototype.constructor=Client Client.prototype.dispose=function(){BaseProto.dispose.call(this) this.data=null} Client.prototype.getRecords=function(offset,count,onSuccess){if(!count){onSuccess(this.data,this.data.length)}else{onSuccess(this.data.slice(offset,offset+count),this.data.length)}} Client.prototype.createRecord=function(recordData,placement,relativeToKey,offset,count,onSuccess){if(placement==='bottom'){this.data.push(recordData)}else if(placement=='above'||placement=='below'){var recordIndex=this.getIndexOfKey(relativeToKey) if(placement=='below')recordIndex++ this.data.splice(recordIndex,0,recordData)}this.getRecords(offset,count,onSuccess)} Client.prototype.searchRecords=function(query,offset,count,onSuccess){const searchFields=this.tableObj.search.getSearchableColumns();const matched=this.data.filter(function(record){for(let i=0;i',bodyContainer:true})} AutocompleteProcessor.prototype.prepareItems=function(items){var result={} if($.isArray(items)){for(var i=0,len=items.length;i0} $.wn.table.validator.base=Base;}(window.jQuery);+function($){"use strict";if($.wn.table===undefined)throw new Error("The $.wn.table namespace is not defined. Make sure that the table.js script is loaded.");if($.wn.table.validator===undefined)throw new Error("The $.wn.table.validator namespace is not defined. Make sure that the table.validator.base.js script is loaded.");var Base=$.wn.table.validator.base,BaseProto=Base.prototype var Required=function(options){Base.call(this,options)};Required.prototype=Object.create(BaseProto) Required.prototype.constructor=Required Required.prototype.validateValue=function(value,rowData){value=this.trim(value) if(value.length===0)return this.getMessage("The value should not be empty.") return} $.wn.table.validator.required=Required}(window.jQuery);+function($){"use strict";if($.wn.table===undefined)throw new Error("The $.wn.table namespace is not defined. Make sure that the table.js script is loaded.");if($.wn.table.validator===undefined)throw new Error("The $.wn.table.validator namespace is not defined. Make sure that the table.validator.base.js script is loaded.");var Base=$.wn.table.validator.base,BaseProto=Base.prototype var BaseNumber=function(options){Base.call(this,options)};BaseNumber.prototype=Object.create(BaseProto) BaseNumber.prototype.constructor=BaseNumber BaseNumber.prototype.doCommonChecks=function(value){if(this.options.min!==undefined||this.options.max!==undefined){if(this.options.min!==undefined){if(this.options.min.value===undefined)throw new Error('The min.value parameter is not defined in the table validator configuration') if(valuethis.options.max.value){return this.options.max.message!==undefined?this.options.max.message:"The value should not be more than "+this.options.max.value}}}return} $.wn.table.validator.baseNumber=BaseNumber}(window.jQuery);+function($){"use strict";if($.wn.table===undefined)throw new Error("The $.wn.table namespace is not defined. Make sure that the table.js script is loaded.");if($.wn.table.validator===undefined)throw new Error("The $.wn.table.validator namespace is not defined. Make sure that the table.validator.base.js script is loaded.");if($.wn.table.validator.baseNumber===undefined)throw new Error("The $.wn.table.validator.baseNumber namespace is not defined. Make sure that the table.validator.baseNumber.js script is loaded.");var Base=$.wn.table.validator.baseNumber,BaseProto=Base.prototype var Integer=function(options){Base.call(this,options)};Integer.prototype=Object.create(BaseProto) Integer.prototype.constructor=Integer Integer.prototype.validateValue=function(value,rowData){value=this.trim(value) if(value.length==0)return var testResult=this.options.allowNegative?/^\-?[0-9]*$/.test(value):/^[0-9]*$/.test(value) if(!testResult){var defaultMessage=this.options.allowNegative?'The value should be an integer.':'The value should be a positive integer';return this.getMessage(defaultMessage)}return this.doCommonChecks(parseInt(value))} $.wn.table.validator.integer=Integer}(window.jQuery);+function($){"use strict";if($.wn.table===undefined)throw new Error("The $.wn.table namespace is not defined. Make sure that the table.js script is loaded.");if($.wn.table.validator===undefined)throw new Error("The $.wn.table.validator namespace is not defined. Make sure that the table.validator.base.js script is loaded.");if($.wn.table.validator.baseNumber===undefined)throw new Error("The $.wn.table.validator.baseNumber namespace is not defined. Make sure that the table.validator.baseNumber.js script is loaded.");var Base=$.wn.table.validator.baseNumber,BaseProto=Base.prototype var Float=function(options){Base.call(this,options)};Float.prototype=Object.create(BaseProto) Float.prototype.constructor=Float Float.prototype.validateValue=function(value,rowData){value=this.trim(value) if(value.length==0)return var testResult=this.options.allowNegative?/^[-]?([0-9]+\.[0-9]+|[0-9]+)$/.test(value):/^([0-9]+\.[0-9]+|[0-9]+)$/.test(value) if(!testResult){var defaultMessage=this.options.allowNegative?'The value should be a floating point number.':'The value should be a positive floating point number';return this.getMessage(defaultMessage)}return this.doCommonChecks(parseFloat(value))} $.wn.table.validator.float=Float}(window.jQuery);+function($){"use strict";if($.wn.table===undefined)throw new Error("The $.wn.table namespace is not defined. Make sure that the table.js script is loaded.");if($.wn.table.validator===undefined)throw new Error("The $.wn.table.validator namespace is not defined. Make sure that the table.validator.base.js script is loaded.");var Base=$.wn.table.validator.base,BaseProto=Base.prototype var Length=function(options){Base.call(this,options)};Length.prototype=Object.create(BaseProto) Length.prototype.constructor=Length Length.prototype.validateValue=function(value,rowData){value=this.trim(value) if(value.length==0)return if(this.options.min!==undefined||this.options.max!==undefined){if(this.options.min!==undefined){if(this.options.min.value===undefined)throw new Error('The min.value parameter is not defined in the Length table validator configuration') if(value.lengththis.options.max.value){return this.options.max.message!==undefined?this.options.max.message:"The string should not be longer than "+this.options.max.value}}}return} $.wn.table.validator.length=Length}(window.jQuery);+function($){"use strict";if($.wn.table===undefined)throw new Error("The $.wn.table namespace is not defined. Make sure that the table.js script is loaded.");if($.wn.table.validator===undefined)throw new Error("The $.wn.table.validator namespace is not defined. Make sure that the table.validator.base.js script is loaded.");var Base=$.wn.table.validator.base,BaseProto=Base.prototype var Regex=function(options){Base.call(this,options)};Regex.prototype=Object.create(BaseProto) Regex.prototype.constructor=Regex Regex.prototype.validateValue=function(value,rowData){value=this.trim(value) if(value.length==0)return if(this.options.pattern===undefined)throw new Error('The pattern parameter is not defined in the Regex table validator configuration') var regexObj=new RegExp(this.options.pattern,this.options.modifiers) if(!regexObj.test(value))return this.getMessage("Invalid value format.") return} $.wn.table.validator.regex=Regex}(window.jQuery);