AnsweredAssumed Answered

Dashlet custom properties displayed on PopUp

Question asked by yascorp on Apr 11, 2014
Latest reply on Apr 13, 2014 by yascorp
When I click on my dashlet link, I get an error and my popUp can't be displaying

Uncaught TypeError: undefined is not a function
Uncaught TypeError: Cannot read property 'attributes' of null (attributes in "simple-dialog.js")

I get the data on my share console, and I do not understand why I'm getting this error.

Can anybody help me, please HELP me, I don't understand this task.

Every help will be gratefull :)))


<javascript>
//<![CDATA[
      new Alfresco.FormUI("div-form", "div").setOptions(
      {
         mode: "create",
         enctype: "application/json",
         fields:
         [
            {
               id : "prop_ca_title"
            }
            ,
            {
               id : "prop_ca_category"
            }
            ,
            {
               id : "prop_ca_description"
            }
           
         ],
         fieldConstraints:
         [
            {
               fieldId : "div_prop_ca_title",
               handler : Alfresco.forms.validation.mandatory,
               params : {},
               event : "keyup,propertychange",
               message : "………."
            }
            ,
            {
               fieldId : "div_prop_ca_title",
               handler : Alfresco.forms.validation.length,
               params : {"maxLength":50,"minLength":0,"crop":true},
               event : "keyup",
               message : "La valeur inclut un nombre de caractères incorrect."
            }
            ,
            {
               fieldId : "div_prop_ca_description",
               handler : Alfresco.forms.validation.length,
               params : {"maxLength":256,"minLength":0,"crop":true},
               event : "keyup",
               message : "……….."
            }
            ,
            {
               fieldId : "div_prop_ca_category",
               handler : Alfresco.forms.validation.inList,
               params : {"sorted":false,"caseSensitive":true,"allowedValues":     ["Sport|Sport","News|News","Finance|Finance","Kitchen|Kitchen"]},
               event : "blur",
               message : "……….."
            }
           
         ]
      }).setMessages(
         {"form.cont ………………."}
      );
   //]]>
</javascript>


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,
       $combine = Alfresco.util.combinePaths;
   
   custom.dashlet.list_news = function list_news_constructor(htmlId) {
      custom.dashlet.list_news.superclass.constructor.call(this, "custom.dashlet.list_news", htmlId);
      this.configDialog = null;
      
      //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 : "",
            title : "",
            description : "",
            category : ""
         },
         
      configDialog: null,
         
      setOptions: function list_news_setOptions(obj)
            {
               this.options = YAHOO.lang.merge(this.options, obj);
               return this;
            },
           
      onComponentsLoaded: function list_news_onComponentsLoaded()
            {
               Event.onContentReady(this.id, this.onReady, this, true);
            },
           
      //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");           
          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);
         Event.stopEvent(e);
         
         /*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 + "modules/list-news/config?";
            url += "params=" + JSON.stringify(params);
            return url;
         }*/

         
         var doSetupFormsValidation = function list_news_doSetupFormsValidation(form){
            
            //Name: mandatory            
            //form.addValidation(this.id + "_prop_ca_title", Alfresco.forms.validation.mandatory, null, "keyup");
                                                                           
            //form.addValidation(this.configDialog.id + "-title", Alfresco.forms.validation.nodeName, null, "keyup");            
            //form.setShowSubmitStateDynamically(true, false);

            /*Dom.get(this.configDialog.id + "-title").value = this.options.titleStr;
               Dom.get(this.configDialog.id + "-description").value = this.options.descriptionStr;
               Dom.get(this.configDialog.id + "-category").value = this.options.categoryStr;*/         
         
         /*var doBeforeDialogShow = function list_news_doBeforeDialogShow(p_form, p_dialog) {
            
            Alfresco.util.populateHTML();
               Dom.get(p_dialog.id + "-configDialog").value = this.options.componentId;   
         }*/
            var elem = Dom.get(this.configDialog.id + "-title");
                if (elem) {
                   elem.value = this.options.title;
                }

                var elem = Dom.get(this.configDialog.id + "-description");
                if (elem) {
                   elem.value = this.options.description;
                }

                var elem = Dom.get(this.configDialog.id + "-category");
                if (elem) {
                   elem.value = this.options.category;
                }
         };
                        
         var templateUrl = YAHOO.lang.substitute(Alfresco.constants.URL_SERVICECONTEXT +
               "components/form?itemKind={itemKind}&itemId={itemId}&htmlid={htmlid}&destination={destination}" +
               "&mode={mode}&submitType={submitType}&formId={formId}&showCancelButton=true",
               {      
                  itemKind: "type",
                  itemId: "ca:entryFormNews",
                  htmlid: "div",               
                  destination: "${form.destination?html}",
                  mode: "create",
                  submitType: "json",//multipart
                  formId: "custom-metadata"
                  //redirect: computeRedirectUrl()
               });
         
         if(!this.configDialog) {
            
            this.configDialog = new Alfresco.module.SimpleDialog(this.id + "-configDialog").setOptions(
                  {
                     width: "100em",
                     templateUrl: templateUrl,
                     actionUrl: null,
                     destroyOnHide: true,
                     
                     doSetupFormsValidation:
                        {
                           fn: doSetupFormsValidation,
                           scope: this                        
                        },

                     onSuccess:
                     {
                        fn: function list_news_onConfig_success(response) {   
                           
                           var div = Dom.get(this.id + "-form");
                                 div.innerHTML = response.serverResponse.responseText;
                                 var form = Dom.getFirstChildBy(div, function(node) {                                                                        
                                     return (node.tagName.toUpperCase() == "FORM");                                    
                                     });
                                 if (form) {
                                    if (form.attributes["prop_ca_title"]) {                                      
                                       var testLogin = form.attributes["title"].value;
                                    }

                                    if (form.attributes["description"]) {
                                        var testPass = form.attributes["description"].value;
                                    }

                                    if (form.attributes["category"]) {
                                       var testPass = form.attributes["category"].value;
                                    }

                                 }
                           /*var obj = response.json;
                           if(obj) {
                                        this.options = YAHOO.lang.merge(this.options, obj);
                           }
                           var result = eval('(' + obj + ')');*/

                           Alfresco.util.PopupManager.displayMessage(
                                 {
                                    text: this.msg("message.success")
                                 });
                           Alfresco.util.Ajax.request({
                              url: Alfresco.constants.URL_SERVICECONTEXT +    "modules/list-news/config/",
                              dataObj: templateUrl,
                              method: Alfresco.util.Ajax.GET,
                              successCallback: {
                                  fn :this.onComponentsLoaded,
                                  obj: this,
                                  scope:this            
                                    },
                               
                                    failureCallback: {
                                       fn :this._formLoadFailure,
                                       obj: this,
                                       scope:this
                                    },
                                   
                                    scope: this,
                                    execScripts: true
                           });
                           },
                        scope: this         
                     },
                     onFailure:
                     {
                        fn: function list_news_onConfig_failure(response) {
                           Alfresco.util.PopupManager.displayMessage(
                                 {
                                    text: this.msg("message.failure")
                                 });
                           },
                        scope: this
                     }
                  });            
         } else {
            this.configDialog.setOptions(
                     {
                        actionUrl: actionUrl
                     });
         }
         this.configDialog.setOptions(
               {
                  actionUrl: actionUrl
               }).show();
         return this.configDialog;
         
      }      
   });
})();
</javascript>

Outcomes