Commit 588fa8ffdf89a11df467981bbcbd726dd0820d41

Authored by Francisco Marcelo de Araújo Lima Júnior
1 parent 0ba0e6e9

#community dashboard - fixes

controllers/public/community_hub_plugin_public_controller.rb
@@ -6,75 +6,82 @@ class CommunityHubPluginPublicController < PublicController @@ -6,75 +6,82 @@ class CommunityHubPluginPublicController < PublicController
6 6
7 7
8 def new_message 8 def new_message
9 - article = Article.find(params[:article_id]) 9 + if logged_in?
  10 +
  11 + begin
  12 + hub = Article.find(params[:article_id])
  13 + rescue
  14 + hub = nil
  15 + end
  16 +
  17 + if hub
  18 + message_data = {}
  19 + message_data.merge!(params[:message]) if params[:message]
  20 +
  21 + message = Comment.new(message_data)
  22 + message.author = user
  23 + message.title = message_timestamp
  24 + message.article = hub
  25 + message.ip_address = request.remote_ip
  26 + message.user_agent = request.user_agent
  27 + message.referrer = request.referrer
  28 +
  29 + if message && message.save
  30 + render :text => {'ok' => true}.to_json, :content_type => 'application/json'
  31 + return true
  32 + end
  33 + end
10 34
11 - message_data = {}  
12 - message_data.merge!(params[:message]) if params[:message]  
13 -  
14 - @message = Comment.new(message_data)  
15 - @message.author = user if logged_in?  
16 - @message.title = message_timestamp  
17 - @message.article = article  
18 - @message.ip_address = request.remote_ip  
19 - @message.user_agent = request.user_agent  
20 - @message.referrer = request.referrer  
21 -  
22 - if @message && @message.save  
23 - render :text => {'ok' => true}.to_json, :content_type => 'application/json'  
24 - else  
25 - render :text => {'ok' => false}.to_json, :content_type => 'application/json'  
26 end 35 end
  36 + render :text => {'ok' => false}.to_json, :content_type => 'application/json'
27 end 37 end
28 38
29 39
30 def new_mediation 40 def new_mediation
31 - profile = Profile.find(params[:profile_id])  
32 -  
33 - mediation_data = {}  
34 - mediation_data.merge!(params[:article]) if params[:article]  
35 -  
36 - @mediation = TinyMceArticle.new(mediation_data)  
37 - @mediation.profile = profile  
38 - @mediation.last_changed_by = user  
39 - @mediation.name = mediation_timestamp  
40 - @mediation.notify_comments = false  
41 - @mediation.type = 'TinyMceArticle'  
42 - @mediation.advertise = false  
43 - @mediation.save  
44 -  
45 - if @mediation && @mediation.save  
46 - render :text => {'ok' => true}.to_json, :content_type => 'application/json'  
47 - else  
48 - render :text => {'ok' => false}.to_json, :content_type => 'application/json' 41 + if logged_in?
  42 +
  43 + begin
  44 + profile = Profile.find(params[:profile_id])
  45 + rescue
  46 + profile = nil
  47 + end
  48 +
  49 + if profile
  50 + mediation_data = {}
  51 + mediation_data.merge!(params[:article]) if params[:article]
  52 +
  53 + mediation = TinyMceArticle.new(mediation_data)
  54 + mediation.profile = profile
  55 + mediation.last_changed_by = user
  56 + mediation.name = mediation_timestamp
  57 + mediation.notify_comments = false
  58 + mediation.type = 'TinyMceArticle'
  59 + mediation.advertise = false
  60 + mediation.created_by_id = user.id
  61 +
  62 + if mediation && mediation.save
  63 + render :text => {'ok' => true}.to_json, :content_type => 'application/json'
  64 + return true
  65 + end
  66 + end
  67 +
49 end 68 end
  69 + render :text => {'ok' => false}.to_json, :content_type => 'application/json'
50 end 70 end
51 71
52 72
53 def newer_mediation_comment 73 def newer_mediation_comment
54 latest_id = params[:latest_post] 74 latest_id = params[:latest_post]
55 mediation = params[:mediation] 75 mediation = params[:mediation]
56 - comments = Comment.find(:all,  
57 - :limit => 100,  
58 - :conditions => ["id > :id and source_id = :mediation", {  
59 - :id => latest_id,  
60 - :mediation => mediation  
61 - }])  
62 -  
63 - render :partial => "mediation_comment",  
64 - :collection => comments 76 + comments = Comment.find(:all, :conditions => ["id > :id and source_id = :mediation", { :id => latest_id, :mediation => mediation }])
  77 + render :partial => "mediation_comment", :collection => comments
