Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function SignInAssistant() {
- /* this is the creator function for your scene assistant object. It will be passed all the
- additional parameters (after the scene name) that were passed to pushScene. The reference
- to the scene controller (this.controller) has not be established yet, so any initialization
- that needs the scene controller should be done in the setup function below. */
- }
- SignInAssistant.prototype.setup = function() {
- /* this function is for setup tasks that have to happen when the scene is first created */
- /* use Mojo.View.render to render view templates and add them to the scene, if needed. */
- /* setup widgets here */
- /* add event handlers to listen to events from widgets */
- //this.userNameModel = {value: TM.prefs.username};
- this.userNameModel = {value: ''};
- this.controller.setupWidget("username", {
- hintText: "Type your username...",
- autoFocus: true,
- autoReplace: false,
- enterSubmits: false,
- textCase: Mojo.Widget.steModeLowerCase}, this.userNameModel);
- this.controller.setupWidget("password", {
- hintText: "Password...",
- autoReplace: false,
- enterSubmits: false}, this.passwordModel = {value: ""});
- this.buttonModel = {label: "", disabled: false};
- this.controller.setupWidget("sign-in-button", {}, this.buttonModel);
- this.signInHandler = this.signIn.bind(this);
- this.controller.listen("sign-in-button", Mojo.Event.tap, this.signInHandler);
- }
- SignInAssistant.prototype.signIn = function() {
- this.controller.get('divButtonWrapper').addClassName('show-loader');
- TM.prefs.username = this.userNameModel.value;
- TM.prefs.password = this.passwordModel.value;
- this.successfulSignInHandler = this.signInSuccess.bind(this);
- this.failedSignInHandler = this.signInFailure.bind(this);
- Twitter.verifyCredentials({onSuccess: this.successfulSignInHandler, onFail: {status: 401, functionToCall: this.failedSignInHandler}});
- }
- SignInAssistant.prototype.signInSuccess = function (transport){
- this.controller.get('divButtonWrapper').removeClassName('show-loader');
- //Saves the user object for later use if needed.
- TM.prefs.userInfo = transport.responseJSON;
- TM.cookie.storePrefs();
- //this.controller.showBanner('Thanks for signing in!', '', '');
- Mojo.Controller.appController.getActiveStageController('card').swapScene('home', {disableSceneScroller: true});
- }
- SignInAssistant.prototype.signInFailure = function (transport){
- this.controller.get('divButtonWrapper').removeClassName('show-loader');
- this.controller.showBanner('Check your username/password', '', '');
- Mojo.View.advanceFocus(this.controller.get('divSignInFormWrapper'));
- }
- SignInAssistant.prototype.activate = function(event) {
- /* put in event handlers here that should only be in effect when this scene is active. For
- example, key handlers that are observing the document */
- }
- SignInAssistant.prototype.deactivate = function(event) {
- /* remove any event handlers you added in activate and do any other cleanup that should happen before
- this scene is popped or another scene is pushed on top */
- this.controller.stopListening('sign-in-button', Mojo.Event.tap, this.signInHandler);
- }
- SignInAssistant.prototype.cleanup = function(event) {
- /* this function should do any cleanup needed before the scene is destroyed as
- a result of being popped off the scene stack */
- //Mojo.Event.stopListening('sign-in-button', Mojo.Event.tap, this.signInHandler);
- }
Add Comment
Please, Sign In to add comment