Commit 80631186064bd17aa5d2e8898c3bfb822c171f88
- Diff rendering mode:
- inline
- side by side
swtr/static/css/swtmaker.css
(5 / 0)
  | |||
1 | 1 | #swt-maker { | |
2 | 2 | } | |
3 | #signinview { | ||
4 | margin 0 20px; | ||
5 | padding: 10px; | ||
6 | text-align: center; | ||
7 | } | ||
3 | 8 | #img-annotation-wrapper { | |
4 | 9 | margin: 30px auto 0 auto; | |
5 | 10 | /*border: 1px solid black;*/ |
swtr/static/js/swtmaker.js
(47 / 6)
  | |||
149 | 149 | //TODO: move this to a annotation view or something | |
150 | 150 | anno.removeAll(); | |
151 | 151 | _.each(swtr.sweets.models, function(swt) { | |
152 | swt.get('how')['editable'] = false; | ||
152 | if(!_.has(swt.get('how'), 'editable')) { | ||
153 | swt.get('how')['editable'] = false; | ||
154 | swt.get('how').text += '\n - by ' + swt.get('who'); | ||
155 | } | ||
153 | 156 | anno.addAnnotation(swt.get('how')); | |
154 | 157 | }); | |
155 | 158 | //console.log(swtr.sweets.toJSON()); | |
… | … | ||
164 | 164 | } | |
165 | 165 | }); | |
166 | 166 | this.cleanUp(); | |
167 | return false; | ||
167 | 168 | }, | |
168 | 169 | cleanUp: function() { | |
169 | console.log('cleaning up'); | ||
170 | //console.log('cleaning up'); | ||
170 | 171 | $(this.el).hide(); | |
171 | 172 | } | |
172 | 173 | }); | |
… | … | ||
176 | 176 | el: $('#swt-maker'), | |
177 | 177 | events: { | |
178 | 178 | 'click #img-url-submit': 'setImage', | |
179 | 'click #sweet': 'sweet' | ||
179 | 'click #sweet': 'sweet', | ||
180 | 'click #signin-credentials': 'getSignInCredentials' | ||
180 | 181 | }, | |
181 | 182 | initialize: function() { | |
182 | 183 | //var allElements = $('body *'); | |
… | … | ||
218 | 218 | getExistingAnnotations: function() { | |
219 | 219 | this.helpview.step(0); | |
220 | 220 | this.$overlay.show(); | |
221 | console.log('getting existing annotations of ', this.imgURL); | ||
221 | //console.log('getting existing annotations of ', this.imgURL); | ||
222 | 222 | swtr.sweets.getAll({ | |
223 | 223 | where: this.imgURL, | |
224 | 224 | success: function(data) { | |
… | … | ||
226 | 226 | swtr.sweets.add(data); | |
227 | 227 | _.each(data, function(swt) { | |
228 | 228 | swt.how['editable'] = false; | |
229 | swt.how.text+= '\n - by ' + swt.who; | ||
229 | swt.how.text += '\n - by ' + swt.who; | ||
230 | 230 | anno.addAnnotation(swt.how); | |
231 | 231 | }); | |
232 | 232 | swtr.appView.$overlay.hide(); | |
… | … | ||
235 | 235 | }, | |
236 | 236 | error: function(jqxhr, error, statusText) { | |
237 | 237 | if(jqxhr.status === 404) { //annotations don't exist for this image | |
238 | console.log('annotations don\'t exist for this image. Create one!'); | ||
238 | //console.log('annotations don\'t exist for this image. Create one!'); | ||
239 | 239 | } | |
240 | 240 | swtr.appView.$overlay.hide(); | |
241 | 241 | swtr.appView.helpview.step(2); | |
… | … | ||
266 | 266 | this.getSweets(); | |
267 | 267 | this.showSweets(); | |
268 | 268 | return false; | |
269 | }, | ||
270 | getSignInCredentials: function(event) { | ||
271 | event.preventDefault(); | ||
272 | if(swtr.who === 'Guest' && !$('#username').length) { | ||
273 | var template = _.template($('#signin-credentials-template').html()); | ||
274 | $('#signin-msg').html(template()); | ||
275 | } | ||
276 | else if($('#username').length && $('#username').val()) { | ||
277 | var username = $('#username').val(); | ||
278 | var password = $('#password').val(); | ||
279 | this.signIn(username, password); | ||
280 | } | ||
281 | return false; | ||
282 | }, | ||
283 | signIn: function(username, password) { | ||
284 | this.$overlay.show(); | ||
285 | $.ajax({ | ||
286 | url: swtr.swtstoreURL() + swtr.endpoints.auth, | ||
287 | type: 'POST', | ||
288 | data: {user: username, hash: password}, | ||
289 | success: function(data) { | ||
290 | swtr.appView.$overlay.hide(); | ||
291 | swtr.who = username; | ||
292 | $('#signinview').html('You are signed in.'); | ||
293 | }, | ||
294 | error: function(jqxhr, status, error) { | ||
295 | swtr.appView.$overlay.hide(); | ||
296 | if(error === 'FORBIDDEN') { | ||
297 | $('#signin-msg').html('Error signing in. Please check your username and password. '); | ||
298 | } | ||
299 | else { | ||
300 | $('#signin-msg').html('Error signin in. Please try again.'); | ||
301 | } | ||
302 | } | ||
303 | }); | ||
269 | 304 | } | |
270 | 305 | }); | |
271 | 306 | ||
… | … | ||
335 | 335 | break; | |
336 | 336 | } | |
337 | 337 | $(this.el).html(text); | |
338 | $(window).scrollTop(0, 0); | ||
338 | 339 | } | |
339 | 340 | }); | |
340 | 341 |
swtr/templates/index.html
(20 / 1)
  | |||
