/*
* Kendo UI v2015.3.1111 (http://www.telerik.com/kendo-ui)
* Copyright 2015 Telerik AD. All rights reserved.
*
* Kendo UI commercial licenses may be obtained at
* http://www.telerik.com/purchase/license-agreement/kendo-ui-complete
* If you do not own a commercial license, this file shall be governed by the trial license terms.
*/
!function(e,define){define(["./kendo.listview.min","./kendo.dropdownlist.min","./kendo.upload.min"],e)}(function(){return function(e,t){function n(e,t,n){var i,o;e.on("dragenter"+k,function(){t(),o=new Date,i||(i=setInterval(function(){var e=new Date-o;e>100&&(n(),clearInterval(i),i=null)},100))}).on("dragover"+k,function(){o=new Date})}function i(e,n){return e!==t&&e.match(/\/$/)||(e=(e||"")+"/"),e+n}function o(e){if(!e)return"";var t=" bytes";return e>=1073741824?(t=" GB",e/=1073741824):e>=1048576?(t=" MB",e/=1048576):e>=1024&&(t=" KB",e/=1024),Math.round(100*e)/100+t}function r(e,t){var n=e[t];return d(n)?n.from||n.field||t:n}var s,a,l,c,h=window.kendo,u=h.ui.Widget,d=e.isPlainObject,f=e.proxy,p=e.extend,g=h.support.placeholder,m=h.support.browser,v=h.isFunction,_=/(^\/|\/$)/g,w="change",y="apply",b="error",x="click",k=".kendoFileBrowser",C=".kendoBreadcrumbs",S=".kendoSearchBox",T="name",A="size",D="type",M={field:D,dir:"asc"},E=h.template('
${text}
'),P='
# if (showUpload) { #
#=messages.uploadFile#
# } ## if (showCreate) { ## } ## if (showDelete) { # # } #
';p(!0,h.data,{schemas:{filebrowser:{data:function(e){return e.items||e||[]},model:{id:"name",fields:{name:"name",size:"size",type:"type"}}}}}),p(!0,h.data,{transports:{filebrowser:h.data.RemoteTransport.extend({init:function(t){h.data.RemoteTransport.fn.init.call(this,e.extend(!0,{},this.options,t))},_call:function(t,n){n.data=e.extend({},n.data,{path:this.options.path()}),v(this.options[t])?this.options[t].call(this,n):h.data.RemoteTransport.fn[t].call(this,n)},read:function(e){this._call("read",e)},create:function(e){this._call("create",e)},destroy:function(e){this._call("destroy",e)},update:function(){},options:{read:{type:"POST"},update:{type:"POST"},create:{type:"POST"},destroy:{type:"POST"}}})}}),s=m.msie&&8>m.version?function(e){return e.offsetTop}:function(t){return t.offsetTop-e(t).height()},a=u.extend({init:function(e,t){var n=this;t=t||{},u.fn.init.call(n,e,t),n.element.addClass("k-filebrowser"),n.element.on(x+k,".k-filebrowser-toolbar button:not(.k-state-disabled):has(.k-delete)",f(n._deleteClick,n)).on(x+k,".k-filebrowser-toolbar button:not(.k-state-disabled):has(.k-addfolder)",f(n._addClick,n)).on("keydown"+k,"li.k-state-selected input",f(n._directoryKeyDown,n)).on("blur"+k,"li.k-state-selected input",f(n._directoryBlur,n)),n._dataSource(),n.refresh(),n.path(n.options.path)},options:{name:"FileBrowser",messages:{uploadFile:"Upload",orderBy:"Arrange by",orderByName:"Name",orderBySize:"Size",directoryNotFound:"A directory with this name was not found.",emptyFolder:"Empty Folder",deleteFile:'Are you sure you want to delete "{0}"?',invalidFileType:'The selected file "{0}" is not valid. Supported file types are {1}.',overwriteFile:'A file with name "{0}" already exists in the current directory. Do you want to overwrite it?',dropFilesHere:"drop file here to upload",search:"Search"},transport:{},path:"/",fileTypes:"*.*"},events:[b,w,y],destroy:function(){var e=this;u.fn.destroy.call(e),e.dataSource.unbind(b,e._errorHandler),e.element.add(e.list).add(e.toolbar).off(k),h.destroy(e.element)},value:function(){var e,n=this,o=n._selectedItem(),r=n.options.transport.fileUrl;return o&&"f"===o.get(D)?(e=i(n.path(),o.get(T)).replace(_,""),r&&(e=v(r)?r(e):h.format(r,encodeURIComponent(e))),e):t},_selectedItem:function(){var e=this.listView,n=e.select();return n.length?this.dataSource.getByUid(n.attr(h.attr("uid"))):t},_toolbar:function(){var t=this,n=h.template(P),i=t.options.messages,o=[{text:i.orderByName,value:"name"},{text:i.orderBySize,value:"size"}];t.toolbar=e(n({messages:i,showUpload:t.options.transport.uploadUrl,showCreate:t.options.transport.create,showDelete:t.options.transport.destroy})).appendTo(t.element).find(".k-upload input").kendoUpload({multiple:!1,localization:{dropFilesHere:i.dropFilesHere},async:{saveUrl:t.options.transport.uploadUrl,autoUpload:!0},upload:f(t._fileUpload,t),error:function(e){t._error({xhr:e.XMLHttpRequest,status:"error"})}}).end(),t.upload=t.toolbar.find(".k-upload input").data("kendoUpload"),t.arrangeBy=t.toolbar.find(".k-tiles-arrange select").kendoDropDownList({dataSource:o,dataTextField:"text",dataValueField:"value",change:function(){t.orderBy(this.value())}}).data("kendoDropDownList"),t._attachDropzoneEvents()},_attachDropzoneEvents:function(){var t=this;t.options.transport.uploadUrl&&(n(e(document.documentElement),e.proxy(t._dropEnter,t),e.proxy(t._dropLeave,t)),t._scrollHandler=f(t._positionDropzone,t))},_dropEnter:function(){this._positionDropzone(),e(document).on("scroll"+k,this._scrollHandler)},_dropLeave:function(){this._removeDropzone(),e(document).off("scroll"+k,this._scrollHandler)},_positionDropzone:function(){var e=this,t=e.element,n=t.offset();e.toolbar.find(".k-dropzone").addClass("k-filebrowser-dropzone").offset(n).css({width:t[0].clientWidth,height:t[0].clientHeight,lineHeight:t[0].clientHeight+"px"})},_removeDropzone:function(){this.toolbar.find(".k-dropzone").removeClass("k-filebrowser-dropzone").css({width:"",height:"",lineHeight:"",top:"",left:""})},_deleteClick:function(){var e=this,t=e.listView.select(),n=h.format(e.options.messages.deleteFile,t.find("strong").text());t.length&&e._showMessage(n,"confirm")&&e.listView.remove(t)},_addClick:function(){this.createDirectory()},_getFieldName:function(e){return r(this.dataSource.reader.model.fields,e)},_fileUpload:function(e){var t,n=this,i=n.options,o=i.fileTypes,r=RegExp(("("+o.split(",").join(")|(")+")").replace(/\*\./g,".*."),"i"),s=e.files[0].name,a=T,l=A;r.test(s)?(e.data={path:n.path()},t=n._createFile(s),t?n.upload.one("success",function(e){t.set(a,e.response[n._getFieldName(a)]),t.set(l,e.response[n._getFieldName(l)]),n._tiles=n.listView.items().filter("["+h.attr("type")+"=f]")}):e.preventDefault()):(e.preventDefault(),n._showMessage(h.format(i.messages.invalidFileType,s,o)))},_findFile:function(e){var t,n,i,o=this.dataSource.data(),r=D,s=T;for(e=e.toLowerCase(),t=0,i=o.length;i>t;t++)if("f"===o[t].get(r)&&o[t].get(s).toLowerCase()===e){n=o[t];break}return n},_createFile:function(e){var t,n,i=this,o=0,r={},s=D,a=i.dataSource.view(),l=i._findFile(e);if(l&&!i._showMessage(h.format(i.options.messages.overwriteFile,e),"confirm"))return null;if(l)return l;for(t=0,n=a.length;n>t;t++)if("f"===a[t].get(s)){o=t;break}return r[s]="f",r[T]=e,r[A]=0,i.dataSource.insert(++o,r)},createDirectory:function(){var e,t,n=this,i=0,o=D,r=T,s=n.dataSource.data(),a=n._nameDirectory(),l=new n.dataSource.reader.model;for(e=0,t=s.length;t>e;e++)"d"===s[e].get(o)&&(i=e);l.set(o,"d"),l.set(r,a),n.listView.one("dataBound",function(){var e=n.listView.items().filter("["+h.attr("uid")+"="+l.uid+"]"),t=e.find("input");e.length&&this.edit(e),this.element.scrollTop(e.attr("offsetTop")-this.element[0].offsetHeight),setTimeout(function(){t.select()})}).one("save",function(e){var t=e.model.get(r);t?e.model.set(r,n._nameExists(t,l.uid)?n._nameDirectory():t):e.model.set(r,a)}),n.dataSource.insert(++i,l)},_directoryKeyDown:function(e){13==e.keyCode&&e.currentTarget.blur()},_directoryBlur:function(){this.listView.save()},_nameExists:function(e,t){var n,i,o=this.dataSource.data(),r=D,s=T;for(n=0,i=o.length;i>n;n++)if("d"===o[n].get(r)&&o[n].get(s).toLowerCase()===e.toLowerCase()&&o[n].uid!==t)return!0;return!1},_nameDirectory:function(){var t,n,i,o="New folder",r=this.dataSource.data(),s=[],a=D,l=T;for(n=0,i=r.length;i>n;n++)"d"===r[n].get(a)&&r[n].get(l).toLowerCase().indexOf(o.toLowerCase())>-1&&s.push(r[n].get(l));if(e.inArray(o,s)>-1){n=2;do t=o+" ("+n+")",n++;while(e.inArray(t,s)>-1);o=t}return o},orderBy:function(e){this.dataSource.sort([{field:D,dir:"asc"},{field:e,dir:"asc"}])},search:function(e){this.dataSource.filter({field:T,operator:"contains",value:e})},_content:function(){var t=this;t.list=e('
').appendTo(t.element).on("dblclick"+k,"li",f(t._dblClick,t)),t.listView=new h.ui.ListView(t.list,{dataSource:t.dataSource,template:t._itemTmpl(),editTemplate:t._editTmpl(),selectable:!0,autoBind:!1,dataBinding:function(e){t.toolbar.find(".k-delete").parent().addClass("k-state-disabled"),("remove"===e.action||"sync"===e.action)&&e.preventDefault()},dataBound:function(){t.dataSource.view().length?t._tiles=this.items().filter("["+h.attr("type")+"=f]"):this.wrapper.append(E({text:t.options.messages.emptyFolder}))},change:f(t._listViewChange,t)})},_dblClick:function(t){var n,o=this,r=e(t.currentTarget);r.hasClass("k-edit-item")&&o._directoryBlur(),r.filter("["+h.attr("type")+"=d]").length?(n=o.dataSource.getByUid(r.attr(h.attr("uid"))),n&&(o.path(i(o.path(),n.get(T))),o.breadcrumbs.value(o.path()))):r.filter("["+h.attr("type")+"=f]").length&&o.trigger(y)},_listViewChange:function(){var e=this._selectedItem();e&&(this.toolbar.find(".k-delete").parent().removeClass("k-state-disabled"),"f"===e.get(D)&&this.trigger(w))},_dataSource:function(){var e,t=this,n=t.options,i=n.transport,o=p({},M),r={field:T,dir:"asc"},s={type:i.type||"filebrowser",sort:[o,r]};d(i)&&(i.path=f(t.path,t),s.transport=i),d(n.schema)?s.schema=n.schema:i.type&&d(h.data.schemas[i.type])&&(e=h.data.schemas[i.type]),t.dataSource&&t._errorHandler?t.dataSource.unbind(b,t._errorHandler):t._errorHandler=f(t._error,t),t.dataSource=h.data.DataSource.create(s).bind(b,t._errorHandler)},_navigation:function(){var t=this,n=e('').appendTo(this.element);t.breadcrumbs=n.find("input:first").kendoBreadcrumbs({value:t.options.path,change:function(){t.path(this.value())}}).data("kendoBreadcrumbs"),t.searchBox=n.parent().find("input:last").kendoSearchBox({label:t.options.messages.search,change:function(){t.search(this.value())}}).data("kendoSearchBox")},_error:function(e){var t,n=this;n.trigger(b,e)||(t=e.xhr.status,"error"==e.status?"404"==t?n._showMessage(n.options.messages.directoryNotFound):"0"!=t&&n._showMessage("Error! The requested URL returned "+t+" - "+e.xhr.statusText):"timeout"==t&&n._showMessage("Error! Server timeout."))},_showMessage:function(e,t){return window[t||"alert"](e)},refresh:function(){var e=this;e._navigation(),e._toolbar(),e._content()},_editTmpl:function(){var e='