1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-30 23:42:33 +01:00
Sonarr/NzbDrone.Web/Scripts/2011.2.712/telerik.grid.editing.min.js
Mark McDowall 8d0cdf272c Moved away from CDNs for 3rd party scripts.
Added Telerik MVC Controls, JQuery, JQueryUI and YUI.
2011-09-07 19:48:37 -07:00

1 line
26 KiB
JavaScript

(function(i){var c=i.telerik,k=/^\/Date\((.*?)\)\/$/,g=/[0#?]/,l=/[npc?]/;c.scripts.push("telerik.grid.editing.js");var h=function(n){this.formId=n;this._isBuild=false;var p="tUnobtrusiveValidation";var o="tUnobtrusiveContainer";var m=this.unobtrusive={adapters:[],parseElement:function(q,t){var r=i(q),s=r.parents("form")[0],v,u,w;if(!s){return}v=m.validationInfo(s);v.options.rules[q.name]=u={};v.options.messages[q.name]=w={};i.each(this.adapters,function(){var x="data-val-"+this.name,y=r.attr(x),z={};if(y!==undefined){x+="-";i.each(this.params,function(){z[this]=r.attr(x+this)});this.adapt({element:q,form:s,message:y,params:z,rules:u,messages:w})}});if(!t){v.attachValidation()}},parse:function(q){i(q).find(":input[data-val=true]").each(function(){m.parseElement(this,true)});i(q).each(function(){var r=m.validationInfo(this);if(r){r.attachValidation()}})},onError:function(q,t){var s=i(this).find("[data-valmsg-for='"+t[0].name+"']"),r=i.parseJSON(s.attr("data-valmsg-replace"))!==false;s.removeClass("field-validation-valid").addClass("field-validation-error");q.data(o,s);if(r){s.empty();q.removeClass("input-validation-error").appendTo(s)}else{q.hide()}},onErrors:function(q,t){var s=i(this).find("[data-valmsg-summary=true]"),r=s.find("ul");if(r&&r.length&&t.errorList.length){r.empty();s.addClass("validation-summary-errors").removeClass("validation-summary-valid");i.each(t.errorList,function(){i("<li />").html(this.message).appendTo(r)})}},onSuccess:function(q){var s=q.data(o),r=i.parseJSON(s.attr("data-valmsg-replace"));if(s){s.addClass("field-valiion-valid").removeClass("field-validation-error");q.removeData(o);if(r){s.empty()}}},validationInfo:function(q){var s=i(q),r=s.data(p);if(!r){r={options:{errorClass:"input-validation-error",errorElement:"span",errorPlacement:i.proxy(m.onError,q),invalidHandler:i.proxy(m.onErrors,q),messages:{},rules:{},success:i.proxy(m.onSuccess,q)},attachValidation:function(){s.validate(this.options)},validate:function(){s.validate();return s.valid()}};s.data(p,r)}return r}}};h.prototype={build:function(){if(this._isBuild){return}this._isBuild=true;var q=[];function o(t,s,r){t.rules[s]=r;if(t.message){t.messages[s]=t.message}}function p(r){return r.replace(/^\s+|\s+$/g,"").split(/\s*,\s*/g)}function n(r){return r.substr(0,r.lastIndexOf(".")+1)}function m(s,r){if(s.indexOf("*.")===0){s=s.replace("*.",r)}return s}q=this.unobtrusive.adapters;q.add=function(t,s,r){if(!r){r=s;s=[]}this.push({name:t,params:s,adapt:r});return this};q.addBool=function(s,r){return this.add(s,function(t){o(t,r||s,true)})};q.addMinMax=function(u,s,w,r,t,v){return this.add(u,[t||"min",v||"max"],function(z){var x=z.params.min,y=z.params.max;if(x&&y){o(z,r,[x,y])}else{if(x){o(z,s,x)}else{if(y){o(z,w,y)}}}})};q.addSingleVal=function(s,t,r){return this.add(s,[t||"val"],function(u){o(u,r||s,u.params[t])})};q.addSingleVal("accept","exts").addSingleVal("regex","pattern");q.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url");q.addMinMax("length","minlength","maxlength","rangelength").addMinMax("range","min","max","range");q.add("equalto",["other"],function(s){var r=i(s.form).find(":input[name="+s.params.other+"]")[0];o(s,"equalTo",r)});q.add("required",function(r){if(r.element.tagName.toUpperCase()!=="INPUT"||r.element.type.toUpperCase()!=="CHECKBOX"){o(r,"required",true)}});q.add("remote",["url","type","additionalfields"],function(t){var r={url:t.params.url,type:t.params.type||"GET",data:{}},s=n(t.element.name);i.each(p(t.params.additionalfields||t.element.name),function(u,w){var v=m(w,s);r.data[v]=function(){return i(t.form).find(":input[name='"+v+"']").val()}});o(t,"remote",r)});if(i.validator.unobtrusive&&i.validator.unobtrusive.adapters){i.extend(q,i.validator.unobtrusive.adapters)}i.validator.addMethod("regex",function(r,t,s){if(this.optional(t)){return true}var u=new RegExp(s).exec(r);return u&&u.index==0&&u[0].length==r.length});i.validator.addMethod("number",function(r,u){var s=c.cultureInfo.numericgroupsize;if(s){var t=new c.stringBuilder();t.cat("^-?(?:\\d+|\\d{1,").cat(s).cat("}(?:").cat(c.cultureInfo.numericgroupseparator).cat("\\d{").cat(s).cat("})+)(?:\\").cat(c.cultureInfo.numericdecimalseparator).cat("\\d+)?$");return this.optional(u)||(t&&new RegExp(t.string()).test(r))}return this.optional(u)||/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(r)})},parse:function(){this.build();this.unobtrusive.parse(this.formId)}};var f=function(m){this.validationMetaData=m};f.prototype={build:function(q){i.validator.addMethod("regex",function(C,E,D){if(this.optional(E)){return true}var F=new RegExp(D).exec(C);return F&&F.index==0&&F[0].length==C.length});i.validator.addMethod("number",function(C,F){var D=c.cultureInfo.numericgroupsize;var E=new c.stringBuilder();E.cat("^-?(?:\\d+|\\d{1,").cat(D).cat("}(?:").cat(c.cultureInfo.numericgroupseparator).cat("\\d{").cat(D).cat("})+)(?:\\").cat(c.cultureInfo.numericdecimalseparator).cat("\\d+)?$");return this.optional(F)||new RegExp(E.string()).test(C)});function v(D,C,E){D.range=[C,E]}function r(C,D){C.regex=D}function B(C){C.required=true}function x(C,D){C.maxlength=D}function o(C,D,E){C[D]=E}function z(F){var C={};for(var E=0;E<F.length;E++){var D=F[E];C[D.FieldName]="#"+D.ValidationMessageId}return C}function p(C){var K={};for(var D=0;D<C.length;D++){var I=C[D];var J={};K[I.FieldName]=J;var G=I.ValidationRules;for(var E=0;E<G.length;E++){var F=G[E];if(F.ErrorMessage){var H=F.ValidationType;switch(F.ValidationType){case"regularExpression":H="regex";break;case"stringLength":H="maxlength";break}J[H]=F.ErrorMessage}}}return K}function A(H){var F=H.ValidationRules;var G={};for(var C=0;C<F.length;C++){var E=F[C];switch(E.ValidationType){case"range":var D=(typeof(E.ValidationParameters.minimum)=="undefined")?E.ValidationParameters.min:E.ValidationParameters.minimum;var I=(typeof(E.ValidationParameters.maximum)=="undefined")?E.ValidationParameters.max:E.ValidationParameters.maximum;v(G,D,I);break;case"regularExpression":case"regex":r(G,E.ValidationParameters.pattern);break;case"required":B(G);break;case"stringLength":x(G,E.ValidationParameters.maximumLength);break;case"length":x(G,E.ValidationParameters.max);break;default:o(G,E.ValidationType,E.ValidationParameters);break}}return G}function y(G){var D={};for(var C=0;C<G.length;C++){var F=G[C];var E=F.FieldName;D[E]=A(F)}return D}var m=i("#"+q.FormId);var u=q.Fields;var n=y(u);var t=z(u);var w=p(u);var s={errorClass:"input-validation-error",errorElement:"span",errorPlacement:function(C,D){var E=t[D.attr("name")];if(E){i(E).empty().removeClass("field-validation-valid").addClass("field-validation-error");C.removeClass("input-validation-error").attr("_for_validation_message",E).appendTo(E)}},messages:w,rules:n,success:function(C){i(C.attr("_for_validation_message")).empty().addClass("field-validation-valid").removeClass("field-validation-error")}};m.validate(s)},parse:function(){this.build(this.validationMetaData)}};c.editing={};function b(){i(document.body).find("div.t-grid").each(function(){var m=i(this).data("tGrid");if(m&&m.cancel){m.cancel()}})}function a(n,m,o){for(var p in m){if(i.isPlainObject(m[p])){a(n,m,o?o+"."+p:p)}else{n[o?o+"."+p:p]=m[p]}}}function j(m){for(var q in m){var p=q.indexOf(".");if(p>-1){var o=q.substring(0,p);var n=m[o]||{};n[q.substring(p+1)]=m[q];m[o]=j(n);delete m[q]}}return m}function d(n){var o,m,p;for(o in n){m=n[o];if(typeof m==="string"){p=k.exec(m);if(p){n[o]=new Date(parseInt(p[1]))}}else{if(i.isPlainObject(m)){d(m)}}}}c.editing.initialize=function(n){i.extend(n,this.implementation);var m=i(n.element);n.modelBinder=new c.grid.ModelBinder();n.formViewBinder=new c.grid.FormViewBinder({date:function(x,u){var w=n.columnFromMember(x);var v=w?w.format:"";return c.formatString(v||"{0:G}",u)}});if(n.isAjax()){if(n.editing.mode=="InCell"){d(n.editing.defaultDataItem||{});n.changeLog=new c.grid.ChangeLog(n.pageSize||(n.data&&n.data.length)||0);i(n.element).bind("dataBound",function(){n.changeLog.clear();n.valid=true;n.td=null});n.cellEditor=new c.grid.CellEditor({columns:n.columns,cellIndex:function(u){return n.cellIndex(u)},id:n.formId(),bind:i.proxy(n.formViewBinder.bind,n.formViewBinder),validate:i.proxy(n.validation,n)});m.delegate(".t-grid-save-changes:not(.t-state-disabled)","click",c.stopAll(function(u){n.submitChanges()}));m.delegate(".t-grid-cancel-changes","click",c.stopAll(function(u){n.cancelChanges()}));n.hasChanges=function(){return n.changeLog.dirty()};n.submitChanges=function(){if(n.changeLog.dirty()&&n.validate()){var u=n.changeLog.inserted;var x=i.grep(n.changeLog.updated,function(z){return z!=undefined});var w=i.grep(n.changeLog.deleted,function(z){return z!=undefined});var v={};if(c.trigger(n.element,"submitChanges",{inserted:u,updated:x,deleted:w,values:v})){return}var y=n.ws?{inserted:i.map(u,function(z){return n._convert(z)}),updated:i.map(x,function(z){return n._convert(z)}),deleted:i.map(w,function(z){return n._convert(z)})}:n.changeLog.serialize(u,x,w);n.sendValues(i.extend(y,v),"updateUrl")}};n.cancelChanges=function(){n.changeLog.clear();n.valid=true;n.td=null;n.ajaxRequest()};n.cellIndex=function(u){return i(u).parent().find("td:not(.t-group-cell,.t-hierarchy-cell)").index(u)};n.rowIndex=function(u){return i(u).parent().find("tr:not(.t-detail-row,.t-grouping-row)").index(u)};var r;n.valid=true;n.editCell=function(x){var u=n.columns[n.cellIndex(x)];if(n.valid&&(u&&!u.readonly)){n.td=x;if(n.form().length){i.data(n.form()[0],"validator",null)}x=i(x);var w=x.parent();var y=n.rowIndex(w);var v=n.changeLog.get(y)||n.dataItem(w);r=x.find(".t-dirty");n.cellEditor.edit(x,v);c.trigger(n.element,"edit",{mode:w.hasClass("t-grid-new-row")?"insert":"edit",form:n.form()[0],dataItem:v,cell:x[0]})}};n.saveCell=function(x){n.valid=n.validate();if(n.valid){x=i(x);var w=x.parent();var v=n.dataItem(w);var y=j(n.modelBinder.bind(x));var u=false;if(c.trigger(n.element,"save",{mode:w.hasClass("t-grid-new-row")?"insert":"edit",dataItem:v,values:y,form:n.form()[0],cell:x[0]})){return}if(w.hasClass("t-grid-new-row")){n.changeLog.insert(n.rowIndex(w),y)}else{u=n.changeLog.update(n.rowIndex(w),v,y)}n.cellEditor.display(x,i.extend(true,{},v,y));if(u||w.hasClass("t-grid-new-row")){r=i('<span class="t-dirty" />')}if(r&&r.length){r.prependTo(n.td)}n.td=null}};n.cancelCell=function(x){x=i(x);var w=x.parent(),u=n.rowIndex(w),v=n.changeLog.get(u)||n.dataItem(w);n.valid=true;n.cellEditor.display(x,v);if(r&&r.length){r.prependTo(n.td)}n.td=null};n.td=null;n.$tbody.delegate("tr:not(.t-grouping-row,.t-no-data) > td:not(.t-detail-cell,.t-grid-edit-cell,.t-group-cell,.t-hierarchy-cell)",n.editing.beginEdit||"click",function(u){if(i(this).closest("tbody")[0]==n.$tbody[0]){n.editCell(this)}});i(document).mousedown(function(u){if(n.td&&!i.contains(n.td,u.target)&&n.td!=u.target&&!i(u.target).closest(".t-animation-container").length){n.saveCell(n.td)}})}else{if(n.editing.beginEdit){n.$tbody.delegate("tr:not(.t-detail-row,.t-grouping-row,.t-grid-edit-row,.t-group-footer)",n.editing.beginEdit,function(u){if(!i(u.target).is(":button,a,:input,a>.t-icon")){n.editRow(i(this))}})}}m.delegate(".t-grid-edit","click",c.stopAll(function(u){n.editRow(i(this).closest("tr"))})).delegate(".t-grid-delete","click",c.stopAll(function(u){n.deleteRow(i(this).closest("tr"))})).delegate(".t-grid-add","click",c.stopAll(function(u){n.addRow()}))}else{m.delegate(".t-grid-delete","click",c.stop(function(u){if(n.editing.confirmDelete!==false&&!confirm(n.localization.deleteConfirmation)){u.preventDefault()}}));n.validation()}n.errorView=new c.grid.ErrorView();var t=new c.grid.DataCellBuilder({columns:n.columns,rowTemplate:n.rowTemplate});var o=i.grep(n.columns,function(u){return u.commands&&i.grep(u.commands,function(v){return v.name=="edit"})[0]})[0];if(!o){o={commands:[{name:"edit",buttonType:"Text"}]};o.insert=n.insertFor(o);o.edit=n.editFor(o)}var p=new c.grid.FormContainerBuilder({html:function(){return unescape(n.editing.editor)},insert:function(){return o.insert()},edit:function(){return o.edit()}});var s=n.editing.mode;var q=function(){return(n.groups||[]).length};if(s=="InLine"){n.rowEditor=new c.grid.Editor({id:n.formId(),cancel:t.display,edit:t.edit,insert:t.insert,groups:q,details:n.detail})}else{if(s=="InForm"){n.rowEditor=new c.grid.Editor({id:n.formId(),cancel:t.display,groups:q,details:n.detail,edit:function(){return'<td colspan="'+n.columns.length+'">'+p.edit()+"</td>"},insert:function(){return'<td colspan="'+n.columns.length+'">'+p.insert()+"</td>"}})}else{if(s=="PopUp"){n.rowEditor=new c.grid.PopUpEditor({id:n.formId(),edit:p.edit,container:n.element,settings:n.editing.popup,insert:p.insert,editTitle:n.localization.edit,insertTitle:n.localization.insert})}else{t=new c.grid.CellBuilder({columns:n.columns});n.rowEditor=new c.grid.Editor({id:n.formId(),cancel:t.display,edit:t.edit,insert:t.insert})}}}if(!n.keyboardNavigation){m.delegate(":input:not(.t-button):not(textarea)","keydown",c.stop(function(v){if(v.keyCode==13||v.keyCode==27){v.preventDefault();var u={13:".t-grid-update, .t-grid-insert",27:".t-grid-cancel"};i(this).closest("tr").find(u[v.keyCode]).click()}}))}};c.editing.implementation={editFor:function(n){var o=this.localization;if(n.commands){var q=i.grep(n.commands,function(s){return s.name=="edit"})[0];if(q){var r=c.grid.ButtonBuilder.create(i.extend({text:o.update},q,{name:"update"}));var p=c.grid.ButtonBuilder.create(i.extend({text:o.cancel},q,{name:"cancel"}));var m=r.build()+p.build();return function(){return m}}else{return function(){return""}}}else{if(!n.readonly&&n.editor){return function(){return unescape(n.editor)}}}return this.displayFor(n)},insertFor:function(n){var o=this.localization;if(n.commands){var q=i.grep(n.commands,function(s){return s.name=="edit"})[0];if(q){var r=c.grid.ButtonBuilder.create(i.extend({text:o.insert},q,{name:"insert"}));var p=c.grid.ButtonBuilder.create(i.extend({text:o.cancel},q,{name:"cancel"}));var m=r.build()+p.build();return function(){return m}}else{return function(){return""}}}else{return this.editFor(n)}},insertRow:function(m){if(this.validate()){var n=this.extractValues(m);if(c.trigger(this.element,"save",{mode:"insert",values:n,form:this.form()[0]})){return}this.sendValues(n,"insertUrl")}},updateRow:function(m){if(this.validate()){var n=this.dataItem(m.data("tr")||m);var o=this.extractValues(m,(this.editing.mode!="InCell"||!this.ws));if(c.trigger(this.element,"save",{mode:"edit",dataItem:n,values:o,form:this.form()[0]})){return}if(this.editing.mode=="InCell"){o=i.extend(n,o)}d(o);this.sendValues(o,"updateUrl")}},deleteRow:function(m){var n=this.dataItem(m);if(this.editing.mode!="InCell"){var o=this.extractValues(m,true);if(c.trigger(this.element,"delete",{dataItem:n,values:o})){return}if(!this._isServerOperation()&&this.dataSource){this.deletedIds.push(this.dataSource.id(n))}if(this.editing.confirmDelete===false||confirm(this.localization.deleteConfirmation)){this.sendValues(o,"deleteUrl")}}else{if(this.editing.confirmDelete===false||confirm(this.localization.deleteConfirmation)){this.changeLog.erase(this.rowIndex(m),n);if(this.td&&i.contains(m[0],this.td)){this.td=null;this.valid=true}if(!this._isServerOperation()&&this.dataSource){this.deletedIds.push(this.dataSource.id(n))}this.cancelRow(m);m.hide()}}},editRow:function(m){var o=this.dataItem(m);if(this.editing.mode!="InCell"){b();var p=this.rowEditor.edit(m,o);var n=this.form();n.undelegate(".t-grid-update").delegate(".t-grid-update","click",c.stopAll(i.proxy(function(){this.updateRow(p)},this))).undelegate(".t-grid-cancel").delegate(".t-grid-cancel","click",c.stopAll(i.proxy(function(){this.cancelRow(m)},this)));this.formViewBinder.bind(p,o);c.trigger(this.element,"edit",{mode:"edit",form:n[0],dataItem:o});this.validation()}else{if(this.valid){this.rowEditor.edit(m,o);this.td=row.find(":input:visible:first").focus().closest("td")[0];this.validation()}}},form:function(){return i("#"+this.formId())},addRow:function(){var p=i.extend(true,{},this.editing.defaultDataItem);if(this.editing.mode!="InCell"){b();var r=this.rowEditor.insert(this.$tbody,p);var n=this.form();n.undelegate(".t-grid-insert").delegate(".t-grid-insert","click",c.stopAll(i.proxy(function(){this.insertRow(r)},this))).undelegate(".t-grid-cancel").delegate(".t-grid-cancel","click",c.stopAll(i.proxy(function(){this.cancelRow(r)},this)));c.trigger(this.element,"edit",{mode:"insert",form:n[0],dataItem:p});this.validation()}else{if(this.valid){var o=this.rowEditor.insert(this.$tbody,p);this.changeLog.insert(p);this.td=o.find(":input:enabled:visible:first").focus().closest("td")[0];for(var m=this.columns.length-1;m>=0;m--){if(!this.columns[m].readonly){var q=o.children().eq(m);if(q[0]!=this.td){q.prepend('<span class="t-dirty" />')}}}c.trigger(this.element,"edit",{mode:"insert",form:this.form()[0],dataItem:p,cell:this.td});this.validation()}}if(this.editing.mode!="PopUp"){this.$tbody.find(" > tr.t-no-data").hide()}},extractValues:function(r,o){var p=this.modelBinder.bind(r);if(o){var q=this.dataItem(r.data("tr")||r);for(var n in this.dataKeys){var m=this.valueFor({member:n})(q);if(m instanceof Date){m=c.formatString("{0:G}",m)}p[this.ws?n:this.dataKeys[n]]=m}}return p},cancelRow:function(m){if(!m.length){return}var n=this.dataItem(m);this.rowEditor.cancel(m,n);if(m.is(".t-grid-new-row")){this.$tbody.find(" > tr.t-no-data").show();return}c.trigger(this.element,"rowDataBound",{row:m[0],dataItem:n})},validate:function(){var m=this.form();if(m.length){var o=m.validate();var n=o.form();if(o.pendingRequest){o.formSubmitted=true;return false}return n}return true},cancel:function(){this.cancelRow(this.$tbody.find(">.t-grid-edit-row"))},_dataSource:function(){var m=this,p=this._dataSourceOptions(),o=[],n=[];i.each(m.dataKeys,function(r,q){o.push(q);n.push(c.getter(r))});if(m.isAjax()){i.extend(true,p,{model:c.Model.define({id:function(r,q){var s;if(q===undefined){return i.map(n,function(t){return t(r)}).join("-")}else{s=q.split("-");i.each(o,function(u,t){r[t]=s[u]})}}})})}m.dataSource=new c.DataSource(p)},_convert:function(o){for(var s in o){var n=o[s];if(n instanceof Date){var p=this.columnFromMember(s);var m="{0:G}";if(p&&p.format){m=p.format}o[s]=this.ws?"\\/Date("+n.getTime()+")\\/":c.formatString(m,n)}if(typeof n==="number"){var t="numeric",p=this.columnFromMember(s),m=(p&&p.format?p.format:"N").toLowerCase(),r={n:t,p:"percent",c:"currency","#":t,"0":t};n=n.toString();var q=m.match(l)||m.match(g);o[s]=q?n.replace(".",c.cultureInfo[r[q]+"decimalseparator"]):n}if(n==undefined){delete o[s]}if(i.isPlainObject(n)){this._convert(n)}}return o},sendValues:function(p,m){if(this.editing.mode!="InCell"||!this.ws){this._convert(p);for(var n in this.dataKeys){var o=this.valueFor({member:n})(p);if(o!=undefined){p[this.ws?n:this.dataKeys[n]]=o}}}this.showBusy();i.ajax(this.ajaxOptions({data:this.ws?(this.editing.mode=="InCell"?p:{value:p}):p,url:this.url(m),hasErrors:i.proxy(this.hasErrors,this),displayErrors:i.proxy(this.displayErrors,this)}))},displayErrors:function(m){this.errorView.bind(i("#"+this.formId()),m.modelState)},hasErrors:function(m){var n=m.modelState;var o=false;if(n){i.each(n,function(p,q){if("errors" in q){o=true;return false}})}return o},formId:function(){return i(this.element).attr("id")+"form"},validation:function(){this.validator().parse()},validator:function(){if(this.validationMetadata){return new f(this.validationMetadata)}else{return new h("#"+this.formId())}}};c.grid.ModelBinder=function(){this.binders={":input.t-autocomplete":function(){return i(this).val()},".t-numerictextbox :input":function(){return i(this).data("tTextBox").value()},":input:not(.t-input):not(:radio),:radio:checked":function(){return i(this).val()},":checkbox":function(){return i(this).is(":checked")},".t-datepicker :input":function(){return i(this).data("tDatePicker").value()},".t-timepicker :input":function(){return i(this).data("tTimePicker").value()},".t-datetimepicker :input":function(){return i(this).data("tDateTimePicker").value()},".t-editor textarea:hidden":function(){var m=i(this).closest(".t-editor").data("tEditor");if(m.encoded){return m.encodedValue()}return m.value()}};this.bind=function(m){var n={};i.each(this.binders,function(o,p){m.find(o).each(function(){if(!this.disabled){n[this.name]=p.call(this)}})});return n}};c.grid.FormViewBinder=function(o){this.converters=o||{};this.binders={":input:not(:radio)":function(p){if(typeof p=="boolean"){p=p+""}i(this).val(p)},":checkbox":function(p){i(this).attr("checked",p==true)},":radio":function(q){var p=i(this).val();if(typeof q=="boolean"){p=p.toLowerCase()}if(p==q.toString()){i(this).attr("checked",true)}}};function n(p){return function(q){i(this).data(p).value(q)}}function m(){return function(p){i(this).closest(".t-editor").data("tEditor").value(p)}}this.binders[".t-numerictextbox :input"]=n("tTextBox");this.binders[".t-dropdown :input:hidden"]=n("tDropDownList");this.binders[".t-datepicker :input"]=n("tDatePicker");this.binders[".t-datetimepicker :input"]=n("tDateTimePicker");this.binders[".t-timepicker :input"]=n("tTimePicker");this.binders[".t-slider :input"]=n("tSlider");this.binders[".t-combobox :input:hidden"]=n("tComboBox");this.binders[".t-editor textarea:hidden"]=m();this.evaluate=function(q,t){if(t!=null){var p=q,r=false,v=t.split(".");while(v.length){var w=v.shift();if(w.indexOf("[")>-1){p=new Function("d","try { return d."+w+"}catch(e){}")(p);if(p!=null){r=true}}else{if(p!=null&&typeof(p[w])!="undefined"){p=p[w];r=true}else{if(r){r=false;break}}}}if(r&&!i.isPlainObject(p)){var s=k.exec(p);if(s){p=new Date(parseInt(s[1]))}var u=c.getType(p);if(u in this.converters){p=this.converters[u](t,p)}return p}}};this.bind=function(r,q){var p;i.each(this.binders,i.proxy(function(s,t){r.find(s).each(i.proxy(function(v,w){var u=this.evaluate(q,w.name);if(u!=p){t.call(w,u)}},this))},this))}};c.grid.CellBuilder=function(m){function n(p,o){return i.map(m.columns,function(q,r){var s;if(r==0&&o=="insert"){s="t-grid-edit-cell"}else{if(r==m.columns.length-1){s="t-last"}}return"<td "+(q.attr?q.attr:"")+(s?' class="'+s+'"':"")+">"+q[r==0?o:"display"](p)+"</td>"}).join("")}this.edit=function(o){return n(o,"edit")};this.insert=function(o){return n(o,"insert")};this.display=function(o){return n(o,"display")}};c.grid.DataCellBuilder=function(m){function n(p,o){return i.map(m.columns,function(r,q){return"<td "+(r.attr?r.attr:"")+(q==m.columns.length-1?' class="t-last">':">")+r[o](p)+"</td>"}).join("")}this.edit=function(o){return n(o,"edit")};this.insert=function(o){return n(o,"insert")};this.display=function(o){if(m.rowTemplate){return'<td colspan="'+m.columns.length+'">'+m.rowTemplate(o)+"</td>"}return n(o,"display")}};c.grid.FormContainerBuilder=function(m){function n(o){return'<div class="t-edit-form-container">'+m.html()+m[o]()+"</div>"}this.edit=function(){return n("edit")};this.insert=function(){return n("insert")}};function e(m){return i("<form />",{className:"t-edit-form",id:m}).submit(c.preventDefault)}c.grid.PopUpEditor=function(o){var n;function m(){var q=n.data("tWindow");q&&q.close();n.remove()}function p(r,q){n=i("<div />",{id:o.container.id+"PopUp"}).appendTo(o.container).css({top:0,left:"50%",marginLeft:-90}).tWindow(o.settings).find(".t-window-content").append(o[q](r)).wrapInner(e(o.id)).end();i(o.container).one("dataBound",m);n.find(".t-close").click(c.stopAll(m)).end().data("tWindow").open().title(o[q+"Title"]);return n}this.edit=function(q,r){q.addClass("t-grid-edit-row");return p(r,"edit").data("tr",q)};this.insert=function(q,r){return p(r,"insert")};this.cancel=function(q){q.removeClass("t-grid-edit-row");m()}};c.grid.Editor=function(o){var n=o.groups||function(){return 0};function m(p,q,r){var s=p.find(".t-group-cell,.t-hierarchy-cell");p.addClass("t-grid-edit-row").empty().append(s).append(o[r](q)).closest("table").wrap(function(){if(!i(this).parent().is("form")){return e(o.id)}})}this.cancel=function(p,q){if(p.is(".t-grid-new-row")){p.remove()}else{m(p,q,"cancel");p.removeClass("t-grid-edit-row")}};this.insert=function(r,q){var s='<tr class="t-grid-new-row">'+new Array(n()+1).join('<td class="t-group-cell" />')+((o.details)?'<td class="t-hierarchy-cell"/>':"")+"</tr>";var p=i(s);r.prepend(p);m(p,q,"insert");return p};this.edit=function(p,q){m(p,q,"edit");return p}};c.grid.CellEditor=function(m){this.edit=function(p,o){var n=m.columns[m.cellIndex(p)];if(!n.readonly){p.parent().addClass("t-grid-edit-row").end().empty().html(n.edit(o)).closest("table").wrap(function(){if(!i(this).parent().is("form")){return e(m.id)}});m.bind(p,o);m.validate();p.find(":input:visible:first").trigger("focusin").focus();p.addClass("t-grid-edit-cell")}return !n.readonly};this.display=function(p,o){var n=m.columns[m.cellIndex(p)];p.removeClass("t-grid-edit-cell").empty().html(n.display(o)).parent().removeClass("t-grid-edit-row")}};c.grid.ChangeLog=function(n){this.insert=function(o,q){if(q==undefined){q=o;this.inserted.splice(0,0,q)}else{var p=this.inserted[o];if(p===undefined){this.inserted.splice(0,0,q)}else{i.extend(p,q)}}};this.get=function(p){var o=this.inserted[p];if(this.inserted[p]){return o}return this.updated[p-this.inserted.length]};this.update=function(u,r,q){u=u-this.inserted.length;var v=this.updated[u]||r||{};var t=false;for(var o in q){var s=v[o],p=q[o];if(s instanceof Date){if(p instanceof Date&&p.getTime()!==s.getTime()){t=true}}else{if(p!==s){t=true}}}if(t){this.updated[u]=i.extend({},v,q)}return t};this.erase=function(p,r){var o=this.inserted[p];if(o){this.inserted.splice(p,1)}else{p=p-this.inserted.length;var q=this.updated[p];if(q){delete this.updated[p]}this.deleted[p]=r}};this.clear=function(){this.updated=new Array(n);this.deleted=new Array(n);this.inserted=[]};function m(p,t,v){var w={};for(var u=0,q=0;u<p.length;u++){var s=p[u];if(v(s)){for(var o in s){var r=s[o],x=t+"["+q+"]."+o;if(i.isPlainObject(r)){a(w,r,x)}else{w[x]=r}}q++}}return w}this.serialize=function(o,q,p){return i.extend({},m(o,"inserted",function(){return true}),m(q,"updated",function(r){return r!==undefined}),m(p,"deleted",function(r){return r!==undefined}))};this.dirty=function(){if(this.inserted.length){return true}for(var o=0;o<this.updated.length;o++){if(this.updated[o]){return true}}for(o=0;o<this.deleted.length;o++){if(this.deleted[o]){return true}}return false};this.clear()};c.grid.ErrorView=function(){this.bind=function(m,n){m.find("span[id$=_validationMessage]").removeClass("field-validation-error").addClass("field-validation-valid").html("").end().find(".input-validation-error").removeClass("input-validation-error").addClass("valid");i.each(n,function(q,o){if("errors" in o&&o.errors[0]){var p=q;q=q.replace(".","_");m.find("#"+q+'_validationMessage, [data-valmsg-for="'+p+'"]').html(o.errors[0]).removeClass("field-validation-valid").removeClass("field-valiion-valid").addClass("field-validation-error").end().find("#"+q).removeClass("valid").addClass("input-validation-error")}})}}})(jQuery);