/* * Kendo UI Web v2012.3.1114 (http://kendoui.com) * Copyright 2012 Telerik AD. All rights reserved. * * Kendo UI Web commercial licenses may be obtained at * https://www.kendoui.com/purchase/license-agreement/kendo-ui-web-commercial.aspx * 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(e,t){var a=window.kendo,r="change",n="dataBound",i="dataBinding",l=a.ui.Widget,o=a.keys,s=">*",d="requestStart",c="error",u="k-state-focused",m="k-state-selected",f="k-edit-item",p="string",v="edit",b="remove",g="save",h="click",_=".kendoListView",S=e.proxy,E=a.ui.progress,w=a.data.DataSource,y=l.extend({init:function(t,r){var n=this;r=e.isArray(r)?{dataSource:r}:r,l.fn.init.call(n,t,r),r=n.options,n.wrapper=t=n.element,t[0].id&&(n._itemId=t[0].id+"_lv_active"),n._element(),n._dataSource(),n.template=a.template(r.template||""),n.altTemplate=a.template(r.altTemplate||r.template),n.editTemplate=a.template(r.editTemplate||""),n._navigatable(),n._selectable(),n._pageable(),n._crudHandlers(),n.options.autoBind&&n.dataSource.fetch(),a.notify(n)},events:[r,i,n,v,b,g],options:{name:"ListView",autoBind:!0,selectable:!1,navigatable:!1,template:"",altTemplate:"",editTemplate:""},_item:function(e){return this.element.children()[e]()},items:function(){return this.element.children()},setDataSource:function(e){this.options.dataSource=e,this._dataSource(),this.options.autoBind&&e.fetch()},_unbindDataSource:function(){var e=this;e.dataSource.unbind(r,e._refreshHandler).unbind(d,e._requestStartHandler).unbind(c,e._errorHandler)},_dataSource:function(){var e=this;e.dataSource&&e._refreshHandler?e._unbindDataSource():(e._refreshHandler=S(e.refresh,e),e._requestStartHandler=S(e._requestStart,e),e._errorHandler=S(e._error,e)),e.dataSource=w.create(e.options.dataSource).bind(r,e._refreshHandler).bind(d,e._requestStartHandler).bind(c,e._errorHandler)},_requestStart:function(){E(this.element,!0)},_error:function(){E(this.element,!1)},_element:function(){this.element.addClass("k-widget k-listview").attr("role","listbox")},refresh:function(r){var l,o,s,d,c,u=this,m=u.dataSource.view(),f="",p=u.template,v=u.altTemplate;if(r&&"itemchange"===r.action)return u.editable||(l=r.items[0],d=e.inArray(l,m),d>=0&&(s=e(p(l)).attr(a.attr("uid"),l.uid),u.items().eq(d).replaceWith(s),u.trigger("itemChange",{item:s,data:l}))),t;if(r=r||{},!u.trigger(i,{action:r.action||"rebind",items:r.items,index:r.index})){for(u._destroyEditable(),d=0,c=m.length;c>d;d++)f+=d%2?v(m[d]):p(m[d]);for(u.element.html(f),o=u.items(),d=0,c=m.length;c>d;d++)o.eq(d).attr(a.attr("uid"),m[d].uid).attr("role","option").attr("aria-selected","false");u.element[0]===document.activeElement&&u.options.navigatable&&u.current(o.eq(0)),u.trigger(n)}},_pageable:function(){var t,r,n=this,i=n.options.pageable;e.isPlainObject(i)&&(r=i.pagerId,t=e.extend({},i,{dataSource:n.dataSource,pagerId:null}),n.pager=new a.ui.Pager(e("#"+r),t))},_selectable:function(){var e,n,i=this,l=i.options.selectable,d=i.options.navigatable;l&&(e=typeof l===p&&l.toLowerCase().indexOf("multiple")>-1,e&&i.element.attr("aria-multiselectable",!0),i.selectable=new a.ui.Selectable(i.element,{aria:!0,multiple:e,filter:s,change:function(){i.trigger(r)}}),d&&i.element.on("keydown"+_,function(a){if(a.keyCode===o.SPACEBAR){if(n=i.current(),a.target==a.currentTarget&&a.preventDefault(),e)if(a.ctrlKey){if(n&&n.hasClass(m))return n.removeClass(m),t}else i.selectable.clear();else i.selectable.clear();i.selectable.value(n)}}))},current:function(e){var a=this,r=a.element,n=a._current;return e===t?n:(n&&(n.removeClass(u).removeAttr("id"),r.removeAttr("aria-activedescendant")),e&&e[0]&&(a._scrollTo(e[0]),r.attr("aria-activedescendant",a._itemId),e.addClass(u).attr("id",a._itemId)),a._current=e,t)},_scrollTo:function(t){var a,r=this,n=!1,i="scroll";"auto"==r.wrapper.css("overflow")||r.wrapper.css("overflow")==i?a=r.wrapper[0]:(a=window,n=!0);var l=function(r,l){var o=n?e(t).offset()[r.toLowerCase()]:t["offset"+r],s=t["client"+l],d=e(a)[i+r](),c=e(a)[l.toLowerCase()]();o+s>d+c?e(a)[i+r](o+s-c):d>o&&e(a)[i+r](o)};l("Top","Height"),l("Left","Width")},_navigatable:function(){var t=this,r=t.options.navigatable,n=t.element,i=function(a){t.current(e(a.currentTarget)),e(a.target).is(":button,a,:input,a>.k-icon,textarea")||n.focus()};r&&(t._tabindex(),n.on("focus"+_,function(){var e=t._current;e&&e.is(":visible")||(e=t._item("first")),t.current(e)}).on("focusout"+_,function(){t._current&&t._current.removeClass(u)}).on("keydown"+_,function(r){var i,l=r.keyCode,s=t.current(),d=e(r.target),c=!d.is(":button,textarea,a,a>.t-icon,input"),u=d.is(":text"),m=a.preventDefault,p=n.find("."+f);if(!(!c&&!u&&o.ESC!=l||u&&o.ESC!=l&&o.ENTER!=l))if(o.UP===l||o.LEFT===l)s&&(s=s.prev()),t.current(s&&s[0]?s:t._item("last")),m(r);else if(o.DOWN===l||o.RIGHT===l)s&&(s=s.next()),t.current(s&&s[0]?s:t._item("first")),m(r);else if(o.PAGEUP===l)t.current(null),t.dataSource.page(t.dataSource.page()-1),m(r);else if(o.PAGEDOWN===l)t.current(null),t.dataSource.page(t.dataSource.page()+1),m(r);else if(o.HOME===l)t.current(t._item("first")),m(r);else if(o.END===l)t.current(t._item("last")),m(r);else if(o.ENTER===l)if(0!==p.length&&(c||u)){i=t.items().index(p),document.activeElement.blur(),t.save();var v=function(){t.element.trigger("focus"),t.current(t.items().eq(i))};t.one("dataBound",v)}else""!==t.options.editTemplate&&t.edit(s);else if(o.ESC===l){if(p=n.find("."+f),0===p.length)return;i=t.items().index(p),t.cancel(),t.element.trigger("focus"),t.current(t.items().eq(i))}}),n.on("mousedown"+_+" touchstart"+_,s,S(i,t)))},clearSelection:function(){var e=this;e.selectable.clear(),e.trigger(r)},select:function(a){var r=this,n=r.selectable;return a=e(a),a.length?(n.options.multiple||(n.clear(),a=a.first()),n.value(a),t):n.value()},_destroyEditable:function(){var e=this;e.editable&&(e.editable.destroy(),delete e.editable)},_modelFromElement:function(e){var t=e.attr(a.attr("uid"));return this.dataSource.getByUid(t)},_closeEditable:function(t){var r,n,i=this,l=i.editable,o=!0;return l&&(t&&(o=l.end()),o&&(r=i._modelFromElement(l.element),n=e(i.template(r)).attr(a.attr("uid"),r.uid),i._destroyEditable(),l.element.replaceWith(n))),o},edit:function(t){var r=this,n=r._modelFromElement(t),i=e(r.editTemplate(n)).addClass(f);r.cancel(),i.attr(a.attr("uid"),n.uid),t.replaceWith(i),r.editable=i.kendoEditable({model:n,clearContainer:!1,errorTemplate:!1}).data("kendoEditable"),r.trigger(v,{model:n,item:i})},save:function(){var e=this,t=e.editable.element,a=e._modelFromElement(t);!e.trigger(g,{model:a,item:t})&&e._closeEditable(!0)&&e.dataSource.sync()},remove:function(e){var t=this,a=t.dataSource,r=t._modelFromElement(e);t.trigger(b,{model:r,item:e})||(e.hide(),a.remove(r),a.sync())},add:function(){var e=this,t=e.dataSource,a=t.indexOf((t.view()||[])[0]);0>a&&(a=0),e.cancel(),t.insert(a,{}),e.edit(e.element.children().first())},cancel:function(){var e=this,t=e.dataSource;e.editable&&(t.cancelChanges(e._modelFromElement(e.editable.element)),e._closeEditable(!1))},_crudHandlers:function(){var t=this,r="touchend"+_+" "+h+_;t.element.on(r,".k-edit-button",function(r){var n=e(this).closest("["+a.attr("uid")+"]");t.edit(n),r.preventDefault()}),t.element.on(r,".k-delete-button",function(r){var n=e(this).closest("["+a.attr("uid")+"]");t.remove(n),r.preventDefault()}),t.element.on(r,".k-update-button",function(e){t.save(),e.preventDefault()}),t.element.on(r,".k-cancel-button",function(e){t.cancel(),e.preventDefault()})},destroy:function(){var e=this;l.fn.destroy.call(e),e._unbindDataSource(),e._destroyEditable(),e.element.off(_),e.pager&&e.pager.destroy(),e.selectable&&e.selectable.destroy(),a.destroy(e.element)}});a.ui.plugin(y)})(window.kendo.jQuery);