|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2016 E2EMail authors. All rights reserved. |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +/** |
| 18 | + * @fileoverview controller for the authorization page. |
| 19 | + */ |
| 20 | +goog.provide('e2email.pages.authorization.AuthorizationCtrl'); |
| 21 | + |
| 22 | +goog.scope(function() { |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +/** |
| 27 | + * Authorization page controller. The view is launched if the application |
| 28 | + * discovers the user is not authorized to connect to Gmail but the user |
| 29 | + * is logged in to chrome, and |
| 30 | + * contains a method to launch the sign-in prcoess. If the sign-in flow |
| 31 | + * succeeds, it launches the setup view, otherwise it remains in this |
| 32 | + * view. |
| 33 | + * |
| 34 | + * @param {!angular.$location} $location the angular $location service. |
| 35 | + * @param {!e2email.components.translate.TranslateService} translateService |
| 36 | + * @param {!e2email.components.gmail.GmailService} gmailService |
| 37 | + * the gmail service. |
| 38 | + * @constructor |
| 39 | + * @ngInject |
| 40 | + * @export |
| 41 | + */ |
| 42 | +e2email.pages.authorization.AuthorizationCtrl = function( |
| 43 | + $location, translateService, gmailService) { |
| 44 | + /** @type {boolean} */ |
| 45 | + this.inProgress = false; |
| 46 | + /** |
| 47 | + * @private {!angular.$location} |
| 48 | + */ |
| 49 | + this.location_ = $location; |
| 50 | + /** |
| 51 | + * @private {!e2email.components.translate.TranslateService} |
| 52 | + */ |
| 53 | + this.translateService_ = translateService; |
| 54 | + /** |
| 55 | + * @private {!e2email.components.gmail.GmailService} |
| 56 | + */ |
| 57 | + this.gmailService_ = gmailService; |
| 58 | + /** |
| 59 | + * @type {?string} |
| 60 | + */ |
| 61 | + this.status = null; |
| 62 | +}; |
| 63 | + |
| 64 | +var AuthorizationCtrl = e2email.pages.authorization.AuthorizationCtrl; |
| 65 | + |
| 66 | + |
| 67 | +/** |
| 68 | + * Start the chrome OAuth signin-process. |
| 69 | + * @export |
| 70 | + */ |
| 71 | +AuthorizationCtrl.prototype.signIn = function() { |
| 72 | + this.inProgress = true; |
| 73 | + this.status = this.translateService_.getMessage('requestApprovalStatus'); |
| 74 | + |
| 75 | + this.gmailService_.signIn().then(goog.bind(function(approved) { |
| 76 | + if (approved) { |
| 77 | + this.status = null; |
| 78 | + this.location_.path('/setup'); |
| 79 | + } else { |
| 80 | + // stay where we are. |
| 81 | + this.status = this.translateService_.getMessage( |
| 82 | + 'approvalUnavailableStatus'); |
| 83 | + } |
| 84 | + }, this)).catch(goog.bind(function(err) { |
| 85 | + this.status = err.toString(); |
| 86 | + }, this)).finally(goog.bind(function() { |
| 87 | + this.inProgress = false; |
| 88 | + }, this)); |
| 89 | +}; |
| 90 | + |
| 91 | + |
| 92 | +/** |
| 93 | + * Returns the current status. |
| 94 | + * @return {?string} The status message. |
| 95 | + * @export |
| 96 | + */ |
| 97 | +AuthorizationCtrl.prototype.getStatus = function() { |
| 98 | + return this.status; |
| 99 | +}; |
| 100 | + |
| 101 | + |
| 102 | +/** |
| 103 | + * Returns whether there's an in-progress operation. |
| 104 | + * @return {boolean} returns true if there's an in-progress operation. |
| 105 | + * @export |
| 106 | + */ |
| 107 | +AuthorizationCtrl.prototype.isInProgress = function() { |
| 108 | + return this.inProgress; |
| 109 | +}; |
| 110 | + |
| 111 | + |
| 112 | +}); // goog.scope |
0 commit comments