Changes for page XWiki JavaScript API
Last modified by Simon Urli on 2024/09/24
From version 30.1
edited by Guillaume Delhumeau
on 2015/05/28
on 2015/05/28
Change comment:
There is no comment for this version
To version 31.1
edited by Marius Dumitru Florea
on 2015/07/16
on 2015/07/16
Change comment:
There is no comment for this version
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. gdelhumeau1 +XWiki.mflorea - Content
-
... ... @@ -231,3 +231,49 @@ 231 231 var form_token = xm ? xm.form_token : $('meta[name="form_token"]').attr('content'); 232 232 }); 233 233 {{/code}} 234 + 235 += Work with Entity References = 236 + 237 +Starting with XWiki 4.2M1 you can resolve and serialize Entity References on the client side easily: 238 + 239 +{{code language="js"}} 240 +var documentReference = XWiki.Model.resolve('wiki:Space.Page', XWiki.EntityType.DOCUMENT); 241 +var attachmentReference = new XWiki.AttachmentReference('logo.png', documentReference); 242 +XWiki.Model.serialize(attachmentReference); 243 +{{/code}} 244 + 245 +You can check the full API [[here>>https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-web/src/main/webapp/resources/uicomponents/model/entityReference.js]]. 246 + 247 +Starting with XWiki 7.2M1 the {{XWiki.Model}} JavaScript API is supporting nested spaces: 248 + 249 +{{code language="js"}} 250 +var documentReference = XWiki.Model.resolve('wiki:Path.To.My.Page', XWiki.EntityType.DOCUMENT); 251 +documentReference.getReversedReferenceChain().map(function(entityReference) { 252 + return entityReference.type + ': ' + entityReference.name 253 +}).join() 254 +// Will produce: 255 +// 0: wiki,1: Path,1: To,1: My,2: Page 256 +{{/code}} 257 + 258 +Starting with 7.2M1 you can also pass a 'provider' as the third argument to {{XWiki.Model.resolve}}. The provider is used to fill missing references, and it is either a function that gets the entity type, an array of entity names or an entity reference. 259 + 260 +{{code language="js"}} 261 +var documentReference = XWiki.Model.resolve('Page', XWiki.EntityType.DOCUMENT, function(type) { 262 + switch(type) { 263 + case: XWiki.EntityType.WIKI: 264 + return 'wiki'; 265 + case: XWiki.EntityType.SPACE: 266 + return 'Space'; 267 + default: 268 + return null; 269 + } 270 +}); 271 +// Produces wiki:Space.Page 272 + 273 +var documentReference = XWiki.Model.resolve('Page', XWiki.EntityType.DOCUMENT, ['wiki', 'Space']); 274 +// Same output 275 + 276 +var spaceReference = new XWiki.SpaceReference('wiki', 'Space'); 277 +var documentReference = XWiki.Model.resolve('Page', XWiki.EntityType.DOCUMENT, spaceReference); 278 +// Same output 279 +{{/code}}