<?xml version="1.0" encoding="UTF-8"?>
<ajxpdriver name="inbox" label="CONF_MESSAGE[Inbox Workspace]" description="CONF_MESSAGE[Received Files]" mixins="filesystem_commons,slug_provider,template_provider" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:../core.ajaxplorer/ajxp_registry.xsd">
    <class_definition filename="plugins/access.inbox/class.inboxAccessDriver.php" classname="inboxAccessDriver"/>
    <client_settings>
        <resources>
            <js file="plugins/access.inbox/res/build/InboxWidgets.js" className="InboxWidgets"/>
            <css file="plugins/access.inbox/res/inbox_style.css"/>
            <i18n namespace="inbox_driver" path="plugins/access.inbox/res/i18n"/>
        </resources>
    </client_settings>
    <registry_contributions>
        <external_file filename="plugins/access.fs/fsTemplatePart.xml" include="client_configs/*" exclude=""/>
        <external_file filename="plugins/access.fs/fsActions.xml"
                       include="actions/*"
                       exclude="actions/action[@name='download_all']|actions/action[@name='download']|actions/action[@name='download_chunk']|actions/action[@name='rename']|actions/action[@name='move']|actions/action[@name='copy']|actions/action[@name='delete']|actions/action[@name='chmod']|actions/action[@name='compress']|actions/action[@name='compress_ui']"/>
        <external_file filename="plugins/access.fs/fsActions.xml" include="client_configs/*" exclude=""/>
        <external_file filename="plugins/access.fs/manifest.xml" include="registry_contributions/hooks/*" exclude=""/>

        <hooks>
            <serverCallback methodName="loadRepositoryInfo" hookName="repository.load_info" />
        </hooks>

        <actions>
            <action name="inbox_accept_invitation">
                <gui src="" text="547" title="547" iconClass="icon-ok-sign">
                    <context dir="true" recycle="false" selection="true" actionBar="true" actionBarGroup="change_main,inline,info_panel_share"/>
                    <selectionContext dir="true" file="true" behaviour="hidden" recycle="false" unique="true" allowedMimes="invitation"/>
                </gui>
                <processing>
                    <clientCallback><![CDATA[
                        var remoteShareId = pydio.getUserSelection().getUniqueNode().getMetadata().get("remote_share_id");
                        PydioApi.getClient().request({get_action:'accept_invitation', remote_share_id:remoteShareId}, function(){
                            pydio.fireContextRefresh();
                        });
                    ]]></clientCallback>
                </processing>
            </action>
            <action name="inbox_reject_invitation">
                <gui src="56" text="548" title="548" iconClass="icon-remove-sign">
                    <context dir="true" recycle="false" selection="true" actionBar="true" actionBarGroup="change_main,inline,info_panel_share"/>
                    <selectionContext dir="true" file="true" behaviour="hidden" recycle="false" unique="true" allowedMimes="invitation"/>
                </gui>
                <processing>
                    <clientCallback><![CDATA[
                        var remoteShareId = pydio.getUserSelection().getUniqueNode().getMetadata().get("remote_share_id");
                        PydioApi.getClient().request({get_action:'reject_invitation', remote_share_id:remoteShareId}, function(){
                            pydio.fireContextRefresh();
                        });
                    ]]></clientCallback>
                </processing>
            </action>
            <action name="inbox_reject_remote_share">
                <gui src="55" text="548" title="548" iconClass="icon-remove-sign">
                    <context dir="true" recycle="false" selection="true" actionBar="true" actionBarGroup="change_main,inline,info_panel_share"/>
                    <selectionContext dir="true" file="true" behaviour="hidden" recycle="false" unique="true" evalMetadata="metadata.get('remote_share_accepted')"/>
                </gui>
                <processing>
                    <clientCallback><![CDATA[
                        var remoteShareId = pydio.getUserSelection().getUniqueNode().getMetadata().get("remote_share_id");
                        PydioApi.getClient().request({get_action:'reject_invitation', remote_share_id:remoteShareId}, function(){
                            pydio.fireContextRefresh();
                        });
                    ]]></clientCallback>
                </processing>
            </action>
            <action name="download" fileDefault="false">
                <gui text="88" title="88" src="download_manager.png" iconClass="icon-download-alt" accessKey="download_access_key" hasAccessKey="true">
                    <context selection="true" dir="" recycle="false"
                             actionBar="true" contextMenu="true" infoPanel="true"
                             actionBarGroup="get,inline,info_panel">
                    </context>
                    <selectionContext dir="false" file="true" recycle="false" unique="true" enableRoot="false"/></gui>
                <rightsContext noUser="true" userLogged="only" read="true" write="false" adminOnly=""/>
                <processing>
                    <clientCallback prepareModal="true"><![CDATA[
                        var userSelection = ajaxplorer.getUserSelection();
                        if(window.gaTrackEvent){
                            var fileNames = userSelection.getFileNames();
                            for(var i=0; i<fileNames.length;i++){
                                window.gaTrackEvent("Data", "Download", fileNames[i]);
                            }
                        }
                        PydioApi.getClient().downloadSelection(userSelection, $('download_form'), 'download');
                        ]]></clientCallback>
                    <serverCallback methodName="switchAction" restParams="/file+" checkParams="false" sdkMethodName="download" developerComment="Download one or many files at once. If multiple files (or a folder path) passed, they are sent back as an archive.">
                        <input_param description="User selection" name="nodes" type="AJXP_NODE[]" mandatory="true"/>
                        <output type="stream"/>
                    </serverCallback>
                </processing>
            </action>
            <action name="copy_inbox" ctrlDragndropDefault="true">
                <gui text="inbox_driver.14" title="inbox_driver.15" src="editcopy.png" iconClass="icon-copy" hasAccessKey="false">
                    <context selection="true" dir="" recycle="hidden"
                             actionBar="true" contextMenu="true" infoPanel="false"
                             actionBarGroup="change_main">
                    </context>
                    <selectionContext dir="false" file="true" recycle="false" unique="false"/></gui>
                <rightsContext noUser="true" userLogged="only" read="true" write="false" adminOnly=""/>
                <processing>
                    <clientCallback prepareModal="true"><![CDATA[
					if(pydio.user){
						var user = pydio.user;
						var activeRepository = user.getActiveRepository();
					}
					var context = pydio.getController();
					var onLoad = function(oForm){
						var getAction = oForm.select('input[name="get_action"]')[0];
						getAction.value = 'copy';
						this.treeSelector = new TreeSelector(oForm, {
                            nodeFilter : function(ajxpNode){
                                return (!ajxpNode.isLeaf() && !ajxpNode.hasMetadataInBranch("ajxp_readonly", "true"));
                            }
                        });
						if(user && user.canCrossRepositoryCopy() && user.hasCrossRepositories()){
							var firstKey ;
							var reposList = new Hash();
							ProtoCompat.map2hash(user.getCrossRepositories()).each(function(pair){
								if(!firstKey) firstKey = pair.key;
								reposList.set(pair.key, pair.value.getLabel());
							}.bind(this));

                            var nodeProvider = new RemoteNodeProvider();
                            nodeProvider.initProvider({tmp_repository_id:firstKey});
                            var rootNode = new AjxpNode("/", false, MessageHash[373], "folder.png", nodeProvider);
                            this.treeSelector.load(rootNode);

							this.treeSelector.setFilterShow(true);
							reposList.each(function(pair){
								this.treeSelector.appendFilterValue(pair.key, pair.value);
							}.bind(this));

							this.treeSelector.setFilterSelectedIndex(0);
							this.treeSelector.setFilterChangeCallback(function(e){
								externalRepo = this.filterSelector.getValue();
								var nodeProvider = new RemoteNodeProvider();
								nodeProvider.initProvider({tmp_repository_id:externalRepo});
								this.resetAjxpRootNode(new AjxpNode("/", false, MessageHash[373], "folder.png", nodeProvider));
							});
						}else{
							this.treeSelector.load();
						}
					}.bind(context);
					var onCancel = function(){
						this.treeSelector.unload();
						hideLightBox();
					}.bind(context);
					var onSubmit = function(){
						var oForm = modal.getForm();
						var getAction = oForm.select('input[name="get_action"]')[0];
						var selectedNode = this.treeSelector.getSelectedNode();
						if(activeRepository && this.treeSelector.getFilterActive(activeRepository)){
							getAction.value = "cross_copy" ;
						}
						pydio.getUserSelection().updateFormOrUrl(oForm);
						this.submitForm(oForm);
						this.treeSelector.unload();
						hideLightBox();
					}.bind(context);
					modal.showDialogForm('Move/Copy', 'copymove_form', onLoad, onSubmit, onCancel);
					]]></clientCallback>
                    <clientForm id="copymove_form"><![CDATA[
					<div id="copymove_form" action="copy" box_width="272">
						<input type="hidden" name="dest_node" value=""/>
						<div class="dialogLegend">AJXP_MESSAGE[175]</div>
						<select id="external_repository" name="dest_repository_id" style="width: 248px; font-size: 12px; height: 21px; margin-top:5px; margin-bottom:7px; border: 1px solid #ccc;"></select>
						<div style="height:200px; width:246px; padding: 0px 0px; border: 1px solid #ccc;">
							<div id="treeCopy" style="height:194px; padding: 3px 2px; overflow:auto; text-align:left;" class="treeCopyContainer"></div>
						</div>
						<input type="text" name="dest" value="/" readonly  style="width:248px; border: 1px solid #ccc; margin-top:7px; margin-bottom:2px;background-image:none;"/>
					</div>
				]]></clientForm>
                    <clientListener name="contextChange"><![CDATA[
				if(pydio){
					var action = pydio.getController().getActionByName("copy");
					if(action){
						action.rightsContext.write = true;
						var ajxpUser = pydio.user;
						if(ajxpUser && !ajxpUser.canWrite() && ajxpUser.canCrossRepositoryCopy() && ajxpUser.hasCrossRepositories()){
							action.rightsContext.write = false;
							pydio.getController().defaultActions['delete']('ctrldragndrop');
							pydio.getController().defaultActions['delete']('dragndrop');
						}
						if(ajxpUser && ajxpUser.canWrite() && pydio.getContextNode().hasAjxpMimeInBranch("ajxp_browsable_archive")){
						    action.rightsContext.write = false;
						}
						if(pydio.getContextNode().hasAjxpMimeInBranch("ajxp_browsable_archive")){
							action.setLabel(247, 248);
							action.setIconSrc('ark_extract.png');
						}else{
							action.setLabel(66, 159);
							action.setIconSrc('editcopy.png');
						}
					}
				}
				]]></clientListener>
                    <serverCallback methodName="switchAction" restParams="/" developerComment="Copy one or more items to a given target">
                        <input_param description="Selection" name="nodes" type="AJXP_NODE[]" mandatory="true"/>
                        <input_param description="Target folder where to copy" name="dest" type="path" mandatory="true"/>
                    </serverCallback>
                </processing>
            </action>
            <action name="share_react" forbidOverride="true"/>
            <action name="share" forbidOverride="true"/>
            <action name="get_my_feed" forbidOverride="true"/>
            <action name="mkdir" forbidOverride="true"/>
            <action name="upload" forbidOverride="true"/>
            <action name="compress" forbidOverride="true"/>
            <action name="compress_ui" forbidOverride="true"/>
        </actions>
        <client_configs>
            <component_config className="FilesList">
                <columns>
                    <additional_column attributeName="share_meta_type" sortType="CellSorterValue" modifier="InboxWidgets.filesListCellModifier"
                                       defaultVisibilty="visible" messageString="Share Type"/>
                </columns>
            </component_config>
        </client_configs>
        <client_configs>
            <template_part ajxpClass="AjxpReactComponent" ajxpId="topPane" ajxpOptions='{"componentNamespace":"InboxWidgets","componentName":"LeftPanel"}'/>
        </client_configs>
    </registry_contributions>
    <dependencies>
        <pluginClass pluginName="access.fs"/>
        <pluginResources pluginName="access.fs"/>
    </dependencies>
    <class_stream_wrapper filename="plugins/access.inbox/class.inboxAccessWrapper.php" classname="inboxAccessWrapper" protocol="ajxp.inbox"/>
</ajxpdriver>
