svetlai

Untitled

Feb 18th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. var observable = require("data/observable");
  4. var validationModule = require("~/common/validate");
  5. var accountServiceModule = require("~/data/account-service");
  6. var helperModule = require("~/common/helper");
  7.  
  8. var ProfileViewModel = (function (_super) {
  9.     __extends(ProfileViewModel, _super);
  10.  
  11.     function ProfileViewModel() {
  12.         _super.call(this);
  13.         this._username = '';
  14.         this._email = '';
  15.         this._imageUrl = '';
  16.         this._location = {
  17.             latitude: '',
  18.             longitude: ''
  19.         };
  20.         this._firstName = '';
  21.         this._lastName = '';
  22.         this._score = 0;
  23.  
  24.         //accountServiceModule.getProfile(getProfileSuccess, helperModule.handleHttpRequestError);
  25.  
  26.         return this;
  27.     }
  28.  
  29.     Object.defineProperty(ProfileViewModel.prototype, "username", {
  30.         get: function () {
  31.             return this._username;
  32.         },
  33.         set: function (value) {
  34.             return;
  35.         }
  36.     });
  37.  
  38.     Object.defineProperty(ProfileViewModel.prototype, "email", {
  39.         get: function () {
  40.             return this._email;
  41.         },
  42.         set: function (value) {
  43.             return;
  44.         }
  45.     });
  46.  
  47.     Object.defineProperty(ProfileViewModel.prototype, 'firstName', {
  48.         get: function () {
  49.             return this._firstName;
  50.         },
  51.         set: function (value) {
  52.             this._firstName = value;
  53.         }
  54.     });
  55.  
  56.     Object.defineProperty(ProfileViewModel.prototype, 'lastName', {
  57.         get: function () {
  58.             return this._lastName;
  59.         },
  60.         set: function (value) {
  61.             this._lastName = value;
  62.         }
  63.     });
  64.  
  65.     Object.defineProperty(ProfileViewModel.prototype, 'imageUrl', {
  66.         get: function () {
  67.             return this._imageUrl;
  68.         },
  69.         set: function (value) {
  70.             this._imageUrl = value;
  71.         }
  72.     });
  73.  
  74.     Object.defineProperty(ProfileViewModel.prototype, 'location', {
  75.         get: function () {
  76.             return this._location;
  77.         },
  78.         set: function (value) {
  79.             this._location = value;
  80.         }
  81.     });
  82.  
  83.     Object.defineProperty(ProfileViewModel.prototype, 'score', {
  84.         get: function () {
  85.             return this._score;
  86.         },
  87.         set: function (value) {
  88.             this._score = value;
  89.         }
  90.     });
  91.  
  92.  
  93.     ProfileViewModel.prototype = {
  94.  
  95.         get: function(){
  96.             return accountServiceModule.getProfile(getProfileSuccess, helperModule.handleHttpRequestError);
  97.         }
  98.  
  99.         //registerTap: function () {
  100.         //    var self = this;
  101.         //    var isEmailValid = validationModule.isValidEmail(self.email);
  102.         //    if (!isEmailValid) {
  103.         //        alert('The email is incorrect.');
  104.         //        return;
  105.         //    }
  106.         //
  107.         //    var isPasswordValid = validationModule.isValidPassword(self.password);
  108.         //    var isConfirmPasswordValid = validationModule.isValidPassword(self.confirmPassword);
  109.         //    if (!isPasswordValid || !isConfirmPasswordValid) {
  110.         //        alert('The password is incorrect.');
  111.         //        return;
  112.         //    }
  113.         //
  114.         //    if (!validationModule.passwordsMatch(self.password, self.confirmPassword)) {
  115.         //        alert('The password and confirmation password do not match.');
  116.         //        return;
  117.         //    }
  118.         //
  119.         //    return accountServiceModule.register(self, registerSuccess, helperModule.handleHttpRequestError);
  120.         //    //alert("Signing in");
  121.         //    //console.log(email);
  122.         //
  123.         //    //if (!app.connectionApi.hasConnection()) {
  124.         //    //    app.notificationsApi.beep(1);
  125.         //    //    app.notifier.error('Please check your connection before register...');
  126.         //    //    return;
  127.         //    //}
  128.         //},
  129.         //
  130.         //toLogin: function () {
  131.         //    helperModule.navigateAnimated("./views/login/login");
  132.         //},
  133.         //
  134.         //toMain: function () {
  135.         //    helperModule.navigateAnimated("./views/main/main");
  136.         //}
  137.     };
  138.  
  139.     //function registerSuccess(response) {
  140.     //    helperModule.notify('Successfully registered!');
  141.     //    helperModule.navigateAnimated("./views/login/login");
  142.     //}
  143.  
  144.  
  145.     return ProfileViewModel;
  146. }(observable.Observable));
  147.  
  148. accountServiceModule.getProfile(getProfileSuccess, helperModule.handleHttpRequestError);
  149.  
  150. function getProfileSuccess(response) {
  151.     mapResponseToViewModel(response);
  152.     console.log('success', JSON.stringify(response));
  153. }
  154.  
  155. function mapResponseToViewModel(response){
  156.     //ProfileViewModel.set('firstName', response.content.toJSON()['FirstName']);
  157.     ProfileViewModel.lastName = response.content.toJSON()['LastName'];
  158.     ProfileViewModel.username = response.content.toJSON()['Username'];
  159.     ProfileViewModel.set('email', response.content.toJSON()['Email']);
  160.     ProfileViewModel.imageUrl = response.content.toJSON()['ImageUrl'];
  161.     ProfileViewModel.location = response.content.toJSON()['Location'];
  162.     ProfileViewModel.score = response.content.toJSON()['Score'];
  163.  
  164.     return ProfileViewModel;
  165. }
  166. exports.ProfileViewModel = ProfileViewModel;
Add Comment
Please, Sign In to add comment