cancel
Showing results for 
Search instead for 
Did you mean: 

How to add my own "delete site" dialog confirm on the site configuration options of alfresco share

4535992
Star Collaborator
Star Collaborator

I don't understand why alfresco choose aikau instead of going ahead with spring.... any small modification you try to make is a nightmare....

I just want to add my own entry/action in the dropdown Toolbar of site-wide operations....

To simplify the example let's leave out all the alfresco server-side stuff and focus on the Share interface-side stuff

Here a image to understand where i put my action:

image

Here the code is use:

1) A spring surf extension (project-share/src/main/resources/alfresco/web-extension/site-data/extensions/service-site-extension.xml)

<extension>
    <modules>
     	<module>
            <id>service-site-extension</id>
            <version>1.0</version>
            <auto-deploy>false</auto-deploy>
            <evaluator type="default.extensibility.evaluator"/>
            <customizations>
                <customization>
                    <targetPackageRoot>org.alfresco.share.header</targetPackageRoot>
                    <sourcePackageRoot>XXX.YYY.ZZZ.share.header</sourcePackageRoot>
                </customization>
            </customizations>
            
            <configurations>
	            <config evaluator="string-compare" condition="DocLibCustom">
				    <dependencies>
				      <js src="/XXX/modules/close-acdat.js"/>
				      <css src="/XXX/modules/close-acdat.css"/>
				    </dependencies>
				 </config>
            </configurations>
      	</module>
    </modules>
</extension>

2) The customization of the "share-header.get.js" (/project-share/src/main/resources/alfresco/web-extension/site-webscripts/XXX/YYY/ZZZ/share/header/share-header.get.js)

<import resource="classpath:/alfresco/site-webscripts/org/alfresco/share/imports/share-header.lib.js">

// CLOSE SITE CONFIGURATION OPTION

if(page.url.templateArgs.site) {
	var siteData = getSiteData();
	if(siteData) {
		var isInAdminGroup = user.isAdmin; /
		var isInManagerGroup = siteData != null && siteData.userIsSiteManager;
		var sitePreset = siteData.profile.sitePreset;
		if((isInAdminGroup || isInManagerGroup)) { 
		    var siteConfig = widgetUtils.findObject(model.jsonModel, "id", "HEADER_SITE_CONFIGURATION_DROPDOWN");
			if (siteConfig != null) {
			   var widgets = siteConfig.config.widgets;
			   // Add Close Site options only if is adimn or manager member of the site
			   widgets.push({
			      id: "HEADER_SERVICE_ACDAT_CLOSE_SITE",
			      name: "alfresco/menus/AlfMenuItem",
			      config: {
			         id: "HEADER_SERVICE_ACDAT_CLOSE_SITE",
			         label: "service-acdat-close_site.label",	            
		             title: "service-acdat-close_site.label",
		             iconAltText: "service-acdat-close_site.label",
			         iconClass: "alf-delete-20-icon",
                     
			         publishTopic: "ALF_CLOSE_ACDAT", // HOW THE HELL I CALL MY JAVASCRIPT FROM THIS ????
 				     //publishTopic: "ALF_DELETE_SITE", /// THIS IS WORK....
			         publishPayload: {
			            shortName: page.url.templateArgs.site,
			            redirect: {
			               url: "user/" + encodeURIComponent(user.name) + "/dashboard",
			               type: "PAGE_RELATIVE",
			               target: "CURRENT"
			            }
			         }
			      }
			   }); 
		  }
		}
	}
}

3) The javascript i want to call.... with the ALF_CLOSE_ACDAT

/**
 * CloseSite module.
 *
 * Displays a dialog with cofirmation to close a site.
 * 
 * @namespace Alfresco.module
 * @class Alfresco.module.ServiceAcdatCloseSite
 */
