Commit 2de2dbb581e74e3f54a0085d989e752dd915bb54
Exists in
master
and in
9 other branches
Merge branch 'master' of gitlab.com:participa/proposal-app
Showing
1 changed file
with
130 additions
and
100 deletions
Show diff stats
js/main.js
@@ -3,20 +3,20 @@ define(['handlebars'], function(Handlebars){ | @@ -3,20 +3,20 @@ define(['handlebars'], function(Handlebars){ | ||
3 | /* global Handlebars, $ */ | 3 | /* global Handlebars, $ */ |
4 | // The template code | 4 | // The template code |
5 | var templateSource = document.getElementById('proposal-template').innerHTML; | 5 | var templateSource = document.getElementById('proposal-template').innerHTML; |
6 | - | 6 | + |
7 | // compile the template | 7 | // compile the template |
8 | var template = Handlebars.compile(templateSource); | 8 | var template = Handlebars.compile(templateSource); |
9 | var supportProposalTemplate = Handlebars.compile(document.getElementById('support-proposal-template').innerHTML); | 9 | var supportProposalTemplate = Handlebars.compile(document.getElementById('support-proposal-template').innerHTML); |
10 | var loginTemplate = Handlebars.compile(document.getElementById('login').innerHTML); | 10 | var loginTemplate = Handlebars.compile(document.getElementById('login').innerHTML); |
11 | var resultsTemplate = Handlebars.compile(document.getElementById('results').innerHTML); | 11 | var resultsTemplate = Handlebars.compile(document.getElementById('results').innerHTML); |
12 | - | 12 | + |
13 | // The div/container that we are going to display the results in | 13 | // The div/container that we are going to display the results in |
14 | var resultsPlaceholder = document.getElementById('proposal-result'); | 14 | var resultsPlaceholder = document.getElementById('proposal-result'); |
15 | - | 15 | + |
16 | var logged_in = false; | 16 | var logged_in = false; |
17 | - | 17 | + |
18 | var loginButton; | 18 | var loginButton; |
19 | - | 19 | + |
20 | var participa = true; | 20 | var participa = true; |
21 | if(participa){ | 21 | if(participa){ |
22 | var host = 'http://www.participa.br'; | 22 | var host = 'http://www.participa.br'; |
@@ -29,10 +29,10 @@ define(['handlebars'], function(Handlebars){ | @@ -29,10 +29,10 @@ define(['handlebars'], function(Handlebars){ | ||
29 | var proposal_discussion = '632'; //local serpro | 29 | var proposal_discussion = '632'; //local serpro |
30 | //var proposal_discussion = '401'; //casa | 30 | //var proposal_discussion = '401'; //casa |
31 | } | 31 | } |
32 | - | 32 | + |
33 | // Load data from localhost when it is dev env. | 33 | // Load data from localhost when it is dev env. |
34 | var noosferoAPI = host + '/api/v1/articles/' + proposal_discussion + '?private_token=' + private_token + '&fields=id,children,categories,abstract,body,title,image,url'; | 34 | var noosferoAPI = host + '/api/v1/articles/' + proposal_discussion + '?private_token=' + private_token + '&fields=id,children,categories,abstract,body,title,image,url'; |
35 | - | 35 | + |
36 | $.getJSON(noosferoAPI) | 36 | $.getJSON(noosferoAPI) |
37 | .done(function( data ) { | 37 | .done(function( data ) { |
38 | data.host = host; | 38 | data.host = host; |
@@ -40,66 +40,66 @@ define(['handlebars'], function(Handlebars){ | @@ -40,66 +40,66 @@ define(['handlebars'], function(Handlebars){ | ||
40 | resultsPlaceholder.innerHTML = template(data); | 40 | resultsPlaceholder.innerHTML = template(data); |
41 | $('.login-container').html(loginTemplate()); | 41 | $('.login-container').html(loginTemplate()); |
42 | $('.countdown').maxlength({text: '%left caracteres restantes'}); | 42 | $('.countdown').maxlength({text: '%left caracteres restantes'}); |
43 | - | 43 | + |
44 | navigateTo(window.location.hash); | 44 | navigateTo(window.location.hash); |
45 | - | 45 | + |
46 | //Actions for links | 46 | //Actions for links |
47 | $( '#nav-proposal-categories a' ).on('click touchstart', function(e){ | 47 | $( '#nav-proposal-categories a' ).on('click touchstart', function(e){ |
48 | e.preventDefault(); | 48 | e.preventDefault(); |
49 | - | 49 | + |
50 | var $link = $(this); | 50 | var $link = $(this); |
51 | - | 51 | + |
52 | // Update URL and Navigate | 52 | // Update URL and Navigate |
53 | updateHash($link.attr('href')); | 53 | updateHash($link.attr('href')); |
54 | }); | 54 | }); |
55 | - | 55 | + |
56 | $( '#nav-proposal-group a' ).on('click touchstart', function(e){ | 56 | $( '#nav-proposal-group a' ).on('click touchstart', function(e){ |
57 | e.preventDefault(); | 57 | e.preventDefault(); |
58 | - | 58 | + |
59 | var $link = $(this); | 59 | var $link = $(this); |
60 | - | 60 | + |
61 | // Update URL and Navigate | 61 | // Update URL and Navigate |
62 | updateHash($link.attr('href')); | 62 | updateHash($link.attr('href')); |
63 | }); | 63 | }); |
64 | - | 64 | + |
65 | $( '.proposal-item a' ).on('click touchstart', function(e){ | 65 | $( '.proposal-item a' ).on('click touchstart', function(e){ |
66 | e.preventDefault(); | 66 | e.preventDefault(); |
67 | - | 67 | + |
68 | var $link = $(this); | 68 | var $link = $(this); |
69 | - | 69 | + |
70 | // Update URL and Navigate | 70 | // Update URL and Navigate |
71 | updateHash($link.attr('href')); | 71 | updateHash($link.attr('href')); |
72 | }); | 72 | }); |
73 | - | 73 | + |
74 | $( '.proposal-category a' ).on('click touchstart', function(e){ | 74 | $( '.proposal-category a' ).on('click touchstart', function(e){ |
75 | e.preventDefault(); | 75 | e.preventDefault(); |
76 | - | 76 | + |
77 | var $link = $(this); | 77 | var $link = $(this); |
78 | - | 78 | + |
79 | // Update URL and Navigate | 79 | // Update URL and Navigate |
80 | updateHash($link.attr('href')); | 80 | updateHash($link.attr('href')); |
81 | }); | 81 | }); |
82 | - | 82 | + |
83 | $( '.proposal-category .go-back' ).on('click touchstart', function(e){ | 83 | $( '.proposal-category .go-back' ).on('click touchstart', function(e){ |
84 | e.preventDefault(); | 84 | e.preventDefault(); |
85 | - | 85 | + |
86 | var oldHash = window.location.hash; | 86 | var oldHash = window.location.hash; |
87 | var regexSubpages = /sobre-o-programa$/; | 87 | var regexSubpages = /sobre-o-programa$/; |
88 | var isSubpage = regexSubpages.exec(oldHash) !== null; | 88 | var isSubpage = regexSubpages.exec(oldHash) !== null; |
89 | var newHash = '#/temas'; // default page | 89 | var newHash = '#/temas'; // default page |
90 | - | 90 | + |
91 | if(isSubpage){ | 91 | if(isSubpage){ |
92 | // return to proposal page | 92 | // return to proposal page |
93 | newHash = oldHash.split('/sobre-o-programa')[0]; | 93 | newHash = oldHash.split('/sobre-o-programa')[0]; |
94 | } | 94 | } |
95 | - | 95 | + |
96 | // Update URL and Navigate | 96 | // Update URL and Navigate |
97 | updateHash(newHash); | 97 | updateHash(newHash); |
98 | }); | 98 | }); |
99 | - | 99 | + |
100 | $( '.send-button a' ).on('click touchstart', function(e){ | 100 | $( '.send-button a' ).on('click touchstart', function(e){ |
101 | e.preventDefault(); | 101 | e.preventDefault(); |
102 | - | 102 | + |
103 | //display form to send proposal (or login form for non-logged users) | 103 | //display form to send proposal (or login form for non-logged users) |
104 | var $this = $(this); | 104 | var $this = $(this); |
105 | loginButton = $this.parents('.send-button'); | 105 | loginButton = $this.parents('.send-button'); |
@@ -107,41 +107,41 @@ define(['handlebars'], function(Handlebars){ | @@ -107,41 +107,41 @@ define(['handlebars'], function(Handlebars){ | ||
107 | $this.parents('.success-proposal-sent').hide(); | 107 | $this.parents('.success-proposal-sent').hide(); |
108 | loginCallback(logged_in); | 108 | loginCallback(logged_in); |
109 | }); | 109 | }); |
110 | - | 110 | + |
111 | $( '#display-contrast' ).on('click touchstart', function(e){ | 111 | $( '#display-contrast' ).on('click touchstart', function(e){ |
112 | e.preventDefault(); | 112 | e.preventDefault(); |
113 | $('#proposal-result').toggleClass('contrast'); | 113 | $('#proposal-result').toggleClass('contrast'); |
114 | }); | 114 | }); |
115 | - | 115 | + |
116 | $( '.show_body a' ).on('click touchstart', function(e){ | 116 | $( '.show_body a' ).on('click touchstart', function(e){ |
117 | e.preventDefault(); | 117 | e.preventDefault(); |
118 | - | 118 | + |
119 | var $link = $(this); | 119 | var $link = $(this); |
120 | - | 120 | + |
121 | // Update URL and Navigate | 121 | // Update URL and Navigate |
122 | updateHash($link.attr('href')); | 122 | updateHash($link.attr('href')); |
123 | }); | 123 | }); |
124 | - | 124 | + |
125 | $( '.go-to-proposal-button a' ).on('click touchstart', function(e){ | 125 | $( '.go-to-proposal-button a' ).on('click touchstart', function(e){ |
126 | e.preventDefault(); | 126 | e.preventDefault(); |
127 | - | 127 | + |
128 | var $link = $(this); | 128 | var $link = $(this); |
129 | - | 129 | + |
130 | // Update URL and Navigate | 130 | // Update URL and Navigate |
131 | updateHash($link.attr('href')); | 131 | updateHash($link.attr('href')); |
132 | }); | 132 | }); |
133 | - | 133 | + |
134 | $( '.proposal-selection' ).change(function(e){ | 134 | $( '.proposal-selection' ).change(function(e){ |
135 | e.preventDefault(); | 135 | e.preventDefault(); |
136 | - | 136 | + |
137 | display_proposal('proposal-item-' + this.value); | 137 | display_proposal('proposal-item-' + this.value); |
138 | }); | 138 | }); |
139 | - | 139 | + |
140 | var availableTags = [ ]; | 140 | var availableTags = [ ]; |
141 | $('#proposal-group li a').each(function(){ | 141 | $('#proposal-group li a').each(function(){ |
142 | availableTags.push({ label: $(this).text(), value: $(this).attr('href')}); | 142 | availableTags.push({ label: $(this).text(), value: $(this).attr('href')}); |
143 | }); | 143 | }); |
144 | - | 144 | + |
145 | $( '#search-input' ).autocomplete({ | 145 | $( '#search-input' ).autocomplete({ |
146 | source: availableTags, | 146 | source: availableTags, |
147 | minLength: 3, | 147 | minLength: 3, |
@@ -155,8 +155,8 @@ define(['handlebars'], function(Handlebars){ | @@ -155,8 +155,8 @@ define(['handlebars'], function(Handlebars){ | ||
155 | results: function() {} | 155 | results: function() {} |
156 | } | 156 | } |
157 | }); | 157 | }); |
158 | - | ||
159 | - | 158 | + |
159 | + | ||
160 | $('.save-article-form').submit(function (e) { | 160 | $('.save-article-form').submit(function (e) { |
161 | e.preventDefault(); | 161 | e.preventDefault(); |
162 | var proposal_id = this.id.split('-').pop(); | 162 | var proposal_id = this.id.split('-').pop(); |
@@ -182,33 +182,33 @@ define(['handlebars'], function(Handlebars){ | @@ -182,33 +182,33 @@ define(['handlebars'], function(Handlebars){ | ||
182 | message.text('Não foi possível enviar.'); | 182 | message.text('Não foi possível enviar.'); |
183 | }); | 183 | }); |
184 | }); | 184 | }); |
185 | - | 185 | + |
186 | }) | 186 | }) |
187 | .fail(function( jqxhr, textStatus, error ) { | 187 | .fail(function( jqxhr, textStatus, error ) { |
188 | var err = textStatus + ', ' + error; | 188 | var err = textStatus + ', ' + error; |
189 | console.log( 'Request Failed: ' + err ); | 189 | console.log( 'Request Failed: ' + err ); |
190 | }); | 190 | }); |
191 | - | 191 | + |
192 | function loadRandomProposal(topic_id, private_token) { | 192 | function loadRandomProposal(topic_id, private_token) { |
193 | var $noProposals = $('.no-proposals'); | 193 | var $noProposals = $('.no-proposals'); |
194 | var $loading = $('.loading'); | 194 | var $loading = $('.loading'); |
195 | var $randomProposal = $('.random-proposal'); | 195 | var $randomProposal = $('.random-proposal'); |
196 | var $body = $(document.body); | 196 | var $body = $(document.body); |
197 | - | 197 | + |
198 | // reset view | 198 | // reset view |
199 | $noProposals.hide(); | 199 | $noProposals.hide(); |
200 | $loading.show(); | 200 | $loading.show(); |
201 | $randomProposal.html(''); | 201 | $randomProposal.html(''); |
202 | - | 202 | + |
203 | var url = host + '/api/v1/articles/' + topic_id + '/children' + '?private_token=' + private_token + '&limit=1&order=random()&_='+new Date().getTime()+'&fields=id,name,abstract,created_by&content_type=ProposalsDiscussionPlugin::Proposal'; | 203 | var url = host + '/api/v1/articles/' + topic_id + '/children' + '?private_token=' + private_token + '&limit=1&order=random()&_='+new Date().getTime()+'&fields=id,name,abstract,created_by&content_type=ProposalsDiscussionPlugin::Proposal'; |
204 | $.getJSON(url).done(function( data ) { | 204 | $.getJSON(url).done(function( data ) { |
205 | $loading.hide(); | 205 | $loading.hide(); |
206 | - | 206 | + |
207 | if(data.articles.length === 0) { | 207 | if(data.articles.length === 0) { |
208 | $noProposals.show(); | 208 | $noProposals.show(); |
209 | return; | 209 | return; |
210 | } | 210 | } |
211 | - | 211 | + |
212 | var article = data.articles[0]; | 212 | var article = data.articles[0]; |
213 | $randomProposal.html(supportProposalTemplate(article)); | 213 | $randomProposal.html(supportProposalTemplate(article)); |
214 | $body.off('click', '.vote-actions .skip'); | 214 | $body.off('click', '.vote-actions .skip'); |
@@ -218,6 +218,13 @@ define(['handlebars'], function(Handlebars){ | @@ -218,6 +218,13 @@ define(['handlebars'], function(Handlebars){ | ||
218 | }); | 218 | }); |
219 | $body.off('click', '.vote-actions .like'); | 219 | $body.off('click', '.vote-actions .like'); |
220 | $body.on('click', '.vote-actions .like', function(e) { | 220 | $body.on('click', '.vote-actions .like', function(e) { |
221 | + //Helps to prevent more than one vote per proposal | ||
222 | + if(hasProposalbeenVoted(article.id)){ | ||
223 | + console.log("Proposta " + article.id + " já havia sido votada"); | ||
224 | + loadRandomProposal(topic_id, private_token); | ||
225 | + e.preventDefault(); | ||
226 | + return; | ||
227 | + } | ||
221 | $.ajax({ | 228 | $.ajax({ |
222 | type: 'post', | 229 | type: 'post', |
223 | url: host + '/api/v1/articles/' + article.id + '/vote', | 230 | url: host + '/api/v1/articles/' + article.id + '/vote', |
@@ -226,34 +233,35 @@ define(['handlebars'], function(Handlebars){ | @@ -226,34 +233,35 @@ define(['handlebars'], function(Handlebars){ | ||
226 | private_token: private_token | 233 | private_token: private_token |
227 | } | 234 | } |
228 | }).done(function( /*data*/ ) { | 235 | }).done(function( /*data*/ ) { |
236 | + addVotedProposal(article.id); | ||
229 | loadRandomProposal(topic_id, private_token); | 237 | loadRandomProposal(topic_id, private_token); |
230 | }); | 238 | }); |
231 | e.preventDefault(); | 239 | e.preventDefault(); |
232 | }); | 240 | }); |
233 | - | 241 | + |
234 | $body.off('click', '.vote-result'); | 242 | $body.off('click', '.vote-result'); |
235 | $body.on('click', '.vote-result', function(e) { | 243 | $body.on('click', '.vote-result', function(e) { |
236 | - | 244 | + |
237 | var $this = $(this); | 245 | var $this = $(this); |
238 | var $proposalDetail = $this.parents('.proposal-detail'); | 246 | var $proposalDetail = $this.parents('.proposal-detail'); |
239 | var $resultsContainer = $proposalDetail.find('.results-container'); | 247 | var $resultsContainer = $proposalDetail.find('.results-container'); |
240 | - | 248 | + |
241 | // $resultsContainer.toggle(); | 249 | // $resultsContainer.toggle(); |
242 | // $resultsContainer.toggleClass('hide'); | 250 | // $resultsContainer.toggleClass('hide'); |
243 | - | 251 | + |
244 | if($resultsContainer.css('display') === 'none') { | 252 | if($resultsContainer.css('display') === 'none') { |
245 | - | 253 | + |
246 | $resultsContainer.find('.loading').show(); | 254 | $resultsContainer.find('.loading').show(); |
247 | $resultsContainer.find('.results-content').hide(); | 255 | $resultsContainer.find('.results-content').hide(); |
248 | - | 256 | + |
249 | var url = host + '/api/v1/articles/' + topic_id + '/children' + '?private_token=' + private_token + '&limit=10&order=votes_score&fields=id,name,abstract,votes_for,votes_against&content_type=ProposalsDiscussionPlugin::Proposal'; | 257 | var url = host + '/api/v1/articles/' + topic_id + '/children' + '?private_token=' + private_token + '&limit=10&order=votes_score&fields=id,name,abstract,votes_for,votes_against&content_type=ProposalsDiscussionPlugin::Proposal'; |
250 | $.getJSON(url).done(function( data ) { | 258 | $.getJSON(url).done(function( data ) { |
251 | - | 259 | + |
252 | $resultsContainer.html(resultsTemplate(data)); | 260 | $resultsContainer.html(resultsTemplate(data)); |
253 | $resultsContainer.find('.loading').hide(); | 261 | $resultsContainer.find('.loading').hide(); |
254 | $resultsContainer.find('.results-content').show(); | 262 | $resultsContainer.find('.results-content').show(); |
255 | $resultsContainer.show(); | 263 | $resultsContainer.show(); |
256 | - | 264 | + |
257 | // scroll to the end | 265 | // scroll to the end |
258 | $('html, body').animate({ | 266 | $('html, body').animate({ |
259 | scrollTop: $(document).height() | 267 | scrollTop: $(document).height() |
@@ -266,12 +274,12 @@ define(['handlebars'], function(Handlebars){ | @@ -266,12 +274,12 @@ define(['handlebars'], function(Handlebars){ | ||
266 | $('.talk-proposal-container').show(); | 274 | $('.talk-proposal-container').show(); |
267 | $resultsContainer.hide(); | 275 | $resultsContainer.hide(); |
268 | } | 276 | } |
269 | - | 277 | + |
270 | e.preventDefault(); | 278 | e.preventDefault(); |
271 | }); | 279 | }); |
272 | }); | 280 | }); |
273 | } | 281 | } |
274 | - | 282 | + |
275 | $(document).ready(function($) { | 283 | $(document).ready(function($) { |
276 | if($.cookie('_dialoga_session')) { | 284 | if($.cookie('_dialoga_session')) { |
277 | var url = host + '/api/v1/users/me?private_token=' + $.cookie('_dialoga_session'); | 285 | var url = host + '/api/v1/users/me?private_token=' + $.cookie('_dialoga_session'); |
@@ -280,7 +288,7 @@ define(['handlebars'], function(Handlebars){ | @@ -280,7 +288,7 @@ define(['handlebars'], function(Handlebars){ | ||
280 | private_token = $.cookie('_dialoga_session'); | 288 | private_token = $.cookie('_dialoga_session'); |
281 | }); | 289 | }); |
282 | } | 290 | } |
283 | - | 291 | + |
284 | $(document).on('click', '.login-action', function(e) { | 292 | $(document).on('click', '.login-action', function(e) { |
285 | var message = $('.login .message'); | 293 | var message = $('.login .message'); |
286 | message.hide(); | 294 | message.hide(); |
@@ -301,11 +309,11 @@ define(['handlebars'], function(Handlebars){ | @@ -301,11 +309,11 @@ define(['handlebars'], function(Handlebars){ | ||
301 | e.preventDefault(); | 309 | e.preventDefault(); |
302 | }); | 310 | }); |
303 | }); | 311 | }); |
304 | - | 312 | + |
305 | function loginCallback(loggedIn, token) { | 313 | function loginCallback(loggedIn, token) { |
306 | logged_in = loggedIn; | 314 | logged_in = loggedIn; |
307 | $('.login .message').text(''); | 315 | $('.login .message').text(''); |
308 | - | 316 | + |
309 | if(logged_in) { | 317 | if(logged_in) { |
310 | if(token){ | 318 | if(token){ |
311 | private_token = token; | 319 | private_token = token; |
@@ -323,7 +331,7 @@ define(['handlebars'], function(Handlebars){ | @@ -323,7 +331,7 @@ define(['handlebars'], function(Handlebars){ | ||
323 | function oauthPluginHandleLoginResult(loggedIn, token) { | 331 | function oauthPluginHandleLoginResult(loggedIn, token) { |
324 | loginCallback(loggedIn, token); | 332 | loginCallback(loggedIn, token); |
325 | } | 333 | } |
326 | - | 334 | + |
327 | function guid() { | 335 | function guid() { |
328 | function s4() { | 336 | function s4() { |
329 | return Math.floor((1 + Math.random()) * 0x10000) | 337 | return Math.floor((1 + Math.random()) * 0x10000) |
@@ -331,7 +339,7 @@ define(['handlebars'], function(Handlebars){ | @@ -331,7 +339,7 @@ define(['handlebars'], function(Handlebars){ | ||
331 | .substring(1); | 339 | .substring(1); |
332 | } | 340 | } |
333 | } | 341 | } |
334 | - | 342 | + |
335 | function display_category_tab(){ | 343 | function display_category_tab(){ |
336 | $('#proposal-group').hide(); | 344 | $('#proposal-group').hide(); |
337 | $('#proposal-categories').show(); | 345 | $('#proposal-categories').show(); |
@@ -340,22 +348,22 @@ define(['handlebars'], function(Handlebars){ | @@ -340,22 +348,22 @@ define(['handlebars'], function(Handlebars){ | ||
340 | $('.proposal-category-items').hide(); | 348 | $('.proposal-category-items').hide(); |
341 | $('.proposal-category .arrow-box').hide(); | 349 | $('.proposal-category .arrow-box').hide(); |
342 | $('.proposal-detail').hide(); | 350 | $('.proposal-detail').hide(); |
343 | - | 351 | + |
344 | $('#content').show(); | 352 | $('#content').show(); |
345 | $('nav').show(); | 353 | $('nav').show(); |
346 | } | 354 | } |
347 | - | 355 | + |
348 | function display_proposals_tab(){ | 356 | function display_proposals_tab(){ |
349 | $('#proposal-categories').hide(); | 357 | $('#proposal-categories').hide(); |
350 | $('#proposal-group').show(); | 358 | $('#proposal-group').show(); |
351 | $('#nav-proposal-group a').addClass('active'); | 359 | $('#nav-proposal-group a').addClass('active'); |
352 | $('#nav-proposal-categories a').removeClass('active'); | 360 | $('#nav-proposal-categories a').removeClass('active'); |
353 | $('.proposal-item p').dotdotdot(); | 361 | $('.proposal-item p').dotdotdot(); |
354 | - | 362 | + |
355 | $('#content').show(); | 363 | $('#content').show(); |
356 | $('nav').show(); | 364 | $('nav').show(); |
357 | } | 365 | } |
358 | - | 366 | + |
359 | function display_proposal(proposal_id){ | 367 | function display_proposal(proposal_id){ |
360 | $('#proposal-categories').hide(); | 368 | $('#proposal-categories').hide(); |
361 | $('#proposal-group').hide(); | 369 | $('#proposal-group').hide(); |
@@ -364,7 +372,7 @@ define(['handlebars'], function(Handlebars){ | @@ -364,7 +372,7 @@ define(['handlebars'], function(Handlebars){ | ||
364 | $('.make-proposal-form').hide(); | 372 | $('.make-proposal-form').hide(); |
365 | $('.login-container').hide(); | 373 | $('.login-container').hide(); |
366 | $('.proposal-detail').hide(); | 374 | $('.proposal-detail').hide(); |
367 | - | 375 | + |
368 | $('.proposal-detail-base').hide(); | 376 | $('.proposal-detail-base').hide(); |
369 | $('#' + proposal_id).show(); | 377 | $('#' + proposal_id).show(); |
370 | $('.proposal-header').show(); | 378 | $('.proposal-header').show(); |
@@ -375,11 +383,11 @@ define(['handlebars'], function(Handlebars){ | @@ -375,11 +383,11 @@ define(['handlebars'], function(Handlebars){ | ||
375 | $('.results-container .results-content').hide(); | 383 | $('.results-container .results-content').hide(); |
376 | $('.experience-proposal-container').show(); | 384 | $('.experience-proposal-container').show(); |
377 | $('.talk-proposal-container').show(); | 385 | $('.talk-proposal-container').show(); |
378 | - | 386 | + |
379 | var topic_id = proposal_id.split('-').pop(); | 387 | var topic_id = proposal_id.split('-').pop(); |
380 | loadRandomProposal(topic_id, private_token); | 388 | loadRandomProposal(topic_id, private_token); |
381 | } | 389 | } |
382 | - | 390 | + |
383 | function display_proposal_detail(){ | 391 | function display_proposal_detail(){ |
384 | $('#proposal-categories').hide(); | 392 | $('#proposal-categories').hide(); |
385 | $('#proposal-group').hide(); | 393 | $('#proposal-group').hide(); |
@@ -392,13 +400,13 @@ define(['handlebars'], function(Handlebars){ | @@ -392,13 +400,13 @@ define(['handlebars'], function(Handlebars){ | ||
392 | $('.results-container').hide(); | 400 | $('.results-container').hide(); |
393 | $('.experience-proposal-container').hide(); | 401 | $('.experience-proposal-container').hide(); |
394 | $('.talk-proposal-container').hide(); | 402 | $('.talk-proposal-container').hide(); |
395 | - | 403 | + |
396 | $('.body').show(); | 404 | $('.body').show(); |
397 | } | 405 | } |
398 | - | 406 | + |
399 | function display_proposal_by_category(item){ | 407 | function display_proposal_by_category(item){ |
400 | var $item = $('#' + item); | 408 | var $item = $('#' + item); |
401 | - | 409 | + |
402 | if($item.hasClass('proposal-category-items')){ | 410 | if($item.hasClass('proposal-category-items')){ |
403 | //Display Topics or Discussion by category | 411 | //Display Topics or Discussion by category |
404 | $('nav').show(); | 412 | $('nav').show(); |
@@ -415,13 +423,13 @@ define(['handlebars'], function(Handlebars){ | @@ -415,13 +423,13 @@ define(['handlebars'], function(Handlebars){ | ||
415 | $('#proposal-category-' + categorySlug).find('.arrow-box').show(); | 423 | $('#proposal-category-' + categorySlug).find('.arrow-box').show(); |
416 | } | 424 | } |
417 | } | 425 | } |
418 | - | 426 | + |
419 | var BARRA_ADDED = false; | 427 | var BARRA_ADDED = false; |
420 | function addBarraDoGoverno(){ | 428 | function addBarraDoGoverno(){ |
421 | console.log('add barra'); | 429 | console.log('add barra'); |
422 | - | 430 | + |
423 | if( BARRA_ADDED ) { return; } | 431 | if( BARRA_ADDED ) { return; } |
424 | - | 432 | + |
425 | var HTML_BODY_PREPEND = '' + | 433 | var HTML_BODY_PREPEND = '' + |
426 | '<div id="barra-brasil" style="background:#7F7F7F; height: 20px; padding:0 0 0 10px;display:block;"> ' + | 434 | '<div id="barra-brasil" style="background:#7F7F7F; height: 20px; padding:0 0 0 10px;display:block;"> ' + |
427 | '<ul id="menu-barra-temp" style="list-style:none;">' + | 435 | '<ul id="menu-barra-temp" style="list-style:none;">' + |
@@ -429,11 +437,11 @@ define(['handlebars'], function(Handlebars){ | @@ -429,11 +437,11 @@ define(['handlebars'], function(Handlebars){ | ||
429 | '<li><a style="font-family:sans,sans-serif; text-decoration:none; color:white;" href="http://epwg.governoeletronico.gov.br/barra/atualize.html">Atualize sua Barra de Governo</a></li>' + | 437 | '<li><a style="font-family:sans,sans-serif; text-decoration:none; color:white;" href="http://epwg.governoeletronico.gov.br/barra/atualize.html">Atualize sua Barra de Governo</a></li>' + |
430 | '</ul>' + | 438 | '</ul>' + |
431 | '</div>'; | 439 | '</div>'; |
432 | - | 440 | + |
433 | var HTML_BODY_APPEND = ''+ | 441 | var HTML_BODY_APPEND = ''+ |
434 | '<div id="footer-brasil"></div>' + | 442 | '<div id="footer-brasil"></div>' + |
435 | '<script defer="defer" src="http://barra.brasil.gov.br/barra.js" type="text/javascript"></script>'; | 443 | '<script defer="defer" src="http://barra.brasil.gov.br/barra.js" type="text/javascript"></script>'; |
436 | - | 444 | + |
437 | var STYLE_TEMA_AZUL = '' + | 445 | var STYLE_TEMA_AZUL = '' + |
438 | '<style>'+ | 446 | '<style>'+ |
439 | '#footer-brasil {'+ | 447 | '#footer-brasil {'+ |
@@ -446,88 +454,88 @@ define(['handlebars'], function(Handlebars){ | @@ -446,88 +454,88 @@ define(['handlebars'], function(Handlebars){ | ||
446 | 'width: auto;'+ | 454 | 'width: auto;'+ |
447 | '}'+ | 455 | '}'+ |
448 | '<style>'; | 456 | '<style>'; |
449 | - | 457 | + |
450 | var $body = $(document.body); | 458 | var $body = $(document.body); |
451 | $body.prepend(HTML_BODY_PREPEND); | 459 | $body.prepend(HTML_BODY_PREPEND); |
452 | $body.append(HTML_BODY_APPEND); | 460 | $body.append(HTML_BODY_APPEND); |
453 | $body.append(STYLE_TEMA_AZUL); | 461 | $body.append(STYLE_TEMA_AZUL); |
454 | - | 462 | + |
455 | BARRA_ADDED = true; | 463 | BARRA_ADDED = true; |
456 | } | 464 | } |
457 | - | 465 | + |
458 | function updateHash(hash){ | 466 | function updateHash(hash){ |
459 | var id = hash.replace(/^.*#/, ''); | 467 | var id = hash.replace(/^.*#/, ''); |
460 | var elem = document.getElementById(id); | 468 | var elem = document.getElementById(id); |
461 | - | 469 | + |
462 | // preserve the query param | 470 | // preserve the query param |
463 | // if (HIDE_BARRA_DO_GOVERNO && (hash.indexOf('?barra=false') === -1)){ | 471 | // if (HIDE_BARRA_DO_GOVERNO && (hash.indexOf('?barra=false') === -1)){ |
464 | // hash += '?barra=false'; | 472 | // hash += '?barra=false'; |
465 | // } | 473 | // } |
466 | - | 474 | + |
467 | if ( !elem ) { | 475 | if ( !elem ) { |
468 | window.location.hash = hash; | 476 | window.location.hash = hash; |
469 | return; | 477 | return; |
470 | } | 478 | } |
471 | - | 479 | + |
472 | elem.id = id+'-tmp'; | 480 | elem.id = id+'-tmp'; |
473 | window.location.hash = hash; | 481 | window.location.hash = hash; |
474 | elem.id = id; | 482 | elem.id = id; |
475 | } | 483 | } |
476 | - | 484 | + |
477 | function locationHashChanged(){ | 485 | function locationHashChanged(){ |
478 | var hash = window.location.hash; | 486 | var hash = window.location.hash; |
479 | navigateTo(hash); | 487 | navigateTo(hash); |
480 | } | 488 | } |
481 | - | 489 | + |
482 | var HIDE_BARRA_DO_GOVERNO = false; | 490 | var HIDE_BARRA_DO_GOVERNO = false; |
483 | function navigateTo(hash){ | 491 | function navigateTo(hash){ |
484 | var regexProposals = /#\/programas/; | 492 | var regexProposals = /#\/programas/; |
485 | var regexCategory = /#\/temas/; | 493 | var regexCategory = /#\/temas/; |
486 | var regexHideBarra = /barra=false$/; | 494 | var regexHideBarra = /barra=false$/; |
487 | - | 495 | + |
488 | if( !(regexHideBarra.exec(hash) !== null) && !HIDE_BARRA_DO_GOVERNO ){ | 496 | if( !(regexHideBarra.exec(hash) !== null) && !HIDE_BARRA_DO_GOVERNO ){ |
489 | addBarraDoGoverno(); | 497 | addBarraDoGoverno(); |
490 | }else{ | 498 | }else{ |
491 | HIDE_BARRA_DO_GOVERNO = true; | 499 | HIDE_BARRA_DO_GOVERNO = true; |
492 | } | 500 | } |
493 | - | 501 | + |
494 | // remove query params | 502 | // remove query params |
495 | hash = hash.split('?')[0]; | 503 | hash = hash.split('?')[0]; |
496 | - | 504 | + |
497 | var parts = hash.split('/'); | 505 | var parts = hash.split('/'); |
498 | - | 506 | + |
499 | var isProposal = regexProposals.exec(hash) !== null; | 507 | var isProposal = regexProposals.exec(hash) !== null; |
500 | var isCategory = regexCategory.exec(hash) !== null; | 508 | var isCategory = regexCategory.exec(hash) !== null; |
501 | - | 509 | + |
502 | if( isProposal ){ | 510 | if( isProposal ){ |
503 | - | ||
504 | - // go to proposal | 511 | + |
512 | + // go to proposal | ||
505 | var proposalId = parts[2]; | 513 | var proposalId = parts[2]; |
506 | navigateToProposal(proposalId); | 514 | navigateToProposal(proposalId); |
507 | } | 515 | } |
508 | - | 516 | + |
509 | if( isCategory ){ | 517 | if( isCategory ){ |
510 | - | ||
511 | - // go to category | 518 | + |
519 | + // go to category | ||
512 | var categoryId = parts[3]; | 520 | var categoryId = parts[3]; |
513 | navigateToCategory(categoryId); | 521 | navigateToCategory(categoryId); |
514 | } | 522 | } |
515 | - | 523 | + |
516 | // default | 524 | // default |
517 | if( !isProposal && !isCategory ){ | 525 | if( !isProposal && !isCategory ){ |
518 | // show the 'index' -> category tab | 526 | // show the 'index' -> category tab |
519 | display_category_tab(); | 527 | display_category_tab(); |
520 | } | 528 | } |
521 | - | 529 | + |
522 | $('html, body').animate({ scrollTop: 0 }, 'fast'); | 530 | $('html, body').animate({ scrollTop: 0 }, 'fast'); |
523 | } | 531 | } |
524 | - | ||
525 | - function navigateToProposal(proposalId){ | 532 | + |
533 | + function navigateToProposal(proposalId){ | ||
526 | if(proposalId === undefined){ | 534 | if(proposalId === undefined){ |
527 | display_proposals_tab(); | 535 | display_proposals_tab(); |
528 | }else{ | 536 | }else{ |
529 | display_proposal('proposal-item-' + proposalId); | 537 | display_proposal('proposal-item-' + proposalId); |
530 | - | 538 | + |
531 | // show sub-page | 539 | // show sub-page |
532 | var regexSubpages = /sobre-o-programa$/; | 540 | var regexSubpages = /sobre-o-programa$/; |
533 | var m; | 541 | var m; |
@@ -536,7 +544,7 @@ define(['handlebars'], function(Handlebars){ | @@ -536,7 +544,7 @@ define(['handlebars'], function(Handlebars){ | ||
536 | } | 544 | } |
537 | } | 545 | } |
538 | } | 546 | } |
539 | - | 547 | + |
540 | function navigateToCategory(categoryId){ | 548 | function navigateToCategory(categoryId){ |
541 | if(categoryId === undefined){ | 549 | if(categoryId === undefined){ |
542 | display_category_tab(); | 550 | display_category_tab(); |
@@ -544,7 +552,29 @@ define(['handlebars'], function(Handlebars){ | @@ -544,7 +552,29 @@ define(['handlebars'], function(Handlebars){ | ||
544 | display_proposal_by_category('proposal-item-' + categoryId); | 552 | display_proposal_by_category('proposal-item-' + categoryId); |
545 | } | 553 | } |
546 | } | 554 | } |
547 | - | 555 | + |
556 | + function addVotedProposal(id) { | ||
557 | + var votedProposals; | ||
558 | + if (typeof($.cookie("votedProposals")) == "undefined"){ | ||
559 | + votedProposals = []; | ||
560 | + } | ||
561 | + else{ | ||
562 | + votedProposals = JSON.parse($.cookie("votedProposals")); | ||
563 | + } | ||
564 | + if (votedProposals.indexOf(id)==-1){ | ||
565 | + votedProposals.push(id); | ||
566 | + } | ||
567 | + $.cookie("votedProposals", JSON.stringify(votedProposals), {expires : 999 }) ; | ||
568 | + } | ||
569 | + | ||
570 | + function hasProposalbeenVoted(id) { | ||
571 | + if (typeof($.cookie("votedProposals")) == "undefined") { | ||
572 | + return false; | ||
573 | + } | ||
574 | + votedProposals = JSON.parse($.cookie("votedProposals")); | ||
575 | + return votedProposals.indexOf(id)!=-1; | ||
576 | + } | ||
577 | + | ||
548 | if('onhashchange' in window){ | 578 | if('onhashchange' in window){ |
549 | window.onhashchange = locationHashChanged; | 579 | window.onhashchange = locationHashChanged; |
550 | }else{ | 580 | }else{ |