CRM-14725 - Load case-type based on ID in URL ("/civicrm/a/#/caseType/123")
authorTim Otten <totten@civicrm.org>
Thu, 22 May 2014 01:51:29 +0000 (18:51 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 22 May 2014 01:51:29 +0000 (18:51 -0700)
js/angular-crmCaseType.js
partials/crmCaseType/caseTypeDetails.html

index c400ae61ff3928090d924f834f4294e243ef8e0c..35037757b3ca8b6066a4741ab227c405979c8560 100644 (file)
@@ -6,11 +6,37 @@
 
   var crmCaseType = angular.module('crmCaseType', ['ngRoute', 'ui.utils']);
 
+  var newCaseTypeDefinitionTemplate = {
+    activityTypes: [
+      {name: 'Open Case', max_instances: 1 },
+      {name: 'Example activity'}
+    ],
+    activitySets: [
+      {
+        name: 'standard_timeline',
+        label: 'Standard Timeline',
+        timeline: '1', // Angular won't bind checkbox correctly with numeric 1
+        activityTypes: [
+          {name: 'Open Case', status: 'Completed' },
+          {name: 'Example activity', reference_activity: 'Open Case', reference_offset: 3, reference_select: 'newest'}
+        ]
+      }
+    ],
+    caseRoles: [
+      { name: 'Case Coordinator', creator: '1', manager: '1'}
+    ]
+  };
+
   crmCaseType.config(['$routeProvider',
     function($routeProvider) {
       $routeProvider.when('/caseType/:id', {
         templateUrl: partialUrl('edit.html'),
-        controller: 'CaseTypeCtrl'
+        controller: 'CaseTypeCtrl',
+        resolve: {
+          selectedCaseType: function($route, crmApi) {
+            return crmApi('CaseType', 'getsingle', {id: $route.current.params.id});
+          }
+        }
       });
     }
   ]);
@@ -29,7 +55,7 @@
     };
   });
 
-  crmCaseType.controller('CaseTypeCtrl', function($scope, crmApi) {
+  crmCaseType.controller('CaseTypeCtrl', function($scope, crmApi, selectedCaseType) {
     $scope.partialUrl = partialUrl;
 
     $scope.activityStatuses = CRM.crmCaseType.actStatuses;
       'pipeline': 'Sequence'
     };
 
-    $scope.caseType = {
-      id: 123,
-      label: 'Adult Day Care Referral',
-      description: 'Superkalafragalisticexpialitotious',
-      is_active: '1', // Angular won't bind checkbox correctly with numeric 1
-      definition: {  // This is the serialized field
-        name: 'Adult Day Care Referral',
-        activityTypes: [
-          {name: 'Open Case', max_instances: 1 },
-          {name: 'Medical evaluation'}
-        ],
-        activitySets: [
-          {
-            name: 'standard_timeline',
-            label: 'Standard Timeline',
-            timeline: '1', // Angular won't bind checkbox correctly with numeric 1
-            activityTypes: [
-              {name: 'Open Case', status: 'Completed' },
-              {name: 'Medical evaluation', reference_activity: 'Open Case', reference_offset: 3, reference_select: 'newest'}
-            ]
-          },
-          {
-            name: 'my_sequence',
-            label: 'My Sequence',
-            pipeline: '1', // Angular won't bind checkbox correctly with numeric 1
-            activityTypes: [
-              {name: 'Medical evaluation'},
-              {name: 'Meeting'},
-              {name: 'Phone Call'}
-            ]
-          }
-
-        ],
-        caseRoles: [
-          { name: 'Senior Services Coordinator', creator: '1', manager: '1' },
-          { name: 'Health Services Coordinator' },
-          { name: 'Benefits Specialist' }
-        ]
-      }
-    };
+    $scope.caseType = selectedCaseType;
+    $scope.caseType.definition = $scope.caseType.definition || _.extend({}, newCaseTypeDefinitionTemplate);
+    $scope.caseType.definition.activityTypes = $scope.caseType.definition.activityTypes || [];
+    $scope.caseType.definition.activitySets = $scope.caseType.definition.activitySets || [];
+    $scope.caseType.definition.caseRoles = $scope.caseType.definition.caseRoles || [];
     window.ct = $scope.caseType;
 
     $scope.addActivitySet = function(workflow) {
index c7f89b5dce71e4f9f431d6802a87b1f18d297719..912b40745a614410fcfed84c4ba855b1e041cc40 100644 (file)
@@ -9,13 +9,13 @@ The original form used table layout; don't know if we have an alternative, CSS-b
   <tr>
     <td class="label">Label</td>
     <td>
-      <input type="text" ng-model="caseType.label"/>
+      <input type="text" ng-model="caseType.title"/>
     </td>
   </tr>
   <tr>
     <td class="label">Name</td>
     <td>
-      <input type="text" ng-model="caseType.definition.name"/> <!-- FIXME lock -->
+      <input type="text" ng-model="name"/> <!-- FIXME lock -->
     </td>
   </tr>
   <tr>