Пример #1
0
'use strict';

var bulkModules = require('bulkModules');

/* @ngInject */
bulkModules.controller('landingCtrl', function($state, _content) {
	var vm = this;

	vm.searchQuery = '';

	vm.search = function() {
		return $state.go('search', { query: vm.searchQuery });
	};

	if (_content.items && _content.items[0]) {
		vm.header = _content.items[0].fields.header || 'film faroe islands';
		vm.subheader = _content.items[0].fields.subheader || 'WELCOME TO';
		vm.description = _content.items[0].fields.description || '';

		if (_content.items[0].fields.mainImage && _content.items[0].fields.mainImage.fields.file.url) {
			vm.styleOverwrite = {
				'background-image': 'url(' + _content.items[0].fields.mainImage.fields.file.url + ')',
			};
		}
	}
});
Пример #2
0
bulkModules.controller('loginCtrl', function($scope, usersResource, authService, $state, $log) {
	var vm = this;

	vm.loginState = true;

	vm.loginModel = {};

	vm.login = function(form) {
		form.$setSubmitted();
		if (form.$valid) {
			authService.login(vm.loginModel)
				.then(function() {
					$state.go('profile');
				})
				.catch(function(error) {
					$log.log(error);
				});
		}
	};

	vm.signupModel = {
		status: 'unpublished'
	};

	vm.signup = function(form) {
		if (form.$valid) {
			authService.signup(vm.signupModel)
				.then(function() {
					$state.go('profile');
				})
				.catch(function(error) {
					$log.log(error);
				});
		}
	};
});
Пример #3
0
bulkModules.controller('mEditCtrl', function($uibModalInstance, $scope, _model, _resource, _form) {
	var mv = this;

	delete _model.$promise;
	delete _model.$resolved;

	mv.title = _form.title;
	mv.model = angular.copy(_model);
	mv.schema = _form.schema;
	mv.form = _form.form;

	mv.dismiss = function() {
		$uibModalInstance.dismiss('cancel');
	};

	mv.remove = function() {
		_resource
			.remove({ id: _model._key })
			.$promise
			.then(function() {
				return $uibModalInstance.close({ removed: true });
			});
	};

	mv.onSubmit = function(form) {
		$scope.$broadcast('schemaFormValidate');

		if (angular.equals(_model, mv.model)) {
			return mv.dismiss();
		}

		if (form.$valid) {
			_resource
				.update({ id: _model._id}, mv.model)
				.$promise
				.then(function(model) {
					$uibModalInstance.close(model);
				});
		}
	};

});
Пример #4
0
bulkModules.controller('searchCtrl', function($scope, $log, $http, $stateParams, $state, _results) {
	var vm = this;

	if ($stateParams.query) {
		vm.searchQuery = $stateParams.query;
	}

	if (_results) {
		vm.results = _results.hits.hits;
		$log.log('results', vm.results);
	}

	vm.filter = {
		location: false,
		company: false,
		actor: false,
		crew: false,
	};

	vm.resultFilter = function(resultItem) {
		var allFalse = Object
			.keys(vm.filter)
			.every(function(key) {
				return !vm.filter[key];
			});

		if (allFalse) {
			return true;
		}

		var type = resultItem._type;

		if (type === 'user') {
			type = resultItem._full.professions.indexOf('Actors') !== -1 ? 'actor' : 'crew';
		}

		if (vm.filter[type]) {
			return true;
		} else {
			return false;
		}
	};

	vm.search = function() {
		$state.go('.', { query: vm.searchQuery }, { reload: false, inherit: false, notify: false });

		if (!vm.searchQuery) {
			vm.results = undefined;
			return;
		}

		$http
			.get('/api/search', {
				params: {
					query: vm.searchQuery
				}
			})
			.then(function(response) {
				return vm.results = response.data.hits.hits;
			});
	};
});
Пример #5
0
'use strict';

var bulkModules = require('bulkModules');

/* @ngInject */
bulkModules.controller('productCtrl', function(_product) {
	var vm = this;
	vm.product = _product;
});
Пример #6
0
bulkModules.controller('loginCtrl', function($scope, usersResource, usersFormFactory, authService, $state, $log) {
	var vm = this;

	vm.loginState = true;
	vm.toggleState = function() {
		vm.loginState = !vm.loginState;
	};

	vm.login = {
		model: {},
		schema: {
			type: 'object',
			properties: {
				email: { type: 'string', format: 'email', required: true },
				password: { type: 'string', required: true },
			},
		},
		form: [
			{ key: 'email', title: 'Email' },
			{ key: 'password', type: 'password', title: 'Password' }
		],
		onSubmit: function(form) {
			$scope.$broadcast('schemaFormValidate');

			if (form.$valid) {
				authService.login(vm.login.model)
					.then(function(model) {
						$state.go('user', { id: model._id });
						$log.log(model);
					})
					.catch(function(error) {
						$log.log(error);
					});
			}
		}
	};

	var signupForm = usersFormFactory.create();
	vm.signup = {
		model: {},
		schema: signupForm.schema,
		form: signupForm.form,
		onSubmit: function(form) {
			$scope.$broadcast('schemaFormValidate');

			if (form.$valid) {
				usersResource
					.create({}, vm.signup.model)
					.$promise
					.then(function(model) {
						$log.log(model);
					});
			}
		}
	};
});