65 end 78 end
66 79
67 80
68 def newer_comments 81 def newer_comments
69 latest_post = params[:latest_post] 82 latest_post = params[:latest_post]
70 hub = Article.find(params[:hub]) 83 hub = Article.find(params[:hub])
71 - posts = Comment.find(:all,  
72 - :order => "id desc",  
73 - :limit => 100,  
74 - :conditions => ["id > :id and source_id = :hub", {  
75 - :id => latest_post,  
76 - :hub => hub  
77 - }]) 84 + posts = Comment.find(:all, :order => "id desc", :conditions => ["id > :id and source_id = :hub", { :id => latest_post, :hub => hub }])
78 85
79 if !posts.empty? 86 if !posts.empty?
80 oldest_post = posts.last.id 87 oldest_post = posts.last.id
@@ -84,27 +91,14 @@ class CommunityHubPluginPublicController < PublicController @@ -84,27 +91,14 @@ class CommunityHubPluginPublicController < PublicController
84 latest_post = 0 91 latest_post = 0
85 end 92 end
86 93
87 - render :partial => "post",  
88 - :collection => posts,  
89 - :locals => {  
90 - :latest_post => latest_post,  
91 - :oldest_post => oldest_post,  
92 - :hub => hub  
93 - } 94 + render :partial => "post", :collection => posts, :locals => { :latest_post => latest_post, :oldest_post => oldest_post, :hub => hub }
94 end 95 end
95 96
96 97
97 def newer_articles 98 def newer_articles
98 latest_post = params[:latest_post] 99 latest_post = params[:latest_post]
99 hub = Article.find(params[:hub]) 100 hub = Article.find(params[:hub])
100 - posts = Article.find(:all,  
101 - :order => "id desc",  
102 - :limit => 100,  
103 - :conditions => ["id > :id and type = :type and parent_id = :hub", {  
104 - :id => latest_post,  
105 - :type => 'TinyMceArticle',  
106 - :hub => hub.id  
107 - }]) 101 + posts = Article.find(:all, :order => "id desc", :conditions => ["id > :id and type = :type and parent_id = :hub", { :id => latest_post, :type => 'TinyMceArticle', :hub => hub.id }])
108 102
109 if !posts.empty? 103 if !posts.empty?
110 oldest_post = posts.last.id 104 oldest_post = posts.last.id
@@ -114,122 +108,88 @@ class CommunityHubPluginPublicController < PublicController @@ -114,122 +108,88 @@ class CommunityHubPluginPublicController < PublicController
114 latest_post = 0 108 latest_post = 0
115 end 109 end
116 110
117 - render :partial => "mediation",  
118 - :collection => posts,  
119 - :locals => {  
120 - :latest_post => latest_post,  
121 - :oldest_post => oldest_post,  
122 - :hub => hub  
123 - }  
124 - end  
125 -  
126 -  
127 - def settings  
128 - settings_section = params[:id]  
129 - render :partial => "settings/twitter", :layout => true  
130 - end  
131 -  
132 -  
133 - def set_hub_view  
134 - hub = Article.find(params[:hub])  
135 - hub_owner = hub.profile  
136 - role = params[:role]  
137 - render :partial => "post_form", :locals => {:hub => hub, :profile => user, :user_role => role}  
138 - end  
139 -  
140 -  
141 - def check_user_level  
142 - if false  
143 - render :text => {'level' => 0}.to_json, :content_type => 'application/json'  
144 - else  
145 - render :text => {'level' => 1}.to_json, :content_type => 'application/json'  
146 - end 111 + render :partial => "mediation", :collection => posts, :locals => { :latest_post => latest_post, :oldest_post => oldest_post, :hub => hub }
147 end 112 end
148 113
149 114
150 def promote_user 115 def promote_user
151 - hub = Article.find(params[:hub])  
152 -  
153 - user_id = params[:user].to_i  
154 -  
155 - hub.mediators += [user_id] unless hub.mediators.include?(user_id)  
156 -  
157 - if hub && hub.save  
158 - render :text => {'ok' => true}.to_json, :content_type => 'application/json'  
159 - else  
160 - render :text => {'ok' => false}.to_json, :content_type => 'application/json' 116 + if logged_in?
  117 + if (!params[:hub].blank? && !params[:user].blank?)
  118 + begin
  119 + hub = Article.find(params[:hub])
  120 + rescue
  121 + hub = nil
  122 + end
  123 + if hub && hub.mediator?(user)
  124 + begin
  125 + user_to_promote = Profile.find(params[:user])
  126 + rescue
  127 + user_to_promote = nil
  128 + end
  129 + if user_to_promote
  130 + hub.mediators += [user_to_promote.id] unless hub.mediators.include?(user_to_promote.id)
  131 + if hub.save
  132 + render :text => {'ok' => true}.to_json, :content_type => 'application/json'
  133 + return true
  134 + end
  135 + end
  136 + end
  137 + end
161 end 138 end
  139 + render :text => {'ok' => false}.to_json, :content_type => 'application/json'
162 end 140 end
163 141
164 142
165 def pin_message 143 def pin_message
166 - message = Comment.find(params[:message])  
167 - hub = Article.find(params[:hub])  
168 -  
169 - mediation = make_mediation_from_message(hub, message)  
170 - mediation.save  
171 -  
172 - if mediation && mediation.save  
173 - hub.pinned_messages += [message.id] unless hub.pinned_messages.include?(message.id)  
174 - hub.pinned_mediations += [mediation.id] unless hub.pinned_mediations.include?(mediation.id)  
175 - hub.save  
176 - render :text => {'ok' => true}.to_json, :content_type => 'application/json'  
177 - else  
178 - render :text => {'ok' => false}.to_json, :content_type => 'application/json'  
179 - end  
180 - 144 + if logged_in?
  145 + if (!params[:hub].blank? && !params[:message].blank?)
  146 + begin
  147 + hub = Article.find(params[:hub])
  148 + rescue
  149 + hub = nil
  150 + end
  151 + if hub && hub.mediator?(user)
  152 + begin
  153 + message = Comment.find(params[:message])
  154 + rescue
  155 + message = nil
  156 + end
  157 + if message
  158 + mediation = TinyMceArticle.new
  159 + mediation.profile = hub.profile
  160 + mediation.parent = hub
  161 + mediation.last_changed_by = message.author
  162 + mediation.created_by_id = message.author.id
  163 + mediation.name = mediation_timestamp
  164 + mediation.body = message.body
  165 + mediation.notify_comments = false
  166 + mediation.type = 'TinyMceArticle'
  167 + mediation.advertise = false
  168 + if mediation.save
  169 + hub.pinned_messages += [message.id] unless hub.pinned_messages.include?(message.id)
  170 + hub.pinned_mediations += [mediation.id] unless hub.pinned_mediations.include?(mediation.id)
  171 + if hub.save
  172 + render :text => {'ok' => true}.to_json, :content_type => 'application/json'
  173 + return true
  174 + end
  175 + end
  176 + end
  177 + end
  178 + end
  179 + end
  180 + render :text => {'ok' => false}.to_json, :content_type => 'application/json'
