CRM-15970 - crmMailingAB - Add support for filtering and sorting
authorTim Otten <totten@civicrm.org>
Tue, 17 Feb 2015 22:05:26 +0000 (14:05 -0800)
committerTim Otten <totten@civicrm.org>
Wed, 18 Feb 2015 03:13:13 +0000 (19:13 -0800)
js/angular-crmMailingAB.js
partials/crmMailingAB/list.html

index e1b822a5e09f5fb1f981a4ee95631b32edc128b6..c5861d45ff2fd55143aa937935a3399bfd1ffbf3 100644 (file)
@@ -10,6 +10,9 @@
         resolve: {
           mailingABList: function ($route, crmApi) {
             return crmApi('MailingAB', 'get', {rowCount: 0});
+          },
+          fields: function(crmMetadata){
+            return crmMetadata.getFields('MailingAB');
           }
         }
       });
     }
   ]);
 
-  angular.module('crmMailingAB').controller('CrmMailingABListCtrl', function ($scope, mailingABList, crmMailingABCriteria, crmMailingABStatus) {
+  angular.module('crmMailingAB').controller('CrmMailingABListCtrl', function($scope, mailingABList, crmMailingABCriteria, crmMailingABStatus, fields) {
     var ts = $scope.ts = CRM.ts(null);
-    $scope.mailingABList = mailingABList.values;
+    $scope.mailingABList = _.values(mailingABList.values);
     $scope.crmMailingABCriteria = crmMailingABCriteria;
     $scope.crmMailingABStatus = crmMailingABStatus;
+    $scope.fields = fields;
+    $scope.filter = {};
   });
 
   angular.module('crmMailingAB').controller('CrmMailingABNewCtrl', function ($scope, abtest, $location) {
index 06c3a8afa1e50e1b56a21d102522326a6f05c415..a59ce9fa8dc325e3350b805476519f8b9c46d35b 100644 (file)
@@ -3,21 +3,45 @@ Controller: ABListingCtrl
 Required vars: mailingABList
 -->
 
+<span crm-ui-order="{var: 'myOrder', defaults: ['-created_date']}"></span>
+
+<div crm-ui-accordion crm-title="ts('Filter')" crm-collapsed="true">
+  <form name="filterForm">
+    <span>
+      <input class="big crm-form-text" ng-model="filter.name" placeholder="{{ts('Name')}}"/>
+    </span>
+    <span>
+      <select crm-ui-select style="width: 10em;" ng-model="filter.status">
+        <option value="">{{ts('- Status -')}}</option>
+        <option ng-repeat="o in fields.status.options" ng-value="o.key">{{o.value}}</option>
+      </select>
+    </span>
+    <span>
+      <select crm-ui-select style="width: 20em;" ng-model="filter.testing_criteria_id">
+        <option value="">{{ts('- Test Type -')}}</option>
+        <option ng-repeat="o in fields.testing_criteria_id.options" ng-value="o.key">{{crmMailingABCriteria.get(o.key).label}}</option>
+      </select>
+    </span>
+  </form>
+</div>
+
 <div ng-show="!$.isEmptyObject(mailingABList)">
   <table class="display">
     <thead>
     <tr>
-      <th>{{ts('Name')}}</th>
-      <th>{{ts('Status')}}</th>
-      <th>{{ts('Test Type')}}</th>
+      <th><a crm-ui-order-by="[myOrder, 'name']">{{ts('Name')}}</a></th>
+      <th><a crm-ui-order-by="[myOrder, 'status']">{{ts('Status')}}</a></th>
+      <th><a crm-ui-order-by="[myOrder, 'testing_criteria_id']">{{ts('Test Type')}}</a></th>
+      <th><a crm-ui-order-by="[myOrder, 'created_date']">{{ts('Created')}}</a></th>
       <th></th>
     </tr>
     </thead>
     <tbody>
-    <tr ng-repeat="mailingAB in mailingABList">
+    <tr ng-repeat="mailingAB in mailingABList | filter:filter | orderBy:myOrder.get()">
       <td>{{mailingAB.name}}</td>
       <td>{{crmMailingABStatus.getByName(mailingAB.status).label}}</td>
       <td>{{crmMailingABCriteria.get(mailingAB.testing_criteria_id).label}}</td>
+      <td>{{mailingAB.created_date}}</td>
       <td>
         <a class="action-item crm-hover-button" ng-href="#/abtest/{{mailingAB.id}}" ng-show="mailingAB.status == 'Draft'">{{ts('Continue')}}</a>
         <a class="action-item crm-hover-button" ng-href="#/abtest/{{mailingAB.id}}/report" ng-show="mailingAB.status != 'Draft'">{{ts('Results')}}</a>