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 | 80 | <div class='subtitle'>Qual a sua sugestão para melhorar este programa?</div> |
81 | 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 | 82 | <div class='send-proposal-button'><a href='#'>Envie Sua Proposta</a></div> |
83 | + <div class="login-container hide">Login</div> | |
83 | 84 | <form class='make-proposal-form hide' id='make-proposal-form-{{id}}'> |
85 | + <div class="message"></div> | |
84 | 86 | <div class="name"> |
85 | 87 | <div><label>Título</label></div> |
86 | 88 | <input id="article_name" name="article[name]" type="text" placeholder="Título"> |
... | ... | @@ -89,7 +91,6 @@ |
89 | 91 | <div><label>Descrição</label></div> |
90 | 92 | <textarea id="article_abstract" name="article[abstract]" placeholder="Descrição"></textarea> |
91 | 93 | </div> |
92 | - <input id='private_token' name='private_token' value='{{../private_token}}' type='hidden'> | |
93 | 94 | <input id='content_type' name='content_type' value='ProposalsDiscussionPlugin::Proposal' type='hidden'> |
94 | 95 | <input type='submit' id='make-proposal-button' class='make-proposal-button' name='make-proposal-button' value='Enviar'> |
95 | 96 | </form> |
... | ... | @@ -129,13 +130,31 @@ |
129 | 130 | </div> |
130 | 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 | 159 | <script src='js/main.js'></script> |
141 | 160 | </body> | ... | ... |
js/main.js
... | ... | @@ -5,12 +5,15 @@ var templateSource = document.getElementById('proposal-template').innerHTML; |
5 | 5 | var template = Handlebars.compile(templateSource); |
6 | 6 | |
7 | 7 | var supportProposalTemplate = Handlebars.compile(document.getElementById('support-proposal-template').innerHTML); |
8 | +var loginTemplate = Handlebars.compile(document.getElementById('login').innerHTML); | |
8 | 9 | |
9 | 10 | // The div/container that we are going to display the results in |
10 | 11 | var resultsPlaceholder = document.getElementById('proposal-result'); |
11 | 12 | |
12 | 13 | var topics; |
13 | 14 | |
15 | +var logged_in = false; | |
16 | + | |
14 | 17 | var participa = true; |
15 | 18 | if(participa){ |
16 | 19 | var host = 'http://www.participa.br'; |
... | ... | @@ -31,6 +34,7 @@ $.getJSON(noosferoAPI) |
31 | 34 | data['host'] = host; |
32 | 35 | data['private_token'] = private_token; |
33 | 36 | resultsPlaceholder.innerHTML = template(data); |
37 | + $('.login-container').html(loginTemplate()); | |
34 | 38 | //Actions for links |
35 | 39 | $( '#nav-proposal-categories a' ).click(function(event){ |
36 | 40 | //Display the category tab |
... | ... | @@ -62,6 +66,10 @@ $.getJSON(noosferoAPI) |
62 | 66 | $('.proposal-detail').hide(); |
63 | 67 | $('#' + item).show(); |
64 | 68 | |
69 | + $('.send-proposal-button').show(); | |
70 | + $('.make-proposal-form').hide(); | |
71 | + $('.login-container').hide(); | |
72 | + | |
65 | 73 | var topic_id = this.id.replace('\#',''); |
66 | 74 | loadRandomProposal(topic_id, private_token); |
67 | 75 | }); |
... | ... | @@ -82,35 +90,32 @@ $.getJSON(noosferoAPI) |
82 | 90 | } |
83 | 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 | 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 | 96 | $('.success-proposal-sent').hide(); |
97 | + loginCallback(logged_in); | |
95 | 98 | event.preventDefault(); |
96 | 99 | }); |
97 | 100 | |
98 | 101 | $('.make-proposal-form').submit(function (e) { |
99 | 102 | e.preventDefault(); |
100 | 103 | var proposal_id = this.id.split('-').pop(); |
104 | + var form = this; | |
101 | 105 | $.ajax({ |
102 | 106 | type: 'post', |
103 | 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 | 110 | .done(function( data ) { |
107 | - this.reset(); | |
111 | + form.reset(); | |
108 | 112 | $('.make-proposal-form').hide(); |
109 | 113 | $('.success-proposal-sent').show(); |
110 | 114 | }) |
111 | 115 | .fail(function( jqxhr, textStatus, error ) { |
112 | 116 | var err = textStatus + ", " + error; |
113 | 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 | 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 | 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 | +}); | ... | ... |