/* * Kendo UI Web v2012.2.710 (http://kendoui.com) * Copyright 2012 Telerik AD. All rights reserved. * * Kendo UI Web commercial licenses may be obtained at http://kendoui.com/web-license * If you do not own a commercial license, this file shall be governed by the * GNU General Public License (GPL) version 3. * For GPL requirements, please review: http://www.gnu.org/copyleft/gpl.html */ ;(function(a,b){var c=window.kendo,d="change",e="dataBound",f="dataBinding",g=c.ui.Widget,h=c.keys,i=">*",j="requestStart",k="error",l="k-state-focused",m="k-focusable",n="k-state-selected",o="k-edit-item",p="string",q="edit",r="remove",s="save",t="click",u=a.proxy,v=c.ui.progress,w=c.data.DataSource,x=g.extend({init:function(b,d){var e=this;d=a.isArray(d)?{dataSource:d}:d,g.fn.init.call(e,b,d),d=e.options,e.wrapper=e.element,e._element(),e._dataSource(),e.template=c.template(d.template||""),e.altTemplate=c.template(d.altTemplate||d.template),e.editTemplate=c.template(d.editTemplate||""),e._navigatable(),e._selectable(),e._pageable(),e._crudHandlers(),e.options.autoBind&&e.dataSource.fetch(),c.notify(e)},events:[d,f,e,q,r,s],options:{name:"ListView",autoBind:!0,selectable:!1,navigatable:!1,template:"",altTemplate:"",editTemplate:""},items:function(){return this.element.find(i)},setDataSource:function(a){this.options.dataSource=a,this._dataSource(),this.options.autoBind&&a.fetch()},_dataSource:function(){var a=this;a.dataSource&&a._refreshHandler?a.dataSource.unbind(d,a._refreshHandler).unbind(j,a._requestStartHandler).unbind(k,a._errorHandler):(a._refreshHandler=u(a.refresh,a),a._requestStartHandler=u(a._requestStart,a),a._errorHandler=u(a._error,a)),a.dataSource=w.create(a.options.dataSource).bind(d,a._refreshHandler).bind(j,a._requestStartHandler).bind(k,a._errorHandler)},_requestStart:function(){v(this.element,!0)},_error:function(){v(this.element,!1)},_element:function(){this.element.addClass("k-widget k-listview")},refresh:function(b){var d=this,g=d.dataSource.view(),h,i,j,k="",l,m,n=d.template,o=d.altTemplate;if(b&&b.action==="itemchange")d.editable||(h=b.items[0],l=g.indexOf(h),l>=0&&(j=a(n(h)),d.items().eq(l).replaceWith(j),d.trigger("itemChange",{item:j,data:h})));else{d.trigger(f),d._destroyEditable();for(l=0,m=g.length;l-1,a.selectable=new c.ui.Selectable(a.element,{multiple:b,filter:i,change:function(){a.trigger(d)}}),g&&a.element.keydown(function(c){c.keyCode===h.SPACEBAR&&(e=a.current(),c.preventDefault(),b?c.ctrlKey?e.hasClass(n)&&(e.removeClass(n),e=null):a.selectable.clear():a.selectable.clear(),a.selectable.value(e))}))},current:function(a){var c=this,d=c._current;a!==b&&a.length&&(!d||d[0]!==a[0])&&(a.addClass(l),d&&d.removeClass(l),c._current=a);return c._current},_navigatable:function(){var b=this,c=b.options.navigatable,d=b.element,e=u(b.current,b),f=function(b){e(a(b.currentTarget)),a(b.target).is(":button,a,:input,a>.k-icon,textarea")||d.focus()};c&&(d.attr("tabIndex",Math.max(d.attr("tabIndex")||0,0)),d.bind({focus:function(){var a=b._current;a&&a.is(":visible")?a.addClass(l):e(d.find(i).first())},focusout:function(){b._current&&b._current.removeClass(l)},keydown:function(a){var c=a.keyCode,e=b.current();h.UP===c?b.current(e?e.prev():d.find(i).first()):h.DOWN===c?b.current(e?e.next():d.find(i).first()):h.PAGEUP==c?(b._current=null,b.dataSource.page(b.dataSource.page()-1)):h.PAGEDOWN==c&&(b._current=null,b.dataSource.page(b.dataSource.page()+1))}}),d.addClass(m).delegate("."+m+i,"mousedown",f))},clearSelection:function(){var a=this;a.selectable.clear(),a.trigger(d)},select:function(b){var c=this,d=c.selectable;b=a(b);if(b.length)d.options.multiple||(d.clear(),b=b.first()),d.value(b);else return d.value()},_destroyEditable:function(){var a=this;a.editable&&(a.editable.destroy(),delete a.editable)},_modelFromElement:function(a){var b=a.attr(c.attr("uid"));return this.dataSource.getByUid(b)},_closeEditable:function(b){var d=this,e=d.editable,f,g,h=!0;e&&(b&&(h=e.end()),h&&(f=d._modelFromElement(e.element),g=a(d.template(f)).attr(c.attr("uid"),f.uid),d._destroyEditable(),e.element.replaceWith(g)));return h},edit:function(b){var d=this,e=d._modelFromElement(b),f=a(d.editTemplate(e)).addClass(o);d.cancel(),f.attr(c.attr("uid"),e.uid),b.replaceWith(f),d.editable=f.kendoEditable({model:e,clearContainer:!1,errorTemplate:!1}).data("kendoEditable"),d.trigger(q,{model:e,item:f})},save:function(){var a=this,b=a.editable.element,c=a._modelFromElement(b);!a.trigger(s,{model:c,item:b})&&a._closeEditable(!0)&&a.dataSource.sync()},remove:function(a){var b=this,c=b.dataSource,d=b._modelFromElement(a);b.trigger(r,{model:d,item:a})||(a.hide(),c.remove(d),c.sync())},add:function(){var a=this,b=a.dataSource,c=b.indexOf((b.view()||[])[0]);c<0&&(c=0),a.cancel(),b.insert(c,{}),a.edit(a.element.children().first())},cancel:function(){var a=this,b=a.dataSource;a.editable&&(b.cancelChanges(a._modelFromElement(a.editable.element)),a._closeEditable(!1))},_crudHandlers:function(){var b=this;b.element.on(t,".k-edit-button",function(d){var e=a(this).closest("["+c.attr("uid")+"]");b.edit(e),d.preventDefault()}),b.element.on(t,".k-delete-button",function(d){var e=a(this).closest("["+c.attr("uid")+"]");b.remove(e),d.preventDefault()}),b.element.on(t,".k-update-button",function(a){b.save(),a.preventDefault()}),b.element.on(t,".k-cancel-button",function(a){b.cancel(),a.preventDefault()})}});c.ui.plugin(x)})(jQuery);