var sesfControllers = angular.module('sesfControllers', []); sesfControllers.factory('ImageUpload', ['$fileUploader', '$rootScope', function($fileUploader, $rootScope){ return { init: function(config, scope, callback){ var uploader = $fileUploader.create({ url: config.url, formData: config.data, removeAfterUpload: config.removeAfterUpload }).bind( 'afteraddingfile', function( event, item ) { $rootScope.log('added file', item); scope.item = item; }).bind( 'changedqueue', function( items ) { scope.$$phase || scope.$apply(); }).bind( 'complete', function( event, xhr, item ) { $rootScope.log( 'Complete: ' + JSON.parse(xhr.response) ); item.progress = null; item.file = null; item.response = JSON.parse(xhr.response); if(!!item.response) { item.status = 'error'; } else { item.response = 'Success'; item.status = 'success'; } if(typeof(callback) == 'function') { callback.call(item.response); } }); } }; }]); sesfControllers.factory( 'HomeService', [ '$rootScope', '$http', '$resource', '$route', function( rootScope, $http, $resource, $route) { return { Sponsors: function () { return $resource('event/sponsors', {limit: 6, all: true}); }, Events: function() { return $resource('home/events', {limit: 1}); }, Report: function() { return $resource('home/report'); } }; }]); sesfControllers.controller('homeController', ['$scope', 'HomeService', '$timeout', '$log', function homeController(scope, HomeService, $timeout, $log) { $log.info('loading home page'); scope.sponsors = HomeService.Sponsors().get(); scope.events = HomeService.Events().query(); scope.maxCarouselIndex = $('.carousel li').length - 1; scope.carouselIndex = 0; scope.advanceCarouselIndex = function(){ if(scope.carouselIndex >= scope.maxCarouselIndex) { return false; } //next_index = scope.carouselIndex + 1; next_index = (scope.carouselIndex >= scope.maxCarouselIndex ? 0 : scope.carouselIndex + 1); scope.carouselIndex = next_index; console.log($('.carousel li')[scope.carouselIndex].scrollHeight); $('#carousel-1').height($('.carousel li')[scope.carouselIndex].scrollHeight + 40); $('.rn-carousel-container').height($('.carousel li')[scope.carouselIndex].scrollHeight + 40); $('.carousel').height($('.carousel li')[scope.carouselIndex].scrollHeight); //$timeout(function() { scope.advanceCarouselIndex(); }, 5000); }; scope.advanceCarouselIndex(0); try{ FB.XFBML.parse(); } catch(err) {} }]); sesfControllers.controller('emptyController', function() { $('html,body').animate({ scrollTop: 0 }, 1); }); sesfControllers.controller('reportPage', ['$scope', '$modal', function(scope, $modal) { scope.reportPage = function(){ var reportModal = $modal.open({ templateUrl: 'template/home?only=report_page', controller: 'reportPageModal' }); }; }]); sesfControllers.controller('reportPageModal', ['$scope', '$modalInstance', 'HomeService', '$timeout', '$log', '$rootScope', 'LoginService', '$location', function(scope, modalInstance, HomeService, $timeout, $log, $rootScope, LoginService, $location) { scope.message = {}; scope.isLoggedIn = LoginService.is_logged_in; scope.ok = function () { var data = scope.message; data.user_id = LoginService.user_id; data.log = JSON.stringify($log.exportLogs()); data.location = $location.path(); var message = HomeService.Report(); message = new message(data); message.$save(null, function(response){ scope.report_page = { response: 'Message Sent', status: 'success' }; $timeout(function() { modalInstance.close(); }, 2000); },function(response) { $log.error('failed to send', scope.message, response); scope.report_page = { response: response.data, status: 'error' }; }); }; scope.cancel = function () { modalInstance.dismiss(); }; }]); sesfControllers.service( 'EventsService', [ '$resource', function( $resource ) { var service = { Events: function(){ return $resource('events/car-shows', {is_active: 1}); } }; return service; }]); sesfControllers.controller('eventsController', ['$scope', 'EventsService', function (scope, EventsService) { scope.events = {}; scope.events.active = EventsService.Events().query(); scope.events.inactive = EventsService.Events().query({is_active: 0}); }]); sesfControllers.factory( 'EventService', [ '$rootScope', '$http', '$resource', '$route', function( rootScope, $http, $resource, $route) { var service = { EventInfo: function () { if(!$route.current.params) { return FALSE; } return $resource('event/info', {show_id: !!$route.current.params.eventId ? $route.current.params.eventId : $route.current.params.galleryId}); }, Agenda: function() { return $resource('event/agenda', {show_id: $route.current.params.eventId, type_id: 1}); }, Locations: function() { return $resource('event/locations', {show_id: $route.current.params.eventId}); }, Registration: function() { return $resource('event/registration', {show_id: $route.current.params.eventId}); }, Extra: function() { return $resource('event/extra', {extra_id: $route.current.params.extraId}); }, Cars: function() { return $resource('event/cars', {show_id: $route.current.params.eventId}); }, Sponsors: function() { return $resource('event/sponsors', {show_id: $route.current.params.eventId}); }, Schedule: function() { return $resource('event/schedule', {show_id: $route.current.params.eventId}); } }; return service; }]); sesfControllers.controller('eventScheduleController', ['$scope', 'EventService', function(scope, EventService) { scope.schedule = EventService.Schedule().get(); scope.sponsors = EventService.Sponsors().get(); }]); sesfControllers.controller('eventController', ['$scope', 'EventService', 'LoginService', function (scope, EventService, LoginService) { scope.event_info = EventService.EventInfo().get(); scope.user_data = LoginService.user_data; }]); sesfControllers.controller('eventRegisterController', ['$scope', '$location', 'EventService', 'appStorage', '$location', 'registration', 'cars', 'EventService', '$timeout', function (scope, location, EventService, appStorage, location, registration, cars, EventService, $timeout) { breadCrumb = appStorage('sesfStorage', 'breadCrumb', scope); if(scope.breadCrumb.registrationData && scope.breadCrumb.lastPage == 'newCar') { scope.registration = scope.breadCrumb.registrationData; breadCrumb.clear(); } else scope.registration = registration; scope.registration.cars = cars; var event_info = EventService.EventInfo().get(); breadCrumb.set('lastPage', 'eventRegistration'); breadCrumb.set('page', location.path()); breadCrumb.set('registrationData', scope.registration); scope.register = function(){ breadCrumb.clear(); scope.registrationResponse = {}; scope.registration.$save(null, function(response){ $('html,body').animate({ scrollTop: 0 }, 100); location.url(event_info.memberProfileURL.replace('#','') + '/billing/' + response.registration.id); return; scope.registrationResponse.all = { response: 'Successfully submitted', status: 'success' }; },function(response){ scope.registrationResponse = { response: response.data, status: 'error' }; }); } }]); sesfControllers.controller('eventExtraController', ['$scope', 'EventService', 'registration', function (scope, EventService, registration) { scope.registration = registration; scope.submit_extra = function(){ scope.registrationResponse = {}; extra = EventService.Extra(); console.log('extras', {extras: scope.registration.registration.extras}); extra.save({extras: scope.registration.registration.extras}, function(){ scope.registrationResponse.all = { response: 'Successfully submitted', status: 'success' }; },function(response){ scope.registrationResponse.all = { response: response.data, status: 'error' }; }); } }]); sesfControllers.controller('eventSponsorController', ['$scope', 'sponsors', function(scope, sponsors) { console.log(sponsors) sponsors.$promise.then(function(val){ console.log(val.sponsors); if(typeof val.sponsors != 'undefined') { var temp = []; val.sponsors.forEach(function(sponsor){ if(typeof temp[sponsor.type_id] == 'undefined') { temp[sponsor.type_id] = [sponsor]; } else { temp[sponsor.type_id].push(sponsor); } }); var sponsorTypes = []; temp.forEach(function(type){ sponsorTypes.push(type); }); console.log(sponsorTypes); scope.sponsors = sponsorTypes; } }) //scope.sponsors = sponsors; }]); sesfControllers.controller('eventAgendaController', ['$scope', 'agenda', 'sponsors', function (scope, agenda, sponsors) { scope.agenda = agenda; scope.sponsors = sponsors; }]); sesfControllers.controller('eventJudgingController', ['$scope', 'agenda', function (scope, agenda) { scope.agenda = agenda; }]); sesfControllers.controller('eventAttendeesController', ['$scope', 'EventService', function (scope, EventService) { }]); sesfControllers.controller('eventDirectionsController', ['$scope', 'EventService', 'LoginService', 'locations', function (scope, EventService, LoginService, locations) { scope.locations = locations; scope.user_data = LoginService.user_data; for (var i = 0; i < scope.locations.length; i++) { scope.locations[i].zoom = 14; scope.locations[i].id = 'angularMap' + i; scope.locations[i].options = { map: { center: new google.maps.LatLng(scope.locations[i].address.lattitude, scope.locations[i].address.longitude), zoom: 14, /* mapTypeId: google.maps.MapTypeId.STEET */ }, volcanoes: { icon: 'https://maps.gstatic.com/mapfiles/ms2/micons/red-dot.png', } }; scope.locations[i].markers = [ { name: scope.locations[i].name, location: { lat: scope.locations[i].address.lattitude, lng: scope.locations[i].address.longitude } } ]; } scope.getMarkerOpts = function(marker) { return angular.extend( { title: marker.name } ); }; }]); sesfControllers.factory('RegistrationService', ['$resource', '$route', function($resource, $route){ return { Registration: function(){ return $resource('/member/register', null); } }; }]); sesfControllers.controller('registerController', ['$rootScope', '$scope', 'RegistrationService', '$location', 'LoginService', function (rootScope, scope, RegistrationService, $location, LoginService) { scope.registrationResponse = {}; var reg = RegistrationService.Registration(); var reg = new reg(); scope.reg = reg; scope.submit = function(){ rootScope.log('reg', scope.reg); $('html,body').animate({ scrollTop: 0 }, 100); reg.$save(null,function(response){ scope.registrationResponse = { response: 'Your account has been successfully created', status: 'success' }; LoginService.Authenticate(); scope.user_info = response; },function(response){ rootScope.log('error', response); scope.registrationResponse = { response: response.data, status: 'error' }; }); } if(LoginService.is_logged_in === true) { $location.path(LoginService.user_data.profileURL.replace('#', '')); } }]); sesfControllers.factory( 'MembersService', [ '$resource', '$location', function($resource, $location ) { var service = { filters: function () { return $resource('members/list-filters', $location.search()); }, paginate: function () { return $resource('members/users', $location.search()); } }; return service; }]); sesfControllers.controller('membersController', ['$scope', 'MembersService', '$location', 'appStorage', '$route', function (scope, MembersService, $location, appStorage, $route) { breadCrumb = appStorage('sesfStorage', 'breadCrumb', scope); breadCrumb.set('lastPage', 'memberList'); scope.isEventPage = $route.current.$$route.eventPage; var show_id = $route.current.$$route.eventPage ? $route.current.params.eventId : $location.search().show_id; scope.baseUrl = $route.current.$$route.eventPage ? '#' + $location.path().replace('/members', '').replace('/cars', '') : '#'; scope.filters = MembersService.filters().query({eventPage: $route.current.$$route.eventPage}); scope.members = MembersService.paginate().get({limit: $route.current.$$route.eventPage ? 25 : 20, show_id: show_id}); }]); sesfControllers.factory('MemberService', ['$resource', '$route', function($resource, $route){ return { Profile: function(){ return $resource('/member/profile', {user_id: $route.current.params.memberId}); }, Password: function(){ return $resource('/login/update-password', {user_id: $route.current.params.memberId}); }, AccountInfo: function(){ return $resource('/member/account-info', {user_id: $route.current.params.memberId}); }, Preferences: function(){ return $resource('/member/private-preferences', { user_id: $route.current.params.memberId }); }, Location: function(){ return $resource('/member/location', {user_id: $route.current.params.memberId}); }, InvoiceList: function() { return $resource('/member/invoice-list', {user_id: $route.current.params.memberId}); }, Invoice: function(){ return $resource('/member/invoice', { registration_id: $route.current.params.registrationId }); }, Cars: function(){ return $resource('/member/cars', { user_id: $route.current.params.memberId }); }, Shows: function(){ return $resource('/member/shows', { user_id: $route.current.params.memberId }); }, Tutorial: function(){ return $resource('/tutorial/tutorial', null); }, Message: function(){ return $resource('/member/message', { user_id: $route.current.params.memberId }); }, SellCar: function(){ return $resource('/member/sell-car', { user_id: $route.current.params.memberId }); } }; }]); sesfControllers.controller('memberController', ['$scope', 'MemberService', '$location', 'appStorage', 'LoginService', '$modal', '$log', function (scope, MemberService, $location, appStorage, LoginService, $modal, $log) { breadCrumb = appStorage('sesfStorage', 'breadCrumb', scope); breadCrumb.set('lastPage', 'profile'); scope.user = MemberService.Profile().get(function(){ scope.is_private = scope.user.is_private; }); scope.addCar = function(){ $location.path('/car/new'); }; scope.isLoggedIn = function(){ return LoginService.is_logged_in; }; scope.sendEmail = function(){ var modalInstance = $modal.open({ templateUrl: 'template/member?only=send_email_modal', controller: 'memberSendEmail' }); }; }]); sesfControllers.controller('memberSendEmail', ['$scope', '$modalInstance', 'MemberService', '$timeout', '$log', function(scope, modalInstance, MemberService, $timeout, $log) { scope.message = {}; scope.ok = function () { var message = MemberService.Message(); message = new message(scope.message); message.$save(null, function(response){ $log.info('sent private email'); scope.message_response = { response: 'Message Sent', status: 'success' }; $timeout(function() { modalInstance.close(); }, 2000); },function(response) { $log.error('failed to send private email ' + JSON.stringify(scope.message) + ' ' + JSON.stringify(response)); scope.message_response = { response: response.data, status: 'error' }; }); }; scope.cancel = function () { modalInstance.dismiss(); }; }]); sesfControllers.controller('memberSettingsPreferencesController', ['$scope', 'MemberService', '$log', function (scope, MemberService, $log) { scope.preferences = MemberService.Preferences().get(); scope.submit = function(){ scope.loc_response = {}; scope.preferences.$save(null, function(){ $log.info('saved member settings preferences') scope.preferences_res = { response: 'Preferences Updated', status: 'success' }; },function(response){ $log.error('failed to save member settings preferences ' + JSON.stringify(response)); scope.preferences_res = { response: response.data, status: 'error' }; }); }; }]); sesfControllers.controller('memberBillingController', ['$scope', 'MemberService', 'invoiceList', '$route', '$log', function(scope, MemberService, invoiceList, $route, $log) { scope.invoiceList = invoiceList; scope.selectedInvoice = {}; scope.$watch('selectedInvoice', function(newVal, oldVal){ if(newVal != oldVal) scope.invoice = MemberService.Invoice().get({registration_id: newVal.id}); }); if($route.current.params.registrationId) { scope.invoice = MemberService.Invoice().get(); scope.$watch('invoiceList', function(){ angular.forEach(invoiceList, function(item){ if(item.id == $route.current.params.registrationId) { scope.selectedInvoice = item; } }); }); } else if(scope.invoiceList.length > 0) { scope.selectedInvoice = invoiceList[0]; scope.invoice = MemberService.Invoice().get({registration_id: scope.selectedInvoice.id}); } }]); sesfControllers.controller('memberSettingsAccountInfoController', ['$scope', 'MemberService', '$log', function (scope, MemberService, $log) { scope.account_info = {}; scope.submit = function(){ var data = { first: scope.user.member_info.first, last: scope.user.member_info.last, email: scope.user.member_info.email, phone: scope.user.member_info.phone } var AccountInfo = MemberService.AccountInfo(); var accountInfo = new AccountInfo(data); accountInfo.$save(null, function(){ $log.info('saved account info'); scope.account_info = { response: 'Account Info Updated', status: 'success' }; },function(response){ $log.error('failed to save account info ' + JSON.stringify(response)); scope.account_info = { response: response.data, status: 'error' }; }); }; }]); sesfControllers.controller('memberSettingsUpdatePasswordController', ['$scope', 'MemberService', '$log', function (scope, MemberService, $log) { scope.password = {}; scope.submit = function(){ var Password = MemberService.Password(); var password = new Password(scope.password); password.$save(null, function(){ $log.info('updated password'); scope.password = { response: 'Password Updated', status: 'success' }; },function(response){ $log.error('failed to update password ' + JSON.stringify(response)); scope.password = { response: response.data, status: 'error' }; }); }; }]); sesfControllers.controller('memberSettingsAddressController', ['$scope', 'MemberService', '$log', function (scope, MemberService, $log) { scope.location = MemberService.Location().get(); scope.submit = function(){ scope.loc_response = {}; scope.location.$save(null, function(){ $log.info('saved address'); scope.loc_response = { response: 'Address Updated', status: 'success' }; },function(response){ $log.error('failed to save address ' + JSON.stringify(response)); scope.loc_response = { response: response.data, status: 'error' }; }); }; }]); sesfControllers.controller('memberSettingsProfileImageController', ['$scope', 'ImageUpload', '$routeParams', '$log', function (scope, ImageUpload, $routeParams, $log){ scope.timestamp = new Date().getTime(); scope.uploader = ImageUpload.init({ url: '/member/profile-image', data: [{user_id: $routeParams.memberId}], removeAfterUpload: true }, scope, function() { $log.info('loaded new image info'); scope.timestamp = new Date().getTime(); scope.user.$get(); }); }]); sesfControllers.controller('memberCarsController', ['$scope', 'cars', '$log', 'MemberService', function(scope, cars, $log, MemberService) { scope.cars = cars; scope.sellCar = function(car){ if(confirm('Are you sure you want to mark this car as SOLD? This will permanently remove the selected car from your garage.')) { var sellCar = MemberService.SellCar(); sellCar = new sellCar(car); sellCar.$save(null, function(response){ $log.info('marked as sold' + JSON.stringify(car)); car.is_sold = true; scope.message_response = { response: 'Marked as Sold', status: 'success' }; },function(response) { $log.error('failed to mark as sold: ' + JSON.stringify(car) + ' ' + JSON.stringify(response)); scope.message_response = { response: response.data, status: 'error' }; }); } }; }]); sesfControllers.controller('memberTutorialController', ['$scope', 'MemberService', 'LoginService', '$location', '$log', function(scope, MemberService, LoginService, $location, $log) { scope.$on('login.update', function(){ if(LoginService.user_id) { scope.tutorial = MemberService.Tutorial().get({id: LoginService.user_id, current_url: $location.path()}); scope.hide = function(){ $log.info('hiding tutorial'); scope.tutorial.show_login_welcome = 0; scope.tutorial.$save(null , function(response) { scope.show_tutorial = false; }); }; } }); }]); sesfControllers.factory( 'CarsService', [ '$resource', '$location', function($resource, $location ) { var service = { filters: function () { return $resource('cars/list-filters', $location.search()); }, paginate: function () { return $resource('cars/list', $location.search()); } }; return service; }]); sesfControllers.controller('carsController', ['$scope', 'CarsService', '$location', 'appStorage', '$route', function (scope, CarsService, $location, appStorage, $route) { breadCrumb = appStorage('sesfStorage', 'breadCrumb', scope); breadCrumb.set('lastPage', 'memberList'); scope.isEventPage = $route.current.$$route.eventPage; var show_id = $route.current.$$route.eventPage ? $route.current.params.eventId : $location.search().show_id; scope.baseUrl = $route.current.$$route.eventPage ? '#' + $location.path().replace('/members', '').replace('/cars', '') : '#'; scope.filters = CarsService.filters().query({eventPage: $route.current.$$route.eventPage}); scope.members = CarsService.paginate().get({limit: $route.current.$$route.eventPage ? 25 : 20, show_id: show_id}); }]); sesfControllers.factory('CarService', ['$resource', '$routeParams', '$route', function($resource, $routeParams, $route){ var service = { Profile: function(){ return $resource('/car/profile', {car_id: $routeParams.carId}, {'new': {method: 'PUT'}}); }, Body: function(){ return $resource('/car/body'); }, Type: function(){ return $resource('/car/type'); } }; return service; }]); sesfControllers.controller('carController', ['$scope', 'CarService', 'appStorage', function (scope, CarService, appStorage) { sesfStorage = appStorage('sesfStorage', 'breadCrumb', scope); scope.car = CarService.Profile().get(function(){ scope.is_private = scope.car.is_private; }); }]); sesfControllers.controller('carNewController', ['$scope', 'CarService', '$location', function (scope, CarService, $location) { var car = CarService.Profile(); scope.carInfo = new car(); scope.bodies = CarService.Body().query(); scope.types = CarService.Type().query(); scope.submit = function(){ scope.carInfo.$new(null,function(response){ $location.path('/car/' + response.id + '/new-image'); },function(response){ scope.carInfoResponse = { response: response.data, status: 'error' }; }); }; }]); sesfControllers.controller('carNewImageController', ['$scope', 'CarService', 'ImageUpload', '$location', 'appStorage', '$routeParams', function (scope, CarService, ImageUpload, $location, appStorage, $routeParams) { breadCrumb = appStorage('sesfStorage', 'breadCrumb', scope); scope.car = CarService.Profile().get(); scope.timestamp = new Date().getTime(); scope.uploader = ImageUpload.init({ url: '/car/profile-image', data: [{car_id: $routeParams.carId}], removeAfterUpload: true }, scope, function() { scope.timestamp = new Date().getTime(); scope.car.$get(); }); scope.submit = function(){ if(scope.breadCrumb.lastPage == 'eventRegistration') { scope.breadCrumb.registrationData.registration.cars.push(scope.car); $location.path(scope.breadCrumb.page); breadCrumb.set('lastPage', 'newCar'); } else $location.path('/car/' + $routeParams.carId + '/settings'); }; }]); sesfControllers.controller('carSettingsCarInfoController', ['$scope', '$q', 'CarService', function (scope, $q, CarService) { scope.carData = {}; $q.all({ profile: CarService.Profile().get(), bodies: CarService.Body().query().$promise, types: CarService.Type().query().$promise }).then(function(result){ scope.carData = result; }); scope.submit = function(){ /* store the body and type selections for after put */ body = scope.carData.profile.body; type = scope.carData.profile.type; scope.carData.profile.$new(null,function(response){ scope.carData.profile.body = body; scope.carData.profile.type = type; scope.carInfoResponse = { response: 'Successfully updated', status: 'success' }; },function(response){ scope.carInfoResponse = { response: response.data, status: 'error' }; }); }; }]); sesfControllers.controller('carSettingsProfileImageController', ['$scope', '$routeParams', 'ImageUpload', function (scope, $routeParams, ImageUpload){ scope.timestamp = new Date().getTime(); scope.uploader = ImageUpload.init({ url: '/car/profile-image', data: [{car_id: $routeParams.carId}], removeAfterUpload: true }, scope, function() { scope.timestamp = new Date().getTime(); scope.car.$get(); }); }]); sesfControllers.service('LoginService', ['$rootScope', '$http', '$routeParams', '$route', '$location', '$log', function($rootScope, $http, $routeParams, $route, $location, $log){ var service = { is_logged_in: false, user_id: null, user_level: 0, nextUrl: '/', login_data: { status: null, response: null }, user_data: {}, Authenticate: function(){ service.login_data = { status: null, response: null }; $http.post('/login/authenticate', { }).success(function(data, status){ $log.info('authenticated'); service.user_data = data; service.is_logged_in = true; $rootScope.$broadcast('login.auth.success'); $rootScope.$broadcast('login.update'); }).error(function(data){ $log.error('not authenticated'); service.is_logged_in = false; service.user_data = {user_level: 0}; $rootScope.$broadcast('login.update'); }); }, Login: function(email, password, remember){ service.login_data = { status: null, response: { response: null } }; $http.post('/login/login', { email: email, password: password, remember: remember }).success(function(data, status){ $log.info('logged in ' + JSON.stringify(data)); service.user_data = data; service.is_logged_in = true; service.login_data.status = 'success'; $rootScope.$broadcast('login.auth.success'); $rootScope.$broadcast('login.update'); }).error(function(data){ $log.error('failed login ' + JSON.stringify(data)); service.is_logged_in = false; service.user_data = null; service.login_data.status = 'error'; service.login_data.response = data; $rootScope.$broadcast('login.update'); }); }, Logout: function(){ service.login_data = { status: null, response: null }; $http.post('/login/logout').success(function(data){ service.user_data = { user_level: 0 }; service.is_logged_in = false; document.cookie = 'laravel_session' + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'; $rootScope.$broadcast('login.update'); }).error(function(data){ service.user_data = { user_level: 0 }; service.is_logged_in = false; $rootScope.$broadcast('login.update'); }); }, forgot_password: { email: null, status: null, response: null }, ForgotPassword: function(email){ service.forgot_password.email = email; $http.post('/login/forgot-password', { email: email }).success(function(data){ $log.info('Forgot Password ' + JSON.stringify(data)); service.forgot_password.email = null; service.forgot_password.status = 'success'; service.forgot_password.response = 'Password Reset Emailed'; $rootScope.$broadcast('forgot_password.update'); }).error(function(data){ $log.error('Forgot Password fail ' + JSON.stringify(data)); service.forgot_password.status = 'error'; service.forgot_password.response = data; $rootScope.$broadcast('forgot_password.update'); }); }, reset_password: { token: $location.search().token, email: null, password: null, password_confirm: null, status: null, response: null }, ResetPassword: function(email, password, password_confirm){ service.forgot_password.email = email; service.forgot_password.password = password; service.forgot_password.password_confirm = password_confirm; $http.post('/login/reset-password', { token: service.reset_password.token, email: email, password: password, password_confirmation: password_confirm }).success(function(data){ service.reset_password.email = null; service.reset_password.status = 'success'; service.reset_password.response = 'Password Successfully Reset'; service.user_data = data; service.is_logged_in = true; $rootScope.$broadcast('reset_password.update'); }).error(function(data){ service.reset_password.status = 'error'; service.reset_password.response = data; $rootScope.$broadcast('reset_password.update'); }); } }; $rootScope.$on('login.update', function(event) { if(service.user_data != null) { service.user_id = service.user_data.user_id; service.user_level = service.user_data.user_level; } }); service.Authenticate(); return service; }]); sesfControllers.controller('loginController', ['$scope', 'LoginService', '$location', '$timeout', '$window', function (scope, LoginService, $location, $timeout, $window) { scope.ready = false; scope.submit = function(){ LoginService.Login(this.email, this.password, this.remember); }; scope.logout = function(){ LoginService.Logout(); $location.path('/'); }; scope.$on('login.update', function(event) { scope.login_data = LoginService.login_data; scope.log('login', scope.login_data); scope.user_data = LoginService.user_data; scope.is_logged_in = LoginService.is_logged_in; if(LoginService.user_data != null) scope.user_id = LoginService.user_data.user_id; if(LoginService.is_logged_in === true && $location.path() == '/login') { if($location.search().redirect == "forum") { $window.location.href = "https://forum.bmwsharkfest.org"; } else if(LoginService.nextUrl == '/') { nextUrl = LoginService.user_data.profileURL; } else { nextUrl = LoginService.nextUrl; } $location.path(nextUrl); LoginService.nextUrl = '/'; } scope.ready = true; }); scope.slideOut = false; scope.$on('login.auth.success', function(event) { if(LoginService.user_data.slideOutName == 1) { scope.slideOut = true; $timeout(function() { scope.slideOut = false; }, 3000); } }); }]); sesfControllers.controller('forgotPasswordController', ['$scope', 'LoginService', '$location', function (scope, LoginService, $location) { scope.forgot_password = LoginService.forgot_password; scope.submit = function(){ LoginService.ForgotPassword(this.email); }; scope.$on('forgot_password.update', function(event) { scope.forgot_password = LoginService.forgot_password; scope.log(LoginService.forgot_password); }); }]); sesfControllers.controller('resetPasswordController', ['$scope', 'LoginService', '$location', function (scope, LoginService, $location) { scope.reset_password = LoginService.reset_password; scope.submit = function(){ LoginService.ResetPassword(this.email, this.password, this.password_confirm); }; scope.$on('reset_password.update', function(event) { scope.reset_password = LoginService.reset_password; scope.log(LoginService.reset_password); }); }]); sesfControllers.service( 'GoogleService', [ '$rootScope', function( rootScope) { var geocoder = new google.maps.Geocoder(); var service = { addressData: {}, geoCode: function(address) { geocoder.geocode({ address: address}, function (result, status) { if (status === google.maps.GeocoderStatus.OK) { service.addressData = result[0]; } }); }, getLatLong: function() { return { lattitude: service.addressData.geometry.location.ob, longitude: service.addressData.geometry.location.pb }; } }; return service; }]); ; sesfControllers.factory('GalleryService', ['$resource', '$route', function($resource, $route){ return { EventList: function(){ return $resource('/gallery/car-show-list', null); }, Gallery: function(){ return $resource('/gallery/info', {gallery_id: $route.current.params.galleryId}); }, GalleryList: function(){ return $resource('/gallery/list', {show_id: $route.current.params.eventId, gallery_id: $route.current.params.galleryId}); }, Items: function(get_subcategory_items, skip){ return $resource('/gallery/items', {show_id: $route.current.params.eventId, gallery_id: $route.current.params.galleryId, skip: skip, get_subcategory_items: get_subcategory_items}); }, RemoveItem: function(){ return $resource('/gallery/remove-item', null); }, Create: function(){ return $resource('/gallery/create', null); }, DefaultItem: function() { return $resource('/gallery/default-item', null); }, ShowHideGallery: function() { return $resource('/gallery/show-hide', null); }, Breadcrumb: function(){ return $resource('/gallery/breadcrumb', {show_id: $route.current.params.eventId, gallery_id: $route.current.params.galleryId}); } }; }]); sesfControllers.controller('galleryEventListController', ['$scope', 'events', 'GalleryService', '$location', 'LoginService', '$log', function (scope, events, GalleryService, $location, LoginService, $log) { scope.user_data = LoginService.user_data; scope.events = events; }]); sesfControllers.controller('galleryListController', ['$scope', 'galleries', 'galleryInfo', 'galleryItems', 'breadcrumb', 'GalleryService', '$location', 'LoginService', '$log', '$route', '$modal', '$window', '$document', function (scope, galleries, galleryInfo, galleryItems, breadcrumb, GalleryService, $location, LoginService, $log, $route, $modal, $window, $document) { scope.galleries = galleries; scope.galleryInfo = galleryInfo; scope.galleryItems = galleryItems; scope.breadcrumb = breadcrumb; scope.user_data = LoginService.user_data; scope.show_id = $route.current.params.eventId; scope.currentSkip = 0; scope.loading = false; $('html,body').animate({ scrollTop: 0 }, 100); angular.element($window).bind('scroll', function() { if(document.body.clientHeight - (document.body.scrollTop + window.innerHeight) < 300 && !scope.loading) { scope.loading = true; scope.loadMore(); } }); scope.loadMore = function(){ scope.currentSkip += scope.galleryItems.per_page; if(scope.currentSkip >= scope.galleryItems.count) { return false; } newItems = GalleryService.Items(true, scope.currentSkip).get(function(data){ scope.galleryItems.items = scope.galleryItems.items.concat(newItems.items); scope.loading = false; }); }; scope.viewItem = function($item, $galleryInfo){ var itemModal = $modal.open({ templateUrl: 'template/gallery?only=view_item', controller: 'viewItemModal', windowClass: 'itemView', backdrop: true, animation: false, resolve: { item: function(){ return $item; }, gallery: function() { return $galleryInfo; } } }); }; }]); sesfControllers.controller('viewItemModal', ['$scope', '$modalInstance', 'GalleryService', '$timeout', '$log', '$rootScope', 'LoginService', '$location', 'item', 'gallery', '$window', function(scope, modalInstance, GalleryService, $timeout, $log, $rootScope, LoginService, $location, $item, $gallery, $window) { scope.item = $item; scope.gallery = $gallery; scope.close = function(){ modalInstance.dismiss('cancel'); }; }]); sesfControllers.controller('galleryCreateController', ['$scope', 'event', 'gallery', 'GalleryService', '$location', 'LoginService', '$log', '$route', function (scope, event, gallery, GalleryService, $location, LoginService, $log, $route) { scope.event = event; scope.gallery = gallery; scope.showId = $route.current.params.eventId; scope.galleryId = $route.current.params.galleryId; scope.create = function(){ var create = new GalleryService.Create(); create.save( { title: this.title, show_id: $route.current.params.eventId, gallery_id: $route.current.params.galleryId }, function(data){ $location.path("/gallery/manage/" + data.id); }, function(response){ scope.response = { response: response.data, status: 'error' }; }); } }]); sesfControllers.controller('galleryManageController', ['$scope', 'gallery', 'galleryItems', 'GalleryService', '$location', '$route', 'LoginService', '$log', function (scope, gallery, galleryItems, GalleryService, $location, $route, LoginService, $log) { scope.gallery = gallery; scope.galleryItems = galleryItems; scope.galleryId = $route.current.params.galleryId; scope.dragControlListeners = { accept: function (sourceItemHandleScope, destSortableScope) {//override to determine drag is allowed or not. default is true. return true; }, itemMoved: function (event) {//Do what you want console.log(scope.galleryItems.items); }, orderChanged: function(event) {//Do what you want $.each(scope.galleryItems.items, function(index, value){ value.sort_order = index + 1; }); } }; scope.saveItems = function(){ scope.saveResponse = {}; scope.galleryItems.$save( { gallery_id: scope.galleryId }, function(data){ scope.saveResponse = { response: 'Saved', status: 'success' }; return true; }, function(data){ scope.saveResponse = { response: 'Failed to save', status: 'error' }; return false; } ); } scope.showHideGallery = function(){ var newIsEnabled = (scope.gallery.is_enabled == 1 ? 0 : 1); GalleryService.ShowHideGallery().save( { gallery_id: scope.galleryId, is_enabled: newIsEnabled }, function(data){ scope.gallery.is_enabled = newIsEnabled; } ); } scope.deleteItem = function(item){ GalleryService.RemoveItem().save( { gallery_id: scope.galleryId, item_id: item.id }, function(data){ scope.galleryItems.items.splice(scope.galleryItems.items.indexOf(item), 1); } ); } scope.defaultItem = function(item){ GalleryService.DefaultItem().save( { gallery_id: scope.galleryId, item_id: item.id }, function(data){ if(scope.gallery.default_item === null) { scope.gallery.default_item = {}; } scope.gallery.default_item.id = item.id; } ); } }]); sesfControllers.factory( 'AdminService', [ '$rootScope', '$http', '$resource', '$route', function( rootScope, $http, $resource, $route) { var service = { getUsers: function (show_id) { return $resource('/admin2/judging_list/getUsersWithoutJudging/:showId', {showId: '@showId'}, { get: {method: 'GET', isArray: true} }); }, getJudging: function() { return $resource('/admin2/judging_list/getJudgingTypes/:showId',{}, { get: {method: 'GET', isArray: true} }); }, add: function() { return $resource('/admin2/judging_list/addJudging', {}); }, remove: function() { return $resource('/admin2/judging_list/removeJudging', {}); }, Registration: function() { return $resource('event/registration', {show_id: $route.current.params.eventId}); }, Extra: function() { return $resource('event/extra', {extra_id: $route.current.params.extraId}); }, Cars: function() { return $resource('event/cars', {show_id: $route.current.params.eventId}); }, Sponsors: function() { return $resource('event/sponsors', {show_id: $route.current.params.eventId}); }, Schedule: function() { return $resource('event/schedule', {show_id: $route.current.params.eventId}); } }; return service; }]); sesfControllers.controller('newJudging', ['$scope', 'AdminService', '$window', function($scope, AdminService, $window) { $scope.selectUser = function(){ $scope.user = JSON.parse($scope.userRaw); console.log('user', $scope.user); } $scope.selectCar = function(){ $scope.car = JSON.parse($scope.carRaw); console.log('car', $scope.car); AdminService.getJudging() .get({showId: $scope.showId, body_id: $scope.car.body_id}) .$promise .then(function(response){ $scope.judgingTypes = response; console.log($scope.judging); }); } $scope.selectJudging = function(){ $scope.judging = JSON.parse($scope.judgingRaw); } $scope.init = function(showId){ $scope.showId = null; $scope.users = []; $scope.judgingTypes = []; $scope.user = {}; $scope.car = {}; $scope.showId = showId; AdminService.getUsers() .get({showId: showId}) .$promise .then(function(response){ $scope.users = response; console.log($scope.users); }); } $scope.add = function(){ console.log($scope.car, $scope.user, $scope.judging); var Judging = AdminService.add(); var judging = new Judging({registration_id: $scope.user.id, car_id: $scope.car.id, judging_type_id: $scope.judging.id}); console.log(judging); judging.$save(null, function(){ $scope.init($scope.showId); $window.location.reload(); }); } $scope.remove = function(){ var Judging = AdminService.remove(); var judging = new Judging({registration_id: $scope.user.id, car_id: $scope.car.id}); judging.$save(null, function(){ $scope.init($scope.showId); $window.location.reload(); }); } }]); sesfControllers.controller('judgingAdmin', ['$scope', 'AdminService', '$window', function($scope, AdminService, $window) { $scope.remove = function(car_id, registration_id){ if(confirm('are you sure?')) { console.log('here'); var Judging = AdminService.remove(); var judging = new Judging({registration_id: registration_id, car_id: car_id}); judging.$save(null, function(){ $window.location.reload(); }); } } }]);