<?xml version="1.0" encoding="UTF-8"?>
<ajxp_plugin label="CONF_MESSAGE[Notification Center]" description="CONF_MESSAGE[Handle users watches and notifications]" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="file:../core.ajaxplorer/ajxp_registry.xsd">
    <class_definition classname="AJXP_NotificationCenter" filename="plugins/core.notifications/class.AJXP_NotificationCenter.php"/>
    <client_settings>
        <resources>
            <i18n namespace="notification.tpl.short" path="plugins/core.notifications/templates/short"/>
            <i18n namespace="notification.tpl.long" path="plugins/core.notifications/templates/long"/>
            <i18n namespace="notification.tpl.group" path="plugins/core.notifications/templates/group"/>
            <i18n namespace="notification.tpl.block" path="plugins/core.notifications/templates/block"/>
            <i18n namespace="notification.tpl.location" path="plugins/core.notifications/templates/location"/>
            <i18n namespace="notification_center" path="plugins/core.notifications/res/i18n"/>
            <css file="plugins/core.notifications/res/css/notification_center.css" autoload="true"/>
            <img_library alias="notification_center" path="plugins/core.notifications/res/img"/>
            <js className="NotificationLoader" file="plugins/core.notifications/class.NotificationLoader.js"/>
        </resources>
    </client_settings>
    <server_settings>
        <param name="activate_notifications" scope="user" description="CONF_MESSAGE[Activate desktop notifications]" label="CONF_MESSAGE[Desktop Notifications]" type="button" choices="run_client_action:activateDesktopNotifications" expose="true" editable="true"/>
        <global_param description="CONF_MESSAGE[Display a new entry with all events happening on a user workspaces, and alerts. An SQL database must be setup for the FEED_DRIVER configuration.]" label="CONF_MESSAGE[User events and alerts]" name="USER_EVENTS" type="boolean" default="false"/>
        <global_param type="plugin_instance:feed" name="UNIQUE_FEED_INSTANCE" group="CONF_MESSAGE[Instance Params]" label="CONF_MESSAGE[Feed Instance]" description="CONF_MESSAGE[Choose the plugin]" mandatory="true" default="feed.sql"/>
    </server_settings>
    <registry_contributions>
        <actions>
            <action name="get_my_feed">
                <gui text="notification_center.1" title="notification_center.2" iconClass="icon-rss" src="notification_center/ICON_SIZE/feed.png" accessKey="" hasAccessKey="false">
             		<context selection="false" dir="" recycle="true" actionBar="true" actionBarGroup="user" contextMenu="false" infoPanel="false"/>
                </gui>
                <rightsContext adminOnly="false" noUser="false" read="false" userLogged="only" write="false"/>
                <subMenu>
                    <dynamicBuilder><![CDATA[
                        var context = window.builderContext;
                        var protoMenu = window.builderProtoMenu;
                        if(!window.ajxpMinisite){
                            ResourcesManager.prototype.loadJSResource('plugins/core.notifications/class.NotificationLoader.js', 'NotificationLoader', function(){
                                NotificationLoader.getInstance().dynamicBuilderLoader(context, protoMenu);
                            });
                        }
                    ]]></dynamicBuilder>
                </subMenu>
                <processing>
                    <clientCallback><![CDATA[
                    ]]></clientCallback>
                    <clientForm id="user_feed"><![CDATA[
                        <div id="user_feed" box_padding="0" class="dialogBox css_boxshadow">
                        </div>
                    ]]></clientForm>
                    <clientListener name="contextChange"><![CDATA[
                        if(!window.NotificationLoader && ajaxplorer.user && !window.ajxpMinisite){
                            ResourcesManager.prototype.loadJSResource('plugins/core.notifications/class.NotificationLoader.js', 'NotificationLoader');
                        }
                    ]]></clientListener>
                    <serverCallback methodName="loadUserFeed"/>
                </processing>
            </action>
            <action name="feed">
                <rightsContext adminOnly="false" noUser="false" read="false" userLogged="only" write="false"/>
                <processing>
                    <serverCallback methodName="loadUserFeed" restParams="/feed_type/path+" developerComment="Load an activity feed for the given node. Filtered by what the current user is authorized to see">
                        <input_param name="path" type="path" description="Optional filter to get activity on a file or a folder"/>
                        <input_param name="format" type="string" description="html, json, xml, array (internal value)"/>
                        <input_param name="feed_type" type="string" description="notif, alert or all"/>
                        <input_param name="offset" type="integer" description="Offset for pagination"/>
                        <input_param name="limit" type="integer" description="Limit for pagination"/>
                        <input_param name="merge_description" type="boolean" description="Wether to merge notification title and description in text"/>
                        <input_param name="merge_description_as_label" type="boolean" description="Wether to merge notification title and description in title"/>
                        <input_param name="current_repository" type="boolean"
                                     description="Wether to get activity from current repository (true), or compute all from authorized repositories for user (false)"/>
                    </serverCallback>
                </processing>
            </action>
            <action name="dismiss_user_alert">
                <gui text="notification_center.7" title="notification_center.7" iconClass="mdi mdi-close-circle" src="notification_center/ICON_SIZE/feed.png" accessKey="" hasAccessKey="false">
                    <context selection="true" dir="" recycle="true" actionBar="true" actionBarGroup="inline-notifications" contextMenu="false" infoPanel="false"/>
                    <selectionContext dir="true" file="true" recycle="false" unique="true"/>
                </gui>
                <rightsContext adminOnly="false" noUser="true" read="false" userLogged="only" write="false"/>
                <processing>
                    <clientCallback><![CDATA[
                    var selection = window.actionArguments[0];
                    if(selection.getUniqueNode) selection = selection.getUniqueNode();
                    if(selection && selection.getMetadata && selection.getMetadata().get("alert_id")){
                        var elMeta = selection.getMetadata();
                        var params = {
                            get_action:'dismiss_user_alert',
                            alert_id:elMeta.get('alert_id')
                        };
                        if(elMeta.get("event_occurence")){
                            params['occurrences'] = elMeta.get("event_occurence");
                        }
                        PydioApi.getClient().request(params, function(){
                            ajaxplorer.notify("server_message:tree/reload_user_feed");
                        });
                    }
                    ]]></clientCallback>
                    <serverCallback methodName="dismissUserAlert" restParams="/alert_id/occurences" developerComment="Dismiss one or more occurences of alerts">
                        <input_param name="alert_id" type="integer" description="Id passed in /feed action list"/>
                        <input_param name="occurences" type="integer" description="1 or more"/>
                    </serverCallback>
                </processing>
            </action>
            <action name="activateDesktopNotifications">
                <gui src="" iconClass="icon-rss" text="notification_center.1" title="notification_title.2">
                    <context dir="true" recycle="true" selection="false"/>
                </gui>
                <processing>
                    <clientCallback><![CDATA[
                        if(window.Notification){
                            alert(pydio.MessageHash["notification_center.12"]);
                            window.Notification.requestPermission(function(grant) {
                                ['default', 'granted', 'denied'].indexOf(grant) === true
                            });
                        }else{
                            alert(pydio.MessageHash["notification_center.13"]);
                        }
                    ]]></clientCallback>
                </processing>
            </action>
        </actions>
        <hooks>
            <serverCallback methodName="persistChangeHookToFeed" hookName="node.change" defer="true"/>
            <serverCallback methodName="persistNotificationToAlerts" hookName="msg.notification"/>
            <serverCallback methodName="loadRepositoryInfo" hookName="repository.load_info"/>
        </hooks>
        <client_configs>
            <component_config className="InfoPanel">
                <infoPanelExtension mime="ajxp_root_node,generic_dir,generic_file" attributes="" modifier="NotificationLoader.prototype.loadInfoPanel">
                    <messages>
                        <message key="type_string" id="share_center.50"/>
                    </messages>
                    <html><![CDATA[
                        <div id="ajxp_activity_panel" data-infoPanelPosition="last">
                        </div>
                    ]]></html>
                </infoPanelExtension>
            </component_config>
            <component_config className="AjxpReactComponent::left_navigator">
                <additional_content
                        id="navigation_alerts"
                        position="0"
                        type="ListProvider"
                        options='{"title":"notification_center.3", "titleClassName":"colorcode-alert", "startOpen":true, "dataModelBadge":{"property":"metadata","metadata_sum":"event_occurence", "className":"alerts_number_badge"}, "fit":"content","silentLoading":true,"actionBarGroups":["inline-notifications"],"nodeProviderProperties":{"get_action":"get_my_feed", "connexion_discrete":true, "format":"xml", "current_repository":"true", "feed_type":"alert", "merge_description":"false"},"reloadOnServerMessage":"tree/reload_user_feed", "connexion_discrete":true, "tipAttribute":"event_description_long", "emptyChildrenMessage":"notification_center.8"}'/>
            </component_config>
        </client_configs>
    </registry_contributions>
    <dependencies>
        <activePlugin pluginName="core.conf"/>
    </dependencies>
</ajxp_plugin>
