filters now accept arbitrary select and have label
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 21 Feb 2013 15:07:15 +0000 (16:07 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 21 Feb 2013 15:30:56 +0000 (16:30 +0100)
app/js/controllers.js
app/partials/list.html.ep

index 7b47fb5..c4783b4 100644 (file)
@@ -202,7 +202,13 @@ function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, ValidS
        };
        $scope.search = {};
        $scope.ready = false;
-       $scope.filters = [ 'student', 'hpd_member', 'reception', 'dinner' ];
+       $scope.filters = [
+               { select: 'user.student', label: 'student', name: 'filter_student' },
+               { select: 'user.hpd_member', label: 'HPD', name: 'filter_hpd' },
+               { select: 'user.reception', label: 'reception', name: 'filter_reception' },
+               { select: 'user.dinner', label: 'dinner', name: 'filter_dinner' },
+               { select: 'payment.received', label: 'payment', name: 'filter_payment' }
+       ];
        $scope.show = {
                registration_type: true,
                filters: true,
@@ -231,26 +237,29 @@ function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, ValidS
                        var type = value.user.registration_type;
                        inc_count( type );
                        inc_count( '' ); // total
-                       angular.forEach( $scope.filters, function(subtype) {
-                               var v = value.user[subtype];
+                       angular.forEach( $scope.filters, function(filter) {
+                               var s = filter.select.split(/\./);
+                               var v = value[s[0]];
+                               if ( angular.isDefined( v ) ) {
+                                       v = v[s[1]];
+                               }
                                if ( v === 'yes' || v === true ) {
-                                       inc_count( subtype );
-                                       inc_count( type + '+' + subtype );
-                                       inc_count( '+' + subtype ); // total
+                                       inc_count( filter.name );
+                                       inc_count( type + '+' + filter.name );
+                                       inc_count( '+' + filter.name ); // total
+                                       value[filter.name] = true;
+                               } else {
+                                       value[filter.name] = false;
                                }
                        });
 
                        // 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;
-                       });
 
                        // count registration state
                        inc_count( 'state+' + value.state );
 
-//                     $log.info( key, value, Counts[type]  );
+//                     $log.info( key, value );
                });
                $log.info('Counts', Counts);
                $scope.Counts = Counts;
index 1a7927b..8262dc3 100644 (file)
@@ -20,8 +20,8 @@ Odaberite tip registracije
 <!--
  <i>{{type.description}}</i>
 -->
- <span class="badge" ng-repeat="subtype in filters" ng-show="Counts[type.code+'+'+subtype]"+>
-       {{Counts[type.code+'+'+subtype]}} {{subtype}}
+ <span class="badge" ng-repeat="filter in filters" ng-show="Counts[type.code+'+'+filter.name]"+>
+       {{Counts[type.code+'+'+filter.name]}} {{filter.label}}
  </span>
 </span>
 </label>
@@ -33,10 +33,10 @@ Odaberite tip registracije
 Filters
 </legend>
 
-<label class="badge filter-{{search[filter]}}" ng-repeat="filter in filters">
- <input ng-model="search[filter]" type="checkbox">
- {{Counts[filter]}}
- {{filter}}
+<label class="badge filter-{{search[filter.name]}}" ng-repeat="filter in filters" >
+ <input ng-model="search[filter.name]" type="checkbox">
+ {{Counts[filter.name]}}
+ {{filter.label}}
 </label>
 
 </fieldset>