CRM-14798 - crmCaseType - Load fresh list of activity-types, activity-statuses, and...
authorTim Otten <totten@civicrm.org>
Thu, 3 Jul 2014 02:24:14 +0000 (19:24 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 3 Jul 2014 03:10:39 +0000 (20:10 -0700)
To avoid additional round-trips, consolidate all loads into a single API call.

CRM/Case/Info.php
js/angular-crmCaseType.js

index 6cdfb926502d79765ef495e961a1a01dc6f9f194..d62a10cbdbcddc6353a8e3c13837a1e30282b541 100644 (file)
@@ -65,29 +65,10 @@ class CRM_Case_Info extends CRM_Core_Component_Info {
       'js' => array('js/angular-crmCaseType.js'),
       'css' => array('css/angular-crmCaseType.css'),
     );
-    // Need full OptionValue records
-    $actStatuses = civicrm_api3('OptionValue', 'get', array('option_group_id' => 'activity_status'));
-    $actTypes = civicrm_api3('OptionValue', 'get', array(
-      'option_group_id' => 'activity_type',
-      'options' => array(
-        'sort' => 'name',
-        'limit' => 0,
-      ),
-    ));
-    $relTypes = civicrm_api3('RelationshipType', 'get', array(
-      'options' => array(
-        'sort' => CRM_Case_XMLProcessor::REL_TYPE_CNAME,
-        'limit' => 0,
-      )
-    ));
 
     CRM_Core_Resources::singleton()->addSetting(array(
       'crmCaseType' => array(
-        'actStatuses' => array_values($actStatuses['values']),
-        'actTypes' => array_values($actTypes['values']),
-        'relTypes' => array_values($relTypes['values']),
-        //CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'),
-
+        'REL_TYPE_CNAME' => CRM_Case_XMLProcessor::REL_TYPE_CNAME,
       ),
     ));
     return $result;
index e4a8fdd2d06e2873c57f5ea819939b2be9fad987..e617064d2b83e91f53ed2a45cd603f680697c9c6 100644 (file)
         templateUrl: partialUrl('edit.html'),
         controller: 'CaseTypeCtrl',
         resolve: {
-          selectedCaseType: function($route, crmApi) {
-            if ( $route.current.params.id !== 'new') {
-              return crmApi('CaseType', 'getsingle', {id: $route.current.params.id});
-            }
-            else {
-              return _.cloneDeep(newCaseTypeTemplate);
+          apiCalls: function($route, crmApi) {
+            var reqs = {};
+            reqs.actStatuses = ['OptionValue', 'get', {
+              option_group_id: 'activity_status'
+            }];
+            reqs.actTypes = ['OptionValue', 'get', {
+              option_group_id: 'activity_type',
+              options: {
+                sort: 'name',
+                limit: 0
+              }
+            }];
+            reqs.relTypes = ['RelationshipType', 'get', {
+              options: {
+                sort: CRM.crmCaseType.REL_TYPE_CNAME,
+                limit: 0
+              }
+            }];
+            if ($route.current.params.id !== 'new') {
+              reqs.caseType = ['CaseType', 'getsingle', {
+                id: $route.current.params.id
+              }];
             }
+            return crmApi(reqs);
           }
         }
       });
     };
   });
 
-  crmCaseType.controller('CaseTypeCtrl', function($scope, crmApi, selectedCaseType) {
+  crmCaseType.controller('CaseTypeCtrl', function($scope, crmApi, apiCalls) {
     $scope.partialUrl = partialUrl;
 
-    $scope.activityStatuses = CRM.crmCaseType.actStatuses;
-    $scope.activityTypes = CRM.crmCaseType.actTypes;
-    $scope.activityTypeNames = _.pluck(CRM.crmCaseType.actTypes, 'name');
-    $scope.relationshipTypeNames = _.pluck(CRM.crmCaseType.relTypes, 'label_b_a'); // label_b_a is CRM_Case_XMLProcessor::REL_TYPE_CNAME
+    $scope.activityStatuses = _.values(apiCalls.actStatuses.values);
+    $scope.activityTypes = apiCalls.actTypes.values;
+    $scope.activityTypeNames = _.pluck(apiCalls.actTypes.values, 'name');
+    $scope.relationshipTypeNames = _.pluck(apiCalls.relTypes.values, CRM.crmCaseType.REL_TYPE_CNAME); // CRM_Case_XMLProcessor::REL_TYPE_CNAME
     $scope.locks = {caseTypeName: true};
 
     $scope.workflows = {
       'sequence': 'Sequence'
     };
 
-    $scope.caseType = selectedCaseType;
+    $scope.caseType = apiCalls.caseType ? apiCalls.caseType : _.cloneDeep(newCaseTypeTemplate);
     $scope.caseType.definition = $scope.caseType.definition || [];
     $scope.caseType.definition.activityTypes = $scope.caseType.definition.activityTypes || [];
     $scope.caseType.definition.activitySets = $scope.caseType.definition.activitySets || [];