181 end 181 end
182 182
183 183
184 protected 184 protected
185 185
186 - def posts_to_json(list)  
187 - list.map do |item| {  
188 - 'id' => item.id,  
189 - 'created_at' => item.created_at,  
190 - 'body' => item.body,  
191 - 'profile' => item.author  
192 - }  
193 - end.to_json  
194 - end  
195 -  
196 -  
197 - def make_mediation_from_message(hub, message)  
198 - begin  
199 - mediation = Article.new  
200 -  
201 - mediation.profile = hub.profile  
202 - mediation.parent = hub  
203 - mediation.name = mediation_timestamp  
204 - mediation.body = message.body  
205 - mediation.abstract = ""  
206 - mediation.last_changed_by = message.author  
207 - mediation.type = 'TinyMceArticle'  
208 - mediation.display_versions = false  
209 - mediation.moderate_comments = false  
210 - mediation.translation_of_id = ""  
211 - mediation.notify_comments = false  
212 - mediation.accept_comments = true  
213 - mediation.tag_list = ""  
214 - mediation.allow_members_to_edit = false  
215 - mediation.display_hits = false  
216 - mediation.published = true  
217 - mediation.license_id = ""  
218 - mediation.category_ids = []  
219 - rescue  
220 - mediation = nil  
221 - end  
222 -  
223 - mediation  
224 - end  
225 -  
226 -  
227 def mediation_timestamp 186 def mediation_timestamp
228 "hub-mediation-#{(Time.now.to_f * 1000).to_i}" 187 "hub-mediation-#{(Time.now.to_f * 1000).to_i}"
229 end 188 end
230 - 189 +
  190 +
231 def message_timestamp 191 def message_timestamp
232 "hub-message-#{(Time.now.to_f * 1000).to_i}" 192 "hub-message-#{(Time.now.to_f * 1000).to_i}"
233 end 193 end
234 194
235 -end  
236 \ No newline at end of file 195 \ No newline at end of file
  196 +end
lib/community_hub_plugin/hub.rb
@@ -4,13 +4,13 @@ require File.dirname(__FILE__) + '/../../facebook_stream/lib_facebook_stream' @@ -4,13 +4,13 @@ require File.dirname(__FILE__) + '/../../facebook_stream/lib_facebook_stream'
4 class CommunityHubPlugin::Hub < Folder 4 class CommunityHubPlugin::Hub < Folder
5 5
6 settings_items :proxy_url, :type => :string, :default => 'http://161.148.1.167:3128' # Remember to use add the port, in case needed. 6 settings_items :proxy_url, :type => :string, :default => 'http://161.148.1.167:3128' # Remember to use add the port, in case needed.
7 - settings_items :twitter_enabled, :type => :boolean, :default => false  
8 - settings_items :hashtags_twitter, :type => :string, :default => "participa.br,participabr,arenanetmundial,netmundial" 7 + settings_items :twitter_enabled, :type => :boolean, :default => false
  8 + settings_items :hashtags_twitter, :type => :string, :default => "participa.br,participabr,arenanetmundial,netmundial"
9 settings_items :twitter_token_file, :type => :string, :default => "twurlrc_mariajoseopinto" 9 settings_items :twitter_token_file, :type => :string, :default => "twurlrc_mariajoseopinto"
10 settings_items :facebook_enabled, :type => :boolean, :default => false 10 settings_items :facebook_enabled, :type => :boolean, :default => false
11 - settings_items :facebook_page_id, :type => :string, :default => "participabr"  
12 - settings_items :facebook_pooling_time, :type => :integer, :default => 5 # Time in seconds  
13 - settings_items :facebook_access_token, :type => :string, :default => 'CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH' 11 + settings_items :facebook_page_id, :type => :string, :default => "participabr"
  12 + settings_items :facebook_pooling_time, :type => :integer, :default => 5 # Time in seconds
  13 + settings_items :facebook_access_token, :type => :string, :default => 'CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH'
14 settings_items :pinned_messages, :type => Array, :default => [] 14 settings_items :pinned_messages, :type => Array, :default => []
15 settings_items :pinned_mediations, :type => Array, :default => [] 15 settings_items :pinned_mediations, :type => Array, :default => []
16 settings_items :mediators, :type => Array, :default => [] 16 settings_items :mediators, :type => Array, :default => []
@@ -42,4 +42,8 @@ class CommunityHubPlugin::Hub &lt; Folder @@ -42,4 +42,8 @@ class CommunityHubPlugin::Hub &lt; Folder
42 def view_page 42 def view_page
43 "content_viewer/hub.rhtml" 43 "content_viewer/hub.rhtml"
44 end 44 end
  45 +
  46 + def mediator?(user)
  47 + self.author.id == user.id || self.mediators.include?(user.id) ? true : false
  48 + end
45 end 49 end
public/javascripts/community_hub.js
1 var latest_post_id = 0; 1 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 +var mediations = [];
  5 +
  6 +function validate_textarea(txt) {
  7 + return (txt.search(/[^\n\s]/)!=-1);
  8 +}
