Multiple Angular modules - Remove partialUrl() helper
authorTim Otten <totten@civicrm.org>
Fri, 23 Jan 2015 08:02:20 +0000 (00:02 -0800)
committerTim Otten <totten@civicrm.org>
Sat, 24 Jan 2015 02:46:11 +0000 (18:46 -0800)
This helper provided a bit of indirection so that we didn't need to
hard-code crazylong templateUrls.  crmResource now provides that indirection
in a prettier way, so partialUrl() is extraneous.

js/angular-crm-ui.js
js/angular-crmAttachment.js
js/angular-crmCaseType.js
js/angular-crmMailing.js
js/angular-crmMailing/directives.js
js/angular-crmMailing/services.js
js/angular-crmMailingAB.js
js/angular-crmMailingAB/directives.js
partials/crmCaseType/edit.html

index f4920de93be7257c1dac2224e0a9dc44f0320e3f..4ead37a3e8ab5082c23bf38f0c97998133e04fad 100644 (file)
@@ -3,10 +3,6 @@
 
   var uidCount = 0;
 
-  var partialUrl = function (relPath) {
-    return '~/crmUi/' + relPath;
-  };
-
   angular.module('crmUi', [])
 
     // example <div crm-ui-accordion crm-title="ts('My Title')" crm-collapsed="true">...content...</div>
     .directive('crmUiField', function() {
       // Note: When writing new templates, the "label" position is particular. See/patch "var label" below.
       var templateUrls = {
-        default: partialUrl('field.html'),
-        checkbox: partialUrl('field-cb.html')
+        default: '~/crmUi/field.html',
+        checkbox: '~/crmUi/field-cb.html'
       };
 
       return {
         scope: {
           crmUiTabSet: '@'
         },
-        templateUrl: partialUrl('tabset.html'),
+        templateUrl: '~/crmUi/tabset.html',
         transclude: true,
         controllerAs: 'crmUiTabSetCtrl',
         controller: function($scope, $parse) {
         scope: {
           crmUiWizard: '@'
         },
-        templateUrl: partialUrl('wizard.html'),
+        templateUrl: '~/crmUi/wizard.html',
         transclude: true,
         controllerAs: 'crmUiWizardCtrl',
         controller: function($scope, $parse) {
index a8082879f9b9e0699fe2d276b2ca5781f2c32388..a859f9258729f97a88d88fe38980387a67259a9f 100644 (file)
@@ -1,8 +1,5 @@
 /// crmFile: Manage file attachments
 (function (angular, $, _) {
-  var partialUrl = function (relPath) {
-    return '~/crmAttachment/' + relPath;
-  };
 
   angular.module('crmAttachment', ['angularFileUpload']);
 
         var model = $parse(attr.crmAttachments);
         scope.att = model(scope.$parent);
         scope.ts = CRM.ts(null);
-        scope.inclUrl = partialUrl('attachments.html');
+        scope.inclUrl = '~/crmAttachment/attachments.html';
 
         // delay rendering of child tree until after model has been populated
         scope.ready = true;
index ba71d5c986de1a97be54ea5319fdc32768b6ab42..cb5e5797a57d99f50ab29e697c22ec6d17b7e52c 100644 (file)
@@ -1,9 +1,5 @@
 (function(angular, $, _) {
 
-  var partialUrl = function(relPath) {
-    return '~/crmCaseType/' + relPath;
-  };
-
   var crmCaseType = angular.module('crmCaseType', ['ngRoute', 'ui.utils', 'crmUi', 'unsavedChanges', 'crmUtil']);
 
   // Note: This template will be passed to cloneDeep(), so don't put any funny stuff in here!
@@ -39,7 +35,7 @@
   crmCaseType.config(['$routeProvider',
     function($routeProvider) {
       $routeProvider.when('/caseType', {
-        templateUrl: partialUrl('list.html'),
+        templateUrl: '~/crmCaseType/list.html',
         controller: 'CaseTypeListCtrl',
         resolve: {
           caseTypes: function($route, crmApi) {
@@ -48,7 +44,7 @@
         }
       });
       $routeProvider.when('/caseType/:id', {
-        templateUrl: partialUrl('edit.html'),
+        templateUrl: '~/crmCaseType/edit.html',
         controller: 'CaseTypeCtrl',
         resolve: {
           apiCalls: function($route, crmApi) {
   });
 
   crmCaseType.controller('CaseTypeCtrl', function($scope, crmApi, apiCalls) {
-    $scope.partialUrl = partialUrl;
     var ts = $scope.ts = CRM.ts(null);
 
     $scope.activityStatuses = _.values(apiCalls.actStatuses.values);
      */
     $scope.activityTableTemplate = function(activitySet) {
       if (activitySet.timeline) {
-        return partialUrl('timelineTable.html');
+        return '~/crmCaseType/timelineTable.html';
       } else if (activitySet.sequence) {
-        return partialUrl('sequenceTable.html');
+        return '~/crmCaseType/sequenceTable.html';
       } else {
         return '';
       }
index 317a6f899eddf975014ba24b051c9bb724981e25..74babf0c6eef9929341b9cc5acc55ea1cf0bf44a 100644 (file)
@@ -1,7 +1,4 @@
 (function (angular, $, _) {
-  var partialUrl = function partialUrl(relPath) {
-    return '~/crmMailing/' + relPath;
-  };
 
   angular.module('crmMailing', [
     'crmUtil', 'crmAttachment', 'ngRoute', 'ui.utils', 'crmUi', 'dialogService'
       });
 
       var editorPaths = {
-        '': partialUrl('edit.html'),
-        '/unified': partialUrl('edit-unified.html'),
-        '/unified2': partialUrl('edit-unified2.html'),
-        '/wizard': partialUrl('edit-wizard.html')
+        '': '~/crmMailing/edit.html',
+        '/unified': '~/crmMailing/edit-unified.html',
+        '/unified2': '~/crmMailing/edit-unified2.html',
+        '/wizard': '~/crmMailing/edit-wizard.html'
       };
       angular.forEach(editorPaths, function(editTemplate, pathSuffix) {
         $routeProvider.when('/mailing/new' + pathSuffix, {
@@ -72,7 +69,6 @@
     $scope.attachments.load();
     $scope.crmMailingConst = CRM.crmMailing;
 
-    $scope.partialUrl = partialUrl;
     var ts = $scope.ts = CRM.ts(null);
 
     $scope.isSubmitted = function isSubmitted() {
           1: $scope.getRecipientsEstimate()
         })
       };
-      dialogService.open('recipDialog', partialUrl('dialog/recipients.html'), model, options);
+      dialogService.open('recipDialog', '~/crmMailing/dialog/recipients.html', model, options);
     };
   });
 
         modal: true,
         title: title // component[0].name
       };
-      dialogService.open('previewComponentDialog', partialUrl('dialog/previewComponent.html'), component[0], options);
+      dialogService.open('previewComponentDialog', '~/crmMailing/dialog/previewComponent.html', component[0], options);
     };
   });
 
         modal: true,
         title: ts('Save Template')
       };
-      return dialogService.open('saveTemplateDialog', partialUrl('dialog/saveTemplate.html'), model, options)
+      return dialogService.open('saveTemplateDialog', '~/crmMailing/dialog/saveTemplate.html', model, options)
         .then(function (item) {
           mailing.msg_template_id = item.id;
           return item;
index 85ba61c85a0667d963747945e5dace0d6abd258d..a66f854ce1ce956f5d7e0263aa77216971c22379 100644 (file)
@@ -1,21 +1,18 @@
 (function (angular, $, _) {
-  var partialUrl = function (relPath) {
-    return '~/crmMailing/' + relPath;
-  };
 
   // The following directives have the same simple implementation -- load
   // a template and export a "mailing" object into scope.
   var simpleBlocks = {
-    crmMailingBlockHeaderFooter: partialUrl('headerFooter.html'),
-    crmMailingBlockMailing: partialUrl('mailing.html'),
-    crmMailingBlockPublication: partialUrl('publication.html'),
-    crmMailingBlockResponses: partialUrl('responses.html'),
-    crmMailingBlockRecipients: partialUrl('recipients.html'),
-    crmMailingBlockSchedule: partialUrl('schedule.html'),
-    crmMailingBlockSummary: partialUrl('summary.html'),
-    crmMailingBlockTracking: partialUrl('tracking.html'),
-    crmMailingBodyHtml: partialUrl('body_html.html'),
-    crmMailingBodyText: partialUrl('body_text.html')
+    crmMailingBlockHeaderFooter: '~/crmMailing/headerFooter.html',
+    crmMailingBlockMailing: '~/crmMailing/mailing.html',
+    crmMailingBlockPublication: '~/crmMailing/publication.html',
+    crmMailingBlockResponses: '~/crmMailing/responses.html',
+    crmMailingBlockRecipients: '~/crmMailing/recipients.html',
+    crmMailingBlockSchedule: '~/crmMailing/schedule.html',
+    crmMailingBlockSummary: '~/crmMailing/summary.html',
+    crmMailingBlockTracking: '~/crmMailing/tracking.html',
+    crmMailingBodyHtml: '~/crmMailing/body_html.html',
+    crmMailingBodyText: '~/crmMailing/body_text.html'
   };
   _.each(simpleBlocks, function(templateUrl, directiveName){
     angular.module('crmMailing').directive(directiveName, function ($parse) {
@@ -39,7 +36,7 @@
   // note: the directive defines a variable called "preview" with any inputs supplied by the user (e.g. the target recipient for an example mailing)
   angular.module('crmMailing').directive('crmMailingBlockPreview', function ($parse) {
     return {
-      templateUrl: partialUrl('preview.html'),
+      templateUrl: '~/crmMailing/preview.html',
       link: function (scope, elm, attr) {
         var mailingModel = $parse(attr.crmMailing);
         scope.mailing = mailingModel(scope);
@@ -67,7 +64,7 @@
       scope: {
         crmMailing: '@'
       },
-      templateUrl: partialUrl('review.html'),
+      templateUrl: '~/crmMailing/review.html',
       link: function (scope, elm, attr) {
         var mailingModel = $parse(attr.crmMailing);
         scope.mailing = mailingModel(scope.$parent);
         crmAvailMailings: '@', // available mailings
         crmMailing: '@' // the mailing for which we are choosing recipients
       },
-      templateUrl: partialUrl('directive/recipients.html'),
+      templateUrl: '~/crmMailing/directive/recipients.html',
       link: function (scope, element, attrs) {
         scope.mailing = scope.$parent.$eval(attrs.crmMailing);
         scope.groups = scope.$parent.$eval(attrs.crmAvailGroups);
index cb4fb936b179ff7147b0aa4f5615f7dc9d1a0b6c..342d760941d9d469fd4f092c33a775b79efd8149 100644 (file)
@@ -1,7 +1,4 @@
 (function (angular, $, _) {
-  var partialUrl = function (relPath) {
-    return '~/crmMailing/' + relPath;
-  };
 
   // The representation of from/reply-to addresses is inconsistent in the mailing data-model,
   // so the UI must do some adaptation. The crmFromAddresses provides a richer way to slice/dice
       // @return Promise
       preview: function preview(mailing, mode) {
         var templates = {
-          html: partialUrl('dialog/previewHtml.html'),
-          text: partialUrl('dialog/previewText.html'),
-          full: partialUrl('dialog/previewFull.html')
+          html: '~/crmMailing/dialog/previewHtml.html',
+          text: '~/crmMailing/dialog/previewText.html',
+          full: '~/crmMailing/dialog/previewFull.html'
         };
         var result = null;
         var p = crmMailingMgr
index ddc532a319731925fb895e46d9a607804f3be8db..77262db65f560f90f802640a0abe451b5ef74447 100644 (file)
@@ -1,18 +1,11 @@
 (function (angular, $, _) {
 
-  var partialUrl = function (relPath, module) {
-    if (!module) {
-      module = 'crmMailingAB';
-    }
-    return '~/' + module + '/' + relPath;
-  };
-
   angular.module('crmMailingAB', ['ngRoute', 'ui.utils', 'ngSanitize', 'crmUi', 'crmAttachment', 'crmMailing', 'crmD3']);
   angular.module('crmMailingAB').config([
     '$routeProvider',
     function ($routeProvider) {
       $routeProvider.when('/abtest', {
-        templateUrl: partialUrl('list.html'),
+        templateUrl: '~/crmMailingAB/list.html',
         controller: 'CrmMailingABListCtrl',
         resolve: {
           mailingABList: function ($route, crmApi) {
@@ -21,7 +14,7 @@
         }
       });
       $routeProvider.when('/abtest/:id', {
-        templateUrl: partialUrl('edit.html'),
+        templateUrl: '~/crmMailingAB/edit.html',
         controller: 'CrmMailingABEditCtrl',
         resolve: {
           abtest: function ($route, CrmMailingAB) {
@@ -31,7 +24,7 @@
         }
       });
       $routeProvider.when('/abtest/:id/report', {
-        templateUrl: partialUrl('report.html'),
+        templateUrl: '~/crmMailingAB/report.html',
         controller: 'CrmMailingABReportCtrl',
         resolve: {
           abtest: function ($route, CrmMailingAB) {
@@ -55,7 +48,6 @@
     var ts = $scope.ts = CRM.ts(null);
     $scope.crmMailingABCriteria = crmMailingABCriteria;
     $scope.crmMailingConst = CRM.crmMailing;
-    $scope.partialUrl = partialUrl;
 
     $scope.isSubmitted = function isSubmitted() {
       return _.size(abtest.mailings.a.jobs) > 0 || _.size(abtest.mailings.b.jobs) > 0;
           1: mailingName.toUpperCase()
         })
       };
-      return dialogService.open('selectWinnerDialog', partialUrl('selectWinner.html'), model, options);
+      return dialogService.open('selectWinnerDialog', '~/crmMailingAB/selectWinner.html', model, options);
     };
   });
 
index ebd388aa6ddeb20d1391326c6b6f2070f47c1a2a..17071a55ee9a1e8be121c444859d963c4493acd1 100644 (file)
@@ -1,14 +1,11 @@
 (function (angular, $, _) {
-  var partialUrl = function (relPath) {
-    return '~/crmMailingAB/' + relPath;
-  };
 
   // example:
   //   scope.myAbtest = new CrmMailingAB();
   //   <crm-mailing-ab-block-mailing="{fromAddressA: 1, fromAddressB: 1}" crm-abtest="myAbtest" />
   var simpleDirectives = {
-    crmMailingAbBlockMailing: partialUrl('joint-mailing.html'),
-    crmMailingAbBlockSetup: partialUrl('setup.html')
+    crmMailingAbBlockMailing: '~/crmMailingAB/joint-mailing.html',
+    crmMailingAbBlockSetup: '~/crmMailingAB/setup.html'
   };
   _.each(simpleDirectives, function (templateUrl, directiveName) {
     angular.module('crmMailingAB').directive(directiveName, function ($parse, crmMailingABCriteria) {
@@ -37,7 +34,7 @@
     return {
       require: '?ngModel',
       scope: {},
-      templateUrl: partialUrl('slider.html'),
+      templateUrl: '~/crmMailingAB/slider.html',
       link: function (scope, element, attrs, ngModel) {
         var TEST_MIN = 1, TEST_MAX = 50;
         var sliders = $('.slider-test,.slider-win', element);
index 0c3c44ac16b82f009ce5451c4dddb930641e689a..d4dd55ff73d4b6a452b5000516ee9eeaf590ca59 100644 (file)
@@ -16,11 +16,11 @@ Required vars: caseType
     </span>
   </div>
 
-  <div ng-include="partialUrl('caseTypeDetails.html')"></div>
+  <div ng-include="'~/crmCaseType/caseTypeDetails.html'"></div>
 
   <h2 ng-show="isForkable()">Roles</h2>
 
-  <div ng-show="isForkable()" ng-include="partialUrl('rolesTable.html')"></div>
+  <div ng-show="isForkable()" ng-include="'~/crmCaseType/rolesTable.html'"></div>
 
   <h2 ng-show="isForkable()">Activities</h2>
 
@@ -46,7 +46,7 @@ Required vars: caseType
     </ul>
 
     <div id="acttab-actType">
-      <div ng-include="partialUrl('activityTypesTable.html')"></div>
+      <div ng-include="'~/crmCaseType/activityTypesTable.html'"></div>
     </div>
 
     <div ng-repeat="activitySet in caseType.definition.activitySets" id="acttab-{{$index}}">
@@ -54,7 +54,7 @@ Required vars: caseType
 
       <div class="crm-accordion-wrapper collapsed">
         <div class="crm-accordion-header">Advanced</div>
-        <div class="crm-accordion-body" ng-include="partialUrl('activitySetDetails.html')"></div>
+        <div class="crm-accordion-body" ng-include="'~/crmCaseType/activitySetDetails.html'"></div>
       </div>
     </div>
   </div>
@@ -69,4 +69,4 @@ Required vars: caseType
     </span>
   </div>
 </div>
-</form>
\ No newline at end of file
+</form>