window.pageGrids=window.pageGrids||{};$.fn.extend({gridmvc:function(){var n=[];return $(this).each(function(){if($(this).data("gridmvc"))n.push($(this).data("gridmvc"));else{var t={lang:$(this).attr("data-lang"),selectable:"true"==$(this).attr("data-selectable"),multiplefilters:"true"==$(this).attr("data-multiplefilters")},t=new GridMvc(this,t);0<$(this).attr("data-gridname").length&&(window.pageGrids[$(this).attr("data-gridname")]=t);n.push(t);$(this).data("gridmvc",t)}}),1==n.length?n[0]:n}});GridMvc=function(n){function t(t,i){this.jqContainer=n(t);i=i||{};this.options=n.extend({},this.defaults(),i);this.init()}return t.prototype.init=function(){this.lang=GridMvc.lang[this.options.lang];"undefined"==typeof this.lang&&(this.lang=GridMvc.lang.en);this.events=[];this.options.selectable&&this.initGridRowsEvents();this.filterWidgets=[];this.addFilterWidget(new TextFilterWidget);this.addFilterWidget(new NumberFilterWidget);this.addFilterWidget(new DateTimeFilterWidget);this.addFilterWidget(new BooleanFilterWidget);this.openedMenuBtn=null;this.initFilters()},t.prototype.initGridRowsEvents=function(){var n=this;this.jqContainer.on("click",".grid-row",function(){n.rowClicked.call(this,n)});this.jqContainer.on("dblclick",".grid-row",function(){n.rowDblClicked.call(this,n)})},t.prototype.rowDblClicked=function(t){var i,r;t.options.selectable&&(i=n(this).closest(".grid-row"),0>=i.length||(r={},i.find(".grid-cell").each(function(){var t=n(this).attr("data-name");0<t.length&&(r[t]=n(this).text())}),t.markRowSelected(i),i=n.Event("RowDblClicked"),t.notifyOnRowEnter(r,i)))},t.prototype.rowClicked=function(t){var i,r,u;t.options.selectable&&(i=n(this).closest(".grid-row"),0>=i.length||(r={},i.find(".grid-cell").each(function(){var t=n(this).attr("data-name");0<t.length&&(r[t]=n(this).text())}),u=n.Event("RowClicked"),t.notifyOnRowSelect(r,u),u.isDefaultPrevented()||t.markRowSelected(i)))},t.prototype.markRowSelected=function(n){this.jqContainer.find(".grid-row.grid-row-selected").removeClass("grid-row-selected");n.addClass("grid-row-selected")},t.prototype.defaults=function(){return{selectable:!0,multiplefilters:!1,lang:"en"}},t.prototype.onRowSelect=function(n){this.events.push({name:"onRowSelect",callback:n})},t.prototype.notifyOnRowSelect=function(n,t){t.row=n;this.notifyEvent("onRowSelect",t)},t.prototype.onRowEnter=function(n){this.events.push({name:"onRowEnter",callback:n})},t.prototype.notifyOnRowEnter=function(n,t){t.row=n;this.notifyEvent("onRowEnter",t)},t.prototype.notifyEvent=function(n,t){for(var i=0;i<this.events.length&&(this.events[i].name!=n||this.events[i].callback(t));i++);},t.prototype.initFilters=function(){var i=this.filterMenuHtml(),t=this;this.jqContainer.find(".grid-filter").each(function(){n(this).click(function(){return t.openFilterPopup.call(this,t,i)})})},t.prototype.openFilterPopup=function(t,i){var r=n(this).attr("data-type")||"",u=t.getFilterWidgetForType(r),s;if(null==u)return!1;if(this.hasAttribute("data-rendered"))return r=t.openMenuOnClick.call(this,t),t.setupPopupInitialPosition(n(this)),r||"undefined"==typeof u.onShow||u.onShow(),r;var o=n(this).attr("data-name")||"",f=n(this).attr("data-filterdata")||"",h=n(this).attr("data-widgetdata")||"{}",f=t.parseFilterValues(f)||{},e=n(this).attr("data-url")||"";if(n(this).attr("data-rendered","1"),n(this).append(i),s=n(this).find(".grid-popup-widget"),"undefined"!=typeof u.onRender)u.onRender(s,t.lang,r,f,function(n){t.closeOpenedPopups();t.applyFilterValues(e,o,n,!1)},n.parseJSON(h));return n(this).find(".grid-filter-btn").hasClass("filtered")&&u.showClearFilterButton()&&(r=n(this).find(".grid-popup-additional"),r.append(t.getClearFilterButton(e)),r.find(".grid-filter-clear").click(function(){t.applyFilterValues(e,o,"",!0)})),r=t.openMenuOnClick.call(this,t),"undefined"!=typeof u.onShow&&u.onShow(),t.setupPopupInitialPosition(n(this)),r},t.prototype.setupPopupInitialPosition=function(t){function f(){var n=t.find(".grid-dropdown-arrow");return{arrow:n,currentDropLeft:parseInt(u.css("left")),currentArrowLeft:parseInt(n.css("left"))}}var u=t.find(".grid-dropdown"),r=u.offset().left,i;0>r?(i=f(),i.arrow.css({left:i.currentArrowLeft+r-10+"px"}),u.css({left:i.currentDropLeft-r+10+"px"})):(i=u.width(),r=n(window).width()-(r+i),0>r&&(i=f(),i.arrow.css({left:i.currentArrowLeft-r+10+"px"}),u.css({left:i.currentDropLeft+r-10+"px"})))},t.prototype.filterMenuHtml=function(){return'<div class="dropdown dropdown-menu grid-dropdown" style="display: none;"><div class="grid-dropdown-arrow"><\/div><div class="grid-dropdown-inner"><div class="grid-popup-widget"><\/div><div class="grid-popup-additional"><\/div><\/div><\/div>'},t.prototype.getClearFilterButton=function(){return'<ul class="menu-list"><li><a class="grid-filter-clear" href="javascript:void(0);">'+this.lang.clearFilterLabel+"<\/a><\/li><\/ul>"},t.prototype.addFilterWidget=function(n){this.filterWidgets.push(n)},t.prototype.parseFilterValues=function(t){t=n.parseJSON(t);for(var r=[],i=0;i<t.length;i++)r.push({filterValue:this.urldecode(t[i].FilterValue),filterType:t[i].FilterType,columnName:t[i].ColumnName});return r},t.prototype.urldecode=function(n){return decodeURIComponent((n+"").replace(/\+/g,"%20"))},t.prototype.getFilterWidgetForType=function(t){for(var i=0;i<this.filterWidgets.length;i++)if(0<=n.inArray(t,this.filterWidgets[i].getAssociatedTypes()))return this.filterWidgets[i];return null},t.prototype.replaceFilterWidget=function(t,i){for(var r=0;r<this.filterWidgets.length;r++)if(0<=n.inArray(t,this.filterWidgets[r].getAssociatedTypes()))return this.filterWidgets.splice(r,1),this.addFilterWidget(i),!0;return!1},t.prototype.applyFilterValues=function(t,i,r,u){var e=this.jqContainer.find(".grid-filter"),f;if(0<t.length&&(t+="&"),f="",u||(f+=this.getFilterQueryData(i,r)),this.options.multiplefilters)for(r=0;r<e.length;r++)n(e[r]).attr("data-name")!=i&&(u=this.parseFilterValues(n(e[r]).attr("data-filterdata")),0!=u.length&&(0<f.length&&(f+="&"),f+=this.getFilterQueryData(n(e[r]).attr("data-name"),u)));window.location.search=t+f},t.prototype.getFilterQueryData=function(n,t){for(var r="",i=0;i<t.length;i++)r+="grid-filter="+encodeURIComponent(n)+"__"+t[i].filterType+"__"+encodeURIComponent(t[i].filterValue),i!=t.length-1&&(r+="&");return r},t.prototype.openMenuOnClick=function(t){if(n(this).hasClass("clicked"))return!0;t.closeOpenedPopups();n(this).addClass("clicked");var i=n(this).find(".dropdown-menu");return 0==i.length?!0:(i.show(),i.addClass("opened"),t.openedMenuBtn=n(this),n(document).bind("click.gridmvc",function(n){t.documentCallback(n,t)}),!1)},t.prototype.documentCallback=function(t,i){t=t||event;var r=t.target||t.srcElement,u=n(".dropdown-menu.opened").get(0),f=n("html").get(0);if("undefined"!=typeof u)do{if(u==r)return;f==r&&(u.style.display="none",n(u).removeClass("opened"));r=r.parentNode}while(r);null!=i.openedMenuBtn&&i.openedMenuBtn.removeClass("clicked");n(document).unbind("click.gridmvc")},t.prototype.closeOpenedPopups=function(){var t=n(".dropdown-menu.opened");t.hide();t.removeClass("opened");null!=this.openedMenuBtn&&this.openedMenuBtn.removeClass("clicked")},t.prototype.selectable=function(n){this.options.selectable=n},t}(window.jQuery);"undefined"==typeof GridMvc.lang&&(GridMvc.lang={});GridMvc.lang.en={filterTypeLabel:"Type: ",filterValueLabel:"Value:",applyFilterButtonText:"Apply",filterSelectTypes:{Equals:"Equals",StartsWith:"StartsWith",Contains:"Contains",EndsWith:"EndsWith",GreaterThan:"Greater than",LessThan:"Less than"},code:"en",boolTrueLabel:"Yes",boolFalseLabel:"No",clearFilterLabel:"Clear filter"};TextFilterWidget=function(){function n(){}return n.prototype.getAssociatedTypes=function(){return["System.String"]},n.prototype.onShow=function(){var n=this.container.find(".grid-filter-input");0>=n.length||n.focus()},n.prototype.showClearFilterButton=function(){return!0},n.prototype.onRender=function(n,t,i,r,u){this.cb=u;this.container=n;this.lang=t;this.value=0<r.length?r[0]:{filterType:1,filterValue:""};this.renderWidget();this.registerEvents()},n.prototype.renderWidget=function(){this.container.append('<div class="form-group"><label>'+this.lang.filterTypeLabel+'<\/label><select class="grid-filter-type form-control"><option value="1" '+("1"==this.value.filterType?'selected="selected"':"")+">"+this.lang.filterSelectTypes.Equals+'<\/option><option value="2" '+("2"==this.value.filterType?'selected="selected"':"")+">"+this.lang.filterSelectTypes.Contains+'<\/option><option value="3" '+("3"==this.value.filterType?'selected="selected"':"")+">"+this.lang.filterSelectTypes.StartsWith+'<\/option><option value="4" '+("4"==this.value.filterType?'selected="selected"':"")+">"+this.lang.filterSelectTypes.EndsWith+'<\/option><\/select><\/div><div class="form-group"><label>'+this.lang.filterValueLabel+'<\/label><input type="text" class="grid-filter-input form-control" value="'+this.value.filterValue+'" /><\/div><div class="grid-filter-buttons"><button type="button" class="btn btn-primary grid-apply" >'+this.lang.applyFilterButtonText+"<\/button><\/div>")},n.prototype.registerEvents=function(){var t=this.container.find(".grid-apply"),n=this;t.click(function(){var t=n.container.find(".grid-filter-type").val(),i=n.container.find(".grid-filter-input").val();n.cb([{filterType:t,filterValue:i}])});this.container.find(".grid-filter-input").keyup(function(n){13==n.keyCode&&t.click();27==n.keyCode&&GridMvc.closeOpenedPopups()})},n}(window.jQuery);NumberFilterWidget=function(){function n(){}return n.prototype.showClearFilterButton=function(){return!0},n.prototype.getAssociatedTypes=function(){return"System.Int32 System.Double System.Decimal System.Byte System.Single System.Float System.Int64".split(" ")},n.prototype.onShow=function(){var n=this.container.find(".grid-filter-input");0>=n.length||n.focus()},n.prototype.onRender=function(n,t,i,r,u){this.cb=u;this.container=n;this.lang=t;this.typeName=i;this.value=0<r.length?r[0]:{filterType:1,filterValue:""};this.renderWidget();this.registerEvents()},n.prototype.renderWidget=function(){this.container.append('<div class="form-group"><label>'+this.lang.filterTypeLabel+'<\/label><select class="grid-filter-type form-control"><option value="1" '+("1"==this.value.filterType?'selected="selected"':"")+">"+this.lang.filterSelectTypes.Equals+'<\/option><option value="5" '+("5"==this.value.filterType?'selected="selected"':"")+">"+this.lang.filterSelectTypes.GreaterThan+'<\/option><option value="6" '+("6"==this.value.filterType?'selected="selected"':"")+">"+this.lang.filterSelectTypes.LessThan+'<\/option><\/select><\/div><div class="form-group"><label>'+this.lang.filterValueLabel+'<\/label><input type="text" class="grid-filter-input form-control" value="'+this.value.filterValue+'" /><\/div><div class="grid-filter-buttons"><button type="button" class="btn btn-primary grid-apply">'+this.lang.applyFilterButtonText+"<\/button><\/div>")},n.prototype.registerEvents=function(){var n=this,i=this.container.find(".grid-apply"),t;i.click(function(){var t=n.container.find(".grid-filter-type").val(),i=n.container.find(".grid-filter-input").val();n.cb([{filterType:t,filterValue:i}])});t=this.container.find(".grid-filter-input");t.keyup(function(n){13==n.keyCode&&i.click();27==n.keyCode&&GridMvc.closeOpenedPopups()}).keypress(function(t){return n.validateInput.call(n,t)});"System.Byte"==this.typeName&&t.attr("maxlength","3")},n.prototype.validateInput=function(n){n=n||window.event;var t=n.keyCode||n.which,t=String.fromCharCode(t),i;switch(this.typeName){case"System.Byte":case"System.Int32":case"System.Int64":i=/[0-9]/;break;default:i=/[0-9]|\.|\,/}i.test(t)||(n.returnValue=!1,n.preventDefault&&n.preventDefault())},n}(window.jQuery);DateTimeFilterWidget=function(n){function t(){}return t.prototype.getAssociatedTypes=function(){return["System.DateTime"]},t.prototype.showClearFilterButton=function(){return!0},t.prototype.onRender=function(t,i,r,u,f,e){this.datePickerIncluded="undefined"!=typeof n.fn.datepicker;this.cb=f;this.data=e;this.container=t;this.lang=i;this.value=0<u.length?u[0]:{filterType:1,filterValue:""};this.renderWidget();this.registerEvents()},t.prototype.renderWidget=function(){var n,t,i;if(this.container.append('<div class="form-group"><label>'+this.lang.filterTypeLabel+'<\/label><select class="grid-filter-type form-control"><option value="1" '+("1"==this.value.filterType?'selected="selected"':"")+">"+this.lang.filterSelectTypes.Equals+'<\/option><option value="5" '+("5"==this.value.filterType?'selected="selected"':"")+">"+this.lang.filterSelectTypes.GreaterThan+'<\/option><option value="6" '+("6"==this.value.filterType?'selected="selected"':"")+">"+this.lang.filterSelectTypes.LessThan+"<\/option><\/select><\/div>"+(this.datePickerIncluded?'<div class="grid-filter-datepicker"><\/div>':'<div class="form-group"><label>'+this.lang.filterValueLabel+'<\/label><input type="text" class="grid-filter-input form-control" value="'+this.value.filterValue+'" /><\/div><div class="grid-filter-buttons"><input type="button" class="btn btn-primary grid-apply" value="'+this.lang.applyFilterButtonText+'" /><\/div>')),this.datePickerIncluded){n=this.data||{};n.format=n.format||"yyyy-mm-dd";n.language=n.language||this.lang.code;t=this;i=this.container.find(".grid-filter-datepicker");i.datepicker(n).on("changeDate",function(n){n=[{filterType:t.container.find(".grid-filter-type").val(),filterValue:n.format()}];t.cb(n)});this.value.filterValue&&i.datepicker("update",this.value.filterValue)}},t.prototype.registerEvents=function(){var n=this,t=this.container.find(".grid-apply");t.click(function(){var t=n.container.find(".grid-filter-type").val(),i=n.container.find(".grid-filter-input").val();n.cb([{filterType:t,filterValue:i}])});this.container.find(".grid-filter-input").keyup(function(n){13==n.keyCode&&t.click()})},t}(window.jQuery);BooleanFilterWidget=function(n){function t(){}return t.prototype.getAssociatedTypes=function(){return["System.Boolean"]},t.prototype.showClearFilterButton=function(){return!0},t.prototype.onRender=function(n,t,i,r,u){this.cb=u;this.container=n;this.lang=t;this.value=0<r.length?r[0]:{filterType:1,filterValue:""};this.renderWidget();this.registerEvents()},t.prototype.renderWidget=function(){this.container.append("<label>"+this.lang.filterValueLabel+'<\/label><ul class="menu-list"><li><a class="grid-filter-choose '+("true"==this.value.filterValue?"choose-selected":"")+'" data-value="true" href="javascript:void(0);">'+this.lang.boolTrueLabel+'<\/a><\/li><li><a class="grid-filter-choose '+("false"==this.value.filterValue?"choose-selected":"")+'" data-value="false" href="javascript:void(0);">'+this.lang.boolFalseLabel+"<\/a><\/li><\/ul>")},t.prototype.registerEvents=function(){var t=this;this.container.find(".grid-filter-choose").click(function(){var i=[{filterType:"1",filterValue:n(this).attr("data-value")}];t.cb(i)})},t}(window.jQuery),function(n){n&&n(function(){n(".grid-mvc").each(function(){n(".grid-mvc").gridmvc()})})}(window.jQuery)