/*  setting module */
app.service('SettingService', [ function(){
	return {
		 changePass: function(oldPass, newPass){
		 	// TODO
		 }
	};
}]);

app.controller('SettingController', ['$scope', '$timeout', 'SettingService', function($scope,$timeout,settingS){
	$scope.logout = function(){
		$scope.goState('login');
	};
	$scope.goSettingPage = function(item){
		item.selected = true;
		$timeout(function(){
			item.selected = false;
	        $scope.goState(item.state); 
	    }, 100);
	};
	$scope.settingBottomItems = [
		{
			icon: 'ion-gear-b',
			text: '意见反馈',
			cssId: 'setting-tip-line',
			state: 'app.setting.feedback',
			showRight: false,
			selected: false
		},
		{
			icon: 'ion-gear-b',
			text: '关于我们',
			cssId: 'setting-about-line',
			state: 'app.setting.aboutus',
			showRight: false,
			selected: false
		}
	];
	$scope.settingTopItems = [
		{
			icon: 'ion-gear-b',
			text: '修改密码',
			cssId: 'setting-changepass-line',
			state: 'app.setting.changepass',
			showRight: true,
			selected: false
		},
		{
			icon: 'ion-gear-b',
			text: '认证中心',
			cssId: 'setting-certify-line',
			state: 'app.setting.certify',
			showRight: true,
			selected: false
		}
	];

	/**
	* 修改密码页面相关代码 
	*/
	$scope.pass = {
		oldPass: '',
		newPass: '',
		newPass2: '',
		changedOk: false
	};
	$scope.couldConfirmChangePass = function(){
		if(!$scope.pass.oldPass || !$scope.pass.newPass || !$scope.pass.newPass2){
			return false;
		}
		if($scope.pass.oldPass!="" && $scope.pass.newPass!="" && $scope.pass.newPass2!=""){
			if($scope.pass.newPass.trim() == $scope.pass.newPass2.trim()){
				return true;
			}
		}
	};
	$scope.confirmChangePass = function(){
		$scope.showLoading();
		$timeout(function(){
			var promise = settingS.changePass($scope.pass.oldPass, $scope.pass.newPass);
			$scope.pass.changedOk = true;
			$scope.hideLoading();
		}, 2000);
	};
	$scope.changePassAgin = function(){
		$scope.pass.changedOk = false;
	};
	$scope.loginAgin = function(){
		$scope.goState("login");
	};


	/**
	* 反馈意见页面相关代码 
	*/
	$scope.feedback = {
		feedbackStr : '',
		qq: '',
		cellphone: '',
		submitOk: false
	};
	$scope.submitFeedback = function(){
		$scope.showLoading();
		$timeout(function(){
			$scope.feedback.submitOk = true;
			$scope.hideLoading();
		},2000);
	};
	$scope.feedbackAgin = function(){
		$scope.feedback.submitOk = false;
	};


	$scope.init = function(){
		for (var i = $scope.settingTopItems.length - 1; i >= 0; i--) {
			$scope.settingItems[i].selected = false;
		};
		for (var i = $scope.settingBottomItems.length - 1; i >= 0; i--) {
			$scope.settingItems[i].selected = false;
		};
	};
	//$scope.init();
}]);