Changes for page MentionsMacro


on 2022-03-20 10:03


on 2020-08-01 04:53
Summary
Details
- XWiki.JavaScriptExtension[0]
-
- Code
-
... ... @@ -1,15 +1,16 @@ 1 1 require.config({ 2 2 paths: { 3 - 'xwiki-suggestUsers': $jsontool.serialize($xwiki.getSkinFile('uicomponents/suggest/suggestUsersAndGroups.js', true)) 3 + 'xwiki-suggestUsers': "$xwiki.getSkinFile('uicomponents/suggest/suggestUsersAndGroups.js', true))" + 4 + "?v=$escapetool.url($xwiki.version)" 4 4 } 5 5 }); 6 6 require(['deferred!ckeditor', 'xwiki-suggestUsers', 'jquery', 'xwiki-meta'], function (ckeditorPromise, suggestUsers, $, xm) { 7 - 8 + 8 8 /** 9 9 * Get the current wiki scope for displaying global, local or global and local users 10 10 */ 11 11 const userScope = "$!services.wiki.user.userScope"; 12 - 13 + 13 13 // see https://stackoverflow.com/a/6248722/657524 14 14 function random6chars() { 15 15 // I generate the UID from two parts here ... ... @@ -20,7 +20,7 @@ 20 20 secondPart = ("000" + secondPart.toString(36)).slice(-3); 21 21 return firstPart + secondPart; 22 22 } 23 - 24 + 24 24 /** 25 25 * Compute a new unique anchor for the given reference. 26 26 * The unique anchor is based on the mentionned user id, concatenaed with a random string of 6 alphanumeric ... ... @@ -39,8 +39,8 @@ 39 39 'input': text, 40 40 'limit': 6, 41 41 }; 42 - suggestUsers.loadUsers(userScope, params).then(user s=>{43 - const cct = user s.map(function (x) {43 + $.when(suggestUsers.loadUsers(userScope, params)).then(function (user) { 44 + const cct = user.map(function (x) { 44 44 // insert an id because that's required by the mentions plugins. 45 45 x.id = x.value; 46 46 // Make sure to display the icon avatar or the image one. ... ... @@ -56,10 +56,10 @@ 56 56 return x; 57 57 }); 58 58 callback(cct); 59 - }) ;60 + }) 60 60 } 61 61 62 - ckeditorPromise. then(ckeditor=>{63 + ckeditorPromise.done(function (ckeditor) { 63 63 function confMentions(name) { 64 64 return { 65 65 feed: function (opts, callback) { ... ... @@ -79,14 +79,22 @@ 79 79 '</li>', 80 80 outputTemplate: function (param) { 81 81 var editor = ckeditor.instances[name]; 83 + var currentWikiReference = xm.documentReference.extractReference(XWiki.EntityType.WIKI); 84 + 85 + // Compute an absolute reference containing the wiki reference even if the user is local. 86 + var documentReference = XWiki.Model.resolve(param.id, XWiki.EntityType.DOCUMENT); 87 + if (!documentReference.extractReference(XWiki.EntityType.WIKI)) { 88 + documentReference = documentReference.appendParent(currentWikiReference); 89 + } 90 + var serializedReference = XWiki.Model.serialize(documentReference); 82 82 editor.once('afterInsertHtml', function () { 83 83 editor.execCommand('xwiki-macro-insert', { 84 84 name: 'mention', 85 - inline: 'enforce',94 + inline: true, 86 86 parameters: { 87 - reference: param.id,96 + reference: serializedReference, 88 88 style: 'FULL_NAME', 89 - anchor: getAnchor( param.id)98 + anchor: getAnchor(serializedReference) 90 90 } 91 91 }); 92 92 }); ... ... @@ -98,7 +98,7 @@ 98 98 } 99 99 100 100 function updateConf(config, name) { 101 - const newConf = config || {};110 + const newConf = config; 102 102 newConf.mentions = newConf.mentions || []; 103 103 newConf.mentions.push(confMentions(name)); 104 104 return newConf; ... ... @@ -115,3 +115,4 @@ 115 115 }; 116 116 }); 117 117 }); 127 +
- XWiki.WikiMacroClass[0]
-
- Macro code
-
... ... @@ -1,10 +1,9 @@ 1 1 {{velocity}} 2 2 #set ($reference = $wikimacro.parameters.reference) 3 3 #set ($style = $wikimacro.parameters.style) 4 -#set ($type = "$!wikimacro.parameters.type") 5 -#set ($content = $services.mentions.format($reference.reference, $style, $type)) 4 +#set ($content = $services.mentions.format($reference.reference, $style)) 6 6 #set ($anchor = $wikimacro.parameters.anchor) 7 -#set ($isCurrentUser = $xcontext.userReference == $reference.reference && ($type == '' || $type == 'user'))6 +#set ($isCurrentUser = $xcontext.userReference == $reference.reference) 8 8 #set ($cssClasses = ['xwiki-mention', 'user']) 9 9 #if ($isCurrentUser) 10 10 #set ($discard = $cssClasses.add('self')) - Default category
-
... ... @@ -1,1 +1,0 @@ 1 -Notifications - Macro description
-
... ... @@ -1,1 +1,1 @@ 1 -Insert sa user mention.1 +Insert a user mention.
- XWiki.WikiMacroParameterClass[3]
-
- Parameter description
-
... ... @@ -1,1 +1,0 @@ 1 -The type of mentioned actor. - Parameter name
-
... ... @@ -1,1 +1,0 @@ 1 -type - Parameter type
-
... ... @@ -1,1 +1,0 @@ 1 -java.lang.String