Changes for page Message Sender Macro

Last modified by Ludovic Dubost on 2024/07/22 15:51

From version 7.1
edited by Ludovic Dubost
on 2018/12/09 12:24
Change comment: Install extension [org.xwiki.platform:xwiki-platform-messagestream-ui/10.10]
To version 13.1
edited by Ludovic Dubost
on 2022/04/20 17:59
Change comment: Install extension [org.xwiki.platform:xwiki-platform-messagestream-ui/14.0]

Summary

Details

XWiki.JavaScriptExtension[0]
Code
... ... @@ -1,9 +1,10 @@
1 1  var XWiki = (function (XWiki) {
2 2  // Start XWiki augmentation.
3 3  XWiki.MessageStream = Class.create({
4 - initialize : function() {
5 - this.prepareForms();
6 - this.enhanceSelect();
4 + initialize : function(container) {
5 + container = container || $(document.body);
6 + this.prepareForms(container);
7 + this.enhanceSelect(container);
7 7   },
8 8   prepareTargetInput : function(event, element) {
9 9   var targetType = element.options[element.selectedIndex].value;
... ... @@ -30,14 +30,14 @@
30 30   }
31 31   });
32 32   },
33 - enhanceSelect: function () {
34 - $$('.messagestream select[name="visibilityLevel"]').each(function(element) {
34 + enhanceSelect: function (container) {
35 + container.select('.messagestream select[name="visibilityLevel"]').each(function(element) {
35 35   element.observe('change', this.prepareTargetInput.bindAsEventListener(this, element));
36 36   this.prepareTargetInput(null, element);
37 37   }.bind(this));
38 38   },
39 - prepareForms: function() {
40 - $$('.messagestream form').each(function(msForm) {
40 + prepareForms: function(container) {
41 + container.select('.messagestream form').each(function(msForm) {
41 41   msForm.action = msForm.action.replace(/xredirect=.*$/, 'xpage=plain')
42 42   msForm.observe('submit', function(event) {
43 43   event.stop();
... ... @@ -63,12 +63,7 @@
63 63   document.fire('xwiki:activity:newActivity', msForm);
64 64   },
65 65   onFailure: function(response) {
66 - var failureReason = '';
67 - if (response.statusText == '' /* No response */ || response.status == 12031 /* In IE */) {
68 - failureReason = 'Server not responding';
69 - } else {
70 - failureReason = response.statusText;
71 - }
67 + var failureReason = response.statusText || 'Server not responding';
72 72   if (msForm) {
73 73   msForm._disabled = false
74 74   if (msForm._notification) {
... ... @@ -77,9 +77,6 @@
77 77   msForm._notification = new XWiki.widgets.Notification("$services.localization.render('xe.activity.messages.submit.failed'): " + failureReason, 'error');
78 78   }
79 79   },
80 - on1223 : function(response) { /*SUCCESS*/
81 - response.request.options.onSuccess(response);
82 - },
83 83   on0 : function(response) { /*FAILURE*/
84 84   response.request.options.onFailure(response);
85 85   },
... ... @@ -93,11 +93,21 @@
93 93   }
94 94  });
95 95  
96 -var init = function() {
97 - return new XWiki.MessageStream();
89 +var init = function (event) {
90 + var elements = (event && event.memo.elements) || [$(document.body)];
91 + elements.forEach(function(container) {
92 + new XWiki.MessageStream(container);
93 + });
94 + return true;
98 98  };
99 -(XWiki.domIsLoaded && init()) || document.observe('xwiki:dom:loaded', init);
100 100  
97 +// Initialize the message sender macro when the page is loaded.
98 +(XWiki.domIsLoaded && init())
99 +|| document.observe('xwiki:dom:loaded', init);
100 +
101 +// Initialize the message sender macro when it is added after the page is loaded.
102 +document.observe('xwiki:dom:updated', init);
103 +
101 101  // End XWiki augmentation.
102 102  return XWiki;
103 103  }(XWiki || {}));
XWiki.StyleSheetExtension[0]
Code
... ... @@ -1,3 +1,5 @@
1 +#template('colorThemeInit.vm')
2 +
1 1  .messagestream-tools {
2 2   display: flex;
3 3   position: relative;
... ... @@ -10,3 +10,37 @@
10 10   flex-grow: 1;
11 11   margin-left: .3em;
12 12  }
15 +
16 +.messagestream .message-content {
17 + padding: .5em 0 .5em 75px;
18 +}
19 +
20 +.messagestream .activitySnapshot {
21 + height: 30px;
22 + margin: 5px 0 0 -50px;
23 + position: absolute;
24 +}
25 +
26 +.messagestream .activitySnapshot img {
27 + border-radius: 10px 10px 0 10px;
28 + box-shadow: -1px 1px 1px rgba(128,128,128,0.6);
29 +}
30 +
31 +/* User's avatar */
32 +.messagestream .activitySnapshot .avatar {
33 + border-radius: 4px;
34 + box-shadow: 0 0 2px 1px rgba(128,128,128,0.6);
35 +}
36 +
37 +.messagestream .activitySnapshot .activityActionAvatar {
38 + background: $theme.pageContentBackgroundColor;
39 + border-color: $theme.pageContentBackgroundColor;
40 + border-style: solid;
41 + border-width: 4px 1px 1px 3px;
42 + box-sizing: content-box;
43 + bottom: -5px;
44 + height: 16px;
45 + position: absolute;
46 + right: -10px;
47 + width: 16px;
48 +}
Parse content
... ... @@ -1,1 +1,1 @@
1 -No
1 +Yes
XWiki.WikiMacroClass[0]
Macro code
... ... @@ -32,7 +32,6 @@
32 32  ##
33 33  ## Skin Extensions
34 34  ##--------------------------------------------------------------
35 -#set ($discard = $xwiki.ssx.use('Main.Activity'))
36 36  #set ($discard = $xwiki.ssx.use('Main.MessageSenderMacro'))
37 37  #set ($discard = $xwiki.jsx.use('Main.MessageSenderMacro'))
38 38  {{/velocity}}
... ... @@ -111,11 +111,11 @@
111 111   #set ($actionQueryString = "xredirect=$escapetool.url($xredirect)")
112 112   {{html}}
113 113   ## Wrap the form in a div so that the layout is preserved in inline mode (where the form is stripped by the rendering).
114 - <div class='messagestream activityUser xform'>
113 + <div class='messagestream xform'>
115 115   #if (!$inEditMode)
116 116   <form action="${xwiki.getURL('Main.MessageSenderMacro', 'view', $!{actionQueryString})}" method='post'>
117 117   #end
118 - <div class='activityContent'>
117 + <div class='message-content'>
119 119   #if(!$inEditMode)
120 120   ## CSRF prevention
121 121   <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
XWiki.WikiMacroParameterClass[2]
Parameter description
... ... @@ -1,3 +1,3 @@
1 1  Comma separated list of visibility options that the macro should allow the user to choose from.
2 2  
3 -This list should be a sublist of the defualt ones: 'everyone', 'followers', 'group', 'user'.
3 +This list should be a sublist of the default ones: 'everyone', 'followers', 'group', 'user'.