From ef5d18a1b619358d9b1f07c34568da2a362976a2 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 23 Jan 2015 00:02:20 -0800 Subject: [PATCH] Multiple Angular modules - Remove partialUrl() helper 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 | 12 ++++------- js/angular-crmAttachment.js | 5 +---- js/angular-crmCaseType.js | 13 ++++-------- js/angular-crmMailing.js | 18 +++++++---------- js/angular-crmMailing/directives.js | 29 ++++++++++++--------------- js/angular-crmMailing/services.js | 9 +++------ js/angular-crmMailingAB.js | 16 ++++----------- js/angular-crmMailingAB/directives.js | 9 +++------ partials/crmCaseType/edit.html | 10 ++++----- 9 files changed, 44 insertions(+), 77 deletions(-) diff --git a/js/angular-crm-ui.js b/js/angular-crm-ui.js index f4920de93b..4ead37a3e8 100644 --- a/js/angular-crm-ui.js +++ b/js/angular-crm-ui.js @@ -3,10 +3,6 @@ var uidCount = 0; - var partialUrl = function (relPath) { - return '~/crmUi/' + relPath; - }; - angular.module('crmUi', []) // example
...content...
@@ -105,8 +101,8 @@ .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 { @@ -417,7 +413,7 @@ scope: { crmUiTabSet: '@' }, - templateUrl: partialUrl('tabset.html'), + templateUrl: '~/crmUi/tabset.html', transclude: true, controllerAs: 'crmUiTabSetCtrl', controller: function($scope, $parse) { @@ -491,7 +487,7 @@ scope: { crmUiWizard: '@' }, - templateUrl: partialUrl('wizard.html'), + templateUrl: '~/crmUi/wizard.html', transclude: true, controllerAs: 'crmUiWizardCtrl', controller: function($scope, $parse) { diff --git a/js/angular-crmAttachment.js b/js/angular-crmAttachment.js index a8082879f9..a859f92587 100644 --- a/js/angular-crmAttachment.js +++ b/js/angular-crmAttachment.js @@ -1,8 +1,5 @@ /// crmFile: Manage file attachments (function (angular, $, _) { - var partialUrl = function (relPath) { - return '~/crmAttachment/' + relPath; - }; angular.module('crmAttachment', ['angularFileUpload']); @@ -131,7 +128,7 @@ 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; diff --git a/js/angular-crmCaseType.js b/js/angular-crmCaseType.js index ba71d5c986..cb5e5797a5 100644 --- a/js/angular-crmCaseType.js +++ b/js/angular-crmCaseType.js @@ -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) { @@ -127,7 +123,6 @@ }); crmCaseType.controller('CaseTypeCtrl', function($scope, crmApi, apiCalls) { - $scope.partialUrl = partialUrl; var ts = $scope.ts = CRM.ts(null); $scope.activityStatuses = _.values(apiCalls.actStatuses.values); @@ -264,9 +259,9 @@ */ $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 ''; } diff --git a/js/angular-crmMailing.js b/js/angular-crmMailing.js index 317a6f899e..74babf0c6e 100644 --- a/js/angular-crmMailing.js +++ b/js/angular-crmMailing.js @@ -1,7 +1,4 @@ (function (angular, $, _) { - var partialUrl = function partialUrl(relPath) { - return '~/crmMailing/' + relPath; - }; angular.module('crmMailing', [ 'crmUtil', 'crmAttachment', 'ngRoute', 'ui.utils', 'crmUi', 'dialogService' @@ -20,10 +17,10 @@ }); 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() { @@ -253,7 +249,7 @@ 1: $scope.getRecipientsEstimate() }) }; - dialogService.open('recipDialog', partialUrl('dialog/recipients.html'), model, options); + dialogService.open('recipDialog', '~/crmMailing/dialog/recipients.html', model, options); }; }); @@ -291,7 +287,7 @@ 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); }; }); @@ -326,7 +322,7 @@ 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; diff --git a/js/angular-crmMailing/directives.js b/js/angular-crmMailing/directives.js index 85ba61c85a..a66f854ce1 100644 --- a/js/angular-crmMailing/directives.js +++ b/js/angular-crmMailing/directives.js @@ -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); @@ -237,7 +234,7 @@ 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); diff --git a/js/angular-crmMailing/services.js b/js/angular-crmMailing/services.js index cb4fb936b1..342d760941 100644 --- a/js/angular-crmMailing/services.js +++ b/js/angular-crmMailing/services.js @@ -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 @@ -356,9 +353,9 @@ // @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 diff --git a/js/angular-crmMailingAB.js b/js/angular-crmMailingAB.js index ddc532a319..77262db65f 100644 --- a/js/angular-crmMailingAB.js +++ b/js/angular-crmMailingAB.js @@ -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; @@ -205,7 +197,7 @@ 1: mailingName.toUpperCase() }) }; - return dialogService.open('selectWinnerDialog', partialUrl('selectWinner.html'), model, options); + return dialogService.open('selectWinnerDialog', '~/crmMailingAB/selectWinner.html', model, options); }; }); diff --git a/js/angular-crmMailingAB/directives.js b/js/angular-crmMailingAB/directives.js index ebd388aa6d..17071a55ee 100644 --- a/js/angular-crmMailingAB/directives.js +++ b/js/angular-crmMailingAB/directives.js @@ -1,14 +1,11 @@ (function (angular, $, _) { - var partialUrl = function (relPath) { - return '~/crmMailingAB/' + relPath; - }; // example: // scope.myAbtest = new CrmMailingAB(); // 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); diff --git a/partials/crmCaseType/edit.html b/partials/crmCaseType/edit.html index 0c3c44ac16..d4dd55ff73 100644 --- a/partials/crmCaseType/edit.html +++ b/partials/crmCaseType/edit.html @@ -16,11 +16,11 @@ Required vars: caseType -
+

Roles

-
+

Activities

@@ -46,7 +46,7 @@ Required vars: caseType
-
+
@@ -54,7 +54,7 @@ Required vars: caseType
@@ -69,4 +69,4 @@ Required vars: caseType - \ No newline at end of file + -- 2.25.1