Commit 588fa8ffdf89a11df467981bbcbd726dd0820d41
1 parent
0ba0e6e9
Exists in
master
#community dashboard - fixes
Showing
6 changed files
with
243 additions
and
353 deletions
Show diff stats
controllers/public/community_hub_plugin_public_controller.rb
... | ... | @@ -6,75 +6,82 @@ class CommunityHubPluginPublicController < PublicController |
6 | 6 | |
7 | 7 | |
8 | 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 | 35 | end |
36 | + render :text => {'ok' => false}.to_json, :content_type => 'application/json' | |
27 | 37 | end |
28 | 38 | |
29 | 39 | |
30 | 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 | 68 | end |
69 | + render :text => {'ok' => false}.to_json, :content_type => 'application/json' | |
50 | 70 | end |
51 | 71 | |
52 | 72 | |
53 | 73 | def newer_mediation_comment |
54 | 74 | latest_id = params[:latest_post] |
55 | 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 | 78 | end |
66 | 79 | |
67 | 80 | |
68 | 81 | def newer_comments |
69 | 82 | latest_post = params[:latest_post] |
70 | 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 | 86 | if !posts.empty? |
80 | 87 | oldest_post = posts.last.id |
... | ... | @@ -84,27 +91,14 @@ class CommunityHubPluginPublicController < PublicController |
84 | 91 | latest_post = 0 |
85 | 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 | 95 | end |
95 | 96 | |
96 | 97 | |
97 | 98 | def newer_articles |
98 | 99 | latest_post = params[:latest_post] |
99 | 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 | 103 | if !posts.empty? |
110 | 104 | oldest_post = posts.last.id |
... | ... | @@ -114,122 +108,88 @@ class CommunityHubPluginPublicController < PublicController |
114 | 108 | latest_post = 0 |
115 | 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 | 112 | end |
148 | 113 | |
149 | 114 | |
150 | 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 | 138 | end |
139 | + render :text => {'ok' => false}.to_json, :content_type => 'application/json' | |
162 | 140 | end |
163 | 141 | |
164 | 142 | |
165 | 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 | 181 | end |
182 | 182 | |
183 | 183 | |
184 | 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 | 186 | def mediation_timestamp |
228 | 187 | "hub-mediation-#{(Time.now.to_f * 1000).to_i}" |
229 | 188 | end |
230 | - | |
189 | + | |
190 | + | |
231 | 191 | def message_timestamp |
232 | 192 | "hub-message-#{(Time.now.to_f * 1000).to_i}" |
233 | 193 | end |
234 | 194 | |
235 | -end | |
236 | 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 | 4 | class CommunityHubPlugin::Hub < Folder |
5 | 5 | |
6 | 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 | 9 | settings_items :twitter_token_file, :type => :string, :default => "twurlrc_mariajoseopinto" |
10 | 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 | 14 | settings_items :pinned_messages, :type => Array, :default => [] |
15 | 15 | settings_items :pinned_mediations, :type => Array, :default => [] |
16 | 16 | settings_items :mediators, :type => Array, :default => [] |
... | ... | @@ -42,4 +42,8 @@ class CommunityHubPlugin::Hub < Folder |
42 | 42 | def view_page |
43 | 43 | "content_viewer/hub.rhtml" |
44 | 44 | end |
45 | + | |
46 | + def mediator?(user) | |
47 | + self.author.id == user.id || self.mediators.include?(user.id) ? true : false | |
48 | + end | |
45 | 49 | end | ... | ... |
public/javascripts/community_hub.js
1 | 1 | var latest_post_id = 0; |
2 | 2 | var oldest_post_id = 0; |
3 | 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 | 10 | function clearLoadingMediationCommentSignal(mediation) { |
6 | 11 | jQuery(".loading-mediation-comment").filter("#" + mediation).removeClass("loading-signal-error"); |
... | ... | @@ -24,8 +29,28 @@ function toogle_mediation_comments(mediation) { |
24 | 29 | |
25 | 30 | |
26 | 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 | 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 | 54 | jQuery(".loading-mediation-comment").filter("#" + mediation).addClass("loading-signal-processing"); |
30 | 55 | |
31 | 56 | jQuery.post(form.attr("action"), form.serialize(), function(data) { |
... | ... | @@ -33,14 +58,22 @@ function new_mediation_comment(button, mediation) { |
33 | 58 | if (data.ok) { |
34 | 59 | jQuery("#mediation-comment-form-" + mediation + " textarea").val(''); |
35 | 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 | 64 | setTimeout(function(){ |
38 | 65 | clearLoadingMediationCommentSignal(mediation); |
39 | 66 | }, 3000); |
67 | + mediations.push( [ mediation, setInterval(function() { update_mediation_comments(mediation, false)}, 5000) ] ); | |
40 | 68 | } |
41 | 69 | else { |
42 | 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 | 78 | }, 'json'); |
46 | 79 | |
... | ... | @@ -48,20 +81,33 @@ function new_mediation_comment(button, mediation) { |
48 | 81 | |
49 | 82 | |
50 | 83 | function new_message(button) { |
84 | + | |
85 | + if (!validate_textarea(jQuery(".hub .form-message #message_body").val())) { | |
86 | + return false; | |
87 | + } | |
88 | + | |
51 | 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 | 94 | jQuery("#loading-message").addClass("loading-signal-processing"); |
54 | 95 | |
55 | 96 | jQuery.post(form.attr("action"), form.serialize(), function(data) { |
56 | 97 | jQuery("#loading-message").removeClass("loading-signal-processing"); |
57 | 98 | if (data.ok) { |
58 | - jQuery(".hub .form #message_body").val(''); | |
99 | + jQuery(".hub .form-message #message_body").val(''); | |
59 | 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 | 104 | setTimeout(clearLoadingMessageSignal, 3000); |
105 | + | |
62 | 106 | } |
63 | 107 | else { |
64 | 108 | jQuery("#loading-message").addClass("loading-signal-error"); |
109 | + jQuery("body").removeClass("loading"); | |
110 | + jQuery(".hub .form-message .submit").attr("disabled", false); | |
65 | 111 | setTimeout(clearLoadingMessageSignal, 3000); |
66 | 112 | } |
67 | 113 | }, 'json'); |
... | ... | @@ -70,8 +116,16 @@ function new_message(button) { |
70 | 116 | |
71 | 117 | |
72 | 118 | function new_mediation(button) { |
119 | + | |
120 | + if (!validate_textarea(tinymce.get('article_body').getContent(''))) { | |
121 | + return false; | |
122 | + } | |
123 | + | |
73 | 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 | 129 | jQuery("#loading-mediation").addClass("loading-signal-processing"); |
76 | 130 | |
77 | 131 | tinymce.triggerSave(); |
... | ... | @@ -79,12 +133,16 @@ function new_mediation(button) { |
79 | 133 | jQuery("#loading-mediation").removeClass("loading-signal-processing"); |
80 | 134 | if (data.ok) { |
81 | 135 | jQuery("#loading-mediation").addClass("loading-signal-done"); |
136 | + jQuery("body").removeClass("loading"); | |
137 | + jQuery(".hub .form-mediation .submit").attr("disabled", false); | |
82 | 138 | tinymce.get('article_body').setContent(''); |
83 | 139 | update_mediations(); |
84 | 140 | setTimeout(clearLoadingMediationSignal, 3000); |
85 | 141 | } |
86 | 142 | else { |
87 | 143 | jQuery("#loading-mediation").addClass("loading-signal-error"); |
144 | + jQuery("body").removeClass("loading"); | |
145 | + jQuery(".hub .form-mediation .submit").attr("disabled", false); | |
88 | 146 | setTimeout(clearLoadingMediationSignal, 3000); |
89 | 147 | } |
90 | 148 | }, 'json'); |
... | ... | @@ -107,7 +165,6 @@ function promote_user(mediation, user_id) { |
107 | 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 | 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 | 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 | 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 | 196 | } |
141 | 197 | |
142 | 198 | |
143 | -function update_mediation_comments(mediation) { | |
199 | +function update_mediation_comments(mediation, recursive) { | |
144 | 200 | |
145 | 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 | 260 | } |
198 | 261 | }, |
199 | 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 | 274 | if (jQuery("#left-tab.show").size() != 0) { |
213 | 275 | |
... | ... | @@ -233,16 +295,23 @@ function update_live_stream() { |
233 | 295 | else { |
234 | 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 | 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 | 317 | function hub_left_tab_click() { |
... | ... | @@ -260,9 +329,7 @@ function hub_right_tab_click() { |
260 | 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 | 334 | jQuery(document).ready(function() { |
268 | 335 | jQuery("#live-posts").scroll(function() { |
... | ... | @@ -271,6 +338,8 @@ jQuery(document).ready(function() { |
271 | 338 | |
272 | 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 | 1 | #banner-embed-container { |
10 | 2 | width: 49%; |
11 | 3 | float: right; |
... | ... | @@ -17,62 +9,7 @@ div.content-tab.hide { |
17 | 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 | 12 | #hub-loading { |
75 | - /*margin-top: 18px;*/ | |
76 | 13 | float: right; |
77 | 14 | } |
78 | 15 | |
... | ... | @@ -81,10 +18,6 @@ div.content-tab.hide { |
81 | 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 | 21 | .hub ul {padding-left: 0px; margin-top: 0;} |
89 | 22 | |
90 | 23 | #content .hub h1{ |
... | ... | @@ -135,11 +68,6 @@ div.content-tab.hide { |
135 | 68 | max-width: 43px; |
136 | 69 | } |
137 | 70 | |
138 | -/*.hub .message{ | |
139 | - display: inline-block; | |
140 | - width: 70%; | |
141 | -}*/ | |
142 | - | |
143 | 71 | .hub .message { |
144 | 72 | display: inline-block; |
145 | 73 | width: 65%; |
... | ... | @@ -151,14 +79,6 @@ div.content-tab.hide { |
151 | 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 | 82 | .hub .message .author { |
163 | 83 | font-weight: bold; |
164 | 84 | display: inline-block; |
... | ... | @@ -176,9 +96,7 @@ div.content-tab.hide { |
176 | 96 | |
177 | 97 | .hub .mediation-bar ul li { |
178 | 98 | display: inline-block; |
179 | - /*margin-right: 5px;*/ | |
180 | 99 | overflow: hidden; |
181 | - /*text-indent: -1000px;*/ | |
182 | 100 | width: 16px; |
183 | 101 | } |
184 | 102 | |
... | ... | @@ -200,23 +118,11 @@ div.content-tab.hide { |
200 | 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 | 121 | .hub .not-promoted { |
209 | - /*background: url("images/hub-not-promote-icon.png") no-repeat center center #fff;*/ | |
210 | 122 | opacity: 0.5; |
211 | 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 | 126 | .hub .pin .not-pinned { |
221 | 127 | opacity: 0.5; |
222 | 128 | filter: alpha(opacity=50); |
... | ... | @@ -247,8 +153,6 @@ div.content-tab.hide { |
247 | 153 | display: block; |
248 | 154 | } |
249 | 155 | |
250 | -/**/ | |
251 | - | |
252 | 156 | .hub .live { |
253 | 157 | border: 0px solid lightGray; |
254 | 158 | display: inline-block; |
... | ... | @@ -265,7 +169,6 @@ div.content-tab.hide { |
265 | 169 | border-style: solid; |
266 | 170 | border-color: lightGray; |
267 | 171 | padding-top: 10px; |
268 | -/*border: 1px solid red;*/ | |
269 | 172 | } |
270 | 173 | |
271 | 174 | |
... | ... | @@ -343,16 +246,13 @@ div.content-tab.hide { |
343 | 246 | } |
344 | 247 | |
345 | 248 | #content .hub .live.hide h1 .title { |
346 | - /*display: inline-block;*/ | |
347 | 249 | display: none; |
348 | 250 | } |
349 | 251 | #content .hub .live.hide .on-air, |
350 | 252 | #content .hub .live.hide .off-air { |
351 | - width: auto; | |
253 | + width: auto; | |
352 | 254 | } |
353 | 255 | |
354 | - | |
355 | - | |
356 | 256 | /****fim aba live fechada****/ |
357 | 257 | |
358 | 258 | /****aba live aberta****/ |
... | ... | @@ -361,12 +261,6 @@ div.content-tab.hide { |
361 | 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 | 264 | .hub .live.show ul#live-posts .li{ |
371 | 265 | |
372 | 266 | } |
... | ... | @@ -377,13 +271,6 @@ float: right; |
377 | 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 | 274 | /****fim aba mlive aberta****/ |
388 | 275 | |
389 | 276 | |
... | ... | @@ -412,7 +299,6 @@ margin-right: 10px; |
412 | 299 | font-family: Arial Black, arial, sans-serif; |
413 | 300 | padding-right: 0; |
414 | 301 | width: 100%; |
415 | - /*font-variant: normal;*/ | |
416 | 302 | } |
417 | 303 | .hub .mediation .expand { |
418 | 304 | float: right; |
... | ... | @@ -445,7 +331,6 @@ margin-right: 10px; |
445 | 331 | font-family: Arial Black, arial, sans-serif; |
446 | 332 | padding-right: 0; |
447 | 333 | width: 100%; |
448 | - /*font-variant: normal;*/ | |
449 | 334 | } |
450 | 335 | .hub .mediation.hide .expand { |
451 | 336 | display: none; |
... | ... | @@ -493,7 +378,6 @@ display: none; |
493 | 378 | font-family: Arial Black, arial, sans-serif; |
494 | 379 | padding-right: 0; |
495 | 380 | width: 100%; |
496 | - /*font-variant: normal;*/ | |
497 | 381 | } |
498 | 382 | .hub .mediation.show .expand { |
499 | 383 | float: right; |
... | ... | @@ -521,8 +405,6 @@ background-color: #f9f9f9; |
521 | 405 | /****fim aba mediation aberta****/ |
522 | 406 | |
523 | 407 | .hub .form-mediation { |
524 | - /*clear: left;*/ | |
525 | - /*float: left;*/ | |
526 | 408 | width: 93%; |
527 | 409 | display: inline-block; |
528 | 410 | height: 376px; |
... | ... | @@ -531,8 +413,6 @@ background-color: #f9f9f9; |
531 | 413 | } |
532 | 414 | |
533 | 415 | .hub .form-message { |
534 | - /*clear: left;*/ | |
535 | - /*float: left;*/ | |
536 | 416 | width: 93%; |
537 | 417 | display: inline-block; |
538 | 418 | height: 148px; |
... | ... | @@ -560,10 +440,8 @@ background-color: #f9f9f9; |
560 | 440 | } |
561 | 441 | |
562 | 442 | .hub div.banner { |
563 | - /*width: 50%;*/ | |
564 | 443 | height: 70px; |
565 | 444 | background-color: #6d6d6d; |
566 | - /*float: right;*/ | |
567 | 445 | text-align: center; |
568 | 446 | padding-top: 30px; |
569 | 447 | } |
... | ... | @@ -573,17 +451,13 @@ background-color: #f9f9f9; |
573 | 451 | font-family: Arial Black, arial, sans-serif; |
574 | 452 | font-size: large; |
575 | 453 | font-weight: normal; |
576 | - /*margin-top: 35px;*/ | |
577 | 454 | display: block; |
578 | 455 | } |
579 | 456 | |
580 | 457 | .hub div.embed { |
581 | 458 | margin-top: 10px; |
582 | 459 | padding: 8px; |
583 | - /*width: 48%;*/ | |
584 | - /*height: 216px;*/ | |
585 | 460 | border: 1px solid #c0c0c0; |
586 | - /*float: right;*/ | |
587 | 461 | } |
588 | 462 | |
589 | 463 | .hub div.embed textarea.code { |
... | ... | @@ -612,27 +486,11 @@ background-color: #f9f9f9; |
612 | 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 | 489 | textarea#message_body { |
620 | 490 | width: auto; |
621 | 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 | 494 | .comment-count { |
637 | 495 | margin-left: 80px; |
638 | 496 | padding: 5px 10px; |
... | ... | @@ -680,5 +538,3 @@ textarea#message_body { |
680 | 538 | .loading-signal-processing { |
681 | 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 | 5 | <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %> |
6 | 6 | </div> |
7 | 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 | 10 | </div> |
10 | 11 | <br /> |
11 | 12 | ... | ... |
views/community_hub_plugin_public/_mediation.rhtml
... | ... | @@ -45,7 +45,7 @@ |
45 | 45 | </span> |
46 | 46 | |
47 | 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 | 49 | </script> |
50 | 50 | |
51 | 51 | <ul id="mediation-comment-list-<%=mediation.id%>" class="mediation-comment-list" style="display:none;"> | ... | ... |