You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

1 lines
38 KiB

(function(n,t,i){function e(n,i){var u=t(n);u.data(o,this);this._container=u;this.data=[];this.total=0;this.fields=[];this._editingRow=null;this._sortField=null;this._sortOrder=r;this._firstDisplayingPage=1;this._init(i);this.render()}var o="JSGrid",f="JSGridItem",s="JSGridEditRow",r="asc",v="desc",y="{first}",p="{pages}",w="{prev}",b="{next}",k="{last}",d="{pageIndex}",g="{pageCount}",nt="{itemCount}",tt="javascript:void(0);",u=function(n,i){return t.isFunction(n)?n.apply(i,t.makeArray(arguments).slice(2)):n},it=function(n){var i=t.Deferred();return n&&n.then?n.then(function(){i.resolve.apply(i,arguments)},function(){i.reject.apply(i,arguments)}):i.resolve(n),i.promise()},h={loadData:t.noop,insertItem:t.noop,updateItem:t.noop,deleteItem:t.noop};e.prototype={width:"auto",height:"auto",updateOnResize:!0,rowClass:t.noop,rowRenderer:null,rowClick:function(n){this.editing&&this.editItem(t(n.event.target).closest("tr"))},rowDoubleClick:t.noop,rowMouseDown:t.noop,rowMouseUp:t.noop,rowMouseUut:t.noop,noDataContent:"Not found",noDataRowClass:"jsgrid-nodata-row",heading:!0,headerRowRenderer:null,headerRowClass:"jsgrid-header-row",headerCellClass:"jsgrid-header-cell",filtering:!1,filterRowRenderer:null,filterRowClass:"jsgrid-filter-row",inserting:!1,insertRowRenderer:null,insertRowClass:"jsgrid-insert-row",editing:!1,editRowRenderer:null,editRowClass:"jsgrid-edit-row",confirmDeleting:!0,deleteConfirm:"Are you sure?",selecting:!0,selectedRowClass:"jsgrid-selected-row",oddRowClass:"jsgrid-row",evenRowClass:"jsgrid-alt-row",cellClass:"jsgrid-cell",sorting:!1,sortableClass:"jsgrid-header-sortable",sortAscClass:"jsgrid-header-sort jsgrid-header-sort-asc",sortDescClass:"jsgrid-header-sort jsgrid-header-sort-desc",paging:!1,pagerContainer:null,pageIndex:1,pageSize:20,pageButtonCount:15,pagerFormat:"{Total} {itemCount} {Pen} {first} {prev} {pages} {next} {last} &nbsp;&nbsp;&nbsp;&nbsp; {Numth} {pageIndex} {Page} {Total} {pageCount} {Page}",pagePrevText:"Prev",pageNextText:"Next",pageFirstText:"First",pageLastText:"Last",pageNavigatorNextText:"...",pageNavigatorPrevText:"...",pagerContainerClass:"jsgrid-pager-container",pagerClass:"jsgrid-pager",pagerNavButtonClass:"jsgrid-pager-nav-button",pagerNavButtonInactiveClass:"jsgrid-pager-nav-inactive-button",pageClass:"jsgrid-pager-page",currentPageClass:"jsgrid-pager-current-page",customLoading:!1,pageLoading:!1,autoload:!1,controller:h,loadIndication:!0,loadIndicationDelay:500,loadMessage:"Please, wait...",loadShading:!0,invalidMessage:"Invalid data entered!",invalidNotify:function(n){var i=t.map(n.errors,function(n){return n.message||null});showMsg([this.invalidMessage].concat(i).join("<br>"),"info")},onInit:t.noop,onRefreshing:t.noop,onRefreshed:t.noop,onPageChanged:t.noop,onItemDeleting:t.noop,onItemDeleted:t.noop,onItemInserting:t.noop,onItemInserted:t.noop,onItemEditing:t.noop,onItemUpdating:t.noop,onItemUpdated:t.noop,onItemInvalid:t.noop,onDataLoading:t.noop,onDataLoaded:t.noop,onOptionChanging:t.noop,onOptionChanged:t.noop,onError:t.noop,invalidClass:"jsgrid-invalid",containerClass:"jsgrid",tableClass:"jsgrid-table",gridHeaderClass:"jsgrid-grid-header",gridBodyClass:"jsgrid-grid-body",_init:function(n){t.extend(this,n);this._initLoadStrategy();this._initController();this._initFields();this._attachWindowLoadResize();this._attachWindowResizeCallback();this._callEventHandler(this.onInit);this.dfheight||(this.dfheight=this.height)},loadStrategy:function(){return this.pageLoading?new jsGrid.loadStrategies.PageLoadingStrategy(this):new jsGrid.loadStrategies.DirectLoadingStrategy(this)},_initLoadStrategy:function(){this._loadStrategy=u(this.loadStrategy,this)},_initController:function(){this._controller=t.extend({},h,u(this.controller,this))},renderTemplate:function(n,t,r){args=[];for(var f in r)args.push(r[f]);return args.unshift(n,t),n=u.apply(null,args),n===i||n===null?"":n},loadIndicator:function(n){return new jsGrid.LoadIndicator(n)},validation:function(n){return jsGrid.Validation&&new jsGrid.Validation(n)},_initFields:function(){var n=this;n.fields=t.map(n.fields,function(i){if(t.isPlainObject(i)){var r=i.type&&jsGrid.fields[i.type]||jsGrid.Field;i=new r(i)}return i._grid=n,i})},_attachWindowLoadResize:function(){t(n).on("load",t.proxy(this._refreshSize,this))},_attachWindowResizeCallback:function(){if(this.updateOnResize)t(n).on("resize",t.proxy(this._refreshSize,this))},_detachWindowResizeCallback:function(){t(n).off("resize",this._refreshSize)},option:function(n,t){var i,r;if(arguments.length===1)return this[n];i={option:n,oldValue:this[n],newValue:t};this._callEventHandler(this.onOptionChanging,i);this._handleOptionChange(i.option,i.newValue);r={option:i.option,value:i.newValue};this._callEventHandler(this.onOptionChanged,r)},fieldOption:function(n,t,i){if(n=this._normalizeField(n),arguments.length===2)return n[t];n[t]=i;this._renderGrid()},_handleOptionChange:function(n,t){this[n]=t;switch(n){case"width":case"height":this._refreshSize();break;case"rowClass":case"rowRenderer":case"rowClick":case"rowDoubleClick":case"rowMouseDown":case"rowMouseUp":case"rowMouseUut":case"noDataRowClass":case"noDataContent":case"selecting":case"selectedRowClass":case"oddRowClass":case"evenRowClass":this._refreshContent();break;case"pageButtonCount":case"pagerFormat":case"pagePrevText":case"pageNextText":case"pageFirstText":case"pageLastText":case"pageNavigatorNextText":case"pageNavigatorPrevText":case"pagerClass":case"pagerNavButtonClass":case"pageClass":case"currentPageClass":case"pagerRenderer":this._refreshPager();break;case"fields":this._initFields();this.render();break;case"data":case"editing":case"heading":case"filtering":case"inserting":case"paging":this.refresh();break;case"loadStrategy":case"pageLoading":this._initLoadStrategy();this.search();break;case"pageIndex":this.openPage(t);break;case"pageSize":this.refresh();this.search();break;case"editRowRenderer":case"editRowClass":this.cancelEdit();break;case"updateOnResize":this._detachWindowResizeCallback();this._attachWindowResizeCallback();break;case"invalidNotify":case"invalidMessage":break;default:this.render()}},destroy:function(){this._detachWindowResizeCallback();this._clear();this._container.removeData(o)},render:function(){return this._renderGrid(),this.autoload?this.loadData():t.Deferred().resolve().promise()},_renderGrid:function(){this._clear();this._container.addClass(this.containerClass).css("position","relative").append(this._createHeader()).append(this._createBody());this._pagerContainer=this._createPagerContainer();this._loadIndicator=this._createLoadIndicator();this._validation=this._createValidation();this.refresh()},_createLoadIndicator:function(){return u(this.loadIndicator,this,{message:this.loadMessage,shading:this.loadShading,container:this._container})},_createValidation:function(){return u(this.validation,this)},_clear:function(){this.cancelEdit();clearTimeout(this._loadingTimer);this._pagerContainer&&this._pagerContainer.empty();this._container.empty().css({position:"",width:"",height:""})},_createHeader:function(){var n=this._headerRow=this._createHeaderRow(),i=this._filterRow=this._createFilterRow(),r=this._insertRow=this._createInsertRow(),u=this._headerGrid=t("<table>").addClass(this.tableClass).append(n).append(i).append(r);return this._header=t("<div>").addClass(this.gridHeaderClass).addClass(this._scrollBarWidth()?"jsgrid-header-scrollbar":"").append(u)},_createBody:function(){var n=this._content=t("<tbody>"),i=this._bodyGrid=t("<table>").addClass(this.tableClass).append(n);return this._body=t("<div>").addClass(this.gridBodyClass).append(i).on("scroll",t.proxy(function(n){this._header.scrollLeft(n.target.scrollLeft)},this))},_createPagerContainer:function(){var n=this.pagerContainer||t("<div>").appendTo(this._container);return t(n).addClass(this.pagerContainerClass)},_eachField:function(n){var i=this;t.each(this.fields,function(t,r){r.visible&&n.call(i,r,t)})},_createHeaderRow:function(){if(t.isFunction(this.headerRowRenderer))return t(this.renderTemplate(this.headerRowRenderer,this));var n=t("<tr>").addClass(this.headerRowClass);return this._eachField(function(i,r){var u=this._prepareCell("<th>",i,"headercss",this.headerCellClass).append(this.renderTemplate(i.headerTemplate,i));if(i.title&&u.attr("data-i18n",i.title),u.appendTo(n),this.sorting&&i.sorting)u.addClass(this.sortableClass).on("click",t.proxy(function(){typeof this.headerClick=="function"&&this.headerClick();this.sort(r)},this))}),n},_prepareCell:function(n,i,r,u){return t(n).css("width",i.width).addClass(u||this.cellClass).addClass(r&&i[r]||i.css).addClass(i.align?"jsgrid-align-"+i.align:"")},_createFilterRow:function(){if(t.isFunction(this.filterRowRenderer))return t(this.renderTemplate(this.filterRowRenderer,this));var n=t("<tr>").addClass(this.filterRowClass);return this._eachField(function(t){this._prepareCell("<td>",t,"filtercss").append(this.renderTemplate(t.filterTemplate,t)).appendTo(n)}),n},_createInsertRow:function(){if(t.isFunction(this.insertRowRenderer))return t(this.renderTemplate(this.insertRowRenderer,this));var n=t("<tr>").addClass(this.insertRowClass);return this._eachField(function(t){this._prepareCell("<td>",t,"insertcss").append(this.renderTemplate(t.insertTemplate,t)).appendTo(n)}),n},_callEventHandler:function(n,i){return n.call(this,t.extend(i,{grid:this})),i},reset:function(){return this._resetSorting(),this._resetPager(),this._loadStrategy.reset()},_resetPager:function(){this._firstDisplayingPage=1;this._setPage(1)},_resetSorting:function(){this._sortField=null;this._sortOrder=r;this._clearSortingCss()},refresh:function(){this._callEventHandler(this.onRefreshing);this.cancelEdit();this._refreshHeading();this._refreshFiltering();this._refreshInserting();this._refreshContent();this._refreshPager();this._refreshSize();this._callEventHandler(this.onRefreshed)},_refreshHeading:function(){this._headerRow.toggle(this.heading)},_refreshFiltering:function(){this._filterRow.toggle(this.filtering)},_refreshInserting:function(){this._insertRow.toggle(this.inserting)},_refreshContent:function(){var t=this._content,i,r,n,u;if(t.empty(),!this.data.length)return t.append(this._createNoDataRow()),this;for(i=this._loadStrategy.firstDisplayIndex(),r=this._loadStrategy.lastDisplayIndex(),n=i;n<r;n++)u=this.data[n],t.append(this._createRow(u,n))},_createNoDataRow:function(){var n=0;return this._eachField(function(){n++}),t("<tr>").addClass(this.noDataRowClass).append(t("<td>").addClass(this.cellClass).attr("colspan",n).append(this.renderTemplate(this.noDataContent,this)))},_createRow:function(n,i){var r;t.isFunction(this.rowRenderer)?r=this.renderTemplate(this.rowRenderer,this,{item:n,itemIndex:i}):(r=t("<tr>"),this._renderCells(r,n));r.addClass(this._getRowClasses(n,i)).data(f,n).on("click",t.proxy(function(t){this.rowClick({item:n,itemIndex:i,event:t});r.siblings().removeClass("grid-selected");r.addClass("grid-selected")},this)).on("dblclick",t.proxy(function(t){this.rowDoubleClick({item:n,itemIndex:i,event:t})},this)).on("mousedown",t.proxy(function(t){this.rowMouseDown({item:n,itemIndex:i,event:t})},this)).on("mouseup",t.proxy(function(t){this.rowMouseUp({item:n,itemIndex:i,event:t})},this)).on("mouseout",t.proxy(function(t){this.rowMouseUut({item:n,itemIndex:i,event:t})},this));return this.selecting&&this._attachRowHover(r),r},_getRowClasses:function(n,t){var i=[];return i.push((t+1)%2?this.oddRowClass:this.evenRowClass),i.push(u(this.rowClass,this,n,t)),i.join(" ")},_attachRowHover:function(n){var i=this.selectedRowClass;n.hover(function(){t(this).addClass(i)},function(){t(this).removeClass(i)})},_renderCells:function(n,t){return this._eachField(function(i){n.append(this._createCell(t,i))}),this},_createCell:function(n,i){var r,u=this._getItemFieldValue(n,i),f={value:u,item:n};return r=t.isFunction(i.cellRenderer)?this.renderTemplate(i.cellRenderer,i,f):t("<td>").append(this.renderTemplate(i.itemTemplate||u,i,f)),this._prepareCell(r,i)},_getItemFieldValue:function(n,t){for(var r=t.name.split("."),i=n[r.shift()];i&&r.length;)i=i[r.shift()];return i},_setItemFieldValue:function(n,t,i){for(var r=t.name.split("."),f=n,u=r[0];f&&r.length;)n=f,u=r.shift(),f=n[u];if(!f)while(r.length)n=n[u]={},u=r.shift();n[u]=i},sort:function(n,i){return t.isPlainObject(n)&&(i=n.order,n=n.field),this._clearSortingCss(),this._setSortingParams(n,i),this._setSortingCss(),this._loadStrategy.sort()},_clearSortingCss:function(){this._headerRow.find("th").removeClass(this.sortAscClass).removeClass(this.sortDescClass)},_setSortingParams:function(n,t){n=this._normalizeField(n);t=t||(this._sortField===n?this._reversedSortOrder(this._sortOrder):r);this._sortField=n;this._sortOrder=t},_normalizeField:function(n){return t.isNumeric(n)?this.fields[n]:typeof n=="string"?t.grep(this.fields,function(t){return t.name===n})[0]:n},_reversedSortOrder:function(n){return n===r?v:r},_setSortingCss:function(){var n=this._visibleFieldIndex(this._sortField);this._headerRow.find("th").eq(n).addClass(this._sortOrder===r?this.sortAscClass:this.sortDescClass)},_visibleFieldIndex:function(n){return t.inArray(n,t.grep(this.fields,function(n){return n.visible}))},_sortData:function(){var t=this._sortFactor(),n=this._sortField;n&&this.data.sort(function(i,r){return t*n.sortingFunc(i[n.name],r[n.name])})},_sortFactor:function(){return this._sortOrder===r?1:-1},_itemsCount:function(){return this._loadStrategy.itemsCount()},_pagesCount:function(){var n=this._itemsCount(),t=this.pageSize;return Math.floor(n/t)+(n%t?1:0)},_refreshPager:function(){var n=this._pagerContainer,t;n.empty();this.paging&&n.append(this._createPager());t=this.paging&&this._pagesCount()>1;t||n.find("#PerPageNum").val("");n.toggle(t);refreshLang()},_createPager:function(){var n;return n=t.isFunction(this.pagerRenderer)?t(this.pagerRenderer({pageIndex:this.pageIndex,pageCount:this._pagesCount()})):t("<div>").append(this._createPagerByFormat()).append(['&nbsp;&nbsp;&nbsp;&nbsp;<span data-i18n="common.PerPage"><\/span>',t("<input/>",{id:"PerPageNum","class":"form-control w50",value:this.pageSize,keyup:function(){for(var t=this.value,i="",n=0;n<t.length;n++)isNaN(t[n])||(i+=t[n]);this.value=i}}),'<span data-i18n="common.Pen"><\/span>']),n.addClass(this.pagerClass),n},_createPagerByFormat:function(){var n=this.pageIndex,i=this._pagesCount(),r=this._itemsCount(),u=this.pagerFormat.split(" ");return t.map(u,t.proxy(function(u){var f=u;return u===p?f=this._createPages():u===y?f=this._createPagerNavButton(this.pageFirstText,1,n>1):u===w?f=this._createPagerNavButton(this.pagePrevText,n-1,n>1):u===b?f=this._createPagerNavButton(this.pageNextText,n+1,n<i):u===k?f=this._createPagerNavButton(this.pageLastText,i,n<i):u===d?f=n:u===g?f=i:u===nt?f=r:u==="{Total}"?f='<span data-i18n="common.Total"><\/span>':u==="{Pen}"?f='<span data-i18n="common.Pen"><\/span>':u==="{Numth}"?f='<span data-i18n="common.Numth"><\/span>':u==="{Page}"&&(f='<span data-i18n="common.Page"><\/span>'),t.isArray(f)?f.concat([" "]):[f," "]},this))},_createPages:function(){var u=this._pagesCount(),f=this.pageButtonCount,i=this._firstDisplayingPage,t=[],r,n;for(i>1&&t.push(this._createPagerPageNavButton(this.pageNavigatorPrevText,this.showPrevPages)),r=0,n=i;r<f&&n<=u;r++,n++)t.push(n===this.pageIndex?this._createPagerCurrentPage():this._createPagerPage(n));return i+f-1<u&&t.push(this._createPagerPageNavButton(this.pageNavigatorNextText,this.showNextPages)),t},_createPagerNavButton:function(n,i,r){return this._createPagerButton(n,this.pagerNavButtonClass+(r?"":" "+this.pagerNavButtonInactiveClass),r?function(){this.openPage(i)}:t.noop)},_createPagerPageNavButton:function(n,t){return this._createPagerButton(n,this.pagerNavButtonClass,t)},_createPagerPage:function(n){return this._createPagerButton(n,this.pageClass,function(){this.openPage(n)})},_createPagerButton:function(n,i,r){var u=t("<a>").attr("href",tt).html(n).on("click",t.proxy(r,this));return t("<span>").addClass(i).append(u)},_createPagerCurrentPage:function(){return t("<span>").addClass(this.pageClass).addClass(this.currentPageClass).text(this.pageIndex)},_refreshSize:function(){this._refreshHeight();this._refreshWidth()},_refreshWidth:function(){var n=this.width==="auto"?this._getAutoWidth():this.width;this._container.width(n)},_getAutoWidth:function(){var n=this._headerGrid,t=this._header,i,r;return n.width("auto"),i=n.outerWidth(),r=t.outerWidth()-t.innerWidth(),n.width(""),i+r},_scrollBarWidth:function(){var n;return function(){var r,u,f,e;return n===i&&(r=t("<div style='width:50px;height:50px;overflow:hidden;position:absolute;top:-10000px;left:-10000px;'><\/div>"),u=t("<div style='height:100px;'><\/div>"),r.append(u).appendTo("body"),f=u.innerWidth(),r.css("overflow-y","auto"),e=u.innerWidth(),r.remove(),n=f-e),n}}(),_refreshHeight:function(){var i=this._container,r=this._pagerContainer,n=this.height,t;i.height(n);n!=="auto"&&(n=i.height(),t=this._header.outerHeight(!0),r.parents(i).length&&(t+=r.outerHeight(!0)),this._body.outerHeight(n-(t===0?90:t)))},showPrevPages:function(){var n=this._firstDisplayingPage,t=this.pageButtonCount;this._firstDisplayingPage=n>t?n-t:1;this._refreshPager()},showNextPages:function(){var t=this._firstDisplayingPage,n=this.pageButtonCount,i=this._pagesCount();this._firstDisplayingPage=t+2*n>i?i-n+1:t+n;this._refreshPager()},openPage:function(n){this._setPage(n);this._loadStrategy.openPage(n)},_setPage:function(n){var t=this._firstDisplayingPage,i=this.pageButtonCount;this.pageIndex=n;n<t&&(this._firstDisplayingPage=n);n>t+i-1&&(this._firstDisplayingPage=n-i+1);this._callEventHandler(this.onPageChanged,{pageIndex:n})},_controllerCall:function(n,i,r,u){if(r)return t.Deferred().reject().promise();this._showLoading();var f=this._controller;if(!f||!f[n])throw Error("controller has no method '"+n+"'");return it(f[n](i)).done(t.proxy(u,this)).fail(t.proxy(this._errorHandler,this)).always(t.proxy(this._hideLoading,this))},_errorHandler:function(){this._callEventHandler(this.onError,{args:t.makeArray(arguments)})},_showLoading:function(){this.loadIndication&&(clearTimeout(this._loadingTimer),this._loadingTimer=setTimeout(t.proxy(function(){this._loadIndicator.show()},this),this.loadIndicationDelay))},_hideLoading:function(){this.loadIndication&&(clearTimeout(this._loadingTimer),this._loadIndicator.hide())},search:function(n){return this._resetSorting(),this._resetPager(),this.loadData(n)},loadData:function(n){n=n||(this.filtering?this.getFilter():{});t.extend(n,this._loadStrategy.loadParams(),this._sortingParams());var r=this._callEventHandler(this.onDataLoading,{filter:n});return this._controllerCall("loadData",n,r.cancel,function(n){if(n){var r={},u={};if(n.itemsCount>=0)u=n;else{if(n[0]&&(n=n[0]),n.RESULT!==i&&!n.RESULT||n.d!==i&&!n.d)return;n.RESULT!==i?(r=n.DATA.rel,t.isArray(r)&&(r={DataList:r,Total:r.length})):r=JSON.parse(n.d);u={data:r.DataList,itemsCount:r.Total}}this._loadStrategy.finishLoad(u);this._callEventHandler(this.onDataLoaded,{data:u})}})},getFilter:function(){var n={};return this._eachField(function(t){t.filtering&&this._setItemFieldValue(n,t,t.filterValue())}),n},_sortingParams:function(){return this.sorting&&this._sortField?{sortField:this._sortField.name,sortOrder:this._sortOrder}:{}},getSorting:function(){var n=this._sortingParams();return{field:n.sortField,order:n.sortOrder}},clearFilter:function(){var n=this._createFilterRow();return this._filterRow.replaceWith(n),this._filterRow=n,this.search()},insertItem:function(n){var i=n||this._getValidatedInsertItem(),r;return i?(r=this._callEventHandler(this.onItemInserting,{item:i}),this._controllerCall("insertItem",i,r.cancel,function(n){n=n||i;this._loadStrategy.finishInsert(n);this._callEventHandler(this.onItemInserted,{item:n})})):t.Deferred().reject().promise()},_getValidatedInsertItem:function(){var n=this._getInsertItem();return this._validateItem(n,this._insertRow)?n:null},_getInsertItem:function(){var n={};return this._eachField(function(t){t.inserting&&this._setItemFieldValue(n,t,t.insertValue())}),n},_validateItem:function(n,i){var r=[],f={item:n,itemIndex:this._rowIndex(i),row:i},u;return(this._eachField(function(u){if(u.validate&&(i!==this._insertRow||u.inserting)&&(i!==this._getEditRow()||u.editing)){var o=this._getItemFieldValue(n,u),e=this._validation.validate(t.extend({value:o,rules:u.validate},f));(this._setCellValidity(i.children().eq(this._visibleFieldIndex(u)),e),e.length)&&r.push.apply(r,t.map(e,function(n){return{field:u,message:n}}))}}),!r.length)?!0:(u=t.extend({errors:r},f),this._callEventHandler(this.onItemInvalid,u),this.invalidNotify(u),!1)},_setCellValidity:function(n,t){n.toggleClass(this.invalidClass,!!t.length).attr("title",t.join("\n"))},clearInsert:function(){var n=this._createInsertRow();this._insertRow.replaceWith(n);this._insertRow=n;this.refresh()},editItem:function(n){var t=this.rowByItem(n);t.length&&this._editRow(t)},rowByItem:function(n){return n.jquery||n.nodeType?t(n):this._content.find("tr").filter(function(){return t.data(this,f)===n})},_editRow:function(n){var t,r,i;this.editing&&((t=n.data(f),r=this._callEventHandler(this.onItemEditing,{row:n,item:t,itemIndex:this._itemIndex(t)}),r.cancel)||(this._editingRow&&this.cancelEdit(),i=this._createEditRow(t),this._editingRow=n,n.hide(),i.insertBefore(n),n.data(s,i)))},_createEditRow:function(n){if(t.isFunction(this.editRowRenderer))return t(this.renderTemplate(this.editRowRenderer,this,{item:n,itemIndex:this._itemIndex(n)}));var i=t("<tr>").addClass(this.editRowClass);return this._eachField(function(t){var r=this._getItemFieldValue(n,t);this._prepareCell("<td>",t,"editcss").append(this.renderTemplate(t.editTemplate||"",t,{value:r,item:n})).appendTo(i)}),i},updateItem:function(n,t){arguments.length===1&&(t=n);var i=n?this.rowByItem(n):this._editingRow;if(t=t||this._getValidatedEditedItem(),t)return this._updateRow(i,t)},_getValidatedEditedItem:function(){var n=this._getEditedItem();return this._validateItem(n,this._getEditRow())?n:null},_updateRow:function(n,r){var u=n.data(f),o=this._itemIndex(u),e=t.extend(!0,{},u,r),s=this._callEventHandler(this.onItemUpdating,{row:n,item:e,itemIndex:o,previousItem:u});return this._controllerCall("updateItem",e,s.cancel,function(f){var h=!f||typeof f.DATA.rel!="object"?i:f.DATA.rel,c=t.extend(!0,{},u),s;e=h||t.extend(!0,u,r);s=this._finishUpdate(n,e,o);this._callEventHandler(this.onItemUpdated,{row:s,item:e,itemIndex:o,previousItem:c})})},_rowIndex:function(n){return this._content.children().index(t(n))},_itemIndex:function(n){return t.inArray(n,this.data)},_finishUpdate:function(n,t,i){this.cancelEdit();this.data[i]=t;var r=this._createRow(t,i);return n.replaceWith(r),r},_getEditedItem:function(){var n={};return this._eachField(function(t){t.editing&&this._setItemFieldValue(n,t,t.editValue())}),n},cancelEdit:function(){this._editingRow&&(this._getEditRow().remove(),this._editingRow.show(),this._editingRow=null)},_getEditRow:function(){return this._editingRow&&this._editingRow.data(s)},deleteItem:function(n){var t=this.rowByItem(n),i=this;t.length&&this.confirmDeleting&&layer.confirm(u(this.deleteConfirm,this,t.data(f)),{icon:3,title:i18next.t("common.Tips")},function(n){return layer.close(n),i._deleteRow(t)})},_deleteRow:function(n){var t=n.data(f),i=this._itemIndex(t),r=this._callEventHandler(this.onItemDeleting,{row:n,item:t,itemIndex:i});return this._controllerCall("deleteItem",t,r.cancel,function(){this._loadStrategy.finishDelete(t,i);this._callEventHandler(this.onItemDeleted,{row:n,item:t,itemIndex:i})})}};t.fn.jsGrid=function(n){var u=t.makeArray(arguments),f=u.slice(1),r=this;return this.each(function(){var h=t(this),u=h.data(o),s;if(u)if(typeof n=="string"){if(s=u[n].apply(u,f),s!==i&&s!==u)return r=s,!1}else u._detachWindowResizeCallback(),u._init(n),u.render();else new e(h,n)}),r};var c={},rt=function(n){var i;t.isPlainObject(n)?i=e.prototype:(i=c[n].prototype,n=arguments[1]||{});t.extend(i,n)},l={},ut=function(n){var i=t.isPlainObject(n)?n:l[n];if(!i)throw Error("unknown locale "+n);a(jsGrid,i)},a=function(n,i){t.each(i,function(i,r){if(t.isPlainObject(r)){a(n[i]||n[i[0].toUpperCase()+i.slice(1)],r);return}n.hasOwnProperty(i)?n[i]=r:n.prototype[i]=r})};n.jsGrid={Grid:e,fields:c,setDefaults:rt,locales:l,locale:ut,version:"1.5.3"}})(window,jQuery),function(n,t){function i(n){this._init(n)}i.prototype={container:"body",message:"Loading...",shading:!0,zIndex:1e3,shaderClass:"jsgrid-load-shader",loadPanelClass:"jsgrid-load-panel",_init:function(n){t.extend(!0,this,n);this._initContainer();this._initShader();this._initLoadPanel()},_initContainer:function(){this._container=t(this.container)},_initShader:function(){this.shading&&(this._shader=t("<div>").addClass(this.shaderClass).hide().css({position:"absolute",top:0,right:0,bottom:0,left:0,zIndex:this.zIndex}).appendTo(this._container))},_initLoadPanel:function(){this._loadPanel=t("<div>").addClass(this.loadPanelClass).text(this.message).hide().css({position:"absolute",top:"50%",left:"50%",zIndex:this.zIndex}).appendTo(this._container)},show:function(){var n=this._loadPanel.show(),t=n.outerWidth(),i=n.outerHeight();n.css({marginTop:-i/2,marginLeft:-t/2});this._shader.show()},hide:function(){this._loadPanel.hide();this._shader.hide()}};n.LoadIndicator=i}(jsGrid,jQuery),function(n,t){function i(n){this._grid=n}function r(n){this._grid=n;this._itemsCount=0}i.prototype={firstDisplayIndex:function(){var n=this._grid;return n.option("paging")?(n.option("pageIndex")-1)*n.option("pageSize"):0},lastDisplayIndex:function(){var n=this._grid,t=n.option("total").length;return n.option("paging")?Math.min(n.option("pageIndex")*n.option("pageSize"),t):t},itemsCount:function(){return this._grid.option("total").length},openPage:function(){this._grid.refresh()},loadParams:function(){return{}},sort:function(){return this._grid._sortData(),this._grid.refresh(),t.Deferred().resolve().promise()},reset:function(){return this._grid.refresh(),t.Deferred().resolve().promise()},finishLoad:function(n){this._grid.option("data",n)},finishInsert:function(n){var t=this._grid;t.option("data").push(n);t.refresh()},finishDelete:function(n,t){var i=this._grid;i.option("data").splice(t,1);i.reset()}};r.prototype={firstDisplayIndex:function(){return 0},lastDisplayIndex:function(){return this._grid.option("data").length},itemsCount:function(){return this._itemsCount},openPage:function(){this._grid.loadData()},loadParams:function(){var n=this._grid;return{pageIndex:n.option("pageIndex"),pageSize:n.option("pageSize")}},reset:function(){return this._grid.loadData()},sort:function(){return this._grid.loadData()},finishLoad:function(n){this._itemsCount=n.itemsCount;this._grid.option("data",n.data)},finishInsert:function(){this._grid.search()},finishDelete:function(){this._grid.search()}};n.loadStrategies={DirectLoadingStrategy:i,PageLoadingStrategy:r}}(jsGrid,jQuery),function(n){var t=function(n){return typeof n!="undefined"&&n!==null},i={string:function(n,i){return!t(n)&&!t(i)?0:t(n)?t(i)?(""+n).localeCompare(""+i):1:-1},number:function(n,t){return n-t},date:function(n,t){return n-t},numberAsString:function(n,t){return parseFloat(n)-parseFloat(t)}};n.sortStrategies=i}(jsGrid,jQuery),function(n,t,i){function r(n){this._init(n)}r.prototype={_init:function(n){t.extend(!0,this,n)},validate:function(n){var i=[];return t.each(this._normalizeRules(n.rules),function(r,u){if(!u.validator(n.value,n.item,u.param)){var f=t.isFunction(u.message)?u.message(n.value,n.item):u.message;i.push(f)}}),i},_normalizeRules:function(n){return t.isArray(n)||(n=[n]),t.map(n,t.proxy(function(n){return this._normalizeRule(n)},this))},_normalizeRule:function(n){if(typeof n=="string"&&(n={validator:n}),t.isFunction(n)&&(n={validator:n}),t.isPlainObject(n))n=t.extend({},n);else throw Error("wrong validation config specified");return t.isFunction(n.validator)?n:this._applyNamedValidator(n,n.validator)},_applyNamedValidator:function(n,i){delete n.validator;var r=u[i];if(!r)throw Error('unknown validator "'+i+'"');return t.isFunction(r)&&(r={validator:r}),t.extend({},r,n)}};n.Validation=r;var u={required:{message:"Field is required",validator:function(n){return n!==i&&n!==null&&n!==""}},rangeLength:{message:"Field value length is out of the defined range",validator:function(n,t,i){return n.length>=i[0]&&n.length<=i[1]}},minLength:{message:"Field value is too short",validator:function(n,t,i){return n.length>=i}},maxLength:{message:"Field value is too long",validator:function(n,t,i){return n.length<=i}},pattern:{message:"Field value is not matching the defined pattern",validator:function(n,t,i){return typeof i=="string"&&(i=new RegExp("^(?:"+i+")$")),i.test(n)}},range:{message:"Field value is out of the defined range",validator:function(n,t,i){return n>=i[0]&&n<=i[1]}},min:{message:"Field value is too small",validator:function(n,t,i){return n>=i}},max:{message:"Field value is too large",validator:function(n,t,i){return n<=i}}};n.validators=u}(jsGrid,jQuery),function(n,t,i){function r(n){t.extend(!0,this,n);this.sortingFunc=this._getSortingFunc()}r.prototype={name:"",title:null,css:"",align:"",width:100,visible:!0,filtering:!0,inserting:!0,editing:!0,sorting:!0,sorter:"string",headerTemplate:function(){return this.title===i||this.title===null?this.name:this.title},itemTemplate:function(n){return n},filterTemplate:function(){return""},insertTemplate:function(){return""},editTemplate:function(n,t){return this._value=n,this.itemTemplate(n,t)},filterValue:function(){return""},insertValue:function(){return""},editValue:function(){return this._value},_getSortingFunc:function(){var i=this.sorter;if(t.isFunction(i))return i;if(typeof i=="string")return n.sortStrategies[i];throw Error('wrong sorter for the field "'+this.name+'"!');}};n.Field=r}(jsGrid,jQuery),function(n,t){function r(n){i.call(this,n)}var i=n.Field;r.prototype=new i({autosearch:!0,readOnly:!1,filterTemplate:function(){if(!this.filtering)return"";var t=this._grid,n=this.filterControl=this._createTextBox();if(this.autosearch)n.on("keypress",function(n){n.which===13&&(t.search(),n.preventDefault())});return n},insertTemplate:function(){return this.inserting?this.insertControl=this._createTextBox():""},editTemplate:function(n){if(!this.editing)return this.itemTemplate.apply(this,arguments);var t=this.editControl=this._createTextBox();return t.val(n),t},filterValue:function(){return this.filterControl.val()},insertValue:function(){return this.insertControl.val()},editValue:function(){return this.editControl.val()},_createTextBox:function(){return t("<input>").attr("type","text").attr("class","form-control w100p").prop("readonly",!!this.readOnly)}});n.fields.text=n.TextField=r}(jsGrid,jQuery),function(n,t,i){function u(n){r.call(this,n)}var r=n.TextField;u.prototype=new r({sorter:"number",align:"right",readOnly:!1,filterValue:function(){return this.filterControl.val()?parseInt(this.filterControl.val()||0,10):i},insertValue:function(){return this.insertControl.val()?parseInt(this.insertControl.val()||0,10):i},editValue:function(){return this.editControl.val()?parseInt(this.editControl.val()||0,10):i},_createTextBox:function(){return t("<input>").attr("type","number").attr("class","form-control w100p").prop("readonly",!!this.readOnly)}});n.fields.number=n.NumberField=u}(jsGrid,jQuery),function(n,t){function r(n){i.call(this,n)}var i=n.TextField;r.prototype=new i({insertTemplate:function(){return this.inserting?this.insertControl=this._createTextArea():""},editTemplate:function(n){if(!this.editing)return this.itemTemplate.apply(this,arguments);var t=this.editControl=this._createTextArea();return t.val(n),t},_createTextArea:function(){return t("<textarea>").prop("readonly",!!this.readOnly)}});n.fields.textarea=n.TextAreaField=r}(jsGrid,jQuery),function(n,t,i){function f(n){if(this.items=[],this.selectedIndex=-1,this.valueField="",this.textField="",n.valueField&&n.items.length){var t=n.items[0][n.valueField];this.valueType=typeof t===r?r:e}this.sorter=this.valueType;u.call(this,n)}var u=n.NumberField,r="number",e="string";f.prototype=new u({align:"center",valueType:r,itemTemplate:function(n){var f=this.items,e=this.valueField,o=this.textField,u,r;return u=e?t.grep(f,function(t){return t[e]===n})[0]||{}:f[n],r=o?u[o]:u,r===i||r===null?"":r},filterTemplate:function(){if(!this.filtering)return"";var t=this._grid,n=this.filterControl=this._createSelect();if(this.autosearch)n.on("change",function(){t.search()});return n},insertTemplate:function(){return this.inserting?this.insertControl=this._createSelect():""},editTemplate:function(n){if(!this.editing)return this.itemTemplate.apply(this,arguments);var t=this.editControl=this._createSelect();return n!==i&&t.val(n),t},filterValue:function(){var n=this.filterControl.val();return this.valueType===r?parseInt(n||0,10):n},insertValue:function(){var n=this.insertControl.val();return this.valueType===r?parseInt(n||0,10):n},editValue:function(){var n=this.editControl.val();return this.valueType===r?parseInt(n||0,10):n},_createSelect:function(){var n=t("<select>"),i=this.valueField,r=this.textField,u=this.selectedIndex;return t.each(this.items,function(f,e){var o=i?e[i]:f,s=r?e[r]:e,h=t("<option>").attr("value",o).text(s).appendTo(n);h.prop("selected",u===f)}),n.prop("disabled",!!this.readOnly),n}});n.fields.select=n.SelectField=f}(jsGrid,jQuery),function(n,t,i){function u(n){r.call(this,n)}var r=n.Field;u.prototype=new r({sorter:"number",align:"center",autosearch:!0,itemTemplate:function(n){return this._createCheckbox().prop({checked:n,disabled:!0})},filterTemplate:function(){if(!this.filtering)return"";var i=this._grid,n=this.filterControl=this._createCheckbox();n.prop({readOnly:!0,indeterminate:!0});n.on("click",function(){var n=t(this);n.prop("readOnly")?n.prop({checked:!1,readOnly:!1}):n.prop("checked")||n.prop({readOnly:!0,indeterminate:!0})});if(this.autosearch)n.on("click",function(){i.search()});return n},insertTemplate:function(){return this.inserting?this.insertControl=this._createCheckbox():""},editTemplate:function(n){if(!this.editing)return this.itemTemplate.apply(this,arguments);var t=this.editControl=this._createCheckbox();return t.prop("checked",n),t},filterValue:function(){return this.filterControl.get(0).indeterminate?i:this.filterControl.is(":checked")},insertValue:function(){return this.insertControl.is(":checked")},editValue:function(){return this.editControl.is(":checked")},_createCheckbox:function(){return t("<input>").attr("type","checkbox")}});n.fields.checkbox=n.CheckboxField=u}(jsGrid,jQuery),function(n,t){function r(n){i.call(this,n);this._configInitialized=!1}var i=n.Field;r.prototype=new i({css:"jsgrid-control-field",align:"center",width:50,filtering:!1,inserting:!1,editing:!1,sorting:!1,buttonClass:"jsgrid-button",modeButtonClass:"jsgrid-mode-button",modeOnButtonClass:"jsgrid-mode-on-button",searchModeButtonClass:"jsgrid-search-mode-button",insertModeButtonClass:"jsgrid-insert-mode-button",editButtonClass:"jsgrid-edit-button",deleteButtonClass:"jsgrid-delete-button",searchButtonClass:"jsgrid-search-button",clearFilterButtonClass:"jsgrid-clear-filter-button",insertButtonClass:"jsgrid-insert-button",updateButtonClass:"jsgrid-update-button",cancelEditButtonClass:"jsgrid-cancel-edit-button",searchModeButtonTooltip:"Switch to searching",insertModeButtonTooltip:"Switch to inserting",editButtonTooltip:"Edit",deleteButtonTooltip:"Delete",searchButtonTooltip:"Search",clearFilterButtonTooltip:"Clear filter",insertButtonTooltip:"Insert",updateButtonTooltip:"Update",cancelEditButtonTooltip:"Cancel edit",editButton:!0,deleteButton:!0,clearFilterButton:!0,modeSwitchButton:!0,_initConfig:function(){this._hasFiltering=this._grid.filtering;this._hasInserting=this._grid.inserting;this._hasInserting&&this.modeSwitchButton&&(this._grid.inserting=!1);this._configInitialized=!0},headerTemplate:function(){this._configInitialized||this._initConfig();var n=this._hasFiltering,t=this._hasInserting;return!this.modeSwitchButton||!n&&!t?"":n&&!t?this._createFilterSwitchButton():t&&!n?this._createInsertSwitchButton():this._createModeSwitchButton()},itemTemplate:function(n,i){var r=t([]);return this.editButton&&(r=r.add(this._createEditButton(i))),this.deleteButton&&(r=r.add(this._createDeleteButton(i))),r},filterTemplate:function(){var n=this._createSearchButton();return this.clearFilterButton?n.add(this._createClearFilterButton()):n},insertTemplate:function(){return this._createInsertButton()},editTemplate:function(){return this._createUpdateButton().add(this._createCancelEditButton())},_createFilterSwitchButton:function(){return this._createOnOffSwitchButton("filtering",this.searchModeButtonClass,!0)},_createInsertSwitchButton:function(){return this._createOnOffSwitchButton("inserting",this.insertModeButtonClass,!1)},_createOnOffSwitchButton:function(n,i,r){var u=r,f=t.proxy(function(){e.toggleClass(this.modeOnButtonClass,u)},this),e=this._createGridButton(this.modeButtonClass+" "+i,"",function(t){u=!u;t.option(n,u);f()});return f(),e},_createModeSwitchButton:function(){var n=!1,i=t.proxy(function(){r.attr("title",n?this.searchModeButtonTooltip:this.insertModeButtonTooltip).toggleClass(this.insertModeButtonClass,!n).toggleClass(this.searchModeButtonClass,n)},this),r=this._createGridButton(this.modeButtonClass,"",function(t){n=!n;t.option("inserting",n);t.option("filtering",!n);i()});return i(),r},_createEditButton:function(n){return this._createGridButton(this.editButtonClass,this.editButtonTooltip,function(t,i){t.editItem(n);i.stopPropagation()})},_createDeleteButton:function(n){return this._createGridButton(this.deleteButtonClass,this.deleteButtonTooltip,function(t,i){t.deleteItem(n);i.stopPropagation()})},_createSearchButton:function(){return this._createGridButton(this.searchButtonClass,this.searchButtonTooltip,function(n){n.search()})},_createClearFilterButton:function(){return this._createGridButton(this.clearFilterButtonClass,this.clearFilterButtonTooltip,function(n){n.clearFilter()})},_createInsertButton:function(){return this._createGridButton(this.insertButtonClass,this.insertButtonTooltip,function(n){n.insertItem().done(function(){n.clearInsert()})})},_createUpdateButton:function(){return this._createGridButton(this.updateButtonClass,this.updateButtonTooltip,function(n,t){n.updateItem();t.stopPropagation()})},_createCancelEditButton:function(){return this._createGridButton(this.cancelEditButtonClass,this.cancelEditButtonTooltip,function(n,t){n.cancelEdit();t.stopPropagation()})},_createGridButton:function(n,i,r){var u=this._grid;return t("<input>").addClass(this.buttonClass).addClass(n).attr({type:"button",title:i}).on("click",function(n){r(u,n)})},editValue:function(){return""}});n.fields.control=n.ControlField=r}(jsGrid,jQuery);