Guest User

Untitled

a guest
Jul 20th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. function SignInAssistant() {
  2. /* this is the creator function for your scene assistant object. It will be passed all the
  3. additional parameters (after the scene name) that were passed to pushScene. The reference
  4. to the scene controller (this.controller) has not be established yet, so any initialization
  5. that needs the scene controller should be done in the setup function below. */
  6. }
  7.  
  8. SignInAssistant.prototype.setup = function() {
  9. /* this function is for setup tasks that have to happen when the scene is first created */
  10.  
  11. /* use Mojo.View.render to render view templates and add them to the scene, if needed. */
  12.  
  13. /* setup widgets here */
  14.  
  15. /* add event handlers to listen to events from widgets */
  16. //this.userNameModel = {value: TM.prefs.username};
  17. this.userNameModel = {value: ''};
  18. this.controller.setupWidget("username", {
  19. hintText: "Type your username...",
  20. autoFocus: true,
  21. autoReplace: false,
  22. enterSubmits: false,
  23. textCase: Mojo.Widget.steModeLowerCase}, this.userNameModel);
  24. this.controller.setupWidget("password", {
  25. hintText: "Password...",
  26. autoReplace: false,
  27. enterSubmits: false}, this.passwordModel = {value: ""});
  28. this.buttonModel = {label: "", disabled: false};
  29. this.controller.setupWidget("sign-in-button", {}, this.buttonModel);
  30. this.signInHandler = this.signIn.bind(this);
  31. this.controller.listen("sign-in-button", Mojo.Event.tap, this.signInHandler);
  32. }
  33.  
  34. SignInAssistant.prototype.signIn = function() {
  35. this.controller.get('divButtonWrapper').addClassName('show-loader');
  36. TM.prefs.username = this.userNameModel.value;
  37. TM.prefs.password = this.passwordModel.value;
  38. this.successfulSignInHandler = this.signInSuccess.bind(this);
  39. this.failedSignInHandler = this.signInFailure.bind(this);
  40. Twitter.verifyCredentials({onSuccess: this.successfulSignInHandler, onFail: {status: 401, functionToCall: this.failedSignInHandler}});
  41. }
  42.  
  43. SignInAssistant.prototype.signInSuccess = function (transport){
  44. this.controller.get('divButtonWrapper').removeClassName('show-loader');
  45. //Saves the user object for later use if needed.
  46. TM.prefs.userInfo = transport.responseJSON;
  47. TM.cookie.storePrefs();
  48. //this.controller.showBanner('Thanks for signing in!', '', '');
  49. Mojo.Controller.appController.getActiveStageController('card').swapScene('home', {disableSceneScroller: true});
  50. }
  51.  
  52. SignInAssistant.prototype.signInFailure = function (transport){
  53. this.controller.get('divButtonWrapper').removeClassName('show-loader');
  54. this.controller.showBanner('Check your username/password', '', '');
  55. Mojo.View.advanceFocus(this.controller.get('divSignInFormWrapper'));
  56. }
  57.  
  58. SignInAssistant.prototype.activate = function(event) {
  59. /* put in event handlers here that should only be in effect when this scene is active. For
  60. example, key handlers that are observing the document */
  61. }
  62.  
  63.  
  64. SignInAssistant.prototype.deactivate = function(event) {
  65. /* remove any event handlers you added in activate and do any other cleanup that should happen before
  66. this scene is popped or another scene is pushed on top */
  67. this.controller.stopListening('sign-in-button', Mojo.Event.tap, this.signInHandler);
  68. }
  69.  
  70. SignInAssistant.prototype.cleanup = function(event) {
  71. /* this function should do any cleanup needed before the scene is destroyed as
  72. a result of being popped off the scene stack */
  73. //Mojo.Event.stopListening('sign-in-button', Mojo.Event.tap, this.signInHandler);
  74. }
Add Comment
Please, Sign In to add comment