Commit 2cc616fc664db976d687cace8632988a1e3a8c48
1 parent
b0ca0333
Exists in
master
and in
11 other branches
Require login to send a new proposal
Showing
2 changed files
with
72 additions
and
18 deletions
Show diff stats
index.html
@@ -80,7 +80,9 @@ | @@ -80,7 +80,9 @@ | ||
80 | <div class='subtitle'>Qual a sua sugestão para melhorar este programa?</div> | 80 | <div class='subtitle'>Qual a sua sugestão para melhorar este programa?</div> |
81 | <div class='info'>Ela se tornará pública em até 24 horas após o envio e poderá ser apoiada por outros participantes.</div> | 81 | <div class='info'>Ela se tornará pública em até 24 horas após o envio e poderá ser apoiada por outros participantes.</div> |
82 | <div class='send-proposal-button'><a href='#'>Envie Sua Proposta</a></div> | 82 | <div class='send-proposal-button'><a href='#'>Envie Sua Proposta</a></div> |
83 | + <div class="login-container hide">Login</div> | ||
83 | <form class='make-proposal-form hide' id='make-proposal-form-{{id}}'> | 84 | <form class='make-proposal-form hide' id='make-proposal-form-{{id}}'> |
85 | + <div class="message"></div> | ||
84 | <div class="name"> | 86 | <div class="name"> |
85 | <div><label>Título</label></div> | 87 | <div><label>Título</label></div> |
86 | <input id="article_name" name="article[name]" type="text" placeholder="Título"> | 88 | <input id="article_name" name="article[name]" type="text" placeholder="Título"> |
@@ -89,7 +91,6 @@ | @@ -89,7 +91,6 @@ | ||
89 | <div><label>Descrição</label></div> | 91 | <div><label>Descrição</label></div> |
90 | <textarea id="article_abstract" name="article[abstract]" placeholder="Descrição"></textarea> | 92 | <textarea id="article_abstract" name="article[abstract]" placeholder="Descrição"></textarea> |
91 | </div> | 93 | </div> |
92 | - <input id='private_token' name='private_token' value='{{../private_token}}' type='hidden'> | ||
93 | <input id='content_type' name='content_type' value='ProposalsDiscussionPlugin::Proposal' type='hidden'> | 94 | <input id='content_type' name='content_type' value='ProposalsDiscussionPlugin::Proposal' type='hidden'> |
94 | <input type='submit' id='make-proposal-button' class='make-proposal-button' name='make-proposal-button' value='Enviar'> | 95 | <input type='submit' id='make-proposal-button' class='make-proposal-button' name='make-proposal-button' value='Enviar'> |
95 | </form> | 96 | </form> |
@@ -129,13 +130,31 @@ | @@ -129,13 +130,31 @@ | ||
129 | </div> | 130 | </div> |
130 | </script> | 131 | </script> |
131 | 132 | ||
132 | - <div id='proposal-result'></div> | 133 | + <script id='login' type='text/x-handlebars-template'> |
134 | + <form class="login"> | ||
135 | + <div class="message"></div> | ||
136 | + <div class="username"> | ||
137 | + <div class="label">Nome de Usuário / E-mail:</div> | ||
138 | + <input id="user_name" name="login" type="text" placeholder="Nome do usuário / E-mail"> | ||
139 | + </div> | ||
140 | + <div class="password"> | ||
141 | + <div class="label">Senha:</div> | ||
142 | + <input id="user_password" name="password" type="password" placeholder="Senha"> | ||
143 | + </div> | ||
144 | + <div class="actions"> | ||
145 | + <a href="http://www.participa.br/account/forgot_password" target="_blank" class="forgot-password">Esqueci minha senha</a> | ||
146 | + <a href="#" class="login-action">Acessar</a> | ||
147 | + </div> | ||
148 | + <div class="oauth"> | ||
149 | + <div class="label">Acessar com:</div> | ||
150 | + <a href="/plugin/oauth_client/facebook?oauth_client_popup=true&id=1" target="_blank" class="facebook">Facebook</a> | ||
151 | + <a href="/plugin/oauth_client/google_oauth2?oauth_client_popup=true&id=2" target="_blank" class="google">Google +</a> | ||
152 | + <a href="http://www.participa.br/account/signup" target="_blank" class="new-user">Cadastrar</a> | ||
153 | + </div> | ||
154 | + </form> | ||
155 | + </script> | ||
133 | 156 | ||
134 | - <div id="login" style="display: none"> | ||
135 | - <a href="/plugin/oauth_client/google_oauth2?oauth_client_popup=true&id=2" target="_blank" class="google">Google</a> | ||
136 | - <a href="/plugin/oauth_client/facebook?oauth_client_popup=true&id=1" target="_blank" class="facebook">Facebook</a> | ||
137 | - <a href="/plugin/oauth_client/noosfero_oauth2?oauth_client_popup=true&id=3" target="_blank" class="participa">Participa</a> | ||
138 | - </div> | 157 | + <div id='proposal-result'></div> |
139 | 158 | ||
140 | <script src='js/main.js'></script> | 159 | <script src='js/main.js'></script> |
141 | </body> | 160 | </body> |
js/main.js
@@ -5,12 +5,15 @@ var templateSource = document.getElementById('proposal-template').innerHTML; | @@ -5,12 +5,15 @@ var templateSource = document.getElementById('proposal-template').innerHTML; | ||
5 | var template = Handlebars.compile(templateSource); | 5 | var template = Handlebars.compile(templateSource); |
6 | 6 | ||
7 | var supportProposalTemplate = Handlebars.compile(document.getElementById('support-proposal-template').innerHTML); | 7 | var supportProposalTemplate = Handlebars.compile(document.getElementById('support-proposal-template').innerHTML); |
8 | +var loginTemplate = Handlebars.compile(document.getElementById('login').innerHTML); | ||
8 | 9 | ||
9 | // The div/container that we are going to display the results in | 10 | // The div/container that we are going to display the results in |
10 | var resultsPlaceholder = document.getElementById('proposal-result'); | 11 | var resultsPlaceholder = document.getElementById('proposal-result'); |
11 | 12 | ||
12 | var topics; | 13 | var topics; |
13 | 14 | ||
15 | +var logged_in = false; | ||
16 | + | ||
14 | var participa = true; | 17 | var participa = true; |
15 | if(participa){ | 18 | if(participa){ |
16 | var host = 'http://www.participa.br'; | 19 | var host = 'http://www.participa.br'; |
@@ -31,6 +34,7 @@ $.getJSON(noosferoAPI) | @@ -31,6 +34,7 @@ $.getJSON(noosferoAPI) | ||
31 | data['host'] = host; | 34 | data['host'] = host; |
32 | data['private_token'] = private_token; | 35 | data['private_token'] = private_token; |
33 | resultsPlaceholder.innerHTML = template(data); | 36 | resultsPlaceholder.innerHTML = template(data); |
37 | + $('.login-container').html(loginTemplate()); | ||
34 | //Actions for links | 38 | //Actions for links |
35 | $( '#nav-proposal-categories a' ).click(function(event){ | 39 | $( '#nav-proposal-categories a' ).click(function(event){ |
36 | //Display the category tab | 40 | //Display the category tab |
@@ -62,6 +66,10 @@ $.getJSON(noosferoAPI) | @@ -62,6 +66,10 @@ $.getJSON(noosferoAPI) | ||
62 | $('.proposal-detail').hide(); | 66 | $('.proposal-detail').hide(); |
63 | $('#' + item).show(); | 67 | $('#' + item).show(); |
64 | 68 | ||
69 | + $('.send-proposal-button').show(); | ||
70 | + $('.make-proposal-form').hide(); | ||
71 | + $('.login-container').hide(); | ||
72 | + | ||
65 | var topic_id = this.id.replace('\#',''); | 73 | var topic_id = this.id.replace('\#',''); |
66 | loadRandomProposal(topic_id, private_token); | 74 | loadRandomProposal(topic_id, private_token); |
67 | }); | 75 | }); |
@@ -82,35 +90,32 @@ $.getJSON(noosferoAPI) | @@ -82,35 +90,32 @@ $.getJSON(noosferoAPI) | ||
82 | } | 90 | } |
83 | event.preventDefault(); | 91 | event.preventDefault(); |
84 | }); | 92 | }); |
85 | - $( '.send-proposal-button a' ).click(function(event){ | ||
86 | - //Display Topics or Discussion by category | ||
87 | - $('.make-proposal-form').show(); | 93 | + $( '.send-proposal-button a, .success-proposal-sent a' ).click(function(event){ |
94 | + //display form to send proposal (or login form for non-logged users) | ||
88 | $('.send-proposal-button').hide(); | 95 | $('.send-proposal-button').hide(); |
89 | - event.preventDefault(); | ||
90 | - }); | ||
91 | - $( '.success-proposal-sent a' ).click(function(event){ | ||
92 | - //Display Topics or Discussion by category | ||
93 | - $('.make-proposal-form').show(); | ||
94 | $('.success-proposal-sent').hide(); | 96 | $('.success-proposal-sent').hide(); |
97 | + loginCallback(logged_in); | ||
95 | event.preventDefault(); | 98 | event.preventDefault(); |
96 | }); | 99 | }); |
97 | 100 | ||
98 | $('.make-proposal-form').submit(function (e) { | 101 | $('.make-proposal-form').submit(function (e) { |
99 | e.preventDefault(); | 102 | e.preventDefault(); |
100 | var proposal_id = this.id.split('-').pop(); | 103 | var proposal_id = this.id.split('-').pop(); |
104 | + var form = this; | ||
101 | $.ajax({ | 105 | $.ajax({ |
102 | type: 'post', | 106 | type: 'post', |
103 | url: host + '/api/v1/articles/' + proposal_id + '/children', | 107 | url: host + '/api/v1/articles/' + proposal_id + '/children', |
104 | - data: $('#'+this.id).serialize() | 108 | + data: $('#'+this.id).serialize() + "&private_token="+private_token |
105 | }) | 109 | }) |
106 | .done(function( data ) { | 110 | .done(function( data ) { |
107 | - this.reset(); | 111 | + form.reset(); |
108 | $('.make-proposal-form').hide(); | 112 | $('.make-proposal-form').hide(); |
109 | $('.success-proposal-sent').show(); | 113 | $('.success-proposal-sent').show(); |
110 | }) | 114 | }) |
111 | .fail(function( jqxhr, textStatus, error ) { | 115 | .fail(function( jqxhr, textStatus, error ) { |
112 | var err = textStatus + ", " + error; | 116 | var err = textStatus + ", " + error; |
113 | console.log( "Request Failed: " + err ); | 117 | console.log( "Request Failed: " + err ); |
118 | + $('.make-proposal-form .message').text('Não foi possível enviar sua proposta.'); | ||
114 | }); | 119 | }); |
115 | }); | 120 | }); |
116 | 121 | ||
@@ -149,6 +154,36 @@ function loadRandomProposal(topic_id, private_token) { | @@ -149,6 +154,36 @@ function loadRandomProposal(topic_id, private_token) { | ||
149 | }); | 154 | }); |
150 | } | 155 | } |
151 | 156 | ||
157 | +function loginCallback(loggedIn, token) { | ||
158 | + logged_in = loggedIn; | ||
159 | + $('.login .message').text(''); | ||
160 | + | ||
161 | + if(logged_in) { | ||
162 | + if(token) private_token = token; | ||
163 | + $('.make-proposal-form').show(); | ||
164 | + $('.make-proposal-form .message').text(''); | ||
165 | + $('.login-container').hide(); | ||
166 | + } else { | ||
167 | + $('.make-proposal-form').hide(); | ||
168 | + $('.login-container').show(); | ||
169 | + } | ||
170 | +} | ||
171 | + | ||
152 | function oauthPluginHandleLoginResult(loggedIn, token) { | 172 | function oauthPluginHandleLoginResult(loggedIn, token) { |
153 | - private_token = token; | 173 | + loginCallback(loggedIn, token); |
154 | } | 174 | } |
175 | + | ||
176 | +jQuery(document).ready(function($) { | ||
177 | + $(document).on('click', '.login-action', function(e) { | ||
178 | + $.ajax({ | ||
179 | + type: 'post', | ||
180 | + url: host + '/api/v1/login', | ||
181 | + data: $(this).parents('.login').serialize(), | ||
182 | + }).done(function(data) { | ||
183 | + loginCallback(true, data.private_token); | ||
184 | + }).fail(function(data) { | ||
185 | + $('.login .message').text('Não foi possível logar'); | ||
186 | + }); | ||
187 | + e.preventDefault(); | ||
188 | + }); | ||
189 | +}); |