AnsweredAssumed Answered

How to get custom edit form properties display & post on a dashlet throw simpleDialog ?

Question asked by yascorp on Apr 9, 2014
Latest reply on Apr 9, 2014 by yascorp
Hello,
I have a custom model with many properties, I want to display my custom model into a dashlet so I can edit on this one and have my post content results into the documentLibrary folder.

I get this error : Uncaught TypeError: undefined is not a function
                   Uncaught TypeError: Cannot read property 'attributes' of null

Thanks for your help :)
Regards !


//list-news.js
<javascript>
if (typeof custom == "undefined" || !custom){
   var custom = {};
   custom.dashlet = {};
}

(function() {
   
   var Dom = YAHOO.util.Dom,
      Event = YAHOO.util.Event;
   
   //var $html = Alfresco.util.encodeHTML;
   
   custom.dashlet.list_news = function list_news_constructor(htmlId) {
      
      custom.dashlet.list_news.superclass.constructor.call(this, "custom.dashlet.list_news", htmlId);
      
      //Register the 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;
   };
   
   YAHOO.extend(custom.dashlet.list_news, Alfresco.component.Base,
   {
      options:
         {   
            componentId : "",
            containerId : "documentlibrary",
         },
         
      configDialog: null,
         
      widgets: {},
         
      onReady: function list_news_onReady() {
         var me = this;
                        
         // Add click handler to config news link that will be visible if user
          // is site manager.
         var configFeedLink = Dom.get(this.id + "-config-link");
          if (configFeedLink) {           
              Event.addListener(configFeedLink, "click",this.onConfigListNewsClick, this, true);           
          }
      },
      
      onConfigListNewsClick : function list_news_onConfigListNewsClick(e) {
         
         var actionUrl = Alfresco.constants.URL_SERVICECONTEXT + "modules/list-news/config/" +
         encodeURIComponent(this.options.componentId);
         
         function computeRedirectUrl(){
            var scope = "window.parent.Alfresco.util.ComponentManager.get('" + this.id + "')";
            var successCallback = "window.parent.Alfresco.util.ComponentManager.get('" + this.id + "-configDialog')" +
                  ".options.onSuccess.fn";
            var failureCallback = "window.parent.Alfresco.util.ComponentManager.get('" + this.id + "-configDialog')" +
                  ".options.onFailure.fn";
            var params = {
                        successCallback: successCallback,
                        successScope: scope,
                        failureCallback: failureCallback,
                        failureScope: scope
            }
            var url = Alfresco.constants.URL_SERVICECONTEXT + "api/multipartcallback?";
            url += "params=" + JSON.stringify(params);
            return url;
         }
                  
                                                   
         var templateUrl = YAHOO.lang.substitute(Alfresco.constants.URL_SERVICECONTEXT +
               "components/form?itemKind={itemKind}&itemId={itemId}&htmlid={htmlid}&formId={formId}" +
               "&destination={destination}&mode={mode}&submitType={submitType}&showCancelButton=true&redirect={redirect}",

               {
                  itemKind: "type",
                  itemId: "ca:entryFormNews",
                  htmlid: "html",
                  formId: "custom-metadata",
                  //destination: destination,
                  mode: "create",
                  submitType: "json",//multipart
                  redirect: computeRedirectUrl()
               });
         
         if(!this.configDialog){
            this.configDialog = new Alfresco.module.SimpleDialog(this.id + "-configDialog").setOptions(
                  {
                     width: "40em",
                     templateUrl: templateUrl,
                     actionUrl: actionUrl,
                     destroyOnHide: true,               
                     
                     onSuccess:
                     {
                        fn: function list_news_onConfig_success(response){
                           Alfresco.util.PopupManager.displayMessage(
                                 {
                                    text: this.msg("message.success")
                                 });
                           },
                        scope: this         
                     },
                     onFailure:
                     {
                        fn: function list_news_onConfig_failure(response){
                           Alfresco.util.PopupManager.displayMessage(
                                 {
                                    text: this.msg("message.failure")
                                 });
                           },
                        scope: this
                     }
                  });
         }
         this.configDialog.setOptions(
               {
                  actionUrl: actionUrl,
                  containerId: this.options.containerId
               }).show();      
      },      
   });
})();
</javascript>




//list-news.get.html.ftl
<html>
<#assign el=args.htmlid?js_string>

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

(function() {
   var list_news = new custom.dashlet.list_news("${args.htmlid}").setOptions(
         {
            "componentId": "${instance.object.id}",
             "titleStr": "${title}",
             "descriptionStr": "${description}",
             "categoryStr": "${category}",
         }).setMessages(${messages});

new Alfresco.widget.DashletResizer("${args.htmlid}", "${instance.object.id}");

/*
* Créer un évennement lors du click
*/
var editDashletEvent = new YAHOO.util.CustomEvent("onDashletConfigure");
editDashletEvent.subscribe(list_news.onConfigListNewsClick, list_news, 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 list_news">
    <div id="list_news_title" class="title">${msg("header.list-news")}</div>
   
    <div class="toolbar flat-button">
      <a id="${el}-config-link" class="configure theme-color-1" href="#">${msg("config")}</a>
   </div>      
       <#–<div class="titleBarActions" style="opacity: 0;">
           <div title="Afficher l'aide pour ce dashlet" class="titleBarActionIcon help"></div>
              <div title="S'inscrire au flux RSS de ce dashlet" class="titleBarActionIcon rss"></div>      
       </div>–>
      
    <div class="body scrollablePanel" <#if args.height??>style="height: ${args.height}px;"</#if>>
       <div class="detail-list-item first-item last-item">
          <h2><span id="${el}-title">${title}</span></h2>
         <p><span id="${el}-description">${description}</span></p>
          <p><span id="${el}-category">${category}</span></p>
                                    
        </div>  
    </div>
</div>
</html>




//share-config-custom.xml
<alfresco-config>
<config evaluator="node-type" condition="ca:entryFormNews" replace="true">
      <forms>         
         <form id="custom-metadata">
            <field-visibility>
               <!– <show id="cm:name" /> –>
               <show id="ca:title" force="true"/>
               <show id="ca:description" />
               <show id="ca:category" force="true"/>
               
               <hide id="cm:mimetype" />
               <hide id="cm:size" />
               <hide id="cm:author" />
               <hide id="cm:creator" />
               <hide id="cm:created" />
               <hide id="cm:modifier" />
               <hide id="cm:modified" />            
            </field-visibility>
               
               <appearance>
                  <set id="customAlfrescoPropertiesGroup" appearance="fieldset" label="Product_Properties" />

                  <field id="ca:title" set="customAlfrescoPropertiesGroup">
                     <control template="/org/alfresco/components/form/controls/textfield.ftl"/>
                  </field>
                  <field id="ca:description" set="customAlfrescoPropertiesGroup" >
                     <control template="/org/alfresco/components/form/controls/textfield.ftl"/>
                  </field>
                    <field id="ca:category" set="customAlfrescoPropertiesGroup" >
                       <control template="/org/alfresco/components/form/controls/textfield.ftl"/>
                    </field>
                             
               </appearance>
            </form>                            
         </forms>
   </config>
</alfresco-config>

Outcomes