+1

Another option could be to pass a JSON serialization of the reference.
Thomas has recently fixed some issues that were preventing JSON
serialization of an entity reference. It should work fine now:

$jsontool.serialize($documentReference)

should produce something close to:

{
  name: 'Page',
  type: 'DOCUMENT',
  parent: {
    name: 'Space2',
    type: 'SPACE',
    parent: {
      ...
    }
  }
}

It's more verbose obviously. For this we need to modify a bit
entityReference.js though, because it expects the entity type to be an
int.

Thanks,
Marius

On Wed, Jul 29, 2015 at 4:34 PM, [email protected] <[email protected]> wrote:
> Hi devs,
>
> In the past we use to pass the wiki, space and page as 3 variables to JS 
> code. For example in dashboard.js we currently have:
>
>     this.sourcePage = this.element.down('.metadata .sourcepage').innerHTML;
>     this.sourceSpace = this.element.down('.metadata .sourcespace').innerHTML;
>     this.sourceWiki = this.element.down('.metadata .sourcewiki').innerHTML;
>
> Now that we need to handle Nested Spaces, it’s more complex and I’m proposing 
> to change our best practice and instead to pass a full reference, as in:
>
>     this.sourceReference = XWiki.Model.resolve(this.element.down('.metadata 
> .source').innerHTML, XWiki.EntityType.DOCUMENT);
>
> More generally the idea would be to do the same as we do in Java code, i.e. 
> to start stopping passing several parameters to functions and instead to use 
> XWiki.EntityReference (or XWiki.DocumentReference, etc).
>
> For example for dashboard.js this allows to replace:
>
>       var link = new Element('a', {'href' : this.sourceURL});
>       link.update(this.sourceWiki + ':' + this.sourceSpace + '.' + 
> this.sourcePage);
>
> With:
>
>       var link = new Element('a', {'href' : this.sourceURL});
>       link.update(XWiki.Model.serialize(this.sourceReference));
>
> WDYT?
>
> Thanks
> -Vincent
>
>
> _______________________________________________
> devs mailing list
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to