AnsweredAssumed Answered

Invoquer le formulaire d'édition de propriétés d'un document depuis un dashlet

Question asked by jeanw on Jun 6, 2013
Latest reply on Sep 19, 2013 by tonyrivet
Bonjour à tous.

Je pense que mon titre est assez clair.
J'ai un dashlet qui m'affiche toutes les métadonnées de mon document. Je veux rajouter un mode édition des métadonnées en invoquant tout simplement le formulaire d'édition qui est utilisé lorsqu'on clique sur le lien "edit properties" dans "documentlibrary".
Dans mon ftl, j'ai le code suivant:
<blockcode><#– Uncomment to use a client-side JavaScript component in conjunction with the dashlet –>

<script type="text/javascript">//<![CDATA[

(function() {
   var getDataDoc = new se.dashlet.GetDataDoc("${args.htmlid}").setOptions(
   {
      "componentId": "${instance.object.id}",
     "siteId": "${page.url.templateArgs.site!""}"
   }).setMessages(${messages});
  
   new Alfresco.widget.DashletResizer("${args.htmlid}", "${instance.object.id}");
  
   var editDashletEvent = new YAHOO.util.CustomEvent("onDashletConfigure");
   editDashletEvent.subscribe(getDataDoc.onConfigGetDataDocClick, getDataDoc, true);
   new Alfresco.widget.DashletTitleBarActions("${args.htmlid?html}").setOptions(
   {
      actions:
      [

      <#if userIsSiteManager>
         {
            cssClass: "edit",
            eventOnClick: editDashletEvent,
            tooltip: "${msg("dashlet.edit.tooltip")?js_string}"
         },
      </#if>
         {
            cssClass: "help",
            bubbleOnClick:
            {
               message: "${msg("dashlet.help")?js_string}"
            },
            tooltip: "${msg("dashlet.help.tooltip")?js_string}"
         }
      ]
   }); 
})();
//]]></script>
<div class="dashlet">

   <div class="title">${msg("header")}</div>

   <div class="body scrollableList" <#if args.height??>style="height: ${args.height}px;"</#if>>

     <div class="detail-list-item first-item last-item">
      
        <table class="metadata">
         <tbody>
            <#list result?keys as data>
            <tr>
               <td class="white">${data}</td>
               <td class="yellow">${result[data]}</td>
            </tr>
            </#list>
         </tbody>
      </table>
     </div>
   </div>
</div>
</blockcode>

Dans mon js, j'ai le code suivant:
<blockcode>
/**
* se root namespace.
*
* @namespace se
*/
if (typeof se == "undefined" || !se)
{
   var se = {};
}

/**
* se dashlet namespace.
*
* @namespace se.dashlet
*/
if (typeof se.dashlet == "undefined" || !se.dashlet)
{
   se.dashlet = {};
}

