/* Controllers */
-
-function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route, View) {
+function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route, Organizations, RegistrationStatus) {
$scope.$routeParams = $routeParams;
$scope.$location = $location;
$scope.organizations = [];
+ Organizations.getArrayPromise().then(function(data) {
+ $scope.organizations = data;
+ $log.info('organizations promise ', $scope.organizations);
+ });
+ $scope.RegistrationStatus = RegistrationStatus;
+
+ $scope.update = function(registration, state) {
- $scope.update = function(registration) {
+ registration.state = state;
if ( ! $scope.has_work && registration.work ) {
delete( registration.work );
registration.$save( function(registration) {
$log.info("saved", registration);
- $log.info('id =', registration.id);
- if ( registration.id ) {
- $location.path( '/confirmation/' + registration.id );
+ $log.info('id =', registration.id, 'state = ', registration.state);
+ if ( registration.id && registration.state ) {
+ $location.path( '/' + registration.state + '/' + registration.id );
} else {
$log.error("can't find id in ", registration);
}
$log.info( $routeParams.registrationId );
- $scope.view = new View();
-if(0){//FIXME
- $scope.view.$get({ view: 'organizations' }, function(result) {
- $log.info('View organizations', result);
- angular.forEach( result.rows, function(value, key) {
- this.push( value.key ); // name of organization
- }, $scope.organizations );
- $log.info('organizations', $scope.organizations);
- });
-}else{//FIXME
- $scope.view.$key_array({ view: 'organizations' }, function(result) {
- $log.info('key_array', result);
-// $scope.organizations = result.rows; // FIXME doesn't refresh bs-typeahead
- angular.forEach( result.rows, function(o) {
- this.push( o );
- }, $scope.organizations );
- $log.info('organizations', $scope.organizations);
- });
}
-}//FIXME
$scope.$watch('user.registration_type', function( oldValue, newValue ) {
$log.info("registration_type watch", oldValue, newValue );
}
}
- $scope.abstract_class = function(abstract) {
- return abstract.length < 2000 ? 'ok' : 'ng-invalid';
+ $scope.abstract_class = function(work) {
+ if ( work === undefined ) return;
+ var abstract = work.abstract;
+ return angular.isString(abstract) && abstract.length <= 2000 ? 'ok' : 'ng-invalid';
}
- $scope.abstract_length = function(abstract) {
- return abstract.length < 2000 ? abstract.length : 2000 - abstract.length;
+ $scope.abstract_length = function(work) {
+ if ( work === undefined ) return;
+ var abstract = work.abstract;
+ if ( ! abstract ) return 0;
+ return abstract.length <= 2000 ? abstract.length : 2000 - abstract.length;
}
$scope.reset();
}
-//RegistrationCtrl.$inject = [ '$scope', '$log' ];
+RegistrationCtrl.$inject = [ '$scope', '$log', 'Registration', '$routeParams', '$location', '$route', 'Organizations' ];
function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter) {
$scope.list = [];
+ $scope.list_results = 0;
+ $scope.pager = {
+ page: 1,
+ limit: 10,
+ results: 0,
+ last_page: 0
+ };
$scope.search = {};
$scope.ready = false;
+ $scope.filters = [ 'student', 'hpd_member', 'reception', 'dinner' ];
$scope.all_registrations = Registration.query( function() {
- var RegistrationTypeCount = { '': 0 };
- angular.forEach( $scope.all_registrations, function(value, key) {
- var type = value.user.registration_type;
- if ( ! angular.isNumber( RegistrationTypeCount[type] ) ) {
- RegistrationTypeCount[type] = 1;
+ var Counts = {};
+ var inc_count = function(type) {
+ if ( ! angular.isNumber( Counts[type] ) ) {
+ Counts[type] = 1;
} else {
- RegistrationTypeCount[type]++;
+ Counts[type]++;
+ }
+ };
+ angular.forEach( $scope.all_registrations, function(value, key) {
+ if ( ! value.user ) {
+ $log.error("all_registrations user corrupted for registration", key, value);
+ return;
}
- RegistrationTypeCount['']++;
- value.registration_type = type; // for search
-
-// $log.info( key, value.user.registration_type, RegistrationTypeCount[type] );
+ var type = value.user.registration_type;
+ inc_count( type );
+ inc_count( '' ); // total
+ angular.forEach( $scope.filters, function(subtype) {
+ var v = value.user[subtype];
+ if ( v === 'yes' || v === true ) {
+ inc_count( subtype );
+ inc_count( type + '+' + subtype );
+ inc_count( '+' + subtype ); // total
+ }
+ });
+
+ // for filter
+ value.registration_type = type;
+ angular.forEach( $scope.filters, function(f) {
+ var v = value.user[f];
+ value[f] = v == true || v == 'yes' ? true : false;
+ });
+
+// $log.info( key, value, Counts[type] );
});
- $log.info('RegistrationTypeCount', RegistrationTypeCount);
- $scope.RegistrationTypeCount = RegistrationTypeCount;
+ $log.info('Counts', Counts);
+ $scope.Counts = Counts;
-// $scope.list = $scope.all_registrations; // FIXME show all registrations on page load
+// $scope.list = $scope.all_registrations; // FIXME show all registrations on page loadyy
$scope.ready = true;
+
});
$scope.filter_list = function(newVal, oldVal) {
- $scope.list = $filter('filter')($scope.all_registrations, $scope.search);
- $log.info('filter_list', newVal, oldVal, 'search', $scope.search, 'results', $scope.list);
+ if ( newVal == oldVal ) return;
+ $log.info('filter_list', newVal, oldVal, 'search', $scope.search);
+ var filtered =
+ $filter('filter')($scope.all_registrations, $scope.search);
+
+// $scope.pager.page = 1;
+ $scope.pager.results = filtered.length;
+ $scope.pager.last_page = Math.ceil( $scope.pager.results / $scope.pager.limit );
+ if ( $scope.pager.page > $scope.pager.last_page ) {
+ $scope.pager.page = 1;
+ }
+ $log.info('pager', $scope.pager);
+
+ var from = ( $scope.pager.page - 1 ) * $scope.pager.limit;
+ $scope.list = [];
+ angular.forEach( filtered, function(v,k) {
+ if ( k >= from && k < from + $scope.pager.limit ) {
+ v.nr = k + 1;
+ this.push(v);
+ }
+ }, $scope.list );
+ $log.info('list length=', $scope.list.length, "offset=", from);
};
+ angular.forEach( $scope.filters, function(f) {
+ $scope.$watch('search.'+f, $scope.filter_list);
+ $log.info('watch search.'+f);
+ });
$scope.$watch('search.registration_type', $scope.filter_list);
- $scope.$watch('search.$', $scope.filter_list); // $ is skipped by search watch!!
+ $scope.$watch('search.$', $scope.filter_list);
+ $scope.$watch('pager.page', $scope.filter_list);
+ $scope.$watch('pager.limit', $scope.filter_list);
$scope.RegistrationTypes = RegistrationTypes;
$log.info( "RegistrationTypes", RegistrationTypes );
}
-function MyCtrl2() {
-}
-MyCtrl2.$inject = [];
+ListCtrl.$inject = [ '$scope', '$log', 'Registration', 'RegistrationTypes', '$filter' ];