unserver-unify
Version:
121 lines (119 loc) • 4.38 kB
JavaScript
'use strict';
angular.module('bamboo.setting').controller('SchoolSignupCtrl', function($scope, ApiService, CommonService, loginService, $state, $timeout, formService,localStorageHelper,$localStorage) {
this.userCredentials = {};
this.company = {};
var self = this;
$scope.submitted = false;
this.wizardstep = 0;
this.maxstep = 0;
self.userCredentials = localStorageHelper.get("REGISTER_INFO_USER");
self.company = localStorageHelper.get("REGISTER_INFO_COMPANY");
console.log(self.userCredentials);
console.log(self.company);
console.log($localStorage);
this.backtostep = function(step) {
self.wizardstep = step;
if (self.wizardstep > self.maxstep) {
self.maxstep = self.wizardstep;
}
}
this.nextfrombasic = function(form) {
$scope.submitted = true;
console.log(form);
if (form.$invalid) {
$scope.shaking = true;
$timeout(function() {
$scope.shaking = false;
}, 500);
console.log(form.$invalid);
return;
}
$scope.submitted = false;
self.wizardstep = 1;
if (self.wizardstep > self.maxstep) {
self.maxstep = self.wizardstep;
}
console.log(self.userCredentials);
console.log(self.company);
}
this.nextform2 = function(form) {
$scope.submitted = true;
console.log(form);
if (form.$invalid) {
$scope.shaking = true;
$timeout(function() {
$scope.shaking = false;
}, 500);
console.log(form.$invalid);
return;
}
$scope.submitted = false;
self.wizardstep = 2;
if (self.wizardstep > self.maxstep) {
self.maxstep = self.wizardstep;
}
console.log(self.userCredentials);
console.log(self.company);
}
this.readTerm = function(){
console.log(self.userCredentials);
console.log(self.company);
localStorageHelper.put("REGISTER_INFO_USER",self.userCredentials);
localStorageHelper.put("REGISTER_INFO_COMPANY",self.company);
console.log($localStorage);
console.log(localStorageHelper.get("REGISTER_INFO_USER"));
console.log(localStorageHelper.get("REGISTER_INFO_COMPANY"));
$state.go("index.agreement");
}
this.registerWithCompany = function() {
$scope.submitted = true;
var info = self.userCredentials;
info.companyUser = true;
info.company = self.company;
info.url = ApiService.HOST + "/#/active_account";
info.ownername = loginService.school.name || "tianhang";
console.log(info);
ApiService.post('/signup', info).then(function(result) {
console.log(result);
if (result.data.success) {
CommonService.showInfo(" " + result.data.success);
$state.go('index.home');
} else {
CommonService.showError(result.data.error);
return;
}
});
};
this.register = function(flag) {
$scope.submitted = true;
this.userCredentials.user_profiles = formService.getFormData();
if (!flag) {
if ($scope.form.$invalid) {
$scope.shaking = true;
$timeout(function() {
$scope.shaking = false;
}, 500);
return;
}
}
var info = self.userCredentials;
//console.log(info);
if (info.pass != info.re_pass) {
CommonService.showError("Password not matched");
return;
}
info.url = ApiService.HOST + "#/active_account";
info.ownername = loginService.school.name;
console.log(info);
ApiService.post('/signup', info).then(function(result) {
//console.log(result);
if (result.data.success) {
CommonService.showInfo(" " + result.data.success);
$state.go('index.home');
} else {
CommonService.showError(result.data.error);
return;
}
});
};
});