mood-panel.js

angular.module('homepage').
directive('moodPanel', function () {
	return {
		controller: 'moodPanelController',
		restrict: 'E',
		replace: true,
		scope: {
			mood: '='
		},
		templateUrl: 'components/feature-components/mood/mood-panel.html'
	};
}).
controller('moodPanelController', function ($scope, $timeout) {
	var moodsList = [
		{ level: -3, name: 'very low', btnClass: 'btn-danger'},
		{ level: -2, name: 'low', btnClass: 'btn-warning'},
		{ level: -1, name: 'bad', btnClass: 'btn-warn'},
		{ level: 0, name: 'neutral', btnClass: 'btn-grey'},
		{ level: 1, name: 'good', btnClass: 'btn-mild'},
		{ level: 2, name: 'high', btnClass: 'btn-info'},
		{ level: 3, name: 'very high', btnClass: 'btn-primary'}
	];
	var feelingList = {
		veryhigh: 	[
			{ name:'Determined', code: 'DTRMD'},
			{ name:'Ecstacy', code: 'ECSTY'},
			{ name:'Exicited', code: 'EXCTD'},
			{ name:'Focused', code: 'FOCSD'},
			{ name:'Inspired', code: 'INPRD'},
			{ name:'Motivated', code: 'MTVTD'},
			{ name:'Overjoyed', code: 'OVRJD'},
			{ name:'Pumped Up', code: 'PMPDU'}
		],
		high: 		[
			{ name:'Amazed', code:'AMAZD'},
			{ name:'Anticipating', code:'ANCTG'},
			{ name:'Appreciated', code:'APCTD'},
			{ name:'Brave', code:'BRAVE'},
			{ name:'Beautiful', code:'BETFL'},
			{ name:'Creative', code:'CRETV'},
			{ name:'Celebrated', code:'CLBTD'},
			{ name:'Confident', code:'COFDT'},
			{ name:'Certain', code:'CRTAN'},
			{ name:'Encouraged', code:'ECRGD'},
			{ name:'Healthy', code:'HLTHY'},
			{ name:'In Awe', code:'INAWE'},
			{ name:'Interested', code:'ITRSD'},
			{ name:'Refreshed', code:'RFRSD'},
			{ name:'Successful', code:'SCFUL'},
			{ name:'Surprised', code:'SUPRD'},
			{ name:'Great', code:'GREAT'}
		],
		good: 		[
			{ name:'Admired', code:'ADMRD'},
			{ name:'Affectionate', code:'AFNAT'},
			{ name:'Attracted', code:'ATRTD'},
			{ name:'Composed', code:'CMPSD'},
			{ name:'Calm', code:'CALMX'},
			{ name:'Joy', code:'JOYXX'},
			{ name:'Loved', code:'LOVED'},
			{ name:'Healthy', code:'HLTHY'},
			{ name:'Hopeful', code:'HOFUL'},
			{ name:'Prepared', code:'PRPRD'},
			{ name:'Refreshed', code:'RFRSD'},
			{ name:'Good', code:'GOODX'}
		],
		neutral: 	[
			{ name:'Affectionate', code:'AFNAT'},
			{ name:'Attracted', code:'ATRTD'},
			{ name:'Composed', code:'CMPSD'},
			{ name:'Calm', code:'CALMX'},
			{ name:'Content', code:'CNTNT'},
			{ name:'Peaceful', code:'PCFUL'},
			{ name:'Relaxed', code:'RLAXD'},
			{ name:'Serenity', code:'NETRL'},
			{ name:'Secure', code:'SECUR'},
			{ name:'At ease', code:'ATESE'},
			{ name:'Okay', code:'OKAYX'}
		],
		bad: 		[
			{ name:'Boredom', code:'BORDM'},
			{ name:'Composed', code:'CMPSD'},
			{ name:'Calm', code:'CALMX'},
			{ name:'Depressed', code:'DPRSD'},
			{ name:'Doubtful', code:'DBFUL'},
			{ name:'Fatigued', code:'FATGD'},
			{ name:'Fearful', code:'FRFUL'},
			{ name:'Ignored', code:'IGNRD'},
			{ name:'Judged', code:'JUDGD'},
			{ name:'Mistreated', code:'MSTRD'},
			{ name:'Nervous', code:'NRVOS'},
			{ name:'Rejected', code:'RJCTD'},
			{ name:'Sad', code:'SADXX'},
			{ name:'Scared', code:'SCRED'},
			{ name:'Weak', code:'WEAKX'},
			{ name:'Low', code:'LOWXX'}
		],
		low: 		[
			{ name:'Annoyed', code:'ANOED'},
			{ name:'Anxious', code:'ANXIS'},
			{ name:'Burned Out', code:'BRNOT'},
			{ name:'Disgust', code:'DSGST'},
			{ name:'Defeated', code:'DEFTD'},
			{ name:'Depressed', code:'DPRSD'},
			{ name:'Embarassed', code:'EMBSD'},
			{ name:'Grief', code:'GRIEF'},
			{ name:'Hated', code:'HATED'},
			{ name:'Hopeless', code:'HPLSS'},
			{ name:'Offended', code:'OFNDD'},
			{ name:'Victimised', code:'VTMSD'},
			{ name:'Worried', code:'WRRED'},
			{ name:'Low', code:'LOWXX'}
		],
		verylow: 	[
			{ name:'Anger', code:'ANGER'},
			{ name:'Depressed', code:'DPRSD'},
			{ name:'Guilty', code:'GULTY'},
			{ name:'Rage', code:'RAGEX'},
			{ name:'Stressed', code:'STRSD'},
			{ name:'Terified', code:'TRFID'},
			{ name:'Worthless', code:'WRTLS'},
			{ name:'Very Low', code:'VYLOW'}
		]
	};

	$scope.moods = moodsList;
	$scope.mood.selectedFeelingsCode = [];			// List of feelings by code
	$scope.mood.selectedFeelingsName = [];			// List of feelings by name
	$scope.selectedFeelingsByIndex = [];				// List of feelings based on original index for CSS styling

	$scope.selectMood = function (level) {
		$scope.mood.level = level;
		$scope.mood.selectedFeelingsCode = []; 		// reset selected feelings
		$scope.mood.selectedFeelingsName = []; 		// reset selected feelings
		$scope.selectedFeelingsByIndex = []; 			// reset selected feelings

		switch(level) {
			case 3: $scope.feelings = feelingList.veryhigh;
					$scope.labelType = 'btn-primary';
					$scope.mood.label = 'Very High';
					break;
			case 2: $scope.feelings = feelingList.high;
					$scope.labelType = 'btn-info';
					$scope.mood.label = 'High';
					break;
			case 1: $scope.feelings = feelingList.good;
					$scope.labelType = 'btn-mild';
					$scope.mood.label = 'Good';
					break;
			case 0: $scope.feelings = feelingList.neutral;
					$scope.labelType = 'btn-grey';
					$scope.mood.label = 'Okay';
					break;
			case -1: $scope.feelings = feelingList.bad;
					$scope.labelType = 'btn-warn';
					$scope.mood.label = 'Bad';
					break;
			case -2: $scope.feelings = feelingList.low;
					$scope.labelType = 'btn-warning';
					$scope.mood.label = 'Low';
					break;
			case -3: $scope.feelings = feelingList.verylow;
					$scope.labelType = 'btn-danger';
					$scope.mood.label = 'Very Low';
					break;
			default:
		}

		$timeout(function () {
			$scope.$apply();
		});
	};

	$scope.selectFeeling = function (index, code) {
		var returnid  = $scope.mood.selectedFeelingsCode.indexOf(code);
		var feeling = $scope.feelings[index].name;

		// Select or unselect the feeling
		if(returnid === -1) {
			$scope.mood.selectedFeelingsCode.push(code);
			$scope.mood.selectedFeelingsName.push(feeling);
			$scope.selectedFeelingsByIndex[index] = code;
		}
		else {
			$scope.mood.selectedFeelingsCode.splice(returnid, 1);
			$scope.mood.selectedFeelingsName.splice(returnid, 1);
			$scope.selectedFeelingsByIndex.splice(index, 1);
		}

		$timeout(function () {
			$scope.$apply();
		});
	};
});