yui - How does alfresco's javascript( not webscript) mechanism - Stack Overflow

When I play with alfresco share, I found it is difficult to track theUI and javascript. you can only

When I play with alfresco share, I found it is difficult to track the UI and javascript. you can only see some class name in the HTML tags, But you are difficult to know how are they constructed, And When, where and how can these scattered HTML code can render such a fancy page.

Can someone help me ? Please offer several example and explain how they work!

Thanks in advance!

When I play with alfresco share, I found it is difficult to track the UI and javascript. you can only see some class name in the HTML tags, But you are difficult to know how are they constructed, And When, where and how can these scattered HTML code can render such a fancy page.

Can someone help me ? Please offer several example and explain how they work!

Thanks in advance!

Share Improve this question edited Sep 17, 2009 at 1:42 SLaks 889k181 gold badges1.9k silver badges2k bronze badges asked Aug 3, 2009 at 7:41 MemoryLeakMemoryLeak 7,27824 gold badges93 silver badges136 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Here is some example that will hopefully help you (it's also available on Wiki). Most of the magic happens in JavaScript (although the layout is set in html partly too).

Let's say you want to build a dashlet. You have several files in the layout like this:

Server side ponents here:

$TOMCAT_HOME/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/ponents/dashlets/...

and client-side scripts are in

$TOMCAT_HOME/share/ponents/dashlets...

So - in the server side, there is a dashlet.get.desc.xml - file that defines the URL and describes the webscript/dashlet.

There is also a dashlet.get.head.ftl file - this is where you can put a <script src="..."> tags and these will be included in the <head> ponent of the plete page.

And finally there is a dashlet.get.html.ftl file that has the <script type="text/javascript"> tag which usually initializes your JS, usually like new Alfresco.MyDashlet().setOptions({...});

Now, there's the client side. You have, like I said, a client-side script in /share/ponents/dashlets/my-dashlet.js (or my-dashlet-min.js). That script usually contains a self-executing anonymous function that defines your Alfresco.MyDashlet object, something like this:

(function()
{
  Alfresco.MyDashlet = function(htmlid) {
    // usually extending Alfresco.ponent.Base or something.
    // here, you also often declare array of YUI ponents you'll need,
    // like button, datatable etc
    Alfresco.MyDashlet.superclass.constructor.call(...);
    // and some extra init code, like binding a custom event from another ponent
    YAHOO.Bubbling.on('someEvent', this.someMethod, this);
  }

  // then in the end, there is the extending of Alfresco.ponent.Base
  // which has basic Alfresco methods, like setOptions(), msg() etc
  // and adding new params and scripts to it. 
  YAHOO.extend(Alfresco.MyDashlet, Alfresco.ponent.Base,
   // extending object holding variables and methods of the new class,
   // setting defaults etc
    {
      options: {
        siteId: null,
        someotherParam: false
      },
      // you can override onComponentsLoaded method here, which fires when YUI ponents you requested are loaded
      // you get the htmlid as parameter. this is usefull, because you
      // can also use ${args.htmlid} in the *html.ftl file to name the
      // html elements, like <input id="${args.htmlid}-my-input"> and 
      // bind buttons to it, 
      // like this.myButton = 
      // so finally your method:
      onComponentsLoaded: function MyDaslet_onComponentsLoaded(id) {
        // you can, for example, render a YUI button here. 
        this.myButton = Alfresco.util.createYUIButton(this, "my-input", this.onButtonClick, extraParamsObj, "extra-string");

        // find more about button by opening /share/js/alfresco.js and look for createYUIButton()
      },

      // finally, there is a "onReady" method that is called when your dashlet is fully loaded, here you can bind additional stuff.
      onReady: function MyDashlet_onReady(id) {
        // do stuff here, like load some Ajax resource:
        Alfresco.util.Ajax.request({
          url: 'url-to-call',
          method: 'get',   // can be post, put, delete
          successCallback: {     // success handler
            fn: this.successHandler,  // some method that will be called on success
            scope: this,
            obj: { myCustomParam: true}
          },
          successMessage: "Success message",
          failureCallback: {
            fn: this.failureHandler   // like retrying
          }
        });
      }

      // after this there are your custom methods and stuff
      // like the success and failure handlers and methods
      // you bound events to with Bubbling library
      myMethod: function (params) {
        // code here
      },
      successHandler: function MyDAshlet_successHandler(response) {
        // here is the object you got back from the ajax call you called
        Alfresco.logger.debug(response);
      }

    }); // end of YAHOO.extend
}

So now you have it. If you go through the alfresco.js file, you'll find out about stuff you can use, like Alfresco.util.Ajax, createYUIButton, createYUIPanel, createYUIeverythingElse etc. You can also learn a lot by trying to play with, say, my-sites or my-tasks dashlets, they're not that plicated.

And Alfresco will put your html.ftl part in the page body, your .head.ftl part in the page head and the end user loads a page which:

  • loads the html part
  • loads the javascript and executes it
  • javascript then takes over, loading other ponents and doing stuff

Try to get that, and you'll be able to get the other more plicated stuff. (maybe :))

You should try firebug for stepping through your client side code.

Alfresco includes a bunch of files that are all pulled together on the server side to serve each "page".

I highly remend Alfresco Developer Guide by Jeff Potts (you can buy it and view it online instantly).

  • James Raddock DOOR3 Inc.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745168364a4614772.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信