Commit e3398b89ab6e1b4fbdbe33e1fba05e4a8af7068f

Authored by Victor Costa
2 parents c91c7131 f968d787

Merge branch 'AI3074-community_dashboard' of gitlab.com:participa/noosfero into …

…AI3074-community_dashboard
lib/community_hub_plugin/hub.rb
@@ -18,6 +18,10 @@ class CommunityHubPlugin::Hub < Folder @@ -18,6 +18,10 @@ class CommunityHubPlugin::Hub < Folder
18 hub.mediators = [hub.author.id] 18 hub.mediators = [hub.author.id]
19 end 19 end
20 20
  21 + def notify_comments
  22 + false
  23 + end
  24 +
21 def self.icon_name(article = nil) 25 def self.icon_name(article = nil)
22 'community-hub' 26 'community-hub'
23 end 27 end
public/javascripts/community_hub.js
@@ -2,39 +2,66 @@ var latest_post_id = 0; @@ -2,39 +2,66 @@ var latest_post_id = 0;
2 var oldest_post_id = 0; 2 var oldest_post_id = 0;
3 live_scroll_position = 0; 3 live_scroll_position = 0;
4 4
  5 +function clearLoadingMediationCommentSignal(mediation) {
  6 + jQuery(".loading-mediation-comment").filter("#" + mediation).removeClass("loading-signal-error");
  7 + jQuery(".loading-mediation-comment").filter("#" + mediation).removeClass("loading-signal-done");
  8 +}
  9 +
  10 +function clearLoadingMessageSignal() {
  11 + jQuery("#loading-message").removeClass("loading-signal-error");
  12 + jQuery("#loading-message").removeClass("loading-signal-done");
  13 +}
  14 +
  15 +function clearLoadingMediationSignal() {
  16 + jQuery("#loading-mediation").removeClass("loading-signal-error");
  17 + jQuery("#loading-mediation").removeClass("loading-signal-done");
  18 +}
  19 +
