Lidarr/NzbDrone.Web/Scripts/2010.3.1318/telerik.grid.editing.min.js

1 line
16 KiB
JavaScript

(function(e){var g=e.telerik;var d=function(i){this.formId=i;this._isBuild=false;var k="tUnobtrusiveValidation";var j="tUnobtrusiveContainer";var h=this.unobtrusive={adapters:[],parseElement:function(l,o){var m=e(l),n=m.parents("form")[0],q,p,r;if(!n){return}q=h.validationInfo(n);q.options.rules[l.name]=p={};q.options.messages[l.name]=r={};e.each(this.adapters,function(){var s="data-val-"+this.name,t=m.attr(s),u={};if(t!==undefined){s+="-";e.each(this.params,function(){u[this]=m.attr(s+this)});this.adapt({element:l,form:n,message:t,params:u,rules:p,messages:r})}});if(!o){q.attachValidation()}},parse:function(l){e(l).find(":input[data-val=true]").each(function(){h.parseElement(this,true)});e("form").each(function(){var m=h.validationInfo(this);if(m){m.attachValidation()}})},onError:function(l,o){var n=e(this).find("[data-valmsg-for='"+o[0].name+"']"),m=e.parseJSON(n.attr("data-valmsg-replace"))!==false;n.removeClass("field-validation-valid").addClass("field-validation-error");l.data(j,n);if(m){n.empty();l.removeClass("input-validation-error").appendTo(n)}else{l.hide()}},onErrors:function(l,o){var n=e(this).find("[data-valmsg-summary=true]"),m=n.find("ul");if(m&&m.length&&o.errorList.length){m.empty();n.addClass("validation-summary-errors").removeClass("validation-summary-valid");e.each(o.errorList,function(){e("<li />").html(this.message).appendTo(m)})}},onSuccess:function(l){var n=l.data(j),m=e.parseJSON(n.attr("data-valmsg-replace"));if(n){n.addClass("field-valiion-valid").removeClass("field-validation-error");l.removeData(j);if(m){n.empty()}}},validationInfo:function(l){var n=e(l),m=n.data(k);if(!m){m={options:{errorClass:"input-validation-error",errorElement:"span",errorPlacement:e.proxy(h.onError,l),invalidHandler:e.proxy(h.onErrors,l),messages:{},rules:{},success:e.proxy(h.onSuccess,l)},attachValidation:function(){n.validate(this.options)},validate:function(){n.validate();return n.valid()}};n.data(k,m)}return m}}};d.prototype={build:function(){if(this._isBuild){return}this._isBuild=true;var j=[];function h(m,l,k){m.rules[l]=k;if(m.message){m.messages[l]=m.message}}function i(k){return k.replace(/^\s+|\s+$/g,"").split(/\s*,\s*/g)}j=this.unobtrusive.adapters;j.add=function(m,l,k){if(!k){k=l;l=[]}this.push({name:m,params:l,adapt:k});return this};j.addBool=function(l,k){return this.add(l,function(m){h(m,k||l,true)})};j.addMinMax=function(n,l,p,k,m,o){return this.add(n,[m||"min",o||"max"],function(s){var q=s.params.min,r=s.params.max;if(q&&r){h(s,k,[q,r])}else{if(q){h(s,l,q)}else{if(r){h(s,p,r)}}}})};j.addSingleVal=function(l,m,k){return this.add(l,[m||"val"],function(n){h(n,k||l,n.params[m])})};j.addSingleVal("accept","exts").addSingleVal("regex","pattern");j.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url");j.addMinMax("length","minlength","maxlength","rangelength").addMinMax("range","min","max","range");j.add("equalto",["other"],function(l){var k=e(l.form).find(":input[name="+l.params.other+"]")[0];h(l,"equalTo",k)});j.add("required",function(k){if(k.element.tagName.toUpperCase()!=="INPUT"||k.element.type.toUpperCase()!=="CHECKBOX"){h(k,"required",true)}});j.add("remote",["url","type","fields"],function(k){var l={url:k.params.url,type:k.params.type||"GET",data:{}};e.each(i(k.params.fields||k.element.name),function(m,n){l.data[n]=function(){return e(k.form).find(":input[name='"+n+"']").val()}});h(k,"remote",l)});if(e.validator.unobtrusive&&e.validator.unobtrusive.adapters){e.extend(j,e.validator.unobtrusive.adapters)}e.validator.addMethod("regex",function(k,m,l){if(this.optional(m)){return true}var n=new RegExp(l).exec(k);return n&&n.index==0&&n[0].length==k.length});e.validator.addMethod("number",function(k,n){var l=g.cultureInfo.numericgroupsize;var m=new g.stringBuilder();m.cat("^-?(?:\\d+|\\d{1,").cat(l).cat("}(?:").cat(g.cultureInfo.numericgroupseparator).cat("\\d{").cat(l).cat("})+)(?:\\").cat(g.cultureInfo.numericdecimalseparator).cat("\\d+)?$");return this.optional(n)||new RegExp(m.string()).test(k)})},parse:function(){this.build();this.unobtrusive.parse(this.formId)}};var c=function(h){this.validationMetaData=h};c.prototype={build:function(l){e.validator.addMethod("regex",function(x,z,y){if(this.optional(z)){return true}var A=new RegExp(y).exec(x);return A&&A.index==0&&A[0].length==x.length});e.validator.addMethod("number",function(x,A){var y=g.cultureInfo.numericgroupsize;var z=new g.stringBuilder();z.cat("^-?(?:\\d+|\\d{1,").cat(y).cat("}(?:").cat(g.cultureInfo.numericgroupseparator).cat("\\d{").cat(y).cat("})+)(?:\\").cat(g.cultureInfo.numericdecimalseparator).cat("\\d+)?$");return this.optional(A)||new RegExp(z.string()).test(x)});function q(y,x,z){y.range=[x,z]}function m(x,y){x.regex=y}function w(x){x.required=true}function s(x,y){x.maxlength=y}function j(x,y,z){x[y]=z}function u(A){var x={};for(var z=0;z<A.length;z++){var y=A[z];x[y.FieldName]="#"+y.ValidationMessageId}return x}function k(x){var F={};for(var y=0;y<x.length;y++){var D=x[y];var E={};F[D.FieldName]=E;var B=D.ValidationRules;for(var z=0;z<B.length;z++){var A=B[z];if(A.ErrorMessage){var C=A.ValidationType;switch(A.ValidationType){case"regularExpression":C="regex";break;case"stringLength":C="maxlength";break}E[C]=A.ErrorMessage}}}return F}function v(C){var A=C.ValidationRules;var B={};for(var x=0;x<A.length;x++){var z=A[x];switch(z.ValidationType){case"range":var y=(typeof(z.ValidationParameters.minimum)=="undefined")?z.ValidationParameters.min:z.ValidationParameters.minimum;var D=(typeof(z.ValidationParameters.maximum)=="undefined")?z.ValidationParameters.max:z.ValidationParameters.maximum;q(B,y,D);break;case"regularExpression":case"regex":m(B,z.ValidationParameters.pattern);break;case"required":w(B);break;case"stringLength":s(B,z.ValidationParameters.maximumLength);break;case"length":s(B,z.ValidationParameters.max);break;default:j(B,z.ValidationType,z.ValidationParameters);break}}return B}function t(B){var y={};for(var x=0;x<B.length;x++){var A=B[x];var z=A.FieldName;y[z]=v(A)}return y}var h=e("#"+l.FormId);var p=l.Fields;var i=t(p);var o=u(p);var r=k(p);var n={errorClass:"input-validation-error",errorElement:"span",errorPlacement:function(x,y){var z=o[y.attr("name")];if(z){e(z).empty().removeClass("field-validation-valid").addClass("field-validation-error");x.removeClass("input-validation-error").attr("_for_validation_message",z).appendTo(z)}},messages:r,rules:i,success:function(x){e(x.attr("_for_validation_message")).empty().addClass("field-validation-valid").removeClass("field-validation-error")}};h.validate(n)},parse:function(){this.build(this.validationMetaData)}};function b(p,o){for(var h=0,n=p.length;h<n;h++){if(p[h].commands){var k=p[h].commands;for(var l=0,m=k.length;l<m;l++){if(k[l].name==o){return k[l]}}}}return{}}g.editing={};function a(){e(document.body).find("div.t-grid").each(function(){var h=e(this).data("tGrid");if(h&&h.cancel){h.cancel()}})}g.editing.initialize=function(i){e.extend(i,this.implementation);var h=e(i.element);if(i.isAjax()){h.delegate(".t-grid-edit","click",g.stopAll(function(j){i.editRow(e(this).closest("tr"))})).delegate(".t-grid-cancel","click",g.stopAll(function(j){i.cancel()})).delegate(".t-grid-delete","click",g.stopAll(function(j){i.deleteRow(e(this).closest("tr"))})).delegate(".t-grid-update","click",g.stopAll(function(j){i.save(this,e.proxy(function(){i.updateRow(e(this).closest("form").closest("tr"))},this))})).delegate(".t-grid-add","click",g.stopAll(function(j){i.addRow()})).delegate(".t-grid-insert","click",g.stopAll(function(j){i.save(this,e.proxy(function(){i.insertRow(e(this).closest("form").closest("tr"))},this))}))}else{h.delegate(".t-grid-delete","click",g.stop(function(j){if(i.editing.confirmDelete!==false&&!confirm(i.localization.deleteConfirmation)){j.preventDefault()}}));i.validation()}i.errorView=new g.grid.ErrorView();i.modelBinder=new g.grid.ModelBinder();i.formViewBinder=new g.grid.FormViewBinder({date:function(m,j){var l=i.columnFromMember(m);var k=l?l.format:"";return g.formatString(k||"{0:G}",j)}});h.delegate(":input:not(.t-button)","keydown",g.stop(function(k){if(k.keyCode==13||k.keyCode==27){var j={13:".t-grid-update, .t-grid-insert",27:".t-grid-cancel"};e(this).closest("tr").find(j[k.keyCode]).click()}}))};function f(j){var i=function(){var k=h.data("tWindow");if(k){k.close()}h.remove()};var h=e("<div />",{id:j.element.id+"PopUp"}).appendTo(j.element).css({top:0,left:"50%",marginLeft:-90}).tWindow(j.settings).delegate(".t-grid-cancel","click",g.stopAll(function(){i()}));e(j.element).one("dataBound",i);e.each(["insert","update"],function(k,l){if(j[l]){h.undelegate(".t-grid-"+l,"click").delegate(".t-grid-"+l,"click",g.stopAll(function(m){j[l](m.target,h)}))}});h.find(".t-close").bind("click",g.stopAll(i)).end().data("tWindow").title(j.title).content(j.content).open();return h}g.editing.implementation={insertRow:function(h){var i=this.extractValues(h);if(g.trigger(this.element,"save",{mode:"insert",values:i,form:h.find("form")[0]})){return}this.sendValues(i,"insertUrl")},updateRow:function(h){var i=this.dataItem(h.data("tr")||h);var j=this.extractValues(h,true);if(g.trigger(this.element,"save",{mode:"edit",dataItem:i,values:j,form:h.find("form")[0]})){return}this.sendValues(j,"updateUrl")},deleteRow:function(h){if(g.trigger(this.element,"delete",{dataItem:this.dataItem(h)})){return}if(this.editing.confirmDelete===false||confirm(this.localization.deleteConfirmation)){this.sendValues(this.extractValues(h,true),"deleteUrl")}},editRow:function(j){a();var k=new g.stringBuilder();var l=b(this.columns,"edit");this.form(k,[{name:"update",attr:l.attr,buttonType:l.buttonType,imageAttr:l.imageAttr},{name:"cancel",attr:l.attr,buttonType:l.buttonType,imageAttr:l.imageAttr}],j.find(".t-hierarchy-cell").find(".t-icon").hasClass("t-plus"));var i=this.dataItem(j);var h=e(k.string());h.find("form").submit(g.preventDefault);h.children().hide();var m=h.find("tr:first td:not(.t-group-cell, .t-hierarchy-cell)");var n=this.editing.mode;if(n!="PopUp"){j.html(h)}else{f({title:this.localization.edit,element:this.element,settings:this.editing.popup,content:h,update:e.proxy(function(p,o){this.save(p,e.proxy(function(){o.data("tr",j);this.updateRow(o)},this))},this)})}this.formViewBinder.bind(h,i);if(n=="InLine"){e.each(this.columns,function(o){if(this.readonly){m.eq(o).html(this.display(i))}})}h.children().show();g.trigger(this.element,"edit",{mode:"edit",form:h.find("form")[0]||h[0],dataItem:i});this.validation()},addRow:function(){a();var l=new g.stringBuilder();var j=this.editing.mode;var k=b(this.columns,"edit");var i;if(j!="PopUp"){l.cat('<tr class="t-grid-new-row">');this.form(l,[{name:"insert",attr:k.attr,buttonType:k.buttonType,imageAttr:k.imageAttr},{name:"cancel",attr:k.attr,buttonType:k.buttonType,imageAttr:k.imageAttr}]);l.cat("</tr>");var h=e(l.string());h.find("form").submit(g.preventDefault);i=h.prependTo(this.$tbody)}else{this.form(l,[{name:"insert",attr:k.attr,buttonType:k.buttonType,imageAttr:k.imageAttr},{name:"cancel",attr:k.attr,buttonType:k.buttonType,imageAttr:k.imageAttr}]);i=e(l.string());i.find("form").submit(g.preventDefault);f({title:this.localization.insert,element:this.element,settings:this.editing.popup,content:i,insert:e.proxy(function(n,m){this.save(n,e.proxy(function(){this.insertRow(m)},this))},this)})}g.trigger(this.element,"edit",{mode:"insert",form:i.find("form")[0]||i[0]});this.validation()},extractValues:function(m,j){var k=this.modelBinder.bind(m);if(j){var l=this.dataItem(m.data("tr")||m);for(var i in this.dataKeys){var h=this.valueFor({member:i})(l);if(h instanceof Date){h=g.formatString("{0:G}",h)}k[this.ws?i:this.dataKeys[i]]=h}}return k},cancelRow:function(h){if(!h.length){return}if(h.is(".t-grid-new-row")){var l=h.closest("tbody");h.remove();if(e.browser.msie){l.hide().show()}return}var k=this.dataItem(h);var j=new g.stringBuilder();var i=h.find(".t-hierarchy-cell").find(".t-icon").hasClass("t-plus");j.rep('<td class="t-group-cell" />',this.groups.length).catIf('<td class="t-hierarchy-cell"><a href="#" class="t-icon '+(i?"t-plus":"t-minus")+'"></a></td>',this.detail);e.each(this.columns,e.proxy(function(m,n){j.cat("<td").cat(n.attr).catIf(' class="t-last"',m==this.columns.length-1).cat(">");if(n.display){j.cat(n.display(k))}this.appendCommandHtml(n.commands,j);j.cat("</td>")},this));h.html(j.string());g.trigger(this.element,"rowDataBound",{row:h[0],dataItem:k})},form:function(l,j,i){var h=this.editing.mode;if(h!="PopUp"){l.cat('<td class="t-edit-container" colspan="').cat(this.columns.length+this.groups.length+(this.detail?1:0)).cat('">')}l.cat('<form class="t-edit-form" action="#" method="post" id="').cat(this.formId()).cat('">');if(h=="InLine"){l.cat('<table cellspacing="0"><colgroup>');e(this.element).find("colgroup:first").children().each(function(){var m=this.style.width;if(this.className!=""){l.cat('<col class="').cat(this.className).cat('" />')}else{if(m!="0px"){l.cat('<col style="width:').cat(m).cat('" />')}else{l.cat("<col />")}}});var k=new g.stringBuilder();k.cat('<td class="t-hierarchy-cell">').catIf('<a href="#" class="t-icon '+(i?"t-plus":"t-minus")+'"></a>',i!=undefined).cat("</td>");l.cat("</colgroup><tbody><tr>").rep('<td class="t-group-cell" />',this.groups.length).catIf(k.string(),this.detail);e.each(this.columns,e.proxy(function(m,n){l.cat("<td").cat(n.attr).catIf(' class="t-last"',m==this.columns.length-1).cat(">").catIf(unescape(n.editor),n.editor).catIf("&nbsp;",!n.editor&&!n.commands);if(n.commands){var o=e.grep(n.commands,function(p){return p.name=="edit"})[0];this.appendCommandHtml(o?j:n.commands,l)}l.cat("</td>")},this));l.cat("</tr></tbody></table>")}else{l.cat('<div class="t-edit-form-container">').cat(unescape(this.editing.editor));this.appendCommandHtml(j,l);l.cat("</div>")}l.cat("</form>");l.catIf("</td>",h!="PopUp")},save:function(h,i){e(h).closest("form").validate().form()&&i()},cancel:function(){this.cancelRow(e("#"+this.formId()).closest("tr"))},sendValues:function(l,h){if(this.ws){for(var i in l){var k=this.columnFromMember(i);if(k&&k.type=="Date"){var j=g.datetime.parse({value:l[i],format:g.cultureInfo.shortDate}).toDate();l[i]="\\/Date("+j.getTime()+")\\/"}}}e.ajax(this.ajaxOptions({data:this.ws?{value:l}:l,url:this.url(h),hasErrors:e.proxy(this.hasErrors,this),displayErrors:e.proxy(this.displayErrors,this)}))},displayErrors:function(h){this.errorView.bind(e("#"+this.formId()),h.modelState)},hasErrors:function(h){var i=h.modelState;var j=false;if(i){e.each(i,function(k,l){if("errors" in l){j=true;return false}})}return j},formId:function(){return e(this.element).attr("id")+"form"},validation:function(){this.validator().parse()},validator:function(){if(this.validationMetadata){return new c(this.validationMetadata)}else{return new d(e("#"+this.formId()))}}};g.grid.ModelBinder=function(){this.binders={":input":function(){return e(this).val()},":checkbox":function(){return e(this).is(":checked")}};this.bind=function(h){var i={};e.each(this.binders,function(j,k){h.find(j).each(function(){if(!this.disabled){i[this.name]=k.call(this)}})});return i}};g.grid.FormViewBinder=function(h){this.converters=h||{};this.binders={":input":function(j){e(this).val(j)},":checkbox":function(j){e(this).attr("checked",j==true)}};function i(j){return function(k){e(this).parent().data(j).value(k)}}this.binders[".t-numerictextbox :input:hidden"]=i("tTextBox");this.binders[".t-dropdown :input:hidden"]=i("tDropDownList");this.binders[".t-combobox :input:hidden"]=i("tComboBox");this.evaluate=function(k,n){if(n!=null){var j=k,l=false,p=n.split(".");while(p.length){var q=p.shift();if(j!=null&&typeof(j[q])!="undefined"){j=j[q];l=true}else{if(l){l=false;break}}}if(l&&!e.isPlainObject(j)){var m=/^\/Date\((.*?)\)\/$/.exec(j);if(m){j=new Date(parseInt(m[1]))}var o=g.getType(j);if(o in this.converters){j=this.converters[o](n,j)}return j}}};this.bind=function(l,k){var j;e.each(this.binders,e.proxy(function(m,n){l.find(m).each(e.proxy(function(p,q){var o=this.evaluate(k,q.name);if(o!=j){n.call(q,o)}},this))},this))}};g.grid.ErrorView=function(){this.bind=function(h,i){h.find("span[id$=_validationMessage]").removeClass("field-validation-error").addClass("field-validation-valid").html("").end().find(".input-validation-error").removeClass("input-validation-error").addClass("valid");e.each(i,function(j,k){if("errors" in k&&k.errors[0]){h.find("#"+j+'_validationMessage, [data-valmsg-for="'+j+'"]').html(k.errors[0]).removeClass("field-validation-valid").addClass("field-validation-error").end().find("#"+j).removeClass("valid").addClass("input-validation-error")}})}}})(jQuery);