Commit 72c499855cc31bc02274a89a6133a94f1915f68b
- Diff rendering mode:
- inline
- side by side
swtr/static/js/swtmaker.js
(31 / 5)
  | |||
7 | 7 | swtr.sweets = new ImgAnnoSwts(); | |
8 | 8 | swtr.appView = new AppView(); | |
9 | 9 | swtr.who = 'Guest'; | |
10 | |||
11 | $.ajaxSetup({ | ||
12 | xhrFields: { | ||
13 | withCredentials: true | ||
14 | }, | ||
15 | crossDomain: true | ||
16 | }); | ||
10 | 17 | }; | |
11 | 18 | ||
12 | 19 | /* Model for Image Annotation Sweets */ | |
… | … | ||
276 | 276 | }, | |
277 | 277 | getSignInCredentials: function(event) { | |
278 | 278 | event.preventDefault(); | |
279 | if(swtr.who === 'Guest' && !$('#username').length) { | ||
279 | navigator.id.request(); | ||
280 | /*if(swtr.who === 'Guest' && !$('#username').length) { | ||
280 | 281 | var template = _.template($('#signin-credentials-template').html()); | |
281 | 282 | $('#signin-msg').html(template()); | |
282 | 283 | } | |
… | … | ||
285 | 285 | var username = $('#username').val(); | |
286 | 286 | var password = $('#password').val(); | |
287 | 287 | this.signIn(username, password); | |
288 | } | ||
288 | }*/ | ||
289 | 289 | return false; | |
290 | 290 | }, | |
291 | 291 | signIn: function(username, password) { | |
… | … | ||
310 | 310 | } | |
311 | 311 | } | |
312 | 312 | }); | |
313 | }, | ||
314 | userLoggedIn: function(userData) { | ||
315 | swtr.who = userData.username; | ||
316 | var text = 'You are signed in as <b>' + swtr.who+ '</b>'; | ||
317 | $('#signinview').html(text); | ||
318 | }, | ||
319 | userLoggedOut: function() { | ||
320 | swtr.who = 'Guest'; | ||
321 | $('#signinview').html('Logged out'); | ||
313 | 322 | } | |
314 | 323 | }); | |
315 | 324 | ||
… | … | ||
362 | 362 | ||
363 | 363 | //swtr.AppView = AppView; | |
364 | 364 | ||
365 | /*navigator.watch({ | ||
365 | // Persona callbacks | ||
366 | navigator.id.watch({ | ||
367 | //when an user logs in | ||
366 | 368 | onlogin: function(assertion) { | |
369 | //verify assertion and login the user | ||
367 | 370 | $.ajax({ | |
368 | 371 | type: 'POST', | |
369 | 372 | url: swtr.swtstoreURL() + swtr.endpoints.login, | |
370 | 373 | data: {assertion: assertion}, | |
371 | success: function() { | ||
374 | success: function(data) { | ||
375 | console.log('user logged in', data); | ||
376 | swtr.appView.userLoggedIn(data); | ||
372 | 377 | }, | |
373 | 378 | error: function() { | |
374 | 379 | navigator.id.logout(); | |
375 | 380 | } | |
376 | 381 | }); | |
377 | 382 | }, | |
383 | //when an user logs out | ||
378 | 384 | onlogout: function() { | |
379 | 385 | $.ajax({ | |
380 | 386 | type: 'POST', | |
387 | //data: {email: swtr.who}, | ||
381 | 388 | url: swtr.swtstoreURL() + swtr.endpoints.logout, | |
382 | 389 | success: function() { | |
390 | console.log('user logged out'); | ||
391 | //swtr.appView.userLoggedOut(); | ||
383 | 392 | }, | |
384 | 393 | error: function() { | |
385 | 394 | } | |
386 | 395 | }); | |
387 | 396 | } | |
388 | });*/ | ||
397 | }); | ||
389 | 398 | ||
390 | 399 | })(swtr); |
swtr/templates/index.html
(2 / 1)
  | |||
53 | 53 | window.swtr = window.swtr || {}; | |
54 | 54 | swtr.swtstoreURL = function() { return '{{ conf.swtstoreURL }}'; } | |
55 | 55 | swtr.endpoints = {'get': '/sweets/q', 'post': '/sweets', 'auth': | |
56 | '/authenticate'}; | ||
56 | '/authenticate', 'login': '/auth/login', 'logout': '/auth/logout'}; | ||
57 | 57 | window.onload = function() { | |
58 | 58 | swtr.init(); | |
59 | 59 | }; | |
… | … | ||
64 | 64 | <script src="{{ url_for('static', filename='js/lib/backbone-1.0.0.min.js') }}"></script> | |
65 | 65 | <script src="{{ url_for('static', filename='js/lib/annotorious.debug.js') }}"></script> | |
66 | 66 | <!--script src="https://login.persona.org/include.js"></script--> | |
67 | <script src="{{ url_for('static', filename='js/lib/mozilla.persona.include.js') }}"></script> | ||
67 | 68 | <script src="{{ url_for('static', filename='js/swtmaker.js') }}"></script> | |
68 | 69 | ||
69 | 70 | <script type="text/template" id="sweet-template"> |