5 function toogle_mediation_comments(mediation) { 20 function toogle_mediation_comments(mediation) {
6 jQuery("#mediation-comment-list-" + mediation ).toggle(); 21 jQuery("#mediation-comment-list-" + mediation ).toggle();
7 jQuery("#mediation-comment-form-" + mediation ).toggle(); 22 jQuery("#mediation-comment-form-" + mediation ).toggle();
8 } 23 }
9 24
10 25
11 -function hub_open_loading(button) {  
12 - var html = '<div id="hub-loading">' +  
13 - '<img src="/images/loading-small.gif" />' +  
14 - '</div>'; 26 +function new_mediation_comment(button, mediation) {
  27 + var form = jQuery(button).parents("form");
15 28
16 - //$('.hub .form .submit').after(html);  
17 - jQuery(button).after(html);  
18 - jQuery('#hub-loading').fadeIn('slow');  
19 -} 29 + jQuery(".loading-mediation-comment").filter("#" + mediation).addClass("loading-signal-processing");
20 30
  31 + jQuery.post(form.attr("action"), form.serialize(), function(data) {
  32 + jQuery(".loading-mediation-comment").filter("#" + mediation).removeClass("loading-signal-processing");
  33 + if (data.ok) {
  34 + jQuery("#mediation-comment-form-" + mediation + " textarea").val('');
  35 + jQuery(".loading-mediation-comment").filter("#" + mediation).addClass("loading-signal-done");
  36 + setTimeout(function(){
  37 + clearLoadingMediationCommentSignal(mediation);
  38 + }, 3000);
  39 + }
  40 + else {
  41 + jQuery(".loading-mediation-comment").filter("#" + mediation).addClass("loading-signal-error");
  42 + setTimeout(clearLoadingMessageSignal, 3000);
  43 + }
  44 + }, 'json');
21 45
22 -function hub_close_loading() {  
23 - jQuery('#hub-loading').fadeOut('slow', function() {  
24 - jQuery('#hub-loading').remove();  
25 - });  
26 } 46 }
27 47
28 48
29 function new_message(button) { 49 function new_message(button) {
30 var form = jQuery(button).parents("form"); 50 var form = jQuery(button).parents("form");
31 51
32 - //hub_open_loading(); 52 + jQuery("#loading-message").addClass("loading-signal-processing");
  53 +
33 jQuery.post(form.attr("action"), form.serialize(), function(data) { 54 jQuery.post(form.attr("action"), form.serialize(), function(data) {
  55 + jQuery("#loading-message").removeClass("loading-signal-processing");
34 if (data.ok) { 56 if (data.ok) {
35 - jQuery("#message_body").val(''); 57 + jQuery(".hub .form #message_body").val('');
  58 + jQuery("#loading-message").addClass("loading-signal-done");
  59 + setTimeout(clearLoadingMessageSignal, 3000);
  60 + }
  61 + else {
  62 + jQuery("#loading-message").addClass("loading-signal-error");
  63 + setTimeout(clearLoadingMessageSignal, 3000);
36 } 64 }
37 - //hub_close_loading();  
38 }, 'json'); 65 }, 'json');
39 66
40 } 67 }
@@ -43,23 +70,25 @@ function new_message(button) { @@ -43,23 +70,25 @@ function new_message(button) {
43 function new_mediation(button) { 70 function new_mediation(button) {
44 var form = jQuery(button).parents("form"); 71 var form = jQuery(button).parents("form");
45 72
46 - //hub_open_loading(); 73 + jQuery("#loading-mediation").addClass("loading-signal-processing");
  74 +
47 tinymce.triggerSave(); 75 tinymce.triggerSave();
48 jQuery.post(form.attr("action"), form.serialize(), function(data) { 76 jQuery.post(form.attr("action"), form.serialize(), function(data) {
  77 + jQuery("#loading-mediation").removeClass("loading-signal-processing");
49 if (data.ok) { 78 if (data.ok) {
  79 + jQuery("#loading-mediation").addClass("loading-signal-done");
50 tinymce.get('article_body').setContent(''); 80 tinymce.get('article_body').setContent('');
  81 + setTimeout(clearLoadingMediationSignal, 3000);
  82 + }
  83 + else {
  84 + jQuery("#loading-mediation").addClass("loading-signal-error");
  85 + setTimeout(clearLoadingMediationSignal, 3000);
51 } 86 }
52 - //hub_close_loading();  
53 }, 'json'); 87 }, 'json');
54 88
55 } 89 }
56 90
57 91
58 -function toogleAutoScrolling() {  
59 - alert(jQuery("#auto_scrolling").attr('checked'));  
60 -}  
61 -  
62 -  
63 function promote_user(user_id) { 92 function promote_user(user_id) {
64 93
65 var hub_id = jQuery(".hub").attr('id'); 94 var hub_id = jQuery(".hub").attr('id');
@@ -88,7 +117,7 @@ function pin_message(post_id) { @@ -88,7 +117,7 @@ function pin_message(post_id) {
88 type: 'get', 117 type: 'get',
89 dataType: 'json', 118 dataType: 'json',
90 data: { message: post_id, hub: hub_id }, 119 data: { message: post_id, hub: hub_id },
91 - success: function(data) { 120 + success: function(data) {
92 }, 121 },
93 error: function(ajax, stat, errorThrown) { 122 error: function(ajax, stat, errorThrown) {
94 console.log(stat); 123 console.log(stat);
@@ -108,8 +137,6 @@ function update_mediation_comments(mediation) { @@ -108,8 +137,6 @@ function update_mediation_comments(mediation) {
108 var latest_post_id = jQuery("#mediation-comment-list-" + mediation + " li.mediation-comment").last().attr('id'); 137 var latest_post_id = jQuery("#mediation-comment-list-" + mediation + " li.mediation-comment").last().attr('id');
109 } 138 }
110 139
111 - //console.log(latest_post_id);  
112 -  
113 jQuery.ajax({ 140 jQuery.ajax({
114 url: '/plugin/community_hub/public/newer_mediation_comment', 141 url: '/plugin/community_hub/public/newer_mediation_comment',
115 type: 'get', 142 type: 'get',
@@ -117,6 +144,7 @@ function update_mediation_comments(mediation) { @@ -117,6 +144,7 @@ function update_mediation_comments(mediation) {
117 success: function(data) { 144 success: function(data) {
118 if (data.trim().length > 0) { 145 if (data.trim().length > 0) {
119 jQuery("#mediation-comment-list-" + mediation + "").append(data); 146 jQuery("#mediation-comment-list-" + mediation + "").append(data);
  147 + jQuery("#mediation-comment-total-" + mediation).html(jQuery("#mediation-comment-list-" + mediation + " li.mediation-comment").size());
120 } 148 }
121 }, 149 },
122 error: function(ajax, stat, errorThrown) { 150 error: function(ajax, stat, errorThrown) {
@@ -201,4 +229,4 @@ jQuery(document).ready(function() { @@ -201,4 +229,4 @@ jQuery(document).ready(function() {
201 229
202 setTimeout(update_live_stream, 5000); 230 setTimeout(update_live_stream, 5000);
203 setTimeout(update_mediations, 7000); 231 setTimeout(update_mediations, 7000);
204 -});  
205 \ No newline at end of file 232 \ No newline at end of file
  233 +});
public/style.css
@@ -78,7 +78,7 @@ clear: both; @@ -78,7 +78,7 @@ clear: both;
78 font-weight: bold; 78 font-weight: bold;
79 float: left; 79 float: left;
80 display: inline-block; 80 display: inline-block;
81 - line-height: 20px; 81 + line-height: 16px;
82 margin-right: 5px; 82 margin-right: 5px;
83 } 83 }
84 84
@@ -107,6 +107,7 @@ clear: both; @@ -107,6 +107,7 @@ clear: both;
107 107
108 .hub .mediation-bar ul li.pin{ 108 .hub .mediation-bar ul li.pin{
109 height: 25px; 109 height: 25px;
  110 + margin-right: 10px;
110 } 111 }
111 112
112 .hub .remove{} 113 .hub .remove{}
@@ -153,6 +154,19 @@ clear: both; @@ -153,6 +154,19 @@ clear: both;
153 margin-bottom: 2px; 154 margin-bottom: 2px;
154 } 155 }
155 156
  157 +.hub .mediation-comment-form {
  158 + margin-left: 70px;
  159 + margin-top: 10px;
  160 +}
  161 +
  162 +.hub input.button.with-text.icon-add.submit{
  163 + display: block;
  164 +}
  165 +
  166 +.hub ul#mediation-posts .post {
  167 + padding-bottom: 10px;
  168 +}
  169 +
156 /**/ 170 /**/
157 171
158 .hub .live { 172 .hub .live {
@@ -367,3 +381,35 @@ textarea#message_body { @@ -367,3 +381,35 @@ textarea#message_body {
367 width: 80%; 381 width: 80%;
368 } 382 }
369 383
  384 +.hub #loading-message,
  385 +.hub #loading-mediation {
  386 + width: 16px;
  387 + height: 16px;
  388 + display: inline-block;
  389 + float: right;
  390 + margin-top: 17px;
  391 + margin-right: 270px;
  392 +}
  393 +
  394 +.hub .loading-mediation-comment {
  395 + width: 16px;
  396 + height: 16px;
  397 + display: inline-block;
  398 + float: right;
  399 + margin-top: 16px;
  400 + margin-right: 260px;
  401 +}
  402 +
  403 +.loading-signal-done {
  404 + background-image: url(/plugins/community_hub/icons/hub-sverde-a.png);
  405 +}
  406 +
  407 +.loading-signal-error {
  408 + background-image: url(/plugins/community_hub/icons/hub-svermelho-a.png);
  409 +}
  410 +
  411 +.loading-signal-processing {
  412 + background-image: url(/plugins/community_hub/icons/hub-samarelo.gif);
  413 +}
  414 +
  415 +
views/community_hub_plugin_public/_mediation.rhtml
@@ -6,25 +6,25 @@ @@ -6,25 +6,25 @@
6 <li class="time"><%= post_time(mediation.created_at) %></li> 6 <li class="time"><%= post_time(mediation.created_at) %></li>
7 <li class="avatar"><%= image_tag(profile_icon(mediation.author, :minor)) %></li> 7 <li class="avatar"><%= image_tag(profile_icon(mediation.author, :minor)) %></li>
8 <li class="message"><span class="author"><%= mediation.author_name %>:</span> <%= mediation.body %></li> 8 <li class="message"><span class="author"><%= mediation.author_name %>:</span> <%= mediation.body %></li>
9 - 9 +
10 <% if mediator?(hub) %> 10 <% if mediator?(hub) %>
11 <li class="mediation-bar"> 11 <li class="mediation-bar">
12 12
13 <ul> 13 <ul>
14 - 14 +
15 <li class="promote"> 15 <li class="promote">
16 - <% if !promoted?(hub, mediation.author.id) %> 16 + <% if promoted?(hub, mediation.author.id) %>
17 <a id="<%= mediation.id %>" href="#" onclick="promote_user(<%= mediation.author.id %>); return false;"> 17 <a id="<%= mediation.id %>" href="#" onclick="promote_user(<%= mediation.author.id %>); return false;">
18 - <img class="promoted" src="/plugins/community_hub/icons/hub-promote-icon.png" /> 18 + <img class="promoted" src="/plugins/community_hub/icons/hub-promote-icon.png" title="<%= _("User promoted") %>" />
19 </a> 19 </a>
20 <% else %> 20 <% else %>
21 - <img class="not-promoted" src="/plugins/community_hub/icons/hub-not-promote-icon.png" /> 21 + <img class="not-promoted" src="/plugins/community_hub/icons/hub-not-promote-icon.png" title="<%= _("User not promoted") %>" />
22 <% end %> 22 <% end %>
23 </li> 23 </li>
24 24
25 <% if pinned_mediation?(hub, mediation.id) %> 25 <% if pinned_mediation?(hub, mediation.id) %>
26 <li class="pin"> 26 <li class="pin">
27 - <img class="pinned" src="/plugins/community_hub/icons/hub-not-pinned-icon.png" /> 27 + <img class="pinned" src="/plugins/community_hub/icons/hub-not-pinned-icon.png" title="<%= _("Message pinned")%>" />
28 </li> 28 </li>
29 <% end %> 29 <% end %>
30 30
@@ -38,16 +38,16 @@ @@ -38,16 +38,16 @@
38 <% total_mediation_comments = mediation.comments.count %> 38 <% total_mediation_comments = mediation.comments.count %>
39 39
40 <span class="comment-count"> 40 <span class="comment-count">
41 - <%= link_to(_( "#{total_mediation_comments} Comments" ) , '#',  
42 - :class => 'display-comment-form',  
43 - :id => 'top-post-comment-button', 41 + <%= link_to(_( "<span id='mediation-comment-total-#{mediation.id}'>#{total_mediation_comments}</span> Comments" ) , '#',
  42 + :class => 'display-comment-form',
  43 + :id => 'top-post-comment-button',
44 :onclick => "toogle_mediation_comments(#{mediation.id}); return false;") %> 44 :onclick => "toogle_mediation_comments(#{mediation.id}); return false;") %>
45 </span> 45 </span>
46 46
47 <script type="text/javascript"> 47 <script type="text/javascript">
48 setTimeout(function() { update_mediation_comments('<%= mediation.id %>')}, 5000); 48 setTimeout(function() { update_mediation_comments('<%= mediation.id %>')}, 5000);
49 </script> 49 </script>
50 - 50 +
51 <ul id="mediation-comment-list-<%=mediation.id%>" class="mediation-comment-list" style="display:none;"> 51 <ul id="mediation-comment-list-<%=mediation.id%>" class="mediation-comment-list" style="display:none;">
52 <% if mediation.accept_comments? && mediation.comments.count > 0 %> 52 <% if mediation.accept_comments? && mediation.comments.count > 0 %>
53 <%= render :partial => 'community_hub_plugin_public/mediation_comment', :collection => mediation.comments %> 53 <%= render :partial => 'community_hub_plugin_public/mediation_comment', :collection => mediation.comments %>
@@ -60,15 +60,15 @@ @@ -60,15 +60,15 @@
60 :locals => { 60 :locals => {
61 :hub => hub, 61 :hub => hub,
62 :mediation => mediation, 62 :mediation => mediation,
63 - :comment => Comment.new, 63 + :comment => Comment.new,
64 :url => { 64 :url => {
65 - :controller => :comment, 65 + :controller => :comment,
66 :action => :create 66 :action => :create
67 - },  
68 - :display_link => true, 67 + },
  68 + :display_link => true,
69 :cancel_triggers_hide => true 69 :cancel_triggers_hide => true
70 } %> 70 } %>
71 </div> 71 </div>
72 <% end %> 72 <% end %>
73 73
74 -</li>  
75 \ No newline at end of file 74 \ No newline at end of file
  75 +</li>
views/community_hub_plugin_public/_mediation_comment_form.rhtml
@@ -8,5 +8,6 @@ @@ -8,5 +8,6 @@
8 <%= f.text_area(:body, 8 <%= f.text_area(:body,
9 :rows => 4, 9 :rows => 4,
10 :placeholder => _('Type your comment here')) %> 10 :placeholder => _('Type your comment here')) %>
11 - <%= submit_button('add', _('Post'), :onclick => 'new_message(this); return false;') %>  
12 -<% end %>  
13 \ No newline at end of file 11 \ No newline at end of file
  12 + <%= submit_button('add', _('Post'), :onclick => "new_mediation_comment(this,#{mediation.id}); return false;") %>
  13 + <span id="<%=mediation.id%>" class="loading-mediation-comment"></span>
  14 +<% end %>
views/community_hub_plugin_public/_post.rhtml
@@ -16,17 +16,7 @@ @@ -16,17 +16,7 @@
16 16
17 <% if mediator?(hub) && post.title != 'hub-message-twitter' && post.title != 'hub-message-facebook' %> 17 <% if mediator?(hub) && post.title != 'hub-message-twitter' && post.title != 'hub-message-facebook' %>
18 <li class="mediation-bar"> 18 <li class="mediation-bar">
19 -  
20 <ul> 19 <ul>
21 - <li class="promote">  
22 - <% if promoted?(hub, post.author.id) == 'promoted' %>  
23 - <a id="<%= post.id %>" href="#" onclick="pin_message(<%= post.id %>); return false;">  
24 - <img class="promoted" src="/plugins/community_hub/icons/hub-promote-icon.png" />  
25 - </a>  
26 - <% else %>  
27 - <img class="not-promoted" src="/plugins/community_hub/icons/hub-not-promote-icon.png" />  
28 - <% end %>  
29 - </li>  
30 <li class="pin"> 20 <li class="pin">
31 <% if !pinned_message?(hub, post.id) %> 21 <% if !pinned_message?(hub, post.id) %>
32 <a id="<%= post.id %>" href="#" onclick="pin_message(<%= post.id %>); return false;"> 22 <a id="<%= post.id %>" href="#" onclick="pin_message(<%= post.id %>); return false;">
@@ -37,7 +27,6 @@ @@ -37,7 +27,6 @@
37 <% end %> 27 <% end %>
38 </li> 28 </li>
39 </ul> 29 </ul>
40 -  
41 </li> 30 </li>
42 <% end %> 31 <% end %>
43 32
views/content_viewer/hub.rhtml
@@ -43,6 +43,7 @@ @@ -43,6 +43,7 @@
43 <br /> 43 <br />
44 <%= f.text_area :body, :style => "width: 99%;", :cols => "38", :rows => "10", :placeholder => _("Type your message here") %> 44 <%= f.text_area :body, :style => "width: 99%;", :cols => "38", :rows => "10", :placeholder => _("Type your message here") %>
45 <%= submit_button('add', _('Post'), :onclick => 'new_message(this); return false;') %> 45 <%= submit_button('add', _('Post'), :onclick => 'new_message(this); return false;') %>
  46 + <span id="loading-message"></span>
46 <% end %> 47 <% end %>
47 48
48 <% else %> 49 <% else %>
@@ -59,6 +60,7 @@ @@ -59,6 +60,7 @@
59 <%= f.hidden_field :parent_id, :value => @page.id %> 60 <%= f.hidden_field :parent_id, :value => @page.id %>
60 <%= f.text_area :body, :style => "width: 100%;", :class => "mceEditor" %> 61 <%= f.text_area :body, :style => "width: 100%;", :class => "mceEditor" %>
61 <%= submit_button('add', _('Post'), :onclick => 'new_mediation(this); return false;') %> 62 <%= submit_button('add', _('Post'), :onclick => 'new_mediation(this); return false;') %>
  63 + <span id="loading-mediation"></span>
62 <% end %> 64 <% end %>
63 65
64 <% end %> 66 <% end %>