cancel
Showing results for 
Search instead for 
Did you mean: 

Basic dashlet setup error (superclass undefined)

cybertoast
Champ in-the-making
Champ in-the-making
I've got a situation I don't understand with dashlets. I've created dashlets that work, and now I have new dashlets that don't and can't figure out why some don't work.

I'm creating a custom My Sites dashlet, and putting it into web-extension/site-webscripts/com/myco/components/dashlets/myco-sites.get.*. I've also got client-side handlers in tomcat/webapps/share/components/dashlets/myco-sites.js (and -min.js).

When I refresh the scripts and load my client-side javascript I get:

MycoSites.superclass is undefined
at the MycoSites.supeclass.constructor.call() - detailed below.

My myco-sites.get.desc.ftl is:

<webscript>
   <shortname>MyCo Document Sites</shortname>
   <description>MyCo document sites with popup</description>
   <authentication>user</authentication>
   <family>user-dashlet</family>
   <url>/components/dashlets/myco-sites</url>
</webscript>

This binds the dashlet to /components/dashlets/myco-sites, but there's no physical file at any /components/dashlets/myco-sites location, if my understanding is correct. It's just an internal path to the script.

My client code (and associated YUI components) is included in the myco-sites.get.head.ftl:

<@script type="text/javascript" src="${page.url.context}/yui/yahoo-dom-event/yahoo-dom-event.js"></@script>
<@script type="text/javascript" src="${page.url.context}/yui/button/button.js"></@script>
<@script type="text/javascript" src="${page.url.context}/yui/container/container.js"></@script>
<@script type="text/javascript" src="${page.url.context}/components/dashlets/myco-sites.js"></@script>

My myco-sites.get.html.ftl is basically the same as my-sites.get.html.ftl, except that I instantiate MycoSites instead of MySites:

<script type="text/javascript">//<![CDATA[
   new MycoSites("${args.htmlid}").setOptions({
   }).setMessages(${messages});
   new Alfresco.widget.DashletResizer("${args.htmlid}", "${instance.object.id}");
//]]></script>

My $tomcat/webapps/share/components/dashlets/myco-sites.js is:

(function()
{
   /**
    * YUI Library aliases
    */
   var Dom = YAHOO.util.Dom,
      Event = YAHOO.util.Event;

   /**
    * Alfresco Share aliases
    */
   var $html = Alfresco.util.encodeHTML;

   /**
    * Alfresco.SampleComponent constructor.
    * @return {Alfresco.SampleComponent} the new component instance
    * @constructor
    */
   MycoSites = function MycoSites_constructor(htmlId)
   {
      MycoSites.superclass.constructor.call(this, "MycoSites", htmlId, ["button", "container"]);
      this.preferencesService = new Alfresco.service.Preferences();
      return this;
   };
   YAHOO.extend(MycoSites, Alfresco.component.base,
   {}
   );

I've got other dashlets that work just fine, and now copying them to a new set of files and reloading them causes the same "superclass is undefined" error.

I can't recall having to register the dashlets in any special way. I've also tried to name my client-side function as Alfresco.dashlet.MycoSites (instead of just MycoSites), and still the same problem.

I'd greatly appreciate any pointers - this is driving me slightly batty since I can't see that I've done anything wrong!

Thanks much for any help.
9 REPLIES 9

mikeh
Star Contributor
Star Contributor
Two things stand out:

1 - You don't need the YUI includes, as the Share code has already included them for you.
2 - Is that the whole client-side code? If so, you're not closing the (function(){… part at the end.

Thanks,
Mike

cybertoast
Champ in-the-making
Champ in-the-making
1 - You don't need the YUI includes, as the Share code has already included them for you.
Ok, that's good to know, but  I figured what the heck - can't hurt to have these included multiple times. But I made the change anyway and still have the same problem.

2 - Is that the whole client-side code? If so, you're not closing the (function(){… part at the end.
Sorry, that was a cut and paste error on my part - just missed the last line. The full function is:

(function()
{
   /**
    * YUI Library aliases
    */
   var Dom = YAHOO.util.Dom,
      Event = YAHOO.util.Event;

   /**
    * Alfresco Share aliases
    */
   var $html = Alfresco.util.encodeHTML;

   /**
    * Alfresco.SampleComponent constructor.
    * @return {Alfresco.SampleComponent} the new component instance
    * @constructor
    */
   MycoSites = function MycoSites_constructor(htmlId)
   {
      MycoSites.superclass.constructor.call(this, "MycoSites", htmlId, ["button", "container"]);
      this.preferencesService = new Alfresco.service.Preferences();
      return this;
   };
   YAHOO.extend(MycoSites, Alfresco.component.base,
   {}
   );
})();

cybertoast
Champ in-the-making
Champ in-the-making
One other thing, which may be useful. Firebug console tells me that I have 2 errors:
The first from yuiloader-debug.js line 581:

extend failed, please check that all dependencies are included.
I was assuming this is from the YAHOO.extend() call, and that it was actually thanks to the superclass failure, but maybe I'm misunderstanding.

The second I put in the earlier message, from myco-sites.js:

MycoSites.superclass is undefined

mikeh
Star Contributor
Star Contributor
Ah ok, try
var MycoSites = function MycoSites_constructor(htmlId)
   …

Ideally you want to create a new top-level JavaScript namespace (like the Alfresco one). You can do this with code like:
// Ensure Myco root object exists
if (typeof Myco == "undefined" || !Myco)
{
   var Myco = {};
}

(function()
{
   …
   Myco.Sites = function… etc.

Mike

cybertoast
Champ in-the-making
Champ in-the-making
Didn't help. I still get exactly the same error. The error happens at the superclass.constructor.call(), so the object (MycoSites) is definitely defined, but it does not seem to inherit from whatever the parent object is (i.e., no superclass). Is there some explicit inheritance that I need to specify somewhere?

cybertoast
Champ in-the-making
Champ in-the-making
And also, the same error occurs even if I name the object Alfresco.dashlet.MycoSites, in keeping with Alfresco.dashlet.MySites. So it seems there's something else amiss.

mikeh
Star Contributor
Star Contributor
Ok, got it (I hope!)

It's Alfresco.component.Base, not Alfresco.component.base.

Try that…

Thanks,
Mike

cybertoast
Champ in-the-making
Champ in-the-making
Doh! It's really irritating when it's little things like this that you just can't see after staring at the code for several hours. Thanks a lot Mike!

mikeh
Star Contributor
Star Contributor
Phew!  Smiley Very Happy
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.