activity-panel.js

angular.module('homepage').
directive('activityPanel', function () {
	return {
		controller: 'activityPanelController',
		restrict: 'E',
		replace: true,
		scope: {
			activity: '='
		},
		templateUrl: 'components/feature-components/activity/activity-panel.html'
	};
}).
controller('activityPanelController', function ($scope) {
	$scope.activities = [
		{ code: 'ATNDG', desc: 'Attending' },
		{ code: 'CLBTG', desc: 'Celebrating' },
		{ code: 'COOKG', desc: 'Cooking' },
		{ code: 'DANCE', desc: 'Dancing' },
		{ code: 'DRNKG', desc: 'Drinking' },
		{ code: 'DRVNG', desc: 'Driving' },
		{ code: 'EATNG', desc: 'Eating' },
		{ code: 'LSTNG', desc: 'Listening' },
		{ code: 'METNG', desc: 'Meeting' },
		{ code: 'PLYNG', desc: 'Playing' },
		{ code: 'REDNG', desc: 'Reading' },
		{ code: 'RSTNG', desc: 'Resting' },
		{ code: 'RIDNG', desc: 'Riding' },
		{ code: 'SNGNG', desc: 'Driving' },
		{ code: 'SHPNG', desc: 'Shopping' },
		{ code: 'SLPNG', desc: 'Sleeping' },
		{ code: 'THKNG', desc: 'Thinking' },
		{ code: 'TRVLG', desc: 'Traveling' },
		{ code: 'WLKNG', desc: 'Walking' },
		{ code: 'WTCNG', desc: 'Watching' },
		{ code: 'WRKNG', desc: 'Working' }
	];

	$scope.setActivityType = function (type) {
		// Activities with subtypes
		var subtypes = ['ATNDG', 'CLBTG', 'COOKG', 'DANCE', 'DRNKG', 'DRVNG', 'EATNG',
			'LSTNG', 'METNG', 'PLYNG', 'REDNG', 'SHPNG', 'SLPNG', 'SNGNG',
			'THKNG', 'TRVLG', 'WLKNG', 'WTCNG', 'WRKNG'];
		// If more info panel to be shown for activity
		var moreinfo = ['ATNDG', 'CLBTG', 'COOKG', 'DANCE', 'DRNKG', 'DRVNG', 'EATNG',
			'LSTNG', 'METNG', 'PLYNG', 'REDNG', 'SHPNG', 'SNGNG',
			'THKNG', 'TRVLG', 'WLKNG', 'WTCNG', 'WRKNG'];

		$scope.activity.activitytype = type;
		setTitle(type);

		// If has subtype
		if (subtypes.indexOf(type) != -1) {
			$scope.activity._.isVisible.subtype = true;
			// Show me more info input field
			if (moreinfo.indexOf(type) != -1) {
				$scope.activity._.isVisible.sleeptype = false;
				$scope.activity._.isVisible.details = true;
			}
			else if ($scope.activity.activitytype == 'SLPNG') {
				$scope.activity._.isVisible.sleeptype = true;
				$scope.activity._.isVisible.details = false;
			}
		}
		else {
			$scope.activity._.isVisible.subtype = false;
			$scope.activity._.isVisible.sleeptype = false;
			$scope.activity._.isVisible.details = true;
		}
	};

	$scope.setActivitySubType = function (type) {
		$scope.activity.activitysubtype = type;
		$scope.activity._.isVisible.whom = true;
		$scope.activity._.isVisible.note = true;
	};

	function setTitle(type) {
		// Set title for text input field
		switch (type) {
			case 'ATNDG':
				$scope.activity.subtypeTitle = 'Event Name';
				break;
			case 'CLBTG':
				$scope.activity.subtypeTitle = 'Event Name';
				break;
			case 'COOKG':
				$scope.activity.subtypeTitle = 'Dishes Name';
				break;
			case 'DANCE':
				$scope.activity.subtypeTitle = 'Dance Name';
				break;
			case 'DRNKG':
				$scope.activity.subtypeTitle = 'Drink Name';
				break;
			case 'DRVNG':
				$scope.activity.subtypeTitle = 'Vehicle Name';
				break;
			case 'EATNG':
				$scope.activity.subtypeTitle = 'Food Name';
				break;
			case 'LSTNG':
				$scope.activity.subtypeTitle = 'Listening To';
				break;
			case 'METNG':
				$scope.activity.subtypeTitle = 'Meeting Title';
				break;
			case 'PLYNG':
				$scope.activity.subtypeTitle = 'Sports Name';
				break;
			case 'REDNG':
			case 'THKNG':
				$scope.activity.subtypeTitle = 'About';
				break;
			case 'SNGNG':
				$scope.activity.subtypeTitle = 'Singing';
				break;
			case 'SHPNG':
				$scope.activity.subtypeTitle = 'Looking For';
				break;
			case 'TRVLG':
			case 'WLKNG':
				$scope.activity.subtypeTitle = 'To';
				break;
			case 'WTCNG':
				$scope.activity.subtypeTitle = 'Watching';
				break;
			case 'WRKNG':
				$scope.activity.subtypeTitle = 'On';
				break;
		}
	}
});