4 9
5 function clearLoadingMediationCommentSignal(mediation) { 10 function clearLoadingMediationCommentSignal(mediation) {
6 jQuery(".loading-mediation-comment").filter("#" + mediation).removeClass("loading-signal-error"); 11 jQuery(".loading-mediation-comment").filter("#" + mediation).removeClass("loading-signal-error");
@@ -24,8 +29,28 @@ function toogle_mediation_comments(mediation) { @@ -24,8 +29,28 @@ function toogle_mediation_comments(mediation) {
24 29
25 30
26 function new_mediation_comment(button, mediation) { 31 function new_mediation_comment(button, mediation) {
  32 +
  33 + if (!validate_textarea(jQuery("#mediation-comment-form-" + mediation + " textarea").val())) {
  34 + return false;
  35 + }
  36 +
  37 + for (var i = 0; i < mediations.length; i++) {
  38 + mediation_id = mediations[i][0];
  39 + if (mediation_id == mediation) {
  40 + interval_id = mediations[i][1];
  41 + clearInterval( interval_id );
  42 + break;
  43 + }
  44 +
  45 + }
  46 +
  47 + mediations.splice(i, 1);
  48 +
27 var form = jQuery(button).parents("form"); 49 var form = jQuery(button).parents("form");
28 50
  51 + jQuery("#mediation-comment-form-" + mediation + " .submit").attr("disabled", true);
  52 +
  53 + jQuery("body").addClass("loading");
29 jQuery(".loading-mediation-comment").filter("#" + mediation).addClass("loading-signal-processing"); 54 jQuery(".loading-mediation-comment").filter("#" + mediation).addClass("loading-signal-processing");
30 55
31 jQuery.post(form.attr("action"), form.serialize(), function(data) { 56 jQuery.post(form.attr("action"), form.serialize(), function(data) {
@@ -33,14 +58,22 @@ function new_mediation_comment(button, mediation) { @@ -33,14 +58,22 @@ function new_mediation_comment(button, mediation) {
33 if (data.ok) { 58 if (data.ok) {
34 jQuery("#mediation-comment-form-" + mediation + " textarea").val(''); 59 jQuery("#mediation-comment-form-" + mediation + " textarea").val('');
35 jQuery(".loading-mediation-comment").filter("#" + mediation).addClass("loading-signal-done"); 60 jQuery(".loading-mediation-comment").filter("#" + mediation).addClass("loading-signal-done");
36 - update_mediation_comments(mediation); 61 + jQuery("body").removeClass("loading");
  62 + jQuery("#mediation-comment-form-" + mediation + " .submit").attr("disabled", false);
  63 + update_mediation_comments(mediation, false);
37 setTimeout(function(){ 64 setTimeout(function(){
38 clearLoadingMediationCommentSignal(mediation); 65 clearLoadingMediationCommentSignal(mediation);
39 }, 3000); 66 }, 3000);
  67 + mediations.push( [ mediation, setInterval(function() { update_mediation_comments(mediation, false)}, 5000) ] );
40 } 68 }
41 else { 69 else {
42 jQuery(".loading-mediation-comment").filter("#" + mediation).addClass("loading-signal-error"); 70 jQuery(".loading-mediation-comment").filter("#" + mediation).addClass("loading-signal-error");
43 - setTimeout(clearLoadingMessageSignal, 3000); 71 + jQuery("body").removeClass("loading");
  72 + jQuery("#mediation-comment-form-" + mediation + " .submit").attr("disabled", false);
  73 + setTimeout(function(){
  74 + clearLoadingMediationCommentSignal(mediation);
  75 + }, 3000);
  76 + mediations.push( [ mediation, setInterval(function() { update_mediation_comments(mediation, false)}, 5000) ] );
44 } 77 }
45 }, 'json'); 78 }, 'json');
46 79
@@ -48,20 +81,33 @@ function new_mediation_comment(button, mediation) { @@ -48,20 +81,33 @@ function new_mediation_comment(button, mediation) {
48 81
49 82
50 function new_message(button) { 83 function new_message(button) {
  84 +
  85 + if (!validate_textarea(jQuery(".hub .form-message #message_body").val())) {
  86 + return false;
  87 + }
  88 +
51 var form = jQuery(button).parents("form"); 89 var form = jQuery(button).parents("form");
52 90
  91 + jQuery(".hub .form-message .submit").attr("disabled", true);
  92 +
  93 + jQuery("body").addClass("loading");
53 jQuery("#loading-message").addClass("loading-signal-processing"); 94 jQuery("#loading-message").addClass("loading-signal-processing");
54 95
55 jQuery.post(form.attr("action"), form.serialize(), function(data) { 96 jQuery.post(form.attr("action"), form.serialize(), function(data) {
56 jQuery("#loading-message").removeClass("loading-signal-processing"); 97 jQuery("#loading-message").removeClass("loading-signal-processing");
57 if (data.ok) { 98 if (data.ok) {
58 - jQuery(".hub .form #message_body").val(''); 99 + jQuery(".hub .form-message #message_body").val('');
59 jQuery("#loading-message").addClass("loading-signal-done"); 100 jQuery("#loading-message").addClass("loading-signal-done");
60 - update_live_stream(); 101 + jQuery("body").removeClass("loading");
  102 + jQuery(".hub .form-message .submit").attr("disabled", false);
  103 + update_live_stream(false);
61 setTimeout(clearLoadingMessageSignal, 3000); 104 setTimeout(clearLoadingMessageSignal, 3000);
  105 +
62 } 106 }
63 else { 107 else {
64 jQuery("#loading-message").addClass("loading-signal-error"); 108 jQuery("#loading-message").addClass("loading-signal-error");
  109 + jQuery("body").removeClass("loading");
  110 + jQuery(".hub .form-message .submit").attr("disabled", false);
65 setTimeout(clearLoadingMessageSignal, 3000); 111 setTimeout(clearLoadingMessageSignal, 3000);
66 } 112 }
67 }, 'json'); 113 }, 'json');
@@ -70,8 +116,16 @@ function new_message(button) { @@ -70,8 +116,16 @@ function new_message(button) {
70 116
71 117
72 function new_mediation(button) { 118 function new_mediation(button) {
  119 +
  120 + if (!validate_textarea(tinymce.get('article_body').getContent(''))) {
  121 + return false;
  122 + }
  123 +
73 var form = jQuery(button).parents("form"); 124 var form = jQuery(button).parents("form");
74 125
  126 + jQuery(".hub .form-mediation .submit").attr("disabled", true);
  127 +
  128 + jQuery("body").addClass("loading");
75 jQuery("#loading-mediation").addClass("loading-signal-processing"); 129 jQuery("#loading-mediation").addClass("loading-signal-processing");
76 130
77 tinymce.triggerSave(); 131 tinymce.triggerSave();
@@ -79,12 +133,16 @@ function new_mediation(button) { @@ -79,12 +133,16 @@ function new_mediation(button) {
79 jQuery("#loading-mediation").removeClass("loading-signal-processing"); 133 jQuery("#loading-mediation").removeClass("loading-signal-processing");
80 if (data.ok) { 134 if (data.ok) {
81 jQuery("#loading-mediation").addClass("loading-signal-done"); 135 jQuery("#loading-mediation").addClass("loading-signal-done");
  136 + jQuery("body").removeClass("loading");
  137 + jQuery(".hub .form-mediation .submit").attr("disabled", false);
82 tinymce.get('article_body').setContent(''); 138 tinymce.get('article_body').setContent('');
83 update_mediations(); 139 update_mediations();
84 setTimeout(clearLoadingMediationSignal, 3000); 140 setTimeout(clearLoadingMediationSignal, 3000);
85 } 141 }
86 else { 142 else {
87 jQuery("#loading-mediation").addClass("loading-signal-error"); 143 jQuery("#loading-mediation").addClass("loading-signal-error");
  144 + jQuery("body").removeClass("loading");
  145 + jQuery(".hub .form-mediation .submit").attr("disabled", false);
88 setTimeout(clearLoadingMediationSignal, 3000); 146 setTimeout(clearLoadingMediationSignal, 3000);
89 } 147 }
90 }, 'json'); 148 }, 'json');
@@ -107,7 +165,6 @@ function promote_user(mediation, user_id) { @@ -107,7 +165,6 @@ function promote_user(mediation, user_id) {
107 jQuery(".promote a").filter("#" + mediation).replaceWith( '<img class="promoted" src="/plugins/community_hub/icons/hub-not-promote-icon.png" title="User promoted">' ); 165 jQuery(".promote a").filter("#" + mediation).replaceWith( '<img class="promoted" src="/plugins/community_hub/icons/hub-not-promote-icon.png" title="User promoted">' );
108 }, 166 },
109 error: function(ajax, stat, errorThrown) { 167 error: function(ajax, stat, errorThrown) {
110 - console.log(stat);  
111 } 168 }
112 }); 169 });
113 170
@@ -131,7 +188,6 @@ function pin_message(post_id) { @@ -131,7 +188,6 @@ function pin_message(post_id) {
131 jQuery(".pin a").filter("#" + post_id).replaceWith( '<img class="pinned" src="/plugins/community_hub/icons/hub-not-pinned-icon.png" title="Message pinned">' ); 188 jQuery(".pin a").filter("#" + post_id).replaceWith( '<img class="pinned" src="/plugins/community_hub/icons/hub-not-pinned-icon.png" title="Message pinned">' );
132 }, 189 },
133 error: function(ajax, stat, errorThrown) { 190 error: function(ajax, stat, errorThrown) {
134 - console.log(stat);  
135 } 191 }
136 }); 192 });
137 193
@@ -140,37 +196,44 @@ function pin_message(post_id) { @@ -140,37 +196,44 @@ function pin_message(post_id) {
140 } 196 }
141 197
142 198
143 -function update_mediation_comments(mediation) { 199 +function update_mediation_comments(mediation, recursive) {
144 200
145 if (jQuery("#right-tab.show").size() != 0) { 201 if (jQuery("#right-tab.show").size() != 0) {
146 202
147 - var hub_id = jQuery(".hub").attr('id'); 203 + if (jQuery(".hub #mediation-comment-list-" + mediation).css('display') != "none") {
148 204
149 - if (jQuery("#mediation-comment-list-" + mediation + " li").first().length == 0) {  
150 - var latest_post_id = 0;  
151 - }  
152 - else {  
153 - var latest_post_id = jQuery("#mediation-comment-list-" + mediation + " li.mediation-comment").last().attr('id');  
154 - } 205 + var hub_id = jQuery(".hub").attr('id');
155 206
156 - jQuery.ajax({  
157 - url: '/plugin/community_hub/public/newer_mediation_comment',  
158 - type: 'get',  
159 - data: { latest_post: latest_post_id, mediation: mediation },  
160 - success: function(data) {  
161 - if (data.trim().length > 0) {  
162 - jQuery("#mediation-comment-list-" + mediation + "").append(data);  
163 - jQuery("#mediation-comment-total-" + mediation).html(jQuery("#mediation-comment-list-" + mediation + " li.mediation-comment").size());  
164 - }  
165 - },  
166 - error: function(ajax, stat, errorThrown) {  
167 - console.log(stat); 207 + if (jQuery("#mediation-comment-list-" + mediation + " li").first().length == 0) {
  208 + var latest_post_id = 0;
168 } 209 }
169 - }); 210 + else {
  211 + var latest_post_id = jQuery("#mediation-comment-list-" + mediation + " li.mediation-comment").last().attr('id');
  212 + }
  213 +
  214 + jQuery.ajax({
  215 + url: '/plugin/community_hub/public/newer_mediation_comment',
  216 + type: 'get',
  217 + data: { latest_post: latest_post_id, mediation: mediation },
  218 + success: function(data) {
  219 + if (data.trim().length > 0) {
  220 + jQuery("#mediation-comment-list-" + mediation + "").append(data);
  221 + jQuery("#mediation-comment-total-" + mediation).html(jQuery("#mediation-comment-list-" + mediation + " li.mediation-comment").size());
  222 + }
  223 + },
  224 + error: function(ajax, stat, errorThrown) {
  225 + }
  226 + });
  227 +
  228 + }
170 229
171 } 230 }
172 231
173 - setTimeout(function() { update_mediation_comments(mediation); }, 5000); 232 + if (recursive) {
  233 + setTimeout(function() {
  234 + update_mediation_comments(mediation, true);
  235 + }, 5000);
  236 + }
174 } 237 }
175 238
176 239
@@ -197,17 +260,16 @@ function update_mediations() { @@ -197,17 +260,16 @@ function update_mediations() {
197 } 260 }
198 }, 261 },
199 error: function(ajax, stat, errorThrown) { 262 error: function(ajax, stat, errorThrown) {
200 - console.log(stat);  
201 } 263 }
202 }); 264 });
203 265
204 } 266 }
205 267
206 - setTimeout(update_mediations, 5000); 268 + setTimeout(update_mediations, 10000);
207 } 269 }
208 270
209 271
210 -function update_live_stream() { 272 +function update_live_stream(recursive) {
211 273
212 if (jQuery("#left-tab.show").size() != 0) { 274 if (jQuery("#left-tab.show").size() != 0) {
213 275
@@ -233,16 +295,23 @@ function update_live_stream() { @@ -233,16 +295,23 @@ function update_live_stream() {
233 else { 295 else {
234 jQuery("#live-posts").scrollTop(live_scroll_position); 296 jQuery("#live-posts").scrollTop(live_scroll_position);
235 } 297 }
  298 + if (first_hub_load) {
  299 + jQuery("body").removeClass("loading");
  300 + first_hub_load = false;
  301 + }
236 } 302 }
237 }, 303 },
238 error: function(ajax, stat, errorThrown) { 304 error: function(ajax, stat, errorThrown) {
239 - console.log(stat);  
240 } 305 }
241 }); 306 });
242 307
243 } 308 }
244 309
245 - setTimeout(update_live_stream, 5000); 310 + if (recursive) {
  311 + setTimeout(function() {
  312 + update_live_stream(true);
  313 + }, 5000);
  314 + }
