/app/monocle/controller/session.js
JavaScript | 343 lines | 307 code | 35 blank | 1 comment | 14 complexity | 77e211564e059470a4c6e9b785062f9e MD5 | raw file
- // Generated by CoffeeScript 1.7.1
- (function() {
- var SessionCtrl, contoller_login, controller_aside, controller_home, controller_login, controller_signup, controller_splash,
- __hasProp = {}.hasOwnProperty,
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
- SessionCtrl = (function(_super) {
- var afterNotification, balanceResponse, beforeSendUserInfo, budgetsResponse, currenciesResponse, errorRecoveryPassowrdResponse, errorResponse, helperTagsResponse, movementsResponse, registrationResponse, sendPasswordResponse, sessionResponse, userInfoResponse;
- __extends(SessionCtrl, _super);
- function SessionCtrl() {
- return SessionCtrl.__super__.constructor.apply(this, arguments);
- }
- SessionCtrl.prototype.events = {
- "load section#home": "onLoadHome",
- "load section#login": "onLoadLogin",
- "load section#signup": "onLoadSignup",
- "tap a[data-action=login]": "onLogin",
- "tap a[data-action=logout]": "onLogout",
- "tap a[data-action=create-account]": "onCreateAccount",
- "tap a[data-action=recovery]": "onRecoveryPassword",
- "tap a[data-action=recovery-password": "onSendPassword"
- };
- SessionCtrl.prototype.elements = {
- "#login_email": "login_email",
- "#login_password": "login_password",
- "#signup_email": "signup_email",
- "#signup_password": "signup_password",
- "#recovery_email": "recovery_email"
- };
- SessionCtrl.prototype.onSendPassword = function(event) {
- var post_data, result, url;
- console.log("onSendPassword");
- url = "http://www.whallet.com/api/v1/user/password.json";
- post_data = {
- email: this.recovery_email.val()
- };
- Lungo.Service.Settings.error = errorRecoveryPassowrdResponse;
- return result = Lungo.Service.post(url, post_data, sendPasswordResponse);
- };
- sendPasswordResponse = function(response) {
- console.log("sendPasswordResponse");
- return Lungo.Notification.success(Helpers.getTranslate('email_found'), Helpers.getTranslate("succes_restore_password"), "check", 3, afterNotification);
- };
- afterNotification = function() {
- return Lungo.Router.back();
- };
- SessionCtrl.prototype.onRecoveryPassword = function(event) {
- var template;
- console.log("onRecoveryPassword");
- template = "<form style=\"width: 100%\">";
- template += "<fieldset style=\"border-bottom: 2px solid #0093D5\">";
- template += "<span id=\"screen-input\" style=\"font-size: 1.4em; height:40px; margin-top:15px\" class=\"text thin left\">";
- template += "<abbr><input type=\"text\" id=\"emailRecovery\" placeholder=\"" + (Helpers.getTranslate("txtemail")) + "\"></abbr>";
- template += "</span></fieldset></form>";
- return Lungo.Notification.confirm({
- icon: '',
- title: Helpers.getTranslate("description_recovery"),
- description: template,
- accept: {
- icon: 'checkmark',
- label: Helpers.getTranslate("accept"),
- callback: function() {
- var inputScreen, post_data, result, url;
- inputScreen = Lungo.dom("#emailRecovery")[0].value;
- url = "http://www.whallet.com/api/v1/user/password.json";
- post_data = {
- email: inputScreen
- };
- Lungo.Service.Settings.error = errorRecoveryPassowrdResponse;
- return result = Lungo.Service.post(url, post_data, sendPasswordResponse);
- }
- },
- cancel: {
- icon: 'close',
- label: Helpers.getTranslate("cancel"),
- callback: null
- }
- });
- };
- SessionCtrl.prototype.onLoadSignup = function(event) {
- return console.log("onLoadSignup");
- };
- SessionCtrl.prototype.onLoadLogin = function(event) {
- var post_data, result, tokenStored, url;
- console.log("onLoadLogin");
- tokenStored = Lungo.Data.Storage.persistent("tokenAuth");
- if (tokenStored !== null) {
- url = "http://www.whallet.com/api/v1/helper/tags.json";
- post_data = {
- token: tokenStored
- };
- result = Lungo.Service.post(url, post_data, helperTagsResponse);
- return Lungo.Router.section("monitor");
- }
- };
- SessionCtrl.prototype.onLoadHome = function(event) {
- return console.log("onLoadHome");
- };
- SessionCtrl.prototype.onCreateAccount = function(event) {
- var post_data, result, url;
- console.log("onCreateAccount");
- url = "http://www.whallet.com/api/v1/registrations.json";
- post_data = {
- email: this.signup_email.val(),
- password: this.signup_password.val(),
- password_confirmation: this.signup_password.val(),
- locale: String.locale
- };
- Lungo.Service.Settings.error = errorResponse;
- return result = Lungo.Service.post(url, post_data, registrationResponse);
- };
- SessionCtrl.prototype.onLogout = function(event) {
- Lungo.Data.Storage.persistent("tokenAuth", null);
- Lungo.Data.Storage.persistent("user", null);
- Lungo.Data.Storage.persistent("userInfo", null);
- Lungo.Data.Storage.persistent("balances", null);
- Lungo.Data.Storage.persistent("movements", null);
- Lungo.Data.Storage.persistent("expenses", null);
- Lungo.Data.Storage.persistent("movementID", null);
- Lungo.Data.Storage.persistent("movementUID", null);
- Lungo.Data.Storage.persistent("budgetID", null);
- Lungo.Data.Storage.persistent("budgetUID", null);
- __Model.Movement.destroyAll();
- __Model.Spending.destroyAll();
- __Model.Balance.destroyAll();
- __Model.Tag.destroyAll();
- __Model.Budget.destroyAll();
- Lungo.dom("section#login #login_email").val("");
- Lungo.dom("section#login #login_password").val("");
- return Lungo.Router.section("home");
- };
- SessionCtrl.prototype.onLogin = function(event) {
- var post_data, result, tokenStored, url;
- console.log("onLogin");
- tokenStored = Lungo.Data.Storage.persistent("tokenAuth");
- Lungo.Notification.show();
- if (tokenStored === null) {
- url = "http://www.whallet.com/api/v1/tokens.json";
- post_data = {
- email: this.login_email.val(),
- password: this.login_password.val()
- };
- Lungo.Service.Settings.error = errorResponse;
- return result = Lungo.Service.post(url, post_data, sessionResponse);
- } else {
- Lungo.Data.Storage.persistent("tokenAuth", null);
- Lungo.Data.Storage.persistent("user", null);
- Lungo.Data.Storage.persistent("userInfo", null);
- Lungo.Data.Storage.persistent("balances", null);
- Lungo.Data.Storage.persistent("movements", null);
- Lungo.Data.Storage.persistent("expenses", null);
- Lungo.Data.Storage.persistent("movementID", null);
- Lungo.Data.Storage.persistent("movementUID", null);
- Lungo.Data.Storage.persistent("budgetID", null);
- Lungo.Data.Storage.persistent("budgetUID", null);
- Lungo.Data.Storage.persistent("budgets", null);
- __Model.Budget.destroyAll();
- __Model.Movement.destroyAll();
- __Model.Spending.destroyAll();
- __Model.Balance.destroyAll();
- __Model.Tag.destroyAll();
- return Lungo.Router.section("monitor");
- }
- };
- errorResponse = function(type, xhr) {
- console.log("errorResponse");
- console.log("xhr: %o", xhr);
- return Lungo.Notification.error(Helpers.getTranslate("error"), Helpers.getTranslate("login_error"), "cancel", 3, null);
- };
- errorRecoveryPassowrdResponse = function(type, xhr) {
- console.log("errorResponse");
- console.log("xhr: %o", xhr);
- return Lungo.Notification.error(Helpers.getTranslate("email_not_found"), Helpers.getTranslate("something_wrong"), "cancel", 3, null);
- };
- registrationResponse = function(response) {
- var post_data, result, url;
- console.log("registrationResponse");
- console.log(response);
- url = "http://www.whallet.com/api/v1/tokens.json";
- post_data = {
- email: Lungo.dom("section#signup #signup_email").val(),
- password: Lungo.dom("section#signup #signup_password").val()
- };
- return result = Lungo.Service.post(url, post_data, sessionResponse);
- };
- sessionResponse = function(response) {
- var date, email, post_data, result, url;
- console.log("sessionResponse");
- if (response.token != null) {
- date = new Date();
- Lungo.Data.Storage.persistent("dateSelected", null);
- Lungo.Data.Storage.persistent("dateSelected", date);
- Lungo.Data.Storage.persistent("tokenAuth", response.token);
- email = Lungo.dom("section#login #login_email").val();
- Lungo.Data.Storage.persistent("user", email);
- url = "http://www.whallet.com/api/v1/helper/tags.json";
- post_data = {
- token: response.token
- };
- result = Lungo.Service.post(url, post_data, helperTagsResponse);
- url = "http://www.whallet.com/api/v1/user/info.json";
- post_data = {
- token: response.token
- };
- result = Lungo.Service.post(url, post_data, userInfoResponse);
- url = "http://www.whallet.com/api/v1/dashboard/balance.json";
- post_data = {
- token: response.token
- };
- result = Lungo.Service.post(url, post_data, balanceResponse);
- Lungo.Data.Storage.persistent("movements", null);
- url = "http://www.whallet.com/api/v1/movements.json";
- post_data = {
- token: response.token,
- year: date.getFullYear(),
- month: date.getMonth() + 1
- };
- result = Lungo.Service.post(url, post_data, movementsResponse);
- Lungo.Data.Storage.persistent("budgets", null);
- url = "http://www.whallet.com/api/v1/budget/list.json";
- post_data = {
- token: response.token
- };
- return result = Lungo.Service.get(url, post_data, budgetsResponse);
- } else {
- return Lungo.Notification.error(Helpers.getTranslate("error"), Helpers.getTranslate("login_error"), "cancel", 3, null);
- }
- };
- movementsResponse = function(response) {
- console.log("Splash.movementsResponse");
- return WhalletMovements.loadFromResponse(response);
- };
- budgetsResponse = function(response) {
- console.log("Splash.budgetsResponse");
- return WhalletBudgets.loadFromResponse(response);
- };
- balanceResponse = function(response) {
- var balanceModel, dataResponse, _i, _len;
- console.log("Splash.balanceResponse");
- __Model.Balance.destroyAll();
- for (_i = 0, _len = response.length; _i < _len; _i++) {
- dataResponse = response[_i];
- balanceModel = new __Model.Balance;
- balanceModel.date = dataResponse.date;
- balanceModel.expense = dataResponse.data.expense;
- balanceModel.income = dataResponse.data.income;
- balanceModel.balance = dataResponse.data.balance;
- balanceModel.save();
- }
- return Lungo.Router.section("monitor");
- };
- helperTagsResponse = function(response) {
- var dataResponse, tag, tagModel, _i, _len, _results;
- console.log("helperTagsResponse");
- _results = [];
- for (_i = 0, _len = response.length; _i < _len; _i++) {
- dataResponse = response[_i];
- _results.push((function() {
- var _j, _len1, _ref, _results1;
- _ref = dataResponse.tags;
- _results1 = [];
- for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
- tag = _ref[_j];
- _results1.push(tagModel = __Model.Tag.create({
- description: tag.name,
- category: dataResponse.category
- }));
- }
- return _results1;
- })());
- }
- return _results;
- };
- beforeSendUserInfo = function(request) {
- return console.log("beforeSendUserInfo");
- };
- userInfoResponse = function(response) {
- var post_data, result, url;
- console.log("userInfoResponse");
- if (response != null) {
- String.locale = response.locale;
- Helpers.updateAllTranslateElement();
- Lungo.Data.Storage.persistent("userInfo", null);
- Lungo.Data.Storage.persistent("userInfo", response);
- if (User.isPro()) {
- Lungo.dom('li#donate').addClass("hidden");
- }
- Android.hideAd();
- Lungo.Data.Storage.persistent("currencies", null);
- url = "http://www.whallet.com/api/v1/helper/currencies.json";
- post_data = {
- locale: response.locale
- };
- return result = Lungo.Service.get(url, post_data, currenciesResponse);
- }
- };
- currenciesResponse = function(response) {
- console.log("currenciesResponse");
- return Lungo.Data.Storage.persistent("currencies", response);
- };
- return SessionCtrl;
- })(Monocle.Controller);
- contoller_login = new SessionCtrl("section#recovery");
- controller_login = new SessionCtrl("section#login");
- controller_signup = new SessionCtrl("section#signup");
- controller_home = new SessionCtrl("section#home");
- controller_splash = new SessionCtrl("section#splash");
- controller_aside = new SessionCtrl("aside#options");
- }).call(this);