Sonarr/packages/TelerikMvcExtensions.2011.3.../content/Scripts/2011.3.1115/telerik.grid.editing.min.js

1 line
28 KiB
JavaScript

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