16 | 16 | ||
17 | 17 | <div id="swt-maker" class="container"> | |
18 | 18 | <div id="helpview" class="alert alert-info"></div> | |
19 | <div class="row" id="signinview"> | ||
20 | <form class="form-inline" role="form"> | ||
21 | <span id="signin-msg">You are not signed in. </span> | ||
22 | <button class="btn btn-sm btn-primary" id="signin-credentials"> | ||
23 | Sign In | ||
24 | </button> | ||
25 | </form> | ||
26 | </div> | ||
19 | 27 | <div id="img-input"> | |
20 | 28 | <div class="form-group"> | |
21 | 29 | <input type="text" placeholder="Enter URL of the image" | |
… | … | ||
52 | 52 | <script> | |
53 | 53 | window.swtr = window.swtr || {}; | |
54 | 54 | swtr.swtstoreURL = function() { return '{{ conf.swtstoreURL }}'; } | |
55 | swtr.endpoints = {'get': '/sweets/q', 'post': '/sweets'}; | ||
55 | swtr.endpoints = {'get': '/sweets/q', 'post': '/sweets', 'auth': | ||
56 | '/authenticate'}; | ||
56 | 57 | window.onload = function() { | |
57 | 58 | swtr.init(); | |
58 | 59 | }; | |
… | … | ||
71 | 71 | /<a href="<%= where %>"><%= where.substr(0, 30) + '...' %></a> | |
72 | 72 | <%= how %> | |
73 | 73 | </li> | |
74 | </script> | ||
75 | <script type="text/template" id="signin-credentials-template"> | ||
76 | <div class="form-group"> | ||
77 | <label class="sr-only" for="username">Username</label> | ||
78 | <input type="text" class="form-control" id="username" placeholder="Enter username"> | ||
79 | </div> | ||
80 | <div class="form-group"> | ||
81 | <label class="sr-only" for="password">Password</label> | ||
82 | <input type="password" class="form-control" id="password" placeholder="Password"> | ||
83 | </div> | ||
74 | 84 | </script> | |
75 | 85 | </body> | |
76 | 86 | </html> |