16 lines
5.4 KiB
JavaScript
16 lines
5.4 KiB
JavaScript
/**
|
|
* Copyright 2014 Telerik AD
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
!function(e,define){define(["./kendo.datepicker.min","./kendo.numerictextbox.min","./kendo.validator.min","./kendo.binder.min"],e)}(function(){return function(e,t){function n(t){return t=null!=t?t:"",t.type||e.type(t)||"string"}function i(t){t.find(":input:not(:button, ["+s.attr("role")+"=upload], ["+s.attr("skip")+"], [type=file]), select").each(function(){var t=s.attr("bind"),n=this.getAttribute(t)||"",i="checkbox"===this.type||"radio"===this.type?"checked:":"value:",r=this.name;-1===n.indexOf(i)&&r&&(n+=(n.length?",":"")+i+r,e(this).attr(t,n))})}function r(e){var t,i,r=(e.model.fields||e.model)[e.field],a=n(r),o=r?r.validation:{},l=s.attr("type"),u=s.attr("bind"),c={name:e.field};for(t in o)i=o[t],h(t,_)>=0?c[l]=t:f(i)||(c[t]=p(i)?i.value||t:i),c[s.attr(t+"-msg")]=i.message;return h(a,_)>=0&&(c[l]=a),c[u]=("boolean"===a?"checked:":"value:")+e.field,c}function a(e){var t,n,i,r,a,o;if(e&&e.length)for(o=[],t=0,n=e.length;n>t;t++)i=e[t],a=i.text||i.value||i,r=null==i.value?i.text||i:i.value,o[t]={text:a,value:r};return o}function o(e,t){var n,i,r=e?e.validation||{}:{};for(n in r)i=r[n],p(i)&&i.value&&(i=i.value),f(i)&&(t[n]=i)}var s=window.kendo,l=s.ui,u=l.Widget,c=e.extend,d=s.support.browser.msie&&9>s.support.browser.version,f=s.isFunction,p=e.isPlainObject,h=e.inArray,g=/("|\%|'|\[|\]|\$|\.|\,|\:|\;|\+|\*|\&|\!|\#|\(|\)|<|>|\=|\?|\@|\^|\{|\}|\~|\/|\||`)/g,m='<div class="k-widget k-tooltip k-tooltip-validation" style="margin:0.5em"><span class="k-icon k-warning"> </span>#=message#<div class="k-callout k-callout-n"></div></div>',v="change",_=["url","email","number","date","boolean"],b={number:function(t,n){var i=r(n);e('<input type="text"/>').attr(i).appendTo(t).kendoNumericTextBox({format:n.format}),e("<span "+s.attr("for")+'="'+n.field+'" class="k-invalid-msg"/>').hide().appendTo(t)},date:function(t,n){var i=r(n),a=n.format;a&&(a=s._extractFormat(a)),i[s.attr("format")]=a,e('<input type="text"/>').attr(i).appendTo(t).kendoDatePicker({format:n.format}),e("<span "+s.attr("for")+'="'+n.field+'" class="k-invalid-msg"/>').hide().appendTo(t)},string:function(t,n){var i=r(n);e('<input type="text" class="k-input k-textbox"/>').attr(i).appendTo(t)},"boolean":function(t,n){var i=r(n);e('<input type="checkbox" />').attr(i).appendTo(t)},values:function(t,n){var i=r(n);e("<select "+s.attr("text-field")+'="text"'+s.attr("value-field")+'="value"'+s.attr("source")+"='"+s.stringify(a(n.values)).replace(/\'/g,"'")+"'"+s.attr("role")+'="dropdownlist"/>').attr(i).appendTo(t),e("<span "+s.attr("for")+'="'+n.field+'" class="k-invalid-msg"/>').hide().appendTo(t)}},k=u.extend({init:function(t,n){var i=this;n.target&&(n.$angular=n.target.options.$angular),u.fn.init.call(i,t,n),i._validateProxy=e.proxy(i._validate,i),i.refresh()},events:[v],options:{name:"Editable",editors:b,clearContainer:!0,errorTemplate:m},editor:function(e,t){var i=this,r=i.options.editors,a=p(e),o=a?e.field:e,l=i.options.model||{},u=a&&e.values,d=u?"values":n(t),f=a&&e.editor,h=f?e.editor:r[d],m=i.element.find("["+s.attr("container-for")+"="+o.replace(g,"\\$1")+"]");h=h?h:r.string,f&&"string"==typeof e.editor&&(h=function(t){t.append(e.editor)}),m=m.length?m:i.element,h(m,c(!0,{},a?e:{field:o},{model:l}))},_validate:function(t){var n,i=this,r=t.value,a=i._validationEventInProgress,o={},l=s.attr("bind"),u=t.field.replace(g,"\\$1"),c="checked:"+u,d="value:"+u;o[t.field]=t.value,n=e(":input["+l+'*="'+d+'"],:input['+l+'*="'+c+'"]',i.element).filter("["+s.attr("validate")+"!='false']"),n.length>1&&(n=n.filter(function(){var t=e(this),n=t.attr(l).split(","),i=h(d,n)>=0||h(c,n)>=0;return i&&(!t.is(":radio")||t.val()==r)}));try{i._validationEventInProgress=!0,(!i.validatable.validateInput(n)||!a&&i.trigger(v,{values:o}))&&t.preventDefault()}finally{i._validationEventInProgress=!1}},end:function(){return this.validatable.validate()},destroy:function(){var e=this;e.angular("cleanup",function(){return{elements:e.element}}),u.fn.destroy.call(e),e.options.model.unbind("set",e._validateProxy),s.unbind(e.element),e.validatable&&e.validatable.destroy(),s.destroy(e.element),e.element.removeData("kendoValidator")},refresh:function(){var n,r,a,l,u,c,f,h,g=this,m=g.options.fields||[],v=g.options.clearContainer?g.element.empty():g.element,_=g.options.model||{},b={};for(g.options.target&&g.angular("compile",function(){return{elements:v,data:[{dataItem:_}]}}),e.isArray(m)||(m=[m]),n=0,r=m.length;r>n;n++)a=m[n],l=p(a),u=l?a.field:a,c=(_.fields||_)[u],o(c,b),g.editor(a,c);if(!r){f=_.fields||_;for(u in f)o(f[u],b)}i(v),g.validatable&&g.validatable.destroy(),s.bind(v,g.options.model),g.options.model.unbind("set",g._validateProxy),g.options.model.bind("set",g._validateProxy),g.validatable=new s.ui.Validator(v,{validateOnBlur:!1,errorTemplate:g.options.errorTemplate||t,rules:b}),h=v.find(":kendoFocusable").eq(0).focus(),d&&h.focus()}});l.plugin(k)}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()}); |