Ext.namespace("Zarafa.plugins.files");Zarafa.plugins.files.ABOUT='<p>Copyright (C) 2005-2016  Zarafa B.V. &lt;info@zarafa.com&gt; and its licensors</p><p>Copyright (C) 2016 Kopano &lt;info@kopano.com&gt; and its licensors</p><p>This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.</p><p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.</p><p>You should have received a copy of the GNU Affero General Public License along with this program.  If not, see <a href="http://www.gnu.org/licenses/" target="_blank">http://www.gnu.org/licenses/</a>.</p>';
Ext.namespace("Zarafa.plugins.files");
Zarafa.plugins.files.FilesContext=Ext.extend(Zarafa.core.Context,{oldView:void 0,oldViewMode:void 0,accountsStore:void 0,constructor:function(a){a=a||{};Ext.applyIf(a,{current_view:Zarafa.plugins.files.data.Views.LIST,current_view_mode:Zarafa.plugins.files.data.ViewModes.RIGHT_PREVIEW});this.registerInsertionPoint("context.settings.categories",this.createSettingCategories,this);this.registerInsertionPoint("main.maintabbar.left",this.createMainTab,this);this.registerInsertionPoint("main.maintoolbar.new.item",this.createNewFilesButton,
this);this.registerInsertionPoint("main.toolbar.actions.last",this.createMainToolbarButtons,this);this.registerInsertionPoint("navigation.center",this.createFilesNavigationPanel,this);this.registerInsertionPoint("main.attachment.method",this.createAttachmentDownloadInsertionPoint,this);this.registerInsertionPoint("common.contextmenu.attachment.actions",this.createAttachmentUploadInsertionPoint,this);this.registerInsertionPoint("context.mail.contextmenu.actions",this.createEmailUploadInsertionPoint,
this);Zarafa.plugins.files.FilesContext.superclass.constructor.call(this,a);a=container.getNotificationResolver();Ext.isFunction(a.addIPFNotificationModule)&&a.addIPFNotificationModule("fileshierarchynotifier");Zarafa.core.data.SharedComponentType.addProperty("zarafa.plugins.files.attachdialog");Zarafa.core.data.SharedComponentType.addProperty("zarafa.plugins.files.createfolderdialog");Zarafa.core.data.SharedComponentType.addProperty("zarafa.plugins.files.fileinfopanel");Zarafa.core.data.SharedComponentType.addProperty("zarafa.plugins.files.sharedialog");
Zarafa.core.data.SharedComponentType.addProperty("zarafa.plugins.files.uploadstatusdialog");Zarafa.core.data.SharedComponentType.addProperty("zarafa.plugins.files.treecontextmenu");Zarafa.core.data.SharedComponentType.addProperty("common.dialog.attachments.files")},createMainTab:function(){return{text:this.getDisplayName(),tabOrderIndex:7,context:this.getName()}},createAttachmentDownloadInsertionPoint:function(a,b){return{text:dgettext("plugin_files","Add from Files"),handler:this.showFilesDownloadAttachmentDialog,
scope:b,context:this,iconCls:"icon_files_category",disabled:!this.isAccountsConfigured()}},showFilesDownloadAttachmentDialog:function(a){a=this.menu.activeItem;Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType["common.dialog.attachments.files"],this.record,{title:dgettext("plugin_files","Add attachment from Files"),modal:!0,model:a.context.getModel()})},isAccountsConfigured:function(){return-1!==this.getAccountsStore().findBy(function(a){if(a.get("status")===Zarafa.plugins.files.data.AccountRecordStatus.OK)return!0})},
createAttachmentUploadInsertionPoint:function(a,b){return{text:dgettext("plugin_files","Add to Files"),handler:this.showFilesUploadAttachmentDialog,scope:b,iconCls:"icon_files_category",beforeShow:this.onAttachmentUploadBeforeShow.createDelegate(this)}},onAttachmentUploadBeforeShow:function(a,b){a.setDisabled(b.isEmbeddedMessage());a.setDisabled(b.isTmpFile());a.setDisabled(!this.isAccountsConfigured())},showFilesUploadAttachmentDialog:function(a){var b=this.records,c=b.store;a=c.getParentRecord().get("store_entryid");
var d=c.getAttachmentParentRecordEntryId(),e=[];b.isUploaded()?e[0]=b.get("attach_num"):e[0]=b.get("tmpname");c=c.getId();b=b.get("name");a=[{entryid:d,store:a,attachNum:e,dialog_attachments:c,filename:b}];a={items:a,type:"attachment",count:a.length};d=this.activeItem.plugin.getModel();Zarafa.plugins.files.data.Actions.openSaveToFilesDialog(d,{response:a})},createEmailUploadInsertionPoint:function(a,b){return{text:dgettext("plugin_files","Add to Files"),handler:this.showFilesUploadEmailDialog,scope:b,
iconCls:"icon_files_category",disabled:!this.isAccountsConfigured()}},showFilesUploadEmailDialog:function(){var a=this.records;Array.isArray(a)||(a=[a]);for(var b=[],c=0,d=a.length;c<d;c++){var e=Ext.isEmpty(a[c].get("subject"))?dgettext("plugin_files","Untitled"):a[c].get("subject");b[c]={store:a[c].get("store_entryid"),entryid:a[c].get("entryid"),filename:e+".eml"}}a={items:b,type:"mail",count:b.length};b=this.activeItem.plugin.getModel();Zarafa.plugins.files.data.Actions.openSaveToFilesDialog(b,
{response:a})},createSettingCategories:function(){return{xtype:"filesplugin.settingsmaincategory",model:this.getModel(),store:this.getAccountsStore()}},getModel:function(){Ext.isDefined(this.model)||(this.model=new Zarafa.plugins.files.FilesContextModel({accountStore:this.getAccountsStore()}));return this.model},getAccountsStore:function(){Ext.isDefined(this.accountsStore)||(this.accountsStore=new Zarafa.plugins.files.data.AccountStore);return this.accountsStore},bid:function(a){return a instanceof
Zarafa.plugins.files.data.FilesFolderRecord?1:-1},bidSharedComponent:function(a,b){var c=-1;Ext.isArray(b)&&(b=b[0]);switch(a){case Zarafa.core.data.SharedComponentType["zarafa.plugins.files.attachdialog"]:case Zarafa.core.data.SharedComponentType["zarafa.plugins.files.fileinfopanel"]:case Zarafa.core.data.SharedComponentType["zarafa.plugins.files.sharedialog"]:case Zarafa.core.data.SharedComponentType["zarafa.plugins.files.uploadstatusdialog"]:case Zarafa.core.data.SharedComponentType["zarafa.plugins.files.treecontextmenu"]:case Zarafa.core.data.SharedComponentType["zarafa.plugins.files.createfolderdialog"]:case Zarafa.core.data.SharedComponentType["common.dialog.attachments.savetofiles"]:c=
1;break;case Zarafa.core.data.SharedComponentType["common.create"]:case Zarafa.core.data.SharedComponentType["common.view"]:case Zarafa.core.data.SharedComponentType["common.preview"]:b instanceof Zarafa.core.data.IPMRecord&&b.isMessageClass("IPM.Files",!0)&&(c=1);break;case Zarafa.core.data.SharedComponentType["common.dialog.attachments.files"]:b instanceof Zarafa.core.data.IPMRecord&&b.supportsAttachments()&&(c=1);break;case Zarafa.core.data.SharedComponentType["common.contextmenu"]:b instanceof
Zarafa.core.data.IPMRecord&&b.isMessageClass("IPM.Files",!0)&&(c=1)}return c},getSharedComponent:function(a,b){var c;switch(a){case Zarafa.core.data.SharedComponentType["zarafa.plugins.files.fileinfopanel"]:c=Zarafa.plugins.files.ui.dialogs.FilesRecordContentPanel;break;case Zarafa.core.data.SharedComponentType["common.create"]:c=Zarafa.plugins.files.ui.dialogs.FilesUploadContentPanel;break;case Zarafa.core.data.SharedComponentType["zarafa.plugins.files.createfolderdialog"]:c=Zarafa.plugins.files.ui.dialogs.CreateFolderContentPanel;
break;case Zarafa.core.data.SharedComponentType["zarafa.plugins.files.sharedialog"]:c=Zarafa.plugins.files.ui.dialogs.ShareContentPanel;break;case Zarafa.core.data.SharedComponentType["zarafa.plugins.files.uploadstatusdialog"]:c=Zarafa.plugins.files.ui.dialogs.UploadStatusContentPanel;break;case Zarafa.core.data.SharedComponentType["common.view"]:case Zarafa.core.data.SharedComponentType["common.preview"]:c=Zarafa.plugins.files.ui.FilesRecordViewPanel;break;case Zarafa.core.data.SharedComponentType["common.contextmenu"]:c=
Zarafa.plugins.files.ui.FilesMainContextMenu;break;case Zarafa.core.data.SharedComponentType["zarafa.plugins.files.treecontextmenu"]:c=Zarafa.plugins.files.ui.FilesTreeContextMenu;break;case Zarafa.core.data.SharedComponentType["common.dialog.attachments.files"]:c=Zarafa.plugins.files.ui.dialogs.AttachFromFilesContentPanel;break;case Zarafa.core.data.SharedComponentType["common.dialog.attachments.savetofiles"]:c=Zarafa.plugins.files.ui.dialogs.SaveToFilesContentPanel}return c},createFilesNavigationPanel:function(){return{xtype:"zarafa.contextnavigation",
context:this,store:this.getAccountsStore(),restrictToShowAllFolderList:!0,items:[{xtype:"panel",id:"zarafa-navigationpanel-file-navigation",cls:"zarafa-context-navigation-block",ref:"filesnavigation",layout:"fit",items:[{xtype:"filesplugin.navigatortreepanel",id:"zarafa-navigationpanel-files-navigation-tree",model:this.getModel(),FilesFilter:Zarafa.plugins.files.data.FileTypes.FOLDER,hideDeletedFolders:!1,enableDD:!0,enableItemDrop:!0,deferredLoading:!0}]}]}},createContentPanel:function(){return{xtype:"filesplugin.filesmainpanel",
title:this.getDisplayName(),context:this}},createNewFilesButton:function(){return{xtype:"menuitem",text:dgettext("plugin_files","Upload file"),plugins:"zarafa.menuitemtooltipplugin",iconCls:"icon_files_category",newMenuIndex:6,context:this.getName(),handler:function(){Zarafa.plugins.files.data.Actions.openCreateFilesContent(this.getModel())},scope:this}},getMainToolbarViewButtons:function(){var a=container.populateInsertionPoint("main.maintoolbar.view.files",this)||[],b=[{overflowText:dgettext("plugin_files",
"No preview"),iconCls:"icon_previewpanel_off",text:dgettext("plugin_files","No preview"),valueViewMode:Zarafa.plugins.files.data.ViewModes.NO_PREVIEW,valueDataMode:Zarafa.plugins.files.data.DataModes.ALL,handler:this.onContextSelectView,scope:this},{overflowText:dgettext("plugin_files","Right preview"),iconCls:"icon_previewpanel_right",text:dgettext("plugin_files","Right preview"),valueViewMode:Zarafa.plugins.files.data.ViewModes.RIGHT_PREVIEW,valueDataMode:Zarafa.plugins.files.data.DataModes.ALL,
handler:this.onContextSelectView,scope:this},{overflowText:dgettext("plugin_files","Bottom preview"),iconCls:"icon_previewpanel_bottom",text:dgettext("plugin_files","Bottom preview"),valueViewMode:Zarafa.plugins.files.data.ViewModes.BOTTOM_PREVIEW,valueDataMode:Zarafa.plugins.files.data.DataModes.ALL,handler:this.onContextSelectView,scope:this}];b.push();return b.concat(a)},createMainToolbarButtons:function(){return[{xtype:"splitbutton",ref:"../../../filesSwitchViewButton",tooltip:dgettext("plugin_files",
"Switch view"),scale:"large",iconCls:"icon_viewswitch",handler:function(){this.showMenu()},menu:{xtype:"menu",items:[{text:dgettext("plugin_files","List"),overflowText:dgettext("plugin_files","List"),iconCls:"icon_contact_list",valueView:Zarafa.plugins.files.data.Views.LIST,handler:this.onSwitchView,scope:this},{text:dgettext("plugin_files","Icons"),overflowText:dgettext("plugin_files","Icons"),iconCls:"icon_note_icon_view",valueView:Zarafa.plugins.files.data.Views.ICON,handler:this.onSwitchView,
scope:this}]},listeners:{afterrender:this.onAfterRenderMainToolbarButtons,menuhide:function(a,b){b.find().forEach(function(a){a.getEl().hasClass("x-menu-item-selected")&&a.getEl().removeClass("x-menu-item-selected")},this)},menushow:function(a,b){var c=b.find("valueView",this.getCurrentView())[0];Ext.isDefined(c)&&c.addClass("x-menu-item-selected")},scope:this}}]},onAfterRenderMainToolbarButtons:function(a){a.mon(container,"contextswitch",function(b,c,d){this.setVisiblityMainToolbarButton(a,d)},this);
a.mon(this,"viewchange",function(b,c,d){this.setVisiblityMainToolbarButton(a,b)},this);this.setVisiblityMainToolbarButton(a)},setVisiblityMainToolbarButton:function(a,b){b=b||container.getCurrentContext();if(b===this){a.show();var c=this.getAccountsStore();a.setDisabled(Ext.isEmpty(c.getRange()))}else a.hide()},onSwitchView:function(a){var b=this.getCurrentViewMode();this.switchView(a.valueView,b)},onContextSelectView:function(a){this.getModel().setDataMode(a.valueDataMode);var b=a.valueView,c=a.valueViewMode;
Ext.isDefined(a.valueView)||(b=this.getCurrentView());Ext.isDefined(a.valueViewMode)||(c=this.getCurrentViewMode());this.switchView(b,c);this.getModel().setPreviewRecord(void 0,!0)}});Zarafa.onReady(function(){!0===container.getSettingsModel().get("zarafa/v1/plugins/files/enable")&&container.registerContext(new Zarafa.core.ContextMetaData({name:"filescontext",displayName:dgettext("plugin_files","Files"),allowUserVisible:!1,pluginConstructor:Zarafa.plugins.files.FilesContext}))});Ext.namespace("Zarafa.plugins.files.context");
Zarafa.plugins.files.FilesContextModel=Ext.extend(Zarafa.core.ContextModel,{backendStore:void 0,hierarchyStore:void 0,accountStore:void 0,constructor:function(a){a=a||{};Ext.applyIf(a,{statefulRecordSelection:!0});Ext.isDefined(a.hierarchyStore)||(a.hierarchyStore=new Zarafa.plugins.files.data.FilesHierarchyStore);Ext.isDefined(a.store)||(a.store=new Zarafa.plugins.files.data.FilesRecordStore(a));Ext.isDefined(a.backendStore)||(a.backendStore=new Zarafa.plugins.files.data.BackendStore);Zarafa.plugins.files.FilesContextModel.superclass.constructor.call(this,
a);a=this.getHierarchyStore();a.on("load",this.onHierarchyLoad,this);this.onHierarchyLoad(a);if(this.accountStore)this.accountStore.on({write:this.updateAccountStore,scope:this})},updateAccountStore:function(){this.hierarchyStore.load()},createRecord:function(a){a=Zarafa.core.data.RecordFactory.createRecordObjectByMessageClass("IPM.Files",{store_entryid:"files",parent_entryid:a||"/"});a.store=this.getStore();return a},setPreviewRecord:function(a,b){if("filescontext"===container.getCurrentContext().getName()){var c=
Zarafa.plugins.files.data.ComponentBox.getPreviewPanel(),d;b&&this.previewRecord?(d=container.getSharedComponent(Zarafa.core.data.SharedComponentType["common.preview"],this.previewRecord),c.removeAll(),Ext.isDefined(d)&&(c.add(new d),c.doLayout(),c.fileinfo.update(this.previewRecord))):this.previewRecord!==a&&(this.previewRecord=a,Ext.isDefined(a)?(d=container.getSharedComponent(Zarafa.core.data.SharedComponentType["common.preview"],a),Ext.isDefined(d)&&c.fileinfo instanceof d?c.fileinfo.update(a):
(c.removeAll(),d&&(c.add(new d),c.doLayout(),c.fileinfo.update(a)))):c.removeAll())}},resumeLoading:function(a){!0===this.suspended&&(this.suspended=!1,!1!==a&&(a=this.getDefaultFolder(),Ext.isDefined(a)&&(a=Ext.apply({},{folder:this.getDefaultFolder()}),this.store.load(a))),delete this.suspendData)},getHierarchyStore:function(){this.hierarchyStore||(this.hierarchyStore=new Zarafa.plugins.files.data.FilesHierarchyStore);return this.hierarchyStore},removeFolder:function(a){var b=this.getFolder(a.get("entryid"));
if(Ext.isDefined(b))this.folders.remove(b),this.setParentFolderToDefaultFolder(b);else if(!0===a.isParentFolderOfSelectedFolder(this.getDefaultFolder()))this.folders.remove(this.getDefaultFolder()),this.setParentFolderToDefaultFolder(a);else return;this.onFolderChange(this,this.folders);this.fireEvent("folderchange",this,this.folders);this.load();return b},setParentFolderToDefaultFolder:function(a){Ext.isEmpty(this.folders)&&((a=a.getParentFolder())?this.folders.push(a):this.folders.push(this.defaultFolder))},
onFolderChange:Ext.emptyFn,onHierarchyLoad:function(a){this.defaultFolder=a.getFolder("#R#");var b=[];if(!Ext.isEmpty(this.last_used_folders))for(var c in this.last_used_folders){var d=a.getById(c);if(d)for(var d=d.getSubStore("folders"),e=this.last_used_folders[c],f=0;f<e.length;f++){var g=d.getById(e[f]);g&&b.push(g)}}Ext.isEmpty(b)&&this.defaultFolder&&b.push(this.defaultFolder);this.setFolders(b)}});Ext.namespace("Zarafa.plugins.files");
Zarafa.plugins.files.FilesPlugin=Ext.extend(Zarafa.core.Plugin,{constructor:function(a){a=a||{};this.registerModules();Zarafa.plugins.files.FilesPlugin.superclass.constructor.call(this,a)},initPlugin:function(){Zarafa.plugins.files.FilesPlugin.superclass.initPlugin.apply(this,arguments);Zarafa.core.mapi.IconIndex.addProperty("files");Zarafa.core.mapi.IconIndex.folder_note=5378;Zarafa.core.mapi.IconIndex.files=5377;Zarafa.core.data.SharedComponentType.addProperty("filesplugin.accountedit");Zarafa.core.data.SharedComponentType.addProperty("filesplugin.featurequotainfo");
Zarafa.core.data.SharedComponentType.addProperty("filesplugin.featureversioninfo");Zarafa.core.data.SharedComponentType.addProperty("common.dialog.attachments.savetofiles")},registerModules:function(){Zarafa.core.ModuleNames["IPM.FILESACCOUNT"]={list:"filesaccountmodule",item:"filesaccountmodule"}},bidSharedComponent:function(a,b){var c=-1;switch(a){case Zarafa.core.data.SharedComponentType["filesplugin.accountedit"]:case Zarafa.core.data.SharedComponentType["filesplugin.featurequotainfo"]:case Zarafa.core.data.SharedComponentType["filesplugin.featureversioninfo"]:case Zarafa.core.data.SharedComponentType["common.dialog.attachments.savetofiles"]:c=
1}return c},getSharedComponent:function(a,b){var c;switch(a){case Zarafa.core.data.SharedComponentType["filesplugin.accountedit"]:c=Zarafa.plugins.files.settings.ui.AccountEditContentPanel;break;case Zarafa.core.data.SharedComponentType["filesplugin.featurequotainfo"]:c=Zarafa.plugins.files.settings.ui.FeatureQuotaInfoContentPanel;break;case Zarafa.core.data.SharedComponentType["filesplugin.featureversioninfo"]:c=Zarafa.plugins.files.settings.ui.FeatureVersionInfoContentPanel}return c}});
Zarafa.onReady(function(){container.registerPlugin(new Zarafa.core.PluginMetaData({name:"files",displayName:dgettext("plugin_files","Files Plugin"),about:Zarafa.plugins.files.ABOUT,allowUserDisable:!0,pluginConstructor:Zarafa.plugins.files.FilesPlugin}))});Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.AccountRecordFields=[{name:"id"},{name:"name"},{name:"status"},{name:"status_description"},{name:"backend"},{name:"backend_config"},{name:"backend_features"},{name:"account_sequence",type:"number"},{name:"cannot_change",type:"boolean",defaultValue:!1}];Zarafa.plugins.files.data.AccountRecordStatus={OK:"ok",ERROR:"err",NEW:"new",UNKNOWN:"unk"};Zarafa.plugins.files.data.AccountRecordFeature={QUOTA:"Quota",VERSION_INFO:"VersionInfo",SHARING:"Sharing",STREAMING:"Streaming",OAUTH:"OAUTH"};
Zarafa.plugins.files.data.AccountRecord=Ext.extend(Zarafa.core.data.IPMRecord,{applyData:function(a){this.beginEdit();Ext.apply(this.data,a.data);Ext.apply(this.modified,a.modified);this.dirty=a.dirty;this.endEdit(!1);return this},supportsFeature:function(a){return(this.get("backend_features")||[]).some(function(b){return b===a})},renewOauthToken:function(){if(!this.supportsFeature(Zarafa.plugins.files.data.AccountRecordFeature.OAUTH))return!1;Zarafa.plugins.files.backend[this.get("backend")].data.OAUTH.reAuthenticate(this.get("id"));
return!0}});Zarafa.core.data.RecordFactory.addFieldToMessageClass("IPM.FilesAccount",Zarafa.plugins.files.data.AccountRecordFields);Zarafa.core.data.RecordFactory.setBaseClassToMessageClass("IPM.FilesAccount",Zarafa.plugins.files.data.AccountRecord);Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.AccountStore=Ext.extend(Zarafa.core.data.ListModuleStore,{constructor:function(a){a=Ext.applyIf(a||{},{preferredMessageClass:"IPM.FilesAccount",autoLoad:!0,autoSave:!0,defaultSortInfo:{field:"account_sequence",direction:"asc"}});Zarafa.plugins.files.data.AccountStore.superclass.constructor.call(this,a);this.addEvents("reorder")}});Ext.reg("filesplugin.accountstore",Zarafa.plugins.files.data.AccountStore);Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.Actions={downloadFrame:void 0,convertDownloadedFileInfoToAttachmentRecord:function(a){var b=Zarafa.core.data.RecordFactory.createRecordObjectByObjectType(Zarafa.core.mapi.ObjectType.MAPI_ATTACH);b.set("tmpname",a.tmpname);b.set("name",a.name);b.set("size",a.size);return b},openCreateMailContent:function(a,b,c){var d=a.getAttachmentStore();Ext.each(b,function(a){a=this.convertDownloadedFileInfoToAttachmentRecord(a);d.add(a)},this);Zarafa.core.data.UIFactory.openCreateRecord(a,
c)},openCreateMailContentForContacts:function(a,b,c){a=container.getContextByName("mail").getModel().createRecord();Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType["zarafa.plugins.files.attachdialog"],void 0,{title:String.format(dgettext("plugin_files","Add attachment from {0}"),container.getSettingsModel().get("zarafa/v1/plugins/files/button_name")),emailrecord:a,manager:Ext.WindowMgr});var d=a.getRecipientStore(),e=[];b=Ext.isArray(b)?b:[b];for(var f=0,g=b.length;f<
g;f++){var h=b[f];if(h.isOpened()){var k=h.convertToRecipient(Zarafa.core.mapi.RecipientType.MAPI_TO,!0);d.add(k)}else e.push({fn:function(){var a=h;return function(b,c,e,f){var g=function(b,c){if(c===a){b.un("open",g,e);var h=a.convertToRecipient(Zarafa.core.mapi.RecipientType.MAPI_TO,!0);d.add(h);f()}};a.getStore().on("open",g,e);a.open()}}()})}c=Ext.applyIf(c||{},{recordComponentPluginConfig:{loadTasks:e}});Zarafa.core.data.UIFactory.openCreateRecord(a,c)},openCreateFilesContent:function(a,b){var c=
a.createRecord();Zarafa.core.data.UIFactory.openCreateRecord(c,b)},deleteRecords:function(a){var b=!0,c=0,d=0,e,f;Ext.each(a,function(a){if(a.get("folder_id")===container.getSettingsModel().get("zarafa/v1/contexts/files/files_path")+"/"||".."===a.get("filename"))b=!1;a.get("object_type")===Zarafa.plugins.files.data.FileTypes.FOLDER?(c+=1,f||(f=a.get("filename"))):a.get("object_type")===Zarafa.plugins.files.data.FileTypes.FILE&&(d+=1,e||(e=a.get("filename")))},this);var g=container.getSettingsModel().get("zarafa/v1/contexts/files/ask_before_delete");
b&&(g?Ext.MessageBox.confirm(dgettext("plugin_files","Confirm deletion"),this.createDeletionMessage(d,e,c,f),function(b){"yes"===b&&this.doDelete(a)},this):this.doDelete(a))},createDeletionMessage:function(a,b,c,d){if(1===a&&0===c)return String.format(dgettext("plugin_files","Are you sure you want to delete {0}?"),b);if(0===a&&1===c)return String.format(dgettext("plugin_files","Are you sure you want to delete {0} and all of its contents?"),d);if(1<=a&&0===c)return String.format(dgettext("plugin_files",
"Are you sure you want to delete {0} files?"),a);if(0===a&&1<=c)return String.format(dgettext("plugin_files","Are you sure want to delete {0} folders and all of their contents?"),c);if(0!==a&&0!==c)return dgettext("plugin_files","Are you sure want to delete the selected items and all of their contents?")},doDelete:function(a){Array.isArray(a)||(a=[a]);var b=a[0].getStore();b.remove(a);b.save(a)},createShareDialog:function(a,b){b=Ext.applyIf(b||{},{modal:!0,records:a});Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType["zarafa.plugins.files.sharedialog"],
void 0,b)},createFolder:function(a,b,c){b=Ext.applyIf(b||{},{accountFilter:c.getFilesStore().get("entryid"),parentFolder:c,model:a,manager:Ext.WindowMgr});a=Zarafa.core.data.RecordFactory.createRecordObjectByCustomType(Zarafa.core.data.RecordCustomObjectType.FILES_FOLDER,{object_type:Zarafa.plugins.files.data.FileTypes.FOLDER});Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType["zarafa.plugins.files.createfolderdialog"],a,b)},doRefreshIconView:function(){Zarafa.plugins.files.data.ComponentBox.getContext().getCurrentView()===
Zarafa.plugins.files.data.Views.ICON&&Zarafa.plugins.files.data.ComponentBox.getItemsView().refresh()},moveRecords:function(a,b,c){if(!Ext.isDefined(b.data)){var d=b.parentNode;b=Zarafa.core.data.RecordFactory.createRecordObjectByObjectType(Zarafa.core.mapi.ObjectType.ZARAFA_FILES,{id:b.id,entryid:b.id,parent_entryid:Ext.isDefined(d)?d.id:"/"},b.id)}this.isRecordExistsAlready(c.hierarchyStore,a,b)?Ext.MessageBox.confirm(dgettext("plugin_files","Confirm overwrite"),dgettext("plugin_files","File already exists. Do you want to overwrite it?"),
function(c){this.doMoveRecords(a,b,c)},this):this.doMoveRecords(a,b)},isRecordExistsAlready:function(a,b,c){Array.isArray(b)||(b=[b]);var d=b.map(function(a){return a.get("display_name")});return a.getFolder(c.id).getChildren().some(function(a){return-1!==d.indexOf(a.get("display_name"))},this)},doMoveRecords:function(a,b,c){var d=a[0].getStore();Ext.isDefined(c)&&"yes"!==c?d.reload():(Ext.each(a,function(a){a.beginEdit();a.moveTo(b);a.set("deleted",!0);a.addMessageAction("overwrite",Ext.isDefined(c)?
c:"no");a.addMessageAction("isFolder",a.get("type")===Zarafa.plugins.files.data.FileTypes.FOLDER);a.dirty=!0;a.endEdit();a.save()}),d.filter("deleted",!1));Zarafa.plugins.files.data.ComponentBox.getContext().getCurrentView()===Zarafa.plugins.files.data.Views.ICON&&Zarafa.plugins.files.data.ComponentBox.getItemsView().refresh()},openRenameDialog:function(a){Ext.MessageBox.prompt(dgettext("plugin_files","Rename"),dgettext("plugin_files","Please enter a new name"),this.doCheckRenameDuplicate.createDelegate(this,
[a],!0),this,!1,a.get("filename"))},doCheckRenameDuplicate:function(a,b,c,d){"ok"===a&&(Ext.isEmpty(b)?Ext.Msg.alert(_("Rename record"),_("A file name should not be empty."),function(a){this.openRenameDialog(d)},this):(a=d.getStore(),c=0,c=a instanceof Zarafa.plugins.files.data.FilesFoldersSubStore?d.getParentFolder().getChildren().findIndex(function(a){return a.get("filename")===b}):a.findExact("filename",b),-1<c?Ext.Msg.alert(_("Rename item"),String.format(_('A file named "{0}" already exists. Please enter a different name.'),
b),function(){this.openRenameDialog(d)},this):this.doRename(b,d)))},doRename:function(a,b){var c=b.get("path");b.addMessageAction("source_folder_id",b.get("folder_id"));b.addMessageAction("isFolder",b.isFolder());b.beginEdit();b.set("display_name",a);b.set("filename",a);b.set("text",a);b.set("folder_id",c+a+"/");b.endEdit();b.save()},downloadItem:function(a){Array.isArray(a)||(a=[a]);var b=Ext.getBody().createChild({tag:"iframe",cls:"x-hidden"});1==a.length?(a=this.getDownloadLink(a[0],!1),b.dom.contentWindow.location=
a):1<a.length&&(a=this.getDownloadLinkForMultipleFiles(a,!1),b.dom.contentWindow.location=a);container.getNotifier().notify("info.files",dgettext("plugin_files","Downloading"),dgettext("plugin_files","Download started... please wait!"))},uploadAsyncItems:function(a,b,c){Ext.isDefined(c)||(c=b.folderId);var d=[],e=!1;Ext.each(a,function(a){a.size>Zarafa.plugins.files.data.Utils.Core.getMaxUploadFilesize()&&(e=!0);d.push({id:c+a.name,isFolder:!1})});e?Zarafa.common.dialogs.MessageBox.show({title:dgettext("plugin_files",
"Upload"),msg:String.format(dgettext("plugin_files","At least one file is too large! Maximum allowed filesize: {0}."),Zarafa.plugins.files.data.Utils.Format.fileSize(Zarafa.plugins.files.data.Utils.Core.getMaxUploadFilesize())),icon:Zarafa.common.dialogs.MessageBox.ERROR,buttons:Zarafa.common.dialogs.MessageBox.OK}):container.getRequest().singleRequest("filesbrowsermodule","checkifexists",{records:d,destination:c},new Zarafa.core.data.AbstractResponseHandler({doCheckifexists:this.checkForExistingFilesDone.createDelegate(this,
[a,c,b,this.doAsyncUpload],!0)}))},doAsyncUpload:function(a,b,c,d){"overwrite"!==a&&"keepboth"!==a||Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType["zarafa.plugins.files.uploadstatusdialog"],void 0,{files:b,destination:c,keepBoth:"keepboth"===a,manager:Ext.WindowMgr,store:d,callbackAllDone:this.uploadDone.bind(this)})},uploadDone:function(a,b,c){this.updateCache(b);c.folderId===b&&c.reload()},checkForExistingFilesDone:function(a,b,c,d,e){!0===a.duplicate?Zarafa.common.dialogs.MessageBox.addCustomButtons({title:dgettext("plugin_files",
"Confirm overwrite"),icon:Ext.MessageBox.QUESTION,msg:dgettext("plugin_files","File already exists. Do you want to overwrite it?"),fn:e.createDelegate(this,[b,c,d],!0),customButton:[{text:dgettext("plugin_files","Keep both"),name:"keepboth"},{text:dgettext("plugin_files","Overwrite"),name:"overwrite"},{text:dgettext("plugin_files","Cancel"),name:"cancel"}],scope:this}):e.createDelegate(this,["overwrite",b,c,d])()},getDownloadLink:function(a,b){return Ext.isDefined(b)&&0==b?a.getAttachmentUrl():a.getInlineImageUrl()},
getDownloadLinkForMultipleFiles:function(a){var b="",c=document.URL,b=c.substring(0,c.lastIndexOf("/")+1),b=b+"index.php?load=custom&name=download_file";Ext.each(a,function(a,c){b=Ext.urlAppend(b,"ids["+c+"]="+encodeURIComponent(a.get("folder_id")))});return b=Ext.urlAppend(b,"inline=false")},msgWarning:function(a){Zarafa.common.dialogs.MessageBox.show({title:dgettext("plugin_files","Warning"),msg:a,icon:Zarafa.common.dialogs.MessageBox.WARNING,buttons:Zarafa.common.dialogs.MessageBox.OK})},onCheckCredentials:function(a,
b){b?(this.usernameField.hide(),this.usernameField.setValue(""),this.usernameField.label.hide(),this.usernameField.allowBlank=!0,this.usernameField.validate(),this.passwordField.hide(),this.passwordField.setValue(""),this.passwordField.label.hide(),this.passwordField.allowBlank=!0):(this.usernameField.show(),this.usernameField.label.show(),this.usernameField.allowBlank=!1,this.usernameField.validate(),this.passwordField.show(),this.passwordField.label.show(),this.passwordField.allowBlank=!1);this.passwordField.validate()},
onCheckSSL:function(a,b){b&&"80"===this.portField.getValue()?this.portField.setValue("443"):b||"443"!==this.portField.getValue()||this.portField.setValue("80")},updateCache:function(a){container.getRequest().singleRequest("filesbrowsermodule","updatecache",{id:a})},openFolder:function(a,b){var c=a.getHierarchyStore().getFolder(b);Ext.isDefined(c)&&container.selectFolder(c)},openSaveToFilesDialog:function(a,b){b=Ext.applyIf(b||{},{model:a,modal:!0});Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType["common.dialog.attachments.savetofiles"],
void 0,b)}};
Ext.override(Ext.tree.AsyncTreeNode,{quietLoad:function(a,b,c){a=0;if(this.loading){var d;a=function(){this.loading||clearInterval(d)}.createDelegate(this);d=setInterval(a,200)}else if(!this.loaded&&!1!==this.fireEvent("beforeload",this)){this.loading=!0;this.ui.beforeLoad(this);var e=this.loader||this.attributes.loader||this.getOwnerTree().getLoader();e&&(this.setCls("x-treenode-load-silent"),e.load(this,this.quietLoadComplete.createDelegate(this,[a,b,c])))}},quietLoadComplete:function(a,b,c){this.setCls("");
0===this.childNodes.length&&(this.leaf=!0);this.loading=!1;this.loaded=!0;this.ui.afterLoad(this);this.fireEvent("load",this);this.ui.expand()},setLeaf:function(a){this.leaf=a}});Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.ComponentBox=Ext.extend(Object,{getContext:function(){return container.getContextByName("filescontext")},getMainPanel:function(){try{return container.getContentPanel()}catch(a){return container.getTabPanel().get(0).getActiveItem()}},getPreviewPanel:function(){return this.getMainPanel().filesPreview},getTabPanel:function(){return container.getTabPanel()},getViewPanel:function(){return this.getMainPanel().viewPanel},getItemsView:function(){return this.getViewPanel().getActiveItem()}});
Zarafa.plugins.files.data.ComponentBox=new Zarafa.plugins.files.data.ComponentBox;Ext.namespace("Zarafa.plugins.files.data");Zarafa.plugins.files.data.DataModes=Zarafa.core.Enum.create({ALL:0});Ext.namespace("Zarafa.plugins.files.data");Zarafa.plugins.files.data.FileTypes=Zarafa.core.Enum.create({FOLDER:0,FILE:1});Ext.namespace("Zarafa.plugins.files.data");Zarafa.plugins.files.data.FilesBackendRecordFields=[{name:"id"},{name:"name"},{name:"backend",mapping:"name"},{name:"displayName"},{name:"message_class"}];
Zarafa.core.data.RecordFactory.addFieldToMessageClass("IPM.FilesBackend",Zarafa.plugins.files.data.FilesBackendRecordFields);Zarafa.core.data.RecordFactory.setBaseClassToMessageClass("IPM.FilesBackend",Zarafa.core.data.IPMRecord);Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.BackendStore=Ext.extend(Zarafa.core.data.ListModuleStore,{constructor:function(a){a=a||{};var b=Zarafa.core.data.RecordFactory.getRecordClassByMessageClass("IPM.FilesBackend");Ext.applyIf(a,{preferredMessageClass:"IPM.FilesBackend",autoLoad:{params:{list_backend:!0}},reader:new Zarafa.core.data.JsonReader({id:"name",idProperty:"name"},b),proxy:new Zarafa.core.data.IPMProxy({listModuleName:"filesaccountmodule",itemModuleName:"filesaccountmodule"})});Zarafa.plugins.files.data.BackendStore.superclass.constructor.call(this,
a)}});Ext.reg("filesplugin.backendstore",Zarafa.plugins.files.data.BackendStore);Ext.namespace("Zarafa.plugins.files.data");Zarafa.plugins.files.data.FilesFolderRecordFields=[{name:"path"},{name:"folder_id"},{name:"id",mapping:"entryid"},{name:"text"},{name:"object_type"},{name:"entryid"},{name:"parent_entryid"},{name:"store_entryid"},{name:"filename"},{name:"icon_index"},{name:"display_name"},{name:"lastmodified"},{name:"message_size"},{name:"has_subfolder",defaultValue:!1}];
Zarafa.plugins.files.data.FilesFolderRecord=Ext.extend(Zarafa.core.data.IPFRecord,{baseIdProperties:["id","folder_id","entryid","store_entryid","parent_entryid"],constructor:function(a,b,c){Ext.isDefined(c)||(c=Zarafa.core.data.RecordFactory.getRecordDefinitionByCustomType(Zarafa.core.data.RecordCustomObjectType.FILES_FOLDER));Zarafa.plugins.files.data.FilesFolderRecord.superclass.constructor.call(this,a,b,c)},commit:function(){this.cacheParentFolder&&(Zarafa.core.EntryId.compareEntryIds(this.get("parent_entryid"),
this.cacheParentFolder.get("entryid"))||delete this.cacheParentFolder);Zarafa.plugins.files.data.FilesFolderRecord.superclass.commit.apply(this,arguments)},getFullyQualifiedDisplayName:function(){return this.getDisplayName()},getDisplayName:function(){return this.get("display_name")},isSubTreeFolder:function(){var a=this.getFilesStore();return a?Zarafa.core.EntryId.compareEntryIds(this.get("entryid"),a.get("subtree_id")):!1},getFilesStore:function(){var a=this.getStore();return a&&a instanceof Zarafa.plugins.files.data.FilesFoldersSubStore?
a.getParentRecord():a},getChildren:function(){var a=[];this.getFilesFolderStore().each(function(b){this===b.getParentFolder()&&a.push(b)},this);return a},getParentFolder:function(){if(!this.cacheParentFolder){var a=this.get("parent_entryid");this.isSubTreeFolder()||Ext.isEmpty(a)||(this.cacheParentFolder=this.getFilesFolderStore().getById(a));this.cacheParentFolder&&this.get("object_type")===Zarafa.plugins.files.data.FileTypes.FOLDER&&(this.cacheParentFolder.data.has_subfolder=this.get("object_type")===
Zarafa.plugins.files.data.FileTypes.FOLDER)}return this.cacheParentFolder},getFilesFolderStore:function(){var a=this.getFilesStore();return a?a.getSubStore("folders"):!1},copy:function(a){a=Zarafa.core.data.RecordFactory.createRecordObjectByCustomType(Zarafa.core.data.RecordCustomObjectType.FILES_FOLDER,this.data,a||this.id);a.idProperties=this.idProperties.clone();a.phantom=this.phantom;return a.applyData(this,!0)},getIcon:function(){return this.isSubTreeFolder()?"icon_16_logo_"+this.getFilesStore().getBackend():
this.isFolder()?"icon_folder_note":Zarafa.plugins.files.data.Utils.File.getIconClass(this.get("display_name"),"16")},isFolder:function(){return this.get("object_type")===Zarafa.plugins.files.data.FileTypes.FOLDER},isHomeFolder:function(){return"#R#"===this.get("entryid")},isFavoritesFolder:Ext.emptyFn,isOwnRoot:Ext.emptyFn,isParentFolderOfSelectedFolder:function(a){Ext.isDefined(a)||(a=this.getDefaultFolder());return this.get("folder_id")===a.get("folder_id")?!0:a.isSubTreeFolder()?!1:this.isParentFolderOfSelectedFolder(a.getParentFolder())}});
Zarafa.core.data.RecordCustomObjectType.addProperty("FILES_FOLDER");Zarafa.core.data.RecordFactory.addFieldToCustomType(Zarafa.core.data.RecordCustomObjectType.FILES_FOLDER,Zarafa.plugins.files.data.FilesFolderRecordFields);Zarafa.core.data.RecordFactory.setBaseClassToCustomType(Zarafa.core.data.RecordCustomObjectType.FILES_FOLDER,Zarafa.plugins.files.data.FilesFolderRecord);
Zarafa.core.data.RecordFactory.addListenerToObjectType(Zarafa.core.data.RecordCustomObjectType.FILES_FOLDER,"createphantom",function(a){a.afterOpen()});Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.FilesFolderResponseHandler=Ext.extend(Zarafa.core.data.ProxyResponseHandler,{doList:function(a){this.receivedRecords=this.readRecordsFromResponse(a,"item")},doUpdatelist:function(a){this.receivedRecords=this.readRecordsFromResponse(a,"item")},doUpdate:function(a){this.receivedRecords=this.receivedRecords.concat(this.correlateRecordFromResponse({item:a}))}});Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.FilesFoldersSubStore=Ext.extend(Zarafa.core.data.IPFStore,{parentRecord:null,constructor:function(a){a=a||{};var b=Zarafa.core.data.RecordFactory.getRecordClassByCustomType(Zarafa.core.data.RecordCustomObjectType.FILES_FOLDER);Ext.applyIf(a,{proxy:new Zarafa.plugins.files.data.FilesHierarchyProxy,writer:new Zarafa.core.data.JsonWriter,reader:new Zarafa.core.data.JsonReader({dynamicRecord:!1},b)});Zarafa.plugins.files.data.FilesFoldersSubStore.superclass.constructor.call(this,
a)},createRecords:function(a,b,c){var d=this.getParentRecord();d&&d.afterEdit();Zarafa.plugins.files.data.FilesFoldersSubStore.superclass.createRecords.call(this,a,b,c)},destroyRecord:function(a,b,c){this.getParentRecord()&&this.getParentRecord().markDirty();Zarafa.plugins.files.data.FilesFoldersSubStore.superclass.destroyRecord.call(this,a,b,c)},getParentRecord:function(){return this.parentRecord},setParentRecord:function(a){this.parentRecord=a},onNotifyObjectdeleted:function(a,b,c,d,e){Array.isArray(b)||
(b=[b]);a=0;for(c=b.length;a<c;a++)b[a].setEventPropagation(!1),b[a].phantom=!0;this.remove(b)},onNotifyObjectmodified:function(a,b,c,d,e){Array.isArray(b)||(b=[b]);a=0;for(d=b.length;a<d;a++){e=b[a];var f=Array.isArray(c)?c[a]:c;e.setEventPropagation(!1);f instanceof Ext.data.Record?e.applyData(f):this.reader.update(e,f);e.setEventPropagation(!0)}},containsStoreInLastLoad:function(a){Array.isArray(a)||(a=[a]);if(this.parentRecord)for(var b=this.parentRecord.get("store_entryid"),c=0,d=a.length;c<
d;c++)if(Zarafa.core.EntryId.compareStoreEntryIds(b,a[c]))return!0;return!1},onNotifyObjectcreated:function(a,b,c,d,e){Array.isArray(c)||(c=[c]);c[0]instanceof Ext.data.Record?this.loadRecords({records:c},{add:!0}):this.loadData({item:c},!0)},load:function(a){Ext.isObject(a)||(a={});Ext.isObject(a.params)||(a.params={});Ext.isDefined(a.cancelPreviousRequest)||(a.cancelPreviousRequest=!0);a.reload&&(a.params={reload:a.reload});if(a.folder){var b=a.folder;Ext.applyIf(a.params||{},{entryid:b.get("entryid"),
store_entryid:b.get("store_entryid"),parent_entryid:b.get("parent_entryid"),folder_id:b.get("folder_id")})}Ext.applyIf(a,{actionType:Zarafa.core.Actions.list});return Zarafa.plugins.files.data.FilesFoldersSubStore.superclass.load.call(this,a)}});Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.FilesHierarchyProxy=Ext.extend(Zarafa.core.data.MAPIProxy,{constructor:function(a){a=a||{};Ext.applyIf(a,{listModuleName:"hierarchylistmodule",itemModuleName:"hierarchylistmodule"});Zarafa.plugins.files.data.FilesHierarchyProxy.superclass.constructor.call(this,a)},getResponseHandlerForRequest:function(a,b,c,d,e,f,g,h,k){return new Zarafa.plugins.files.data.FilesFolderResponseHandler({proxy:this,action:c,reader:f,sendRecords:d,options:k,callback:g,scope:h})}});Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.FilesHierarchyStore=Ext.extend(Zarafa.core.data.IPFStore,{stateful:!0,state:void 0,loading:!1,customObjectType:Zarafa.core.data.RecordCustomObjectType.FILES_FOLDER_STORE,constructor:function(a){a=a||{};Ext.applyIf(a,{standalone:!0,autoLoad:!0,proxy:new Zarafa.plugins.files.data.FilesHierarchyProxy,writer:new Zarafa.core.data.JsonWriter,reader:new Zarafa.plugins.files.data.FilesJsonReader({customObjectType:Zarafa.core.data.RecordCustomObjectType.FILES_FOLDER_STORE})});this.addEvents("addFolder",
"removeFolder","updateFolder");Zarafa.plugins.files.data.FilesHierarchyStore.superclass.constructor.call(this,a);this.on({add:this.onAdd,beforeload:this.onBeforeLoad,load:this.onAfterLoad,remove:this.onRemove,scope:this})},onAfterLoad:function(a,b,c){this.hookStoreRecord(b);this.loading=!1},onBeforeLoad:function(){this.loading=!0},isLoading:function(){return this.loading},onAdd:function(a,b,c){this.hookStoreRecord(b)},onRemove:function(a,b,c){this.unhookStoreRecord(b)},hookStoreRecord:function(a){for(var b=
0,c=a.length;b<c;b++)a[b].getSubStore("folders").on({add:this.onFolderAdd,remove:this.onFolderRemove,update:this.onFolderUpdate,scope:this})},unhookStoreRecord:function(a){a=a.getSubStore("folders");a.un("add",this.onFolderAdd,this);a.un("remove",this.onFolderRemove,this);a.un("update",this.onFolderUpdate,this)},onFolderAdd:function(a,b,c){this.fireEvent("addFolder",this,a.getParentRecord(),b,c)},onFolderUpdate:function(a,b,c){this.fireEvent("updateFolder",this,a.getParentRecord(),b,c)},onFolderRemove:function(a,
b,c){this.fireEvent("removeFolder",this,a.getParentRecord(),b,c)},getFolder:function(a){for(var b=0,c=this.getCount();b<c;b++){var d=this.getAt(b).getFolderStore();if(d&&(d=d.getById(a)))return d}},getFolderByFolderId:function(a){for(var b=0,c=this.getCount();b<c;b++){var d=this.getAt(b).getFolderStore();if(d){var e=d.findExact("folder_id",a);if(-1<e)return d.getAt(e)}}},load:function(a){Ext.isObject(a)||(a={});Ext.isObject(a.params)||(a.params={});Ext.isDefined(a.cancelPreviousRequest)||(a.cancelPreviousRequest=
!0);a.reload&&(a.params={reload:a.reload});Ext.applyIf(a,{actionType:Zarafa.core.Actions.list});return Zarafa.plugins.files.data.FilesHierarchyStore.superclass.load.call(this,a)}});Ext.reg("filesplugin.hierarchystore",Zarafa.plugins.files.data.FilesHierarchyStore);Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.FilesJsonReader=Ext.extend(Zarafa.core.data.JsonReader,{customObjectType:Zarafa.core.data.RecordCustomObjectType.FILES_FOLDER_STORE,constructor:function(a,b){a=Ext.applyIf(a||{},{dynamicRecord:!1,id:"store_entryid",idProperty:"store_entryid",customObjectType:a.customObjectType||Zarafa.core.data.RecordCustomObjectType.FILES_FOLDER_STORE});Ext.isDefined(b)||(b=Zarafa.core.data.RecordFactory.getRecordClassByCustomType(a.customObjectType));Zarafa.plugins.files.data.FilesJsonReader.superclass.constructor.call(this,
a,b)}});Ext.namespace("Zarafa.plugins.files.data");Zarafa.plugins.files.data.FilesProxy=Ext.extend(Zarafa.core.data.IPMProxy,{getResponseHandlerForRequest:function(a,b,c,d,e,f,g,h,k){return new Zarafa.plugins.files.data.ResponseHandler({proxy:this,action:c,reader:f,sendRecords:d,options:k,callback:g,scope:h})}});Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.FilesRecordFields=[{name:"id",mapping:"entryid"},{name:"folder_id"},{name:"path"},{name:"type",type:"int",defaultValue:Zarafa.plugins.files.data.FileTypes.FOLDER},{name:"filename"},{name:"display_name",mapping:"filename"},{name:"isshared",type:"boolean",defaultValue:!1},{name:"sharedid"},{name:"lastmodified",type:"int",defaultValue:null},{name:"message_size",type:"int",defaultValue:0},{name:"deleted",type:"boolean",defaultValue:!1}];
Zarafa.plugins.files.data.FilesRecord=Ext.extend(Zarafa.core.data.IPMRecord,{disabled:!1,baseIdProperties:["folder_id","entryid","store_entryid","parent_entryid"],applyData:function(a){this.beginEdit();Ext.apply(this.data,a.data);Ext.apply(this.modified,a.modified);this.dirty=a.dirty;this.endEdit(!1);return this},getInlineImageUrl:function(){return container.getBasePath()+"index.php?load=custom&name=download_file&"+Ext.urlEncode({id:this.get("folder_id"),inline:!0})},getAttachmentUrl:function(){return container.getBasePath()+
"index.php?sessionid="+container.getUser().getSessionId()+"&load=custom&name=download_file&"+Ext.urlEncode({id:this.get("folder_id"),inline:!1})},setDisabled:function(a){this.disabled=a},getDisabled:function(){return this.disabled},getAccount:function(){var a=Zarafa.plugins.files.data.Utils.File.getAccountId(this.get("folder_id"));return container.getCurrentContext().getAccountsStore().getById(a)},isFolder:function(){return this.get("type")===Zarafa.plugins.files.data.FileTypes.FOLDER},moveTo:function(a){this.addMessageAction("action_type",
"move");this.addMessageAction("parent_entryid",a.get("entryid"));this.addMessageAction("destination_folder_id",a.get("folder_id"))}});Zarafa.core.data.RecordCustomObjectType.addProperty("ZARAFA_FILES");Zarafa.core.data.RecordFactory.addFieldToMessageClass("IPM.Files",Zarafa.plugins.files.data.FilesRecordFields);Zarafa.core.data.RecordFactory.setBaseClassToMessageClass("IPM.Files",Zarafa.plugins.files.data.FilesRecord);
Zarafa.core.data.RecordFactory.addFieldToCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_FILES,Zarafa.plugins.files.data.FilesRecordFields);Zarafa.core.data.RecordFactory.setBaseClassToCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_FILES,Zarafa.plugins.files.data.FilesRecord);Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.FilesRecordStore=Ext.extend(Zarafa.core.data.ListModuleStore,{folderId:void 0,constructor:function(a){Ext.applyIf(a||{},{remoteGroup:!0,preferredMessageClass:"IPM.Files",defaultSortInfo:{field:"filename",direction:"asc"},entryId:"#R#",folderId:"#R#",listeners:{load:this.onLoad,exception:this.onLoadException},proxy:new Zarafa.plugins.files.data.FilesProxy({listModuleName:"filesbrowsermodule",itemModuleName:"filesbrowsermodule"})});this.addEvents("createfolder");Zarafa.plugins.files.data.FilesRecordStore.superclass.constructor.call(this,
a)},initEvents:function(){Zarafa.plugins.files.data.FilesRecordStore.superclass.initEvents.apply(this,arguments);if(Ext.isDefined(this.hierarchyStore))this.hierarchyStore.on("addFolder",this.onHierarchyAddFolder,this)},onHierarchyAddFolder:function(a,b,c){var d=!1;Ext.each(c,function(a,b,c){if(a.get("parent_entryid")===this.entryId)return d=!0,!1},this);d&&this.reload()},load:function(a){Ext.isObject(a)||(a={});Ext.isObject(a.params)||(a.params={});Ext.isEmpty(a.folder)?Ext.isDefined(a.params.entryid)&&
Ext.isDefined(a.params.store_entryid)&&(this.setEntryId(a.params.entryid,!1),this.setStoreEntryId(a.params.store_entryid,!1),Ext.isDefined(a.params.folderid)&&this.setFolderId(a.params.folderid,!1)):this.setFolder(a.folder);Ext.apply(a.params,{entryid:this.entryId,id:this.folderId,store_entryid:this.storeEntryId});Ext.applyIf(a,{actionType:this.actionType});return Zarafa.plugins.files.data.FilesRecordStore.superclass.load.call(this,a)},setFolder:function(a){Ext.each(a,function(a,c){this.setEntryId(a.get("entryid"),
0!==c);this.setStoreEntryId(a.get("store_entryid"),0!==c);this.setFolderId(a.get("folder_id"),0!==c)},this)},setFolderId:function(a,b){!Ext.isEmpty(b)&&b?(Ext.isEmpty(this.folderId)&&(this.folderId=[]),Ext.isEmpty(this.folderId)||Array.isArray(this.folderId)||(this.folderId=[this.folderId]),this.folderId.push(a)):this.folderId=a},onLoad:function(a,b,c){a=c.params.id;b=Zarafa.plugins.files.data.ComponentBox;c=b.getViewPanel();var d=!1;if(Ext.isEmpty(a)||"#R#"===a)c.switchView("files-accountview"),
b.getPreviewPanel().topToolbar.disable(),d=!0;else if(b.getItemsView()instanceof Zarafa.plugins.files.ui.FilesRecordAccountView)switch(b.getContext().getCurrentView()){case Zarafa.plugins.files.data.Views.LIST:c.switchView("files-gridview");break;case Zarafa.plugins.files.data.Views.ICON:c.switchView("files-iconview")}container.getMainPanel().filesSwitchViewButton.setDisabled(d)},onLoadException:function(a,b,c,d,e,f){e.error&&e.error.info.code&&401==parseInt(e.error.info.code)&&(a=Zarafa.plugins.files.data.Utils.File.getAccountId(d.params.id),
a=container.getCurrentContext().getAccountsStore().getById(a),Ext.isDefined(a)&&a.supportsFeature(Zarafa.plugins.files.data.AccountRecordFeature.OAUTH)&&a.renewOauthToken())},reload:function(a){var b=this.getPath();a=Ext.applyIf(a||{},{params:{reload:!0,id:b},reload:!0});Zarafa.plugins.files.data.FilesRecordStore.superclass.reload.call(this,a)},getPath:function(){return this.entryId}});Ext.reg("filesplugin.filesrecordstore",Zarafa.plugins.files.data.FilesRecordStore);Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.FilesShadowProxy=Ext.extend(Zarafa.core.data.ShadowProxy,{getResponseHandlerForRequest:function(a,b,c,d,e,f,g,h,k){return new Zarafa.plugins.files.data.FilesFolderResponseHandler({proxy:this,action:c,reader:f,sendRecords:d,options:k,callback:g,scope:h})},getListModuleName:function(a){return"hierarchylistmodule"},getItemModuleName:function(a){return"hierarchylistmodule"}});Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.FilesShadowStore=Ext.extend(Zarafa.core.data.ShadowStore,{constructor:function(a){a=a||{};var b=Zarafa.core.data.RecordFactory.getRecordClassByCustomType(Zarafa.core.data.RecordCustomObjectType.FILES_FOLDER);Ext.applyIf(a,{batch:!1,proxy:new Zarafa.plugins.files.data.FilesShadowProxy,writer:new Zarafa.core.data.JsonWriter,reader:new Zarafa.core.data.JsonReader({dynamicRecord:!1},b)});Zarafa.plugins.files.data.FilesShadowStore.superclass.constructor.call(this,a)}});Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.FilesStoreRecordFields=[{name:"path"},{name:"entryid"},{name:"store_entryid"},{name:"text"},{name:"object_type"},{name:"status"},{name:"status_description"},{name:"backend"},{name:"backend_config"},{name:"backend_features"},{name:"cannot_change"},{name:"filename"},{name:"subtree_id"},{name:"display_name"},{name:"account_sequence"}];
Zarafa.plugins.files.data.FilesStoreRecord=Ext.extend(Zarafa.core.data.IPFRecord,{baseIdProperties:["store_entryid"],constructor:function(a,b,c){Ext.isDefined(c)||(c=Zarafa.core.data.RecordFactory.getRecordDefinitionByCustomType(Zarafa.core.data.RecordCustomObjectType.FILES_FOLDER_STORE));Zarafa.plugins.files.data.FilesStoreRecord.superclass.constructor.call(this,a,b,c)},getSubtreeFolder:function(){return this.getFolder(this.get("subtree_id"))},getFolder:function(a){var b=this.getFolderStore();if(b)return b.getById(a)},
getFolderStore:function(){return this.getSubStore("folders")},getBackend:function(){return this.get("backend")}});Zarafa.core.data.RecordCustomObjectType.addProperty("FILES_FOLDER_STORE");Zarafa.core.data.RecordFactory.addFieldToCustomType(Zarafa.core.data.RecordCustomObjectType.FILES_FOLDER_STORE,Zarafa.plugins.files.data.FilesStoreRecordFields);Zarafa.core.data.RecordFactory.setBaseClassToCustomType(Zarafa.core.data.RecordCustomObjectType.FILES_FOLDER_STORE,Zarafa.plugins.files.data.FilesStoreRecord);
Zarafa.core.data.RecordFactory.setSubStoreToCustomType(Zarafa.core.data.RecordCustomObjectType.FILES_FOLDER_STORE,"folders",Zarafa.plugins.files.data.FilesFoldersSubStore);Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.NavigatorTreeLoader=Ext.extend(Ext.tree.TreeLoader,{isDeferred:!1,deferredLoading:!1,deferredLoadingActiveParent:void 0,nodeConfig:void 0,constructor:function(a){a=a||{};Ext.applyIf(a,{directFn:this.directFn.createDelegate(this)});Zarafa.plugins.files.data.NavigatorTreeLoader.superclass.constructor.call(this,a);if(this.tree.rendered)this.onTreeAfterRender();else this.tree.on("afterrender",this.onTreeAfterRender,this,{single:!0})},onTreeAfterRender:function(){this.bindStore(this.store,
!0);!0===this.deferredLoading&&(this.isParentCardLayout(this.tree)?this.deferredLoadingActiveParent=this.tree:(this.deferredLoadingActiveParent=this.tree.findParentBy(this.isParentCardLayout,this),this.deferredLoadingActiveParent||(this.deferredLoading=!1)))},isParentCardLayout:function(a){return a.ownerCt&&a.ownerCt.layout&&"card"===a.ownerCt.layout.type},bindStore:function(a,b){if(!0===b||this.store!==a)if(this.store&&(this.store.un("load",this.onHierarchyLoad,this),this.store.un("remove",this.onHierarchyStoreRemove,
this),this.store.un("addFolder",this.onHierarchyAddFolder,this),this.store.un("updateFolder",this.onHierarchyUpdateFolder,this),this.store.un("removeFolder",this.onHierarchyRemoveFolder,this)),this.store=a)this.store.on({load:this.onHierarchyLoad,remove:this.onHierarchyStoreRemove,addFolder:this.onHierarchyAddFolder,updateFolder:this.onHierarchyUpdateFolder,removeFolder:this.onHierarchyRemoveFolder,scope:this})},onHierarchyLoad:function(){var a=this.deferredLoadingActiveParent;a===a.ownerCt.layout.activeItem?
this.doHierarchyLoad():(this.isDeferred=!0,this.deferredLoadingActiveParent.on("activate",this.doHierarchyLoad,this,{single:!0}))},doHierarchyLoad:function(){var a=this.tree.getRootNode();!1!==this.fireEvent("beforeload",this,a,this.directFn)&&this.directFn(a.id,this.doHierarchyLoadCallback.createDelegate(this));this.isDeferred=!1},doHierarchyLoadCallback:function(a,b){for(var c=this.tree.getRootNode(),d=0,e=a.length;d<e;d++){var f=a[d],g=f.folder,h=c.findChildByEntryId(g.get("id"));h?h.attributes.folder!==
g&&(h.attributes.folder=g,h.reload()):(f=this.createNode(f),c.appendChild(f))}c.childNodes.length!==a.length&&c.reload();this.fireEvent("load",this,c,b)},onHierarchyStoreRemove:function(){console.log(" onHierarchyStoreRemove called")},onHierarchyAddFolder:function(a,b,c){if(!0!==this.isDeferred)if(Array.isArray(c))for(var d=0,e=c.length;d<e;d++)this.onHierarchyAddFolder(a,b,c[d]);else!0!==c.phantom&&this.tree.nodeFilter(c)&&!this.tree.getNodeById(c.get("id"))&&(a=this.getFilteredParentNode(c),b="filesfolder",
a||(a=this.tree.getRootNode(),b="filesrootfolder"),c=this.createNode(Ext.apply({nodeType:b,folder:c},this.nodeConfig)),a.loading=!1,a.appendChild(c),a.expand(!1,!0))},onHierarchyUpdateFolder:function(a,b,c){if(!0!==this.isDeferred){var d=this.tree.getNodeById(c.get("entryid"));if(d)c.isHomeFolder()||d.updateUI(c);else if(d=this.getFilteredParentNode(c),!Ext.isDefined(d)||d&&d.isExpanded())this.onHierarchyAddFolder(a,b,c)}},onHierarchyRemoveFolder:function(a,b,c){!0!==this.isDeferred&&(a=this.tree.getNodeById(c.get("id")))&&
a.remove(!0)},getFilteredParentNode:function(a,b){var c=a.getParentFolder(),d=!1;c&&(c===b?d=b:this.tree.nodeFilter(c)&&(d=this.tree.getNodeById(c.get("id"))),d||(d=this.getFilteredParentNode(c)));return d},directFn:function(a,b){var c=this.tree.getNodeById(a),d=[];if(c.isRoot)for(var c=this.store.getRange(),e=0,f=c.length;e<f;e++){var g=c[e],h=g.getSubtreeFolder();h&&this.tree.nodeFilter(h)&&d.push(Ext.apply({nodeType:"filesrootfolder",folder:h},this.nodeConfig))}else if(d=this.getFilteredChildNodes(c.getFolder(),
"filesfolder"),Ext.isEmpty(d)&&c.isExpandable()&&!c.isExpanded()){h=c.getFolder();g=h.getStore();g.load({folder:h,actionType:Zarafa.core.Actions.updatelist,cancelPreviousRequest:!1,add:!0});return}b(d,{status:!0})},getFilteredChildNodes:function(a,b){for(var c=a.getChildren(),d=[],e=0,f=c.length;e<f;e++){var g=c[e];this.tree.nodeFilter(g)&&d.push(Ext.apply({nodeType:b,folder:g},this.nodeConfig))}return d},createNode:function(a){var b=a.folder;b&&(a.extendedDisplayName="filesrootfolder"===a.nodeType);
a.uiProvider=Zarafa.plugins.files.ui.FolderNodeUI;a.leaf=!b.get("has_subfolder");return Zarafa.plugins.files.data.NavigatorTreeLoader.superclass.createNode.apply(this,arguments)},setReload:function(a){this.reload=a},destroy:function(){this.bindStore(null);Zarafa.plugins.files.data.NavigatorTreeLoader.superclass.destroy.apply(this,arguments)}});Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.ResponseHandler=Ext.extend(Zarafa.core.data.IPMResponseHandler,{nodeId:void 0,successCallback:null,failureCallback:null,doGetquota:function(a){this.successCallback(a)},doGetbackends:function(a){this.successCallback(a)},doGetversion:function(a){this.successCallback(a)},doGetfilestree:function(a){this.successCallback(a.items,a)},doCheckifexists:function(a){this.successCallback(a)},doDownloadtotmp:function(a){this.successCallback(a.items,a)},doCreatedir:function(a){this.successCallback(a)},
doUploadtobackend:function(a){this.successCallback(a)},doError:function(a){Zarafa.common.dialogs.MessageBox.show({title:dgettext("plugin_files","Error"),msg:a.info.original_message,icon:Zarafa.common.dialogs.MessageBox.ERROR,buttons:Zarafa.common.dialogs.MessageBox.OK})}});Ext.reg("filesplugin.responsehandler",Zarafa.plugins.files.data.ResponseHandler);Ext.namespace("Zarafa.plugins.files.data");
Zarafa.plugins.files.data.Utils={Base64:{_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(a){var b="",c,d,e,f,g,h,k=0;for(a=this._utf8_encode(a);k<a.length;)c=a.charCodeAt(k++),d=a.charCodeAt(k++),e=a.charCodeAt(k++),f=c>>2,c=(c&3)<<4|d>>4,g=(d&15)<<2|e>>6,h=e&63,isNaN(d)?g=h=64:isNaN(e)&&(h=64),b=b+this._keyStr.charAt(f)+this._keyStr.charAt(c)+this._keyStr.charAt(g)+this._keyStr.charAt(h);return b},decode:function(a){var b="",c,d,e,f,g,h=0;for(a=a.replace(/[^A-Za-z0-9\+\/\=]/g,
"");h<a.length;)c=this._keyStr.indexOf(a.charAt(h++)),d=this._keyStr.indexOf(a.charAt(h++)),f=this._keyStr.indexOf(a.charAt(h++)),g=this._keyStr.indexOf(a.charAt(h++)),c=c<<2|d>>4,d=(d&15)<<4|f>>2,e=(f&3)<<6|g,b+=String.fromCharCode(c),64!=f&&(b+=String.fromCharCode(d)),64!=g&&(b+=String.fromCharCode(e));return b=this._utf8_decode(b)},_utf8_decode:function(a){for(var b="",c=0,d,e,f;c<a.length;)d=a.charCodeAt(c),128>d?(b+=String.fromCharCode(d),c++):191<d&&224>d?(e=a.charCodeAt(c+1),b+=String.fromCharCode((d&
31)<<6|e&63),c+=2):(e=a.charCodeAt(c+1),f=a.charCodeAt(c+2),b+=String.fromCharCode((d&15)<<12|(e&63)<<6|f&63),c+=3);return b},_utf8_encode:function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;c<a.length;c++){var d=a.charCodeAt(c);128>d?b+=String.fromCharCode(d):(127<d&&2048>d?b+=String.fromCharCode(d>>6|192):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128)),b+=String.fromCharCode(d&63|128))}return b}},Renderer:{typeRenderer:function(a,b,c){switch(a){case Zarafa.plugins.files.data.FileTypes.FOLDER:b.css=
"zarafa-files-listview-icon "+Zarafa.plugins.files.data.Utils.File.getIconClass("folder","16");break;case Zarafa.plugins.files.data.FileTypes.FILE:b.css="zarafa-files-listview-icon "+Zarafa.plugins.files.data.Utils.File.getIconClass(c.get("filename"),"16")}b.css+=" zarafa-grid-empty-cell";return""},sharedRenderer:function(a,b,c){a&&(b.css="zarafa-files-listview-icon files_icon_16_share");b.css+=" zarafa-grid-empty-cell";return""},datetimeRenderer:function(a,b,c){b.css="mail_date";a=new Date(a);return Ext.isDate(a)?
a.format(dgettext("plugin_files","l d/m/Y G:i")):dgettext("plugin_files","Never")}},Format:{fileSize:function(a){return-1===a||"none"===a?"":1024>a?a+" bytes":1048576>a?Math.round(10*a/1024)/10+" KB":1073741824>a?Math.round(10*a/1048576)/10+" MB":Math.round(10*a/1073741824)/10+" GB"},fileSizeList:function(a){return-1===a||"none"===a?"":1024>a?100>=a&&0!=a?"0.1 &nbsp;KB":Math.round(10*a/1024)/10+" &nbsp;KB":1048576>a?Math.round(10*a/1024)/10+" &nbsp;KB":1073741824>a?Math.round(10*a/1048576)/10+" &nbsp;MB":
1099511627776>a?Math.round(10*a/1073741824)/10+" &nbsp;GB":Math.round(10*a/1099511627776)/10+" &nbsp;TB"},truncate:function(a,b){return a.length>b?a.substr(0,b-1)+"&hellip;":a}},File:{getExtension:function(a){var b=a.lastIndexOf(".");return 0>b?"":a.substr(b+1)},getIconClass:function(a,b){Ext.isDefined(b)||(b="48");if("folder"===a)return"files"+b+"icon_folder";var c=this.getExtension(a).toLowerCase(),d="aac ai aiff apk avi bmp c cpp css csv dat dmg doc docx dotx dwg dxf eps exe flv gif gz h hpp html ics iso java jpg js key less mid mp3 mp4 mpg odf ods odt otp ots ott pdf php png ppt psd py qt rar rb rtf sass sql tga tgz tiff txt wav xls xlsx xml yml zip".split(" ").indexOf(c);
return Ext.isEmpty(c)||-1===d?"files"+b+"icon_blank":"files"+b+"icon_"+c},isValidFilename:function(a){return Ext.isEmpty(a)||-1!==a.indexOf("/")||-1!==a.indexOf("\\")||-1!==a.indexOf("<")||-1!==a.indexOf(">")||-1!==a.indexOf(":")||-1!==a.indexOf("'")||-1!==a.indexOf("|")||-1!==a.indexOf("?")||-1!==a.indexOf("*")?!1:!0},getAccountId:function(a){if(!Ext.isDefined(a)||-1===a.indexOf("/"))return null;var b=0;0==a.indexOf("#R#")&&(b=3);return a.substr(b,a.indexOf("/")-b)},stripAccountId:function(a){return Ext.isDefined(a)?
-1===a.indexOf("/")?"#R#":a.substr(a.indexOf("/")):!1},getFileName:function(a){return a.replace(/^.*[\\\/]/,"")},getDirName:function(a){return a.replace(/\\/g,"/").replace(/\/[^\/]*\/?$/,"")}},Core:{getMaxUploadFilesize:function(){return container.getServerConfig().getMaxAttachmentSize()}},Validator:{actionSelectionVisibilityFilter:function(a,b,c,d,e){if(!Ext.isDefined(a)||Ext.isEmpty(a)||b&&Ext.isArray(a)&&1!=a.length)return!1;if(c||d||e)for(b=0;b<a.length;b++)if(c&&a[b].get("type")==Zarafa.plugins.files.data.FileTypes.FOLDER||
d&&a[b].get("type")!==Zarafa.plugins.files.data.FileTypes.FOLDER||e&&".."===a[b].get("filename"))return!1;return!0}}};Ext.namespace("Zarafa.plugins.files.data");Zarafa.plugins.files.data.ViewModes=Zarafa.core.Enum.create({NO_PREVIEW:0,RIGHT_PREVIEW:1,BOTTOM_PREVIEW:2});Ext.namespace("Zarafa.plugins.files.data");Zarafa.plugins.files.data.Views=Zarafa.core.Enum.create({LIST:0,ICON:1,ACCOUNT:2});Ext.namespace("Zarafa.plugins.files.settings");
Zarafa.plugins.files.settings.SettingsAccountsWidget=Ext.extend(Zarafa.settings.ui.SettingsWidget,{constructor:function(a){a=a||{};Ext.applyIf(a,{title:dgettext("plugin_files","Manage Accounts"),xtype:"filesplugin.settingsaccountswidget",height:400,layout:"fit",items:[{xtype:"filesplugin.accountpanel",model:a.model,store:a.store}]});Zarafa.plugins.files.settings.SettingsAccountsWidget.superclass.constructor.call(this,a)}});Ext.reg("filesplugin.settingsaccountswidget",Zarafa.plugins.files.settings.SettingsAccountsWidget);
Ext.namespace("Zarafa.plugins.files.settings");
Zarafa.plugins.files.settings.SettingsMainCategory=Ext.extend(Zarafa.settings.ui.SettingsCategory,{constructor:function(a){a=a||{};Ext.applyIf(a,{title:dgettext("plugin_files","Files"),categoryIndex:1,iconCls:"icon_files_category",items:[{xtype:"filesplugin.settingsaccountswidget",model:a.model,store:a.store},{xtype:"filesplugin.settingsresetwidget"},container.populateInsertionPoint("context.settings.category.files",this)]});Zarafa.plugins.files.settings.SettingsMainCategory.superclass.constructor.call(this,a)}});
Ext.reg("filesplugin.settingsmaincategory",Zarafa.plugins.files.settings.SettingsMainCategory);Ext.namespace("Zarafa.plugins.files.settings");
Zarafa.plugins.files.settings.SettingsResetWidget=Ext.extend(Zarafa.settings.ui.SettingsWidget,{loadMask:void 0,constructor:function(a){a=a||{};Ext.applyIf(a,{title:dgettext("plugin_files","Reset Files settings"),layout:"form",items:[{xtype:"displayfield",hideLabel:!0,value:dgettext("plugin_files","Resets Files settings to their original defaults")},{xtype:"button",text:dgettext("plugin_files","Reset Files settings"),width:150,handler:this.onResetSettings,scope:this}]});Zarafa.plugins.files.settings.SettingsResetWidget.superclass.constructor.call(this,
a)},onResetSettings:function(){var a=dgettext("plugin_files","Are you sure to remove all settings and accounts?"),a=a+"<br/>"+("<i>"+dgettext("plugin_files",'Accounts marked by your administrator as "cannot be changed" will not be removed.')+"</i>"),a=a+"<br/><br/>"+dgettext("plugin_files","WebApp will automatically restart in order for these changes to take effect."),a=a+"<br/>";Zarafa.common.dialogs.MessageBox.addCustomButtons({title:dgettext("plugin_files","Reset Files settings"),msg:a,fn:this.resetDefaultSettings,
customButton:[{text:dgettext("plugin_files","Reset"),name:"reset"},{text:dgettext("plugin_files","Cancel"),name:"cancel"}],scope:this})},resetDefaultSettings:function(a){if("reset"===a){a=container.getSettingsModel();var b=a.getSettingsObject("zarafa/v1/plugins/files/accounts"),c;for(c in b)!0!==b[c].cannot_change&&a.reset("zarafa/v1/plugins/files/accounts/"+c);a.reset("zarafa/v1/contexts/files");a.save();this.loadMask=new Zarafa.common.ui.LoadMask(Ext.getBody(),{msg:"<b>"+dgettext("plugin_files",
"Webapp is reloading, Please wait.")+"</b>"});this.loadMask.show();this.mon(a,"save",this.onSettingsSave,this);this.mon(a,"exception",this.onSettingsException,this)}},onSettingsSave:function(a,b){b.action===Zarafa.core.Actions.reset&&(this.mun(a,"save",this.onSettingsSave,this),this.mun(a,"exception",this.onSettingsException,this),Zarafa.core.Util.reloadWebapp())},onSettingsException:function(a,b,c,d,e){d.action===Zarafa.core.Actions.reset&&(this.loadMask.hide(),this.mun(a,"save",this.onSettingsSave,
this),this.mun(a,"exception",this.onSettingsException,this))}});Ext.reg("filesplugin.settingsresetwidget",Zarafa.plugins.files.settings.SettingsResetWidget);Ext.namespace("Zarafa.plugins.files.settings.data");
Zarafa.plugins.files.settings.data.AccountRenderUtil={statusRenderer:function(a,b,c){switch(a){case Zarafa.plugins.files.data.AccountRecordStatus.OK:b.css="zarafa-files-listview-icon zarafa-files-account-ok";break;case Zarafa.plugins.files.data.AccountRecordStatus.NEW:b.css="zarafa-files-listview-icon zarafa-files-account-new";break;case Zarafa.plugins.files.data.AccountRecordStatus.ERROR:b.css="zarafa-files-listview-icon zarafa-files-account-error";break;case Zarafa.plugins.files.data.AccountRecordStatus.UNKNOWN:b.css=
"zarafa-files-listview-icon zarafa-files-account-unknown"}b.css+=" zarafa-grid-empty-cell";b.attr='ext:qtip="'+c.get("status_description")+'"';return""},featureRenderer:function(a,b,c,d,e,f,g){a=c.get("backend_features");return Ext.isDefined(a)&&null!==a&&Zarafa.plugins.files.settings.data.AccountRenderUtil.arrayContains(a,g)?"zarafa-files-feature-spacer":"x-hide-display"},backendRenderer:function(a){return Ext.isEmpty(a)?"":'<span class="icon_16_'+a+' files_backend_selector">&nbsp;</span>'+a},arrayContains:function(a,
b){for(var c=a.length;c--;)if(a[c]===b)return!0;return!1}};Ext.namespace("Zarafa.plugins.files.settings.ui");
Zarafa.plugins.files.settings.ui.AccountEditContentPanel=Ext.extend(Zarafa.core.ui.ContentPanel,{constructor:function(a){a=a||{};Ext.applyIf(a,{xtype:"filesplugin.accounteditcontentpanel",layout:"fit",modal:!0,width:400,height:250,stateful:!1,title:dgettext("plugin_files","Edit Account"),items:[{xtype:"filesplugin.accounteditpanel",item:a.item,backendStore:a.backendStore}]});Zarafa.plugins.files.settings.ui.AccountEditContentPanel.superclass.constructor.call(this,a)}});
Ext.reg("filesplugin.accounteditcontentpanel",Zarafa.plugins.files.settings.ui.AccountEditContentPanel);Ext.namespace("Zarafa.plugins.files.settings.ui");
Zarafa.plugins.files.settings.ui.AccountEditPanel=Ext.extend(Ext.Panel,{currentItem:void 0,constructor:function(a){a=a||{};a.item&&(this.currentItem=a.item);Ext.applyIf(a,{xtype:"filesplugin.accounteditpanel",layout:"anchor",autoScroll:!0,border:!1,items:this.createPanelItems(a),buttons:[{text:dgettext("plugin_files","Save"),ref:"../saveBtn",cls:"zarafa-action",disabled:!0,handler:this.doSave,scope:this},{text:dgettext("plugin_files","Cancel"),handler:this.doClose,scope:this}]});Zarafa.plugins.files.settings.ui.AccountEditPanel.superclass.constructor.call(this,
a)},doClose:function(){this.dialog.close()},doSave:function(){var a=this.dialog.store,b=this.dialog.accName,c=this.dialog.accBackend,d=!0,e={};Ext.each(this.dialog.metaForm.form.items.items,function(a){e[a.getName()]=a.getValue();if(!a.isValid())return d=!1});d&&(this.currentItem?(this.currentItem.beginEdit(),this.currentItem.set("name",b.getValue()),this.currentItem.set("status",Zarafa.plugins.files.data.AccountRecordStatus.NEW),this.currentItem.set("backend",c.getValue()),this.currentItem.set("backend_config",
e),this.currentItem.endEdit()):(this.currentItem=new a.recordType({id:-1,name:b.getValue(),status:Zarafa.plugins.files.data.AccountRecordStatus.NEW,backend:c.getValue(),backend_config:e}),a.add(this.currentItem)),this.doClose())},createPanelItems:function(a){var b="",c="",d=!1,e;Ext.isDefined(a.item)&&(b=a.item.get("name"),c=a.item.get("backend"),d=!0,e=Ext.urlAppend(container.getBaseURL(),"load=custom&name=form&backend="+encodeURI(c)));return[{xtype:"fieldset",checkboxToggle:!1,title:dgettext("plugin_files",
"Account Information"),defaultType:"textfield",ref:"accInfo",collapsed:!1,items:[{xtype:"panel",layout:"form",border:!1,flex:1,defaults:{anchor:"100%",style:"margin-bottom: 10px;"},defaultType:"textfield",items:[{fieldLabel:dgettext("plugin_files","Account name"),labelAlign:"top",ref:"../../../accName",value:b,name:"accountName"},{xtype:"combo",fieldLabel:dgettext("plugin_files","Account type"),ref:"../../../accBackend",store:a.backendStore,valueField:"backend",value:c,displayField:"displayName",
tpl:'<tpl for="."><div ext:qtip="{displayText}" class="x-combo-list-item"><span class="icon_16_{backend} files_backend_selector">&nbsp;</span>{displayName}</div></tpl>',emptyText:dgettext("plugin_files","Select backend..."),triggerAction:"all",mode:"local",forceSelection:!0,editable:!1,listeners:{select:this.onBackendSelect,scope:this}}]}]},{xtype:"fieldset",checkboxToggle:!1,title:dgettext("plugin_files","Account Configuration"),autoHeight:!0,defaultType:"textfield",ref:"metaInfo",collapsed:!1,items:[{xtype:"metaform",
autoInit:d,method:"GET",flex:1,defaults:{anchor:"100%",style:"margin-bottom: 10px;"},ref:"../../metaForm",url:e,listeners:{actioncomplete:this.onMetaFormReady.createDelegate(this)}}]}]},onBackendSelect:function(a,b,c){c=b.data.backend;a=this.dialog.metaForm;b=this.saveBtn;c=Ext.urlAppend(container.getBaseURL(),"load=custom&name=form&backend="+encodeURI(c));a.url=c;a.load();b.enable()},onMetaFormReady:function(){if(Ext.isDefined(this.item)){var a=this.saveBtn;this.dialog.metaForm.bindData(this.item.data.backend_config);
a.setText(dgettext("files_plugin","Update"));a.enable()}this.dialog.metaForm.on("afterlayout",function(){this.dialog.metaForm.doLayout();Ext.WindowMgr.getActive().setHeight(this.accInfo.getHeight()+this.metaInfo.getHeight()+90)},this,{single:!0})}});Ext.reg("filesplugin.accounteditpanel",Zarafa.plugins.files.settings.ui.AccountEditPanel);Ext.namespace("Zarafa.plugins.files.settings.ui");
Zarafa.plugins.files.settings.ui.AccountGrid=Ext.extend(Zarafa.common.ui.grid.GridPanel,{store:null,backendStore:void 0,constructor:function(a){a=a||{};Ext.applyIf(a,{xtype:"filesplugin.accountgrid",store:a.store,border:!1,baseCls:"accountGrid",enableHdMenu:!1,loadMask:this.initLoadMask(),viewConfig:{forceFit:!0,deferEmptyText:!1,emptyText:'<div class="emptytext">'+dgettext("plugin_files","No account created!")+"</div>"},sm:this.initSelectionModel(),cm:this.initColumnModel(),listeners:{rowdblclick:this.onRowDblClick,
scope:this},tbar:[{iconCls:"filesplugin_icon_add",text:dgettext("plugin_files","Add Account"),ref:"../addAccountBtn",handler:this.onAccountAdd,scope:this},{iconCls:"filesplugin_icon_delete",text:dgettext("plugin_files","Remove Account"),disabled:!0,ref:"../removeAccountBtn",handler:this.onAccountRemove,scope:this},{xtype:"spacer",width:10},{xtype:"button",iconCls:"zarafa-rules-sequence-up",disabled:!0,ref:"../upButton",handler:this.onAccountSequenceUp,scope:this,width:20},{xtype:"spacer",width:10},
{xtype:"button",iconCls:"zarafa-rules-sequence-down",disabled:!0,ref:"../downButton",handler:this.onAccountSequenceDown,scope:this,width:20}]});Zarafa.plugins.files.settings.ui.AccountGrid.superclass.constructor.call(this,a)},initLoadMask:function(){return{msg:dgettext("plugin_files","Loading accounts")+"..."}},initEvents:function(){this.on("afterrender",this.onAfterRender,this)},onAfterRender:function(){this.store.reload()},initSelectionModel:function(){return new Ext.grid.RowSelectionModel({singleSelect:!0,
listeners:{selectionchange:this.onRowSelected}})},initColumnModel:function(){return new Zarafa.plugins.files.settings.ui.AccountGridColumnModel},onRowSelected:function(a){if(!(1>a.getCount())){var b=this.grid.removeAccountBtn,c=a.getSelections()[0].get("cannot_change");b.setDisabled(c);this.grid.upButton.setDisabled(!a.hasPrevious());this.grid.downButton.setDisabled(!a.hasNext())}},onRowDblClick:function(a,b){this.getStore().getAt(b).get("cannot_change")||Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType["filesplugin.accountedit"],
void 0,{store:a.getStore(),item:a.getStore().getAt(b),backendStore:this.backendStore,manager:Ext.WindowMgr})},onAccountAdd:function(){Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType["filesplugin.accountedit"],void 0,{store:this.getStore(),backendStore:this.backendStore,modal:!0})},onAccountRemove:function(){var a=this.getSelectionModel().getSelections();Ext.isDefined(a[0])&&Ext.MessageBox.confirm(dgettext("plugin_files","Confirm deletion"),String.format(dgettext("plugin_files",
'Do you really want to delete the account "{0}"?'),a[0].get("name")),this.doRemove.createDelegate(this,[a[0]],!0),this)},doRemove:function(a,b,c,d){"yes"===a&&this.getStore().remove(d)},onAccountSequenceUp:function(){var a=this.getStore(),b=this.getSelectionModel().getSelected(),c;a.each(function(a){b.get("account_sequence")>a.get("account_sequence")&&(!c||a.get("account_sequence")>c.get("account_sequence"))&&(c=a)},this);this.swapAccounts(b,c)},onAccountSequenceDown:function(){var a=this.getStore(),
b=this.getSelectionModel().getSelected(),c;a.each(function(a){b.get("account_sequence")<a.get("account_sequence")&&(!c||a.get("account_sequence")<c.get("account_sequence"))&&(c=a)},this);this.swapAccounts(b,c)},swapAccounts:function(a,b){var c=parseInt(a.get("account_sequence")),d=parseInt(b.get("account_sequence"));this.upButton.setDisabled(!0);this.downButton.setDisabled(!0);this.store.suspendEvents();a.set("account_sequence",d);b.set("account_sequence",c);this.store.resumeEvents();this.store.save(this.store.getModifiedRecords());
this.store.on("update",this.onAfterSequenceChanged.createDelegate(this,[a,b],!0),null,{single:!0})},onAfterSequenceChanged:function(a,b,c,d,e){a.reload();a.on("load",this.onAfterSequenceReload.createDelegate(this,[d,e],!0),this,{single:!0})},onAfterSequenceReload:function(a,b,c,d,e){b=this.getSelectionModel();this.upButton.setDisabled(!b.hasPrevious());this.downButton.setDisabled(!b.hasNext());a.fireEvent("reorder",d,e)}});Ext.reg("filesplugin.accountgrid",Zarafa.plugins.files.settings.ui.AccountGrid);
Ext.namespace("Zarafa.plugins.files.settings.ui");
Zarafa.plugins.files.settings.ui.AccountGridColumnModel=Ext.extend(Zarafa.common.ui.grid.ColumnModel,{constructor:function(a){a=a||{};Ext.applyIf(a,{columns:this.createDefaultColumns(),defaults:{sortable:!0}});Zarafa.plugins.files.settings.ui.AccountGridColumnModel.superclass.constructor.call(this,a)},createDefaultColumns:function(){return[new Ext.grid.RowNumberer,{header:dgettext("plugin_files","ID"),dataIndex:"id",width:50,hidden:!0,sortable:!1,tooltip:dgettext("plugin_files","Sort by: ID")},{header:dgettext("plugin_files",
"Status"),dataIndex:"status",width:40,sortable:!1,renderer:Zarafa.plugins.files.settings.data.AccountRenderUtil.statusRenderer,tooltip:dgettext("plugin_files","Sort by: Status")},{header:dgettext("plugin_files","Name"),dataIndex:"name",flex:1,sortable:!1,tooltip:dgettext("plugin_files","Sort by: Name")},{header:dgettext("plugin_files","Backend"),dataIndex:"backend",width:40,sortable:!1,renderer:Zarafa.plugins.files.settings.data.AccountRenderUtil.backendRenderer,tooltip:dgettext("plugin_files","Sort by: Backend")},
{xtype:"actioncolumn",header:dgettext("plugin_files","Features"),dataIndex:"backend_features",width:40,sortable:!1,tooltip:dgettext("plugin_files","Shows all available features of the backend."),items:[{getClass:Zarafa.plugins.files.settings.data.AccountRenderUtil.featureRenderer.createDelegate(this,[Zarafa.plugins.files.data.AccountRecordFeature.QUOTA],!0),icon:"plugins/files/resources/icons/features/quota.png",tooltip:dgettext("plugin_files","Show quota information"),handler:this.showDialog.createDelegate(this,
["filesplugin.featurequotainfo"],2)},{getClass:Zarafa.plugins.files.settings.data.AccountRenderUtil.featureRenderer.createDelegate(this,[Zarafa.plugins.files.data.AccountRecordFeature.VERSION_INFO],!0),icon:"plugins/files/resources/icons/features/info.png",tooltip:dgettext("plugin_files","Show version information"),handler:this.showDialog.createDelegate(this,["filesplugin.featureversioninfo"],2)},{getClass:Zarafa.plugins.files.settings.data.AccountRenderUtil.featureRenderer.createDelegate(this,[Zarafa.plugins.files.data.AccountRecordFeature.SHARING],
!0),icon:"plugins/files/resources/icons/features/sharing.png",tooltip:dgettext("plugin_files","Share files")},{getClass:Zarafa.plugins.files.settings.data.AccountRenderUtil.featureRenderer.createDelegate(this,[Zarafa.plugins.files.data.AccountRecordFeature.STREAMING],!0),icon:"plugins/files/resources/icons/features/streaming.png",tooltip:dgettext("plugin_files","Fast Down/Upload")}]}]},showDialog:function(a,b,c){b=a.getStore().getAt(b);"ok"===b.get("status")&&Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType[c],
void 0,{store:a.getStore(),item:b,manager:Ext.WindowMgr})}});Ext.namespace("Zarafa.plugins.files.settings.ui");Zarafa.plugins.files.settings.ui.AccountPanel=Ext.extend(Ext.Panel,{constructor:function(a){a=Ext.applyIf(a||{},{border:!1,layout:"fit",items:[{xtype:"filesplugin.accountgrid",backendStore:a.model.backendStore,store:a.store,flex:1}]});Zarafa.plugins.files.settings.ui.AccountPanel.superclass.constructor.call(this,a)}});Ext.reg("filesplugin.accountpanel",Zarafa.plugins.files.settings.ui.AccountPanel);
Ext.namespace("Zarafa.plugins.files.settings.ui");Zarafa.plugins.files.settings.ui.FeatureQuotaInfoContentPanel=Ext.extend(Zarafa.core.ui.ContentPanel,{constructor:function(a){a=a||{};Ext.applyIf(a,{xtype:"filesplugin.featurequotainfocontentpanel",title:dgettext("plugin_files","Quota Information"),statefull:!1,width:200,autoHeight:!0,items:[{xtype:"filesplugin.featurequotainfopanel",item:a.item}]});Zarafa.plugins.files.settings.ui.FeatureQuotaInfoContentPanel.superclass.constructor.call(this,a)}});
Ext.reg("filesplugin.featurequotainfocontentpanel",Zarafa.plugins.files.settings.ui.FeatureQuotaInfoContentPanel);Ext.namespace("Zarafa.plugins.files.settings.ui");
Zarafa.plugins.files.settings.ui.FeatureQuotaInfoPanel=Ext.extend(Ext.Panel,{account:void 0,constructor:function(a){a=a||{};a.item&&(this.account=a.item);Ext.applyIf(a,{xtype:"filesplugin.featurequotainfopanel",items:this.createPanelItems(),buttons:[{text:dgettext("plugin_files","Reload"),handler:this.doReload.createDelegate(this),scope:this},{text:dgettext("plugin_files","Close"),handler:this.doClose,scope:this}]});Zarafa.plugins.files.settings.ui.FeatureQuotaInfoPanel.superclass.constructor.call(this,
a);this.doReload()},doClose:function(){this.dialog.close()},doReload:function(){var a=new Zarafa.core.data.AbstractResponseHandler({doGetquota:this.gotQuotaValues.createDelegate(this)});container.getRequest().singleRequest("filesaccountmodule","getquota",{accountId:this.account.get("id"),folder:"/"},a)},gotQuotaValues:function(a){if(this.formPanel){var b=parseInt(a.quota[0].amount);a=parseInt(a.quota[1].amount);0>b&&(b=0);0>a&&(a=0);this.formPanel.getForm().setValues([{id:"usedField",value:Ext.util.Format.fileSize(b)},
{id:"availableField",value:Ext.util.Format.fileSize(a)},{id:"totalField",value:Ext.util.Format.fileSize(a+b)}])}},createPanelItems:function(){return[{xtype:"form",border:!1,ref:"formPanel",labelAlign:"left",items:[{xtype:"displayfield",name:"usedField",fieldLabel:dgettext("plugin_files","Used"),value:dgettext("plugin_files","Loading")+"&hellip;"},{xtype:"displayfield",name:"availableField",fieldLabel:dgettext("plugin_files","Free"),value:dgettext("plugin_files","Loading")+"&hellip;"},{xtype:"displayfield",
name:"totalField",fieldLabel:dgettext("plugin_files","Total"),value:dgettext("plugin_files","Loading")+"&hellip;"}]}]}});Ext.reg("filesplugin.featurequotainfopanel",Zarafa.plugins.files.settings.ui.FeatureQuotaInfoPanel);Ext.namespace("Zarafa.plugins.files.settings.ui");
Zarafa.plugins.files.settings.ui.FeatureVersionInfoContentPanel=Ext.extend(Zarafa.core.ui.ContentPanel,{constructor:function(a){a=a||{};Ext.applyIf(a,{xtype:"filesplugin.featureversioninfocontentpanel",stateful:!1,title:dgettext("plugin_files","Version Information"),width:300,height:100,items:[{xtype:"filesplugin.featureversioninfopanel",item:a.item}]});Zarafa.plugins.files.settings.ui.FeatureVersionInfoContentPanel.superclass.constructor.call(this,a)}});
Ext.reg("filesplugin.featureversioninfocontentpanel",Zarafa.plugins.files.settings.ui.FeatureVersionInfoContentPanel);Ext.namespace("Zarafa.plugins.files.settings.ui");
Zarafa.plugins.files.settings.ui.FeatureVersionInfoPanel=Ext.extend(Ext.Panel,{account:void 0,constructor:function(a){a=a||{};a.item&&(this.account=a.item);Ext.applyIf(a,{xtype:"filesplugin.featureversioninfopanel",items:this.createPanelItems(a),buttons:[{text:dgettext("plugin_files","Close"),handler:this.doClose,scope:this}]});Zarafa.plugins.files.settings.ui.FeatureVersionInfoPanel.superclass.constructor.call(this,a);this.doReload()},doClose:function(){this.dialog.close()},doReload:function(){var a=
new Zarafa.core.data.AbstractResponseHandler({doGetversion:this.gotVersionValues.createDelegate(this)});container.getRequest().singleRequest("filesaccountmodule","getversion",{accountId:this.account.get("id")},a)},gotVersionValues:function(a){this.backendVersionField.setValue(a.version.backend);this.serverVersionField.setValue(a.version.server)},createPanelItems:function(){return[{xtype:"form",border:!1,labelAlign:"left",items:[{xtype:"displayfield",ref:"../backendVersionField",fieldLabel:dgettext("plugin_files",
"Backend"),value:dgettext("plugin_files","Loading")+"&hellip;"},{xtype:"displayfield",ref:"../serverVersionField",fieldLabel:this.account.get("backend"),value:dgettext("plugin_files","Loading")+"&hellip;"}]}]}});Ext.reg("filesplugin.featureversioninfopanel",Zarafa.plugins.files.settings.ui.FeatureVersionInfoPanel);Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.FilesHierarchyRootNode=Ext.extend(Zarafa.hierarchy.ui.HierarchyRootNode,{findChildByEntryId:function(a){return this.findChildBy(function(b){return Zarafa.core.EntryId.compareEntryIds(b.attributes.folder.get("id"),a)})},findChildStoreByEntryId:function(a){return this.findChildBy(function(b){return Zarafa.core.EntryId.compareStoreEntryIds(b.attributes.folder.get("id"),a)})}});Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.FilesListToolbar=Ext.extend(Zarafa.core.ui.ContentPanelToolbar,{context:void 0,model:void 0,constructor:function(a){a=a||{};!Ext.isDefined(a.model)&&Ext.isDefined(a.context)&&(this.model=a.context.getModel());Ext.applyIf(a,{enableOverflow:!0,items:this.createToolbarItems()});Zarafa.plugins.files.ui.FilesListToolbar.superclass.constructor.call(this,a);this.initEvent();this.onFolderChangeLoad(this.model,[this.model.getDefaultFolder()])},initEvent:function(){this.mon(this.model,
{recordselectionchange:this.onRecordSelectionChange,folderchange:this.onFolderChangeLoad,scope:this})},createToolbarItems:function(){return[{cls:"files_icon_actionbutton",text:dgettext("plugin_files","Upload"),ref:"uploadButton",overflowText:dgettext("plugin_files","Upload files"),iconCls:"files_icon_action files_icon_action_upload",handler:this.onFileUpload,model:this.model,disabled:!0,scope:this},{cls:"files_icon_actionbutton",text:dgettext("plugin_files","New Folder"),ref:"createFolderButton",
disabled:!0,overflowText:dgettext("plugin_files","New Folder"),iconCls:"files_icon_action files_icon_action_new_folder",handler:this.onCreateFolder,scope:this},{ref:"downloadBtn",cls:"files_icon_actionbutton",text:dgettext("plugin_files","Download"),overflowText:dgettext("plugin_files","Download files"),iconCls:"files_icon_action files_icon_action_download",handler:this.onFileDownload,disabled:!0,scope:this},{cls:"files_icon_actionbutton",ref:"shareBtn",text:dgettext("plugin_files","Share"),overflowText:dgettext("plugin_files",
"Share files"),iconCls:"files_icon_action files_icon_action_share",handler:this.onFileShare,disabled:!0,scope:this},{cls:"files_icon_actionbutton",ref:"attachToMailBtn",text:dgettext("plugin_files","Attach to mail"),overflowText:dgettext("plugin_files","Attach to mail"),iconCls:"files_icon_action files_icon_action_attach_to_mail",handler:this.onFileAddToMail,disabled:!0,scope:this},{xtype:"tbfill"},{tooltip:dgettext("plugin_files","Rename"),overflowText:dgettext("plugin_files","Rename"),ref:"renameBtn",
iconCls:"files_icon_action files_icon_action_edit",handler:this.onRename,nonEmptySelectOnly:!0,disabled:!0,scope:this},{xtype:"zarafa.toolbarbutton",tooltip:dgettext("plugin_files","Delete"),ref:"deleteBtn",overflowText:dgettext("plugin_files","Delete"),iconCls:"files_icon_action files_icon_action_delete",handler:this.onDelete,disabled:!0,scope:this}]},onRecordSelectionChange:function(a,b){var c=Zarafa.plugins.files.data.Utils.Validator,d=c.actionSelectionVisibilityFilter(b,!1,!0,!1,!0);this.downloadBtn.setDisabled(!d);
this.attachToMailBtn.setDisabled(!d);if(d=c.actionSelectionVisibilityFilter(b,!0,!1,!1,!0)){this.shareBtn.setDisabled(!d);var e=b[0].getAccount();this.shareBtn.setVisible(e.supportsFeature(Zarafa.plugins.files.data.AccountRecordFeature.SHARING))}else this.shareBtn.setVisible(!1);this.renameBtn.setDisabled(!d);this.deleteBtn.setDisabled(!c.actionSelectionVisibilityFilter(b,!1,!1,!1,!0))},onFolderChangeLoad:function(a,b){var c=b[0]||void 0;Ext.isEmpty(c)||"#R#"===c.get("folder_id")?(this.setDisabled(!0),
this.shareBtn.setVisible(!1)):(this.createFolderButton.setDisabled(!1),this.uploadButton.setDisabled(!1))},onCreateFolder:function(){var a=this.model,b=a.getHierarchyStore().getFolder(a.getStore().getPath());Zarafa.plugins.files.data.Actions.createFolder(a,void 0,b)},onFileUpload:function(a,b){(new Zarafa.plugins.files.ui.UploadComponent({callback:this.uploadCallback,multiple:!0,scope:this})).openUploadDialog()},onFileDownload:function(){var a=this.model.getSelectedRecords();Zarafa.plugins.files.data.Actions.downloadItem(a)},
onFileShare:function(a,b){var c=this.model.getSelectedRecords();Zarafa.plugins.files.data.Actions.createShareDialog(c)},onFileAddToMail:function(a,b){var c=this.model.getSelectedRecords(),d=container.getContextByName("mail").getModel().createRecord(),e=[],f=d.getAttachmentStore();Ext.each(c,function(a){e.push(a.get("folder_id"))},this);container.getNotifier().notify("info.files",dgettext("plugin_files","Attaching"),dgettext("plugin_files","Creating email... Please wait!"));try{container.getRequest().singleRequest("filesbrowsermodule",
"downloadtotmp",{ids:e,maxAttachmentSize:container.getServerConfig().getMaxAttachmentSize(),dialog_attachments:f.getId()},new Zarafa.core.data.AbstractResponseHandler({doDownloadtotmp:this.attachToMail.createDelegate(this,[d],!0)}))}catch(g){Zarafa.plugins.files.data.Actions.msgWarning(g.message)}},uploadCallback:function(a,b){Zarafa.plugins.files.data.Actions.uploadAsyncItems(a,this.model.getStore())},attachToMail:function(a,b){Zarafa.plugins.files.data.Actions.openCreateMailContent(b,a.items)},
onRename:function(a,b){var c=this.model.getSelectedRecords();Zarafa.plugins.files.data.Actions.openRenameDialog(c[0])},onDelete:function(a,b){var c=this.model,d=c.getSelectedRecords(),e=[];Ext.each(d,function(a){e.push(c.getHierarchyStore().getFolder(a.id))},this);Zarafa.plugins.files.data.Actions.deleteRecords(d)}});Ext.reg("filesplugin.fileslisttoolbar",Zarafa.plugins.files.ui.FilesListToolbar);Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.FilesMainContextMenu=Ext.extend(Zarafa.core.ui.menu.ConditionalMenu,{context:void 0,constructor:function(a){a=a||{};Ext.applyIf(a,{items:[this.createContextActionItems(a.context.model),{xtype:"menuseparator"},container.populateInsertionPoint("plugin.files.contextmenu.actions",this),{xtype:"menuseparator"},container.populateInsertionPoint("plugin.files.contextmenu.options",this)]});Zarafa.plugins.files.ui.FilesMainContextMenu.superclass.constructor.call(this,a)},createContextActionItems:function(a){return[{xtype:"zarafa.conditionalitem",
text:dgettext("plugin_files","Download"),iconCls:"files_icon_action files_icon_action_download",handler:this.onContextItemDownload,beforeShow:function(a,c){var b=Zarafa.plugins.files.data.Utils.Validator.actionSelectionVisibilityFilter(c,!1,!0,!1,!1);a.setVisible(b)},scope:this},{xtype:"zarafa.conditionalitem",text:dgettext("plugin_files","Share"),iconCls:"files_icon_action files_icon_action_share",handler:this.onContextItemShare,beforeShow:function(a,c){var b=!1,e=!1;0<c.length&&(b=c[0].getAccount(),
e=c[0].get("isshared"),b=b.supportsFeature(Zarafa.plugins.files.data.AccountRecordFeature.SHARING));b=b&&Zarafa.plugins.files.data.Utils.Validator.actionSelectionVisibilityFilter(c,!0,!1,!1,!0);a.setVisible(b);1==e&&a.setText(dgettext("plugin_files","Edit share"))},scope:this},{xtype:"zarafa.conditionalitem",text:dgettext("plugin_files","New Folder"),iconCls:"files_icon_action files_icon_action_new_folder",handler:this.onContextItemNewFolder,beforeShow:function(a,c){a.setVisible(Zarafa.plugins.files.data.Utils.Validator.actionSelectionVisibilityFilter(c,
!0,!1,!0,!0))},model:a,scope:this},{xtype:"zarafa.conditionalitem",text:dgettext("plugin_files","Attach to mail"),iconCls:"files_icon_action files_icon_action_attach_to_mail",handler:this.onContextItemAttach,beforeShow:function(a,c){for(var b=Zarafa.plugins.files.data.Utils.Validator.actionSelectionVisibilityFilter(c,!1,!0,!1,!0),e=container.getServerConfig().getMaxAttachmentSize(),f=0;f<c.length;f++)if(c[f].get("message_size")>e){b=!1;break}a.setVisible(b)},scope:this},{xtype:"zarafa.conditionalitem",
text:dgettext("plugin_files","Rename"),iconCls:"files_icon_action files_icon_action_edit",handler:this.onContextItemRename,beforeShow:function(a,c){a.setVisible(Zarafa.plugins.files.data.Utils.Validator.actionSelectionVisibilityFilter(c,!0,!1,!1,!0))},scope:this},{xtype:"zarafa.conditionalitem",text:dgettext("plugin_files","Delete"),iconCls:"files_icon_action files_icon_action_delete",handler:this.onContextItemDelete,beforeShow:function(a,c){a.setVisible(Zarafa.plugins.files.data.Utils.Validator.actionSelectionVisibilityFilter(c,
!1,!1,!1))},scope:this},{xtype:"zarafa.conditionalitem",text:dgettext("plugin_files","Info"),iconCls:"icon_info",handler:this.onContextItemInfo,beforeShow:function(a,c){var b=Zarafa.plugins.files.data.Utils.Validator.actionSelectionVisibilityFilter(c,!0,!1,!1,!0),e=this.context.getCurrentViewMode()===Zarafa.plugins.files.data.ViewModes.NO_PREVIEW;a.setDisabled(!b||!e)},scope:this}]},onContextItemDownload:function(){Zarafa.plugins.files.data.Actions.downloadItem(this.records)},onContextItemDelete:function(){Zarafa.plugins.files.data.Actions.deleteRecords(this.records)},
onContextItemShare:function(){Zarafa.plugins.files.data.Actions.createShareDialog(this.records)},onContextItemNewFolder:function(a){a=a.model;var b=a.getHierarchyStore().getFolder(this.records[0].get("entryid"));Zarafa.plugins.files.data.Actions.createFolder(a,void 0,b)},onContextItemInfo:function(){var a=void 0;1==this.records.length&&(a=this.records[0]);a=Ext.applyIf({},{modal:!0,record:a});Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType["zarafa.plugins.files.fileinfopanel"],
void 0,a)},onContextItemRename:function(){Zarafa.plugins.files.data.Actions.openRenameDialog(this.records[0])},onContextItemAttach:function(){var a=container.getContextByName("mail").getModel().createRecord(),b=[],c=a.getAttachmentStore();Ext.each(this.records,function(a){b.push(a.get("folder_id"))},this);container.getNotifier().notify("info.files",dgettext("plugin_files","Attaching"),dgettext("plugin_files","Creating email... Please wait!"));try{container.getRequest().singleRequest("filesbrowsermodule",
"downloadtotmp",{ids:b,maxAttachmentSize:container.getServerConfig().getMaxAttachmentSize(),dialog_attachments:c.getId()},new Zarafa.core.data.AbstractResponseHandler({doDownloadtotmp:this.attachToMail.createDelegate(this,[a],!0)}))}catch(d){Zarafa.plugins.files.data.Actions.msgWarning(d.message)}},attachToMail:function(a,b){Zarafa.plugins.files.data.Actions.openCreateMailContent(b,a.items)}});Ext.reg("filesplugin.filesmaincontextmenu",Zarafa.plugins.files.ui.FilesMainContextMenu);Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.FilesMainPanel=Ext.extend(Zarafa.common.ui.ContextMainPanel,{constructor:function(a){a=a||{};Ext.applyIf(a,{xtype:"filesplugin.filesmainpanel",layout:"zarafa.switchborder",header:!1,iconCls:"icon_files",items:[this.initMainItems(a),this.initPreviewPanel()],tbar:{xtype:"filesplugin.filestoptoolbar",height:28,context:a.context}});Zarafa.plugins.files.ui.FilesMainPanel.superclass.constructor.call(this,a)},initMainItems:function(a){return{xtype:"panel",layout:"zarafa.collapsible",
cls:"zarafa-files-context-mainpanel",minWidth:200,minHeight:200,region:"center",border:!1,split:!0,items:[{xtype:"zarafa.switchviewcontentcontainer",ref:"../viewPanel",layout:"card",lazyItems:this.initViews(a.context)}],tbar:{xtype:"filesplugin.fileslisttoolbar",defaultTitle:dgettext("plugin_files","Files"),height:33,context:a.context}}},initViews:function(a){var b=[{xtype:"filesplugin.filesrecordaccountview",flex:1,id:"files-accountview",anchor:"100%",context:a},{xtype:"filesplugin.filesrecordgridview",
flex:1,id:"files-gridview",anchor:"100%",context:a},{xtype:"filesplugin.filesrecordiconview",flex:1,id:"files-iconview",anchor:"100%",context:a}];a=container.populateInsertionPoint("plugin.files.views",this,a);return b=b.concat(a)},initPreviewPanel:function(){return{xtype:"filesplugin.filespreviewpanel",ref:"filesPreview",border:!1,region:"south",split:!0}},initEvents:function(){Ext.isDefined(this.context)&&(this.mon(this.context,"viewchange",this.onViewChange,this),this.mon(this.context,"viewmodechange",
this.onViewModeChange,this),this.onViewChange(this.context,this.context.getCurrentView()),this.onViewModeChange(this.context,this.context.getCurrentViewMode()));Zarafa.plugins.files.ui.FilesMainPanel.superclass.initEvents.apply(this,arguments)},onViewChange:function(a,b,c){a=a.getModel().getStore();switch(b){case Zarafa.plugins.files.data.Views.LIST:this.viewPanel.switchView("#R#"===a.getPath()?"files-accountview":"files-gridview");break;case Zarafa.plugins.files.data.Views.ICON:this.viewPanel.switchView("files-iconview")}},
onViewModeChange:function(a,b,c){var d;switch(b){case Zarafa.plugins.files.data.ViewModes.NO_PREVIEW:d=Zarafa.common.ui.layout.SwitchBorderLayout.Orientation.OFF;break;case Zarafa.plugins.files.data.ViewModes.RIGHT_PREVIEW:d=Zarafa.common.ui.layout.SwitchBorderLayout.Orientation.HORIZONTAL;break;case Zarafa.plugins.files.data.ViewModes.BOTTOM_PREVIEW:d=Zarafa.common.ui.layout.SwitchBorderLayout.Orientation.VERTICAL;break;case Zarafa.plugins.files.data.ViewModes.SEARCH:return}a=this.getLayout();Ext.isFunction(a.setOrientation)?
a.setOrientation(d):Ext.isString(a)?this.layoutConfig=Ext.apply(this.layoutConfig||{},{orientation:d}):this.layout.orientation=d}});Ext.reg("filesplugin.filesmainpanel",Zarafa.plugins.files.ui.FilesMainPanel);Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.FilesPreviewPanel=Ext.extend(Ext.Panel,{constructor:function(a){a=a||{};var b=Ext.applyIf(a.tbar||{},{xtype:"zarafa.toolbar",height:33,hidden:!1,items:[]});Ext.applyIf(a,{xtype:"filesplugin.filespreviewpanel",layout:"fit",stateful:!0,cls:"zarafa-files-previewpanel",width:300,height:300,tbar:b});Zarafa.plugins.files.ui.FilesPreviewPanel.superclass.constructor.call(this,a)}});Ext.reg("filesplugin.filespreviewpanel",Zarafa.plugins.files.ui.FilesPreviewPanel);Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.FilesRecordAccountView=Ext.extend(Ext.Panel,{context:void 0,model:void 0,constructor:function(a){a=a||{};!Ext.isDefined(a.model)&&Ext.isDefined(a.context)&&(a.model=a.context.getModel());!Ext.isDefined(a.store)&&Ext.isDefined(a.model)&&(a.store=a.model.getStore());Ext.applyIf(a,{xtype:"filesplugin.filesrecordaccountview",layout:"fit",cls:"zarafa-files-accountview",loadMask:!0,header:!1,border:!1,maskDisabled:!1,height:400,loadingText:dgettext("plugin_files","Loading accounts")+
"...",items:[{xtype:"dataview",ref:"accountView",store:a.store,emptyText:'<div class="emptytext">'+dgettext("plugin_files","There are no accounts added. Go to settings, Files tab and add an account")+"</div>",autoScroll:!0,singleSelect:!0,deferEmptyText:!1,overClass:"zarafa-files-accountview-over",tpl:this.initTemplate(a.model),selectedClass:"zarafa-files-accountview-selected",itemSelector:"div.zarafa-files-accountview-container"}]});Zarafa.plugins.files.ui.FilesRecordAccountView.superclass.constructor.call(this,
a)},initTemplate:function(a){return new Ext.XTemplate('<div style="height: 100%; width: 100%; overflow: auto;">','<tpl for=".">','<div class="zarafa-files-accountview-container">','<div class="zarafa-files-account-background {.:this.getAccountType}"> </div>','<div class="zarafa-files-account-info">','<span class="zarafa-files-accountview-subject">{filename:htmlEncode}</span>','<span class="zarafa-files-accountview-account">{.:this.getAccountIdentifier}</span>',"</div>","</div>","</tpl>","</div>",
{getAccountType:function(a){a=this.model.getHierarchyStore().getById(a.id);var b="Webdav";Ext.isDefined(a)&&(b=a.get("backend"));return"icon_256_"+b},getAccountIdentifier:function(a){var b=this.model.getHierarchyStore().getById(a.id);a="";Ext.isDefined(b)&&(b=b.get("backend_config"))&&Ext.isDefined(b.user)&&Ext.isDefined(b.server_address)&&(a=b.user+"@"+b.server_address);return Zarafa.plugins.files.data.Utils.Format.truncate(a,27)},model:a})},initEvents:function(){this.accountView.on({dblclick:this.onIconDblClick,
scope:this})},initComponent:function(){Zarafa.plugins.files.ui.FilesRecordAccountView.superclass.initComponent.apply(this,arguments);if(this.loadMask)this.on("afterrender",this.createLoadMask,this)},createLoadMask:function(){this.model.getHierarchyStore().isLoading()&&(this.loadMask=new Zarafa.common.ui.LoadMask(this.getEl(),{msg:this.loadingText,store:this.store}),this.loadMask.show())},destroy:function(){Ext.destroy(this.loadMask);Zarafa.plugins.files.ui.FilesRecordAccountView.superclass.destroy.apply(this,
arguments)},onIconDblClick:function(a,b){var c=this.accountView.getStore().getAt(b),c=this.model.getHierarchyStore().getFolder(c.get("entryid"));container.selectFolder(c)}});Ext.reg("filesplugin.filesrecordaccountview",Zarafa.plugins.files.ui.FilesRecordAccountView);Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.FilesRecordDetailsPanel=Ext.extend(Ext.form.FormPanel,{defaultPreviewImage:"plugins/files/resources/icons/no-preview.jpg",record:void 0,constructor:function(a){a=a||{};var b={type:"vbox",align:"stretch",pack:"start"};Zarafa.plugins.files.data.ComponentBox.getContext().getCurrentViewMode()===Zarafa.plugins.files.data.ViewModes.BOTTOM_PREVIEW&&Ext.apply(b,{type:"hbox"});a=Ext.applyIf(a,{xtype:"filesplugin.filesrecorddetailspanel",ref:"../fileinfo",autoDestroy:!0,layout:b,border:!1,
items:[this.fieldSetFileInfo(),this.fieldSetFilePreview()]});Ext.isDefined(a.record)&&(a=Ext.applyIf(a,{listeners:{afterlayout:function(a){this.update(this.record)}}}));Zarafa.plugins.files.ui.FilesRecordDetailsPanel.superclass.constructor.call(this,a)},refresh:function(){this.removeAll();this.add(this.fieldSetFileInfo());this.add(this.fieldSetFilePreview())},fieldSetFileInfo:function(){return{xtype:"fieldset",title:dgettext("plugin_files","File information"),height:150,width:300,defaults:{anchor:"-3"},
items:[{xtype:"textfield",fieldLabel:dgettext("plugin_files","Filename"),ref:"../filename",value:"unknown",readOnly:!0},{xtype:"textfield",fieldLabel:dgettext("plugin_files","Filesize"),ref:"../filesize",value:"unknown",readOnly:!0},{xtype:"textfield",fieldLabel:dgettext("plugin_files","Last modified"),ref:"../lastmodified",value:"unknown",readOnly:!0},{xtype:"textfield",fieldLabel:dgettext("plugin_files","Type"),ref:"../type",value:"unknown",readOnly:!0},{xtype:"textfield",fieldLabel:dgettext("plugin_files",
"Is shared"),ref:"../shared",hidden:!0,value:"unknown",readOnly:!0}]}},fieldSetFilePreview:function(){var a="width: 100%;";switch(Zarafa.plugins.files.data.ComponentBox.getContext().getCurrentViewMode()){case Zarafa.plugins.files.data.ViewModes.RIGHT_PREVIEW:a="width: 100%;";break;case Zarafa.plugins.files.data.ViewModes.BOTTOM_PREVIEW:a="height: 100%;"}return{xtype:"fieldset",title:dgettext("plugin_files","File preview"),ref:"filepreview",flex:1,autoScroll:!0,defaultType:"textfield",items:[{xtype:"component",
id:"previewimage",autoEl:{tag:"img",src:this.defaultPreviewImage,style:a}}]}},setPreviewPanel:function(a,b){var c=Zarafa.plugins.files.data.ComponentBox.getContext().getCurrentViewMode(),d=Ext.isDefined(container.getPluginByName("filepreviewer"))?!0:!1,e=Ext.isDefined(container.getPluginByName("pdfbox"))?!0:!1,f=Ext.isDefined(container.getPluginByName("webodf"))?!0:!1,g="width: 100%;";switch(c){case Zarafa.plugins.files.data.ViewModes.RIGHT_PREVIEW:g="width: 100%;";break;case Zarafa.plugins.files.data.ViewModes.BOTTOM_PREVIEW:g=
"height: 100%;"}c={};if(d||Ext.isEmpty(b)||!/\.(gif|jpg|jpeg|tiff|png|bmp)$/i.test(b))if(d&&!Ext.isEmpty(b)&&(new RegExp(container.getSettingsModel().get("zarafa/v1/plugins/filepreviewer/supported_filetypes"),"i")).test(b))c={xtype:"filepreviewer.viewerpanel",record:a,defaultScale:1,autoResize:this.filepreview,height:this.filepreview.getInnerHeight()};else if(!d&&e&&!Ext.isEmpty(b)&&/\.(pdf)$/i.test(b))c={xtype:"filesplugin.pdfjspanel",src:Zarafa.plugins.files.data.Actions.getDownloadLink(a),title:a.get("filename")};
else if(d||e||Ext.isEmpty(b)||!/\.(pdf)$/i.test(b))if(!Ext.isEmpty(b)&&/\.(txt|html|php|js|c|cpp|h|java|sh|bat|log|cfg|conf|tex|py|pl)$/i.test(b))c={xtype:"textarea",hideLabel:!0,readOnly:!0,anchor:"0, 0",listeners:{afterrender:function(){Ext.Ajax.request({method:"GET",url:Zarafa.plugins.files.data.Actions.getDownloadLink(a),success:function(a,b){this.setRawValue(a.responseText)},scope:this})}}};else if(!Ext.isEmpty(b)&&/\.(mp3|wav)$/i.test(b)){d="";switch(b.toLowerCase()){case ".wav":d="audio/wav";
break;default:d="audio/mpeg"}c={xtype:"component",autoEl:{tag:"audio",style:g,controls:"controls",cn:[{tag:"source",src:Zarafa.plugins.files.data.Actions.getDownloadLink(a),type:d},dgettext("plugin_files","Your browser does not support previewing of audio files!")]}}}else if(!Ext.isEmpty(b)&&/\.(mp4|ogg|webm)$/i.test(b)){d="";switch(b.toLowerCase()){case ".ogg":d="video/ogg";break;case ".webm":d="video/webm";break;default:d="audio/mp4"}c={xtype:"component",autoEl:{tag:"video",style:g+"height: auto;",
poster:"plugins/files/resources/images/preview/video_loader.gif",preload:"metadata",controls:"controls",cn:[{tag:"source",src:Zarafa.plugins.files.data.Actions.getDownloadLink(a),type:d},dgettext("plugin_files","Your browser does not support previewing of video files!")]}}}else c=f&&!Ext.isEmpty(b)&&/\.(odp|odt|ods)$/i.test(b)?{xtype:"filesplugin.webodfpanel",src:Zarafa.plugins.files.data.Actions.getDownloadLink(a),title:a.get("filename")}:{xtype:"component",autoEl:{tag:"img",src:this.defaultPreviewImage,
style:g}};else c={xtype:"component",autoEl:{tag:"iframe",width:"98%",height:"98%",border:"none",seamless:"",src:Zarafa.plugins.files.data.Actions.getDownloadLink(a)}};else c={xtype:"component",autoEl:{tag:"img",src:Zarafa.plugins.files.data.Actions.getDownloadLink(a),style:g}};this.filepreview.removeAll(!0);this.filepreview.add(c);this.filepreview.doLayout()},update:function(a){this.filename.setValue(a.get("filename"));var b=a.get("type")==Zarafa.plugins.files.data.FileTypes.FILE;this.filesize.setVisible(b);
b&&this.filesize.setValue(Zarafa.plugins.files.data.Utils.Format.fileSize(a.get("message_size")));var c=Ext.util.Format.date(new Date(a.get("lastmodified")),dgettext("plugin_files","d.m.Y G:i"));this.lastmodified.setValue(c);c=dgettext("plugin_files","Folder");if(b)var d=this.getExtension(a.get("filename")),c=String.format(dgettext("plugin_files","File ({0})"),d);this.type.setValue(c);b=a.getAccount().supportsFeature(Zarafa.plugins.files.data.AccountRecordFeature.SHARING);this.shared.setVisible(b);
b&&this.shared.setValue(a.get("isshared")?dgettext("plugin_files","Yes"):dgettext("plugin_files","No"));this.setPreviewPanel(a,d)},onRender:function(a,b){Zarafa.plugins.files.ui.FilesRecordDetailsPanel.superclass.onRender.call(this,a,b);this.resizeEl=this.positionEl=this.wrap=this.el.wrap({cls:"preview-body"})},getExtension:function(a){var b=a.lastIndexOf(".");return 0>b?"":a.substr(b)}});Ext.reg("filesplugin.filesrecorddetailspanel",Zarafa.plugins.files.ui.FilesRecordDetailsPanel);Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.FilesRecordGridColumnModel=Ext.extend(Zarafa.common.ui.grid.ColumnModel,{useCompactView:!1,constructor:function(a){a=a||{};this.defaultColumns=this.createDefaultColumns();this.compactColumns=this.createCompactColumns();Ext.applyIf(a,{columns:this.defaultColumns,defaults:{sortable:!0}});!0===a.useCompactView&&(a.columns=this.compactColumns);Ext.apply(this,a);Zarafa.plugins.files.ui.FilesRecordGridColumnModel.superclass.constructor.call(this,a)},createDefaultColumns:function(){return[{id:"type",
dataIndex:"type",header:'<p class="icon_index">&nbsp;</p>',headerCls:"zarafa-icon-column icon",renderer:Zarafa.plugins.files.data.Utils.Renderer.typeRenderer,width:24,fixed:!0,tooltip:dgettext("plugin_files","Sort by: Type")},{header:"ID",dataIndex:"id",width:50,hidden:!0,tooltip:dgettext("plugin_files","Sort by: ID")},{header:"Path",dataIndex:"path",width:100,hidden:!0,tooltip:dgettext("plugin_files","Sort by: Path")},{header:dgettext("plugin_files","Filename"),dataIndex:"filename",width:160,tooltip:dgettext("plugin_files",
"Sort by: Filename")},{header:dgettext("plugin_files","Last modified"),dataIndex:"lastmodified",width:160,renderer:Zarafa.plugins.files.data.Utils.Renderer.datetimeRenderer,tooltip:dgettext("plugin_files","Sort by: Last modified")},{header:dgettext("plugin_files","Size"),dataIndex:"message_size",width:80,renderer:Zarafa.plugins.files.data.Utils.Format.fileSizeList,tooltip:dgettext("plugin_files","Sort by: Size")},{id:"isshared",dataIndex:"isshared",header:'<p class="files_icon_12_share">&nbsp;</p>',
headerCls:"zarafa-icon-column icon",renderer:Zarafa.plugins.files.data.Utils.Renderer.sharedRenderer,listeners:{click:this.doOnShareButtonClick},width:32,fixed:!0,tooltip:dgettext("plugin_files","Sort by: Shared")}]},createCompactColumns:function(){return[{id:"column_type",dataIndex:"type",header:'<p class="icon_index">&nbsp;</p>',headerCls:"zarafa-icon-column icon",renderer:Zarafa.plugins.files.data.Utils.Renderer.typeRenderer,width:24,fixed:!0,tooltip:dgettext("plugin_files","Sort by: Type")},{header:dgettext("plugin_files",
"Filename"),dataIndex:"filename",width:160,tooltip:dgettext("plugin_files","Sort by: Filename")},{header:dgettext("plugin_files","Last modified"),dataIndex:"lastmodified",width:100,renderer:Zarafa.plugins.files.data.Utils.Renderer.datetimeRenderer,tooltip:dgettext("plugin_files","Sort by: Last modified")},{header:dgettext("plugin_files","Size"),dataIndex:"message_size",width:80,hidden:!0,renderer:Zarafa.plugins.files.data.Utils.Format.fileSizeList,tooltip:dgettext("plugin_files","Sort by: Size")},
{id:"isshared",dataIndex:"isshared",header:'<p class="files_icon_12_share">&nbsp;</p>',headerCls:"zarafa-icon-column icon",renderer:Zarafa.plugins.files.data.Utils.Renderer.sharedRenderer,listeners:{click:this.doOnShareButtonClick},width:32,fixed:!0,tooltip:dgettext("plugin_files","Sort by: Shared")}]},setCompactView:function(a){this.useCompactView!==a&&((this.useCompactView=a)?(this.name="compact",this.defaultColumns=this.config,this.columns=this.compactColumns):(this.name="default",this.compactColumns=
this.config,this.columns=this.defaultColumns),this.setConfig(this.columns,!1))},doOnShareButtonClick:function(a,b,c,d){a=b.store.getAt(c);!0===a.get("isshared")&&Zarafa.plugins.files.data.Actions.createShareDialog([a])}});Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.FilesRecordGridView=Ext.extend(Zarafa.common.ui.grid.GridPanel,{context:void 0,model:void 0,dropTarget:void 0,constructor:function(a){a=a||{};!Ext.isDefined(a.model)&&Ext.isDefined(a.context)&&(a.model=a.context.getModel());!Ext.isDefined(a.store)&&Ext.isDefined(a.model)&&(a.store=a.model.getStore());a.store=Ext.StoreMgr.lookup(a.store);Ext.applyIf(a,{xtype:"filesplugin.filesrecordgridview",ddGroup:"dd.filesrecord",id:"files-gridview",enableDragDrop:!0,border:!1,stateful:!0,
statefulRelativeDimensions:!1,loadMask:this.initLoadMask(),viewConfig:this.initViewConfig(),sm:this.initSelectionModel(),cm:this.initColumnModel(),keys:{key:Ext.EventObject.DELETE,handler:this.onKeyDelete,scope:this}});Zarafa.plugins.files.ui.FilesRecordGridView.superclass.constructor.call(this,a)},initEvents:function(){Zarafa.plugins.files.ui.FilesRecordGridView.superclass.initEvents.call(this);this.mon(this,"cellcontextmenu",this.onCellContextMenu,this);this.mon(this,"rowbodycontextmenu",this.onRowBodyContextMenu,
this);this.mon(this,"rowdblclick",this.onRowDblClick,this);this.mon(this,"afterrender",this.initDropTarget,this);this.mon(this.getSelectionModel(),"rowselect",this.onRowSelect,this,{buffer:1});this.mon(this.getSelectionModel(),"selectionchange",this.onSelectionChange,this,{buffer:1});this.mon(this.context,"viewmodechange",this.onContextViewModeChange,this);this.onContextViewModeChange(this.context,this.context.getCurrentViewMode());this.mon(this.bwrap,"drop",this.onDropItemToUpload,this)},initLoadMask:function(){return{msg:dgettext("plugin_files",
"Loading files")+"..."}},initViewConfig:function(){return{enableRowBody:!1,rowSelectorDepth:15}},initSelectionModel:function(){return new Ext.grid.RowSelectionModel},initColumnModel:function(){return new Zarafa.plugins.files.ui.FilesRecordGridColumnModel},initDropTarget:function(){this.dropTarget=new Ext.dd.DropTarget(this.getEl(),{ddGroup:"dd.filesrecord",copy:!1,gridStore:this.getStore(),gridSM:this.getSelectionModel(),notifyDrop:function(a,b,c){if(this.notifyOver(a,b,c)!==this.dropAllowed)return!1;
a=a.getDragData(b).rowIndex;b=this.gridStore.getAt(a);return Ext.isDefined(a)&&b.get("type")===Zarafa.plugins.files.data.FileTypes.FOLDER?(Ext.each(c.selections,function(a){a.setDisabled(!0)}),Zarafa.plugins.files.data.Actions.moveRecords(c.selections,b,{hierarchyStore:this.gridStore.hierarchyStore})):!1},notifyOver:function(a,b,c){a=a.getDragData(b).rowIndex;var d=this.dropNotAllowed;if(Ext.isDefined(a)){var e=this.gridStore.getAt(a);e.get("type")===Zarafa.plugins.files.data.FileTypes.FOLDER&&(d=
this.dropAllowed);Ext.each(c.selections,function(a){var b=a.get("folder_id"),c=e.get("folder_id");if(b===c||".."===a.get("filename")||c.slice(0,b.length)===b)return d=this.dropNotAllowed,!1},this)}return d},notifyEnter:function(a,b,c){return this.notifyOver(a,b,c)}});this.getView().dragZone.onBeforeDrag=function(a,b){var c=!0,d=!1,e=a.grid.getStore().getAt(a.rowIndex);Ext.each(a.selections,function(a){e.get("id")===a.get("id")&&(d=!0);if(".."===a.get("filename")||a.getDisabled())return c=!1});return d?
c:".."===e.get("filename")||e.getDisabled()?!1:!0}},onDropItemToUpload:function(a){a.stopPropagation();a.preventDefault();Zarafa.plugins.files.data.Actions.uploadAsyncItems(a.browserEvent.target.files||a.browserEvent.dataTransfer.files,this.getStore())},onContextViewModeChange:function(a,b,c){a=b===Zarafa.plugins.files.data.ViewModes.RIGHT_PREVIEW;this.getColumnModel().setCompactView(a)},onCellContextMenu:function(a,b,c,d){a=this.getSelectionModel();a.hasSelection()?a.isSelected(b)||(a.clearSelections(),
a.selectRow(b)):a.selectRow(b);b=a.getSelections();b.some(function(a){return!0===a.getDisabled()},this)||Zarafa.core.data.UIFactory.openDefaultContextMenu(b,{position:d.getXY(),context:this.context})},onRowBodyContextMenu:function(a,b,c){this.onCellContextMenu(a,b,-1,c)},onRowDblClick:function(a,b){var c=this.getStore().getAt(b);c.get("type")===Zarafa.plugins.files.data.FileTypes.FOLDER?Zarafa.plugins.files.data.Actions.openFolder(this.model,c.get("entryid")):Zarafa.plugins.files.data.Actions.downloadItem(c)},
onKeyDelete:function(a,b){var c=this.getSelectionModel().getSelections();Zarafa.plugins.files.data.Actions.deleteRecords(c)},onRowSelect:function(a,b,c){b=this.context.getCurrentViewMode();a=a.getCount();b===Zarafa.plugins.files.data.ViewModes.NO_PREVIEW||1<a||c.getDisabled()||(1===a?(a=container.getSettingsModel().get("zarafa/v1/contexts/files/files_path")+"/",c.get("folder_id")!==a&&this.model.setPreviewRecord(c)):this.model.setPreviewRecord(void 0))},onSelectionChange:function(a){a=a.getSelections();
this.model.setSelectedRecords(Ext.isEmpty(a)?void 0:a)}});Ext.reg("filesplugin.filesrecordgridview",Zarafa.plugins.files.ui.FilesRecordGridView);Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.FilesRecordIconView=Ext.extend(Zarafa.common.ui.DraggableDataView,{context:void 0,model:void 0,dropTarget:void 0,keyMap:void 0,constructor:function(a){a=a||{};!Ext.isDefined(a.model)&&Ext.isDefined(a.context)&&(a.model=a.context.getModel());!Ext.isDefined(a.store)&&Ext.isDefined(a.model)&&(a.store=a.model.getStore());a.store=Ext.StoreMgr.lookup(a.store);a.plugins=Ext.value(a.plugins,[]);a.plugins.push("zarafa.icondragselectorplugin");Ext.applyIf(a,{xtype:"filesplugin.filesrecordiconview",
cls:"zarafa-files-iconview",loadingText:dgettext("plugin_files","Loading files")+"...",deferEmptyText:!1,autoScroll:!0,emptyText:'<div class="emptytext">'+dgettext("plugin_files","There are no items to show in this view")+"</div>",overClass:"zarafa-files-iconview-over",tpl:this.initTemplate(),multiSelect:!0,selectedClass:"zarafa-files-iconview-selected",itemSelector:"div.zarafa-files-iconview-thumb",enableDragDrop:!0,ddGroup:"dd.filesrecord"});Zarafa.plugins.files.ui.FilesRecordIconView.superclass.constructor.call(this,
a);this.initEvents()},initTemplate:function(){return new Ext.XTemplate('<div style="height: 100%; width: 100%; overflow: auto;">','<tpl for=".">','<div class="zarafa-files-iconview-thumb">','<div class="zarafa-files-iconview-icon {.:this.getTheme} {.:this.getHidden}"></div>','<div class="zarafa-files-iconview-subject">{filename:htmlEncode}</div>',"</div>","</tpl>","</div>",{getHidden:function(a){return".."===a.filename?"files_type_hidden":""},getTheme:function(a){switch(a.type){case Zarafa.plugins.files.data.FileTypes.FOLDER:return Zarafa.plugins.files.data.Utils.File.getIconClass("folder");
case Zarafa.plugins.files.data.FileTypes.FILE:return Zarafa.plugins.files.data.Utils.File.getIconClass(a.filename);default:return"files48icon_blank"}}})},initEvents:function(){this.on({contextmenu:this.onFilesIconContextMenu,dblclick:this.onIconDblClick,selectionchange:this.onSelectionChange,afterrender:this.onAfterRender,scope:this});this.mon(this.store,"createfolder",this.onCreateFolder,this)},onCreateFolder:function(a,b,c){a.getPath()===b&&(b=Zarafa.core.data.RecordFactory.createRecordObjectByCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_FILES,
c),a.add(b),a.on("update",Zarafa.plugins.files.data.Actions.doRefreshIconView,Zarafa.plugins.files.data.Actions,{single:!0}),b.commit(!0))},onAfterRender:function(){Zarafa.core.KeyMapMgr.isGloballyEnabled()&&(this.keyMap=new Ext.KeyMap(this.getEl(),{key:Ext.EventObject.DELETE,fn:this.onKeyDelete.createDelegate(this)}),Zarafa.core.KeyMapMgr.disableAllKeymaps(this.getEl()));this.initDropTarget()},onKeyDelete:function(a,b){var c=this.getSelectedRecords();Zarafa.plugins.files.data.Actions.deleteRecords(c)},
initDropTarget:function(){var a=this.getEl(),b=a.wrap({cls:"x-form-field-wrap"});this.mon(b,"drop",this.onDropItemToUpload,this);this.dropTarget=new Ext.dd.DropTarget(a,{ddGroup:"dd.filesrecord",copy:!1,fileStore:this.getStore(),model:this.model,notifyDrop:function(a,b,e){if(this.notifyOver(a,b,e)!==this.dropAllowed)return!1;a=a.getDragData(b);return Ext.isDefined(a)&&(a=a.index,b=this.fileStore.getAt(a),Ext.isDefined(a)&&b.get("type")===Zarafa.plugins.files.data.FileTypes.FOLDER)?(Ext.each(e.selections,
function(a){a.setDisabled(!0)}),Zarafa.plugins.files.data.Actions.moveRecords(e.selections,b,{hierarchyStore:this.model.getHierarchyStore()})):!1},notifyOver:function(a,b,e){a=a.getDragData(b);var c=this.dropNotAllowed;if(Ext.isDefined(a)&&(a=a.index,Ext.isDefined(a))){var d=this.fileStore.getAt(a);d.get("type")===Zarafa.plugins.files.data.FileTypes.FOLDER&&(c=this.dropAllowed);Ext.each(e.selections,function(a){var b=a.get("id"),e=d.get("id");if(b===e||".."===a.get("filename")||e.slice(0,b.length)===
b)return c=this.dropNotAllowed,!1},this)}return c},notifyEnter:function(a,b,e){return this.notifyOver(a,b,e)}});this.dragZone.onBeforeDrag=function(a,b){var c=!0,d=!1,g=this.view.getStore().getAt(a.index);Ext.each(a.selections,function(a){g.get("id")===a.get("id")&&(d=!0);if(a.getDisabled())return c=!1});return d?c:g.getDisabled()?!1:!0}},onDropItemToUpload:function(a){a.stopPropagation();a.preventDefault();Zarafa.plugins.files.data.Actions.uploadAsyncItems(a.browserEvent.target.files||a.browserEvent.dataTransfer.files,
this.getStore())},onFilesIconContextMenu:function(a,b,c,d){a.isSelected(c)||a.select(c);a=a.getSelectedRecords();var e=!0;Ext.each(a,function(a){!0===a.getDisabled()&&(e=!1)});e&&Zarafa.core.data.UIFactory.openDefaultContextMenu(a,{position:d.getXY(),context:this.context})},onIconDblClick:function(a,b,c,d){a=this.getStore().getAt(b);a.get("type")===Zarafa.plugins.files.data.FileTypes.FOLDER?Zarafa.plugins.files.data.Actions.openFolder(this.model,a.get("entryid")):Zarafa.plugins.files.data.Actions.downloadItem(a)},
onSelectionChange:function(a,b){var c=a.getSelectedRecords(),c=c.filter(function(a){return Ext.isDefined(a)},this);this.model.setSelectedRecords(c,!1);var d=this.context.getCurrentViewMode(),e=c.length;d!==Zarafa.plugins.files.data.ViewModes.NO_PREVIEW&&(1!==e?this.model.setPreviewRecord(void 0):1==e&&(c[0].get("folder_id")!==container.getSettingsModel().get("zarafa/v1/contexts/files/files_path")+"/"&&".."!==c[0].get("filename")?this.model.setPreviewRecord(c[0]):this.model.setPreviewRecord(void 0)))}});
Ext.reg("filesplugin.filesrecordiconview",Zarafa.plugins.files.ui.FilesRecordIconView);Ext.namespace("Zarafa.plugins.files.ui");Zarafa.plugins.files.ui.FilesRecordViewPanel=Ext.extend(Ext.Panel,{constructor:function(a){a=a||{};Ext.applyIf(a,{xtype:"filesplugin.filesrecordviewpanel",border:!1,cls:"zarafa-filesviewpanel",layout:"zarafa.collapsible",items:[{xtype:"filesplugin.filesrecorddetailspanel"}]});Zarafa.plugins.files.ui.FilesRecordViewPanel.superclass.constructor.call(this,a)}});
Ext.reg("filesplugin.filesrecordviewpanel",Zarafa.plugins.files.ui.FilesRecordViewPanel);Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.FilesTopToolbar=Ext.extend(Ext.Toolbar,{context:void 0,model:void 0,constructor:function(a){a=a||{};!Ext.isDefined(a.model)&&Ext.isDefined(a.context)&&(a.model=a.context.getModel());Ext.applyIf(a,{cls:"files_top_toolbar",items:[{xtype:"filesplugin.navigationbar",model:a.model,accountsStore:a.context.getAccountsStore()},{xtype:"tbfill"},{xtype:"filesplugin.quotabar",model:a.model,accountsStore:a.context.getAccountsStore()}]});Zarafa.plugins.files.ui.FilesTopToolbar.superclass.constructor.call(this,
a)}});Ext.reg("filesplugin.filestoptoolbar",Zarafa.plugins.files.ui.FilesTopToolbar);Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.FilesTreeContextMenu=Ext.extend(Zarafa.core.ui.menu.ConditionalMenu,{model:void 0,constructor:function(a){a=a||{};Ext.applyIf(a,{items:[this.createContextActionItems(),{xtype:"menuseparator"},container.populateInsertionPoint("plugin.files.treecontextmenu.actions",this),{xtype:"menuseparator"},container.populateInsertionPoint("plugin.files.treecontextmenu.options",this)]});Zarafa.plugins.files.ui.FilesTreeContextMenu.superclass.constructor.call(this,a)},createContextActionItems:function(){return[{xtype:"zarafa.conditionalitem",
text:dgettext("plugin_files","New Folder"),iconCls:"files_icon_action files_icon_action_new_folder",handler:this.onContextItemNewFolder,scope:this},{xtype:"zarafa.conditionalitem",text:dgettext("plugin_files","Refresh"),iconCls:"files_icon_action icon_cache",handler:this.onContextItemRefresh,beforeShow:this.onBeforeShowItem,name:"refresh",scope:this},{xtype:"zarafa.conditionalitem",text:dgettext("plugin_files","Rename"),iconCls:"files_icon_action files_icon_action_edit",handler:this.onContextItemRename,
name:"rename",beforeShow:this.onBeforeShowItem,scope:this},{xtype:"zarafa.conditionalitem",text:dgettext("plugin_files","Delete"),iconCls:"files_icon_action files_icon_action_delete",name:"delete",handler:this.onContextItemDelete,beforeShow:this.onBeforeShowItem,scope:this}]},onBeforeShowItem:function(a,b){var c=Zarafa.plugins.files.data.Utils.File.stripAccountId(b.get("folder_id"));"refresh"===a.name?a.setVisible("/"===c):a.setVisible("/"!==c)},onContextItemRefresh:function(){this.model.getHierarchyStore().reload()},
onContextItemDelete:function(){Zarafa.plugins.files.data.Actions.deleteRecords(this.records)},onContextItemNewFolder:function(){Zarafa.plugins.files.data.Actions.createFolder(this.model,void 0,this.records)},onContextItemRename:function(){Zarafa.plugins.files.data.Actions.openRenameDialog(this.records)}});Ext.reg("filesplugin.filestreecontextmenu",Zarafa.plugins.files.ui.FilesTreeContextMenu);Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.FolderNodeUI=Ext.extend(Ext.tree.TreeNodeUI,{renderElements:function(a,b,c,d){this.indentMarkup=a.parentNode?a.parentNode.ui.getChildIndent():"";var e=Ext.isBoolean(b.checked),f,g='<li class="x-tree-node"><div ext:tree-node-id="'+a.id+'" class="x-tree-node-el x-tree-node-leaf x-unselectable zarafa-hierarchy-node" unselectable="on"><span class="x-tree-node-indent">'+this.indentMarkup+'</span><img src="'+this.emptyIcon+'" class="x-tree-ec-icon x-tree-elbow" />'+(e?'<input class="x-tree-node-cb zarafa-hierarchy-node-cb" type="checkbox" '+
(b.checked?'checked="checked" />':"/>"):"")+('<img src="'+(b.icon||this.emptyIcon)+'" class="x-tree-node-icon" unselectable="on" />')+'<a hidefocus="on" class="x-tree-node-anchor zarafa-hierarchy-node-anchor" href="'+(b.href?b.href:Ext.isGecko?"":"#")+'" tabIndex="1" '+(b.hrefTarget?' target="'+b.hrefTarget+'"':"")+'><span unselectable="on">'+(a.tpl?a.tpl.apply(b):a.text)+'</span><span class="zarafa-hierarchy-node-backend" unselectable="on"></span></a></div><ul class="x-tree-node-ct" style="display:none;"></ul></li>';
!0!==d&&a.nextSibling&&(f=a.nextSibling.ui.getEl())?this.wrap=Ext.DomHelper.insertHtml("beforeBegin",f,g):this.wrap=Ext.DomHelper.insertHtml("beforeEnd",c,g);this.elNode=this.wrap.childNodes[0];this.ctNode=this.wrap.childNodes[1];c=this.elNode.childNodes;this.indentNode=c[0];this.ecNode=c[1];this.iconNode=c[2];d=3;e&&(this.checkbox=c[2],this.iconNode=c[3],d++);this.anchor=c[d];this.textNode=c[d].firstChild;this.folderBackendNode=c[d].firstChild.nextSibling;e=Ext.get(this.elNode);c=Ext.get(this.iconNode);
d=Ext.get(this.wrap);Ext.isEmpty(b.cls)||e.addClass(b.cls);b.icon&&c.addClass("x-tree-node-inline-icon");b.iconCls&&c.addClass(b.iconCls);Ext.isEmpty(b.containerCls)||d.addClass(b.containerCls);this.showFolderBackend(a)},onContainerClsChange:function(a,b,c){this.rendered&&(a=Ext.get(this.wrap),Ext.isEmpty(c)?a.addClass(b):a.replaceClass(c,b))},onTextChange:function(a,b,c){this.rendered&&(this.textNode.innerHTML=a.tpl?a.tpl.apply(a.attributes):b)},onIconChange:function(a,b,c){this.rendered&&(a=Ext.get(this.iconNode),
Ext.isEmpty(c)?a.addClass(b):a.replaceClass(c,b))},showFolderBackend:function(a){var b=a.getFolder();Ext.isDefined(b)&&b.isSubTreeFolder()&&(a=Ext.get(this.folderBackendNode),b=" - "+b.getFilesStore().getBackend(),a.update(b),a.repaint())}});Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.MultipleFileUploadField=Ext.extend(Ext.ux.form.FileUploadField,{createFileInput:function(){var a={id:this.getFileInputId(),name:this.name||this.getId(),cls:"x-form-file",tag:"input",type:"file",size:1,multiple:"multiple"};this.fileInput=this.wrap.createChild(a)},bindListeners:function(){this.fileInput.on({scope:this,mouseenter:function(){this.button.addClass(["x-btn-over","x-btn-focus"])},mouseleave:function(){this.button.removeClass(["x-btn-over","x-btn-focus","x-btn-click"])},
mousedown:function(){this.button.addClass("x-btn-click")},mouseup:function(){this.button.removeClass(["x-btn-over","x-btn-focus","x-btn-click"])},change:function(){var a=this.fileInput.dom.value;1<this.fileInput.dom.files.length&&(a=this.fileInput.dom.files.length+" "+dgettext("plugin_files","files selected"));this.setValue(a);this.fireEvent("fileselected",this,a)}})}});Ext.reg("filesplugin.multiplefileuploadfield",Zarafa.plugins.files.ui.MultipleFileUploadField);Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.Tree=Ext.extend(Ext.tree.TreePanel,{accountFilter:void 0,nodeConfig:void 0,FilesFilter:void 0,treeSorter:!0,constructor:function(a){a=a||{};Ext.isDefined(a.accountFilter)&&(this.accountFilter=a.accountFilter);a.store||(a.store=a.model.getHierarchyStore());Ext.applyIf(a,{xtype:"filesplugin.tree",enableDD:!0,border:!1,ddGroup:"dd.filesrecord",ddAppendOnly:!0,pathSeparator:"&",root:new Zarafa.plugins.files.ui.FilesHierarchyRootNode({text:"Files",id:"#R#",cc:!1,leaf:!1,expanded:!0,
uiProvider:Ext.tree.RootTreeNodeUI}),expanded:!0,rootVisible:!1,autoScroll:!0,maskDisabled:!0});Zarafa.plugins.files.ui.Tree.superclass.constructor.call(this,a);!this.treeSorter||this.treeSorter instanceof Ext.tree.TreeSorter||(this.treeSorter=new Ext.tree.TreeSorter(this))},initEvents:function(){Zarafa.plugins.files.ui.Tree.superclass.initEvents.apply(this,arguments);this.on("afterrender",this.onAfterRenderTree,this)},initComponent:function(){this.loader||(this.loader=new Zarafa.plugins.files.data.NavigatorTreeLoader({tree:this,
store:this.store,nodeConfig:this.nodeConfig,deferredLoading:this.deferredLoading}));Zarafa.plugins.files.ui.Tree.superclass.initComponent.apply(this,arguments);if(this.loadMask)this.on("render",this.createLoadMask,this)},createLoadMask:function(){this.loadMask=new Zarafa.common.ui.LoadMask(this.ownerCt.getEl(),Ext.apply({store:this.store},this.loadMask));this.store.isLoading()&&this.loadMask.show()},onAfterRenderTree:function(){this.mon(this.selModel,"selectionchange",this.onSelectionChange,this)},
onSelectionChange:function(a,b){Ext.isEmpty(b)||b.isExpandable()&&!b.isExpanded()&&b.expand(!1,!0)},selectFolderInTree:function(a,b){var c;return(c=!1!==b?this.ensureFolderVisible(a):this.getNodeById(a.id))?(this.getSelectionModel().select(c,void 0,b),!0):!1},ensureFolderVisible:function(a){var b=this.getNodeById(a.id);if(!b){b=a.getParentFolder();if(!b)return!1;b=this.ensureFolderVisible(b);if(!b)return!1;b.expand();b=this.getNodeById(a.id)}return b?(b.ensureVisible(),b=this.getNodeById(a.id),b.update(!0),
b):!1},nodeFilter:function(a){var b=!1;Ext.isDefined(this.accountFilter)&&(b=a.getFilesStore().get("entryid")!==this.accountFilter);!b&&Ext.isDefined(this.FilesFilter)&&(b=a.get("object_type")!==Zarafa.plugins.files.data.FileTypes.FOLDER);!b&&a.isHomeFolder()&&(b=!0);return!b}});Ext.reg("filesplugin.tree",Zarafa.plugins.files.ui.Tree);Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.TreeSorter=Ext.extend(Ext.tree.TreeSorter,{constructor:function(a,b){Zarafa.plugins.files.ui.TreeSorter.superclass.constructor.apply(this,arguments);this.sortFn=this.hierarchySort.createDelegate(this)},hierarchySort:function(a,b){var c=a.attributes,d=b.attributes,e=c.isFolder,f=d.isFolder;return e&&f||!e&&!f?(d=d.text,c.text.toUpperCase()<d.toUpperCase()?-1:1):!e&&f?1:-1}});Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.UploadComponent=Ext.extend(Ext.Component,{callback:Ext.emptyFn,scope:void 0,multiple:!1,accept:void 0,constructor:function(a){a=a||{};Ext.applyIf(a,{xtype:"filesplugin.uploadcomponent"});Zarafa.plugins.files.ui.UploadComponent.superclass.constructor.call(this,a)},openUploadDialog:function(){var a=this.getUploadEl();a.on("change",this.onFileInputChange,this);a.dom.click()},getUploadEl:function(){var a=Ext.DomHelper.append(Ext.getBody(),{cls:"x-hidden",tag:"input",type:"file"});
Ext.isDefined(this.multiple)&&this.multiple&&(a.multiple=this.multiple);Ext.isDefined(this.accept)&&(a.accept=this.accept);return a=Ext.get(a)},onFileInputChange:function(a){var b=a.browserEvent;a=Ext.get(b.target);b=(b=b.dataTransfer)?b.files:void 0;this.callback.call(this.scope,a.dom.files||b);a.remove()}});Ext.reg("filesplugin.uploadcomponent",Zarafa.plugins.files.ui.UploadComponent);Ext.namespace("Zarafa.plugins.files.ui.dialogs");
Zarafa.plugins.files.ui.dialogs.AttachFromFilesContentPanel=Ext.extend(Zarafa.core.ui.ContentPanel,{constructor:function(a){a=a||{};Ext.applyIf(a,{layout:"fit",title:dgettext("plugin_files","Add attachment from Files"),closeOnSave:!0,width:400,height:300,items:[{xtype:"filesplugin.attachfromfilespanel",model:a.model,emailrecord:a.record}]});Zarafa.plugins.files.ui.dialogs.AttachFromFilesContentPanel.superclass.constructor.call(this,a)}});Ext.reg("filesplugin.attachfromfilescontentpanel",Zarafa.plugins.files.ui.dialogs.AttachFromFilesContentPanel);
Ext.namespace("Zarafa.plugins.files.ui.dialogs");
Zarafa.plugins.files.ui.dialogs.AttachFromFilesGridPanel=Ext.extend(Ext.grid.GridPanel,{constructor:function(a){a=a||{};var b=new Ext.grid.CheckboxSelectionModel({checkOnly:!0,headerCls:"zarafa-icon-column",header:'<p class="icon_all_day">&nbsp;<span class="title">'+_("All Day")+"</span></p>",width:24});Ext.applyIf(a,{xtype:"filesplugin.attachfromfilesgridpanel",style:{paddingLeft:"9px"},columns:[b,{id:"type",dataIndex:"type",header:'<p class="icon_index">&nbsp;</p>',headerCls:"zarafa-icon-column icon",
renderer:Zarafa.plugins.files.data.Utils.Renderer.typeRenderer,width:24,fixed:!0,tooltip:dgettext("plugin_files","Sort by: Type")},{header:dgettext("plugin_files","Filename"),dataIndex:"filename",width:160,tooltip:dgettext("plugin_files","Sort by: Filename")},{header:dgettext("plugin_files","Size"),dataIndex:"message_size",width:80,renderer:Zarafa.plugins.files.data.Utils.Format.fileSizeList,tooltip:dgettext("plugin_files","Sort by: Size")}],selModel:b,loadMask:{msg:_("Loading files")+"..."},store:{xtype:"filesplugin.filesrecordstore"},
viewConfig:{forceFit:!0}});Zarafa.plugins.files.ui.dialogs.AttachFromFilesGridPanel.superclass.constructor.call(this,a)}});Ext.reg("filesplugin.attachfromfilesgridpanel",Zarafa.plugins.files.ui.dialogs.AttachFromFilesGridPanel);Ext.namespace("Zarafa.plugins.files.ui.dialogs");
Zarafa.plugins.files.ui.dialogs.AttachFromFilesPanel=Ext.extend(Ext.Panel,{emailRecord:void 0,constructor:function(a){a=a||{};Ext.isDefined(a.emailrecord)&&(this.emailRecord=a.emailrecord);a=Ext.applyIf(a,{xtype:"filesplugin.attachfromfilespanel",layout:{type:"hbox",align:"stretch"},border:!1,header:!1,items:[{xtype:"filesplugin.tree",model:a.model,border:!0,flex:1,ref:"hierarchyTree"},{xtype:"filesplugin.attachfromfilesgridpanel",ref:"attachGrid",flex:2}],buttonAlign:"right",buttons:this.createActionButtons()});
Zarafa.plugins.files.ui.dialogs.AttachFromFilesPanel.superclass.constructor.call(this,a);Ext.isDefined(this.model)&&this.mon(this.hierarchyTree,"click",this.onTreeNodeClick,this)},onTreeNodeClick:function(a){a=a.getFolder();this.attachGrid.store.load({params:{only_files:!0},folder:a})},createActionButtons:function(){return[{xtype:"button",text:dgettext("plugin_files","Add attachment"),iconCls:"icon_files_category_white",handler:this.downloadSelectedFilesFromFilesToTmp,scope:this},{text:dgettext("plugin_files",
"Cancel"),handler:this.onClickCancel,scope:this}]},onClickCancel:function(){this.dialog.close()},downloadSelectedFilesFromFilesToTmp:function(){var a=this.attachGrid.getSelectionModel().getSelections(),b=[],c=this.dialog.record;Ext.isDefined(this.emailRecord)&&(c=this.emailRecord);var c=c.getAttachmentStore(),d=container.getServerConfig().getMaxAttachmentSize(),e=!1;Ext.each(a,function(a,c){if(a.get("message_size")>d)return Zarafa.common.dialogs.MessageBox.show({title:dgettext("plugin_files","Warning"),
msg:String.format(dgettext("plugin_files","The file {0} is too large!"),a.get("filename"))+" ("+dgettext("plugin_files","max")+": "+Ext.util.Format.fileSize(d)+")",icon:Zarafa.common.dialogs.MessageBox.WARNING,buttons:Zarafa.common.dialogs.MessageBox.OK}),e=!0,!1;b.push(a.get("folder_id"))});if(!e)if(1>b.length)Ext.MessageBox.show({title:dgettext("plugin_files","Warning"),msg:dgettext("plugin_files","You have to choose at least one file!"),icon:Zarafa.common.dialogs.MessageBox.WARNING,buttons:Zarafa.common.dialogs.MessageBox.OK});
else try{this.disable(),container.getRequest().singleRequest("filesbrowsermodule","downloadtotmp",{ids:b,dialog_attachments:c.getId()},new Zarafa.core.data.AbstractResponseHandler({doDownloadtotmp:this.addDownloadedFilesAsAttachmentToEmail.createDelegate(this)}))}catch(f){Zarafa.common.dialogs.MessageBox.show({title:dgettext("plugin_files","Warning"),msg:f.getMessage(),icon:Zarafa.common.dialogs.MessageBox.WARNING,buttons:Zarafa.common.dialogs.MessageBox.OK})}},convertDownloadedFileInfoToAttachmentRecord:function(a){var b=
Zarafa.core.data.RecordFactory.createRecordObjectByObjectType(Zarafa.core.mapi.ObjectType.MAPI_ATTACH);b.set("tmpname",a.tmpname);b.set("name",a.name);b.set("size",a.size);b.set("attach_id",a.attach_id);return b},addDownloadedFilesAsAttachmentToEmail:function(a){a=a.items;var b=this.dialog.record;Ext.isDefined(this.emailRecord)&&(b=this.emailRecord);var c=b.getAttachmentStore();Ext.each(a,function(a){a=this.convertDownloadedFileInfoToAttachmentRecord(a);c.add(a)},this);this.dialog.close()}});
Ext.reg("filesplugin.attachfromfilespanel",Zarafa.plugins.files.ui.dialogs.AttachFromFilesPanel);Ext.namespace("Zarafa.plugins.files.ui.dialogs");
Zarafa.plugins.files.ui.dialogs.CreateFolderContentPanel=Ext.extend(Zarafa.core.ui.RecordContentPanel,{constructor:function(a){a=a||{};Ext.applyIf(a,{xtype:"zarafa.createfoldercontentpanel",layout:"fit",title:dgettext("plugin_files","Create New Folder"),recordComponentPluginConfig:Ext.applyIf(a.recordComponentPluginConfig||{},{allowWrite:!0,ignoreUpdates:!1,useShadowStore:!0,shadowStore:new Zarafa.plugins.files.data.FilesShadowStore}),showLoadMask:!1,showInfoMask:!1,width:300,height:350,items:[{xtype:"filesplugin.createfolderpanel",
accountFilter:a.accountFilter,parentFolder:a.parentFolder,model:a.model}]});Zarafa.plugins.files.ui.dialogs.CreateFolderContentPanel.superclass.constructor.call(this,a)},onUpdateRecord:function(a,b,c){Zarafa.plugins.files.ui.dialogs.CreateFolderContentPanel.superclass.onUpdateRecord.apply(this,arguments);if(b==Ext.data.Record.COMMIT)return this.close(),!1}});Ext.reg("filesplugin.createfoldercontentpanel",Zarafa.plugins.files.ui.dialogs.CreateFolderContentPanel);Ext.namespace("Zarafa.plugins.files.ui.dialogs");
Zarafa.plugins.files.ui.dialogs.CreateFolderPanel=Ext.extend(Ext.Panel,{parentFolder:void 0,constructor:function(a){a=a||{};a.plugins=Ext.value(a.plugins,[]);a.plugins.push("zarafa.recordcomponentupdaterplugin");a=Ext.applyIf(a,{xtype:"filesplugin.createfolderpanel",layout:{type:"fit",align:"stretch"},border:!1,header:!1,items:this.createPanel(a),buttonAlign:"right",buttons:[{text:dgettext("plugin_files","Ok"),ref:"../okButton",cls:"zarafa-action",handler:this.onOk,scope:this},{text:dgettext("plugin_files",
"Cancel"),ref:"../cancelButton",handler:this.onCancel,scope:this}]});Zarafa.plugins.files.ui.dialogs.CreateFolderPanel.superclass.constructor.call(this,a)},createPanel:function(a){return[{xtype:"panel",layout:"form",border:!1,defaults:{anchor:"100%"},labelAlign:"top",items:[{xtype:"textfield",fieldLabel:dgettext("plugin_files","Name"),cls:"form-field-name",ref:"../newNameField"},{xtype:"filesplugin.tree",model:a.model,FilesFilter:Zarafa.plugins.files.data.FileTypes.FOLDER,bodyCssClass:"files-create-folder-tree-panel",
fieldLabel:dgettext("plugin_files","Select where to place the folder"),anchor:"100% 80%",forceLayout:!0,ref:"../hierarchyTree",accountFilter:a.accountFilter}]}]},initEvents:function(){Zarafa.plugins.files.ui.dialogs.CreateFolderPanel.superclass.initEvents.apply(this,arguments);this.parentFolder&&this.mon(this.hierarchyTree,"load",this.onTreeNodeLoad,this);this.mon(this.hierarchyTree.getSelectionModel(),"selectionchange",this.onHierarchyNodeSelect,this)},onCancel:function(){this.dialog.close()},onOk:function(a,
b){var c=this.newNameField.getValue();if(Ext.isEmpty(c.trim()))Ext.MessageBox.show({title:dgettext("plugin_files","Kopano WebApp"),msg:dgettext("plugin_files","You must specify a name."),buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.INFO,scope:this});else if(this.parentFolder.getChildren().some(function(a){return a.get("filename")===c}))Zarafa.plugins.files.data.Actions.msgWarning(dgettext("plugin_files","Folder already exists"));else if(Zarafa.plugins.files.data.Utils.File.isValidFilename(c)){var d=
this.record;d.beginEdit();d.set("display_name",c);d.set("filename",c);d.set("text",c);d.set("icon_index",Zarafa.core.mapi.IconIndex.folder_note);d.set("folder_id",this.parentFolder.get("folder_id")+c+"/");d.set("path",this.parentFolder.get("folder_id"));d.set("parent_entryid",this.parentFolder.get("entryid"));d.set("store_entryid",this.parentFolder.get("store_entryid"));d.endEdit();this.dialog.saveRecord()}else Zarafa.plugins.files.data.Actions.msgWarning(dgettext("plugin_files","Incorrect foldername"))},
onHierarchyNodeSelect:function(a,b){b&&(this.parentFolder=b.getFolder())},onTreeNodeLoad:function(){this.hierarchyTree.selectFolderInTree(this.parentFolder)&&(this.mun(this.hierarchyTree,"load",this.onTreeNodeLoad,this),this.newNameField.focus())},update:function(a,b){this.record=a}});Ext.reg("filesplugin.createfolderpanel",Zarafa.plugins.files.ui.dialogs.CreateFolderPanel);Ext.namespace("Zarafa.plugins.files.ui.dialogs");
Zarafa.plugins.files.ui.dialogs.FilesRecordContentPanel=Ext.extend(Zarafa.core.ui.ContentPanel,{constructor:function(a){a=a||{};Ext.applyIf(a,{xtype:"filesplugin.filesrecordcontentpanel",layout:"fit",title:dgettext("plugin_files","File information"),items:[this.createPanel(a)]});Zarafa.plugins.files.ui.dialogs.FilesRecordContentPanel.superclass.constructor.call(this,a)},createPanel:function(a){return{xtype:"filesplugin.filesrecorddetailspanel",record:a.record}}});
Ext.reg("filesplugin.filesrecordcontentpanel",Zarafa.plugins.files.ui.dialogs.FilesRecordContentPanel);Ext.namespace("Zarafa.plugins.files.ui.dialogs");
Zarafa.plugins.files.ui.dialogs.FilesUploadContentPanel=Ext.extend(Zarafa.core.ui.ContentPanel,{targetFolder:void 0,constructor:function(a){a=a||{};Ext.applyIf(a,{xtype:"filesplugin.filesuploadcontentpanel",layout:"fit",title:dgettext("plugin_files","Upload file"),items:[{xtype:"form",ref:"mainuploadform",layout:{type:"vbox",align:"stretch",pack:"start"},fileUpload:!0,padding:5,items:[this.createFolderSelector(),this.createUploadField()],buttons:this.createActionButtons()}]});Zarafa.plugins.files.ui.dialogs.FilesUploadContentPanel.superclass.constructor.call(this,
a)},createUploadField:function(){return{xtype:"panel",title:dgettext("plugin_files","Select a file")+" ("+dgettext("plugin_files","Maximum upload size")+": "+Zarafa.plugins.files.data.Utils.Format.fileSize(Zarafa.plugins.files.data.Utils.Core.getMaxUploadFilesize())+"):",layout:"fit",padding:10,items:[{xtype:"filesplugin.multiplefileuploadfield",buttonText:dgettext("plugin_files","Browse")+"...",name:"attachments[]",disabled:!0,listeners:{fileselected:this.onUploadFieldChanged,scope:this},ref:"../../mainuploadfield"}]}},
createFolderSelector:function(){var a=container.getContextByName("filescontext").getModel();return{xtype:"filesplugin.tree",title:dgettext("plugin_files","Select upload folder")+":",FilesFilter:Zarafa.plugins.files.data.FileTypes.FOLDER,flex:1,store:a.getHierarchyStore(),listeners:{click:this.onFolderSelected,scope:this}}},createActionButtons:function(){return[{xtype:"button",ref:"../../mainuploadbutton",disabled:!0,text:"&nbsp;&nbsp;"+dgettext("plugin_files","Upload"),iconCls:"icon_files",handler:this.doUpload,
scope:this},{xtype:"button",text:dgettext("plugin_files","Cancel"),handler:this.onClose,scope:this}]},onFolderSelected:function(a){this.targetFolder=a.getFolder().get("folder_id");this.dialog.mainuploadfield.enable()},onUploadFieldChanged:function(a,b,c){if(Ext.isEmpty(b))this.mainuploadbutton.setDisabled(!0);else{a.ownerCt.ownerCt.getForm();var d=!1;Ext.each(this.mainuploadfield.fileInput.dom.files,function(a){if(a.size>Zarafa.plugins.files.data.Utils.Core.getMaxUploadFilesize())return this.mainuploadfield.reset(),
Zarafa.common.dialogs.MessageBox.show({title:dgettext("plugin_files","Error"),msg:String.format(dgettext("plugin_files",'File "{0}" is too large! Maximum allowed filesize: {1}.'),a.name,Zarafa.plugins.files.data.Utils.Format.fileSize(Zarafa.plugins.files.data.Utils.Core.getMaxUploadFilesize())),icon:Zarafa.common.dialogs.MessageBox.ERROR,buttons:Zarafa.common.dialogs.MessageBox.OK}),this.mainuploadbutton.setDisabled(!0),d=!0,!1;d||this.mainuploadbutton.setDisabled(!1)},this)}},doUpload:function(){Zarafa.plugins.files.data.Actions.uploadAsyncItems(this.mainuploadfield.fileInput.dom.files,
this.record.getStore(),this.targetFolder);this.onClose()},onClose:function(){this.close()}});Ext.reg("filesplugin.filesuploadcontentpanel",Zarafa.plugins.files.ui.dialogs.FilesUploadContentPanel);Ext.namespace("Zarafa.plugins.files.ui.dialogs");
Zarafa.plugins.files.ui.dialogs.SaveToFilesContentPanel=Ext.extend(Zarafa.core.ui.ContentPanel,{constructor:function(a){a=a||{};Ext.applyIf(a,{layout:"fit",title:dgettext("plugin_files","Add item to Files"),closeOnSave:!0,width:400,height:300,items:[{xtype:"filesplugin.savetofilespanel",response:a.response,model:a.model}]});Zarafa.plugins.files.ui.dialogs.SaveToFilesContentPanel.superclass.constructor.call(this,a)}});Ext.reg("filesplugin.savetofilescontentpanel",Zarafa.plugins.files.ui.dialogs.SaveToFilesContentPanel);
Ext.namespace("Zarafa.plugins.files.ui.dialogs");
Zarafa.plugins.files.ui.dialogs.SaveToFilesPanel=Ext.extend(Ext.Panel,{response:null,constructor:function(a){a=a||{};this.response=a.response;a=Ext.applyIf(a,{xtype:"filesplugin.savetofilespanel",layout:{type:"hbox",align:"stretch"},border:!1,header:!1,items:[this.createTreePanel(a),this.createGridPanel()],buttonAlign:"right",buttons:this.createActionButtons()});Zarafa.plugins.files.ui.dialogs.SaveToFilesPanel.superclass.constructor.call(this,a);Ext.isDefined(this.model)&&this.mon(this.hierarchyTree,
"click",this.onTreeNodeClick,this)},createTreePanel:function(a){return{xtype:"filesplugin.tree",model:a.model,border:!0,flex:1,ref:"hierarchyTree"}},createGridPanel:function(){return{xtype:"grid",style:{paddingLeft:"9px"},ref:"filesGrid",flex:2,columns:[{dataIndex:"type",header:'<p class="icon_index">&nbsp;</p>',headerCls:"zarafa-icon-column icon",renderer:Zarafa.plugins.files.data.Utils.Renderer.typeRenderer,width:24,fixed:!0,tooltip:dgettext("plugin_files","Sort by: Type")},{header:dgettext("plugin_files",
"Filename"),dataIndex:"filename",width:160,tooltip:dgettext("plugin_files","Sort by: Filename")},{header:dgettext("plugin_files","Size"),dataIndex:"message_size",width:80,renderer:Zarafa.plugins.files.data.Utils.Format.fileSizeList,tooltip:dgettext("plugin_files","Sort by: Size")}],loadMask:{msg:_("Loading files")+"..."},store:{xtype:"filesplugin.filesrecordstore"},viewConfig:{deferEmptyText:!0,emptyText:'<div class="emptytext">'+_("There are no items to show in this list")+"</div>",forceFit:!0}}},
createActionButtons:function(){return[{xtype:"button",text:dgettext("plugin_files","New folder"),cls:"zarafa-normal",handler:this.onClickNewFolder,scope:this},{xtype:"button",text:dgettext("plugin_files","Save"),cls:"zarafa-action",iconCls:"icon_files_category_white",handler:this.onClickSave,scope:this}]},onTreeNodeClick:function(a){a=a.getFolder();this.filesGrid.store.load({params:{only_files:!0},folder:a})},onClickSave:function(){var a=this.getSelectedFolder();if(!Ext.isDefined(a))return!1;for(var b=
this.filesGrid.getStore(),c=[],d=0,e=this.response.count;d<e;d++){var f=this.response.items[d].filename;-1!==b.find("display_name",f)&&c.push(f)}Ext.isEmpty(c)?this.doUpload(a):Ext.MessageBox.confirm(dgettext("plugin_files","Confirm overwrite"),dgettext("plugin_files","File already exists. Do you want to overwrite it?"),function(b){"no"!==b&&this.doUpload(a,b)},this)},onClickNewFolder:function(){var a=this.getSelectedFolder();Ext.isDefined(a)&&Zarafa.plugins.files.data.Actions.createFolder(this.model,
void 0,a)},getSelectedFolder:function(){var a=this.hierarchyTree.getSelectionModel().getSelectedNode();if(Ext.isEmpty(a))Zarafa.plugins.files.data.Actions.msgWarning(dgettext("plugin_files","You have to choose a folder!"));else return a.getFolder()},doUpload:function(a,b){if(!Ext.isDefined(b)||"yes"===b)try{this.disable(),container.getRequest().singleRequest("filesbrowsermodule","uploadtobackend",{items:this.response.items,count:this.response.count,type:this.response.type,destdir:a.get("folder_id")},
new Zarafa.core.data.AbstractResponseHandler({doUploadtobackend:this.uploadDone.createDelegate(this)}))}catch(c){Zarafa.plugins.files.data.Actions.msgWarning(c.message)}},uploadDone:function(a){!0===a.status?container.getNotifier().notify("info.files",dgettext("plugin_files","Uploaded"),dgettext("plugin_files","Attachment successfully stored in Files")):container.getNotifier().notify("error",dgettext("plugin_files","Upload Failed"),dgettext("plugin_files","Attachment could not be stored in Files! Error: "+
a.status));this.dialog.close()}});Ext.reg("filesplugin.savetofilespanel",Zarafa.plugins.files.ui.dialogs.SaveToFilesPanel);Ext.namespace("Zarafa.plugins.files.ui.dialogs");
Zarafa.plugins.files.ui.dialogs.ShareContentPanel=Ext.extend(Zarafa.core.ui.ContentPanel,{records:null,constructor:function(a){a=a||{};Ext.applyIf(a,{layout:"fit",title:dgettext("plugin_files","Share Files"),width:800,height:500,items:[container.populateInsertionPoint("plugin.files.sharedialog",this,a.context)]});Zarafa.plugins.files.ui.dialogs.ShareContentPanel.superclass.constructor.call(this,a)}});Ext.reg("filesplugin.sharecontentpanel",Zarafa.plugins.files.ui.dialogs.ShareContentPanel);Ext.namespace("Zarafa.plugins.files.ui.dialogs");
Zarafa.plugins.files.ui.dialogs.SharePanel=Ext.extend(Ext.Panel,{constructor:function(a){a=a||{};var b=a.ownerCt.records,c=!0;0<b.length&&b[0].getAccount().get("backend")===a.plugin.info.name.substring(12)&&(c=!1);c&&Ext.applyIf(a,{disabled:!0,hidden:!0});Zarafa.plugins.files.ui.dialogs.SharePanel.superclass.constructor.call(this,a)}});Ext.reg("filesplugin.sharepanel",Zarafa.plugins.files.ui.dialogs.SharePanel);Ext.namespace("Zarafa.plugins.files.ui.dialogs");
Zarafa.plugins.files.ui.dialogs.UploadStatusContentPanel=Ext.extend(Zarafa.core.ui.ContentPanel,{constructor:function(a){a=a||{};Ext.applyIf(a,{layout:"fit",title:dgettext("plugin_files","Uploading files to ")+Zarafa.plugins.files.data.Utils.File.stripAccountId(a.destination)+" &hellip;",closeOnSave:!0,width:480,height:445,items:[{xtype:"filesplugin.uploadstatuspanel",files:a.files,destination:a.destination,keepBoth:a.keepBoth,callbackAllDone:a.callbackAllDone||Ext.emptyFn,callbackUploadFailed:a.callbackUploadFailed||
Ext.emptyFn,callbackUploadAborted:a.callbackUploadAborted||Ext.emptyFn,store:a.store}]});Zarafa.plugins.files.ui.dialogs.UploadStatusContentPanel.superclass.constructor.call(this,a)}});Ext.reg("filesplugin.uploadstatuscontentpanel",Zarafa.plugins.files.ui.dialogs.UploadStatusContentPanel);Ext.namespace("Zarafa.plugins.files.ui.dialogs");
Zarafa.plugins.files.ui.dialogs.UploadStatusPanel=Ext.extend(Ext.form.FormPanel,{files:null,destination:null,xhr:[],statsTimer:null,timerCounter:null,timerIntervall:200,callbackAllDone:Ext.emptyFn,callbackUploadFailed:Ext.emptyFn,callbackUploadAborted:Ext.emptyFn,store:void 0,constructor:function(a){a=a||{};Ext.applyIf(a,{autoScroll:!0,defaults:{anchor:"100%"},items:this.initUploadUI(a),listeners:{afterrender:this.startUpload,scope:this}});Zarafa.plugins.files.ui.dialogs.UploadStatusPanel.superclass.constructor.call(this,
a)},getBasicElement:function(a,b){return{xtype:"panel",padding:10,custom_fileid:b,ref:"fileuploadfield_"+b,items:[{layout:"column",border:!1,defaults:{border:!1},anchor:"0",items:[{columnWidth:.8,items:{xtype:"displayfield",fieldClass:"fp_upload_header",value:a.name}},{columnWidth:.2,style:"text-align: right;",items:{xtype:"displayfield",fieldClass:"fp_upload_header",value:Zarafa.plugins.files.data.Utils.Format.fileSizeList(a.size)}}]},{layout:"column",border:!1,defaults:{border:!1},anchor:"0",items:[{columnWidth:.95,
items:{xtype:"progress",text:dgettext("plugin_files","Starting upload")+"&hellip;",ref:"../../progress"}},{columnWidth:.05,items:{xtype:"button",ref:"../../cancel",custom_fileid:b,tooltip:dgettext("plugin_files","Cancel upload"),overflowText:dgettext("plugin_files","Cancel upload"),iconCls:"icon_action_cancel",handler:this.doCancelUpload.createDelegate(this)}}]},{layout:"column",border:!1,defaults:{border:!1},anchor:"0",items:[{columnWidth:.33,items:{xtype:"displayfield",value:"- kB/s",ref:"../../speed"}},
{columnWidth:.33,items:[{xtype:"displayfield",value:"0 MB",ref:"../../uploaded"}]},{columnWidth:.33,style:"text-align: right;",items:{xtype:"displayfield",value:dgettext("plugin_files","- seconds left"),ref:"../../eta"}}]}]}},initUploadUI:function(a){var b=[];Ext.each(a.files,function(a,d){b.push(this.getBasicElement(a,d))},this);return b},startUpload:function(){Ext.each(this.files,function(a,b){this.xhr[b]=new XMLHttpRequest;this.xhr[b].open("post","index.php?load=custom&name=upload_file&keep_both="+
this.keepBoth,!0);this.xhr[b].upload.addEventListener("progress",this.onUpdateProgress.createDelegate(this,[b],!0),!1);this.xhr[b].addEventListener("load",this.onFinishProgress.createDelegate(this,[b],!0),!1);this.xhr[b].addEventListener("error",this.onUploadFailed.createDelegate(this,[b],!0),!1);this.xhr[b].addEventListener("abort",this.onUploadAborted.createDelegate(this,[b],!0),!1);this.xhr[b].setRequestHeader("Content-Type","multipart/form-data");this.xhr[b].setRequestHeader("X-FILE-NAME",encodeURIComponent(a.name));
this.xhr[b].setRequestHeader("X-FILE-SIZE",a.size);this.xhr[b].setRequestHeader("X-FILE-TYPE",a.type);this.xhr[b].setRequestHeader("X-FILE-DESTINATION",this.destination);this.xhr[b].send(a);this.xhr[b].cust_loaded=0;this.xhr[b].cust_total=0},this);this.statsTimer=window.setInterval(this.getStats.createDelegate(this),this.timerIntervall);this.timerCounter=this.xhr.length},getStats:function(){Ext.each(this.xhr,function(a,b){var c=a.cust_loaded_old,d=a.cust_loaded,e=a.cust_total;a.cust_loaded_old=d;
var f=(d-c)/(this.timerIntervall/1E3),g=" B/s",h=(e-d)/f,k=dgettext("plugin_files"," seconds left");60<h&&(h/=60,k=dgettext("plugin_files"," minutes left"));1E3<f&&(f/=1E3,g=" kB/s");1E3<f&&(f/=1E3,g=" mB/s");var l=this["fileuploadfield_"+b];Ext.isDefined(l)&&(Ext.isDefined(c)&&0!=d&&0!=e?d!=c&&(l.speed.setValue(f.toFixed(2)+g),l.eta.setValue(parseInt(h)+k)):(l.speed.setValue("- kB/s"),l.eta.setValue(dgettext("plugin_files","- seconds left"))))},this)},onUpdateProgress:function(a,b){var c=this["fileuploadfield_"+
b];if(Ext.isDefined(c))if(a.lengthComputable){this.xhr[b].cust_loaded=a.loaded;this.xhr[b].cust_total=a.total;var d=(a.loaded/a.total*100).toFixed(2);c.progress.updateProgress(a.loaded/a.total,dgettext("plugin_files","Uploading: ")+d+"%",!0);c.uploaded.setValue(Zarafa.plugins.files.data.Utils.Format.fileSizeList(a.loaded))}else c.progress.updateProgress(.5,dgettext("plugin_files","Upload status unavailable... please wait."),!0)},onFinishProgress:function(a,b){var c=this["fileuploadfield_"+b];c&&(c.progress.updateProgress(1,
dgettext("plugin_files","Upload finished!"),!0),this.xhr[b].cust_loaded=0,this.xhr[b].cust_total=0,c.cancel.disable(),this.checkTimerAlive())},onUploadAborted:function(a,b){var c=this["fileuploadfield_"+b];if(Ext.isDefined(c)){var d=c.progress;d.updateProgress(1,dgettext("plugin_files","Upload aborted!"),!0);d.addClass("fp_upload_canceled");c.cancel.disable();this.callbackUploadAborted(this.files[b],this.destination,a);this.checkTimerAlive()}},onUploadFailed:function(a,b){var c=this["fileuploadfield_"+
b];if(Ext.isDefined(c)){var d=c.progress;d.updateProgress(1,dgettext("plugin_files","Upload failed!"),!0);d.addClass("fp_upload_canceled");c.cancel.disable();this.callbackUploadFailed(this.files[b],this.destination,a);this.checkTimerAlive()}},checkTimerAlive:function(){this.timerCounter--;0>=this.timerCounter&&(window.clearTimeout(this.statsTimer),this.onUploadsFinished())},doCancelUpload:function(a,b){this.xhr[a.custom_fileid].abort()},onUploadsFinished:function(){this.dialog.close();this.callbackAllDone(this.files,
this.destination,this.store)}});Ext.reg("filesplugin.uploadstatuspanel",Zarafa.plugins.files.ui.dialogs.UploadStatusPanel);Ext.namespace("Zarafa.plugins.files.ui.snippets");
Zarafa.plugins.files.ui.snippets.FilesNavigationBar=Ext.extend(Ext.Panel,{context:void 0,model:void 0,maxPathBeforeTruncate:5,maxStringBeforeTruncate:20,pathTruncateText:"&hellip;",hasOverflow:!1,currentPath:"#R#",filesStore:void 0,constructor:function(a){a=a||{};Ext.isDefined(a.model)&&!Ext.isDefined(a.filesStore)&&(a.filesStore=a.model.getStore(),this.currentPath=a.filesStore.folderId);Ext.applyIf(a,{xtype:"filesplugin.navigationbar",maskDisabled:!1,hideBorders:!0,border:!1,cls:"navbar_container",
height:25,defaults:{height:25},layout:"column"});Zarafa.plugins.files.ui.snippets.FilesNavigationBar.superclass.constructor.call(this,a)},initEvents:function(){this.on("afterrender",this.onAfterRender,this);this.mon(this.model,"folderchange",this.onFolderChange,this);this.mon(this.model.getHierarchyStore(),"updateFolder",this.onUpdateFolder,this);this.mon(this.model.getHierarchyStore(),"load",this.onHierarchyStoreLoad,this)},onHierarchyStoreLoad:function(){var a=this.model.getDefaultFolder();this.updateNavigationBar(a)},
onUpdateFolder:function(a,b,c){c.get("entryid")===this.model.getDefaultFolder().get("entryid")&&this.updateNavigationBar(c)},onAfterRender:function(){this.generateNavigationButtons(this.model.getDefaultFolder())},onFolderChange:function(a){a=a.getDefaultFolder();this.updateNavigationBar(a)},updateNavigationBar:function(a){var b=a.get("folder_id");this.currentPath!==b&&(this.currentPath=b,this.generateNavigationButtons(a))},recalculateMaxPath:function(){var a=8*this.maxStringBeforeTruncate,b=this.getWidth(),
c=this.items?this.items.items:[],d=this.hasOverflow?3:2;Ext.each(c,function(a){b-=a.getWidth()});if(b<a){var e=a-b,f=0;Ext.each(c,function(a){e-=a.getWidth();f++;if(0>=e)return!1});this.maxPathBeforeTruncate=c.length-f}else this.maxPathBeforeTruncate=Math.floor(c.length+b/a);this.maxPathBeforeTruncate-=d},createHomeButton:function(){this.add({xtype:"button",cls:"files_navbar_button files_navbar_button_first",tooltip:dgettext("plugin_files","Home"),path:"#R#",listeners:{click:this.doNavButtonClick,
scope:this},iconCls:"files_navbar files_navbar_home"})},createBackEndRootButton:function(a,b,c){if(!Ext.isEmpty(b)&&(a=this.accountsStore.getById(b),!Ext.isEmpty(a))){var d=c?" files_navbar_button_last":"";c=Zarafa.plugins.files.data.Utils.Format.truncate(a.get("name"),this.maxStringBeforeTruncate);b={xtype:"button",cls:"files_navbar_button"+d,path:"#R#"+b+"/",listeners:{click:this.doNavButtonClick,scope:this},text:c};Ext.isEmpty(c)&&(b.iconCls="files_navbar icon_16_"+a.get("backend"));this.add(b)}},
generateNavigationButtons:function(a){a=Ext.isDefined(a)?a.get("folder_id"):"#R#";var b=Zarafa.plugins.files.data.Utils.File.getAccountId(a);a=Zarafa.plugins.files.data.Utils.File.stripAccountId(a);this.recalculateMaxPath();this.removeAll(!0);this.createHomeButton();var c=-1===a.indexOf("/")||"/"===a;this.createBackEndRootButton(a,b,c);if(!c){var d="/",e=a.replace(/^\/|\/$/g,"").split("/");if(e.length>this.maxPathBeforeTruncate){this.hasOverflow=!0;a=e.splice(0,e.length-this.maxPathBeforeTruncate);
var f=[];Ext.each(a,function(a){d+=a+"/";f.push({text:Zarafa.plugins.files.data.Utils.Format.truncate(a,this.maxStringBeforeTruncate),handler:this.doNavButtonClick,iconCls:"icon_folder_note",path:"#R#"+b+d,scope:this})},this);a=new Ext.Button({cls:"files_navbar_button",menu:f,text:this.pathTruncateText});this.add(a)}else this.hasOverflow=!1;Ext.each(e,function(a,c){d+=a+"/";var f=c==e.length-1?" files_navbar_button_last":"",f=new Ext.Button({text:Zarafa.plugins.files.data.Utils.Format.truncate(a,
this.maxStringBeforeTruncate),cls:"files_navbar_button"+f,path:"#R#"+b+d,listeners:{click:this.doNavButtonClick,scope:this}});this.add(f)},this)}this.doLayout()},doNavButtonClick:function(a){var b=this.model;a=b.getHierarchyStore().getFolderByFolderId(a.path);Ext.isDefined(a)&&(a.isHomeFolder()&&b.setPreviewRecord(void 0),container.selectFolder(a))}});Ext.reg("filesplugin.navigationbar",Zarafa.plugins.files.ui.snippets.FilesNavigationBar);Ext.namespace("Zarafa.plugins.files.ui.snippets");
Zarafa.plugins.files.ui.snippets.FilesQuotaBar=Ext.extend(Ext.Panel,{model:void 0,quotaText:dgettext("plugin_files","{0} of {1} in use"),loadOnlyOnce:!0,defaultDirectory:"/",constructor:function(a){a=a||{};!Ext.isDefined(a.store)&&Ext.isDefined(a.model)&&(a.store=a.model.getStore());Ext.applyIf(a,{xtype:"filesplugin.quotabar",cls:"files_quota_bar_snippet",border:!1,items:[{xtype:"panel",ref:"quotaPanel",layout:"table",layoutConfig:{columns:2},cls:"files_quota_bar_container",border:!1,items:[{xtype:"label",
ref:"../usageInfo",autoWidth:!0},{xtype:"progress",width:"150",ref:"../progressBar",height:"8",cls:"files_quota_bar",style:"margin: 0 0 0 20px"}]},{xtype:"label",border:!1,hidden:!0,ref:"loadingIcon",html:'<div class="img"></div>'}]});Zarafa.plugins.files.ui.snippets.FilesQuotaBar.superclass.constructor.call(this,a)},initEvents:function(){this.mon(this.store,{load:this.onStoreLoad,scope:this})},onStoreLoad:function(a,b,c){a=Zarafa.plugins.files.data.Utils.File.getAccountId(a.folderId);b=this.accountsStore.getById(a);
Ext.isDefined(b)&&b.supportsFeature(Zarafa.plugins.files.data.AccountRecordFeature.QUOTA)?(this.loaded==a&&this.loadOnlyOnce||(this.quotaPanel.hide(),this.loadingIcon.show(),this.loadQuotaInformation(a,this.defaultDirectory)),this.isVisible()||this.show(),this.loaded=a):this.hide()},loadQuotaInformation:function(a,b){var c=new Zarafa.core.data.AbstractResponseHandler({doGetquota:this.gotQuotaValues.createDelegate(this)});container.getRequest().singleRequest("filesaccountmodule","getquota",{accountId:a,
folder:b},c)},gotQuotaValues:function(a){if(this.quotaPanel){var b=parseInt(a.quota[0].amount);a=parseInt(a.quota[1].amount);a=b+a;this.loadingIcon.hide();this.quotaPanel.show();this.usageInfo.setText(String.format(this.quotaText,Ext.util.Format.fileSize(b),Ext.util.Format.fileSize(a)));this.progressBar.updateProgress(b/a)}}});Ext.reg("filesplugin.quotabar",Zarafa.plugins.files.ui.snippets.FilesQuotaBar);Ext.namespace("Zarafa.plugins.files.ui.snippets");
Zarafa.plugins.files.ui.snippets.PDFjsPanel=Ext.extend(Ext.Panel,{src:"",title:"",pageScale:1,disableWorker:!0,disableTextLayer:!0,loadingMessage:"Loading PDF, please wait...",beforePageText:"Page",afterPageText:"of {0}",firstText:"First Page",prevText:"Previous Page",nextText:"Next Page",lastText:"Last Page",fullscreenText:"Fullscreen",inputItemWidth:30,scaleWidth:60,constructor:function(a){a=a||{};a=Ext.applyIf(a,{xtype:"filesplugin.pdfjspanel",border:!1,baseCls:"x-panel pdf",bodyCssCls:"pdf-body",
pageScale:1,header:!1,items:[{xtype:"component",autoEl:{cn:[{tag:"canvas","class":"pdf-page-container"},{tag:"div","class":"pdf-text-layer"}]},listeners:{afterrender:this.init.createDelegate(this)}}],bbar:this.getPagingToolbar()});PDFJS.disableTextLayer=this.disableTextLayer;Zarafa.plugins.files.ui.snippets.PDFjsPanel.superclass.constructor.call(this,a)},getPagingToolbar:function(){return{xtype:"toolbar",height:25,items:[{ref:"first",tooltip:this.firstText,overflowText:this.firstText,iconCls:"x-tbar-page-first",
disabled:!0,handler:this.moveFirst,scope:this},{ref:"prev",tooltip:this.prevText,overflowText:this.prevText,iconCls:"x-tbar-page-prev",disabled:!0,handler:this.movePrevious,scope:this},"-",this.beforePageText,{xtype:"numberfield",ref:"inputItem",name:"inputItem",cls:"x-tbar-page-number",minValue:1,allowDecimals:!1,allowNegative:!1,enableKeyEvents:!0,selectOnFocus:!0,submitValue:!1,width:this.inputItemWidth,disabled:!0,margins:"-1 2 3 2",listeners:{scope:this,keydown:this.onPagingKeyDown,blur:this.onPagingBlur}},
{xtype:"tbtext",ref:"afterTextItem",text:String.format(this.afterPageText,1),margins:"0 5 0 0"},"-",{ref:"next",tooltip:this.nextText,overflowText:this.nextText,iconCls:"x-tbar-page-next",disabled:!0,handler:this.moveNext,scope:this},{ref:"last",tooltip:this.lastText,overflowText:this.lastText,iconCls:"x-tbar-page-last",disabled:!0,handler:this.moveLast,scope:this},"->",{xtype:"combo",ref:"scaleCombo",triggerAction:"all",lazyInit:!1,forceSelection:!0,editable:!1,autoSelect:!0,disabled:!0,hidden:!0,
width:this.scaleWidth,store:{xtype:"jsonstore",autoDestroy:!0,fields:["scale","text"],data:[{scale:.5,text:"50%"},{scale:.75,text:"75%"},{scale:1,text:"100%"},{scale:1.25,text:"125%"},{scale:1.5,text:"150%"},{scale:2,text:"200%"},{scale:4,text:"400%"}]},valueField:"scale",displayField:"text",mode:"local",listeners:{scope:this,select:this.onScaleChange}},{ref:"fullscreen",tooltip:this.fullscreenText,overflowText:this.fullscreenText,iconCls:"files_icon_action_fullscreen",disabled:!1,handler:this.displayFullscreen,
scope:this}]}},init:function(){this.pageContainer=this.el.query(".pdf-page-container")[0];PDFJS.disableTextLayer||(this.textLayerDiv=this.el.query(".pdf-text-layer")[0]);this.disableWorker&&(PDFJS.disableWorker=!0);this.getDocument()},onLoad:function(){try{var a;a=0===this.pdfDoc.numPages;this.currentPage=this.currentPage||(a?0:1);this.renderPage(this.currentPage)}catch(b){console.log("PDF: Can't render: "+b.message)}},renderPage:function(a){var b=this,c,d,e,f,g=b.getBottomToolbar();this.isRendering||
(b.isRendering=!0,b.currentPage=a,e=b.currentPage,d=b.pdfDoc.numPages,f=String.format(b.afterPageText,isNaN(d)?1:d),c=0===d,g.afterTextItem.setText(f),g.inputItem.setDisabled(c),g.inputItem.setValue(e),g.first.setDisabled(1===e||c),g.prev.setDisabled(1===e||c),g.next.setDisabled(e===d||c),g.last.setDisabled(e===d||c),g.scaleCombo.setDisabled(c),g.scaleCombo.setValue(b.pageScale),b.pdfDoc.getPage(a).then(function(a){if(b.pageContainer){var c=a.getViewport(b.pageScale);b.pageContainer.height=c.height;
b.pageContainer.width=c.width;var d=b.pageContainer.getContext("2d");d.save();d.fillStyle="rgb(255, 255, 255)";d.fillRect(0,0,b.pageContainer.width,b.pageContainer.height);d.restore();a.render({canvasContext:d,viewport:c,textLayer:null});b.isRendering=!1;b.loader&&b.loader.destroy();b.rendered&&b.fireEvent("change",b,{current:b.currentPage,total:b.pdfDoc.numPages})}else b.isRendering=!1}))},moveFirst:function(){!1!==this.fireEvent("beforechange",this,1)&&this.renderPage(1)},movePrevious:function(){var a=
this.currentPage-1;0<a&&!1!==this.fireEvent("beforechange",this,a)&&this.renderPage(a)},moveNext:function(){var a=this.currentPage+1;a<=this.pdfDoc.numPages&&!1!==this.fireEvent("beforechange",this,a)&&this.renderPage(a)},moveLast:function(){var a=this.pdfDoc.numPages;!1!==this.fireEvent("beforechange",this,a)&&this.renderPage(a)},readPageFromInput:function(){var a=this.getBottomToolbar().inputItem.getValue(),b=parseInt(a,10);return!a||isNaN(b)?(this.getBottomToolbar().inputItem.setValue(this.currentPage),
!1):b},onPagingFocus:function(){this.getBottomToolbar().inputItem.select()},onPagingBlur:function(a){a=this.getPageData().currentPage;this.getBottomToolbar().inputItem.setValue(a)},onPagingKeyDown:function(a,b){var c=b.getKey(),d=b.shiftKey?10:1,e,f=this.pdfDoc.numPages;if(c==b.RETURN)b.stopEvent(),e=this.readPageFromInput(),!1!==e&&(e=Math.min(Math.max(1,e),f),!1!==this.fireEvent("beforechange",this,e)&&this.renderPage(e));else if(c==b.HOME||c==b.END)b.stopEvent(),e=c==b.HOME?1:f,a.setValue(e);else if(c==
b.UP||c==b.PAGE_UP||c==b.DOWN||c==b.PAGE_DOWN)if(b.stopEvent(),e=this.readPageFromInput()){if(c==b.DOWN||c==b.PAGE_DOWN)d*=-1;e+=d;1<=e&&e<=f&&a.setValue(e)}},onScaleChange:function(a,b){this.pageScale=b.get(a.valueField);this.renderPage(this.currentPage)},displayFullscreen:function(){Ext.ux.PdfBox.open({easing:"elasticOut",resizeDuration:.6,close:"&#215;",hideInfo:"auto",href:this.src,title:this.tile})},setSrc:function(a){this.src=a;return this.getDocument()},getDocument:function(){var a=this;a.src&&
PDFJS.getDocument(a.src).then(function(b){a.pdfDoc=b;a.onLoad()});return a}});Ext.reg("filesplugin.pdfjspanel",Zarafa.plugins.files.ui.snippets.PDFjsPanel);Ext.namespace("Zarafa.plugins.files.ui.snippets");
Zarafa.plugins.files.ui.snippets.WebODFPanel=Ext.extend(Ext.Panel,{odfCanvas:null,pages:[],currentPage:0,src:null,title:"",loadingMessage:"Loading PDF, please wait...",beforePageText:"Page",afterPageText:"of {0}",firstText:"First Page",prevText:"Previous Page",nextText:"Next Page",lastText:"Last Page",fullscreenText:"Fullscreen",inputItemWidth:30,scaleWidth:60,panelID:null,constructor:function(a){a=a||{};a=Ext.applyIf(a,{xtype:"filesplugin.webodfpanel",border:!1,header:!1,items:[{xtype:"component",
cls:"webodfpanel-outerDocumentContainer",autoEl:{cn:[{tag:"div","class":"webodfpanel-canvas"}]},listeners:{afterrender:this.initODF.createDelegate(this)}}],bbar:this.getPagingToolbar()});Zarafa.plugins.files.ui.snippets.WebODFPanel.superclass.constructor.call(this,a)},getPagingToolbar:function(){return{xtype:"toolbar",height:25,items:[{ref:"first",tooltip:this.firstText,overflowText:this.firstText,iconCls:"x-tbar-page-first",disabled:!0,handler:this.moveFirst,scope:this},{ref:"prev",tooltip:this.prevText,
overflowText:this.prevText,iconCls:"x-tbar-page-prev",disabled:!0,handler:this.movePrevious,scope:this},"-",this.beforePageText,{xtype:"numberfield",ref:"inputItem",name:"inputItem",cls:"x-tbar-page-number",minValue:1,allowDecimals:!1,allowNegative:!1,enableKeyEvents:!0,selectOnFocus:!0,submitValue:!1,width:this.inputItemWidth,disabled:!0,margins:"-1 2 3 2",listeners:{scope:this,keydown:this.onPagingKeyDown,blur:this.onPagingBlur}},{xtype:"tbtext",ref:"afterTextItem",text:String.format(this.afterPageText,
1),margins:"0 5 0 0"},"-",{ref:"next",tooltip:this.nextText,overflowText:this.nextText,iconCls:"x-tbar-page-next",disabled:!0,handler:this.moveNext,scope:this},{ref:"last",tooltip:this.lastText,overflowText:this.lastText,iconCls:"x-tbar-page-last",disabled:!0,handler:this.moveLast,scope:this},"->",{xtype:"combo",ref:"scaleCombo",triggerAction:"all",lazyInit:!1,forceSelection:!0,editable:!1,autoSelect:!0,disabled:!0,hidden:!0,width:this.scaleWidth,store:{xtype:"jsonstore",autoDestroy:!0,fields:["scale",
"text"],data:[{scale:.5,text:"50%"},{scale:.75,text:"75%"},{scale:1,text:"100%"},{scale:1.25,text:"125%"},{scale:1.5,text:"150%"},{scale:2,text:"200%"},{scale:4,text:"400%"}]},valueField:"scale",displayField:"text",mode:"local",listeners:{scope:this,select:this.onScaleChange}},{ref:"fullscreen",tooltip:this.fullscreenText,overflowText:this.fullscreenText,iconCls:"files_icon_action_fullscreen",disabled:!1,handler:this.displayFullscreen,scope:this}]}},initODF:function(){this.canvasContainer=Ext.DomQuery.selectNode("div[class*=webodfpanel-canvas]",
this.el.dom);this.odfCanvas=new odf.OdfCanvas(this.canvasContainer);this.odfCanvas.load(this.src)},moveFirst:function(){!1!==this.fireEvent("beforechange",this,1)&&this.renderPage(1)},movePrevious:function(){var a=this.currentPage-1;0<a&&!1!==this.fireEvent("beforechange",this,a)&&this.renderPage(a)},moveNext:function(){var a=this.currentPage+1;a<=this.pdfDoc.numPages&&!1!==this.fireEvent("beforechange",this,a)&&this.renderPage(a)},moveLast:function(){var a=this.pdfDoc.numPages;!1!==this.fireEvent("beforechange",
this,a)&&this.renderPage(a)},readPageFromInput:function(){var a=this.getBottomToolbar().inputItem.getValue(),b=parseInt(a,10);return!a||isNaN(b)?(this.getBottomToolbar().inputItem.setValue(this.currentPage),!1):b},onPagingFocus:function(){this.getBottomToolbar().inputItem.select()},onPagingBlur:function(a){a=this.getPageData().currentPage;this.getBottomToolbar().inputItem.setValue(a)},onPagingKeyDown:function(a,b){var c=b.getKey(),d=b.shiftKey?10:1,e,f=this.pdfDoc.numPages;if(c==b.RETURN)b.stopEvent(),
e=this.readPageFromInput(),!1!==e&&(e=Math.min(Math.max(1,e),f),!1!==this.fireEvent("beforechange",this,e)&&this.renderPage(e));else if(c==b.HOME||c==b.END)b.stopEvent(),e=c==b.HOME?1:f,a.setValue(e);else if(c==b.UP||c==b.PAGE_UP||c==b.DOWN||c==b.PAGE_DOWN)if(b.stopEvent(),e=this.readPageFromInput()){if(c==b.DOWN||c==b.PAGE_DOWN)d*=-1;e+=d;1<=e&&e<=f&&a.setValue(e)}},onScaleChange:function(a,b){this.pageScale=b.get(a.valueField);this.renderPage(this.currentPage)},displayFullscreen:function(){Zarafa.plugins.webodf.WebOdfBox.open({resizeDuration:.4,
overlayDuration:.6,href:this.src,title:this.title})}});Ext.reg("filesplugin.webodfpanel",Zarafa.plugins.files.ui.snippets.WebODFPanel);Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.FilesFolderNode=Ext.extend(Ext.tree.AsyncTreeNode,{folder:void 0,isNodeSelected:!1,tpl:new Ext.XTemplate("{text:htmlEncode}",{compiled:!0}),constructor:function(a){a=a||{};var b=a.folder;Ext.isDefined(b)&&Ext.applyIf(a,{id:b.get("id")});Ext.applyIf(a,{containerCls:"zarafa-tree-container",cls:"zarafa-tree-node"});Zarafa.plugins.files.ui.FilesFolderNode.superclass.constructor.call(this,a);Ext.isString(this.tpl)&&(this.tpl=new Ext.XTemplate(this.tpl,{compiled:!0}));b&&this.updateUI(b)},
getFolder:function(){return this.attributes.folder},updateUI:function(a){this.attributes.folder=a;this.setText(this.getTextFromFolder(a));this.ui.getIconEl()&&"svg"===this.ui.getIconEl().tagName||(this.setIcon(a.getIcon()),this.setContainerCls(this.attributes.containerCls))},setIcon:function(a){var b=this.iconCls;this.iconCls=this.attributes.iconCls=a;if(this.rendered)this.getUI().onIconChange(this,a,b)},setContainerCls:function(a){var b=this.containerCls;this.containerCls=this.attributes.containerCls=
a;if(this.rendered)this.getUI().onContainerClsChange(this,a,b)},getTextFromFolder:function(a){return a.getDisplayName()},update:function(a){this.ownerTree&&this.ownerTree.model&&this.ownerTree.model.getFolder(this.getFolder().get("id"));if(a)for(var b=0,c=this.childNodes.length;b<c;b++)this.childNodes[b].update(a)}});Ext.tree.TreePanel.nodeTypes.filesfolder=Zarafa.plugins.files.ui.FilesFolderNode;Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.NavigatorTreePanel=Ext.extend(Zarafa.plugins.files.ui.Tree,{nodeToSelect:null,filesStore:void 0,constructor:function(a){a=a||{};Ext.applyIf(a,{xtype:"filesplugin.navigatortreepanel",loadMask:!0});Zarafa.plugins.files.ui.NavigatorTreePanel.superclass.constructor.call(this,a);this.mon(this.store,"removeFolder",this.onFolderRemove,this)},onFolderRemove:function(a,b,c){this.model&&this.model.removeFolder(c)},initEvents:function(){Zarafa.plugins.files.ui.NavigatorTreePanel.superclass.initEvents.apply(this,
arguments);this.on({click:this.onNodeClick,beforenodedrop:this.onBeforeNodeDrop,nodedragover:this.onNodeDragOver,afterrender:this.onAfterRender,contextmenu:this.onContextMenu,scope:this});this.mon(container,"folderselect",this.onFolderSelect,this);this.mon(this.store,"load",this.onHierarchyStoreLoad,this)},onBeforeNodeDrop:function(a){if(Ext.isArray(a.data.selections))return a.cancel=!1,Ext.each(a.data.selections,function(a){a.setDisabled(!0)}),Zarafa.plugins.files.data.Actions.moveRecords(a.data.selections,
a.target.getFolder(),{hierarchyStore:this.store})},onNodeDragOver:function(a){var b=!0,c=a.target.getFolder(),d=c.getFilesStore().get("backend_config").current_account_id;Ext.each(a.data.selections,function(a){var e=this.store.getFolder(a.get("parent_entryid"));if(!Ext.isDefined(e))return b=!1;var g=e.getFilesStore().get("backend_config").current_account_id;if(d!==g||c.get("entryid")===a.get("entryid")||e.get("entryid")===c.get("entryid"))return b=!1},this);return b},onNodeClick:function(a){container.selectFolder(a.getFolder())},
onFolderSelect:function(a){Array.isArray(a)&&(a=1<a.length&&this.model?this.model.getDefaultFolder():a[0]);a&&(Ext.isFunction(a.isHomeFolder)&&a.isHomeFolder()?this.selModel.clearSelections():this.selectFolderInTree(a))},onHierarchyStoreLoad:function(){this.root.reload();this.onFolderSelect(this.model.getDefaultFolder())},onAfterRender:function(a){this.dragZone.lock();this.dropZone=new Ext.tree.TreeDropZone(this,{ddGroup:this.ddGroup,appendOnly:!0===this.ddAppendOnly,getDropPoint:function(a,c,d){return"append"}})},
onContextMenu:function(a,b){Zarafa.core.data.UIFactory.openContextMenu(Zarafa.core.data.SharedComponentType["zarafa.plugins.files.treecontextmenu"],a.getFolder(),{position:b.getXY(),model:this.model})}});Ext.reg("filesplugin.navigatortreepanel",Zarafa.plugins.files.ui.NavigatorTreePanel);Ext.namespace("Zarafa.plugins.files.ui");
Zarafa.plugins.files.ui.FilesRootFolderNode=Ext.extend(Zarafa.plugins.files.ui.FilesFolderNode,{constructor:function(a){a=a||{};var b="zarafa-tree-root-container",c="zarafa-tree-root-node";a.folder.isSubTreeFolder();a.folder&&(b+=" zarafa-tree-ipm-subtree-container",c+=" zarafa-tree-ipm-subtree-node",a.id=a.folder.get("id"));Ext.applyIf(a,{containerCls:b,cls:c,expanded:!0,allowDrag:!1,draggable:!1});Zarafa.plugins.files.ui.FilesRootFolderNode.superclass.constructor.call(this,a)}});
Ext.tree.TreePanel.nodeTypes.filesrootfolder=Zarafa.plugins.files.ui.FilesRootFolderNode;
