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 line
9.7 KiB
1 line
9.7 KiB
(function(h){var l=h.telerik;h.validator.addMethod("regex",function(o,q,p){if(this.optional(q)){return true}var r=new RegExp(p).exec(o);return r&&r.index==0&&r[0].length==o.length});h.validator.addMethod("number",function(o,r){var p=l.cultureInfo.numericgroupsize;var q=new l.stringBuilder();q.cat("^-?(?:\\d+|\\d{1,").cat(p).cat("}(?:").cat(l.cultureInfo.numericgroupseparator).cat("\\d{").cat(p).cat("})+)(?:\\").cat(l.cultureInfo.numericdecimalseparator).cat("\\d+)?$");return this.optional(r)||new RegExp(q.string()).test(o)});function b(p,o,q){p.range=[o,q]}function j(o,p){o.regex=p}function c(o){o.required=true}function m(o,p){o.maxlength=p}function e(o,p,q){o[p]=q}function g(r){var o={};for(var q=0;q<r.length;q++){var p=r[q];o[p.FieldName]="#"+p.ValidationMessageId}return o}function d(o){var w={};for(var p=0;p<o.length;p++){var u=o[p];var v={};w[u.FieldName]=v;var s=u.ValidationRules;for(var q=0;q<s.length;q++){var r=s[q];if(r.ErrorMessage){var t=r.ValidationType;switch(r.ValidationType){case"regularExpression":t="regex";break;case"stringLength":t="maxlength";break}v[t]=r.ErrorMessage}}}return w}function k(s){var o=s.ValidationRules;var r={};for(var p=0;p<o.length;p++){var q=o[p];switch(q.ValidationType){case"range":b(r,q.ValidationParameters.minimum,q.ValidationParameters.maximum);break;case"regularExpression":j(r,q.ValidationParameters.pattern);break;case"required":c(r);break;case"stringLength":m(r,q.ValidationParameters.maximumLength);break;default:e(r,q.ValidationType,q.ValidationParameters);break}}return r}function n(s){var p={};for(var o=0;o<s.length;o++){var r=s[o];var q=r.FieldName;p[q]=k(r)}return p}function i(r){var p=h("#"+r.FormId);var o=r.Fields;var q=n(o);var t=g(o);var s=d(o);var u={errorClass:"input-validation-error",errorElement:"span",errorPlacement:function(v,w){var x=t[w.attr("name")];h(x).empty().removeClass("field-validation-valid").addClass("field-validation-error");v.removeClass("input-validation-error").attr("_for_validation_message",x).appendTo(x)},messages:s,rules:q,success:function(w){var v=h(w.attr("_for_validation_message"));h(v).empty().addClass("field-validation-valid").removeClass("field-validation-error")}};p.validate(u)}function a(u,t){for(var o=0,s=u.length;o<s;o++){if(u[o].commands){var p=u[o].commands;for(var q=0,r=p.length;q<r;q++){if(p[q].name==t){return p[q]}}}}return{}}l.editing={};l.editing.initialize=function(p){h.extend(p,this.implementation);var o=h(p.element);if(p.isAjax()){o.delegate(".t-grid-edit","click",l.stopAll(function(q){p.editRow(h(this).closest("tr"))})).delegate(".t-grid-cancel","click",l.stopAll(function(q){p.cancel()})).delegate(".t-grid-delete","click",l.stopAll(function(q){p.deleteRow(h(this).closest("tr"))})).delegate(".t-grid-update","click",l.stopAll(function(q){p.save(this,h.proxy(function(){p.updateRow(h(this).closest("form").closest("tr"))},this))})).delegate(".t-grid-add","click",l.stopAll(function(q){p.addRow()})).delegate(".t-grid-insert","click",l.stopAll(function(q){p.save(this,h.proxy(function(){p.insertRow(h(this).closest("form").closest("tr"))},this))}))}else{o.delegate(".t-grid-delete","click",l.stop(function(q){if(p.editing.confirmDelete!==false&&!confirm(p.localization.deleteConfirmation)){q.preventDefault()}}));p.validation()}o.delegate(":input:not(.t-button)","keydown",l.stop(function(r){var q={13:".t-grid-update, .t-grid-insert",27:".t-grid-cancel"};h(this).closest("tr").find(q[r.keyCode]).click()}))};function f(q){var o=h("#"+q.element.id+"PopUp");if(!o.length){o=h("<div />",{id:q.element.id+"PopUp"}).appendTo(q.element).css({top:0,left:"50%",marginLeft:-90}).tWindow(q.settings).delegate(".t-grid-cancel","click",l.stopAll(function(){o.data("tWindow").close()}))}h.each(["insert","update"],function(r,s){if(q[s]){o.undelegate(".t-grid-"+s,"click").delegate(".t-grid-"+s,"click",l.stopAll(function(t){q[s](t.target,o)}))}});o.find("> .t-content").empty().append(q.content);var p=o.data("tWindow");p.title(q.title);p.open();return o}l.editing.implementation={insertRow:function(o){var p=this.extractValues(o);if(l.trigger(this.element,"save",{mode:"insert",values:p,form:o.find("form")[0]})){return}this.sendValues(p,"insertUrl")},updateRow:function(o){var p=this.dataItem(o.data("tr")||o);var q=this.extractValues(o,true);if(l.trigger(this.element,"save",{mode:"edit",dataItem:p,values:q,form:o.find("form")[0]})){return}this.sendValues(q,"updateUrl")},deleteRow:function(o){if(l.trigger(this.element,"delete",{dataItem:this.dataItem(o)})){return}if(this.editing.confirmDelete===false||confirm(this.localization.deleteConfirmation)){this.sendValues(this.extractValues(o,true),"deleteUrl")}},editRow:function(q){this.cancel();var r=new l.stringBuilder();var s=a(this.columns,"edit");this.form(r,[{name:"update",attr:s.attr,buttonType:s.buttonType,imageAttr:s.imageAttr},{name:"cancel",attr:s.attr,buttonType:s.buttonType,imageAttr:s.imageAttr}],q.find(".t-hierarchy-cell").find(".t-icon").hasClass("t-plus"));var p=this.dataItem(q);var o=h(r.string());o.children().hide();var t=o.find("tr:first td:not(.t-group-cell, .t-hierarchy-cell)");var u=this.editing.mode;if(u!="PopUp"){q.html(o)}else{f({title:this.localization.edit,element:this.element,settings:this.editing.popup,content:o,update:h.proxy(function(w,v){this.save(w,h.proxy(function(){v.data("tr",q);this.updateRow(v);v.data("tWindow").close()},this))},this)})}h.each(this.columns,function(v){if(this.edit){o.find(':input[name$="'+this.member+'"]').val(this.edit(p)+"").parent().filter(".t-numerictextbox").each(h.proxy(function(x,w){h(w).data("tTextBox").value(this.edit(p))},this)).end().find(':checkbox[name$="'+this.member+'"]').attr("checked",this.edit(p)==true)}if(u=="InLine"&&this.readonly){t.eq(v).html(this.display(p))}});o.children().show();l.trigger(this.element,"edit",{mode:"edit",form:o.find("form")[0]||o[0],dataItem:p});this.validation()},addRow:function(){this.cancel();var r=new l.stringBuilder();var p=this.editing.mode;var q=a(this.columns,"edit");var o;if(p!="PopUp"){r.cat('<tr class="t-grid-new-row">');this.form(r,[{name:"insert",attr:q.attr,buttonType:q.buttonType,imageAttr:q.imageAttr},{name:"cancel",attr:q.attr,buttonType:q.buttonType,imageAttr:q.imageAttr}]);r.cat("</tr>");o=h(r.string()).prependTo(this.$tbody)}else{this.form(r,[{name:"insert",attr:q.attr,buttonType:q.buttonType,imageAttr:q.imageAttr},{name:"cancel",attr:q.attr,buttonType:q.buttonType,imageAttr:q.imageAttr}]);o=h(r.string());f({title:this.localization.insert,element:this.element,settings:this.editing.popup,content:o,insert:h.proxy(function(t,s){this.save(t,h.proxy(function(){this.insertRow(s);s.data("tWindow").close()},this))},this)})}l.trigger(this.element,"edit",{mode:"insert",form:o.find("form")[0]||o[0]});this.validation()},extractValues:function(o,r){var s={};h.each(this.columns,function(){var t=this.member;if(this.edit){o.find(':input[name$="'+t+'"]').each(function(){s[t]=h(this).val()}).end().find(':checkbox[name$="'+t+'"]').each(function(){s[t]=h(this).attr("checked")})}});if(r){var q=this.dataItem(o.data("tr")||o);for(var p in this.dataKeys){s[this.ws?p:this.dataKeys[p]]=this.valueFor({member:p})(q)}}return s},cancelRow:function(o){if(!o.length){return}if(o.is(".t-grid-new-row")){o.remove();return}var q=this.dataItem(o);var r=new l.stringBuilder();var p=o.find(".t-hierarchy-cell").find(".t-icon").hasClass("t-plus");r.rep('<td class="t-groupcell" />',this.groups.length).catIf('<td class="t-hierarchy-cell"><a href="#" class="t-icon '+(p?"t-plus":"t-minus")+'"></a></td>',this.detail);h.each(this.columns,h.proxy(function(s,t){r.cat("<td").cat(t.attr).catIf(' class="t-last"',s==this.columns.length-1).cat(">");if(t.display){r.cat(t.display(q))}this.appendCommandHtml(t.commands,r);r.cat("</td>")},this));o.html(r.string());l.trigger(this.element,"rowDataBound",{row:o[0],dataItem:q})},form:function(r,o,s){var p=this.$tbody.siblings("colgroup");var t=this.editing.mode;if(t!="PopUp"){r.cat('<td class="t-edit-container" colspan="').cat(this.columns.length+this.groups.length+(this.detail?1:0)).cat('">')}r.cat('<form class="t-edit-form" action="#" method="post" id="').cat(this.formId()).cat('">');if(t=="InLine"){r.cat('<table cellspacing="0"><colgroup>');this.$tbody.siblings("colgroup").children().each(function(){var u=h(this).css("width");if(u!="0px"){r.cat('<col style="width:').cat(u).cat('" />')}else{r.cat("<col />")}});var q=new l.stringBuilder();q.cat('<td class="t-hierarchy-cell">').catIf('<a href="#" class="t-icon '+(s?"t-plus":"t-minus")+'"></a>',s!=undefined).cat("</td>");r.cat("</colgroup><tbody><tr>").rep('<td class="t-groupcell" />',this.groups.length).catIf(q.string(),this.detail);h.each(this.columns,h.proxy(function(u,v){r.cat("<td").cat(v.attr).catIf(' class="t-last"',u==this.columns.length-1).cat(">").catIf(v.editor,v.editor).catIf(" ",!v.editor&&!v.commands);if(v.commands){this.appendCommandHtml(o,r)}r.cat("</td>")},this));r.cat("</tr></tbody></table>")}else{r.cat('<div class="t-edit-form-container">').cat(this.editing.editor).cat("<div>");h.each(this.columns,h.proxy(function(u,v){if(v.commands){this.appendCommandHtml(o,r)}},this));r.cat("</div></div>")}r.cat("</form>");r.catIf("</td>",t!="PopUp")},save:function(o,p){h(o).closest("form").validate().form()&&p()},cancel:function(){this.cancelRow(h("#"+this.formId()).closest("tr"))},sendValues:function(s,o){if(this.ws){for(var p in s){var r=this.columnFromMember(p);if(r&&r.type=="Date"){var q=l.datetime.parse(s[p],l.cultureInfo.shortDate).toDate();s[p]="\\/Date("+q.getTime()+")\\/"}}}h.ajax(this.ajaxOptions({data:this.ws?{value:s}:s,url:this.url(o)}))},formId:function(){return h(this.element).attr("id")+"form"},validation:function(){if(window.mvcClientValidationMetadata){var o=this.formId();var p=h.grep(window.mvcClientValidationMetadata,function(q){return q.FormId==o})[0];if(p){p.Fields=h.grep(p.Fields,h.proxy(function(q){var r=this.columnFromMember(q.FieldName);return !r||r.type!="Boolean"},this));i(p)}}}}})(jQuery); |