cancel
Showing results for 
Search instead for 
Did you mean: 

Dashlet Button not working

ramprasad_g
Champ in-the-making
Champ in-the-making
Hi,

I am new to Alfresco, this is my basic example.
Below is my sample code, which is to add button to dashlet.
As per my JS, it should show alert message when I click on button, but I am getting error as, Alfresco.SampleDashlet is not a constructor.
Please let me know where I did mistake.

/**
* Sample Hello World dashboard component.
*
* @namespace dashlet
* @class dashlet.HelloWorld
* @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 HelloWorld constructor.
    *
    * @param {String} htmlId The HTML id of the parent element
    * @return {MyCompany.dashlet.HelloWorld} The new component instance
    * @constructor
    */
   Alfresco.SampleDashlet = function(htmlId)
   {
      Alfresco.SampleDashlet.superclass.constructor.call(this, "Alfresco.SampleDashlet", htmlId, ["button"]);

      /* Initialise prototype properties */
      this.listWidgets = [];
    
      return this;
   };

   /**
    * Extend from Alfresco.component.Base and add class implementation
    */
   YAHOO.extend(Alfresco.SampleDashlet, Alfresco.component.Base,
   {
      /**
       * Object container for initialization options
       *
       * @property options
       * @type object
       */
      options:
      {
      },

      /**
       * Fired by YUI when parent element is available for scripting
       *
       * @method onReady
       */
      onReady: function HelloWorld_onReady()
      {
         // Save a reference to the button in case we need it later
         this.widgets.testButton = Alfresco.util.createYUIButton(this, "testButton", this.onButtonClick);
      },
     
      /**
       * Button click event handler
       *
       * @method onButtonClick
       */
      onButtonClick: function HelloWorld_onButtonClick(e)
      {
        console.log('Hi');
      }
     
   });
})();
2 REPLIES 2

krutik_jayswal
Elite Collaborator
Elite Collaborator
Can you please post your FTl file for this dashlet?

Regards,
Krutik Jayswal
Alfresco Developer
krutik.jayswal@gmail.com
BLOG: http://krutikjayswal-alfresco.blogspot.in

Hi,

<@markup id="css" >
   <#– CSS Dependencies –>
   <link rel="stylesheet" type="text/css" href="${page.url.context}/res/components/site/dashlets/sampledashlet.css" group="dashlets" />
</@>

<@markup id="js">
   <#– JavaScript Dependencies –>
   <script type="text/javascript" src="${page.url.context}/res/components/site/dashlets/sampledashlet.js" group="dashlets"></script>
</@>

<@markup id="widgets">
   <@createWidgets group="dashlets"/>
</@>

<@markup id="html">
    <@uniqueIdDiv>
        <div class="dashlet">
           <div class="title">Sample Dashlet</div>
           <div class="body">
             <div class="detail-list-item last-item">
                <button id="testButton">${msg("Generate SpreadSheet")}</button>
             </div>
           </div>
        </div>
    </@>
</@>