2009-08-03 30 views
4

當我玩露天份額時,發現很難跟蹤UI和javascript。你只能在HTML標籤中看到一些類名,但是你很難知道它們是如何構建的,以及這些分散的HTML代碼何時,如何以及如何渲染這樣一個奇特的頁面。alfresco的javascript(不是webscript)機制

有人可以幫助我嗎?請提供幾個例子並解釋它們的工作方式!

在此先感謝!

回答

2

你應該嘗試用螢火蟲來瀏覽你的客戶端代碼。

Alfresco包括一堆文件,這些文件在服務器端都被拉到一起以便爲每個「頁面」提供服務。

我強烈推薦Jeff Potts的Alfresco Developer Guide(您可以立即購買並在線查看)。

  • 詹姆斯Raddock 公司DOOR3
3

下面是一些例子,希望能幫助你(它也可在維基)。大部分魔術都發生在JavaScript中(儘管佈局也部分在html中設置)。

比方說,你想建立一個dashlet。你必須在佈局像這樣幾個文件:

服務器端組件的位置:

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

和客戶端腳本在

$TOMCAT_HOME/share/components/dashlets... 

所以 - 在服務器端,有一個dashlet.get.desc.xml - 定義URL並描述web腳本/ dashlet的文件。

還有一個dashlet.get.head.ftl文件 - 這就是你可以把一個< SCRIPT SRC =「...」 >標籤,這些將被包含在整個頁面的<頭>組件。

終於有具有<腳本類型=「文/ JavaScript的」 >標籤通常初始化您JS,平時喜歡新Alfresco.MyDashlet()。setOptions({一dashlet.get.html.ftl文件。 ..});

現在,有客戶端。就像我說過的,您有/share/components/dashlets/my-dashlet.js(或my-dashlet-min.js)中的客戶端腳本。該腳本通常包含一個自執行匿名函數定義你的Alfresco.MyDashlet對象,像這樣:所以現在你擁有了它

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

    // then in the end, there is the extending of Alfresco.component.Base 
    // which has basic Alfresco methods, like setOptions(), msg() etc 
    // and adding new params and scripts to it. 
    YAHOO.extend(Alfresco.MyDashlet, Alfresco.component.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 components 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 
} 

。如果你瀏覽alfresco.js文件,你會發現你可以使用的東西,比如Alfresco.util.Ajax,createYUIButton,createYUIPanel,createYUIeverythingElse等。你也可以通過嘗試玩,比如說我的網站或我的任務dashlets,他們並不那麼複雜。

而且Alfresco會將你的html.ftl部分放在頁面主體,你的頭部。在頁頭和最終用戶FTL部分加載一個網頁,其中:

  • 加載HTML部分
  • 加載javascript並執行它,然後
  • JavaScript的接管,加載其他組件和做的東西

試着弄明白,你就可以得到其他更復雜的東西。 (也許:))

相關問題