jvdrean (SVN) wrote:
> Author: jvdrean
> Date: 2009-03-03 23:40:14 +0100 (Tue, 03 Mar 2009)
> New Revision: 17211
> 
> Added:
>    
> platform/web/trunk/standard/src/main/webapp/resources/js/xwiki/xwikiexplorer/
>    
> platform/web/trunk/standard/src/main/webapp/resources/js/xwiki/xwikiexplorer/xwikiexplorer.js
> Modified:
>    platform/web/trunk/standard/src/main/webapp/resources/js/xwiki/xwiki.js
> Log:
> XWIKI-3287 : Provide a tree widget allowing to browse a XWiki farm 
> (wikis>spaces>pages>attachments)
> 
> First version of XWikiExplorer widget.
> 
> 
> 
> Modified: 
> platform/web/trunk/standard/src/main/webapp/resources/js/xwiki/xwiki.js
> ===================================================================
> --- platform/web/trunk/standard/src/main/webapp/resources/js/xwiki/xwiki.js   
> 2009-03-03 22:27:35 UTC (rev 17210)
> +++ platform/web/trunk/standard/src/main/webapp/resources/js/xwiki/xwiki.js   
> 2009-03-03 22:40:14 UTC (rev 17211)
> - * Add click listeners on all rendering errors (new rendering engine) to let 
> users expands error messages to read technical information.
> + * Build a resource object from a wiki resource descriptor (aka fullName).
> + *
> + * Examples of resource objects:

----
> + * { wiki: "xwiki", space: "Main", prefixedSpace: "xwiki:Main", 
> + *   fullName: "Main.WebHome", prefixedFullName: "xwiki:Main.WebHome", 
> + *   name: "WebHome", attachment: "" }
> + * { wiki: "xwiki", space: "Main", prefixedSpace: "xwiki:Main", 
> + *   fullName: "Main.WebHome", prefixedFullName: "xwiki:Main.WebHome", 
> + *   name: "WebHome", attachment: "" }
----
These two are identical.

> + * { wiki: "xwiki", space: "Main", prefixedSpace: "xwiki:Main", 
> + *   fullName: "Main.WebHome", prefixedFullName: "xwiki:Main.WebHome", 
> + *   name: "WebHome", attachment: "attach.zip" }
> + *
> + * @param fullName fullName of the resource to create (examples: 
> xwiki:Main.WebHome, xwiki:[email protected]).
> + * @return the newly created resource object.
>   */


Why did this one disappear?
> -document.observe("dom:loaded", function() {
> -   $$('[class="xwikirenderingerror"]').each(function(error) {
> -      if(error.nextSibling.innerHTML !== "" 
> -        && error.nextSibling.hasClassName("xwikirenderingerrordescription")) 
> {
> -         error.style.cursor="pointer";
> -         error.title = 
> "$msg.get('platform.core.rendering.error.readTechnicalInfomation')";
> -         Event.observe(error, "click", function(event){
> -            toggleClass(event.element().nextSibling,'hidden');
> -         });
> -      }
> -   });
> -});