(function()
{
   /**
    * CloseSite constructor.
    *
    * CloseSite is considered a singleton so constructor should be treated as private,
    * please use Alfresco.module.getServiceAcdatCloseSiteInstance() instead.
    *
    * @param {string} htmlId The HTML id of the parent element
    * @return {Alfresco.module.CloseSite} The new CloseSite instance
    * @constructor
    * @private
    */
   Alfresco.module.ServiceAcdatCloseSite = function(containerId)
   {
      var instance = Alfresco.util.ComponentManager.get(containerId);
      if (instance !== null)
      {
         throw new Error("An instance of Alfresco.module.ServiceAcdatCloseSite already exists.");
      }

      Alfresco.module.ServiceAcdatCloseSite.superclass.constructor.call(this, "Alfresco.module.ServiceAcdatCloseSite", containerId, ["button", "container", "connection", "selector", "json"]);

      // Set prototype properties
      this.closePromptActive = false;

      return this;
   };

   YAHOO.extend(Alfresco.module.ServiceAcdatCloseSite, Alfresco.component.Base,
   {
      /**
       * Will become true when the template (that sets the i18n messages)
       * to this module has been loaded.
       */
      localized: false,

      /**
       * Makes sure the dialog isn't displayed twice at the same time
       */
      closePromptActive: false,

      /**
       * Shows the dialog
       * in different ways depending on the config parameter.
       *
       * @method show
       * @param config {object} describes how the upload dialog should be displayed
       * The config object is in the form of:
       * {
       *    site:
       *    {
       *       shortName: {string},    // shortName of site to close
       *       title: {string}      // Name of site to close
       *    }
       * }
       */
      show: function CloseSite_show(config)
      {
         var c = config;
         if (this.localized)
         {
             this._showDialog(c);
         }
         else
         {
            Alfresco.util.Ajax.request(
            {
               url: Alfresco.constants.URL_SERVICECONTEXT + "modules/service-acdat/close-site",
               dataObj:{ htmlid: this.id },
               successCallback:
               {
                  fn: function()
                  {
                     this.onMessagesLoaded(c);
                  },
                  scope: this
               },
               execScripts: true,
               failureMessage: "Could not load close site messages"
            });
         }
      },

      /**
       * Called when the CloseSite messages has been returned from the server.
       * Shows the dialog.
       *
       * @method onMessagesLoaded
       * @param config {object} The config for the dialog
       */
      onMessagesLoaded: function CloseSite_onMessagesLoaded(config)
      {
         this.localized = true;
         this._showDialog(config);
      },

      /**
       * Shows the dialog.
       *
       * @method _showDialog
       * @param config {object} The config for the dialog
       * @private
       */
      _showDialog: function CloseSite__showDialog(config)
      {
         if (!this.closePromptActive)
         {
            this.closePromptActive = true;
            var me = this,
               c = config;
            Alfresco.util.PopupManager.displayPrompt(
            {
               title: Alfresco.util.message("title.closeSite", this.name),
               text: Alfresco.util.message("label.closeSite", this.name,
               {
                  "0": Alfresco.util.encodeHTML(c.site.title)
               }),
               noEscape: true,
               buttons: [
               {
                  text: Alfresco.util.message("button.close", this.name),
                  handler: function CloseSite__sD_close()
                  {                        
                     this.destroy();
                     me._onCloseClick.call(me, c);
                  }
               },
               {
                  text: Alfresco.util.message("button.cancel", this.name),
                  handler: function CloseSite__sD_cancel()
                  {
                     me.closePromptActive = false;
                     this.destroy();
                  },
                  isDefault: true
               }]
            });
            
            var Dom = YAHOO.util.Dom;
            var elements = Dom.getElementsByClassName('yui-button', 'span', 'prompt');
            Dom.addClass(elements[0], 'alf-primary-button');
         }
      },
      
      /**
       * Handles close click event.
       *
       * @method _onCloseClick
       * @param config {object} The config for the dialog
       * @private
       */
      _onCloseClick: function CloseSite__onCloseClick(config)
      {
         var me = this,
            c = config;
         Alfresco.util.PopupManager.displayPrompt(
         {
            title: Alfresco.util.message("title.closeSite", this.name),
            text: Alfresco.util.message("label.confirmCloseSite", this.name),
            noEscape: true,            
            buttons: [
               {
                  text: Alfresco.util.message("button.yes", this.name),
                  handler: function CloseSite__oDC_close()
                  {
                     this.destroy();
                     me._onConfirmedCloseClick.call(me, c);
                  }
               },
               {
                  text: Alfresco.util.message("button.no", this.name),
                  handler: function CloseSite__oDC_cancel()
                  {
                     me.closePromptActive = false;
                     this.destroy();
                  },
                  isDefault: true
               }]
         });
      },

      /**
       * Handles confirmed close click event.
       *
       * @method _onConfirmedCloseClick
       * @param config {object} The config for the dialog
       * @private
       */
      _onConfirmedCloseClick: function CloseSite__onConfirmedCloseClick(config)
      {
         var me = this,
            c = config;
         var feedbackMessage = Alfresco.util.PopupManager.displayMessage(
         {
            text: Alfresco.util.message("message.closingSite", this.name),
            spanClass: "wait",
            displayTime: 0
         });
         
         // user has confirmed, perform the actual close
         Alfresco.util.Ajax.jsonPost(
         {
            url: Alfresco.constants.URL_SERVICECONTEXT + "modules/service-acdat/close-site",
            dataObj:
            {
               shortName: config.site.shortName
            },
            successCallback:
            {
               fn: function(response)
               {
                  me.closePromptActive = false;
                  feedbackMessage.destroy();
                  if (response.json && response.json.success)
                  {
                     Alfresco.util.PopupManager.displayMessage(
                     {
                        text: Alfresco.util.message("message.siteClosed", this.name)
                     });
                     
                     // Tell other components that the site has been closed
                     YAHOO.Bubbling.fire("siteClosed",
                     {
                        site: c.site
                     });
                  }
                  else
                  {
                     Alfresco.util.PopupManager.displayMessage(
                     {
                        text: Alfresco.util.message("message.closeFailed", this.name)
                     });
                  }
               },
               scope: this
            },
            failureCallback:
            {
               fn: function(response)
               {
                  me.closePromptActive = false;
                  feedbackMessage.destroy();
                  Alfresco.util.PopupManager.displayMessage(
                  {
                     text: Alfresco.util.message("message.closeFailed", this.name)
                  });
               },
               scope: this
            }
         });
      }
   });
})();

Alfresco.module.getServiceAcdatCloseSiteInstance = function()
{
   var instanceId = "alfresco-service-acdat-closesite-instance";
   return Alfresco.util.ComponentManager.get(instanceId) || new Alfresco.module.ServiceAcdatCloseSite(instanceId);
};

now I don't understand how I have to add my ALF_CLOSE_ACDAT to make a simple confirmation dialog appear and then launch an action on Alfresco, but clearly I can't make the confirmation dialog appear...

If I enter ALF_DELETE_SITE the button works and brings up the confirmation dialog as it should....
At the github source code level I cannot see where the string ALF_DELETE_SITE is used to invoke the javascript code "delete-site.js"

SO IN BRIEF MY QUESTION IS HOW THE HELL DO I CONNECT "ALF_CLOSE_ACDAT " TO THE JAVASCRIPT FILE "close-acdat.js" to make the confirmation dialog appear exactly as ALD_DELETE_SITE does ?

0 REPLIES 0