246 } 315 }
247 316
248 function hub_left_tab_click() { 317 function hub_left_tab_click() {
@@ -260,9 +329,7 @@ function hub_right_tab_click() { @@ -260,9 +329,7 @@ function hub_right_tab_click() {
260 jQuery(".hub #left-tab.hide").click(hub_left_tab_click); 329 jQuery(".hub #left-tab.hide").click(hub_left_tab_click);
261 } 330 }
262 331
263 -function marcelo() {  
264 - console.log('teste!');  
265 -} 332 +first_hub_load = true;
266 333
267 jQuery(document).ready(function() { 334 jQuery(document).ready(function() {
268 jQuery("#live-posts").scroll(function() { 335 jQuery("#live-posts").scroll(function() {
@@ -271,6 +338,8 @@ jQuery(document).ready(function() { @@ -271,6 +338,8 @@ jQuery(document).ready(function() {
271 338
272 jQuery(".hub #right-tab.hide").click(hub_right_tab_click); 339 jQuery(".hub #right-tab.hide").click(hub_right_tab_click);
273 340
274 - setTimeout(update_live_stream, 5000);  
275 - setTimeout(update_mediations, 5000); 341 + jQuery("body").addClass("loading");
  342 +
  343 + update_live_stream(true);
  344 + update_mediations();
276 }); 345 });
public/style.css
1 -/*div.content-tab.show {  
2 - display: block;  
3 -}  
4 -  
5 -div.content-tab.hide {  
6 - display: none;  
7 -}*/  
8 -  
9 #banner-embed-container { 1 #banner-embed-container {
10 width: 49%; 2 width: 49%;
11 float: right; 3 float: right;
@@ -17,62 +9,7 @@ div.content-tab.hide { @@ -17,62 +9,7 @@ div.content-tab.hide {
17 height: 350px; 9 height: 350px;
18 } 10 }
19 11
20 -/*.hub #left-tab {  
21 - comentado-border: 0px solid lightGray;-comentado  
22 - border: 1px solid red;  
23 - display: inline-block;  
24 - float: left;  
25 - width: 49%;  
26 - margin-bottom: 2em;  
27 - cursor: pointer;  
28 -}*/  
29 -  
30 -/*.hub #right-tab {  
31 - border: 1px solid green;  
32 - display: inline-block;  
33 - clear: right;  
34 - float: none;  
35 - margin-left: 1%;  
36 - width: 50%;  
37 - margin-bottom: 2em;  
38 - cursor: pointer;  
39 -}*/  
40 -  
41 -.hub #content-tab {  
42 -}  
43 -  
44 -/*.hub #left-tab .on-air {  
45 - background-color: #d40000;  
46 - border-radius: 10px 10px 10px 10px;  
47 - color: white;  
48 - display: inline-block;  
49 - font-size: 16px;  
50 - font-weight: bold;  
51 - padding: 0 0.5em;  
52 - text-align: center;  
53 - text-transform: uppercase;  
54 - vertical-align: top;  
55 - width: 20%;  
56 -  
57 -}  
58 -  
59 -.hub #left-tab .off-air {  
60 - background-color: gray;  
61 - border-radius: 10px 10px 10px 10px;  
62 - color: black;  
63 - display: inline-block;  
64 - font-size: 16px;  
65 - font-weight: bold;  
66 - padding: 0 0.5em;  
67 - text-align: center;  
68 - text-transform: uppercase;  
69 - vertical-align: top;  
70 - width: 20%;  
71 -}  
72 -*/  
73 -  
74 #hub-loading { 12 #hub-loading {
75 - /*margin-top: 18px;*/  
76 float: right; 13 float: right;
77 } 14 }
78 15
@@ -81,10 +18,6 @@ div.content-tab.hide { @@ -81,10 +18,6 @@ div.content-tab.hide {
81 background-image: url(/plugins/community_hub/icons/community-hub.png) 18 background-image: url(/plugins/community_hub/icons/community-hub.png)
82 } 19 }
83 20
84 -.hub {  
85 - /*border: 1px solid red;*/  
86 -}  
87 -  
88 .hub ul {padding-left: 0px; margin-top: 0;} 21 .hub ul {padding-left: 0px; margin-top: 0;}
89 22
90 #content .hub h1{ 23 #content .hub h1{
@@ -135,11 +68,6 @@ div.content-tab.hide { @@ -135,11 +68,6 @@ div.content-tab.hide {
135 max-width: 43px; 68 max-width: 43px;
136 } 69 }
137 70
138 -/*.hub .message{  
139 - display: inline-block;  
140 - width: 70%;  
141 -}*/  
142 -  
143 .hub .message { 71 .hub .message {
144 display: inline-block; 72 display: inline-block;
145 width: 65%; 73 width: 65%;
@@ -151,14 +79,6 @@ div.content-tab.hide { @@ -151,14 +79,6 @@ div.content-tab.hide {
151 width: 80%; 79 width: 80%;
152 } 80 }
153 81
154 -/*.hub .message .author {  
155 - font-weight: bold;  
156 - float: left;  
157 - display: inline-block;  
158 - line-height: 16px;  
159 - margin-right: 5px;  
160 -}*/  
161 -  
162 .hub .message .author { 82 .hub .message .author {
163 font-weight: bold; 83 font-weight: bold;
164 display: inline-block; 84 display: inline-block;
@@ -176,9 +96,7 @@ div.content-tab.hide { @@ -176,9 +96,7 @@ div.content-tab.hide {
176 96
177 .hub .mediation-bar ul li { 97 .hub .mediation-bar ul li {
178 display: inline-block; 98 display: inline-block;
179 - /*margin-right: 5px;*/  
180 overflow: hidden; 99 overflow: hidden;
181 - /*text-indent: -1000px;*/  
182 width: 16px; 100 width: 16px;
183 } 101 }
184 102
@@ -200,23 +118,11 @@ div.content-tab.hide { @@ -200,23 +118,11 @@ div.content-tab.hide {
200 text-indent: -10000px; 118 text-indent: -10000px;
201 } 119 }
202 120
203 -/*  
204 -.hub .promoted {  
205 - background: url("images/hub-promote-icon.png") no-repeat center center #fff;  
206 -}*/  
207 -  
208 .hub .not-promoted { 121 .hub .not-promoted {
209 - /*background: url("images/hub-not-promote-icon.png") no-repeat center center #fff;*/  
210 opacity: 0.5; 122 opacity: 0.5;
211 filter: alpha(opacity=50); 123 filter: alpha(opacity=50);
212 } 124 }
213 125
214 -/*  
215 -.hub .pin {  
216 - background: url("images/hub-pin-icon.png") no-repeat center center #fff;  
217 -}  
218 -*/  
219 -  
220 .hub .pin .not-pinned { 126 .hub .pin .not-pinned {
221 opacity: 0.5; 127 opacity: 0.5;
222 filter: alpha(opacity=50); 128 filter: alpha(opacity=50);
@@ -247,8 +153,6 @@ div.content-tab.hide { @@ -247,8 +153,6 @@ div.content-tab.hide {
247 display: block; 153 display: block;
248 } 154 }
249 155
250 -/**/  
251 -  
252 .hub .live { 156 .hub .live {
253 border: 0px solid lightGray; 157 border: 0px solid lightGray;
254 display: inline-block; 158 display: inline-block;
@@ -265,7 +169,6 @@ div.content-tab.hide { @@ -265,7 +169,6 @@ div.content-tab.hide {
265 border-style: solid; 169 border-style: solid;
266 border-color: lightGray; 170 border-color: lightGray;
267 padding-top: 10px; 171 padding-top: 10px;
268 -/*border: 1px solid red;*/  
269 } 172 }
270 173
271 174
@@ -343,16 +246,13 @@ div.content-tab.hide { @@ -343,16 +246,13 @@ div.content-tab.hide {
343 } 246 }
344 247
345 #content .hub .live.hide h1 .title { 248 #content .hub .live.hide h1 .title {
346 - /*display: inline-block;*/  
347 display: none; 249 display: none;
348 } 250 }
349 #content .hub .live.hide .on-air, 251 #content .hub .live.hide .on-air,
350 #content .hub .live.hide .off-air { 252 #content .hub .live.hide .off-air {
351 - width: auto; 253 + width: auto;
352 } 254 }
353 255
354 -  
355 -  
356 /****fim aba live fechada****/ 256 /****fim aba live fechada****/
357 257
358 /****aba live aberta****/ 258 /****aba live aberta****/
@@ -361,12 +261,6 @@ div.content-tab.hide { @@ -361,12 +261,6 @@ div.content-tab.hide {
361 width: 85%; 261 width: 85%;
362 } 262 }
363 263
364 -/*.hub .live.show ul#live-posts{  
365 - overflow-x: hidden;  
366 - overflow-y: scroll;  
367 - background-color: #fff;  
368 -}*/  
369 -  
370 .hub .live.show ul#live-posts .li{ 264 .hub .live.show ul#live-posts .li{
371 265
372 } 266 }
@@ -377,13 +271,6 @@ float: right; @@ -377,13 +271,6 @@ float: right;
377 margin-right: 10px; 271 margin-right: 10px;
378 } 272 }
379 273
380 -/*#content .hub .live.show .on-air,  
381 -#content .hub .live.show .off-air {  
382 - width: 20%;  
383 -}*/  
384 -  
385 -  
386 -  
387 /****fim aba mlive aberta****/ 274 /****fim aba mlive aberta****/
388 275
389 276
@@ -412,7 +299,6 @@ margin-right: 10px; @@ -412,7 +299,6 @@ margin-right: 10px;
412 font-family: Arial Black, arial, sans-serif; 299 font-family: Arial Black, arial, sans-serif;
413 padding-right: 0; 300 padding-right: 0;
414 width: 100%; 301 width: 100%;
415 - /*font-variant: normal;*/  
416 } 302 }
417 .hub .mediation .expand { 303 .hub .mediation .expand {
418 float: right; 304 float: right;
@@ -445,7 +331,6 @@ margin-right: 10px; @@ -445,7 +331,6 @@ margin-right: 10px;
445 font-family: Arial Black, arial, sans-serif; 331 font-family: Arial Black, arial, sans-serif;
446 padding-right: 0; 332 padding-right: 0;
447 width: 100%; 333 width: 100%;
448 - /*font-variant: normal;*/  
449 } 334 }
450 .hub .mediation.hide .expand { 335 .hub .mediation.hide .expand {
451 display: none; 336 display: none;
@@ -493,7 +378,6 @@ display: none; @@ -493,7 +378,6 @@ display: none;
493 font-family: Arial Black, arial, sans-serif; 378 font-family: Arial Black, arial, sans-serif;
494 padding-right: 0; 379 padding-right: 0;
495 width: 100%; 380 width: 100%;
496 - /*font-variant: normal;*/  
497 } 381 }
498 .hub .mediation.show .expand { 382 .hub .mediation.show .expand {
499 float: right; 383 float: right;
@@ -521,8 +405,6 @@ background-color: #f9f9f9; @@ -521,8 +405,6 @@ background-color: #f9f9f9;
521 /****fim aba mediation aberta****/ 405 /****fim aba mediation aberta****/
522 406
523 .hub .form-mediation { 407 .hub .form-mediation {
524 - /*clear: left;*/  
525 - /*float: left;*/  
526 width: 93%; 408 width: 93%;
527 display: inline-block; 409 display: inline-block;
528 height: 376px; 410 height: 376px;
@@ -531,8 +413,6 @@ background-color: #f9f9f9; @@ -531,8 +413,6 @@ background-color: #f9f9f9;
531 } 413 }
532 414
533 .hub .form-message { 415 .hub .form-message {
534 - /*clear: left;*/  
535 - /*float: left;*/  
536 width: 93%; 416 width: 93%;
537 display: inline-block; 417 display: inline-block;
538 height: 148px; 418 height: 148px;
@@ -560,10 +440,8 @@ background-color: #f9f9f9; @@ -560,10 +440,8 @@ background-color: #f9f9f9;
560 } 440 }
561 441
562 .hub div.banner { 442 .hub div.banner {
563 - /*width: 50%;*/  
564 height: 70px; 443 height: 70px;
565 background-color: #6d6d6d; 444 background-color: #6d6d6d;
566 - /*float: right;*/  
567 text-align: center; 445 text-align: center;
568 padding-top: 30px; 446 padding-top: 30px;
569 } 447 }
@@ -573,17 +451,13 @@ background-color: #f9f9f9; @@ -573,17 +451,13 @@ background-color: #f9f9f9;
573 font-family: Arial Black, arial, sans-serif; 451 font-family: Arial Black, arial, sans-serif;
574 font-size: large; 452 font-size: large;
575 font-weight: normal; 453 font-weight: normal;
576 - /*margin-top: 35px;*/  
577 display: block; 454 display: block;
578 } 455 }
579 456
580 .hub div.embed { 457 .hub div.embed {
581 margin-top: 10px; 458 margin-top: 10px;
582 padding: 8px; 459 padding: 8px;
583 - /*width: 48%;*/  
584 - /*height: 216px;*/  
585 border: 1px solid #c0c0c0; 460 border: 1px solid #c0c0c0;
586 - /*float: right;*/  
587 } 461 }
588 462
589 .hub div.embed textarea.code { 463 .hub div.embed textarea.code {
@@ -612,27 +486,11 @@ background-color: #f9f9f9; @@ -612,27 +486,11 @@ background-color: #f9f9f9;
612 margin-top: 10px; 486 margin-top: 10px;
613 } 487 }
614 488
615 -.hub .settings .twitter, .hub .settings .facebook, .hub .settings .general {  
616 - /* border: 1px solid red;*/  
617 -}  
618 -  
619 textarea#message_body { 489 textarea#message_body {
620 width: auto; 490 width: auto;
621 margin-left: 80px; 491 margin-left: 80px;
622 } 492 }
623 493
624 -/*  
625 -.comment-count {  
626 - margin-left: 80px;  
627 - padding: 5px 10px;  
628 - background-color: white;  
629 - display: inline-block;  
630 - border-radius: 5px;  
631 - font-weight: bold;  
632 - margin-bottom: -5px;  
633 -}  
634 -*/  
635 -  
636 .comment-count { 494 .comment-count {
637 margin-left: 80px; 495 margin-left: 80px;
638 padding: 5px 10px; 496 padding: 5px 10px;
@@ -680,5 +538,3 @@ textarea#message_body { @@ -680,5 +538,3 @@ textarea#message_body {
680 .loading-signal-processing { 538 .loading-signal-processing {
681 background-image: url(/plugins/community_hub/icons/hub-samarelo.gif); 539 background-image: url(/plugins/community_hub/icons/hub-samarelo.gif);
682 } 540 }
683 -  
684 -  
views/cms/community_hub_plugin/_hub.rhtml
@@ -5,7 +5,8 @@ @@ -5,7 +5,8 @@
5 <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %> 5 <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %>
6 </div> 6 </div>
7 <div> 7 <div>
8 - <%= required labelled_form_field(_('Description'), text_area(:article, 'body', :style => 'width: 99%;')) %> 8 + <%= render :file => 'shared/tiny_mce' %>
  9 + <%= required labelled_form_field(_('Description'), text_area(:article, 'body', :style => 'width: 100%;', :class => 'mceEditor')) %>
9 </div> 10 </div>
10 <br /> 11 <br />
11 12
views/community_hub_plugin_public/_mediation.rhtml
@@ -45,7 +45,7 @@ @@ -45,7 +45,7 @@
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 + mediations.push( [ <%= mediation.id %>, setInterval(function() { update_mediation_comments('<%= mediation.id %>', false)}, 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;">