/**
* Sample GetDataDoc dashboard component.
*
* @namespace se.dashlet
* @class se.dashlet.GetDataDoc
* @author
*/
(function()
{
   /**
    * YUI Library aliases
    */
   var Dom = YAHOO.util.Dom,
      Event = YAHOO.util.Event;

   /**
    * Alfresco Slingshot aliases
    */
   var $html = Alfresco.util.encodeHTML,
      $combine = Alfresco.util.combinePaths;


   /**
    * Dashboard GetDataDoc constructor.
    *
    * @param {String} htmlId The HTML id of the parent element
    * @return {se.dashlet.GetDataDoc} The new component instance
    * @constructor
    */
   se.dashlet.GetDataDoc = function GetDataDoc_constructor(htmlId)
   {
      this.configDialog = null;
      return se.dashlet.GetDataDoc.superclass.constructor.call(this, "se.dashlet.GetDataDoc", htmlId);
      /**
      * Register this component
      */
      Alfresco.util.ComponentManager.register(this);

      /**
      * Load YUI Components
      */
      Alfresco.util.YUILoaderHelper.require(["button", "container", "datasource", "datatable", "paginator", "json", "history", "tabview"], this.onComponentsLoaded, this);

      return this;
   };

   /**
    * Extend from Alfresco.component.Base and add class implementation
    */
   YAHOO.extend(se.dashlet.GetDataDoc, Alfresco.component.Base,
   {
      /**
       * Object container for initialization options
       *
       * @property options
       * @type object
       */
      options:
      {
      componentId: "",
      siteId: "",
      containerId: "documentlibrary",
      },

      /**
       * Fired by YUI when parent element is available for scripting
       *
       * @method onReady
       */
      onReady: function GetDataDoc_onReady()
      {
         // Code goes here
       var me = this;
      },
     onConfigGetDataDocClick: function getDataDoc_onConfigGetDataDocClick(e)
        {
         var nodeRef = "workspace://SpacesStore/9e07c849-19f5-4e6e-a709-4c5d2f995069";
         var record = new Alfresco.util.NodeRef(nodeRef);
         //this.onActionDetails(node);
         alert("Test PopUp");
         
         //My code test
         var scope = this,
            nodeRef = record.nodeRef,
            jsNode = record.jsNode;

         // Intercept before dialog show
         var doBeforeDialogShow = function dlA_onActionDetails_doBeforeDialogShow(p_form, p_dialog)
         {
            // Dialog title
            var fileSpan = '<span class="light">' + $html(record.displayName) + '</span>';

            Alfresco.util.populateHTML(
               [ p_dialog.id + "-dialogTitle", scope.msg("edit-details.title", fileSpan) ]
            );

            // Edit metadata link button
            this.widgets.editMetadata = Alfresco.util.createYUIButton(p_dialog, "editMetadata", null,
            {
               type: "link",
               label: scope.msg("edit-details.label.edit-metadata"),
               href: $siteURL("edit-metadata?nodeRef=" + nodeRef)
            });
         };

         var templateUrl = YAHOO.lang.substitute(Alfresco.constants.URL_SERVICECONTEXT + "components/form?itemKind={itemKind}&itemId={itemId}&destination={destination}&mode={mode}&submitType={submitType}&formId={formId}&showCancelButton=true",
         {
            itemKind: "node",
            itemId: nodeRef,
            mode: "edit",
            submitType: "json",
            formId: "doclib-simple-metadata"
         });

         // Using Forms Service, so always create new instance
         this.configDialog = new Alfresco.module.SimpleDialog(this.id + "-configDialog-" + Alfresco.util.generateDomId());

         this.configDialog.setOptions(
         {
            width: "40em",
            templateUrl: templateUrl,
            actionUrl: "",
            destroyOnHide: true,
            doBeforeDialogShow:
            {
               fn: doBeforeDialogShow,
               scope: this
            },
            onSuccess:
            {
               fn: function dlA_onActionDetails_success(response)
               {
                  // Reload the node's metadata
                  Alfresco.util.Ajax.request(
                  {
                     url: $combine(Alfresco.constants.URL_SERVICECONTEXT, "components/documentlibrary/data/node/", jsNode.nodeRef.uri) + "?view=" + this.actionsView,
                     successCallback:
                     {
                        fn: function dlA_onActionDetails_refreshSuccess(response)
                        {
                           var record = response.json.item
                           record.jsNode = new Alfresco.util.Node(response.json.item.node);

                           // Fire "renamed" event
                           YAHOO.Bubbling.fire(record.node.isContainer ? "folderRenamed" : "fileRenamed",
                           {
                              file: record
                           });

                           // Fire "tagRefresh" event
                           YAHOO.Bubbling.fire("tagRefresh");
                    
                     // Fire "registerAction" event
                           YAHOO.Bubbling.fire("registerAction",
                     {
                        actionName: "onActionDetails",
                        fn: onActionDetails
                     });

                           // Display success message
                           Alfresco.util.PopupManager.displayMessage(
                           {
                              text: this.msg("message.details.success")
                           });
                        },
                        scope: this
                     },
                     failureCallback:
                     {
                        fn: function dlA_onActionDetails_refreshFailure(response)
                        {
                           Alfresco.util.PopupManager.displayMessage(
                           {
                              text: this.msg("message.details.failure")
                           });
                        },
                        scope: this
                     }
                  });
               },
               scope: this
            },
            onFailure:
            {
               fn: function dLA_onActionDetails_failure(response)
               {
                  Alfresco.util.PopupManager.displayMessage(
                  {
                     text: this.msg("message.details.failure")
                  });
               },
               scope: this
            }
         });
       //Display module
       this.configDialog.show();
      }
   });
})();

</blockcode>

Pour le moment je fixe le nodeRef en dure pour mes tests.
 var nodeRef = "workspace://SpacesStore/9e07c849-19f5-4e6e-a709-4c5d2f995069";

J'ai fais une alerte pour voir si ma fonction etait bien invoqué.
alert("Test PopUp");


Merci d'avance

JeanW

Outcomes