This method is a bit too long, suggesting refactoring. Also, we don't 
use tabs...
> +getResource : function(fullName) {    
> +     var resource = {
> +                     wiki : "",
> +                     space : "",
> +                     prefixedSpace : "",
> +                     fullName : fullName,
> +                     prefixedFullName : "",
> +                     name : "",
> +                     attachment : "",
> +                     anchor: ""
> +     }; 
>  
> +     // Extract wiki and set prefixedFullName.
> +     if (fullName.contains(this.constants.wikiSpaceSeparator)) {
> +             resource.wiki = fullName.substring(0, 
> fullName.indexOf(this.constants.wikiSpaceSeparator));
> +             // Remove wiki from fullName.
> +             resource.fullName = 
> fullName.substring(fullName.indexOf(this.constants.wikiSpaceSeparator) + 1, 
> fullName.length);
> +             resource.prefixedFullName = fullName;   
> +     } else if (fullName.contains(this.constants.spacePageSeparator)) {      
> +             // Fallback on current wiki.
> +             resource.wiki = this.constants.currentWiki;
> +             resource.prefixedFullName = resource.wiki + 
> this.constants.wikiSpaceSeparator + fullName;
> +     }               
> +     
> +     // Extract attachment and remove it from fullName and prefixedFullName 
> if any.
> +     if (resource.fullName.contains(this.constants.pageAttachmentSeparator)) 
> {
> +             resource.fullName = resource.fullName.substring(0, 
> resource.fullName.indexOf(this.constants.pageAttachmentSeparator));
> +             resource.prefixedFullName = 
> resource.prefixedFullName.substring(0, 
> resource.prefixedFullName.indexOf(this.constants.pageAttachmentSeparator));
> +     }       
> +     
> +     // Extract anchor and remove it from fullName and prefixedFullName if 
> any.
> +     if (resource.fullName.contains(this.constants.anchorSeparator)) {
> +             resource.anchor = 
> resource.fullName.substring(resource.fullName.indexOf(this.constants.anchorSeparator)
>  + 1, resource.fullName.length);
> +             resource.fullName = resource.fullName.substring(0, 
> resource.fullName.indexOf(this.constants.anchorSeparator));
> +             resource.prefixedFullName = 
> resource.prefixedFullName.substring(0, 
> resource.prefixedFullName.indexOf(this.constants.anchorSeparator));
> +     }
> +
> +     // Extract space and page name.
> +     if (fullName.contains(this.constants.spacePageSeparator)) {
> +             // Space
> +             resource.space = 
> fullName.substring(fullName.indexOf(this.constants.wikiSpaceSeparator) + 1, 
> fullName.indexOf(this.constants.spacePageSeparator));
> +             resource.prefixedSpace = resource.wiki + 
> this.constants.wikiSpaceSeparator + resource.space;
> +             if (fullName.length - 
> fullName.indexOf(this.constants.spacePageSeparator) > 0) {        
> +                     if 
> (!fullName.contains(this.constants.pageAttachmentSeparator)) {
> +                             // Page name.
> +                             resource.name = 
> fullName.substring(fullName.indexOf(this.constants.spacePageSeparator) + 1, 
> fullName.length);          
> +                     } else {
> +                             // Page name.
> +                             resource.name = 
> fullName.substring(fullName.indexOf(this.constants.spacePageSeparator) + 1, 
> fullName.indexOf(this.constants.pageAttachmentSeparator));          
> +                             if (fullName.length - 
> fullName.indexOf(this.constants.pageAttachmentSeparator) > 0) {   
> +                                     // Attachment name.
> +                                     resource.attachment = 
> fullName.substring(fullName.indexOf(this.constants.pageAttachmentSeparator) + 
> 1, fullName.length);  
> +                             }
> +                     }
> +
> +             }
> +     }
> +     
> +     return resource;
> +}                            
> +};
> +
>  /**
>   * Hide the fieldset inside the given form. 
>   *
> 
> Added: 
> platform/web/trunk/standard/src/main/webapp/resources/js/xwiki/xwikiexplorer/xwikiexplorer.js
> ===================================================================
> --- 
> platform/web/trunk/standard/src/main/webapp/resources/js/xwiki/xwikiexplorer/xwikiexplorer.js
>                              (rev 0)
> +++ 
> platform/web/trunk/standard/src/main/webapp/resources/js/xwiki/xwikiexplorer/xwikiexplorer.js
>      2009-03-03 22:40:14 UTC (rev 17211)
> @@ -0,0 +1,742 @@


Our standard header notice would be nice...
> +/**
> + * XWiki Explorer widget for smartClient.
> + */
> +
> +if (typeof XWiki == "undefined") {
> +  alert("ERROR: xwikiexplorer.js depends on xwiki.js");

Just alert? This is critical, the rest of the code should be on an else, 
or throw an error instead.

> +}
> + 
> +XWiki.xwikiExplorer = {
> +             
> +  /**
> +   * Base URI for XWiki REST service.
> +   */
> +  baseRestURI : XWiki.constants.contextPath + "/rest/",
> +    

It would be nice to have these URLs valid in the future.

> +  /**
> +   * REST children relationship.
> +   */ 
> +  restChildrenRel: "http://www.xwiki.org/rel/children";,
> +  
> +  /**
> +   * REST children relationship.
> +   */ 
> +  restParentRel: "http://www.xwiki.org/rel/parent";,
> +  
> +  /**
> +   * REST attachments relationship.
> +   */ 
> +  restAttachmentsRel: "http://www.xwiki.org/rel/attachments";,
> +  
> +  /**
> +   * REST home relationship.
> +   */ 
> +  restHomeRel: "http://www.xwiki.org/rel/home";,
> +  
> +  /**
> +   * A set of callbacks fired by several smartClient classes (callback 
> handlers are injected by XWiki.smartClient).
> +   */  
> +  callbacks : {
> +    // XWikiExplorerResultTree.dataArrived

More unwanted tabs here:
> +     dataArrived : new Array(),
> +     // DataSource.transformResponse
> +     transformResponse : new Array()
> +  },
> +
> +  /** 
> +   * Create a SmartClient class extending isc.ResultTree to allow:
> +   * Dynamic DS instantiation.
> +   * Custom icon per entry type without having any icon field in the REST 
> response.
> +   */
> +  createXWikiExplorerResultTreeClass : function() {
> +     
> +    /*
> +     * XWikiExplorerResultTree class overriding default ResultTree class.
> +     * Used by xwikiExplorer DataSources. 
> +     */
> +    isc.ClassFactory.defineClass("XWikiExplorerResultTree", isc.ResultTree);
> +    isc.XWikiExplorerResultTree.addMethods({
> + 
> +      /** 
> +       * Override isc.ResultTree.getChildDataSource     
> +       */ 
> +      getChildDataSource : function (node, nodeDS) {              
> +        // look for explicitly specified child type 
> +        var childDSName = node[this.childTypeProperty];

It is a good practice to always use {} around blocks, even if it's just 
one line.
> +        if (childDSName != null) 
> +          return isc.DS.get(childDSName);



-- 
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to