Commit | Line | Data |
---|---|---|
685acae4 | 1 | /// crmUi: Sundry UI helpers |
2 | (function (angular, $, _) { | |
3 | ||
835fcb5e | 4 | var uidCount = 0, |
826f5ace CW |
5 | pageTitle = 'CiviCRM', |
6 | documentTitle = 'CiviCRM'; | |
f8601d61 | 7 | |
685acae4 | 8 | angular.module('crmUi', []) |
030dce01 | 9 | |
0cbed02c | 10 | // example <div crm-ui-accordion crm-title="ts('My Title')" crm-collapsed="true">...content...</div> |
e4f46be0 | 11 | // WISHLIST: crmCollapsed should support two-way/continuous binding |
030dce01 TO |
12 | .directive('crmUiAccordion', function() { |
13 | return { | |
14 | scope: { | |
207819ec | 15 | crmUiAccordion: '=' |
030dce01 | 16 | }, |
207819ec | 17 | template: '<div ng-class="cssClasses"><div class="crm-accordion-header">{{crmUiAccordion.title}} <a crm-ui-help="help" ng-if="help"></a></div><div class="crm-accordion-body" ng-transclude></div></div>', |
030dce01 | 18 | transclude: true, |
0cbed02c TO |
19 | link: function (scope, element, attrs) { |
20 | scope.cssClasses = { | |
207819ec CW |
21 | 'crm-accordion-wrapper': true, |
22 | collapsed: scope.crmUiAccordion.collapsed | |
0cbed02c | 23 | }; |
207819ec CW |
24 | scope.help = null; |
25 | scope.$watch('crmUiAccordion', function(crmUiAccordion) { | |
26 | if (crmUiAccordion && crmUiAccordion.help) { | |
27 | scope.help = crmUiAccordion.help.clone({}, { | |
28 | title: crmUiAccordion.title | |
29 | }); | |
30 | } | |
31 | }); | |
0cbed02c | 32 | } |
030dce01 TO |
33 | }; |
34 | }) | |
35 | ||
69a65adc TO |
36 | // Examples: |
37 | // crmUiAlert({text: 'My text', title: 'My title', type: 'error'}); | |
38 | // crmUiAlert({template: '<a ng-click="ok()">Hello</a>', scope: $scope.$new()}); | |
39 | // var h = crmUiAlert({templateUrl: '~/crmFoo/alert.html', scope: $scope.$new()}); | |
40 | // ... h.close(); ... | |
41 | .service('crmUiAlert', function($compile, $rootScope, $templateRequest, $q) { | |
42 | var count = 0; | |
43 | return function crmUiAlert(params) { | |
44 | var id = 'crmUiAlert_' + (++count); | |
45 | var tpl = null; | |
46 | if (params.templateUrl) { | |
47 | tpl = $templateRequest(params.templateUrl); | |
48 | } | |
49 | else if (params.template) { | |
50 | tpl = params.template; | |
51 | } | |
52 | if (tpl) { | |
53 | params.text = '<div id="' + id + '"></div>'; // temporary stub | |
54 | } | |
55 | var result = CRM.alert(params.text, params.title, params.type, params.options); | |
56 | if (tpl) { | |
57 | $q.when(tpl, function(html) { | |
58 | var scope = params.scope || $rootScope.$new(); | |
59 | var linker = $compile(html); | |
60 | $('#' + id).append($(linker(scope))); | |
61 | }); | |
62 | } | |
63 | return result; | |
64 | }; | |
65 | }) | |
66 | ||
a42344f4 CW |
67 | // Simple wrapper around $.crmDatepicker. |
68 | // example with no time input: <input crm-ui-datepicker="{time: false}" ng-model="myobj.datefield"/> | |
70e7470f | 69 | // example with custom date format: <input crm-ui-datepicker="{date: 'm/d/y'}" ng-model="myobj.datefield"/> |
a42344f4 | 70 | .directive('crmUiDatepicker', function () { |
510d515d TO |
71 | return { |
72 | restrict: 'AE', | |
2f31bc16 | 73 | require: 'ngModel', |
510d515d | 74 | scope: { |
a42344f4 | 75 | crmUiDatepicker: '=' |
510d515d | 76 | }, |
2f31bc16 | 77 | link: function (scope, element, attrs, ngModel) { |
ac5009c1 CW |
78 | ngModel.$render = function () { |
79 | element.val(ngModel.$viewValue).change(); | |
80 | }; | |
81 | ||
a42344f4 CW |
82 | element |
83 | .crmDatepicker(scope.crmUiDatepicker) | |
84 | .on('change', function() { | |
ac5009c1 | 85 | var requiredLength = 19; |
a42344f4 CW |
86 | if (scope.crmUiDatepicker && scope.crmUiDatepicker.time === false) { |
87 | requiredLength = 10; | |
88 | } | |
89 | if (scope.crmUiDatepicker && scope.crmUiDatepicker.date === false) { | |
ac5009c1 | 90 | requiredLength = 8; |
a42344f4 CW |
91 | } |
92 | ngModel.$setValidity('incompleteDateTime', !($(this).val().length && $(this).val().length !== requiredLength)); | |
510d515d | 93 | }); |
510d515d TO |
94 | } |
95 | }; | |
96 | }) | |
97 | ||
c4c69e7b TO |
98 | // Display debug information (if available) |
99 | // For richer DX, checkout Batarang/ng-inspector (Chrome/Safari), or AngScope/ng-inspect (Firefox). | |
100 | // example: <div crm-ui-debug="myobject" /> | |
101 | .directive('crmUiDebug', function ($location) { | |
102 | return { | |
103 | restrict: 'AE', | |
104 | scope: { | |
105 | crmUiDebug: '@' | |
106 | }, | |
107 | template: function() { | |
108 | var args = $location.search(); | |
916f65c0 | 109 | return (args && args.angularDebug) ? '<div crm-ui-accordion=\'{title: ts("Debug (%1)", {1: crmUiDebug}), collapsed: true}\'><pre>{{data|json}}</pre></div>' : ''; |
c4c69e7b TO |
110 | }, |
111 | link: function(scope, element, attrs) { | |
112 | var args = $location.search(); | |
113 | if (args && args.angularDebug) { | |
114 | scope.ts = CRM.ts(null); | |
115 | scope.$parent.$watch(attrs.crmUiDebug, function(data) { | |
116 | scope.data = data; | |
117 | }); | |
118 | } | |
119 | } | |
120 | }; | |
121 | }) | |
122 | ||
489c2674 | 123 | // Display a field/row in a field list |
c4256f35 CW |
124 | // example: <div crm-ui-field="{title: ts('My Field')}"> {{mydata}} </div> |
125 | // example: <div crm-ui-field="{name: 'subform.myfield', title: ts('My Field')}"> <input crm-ui-id="subform.myfield" name="myfield" /> </div> | |
126 | // example: <div crm-ui-field="{name: 'subform.myfield', title: ts('My Field')}"> <input crm-ui-id="subform.myfield" name="myfield" required /> </div> | |
563ba527 | 127 | // example: <div crm-ui-field="{name: 'subform.myfield', title: ts('My Field'), help: hs('help_field_name')}"> {{mydata}} </div> |
3cc9c048 | 128 | .directive('crmUiField', function() { |
489c2674 TO |
129 | // Note: When writing new templates, the "label" position is particular. See/patch "var label" below. |
130 | var templateUrls = { | |
ef5d18a1 TO |
131 | default: '~/crmUi/field.html', |
132 | checkbox: '~/crmUi/field-cb.html' | |
489c2674 TO |
133 | }; |
134 | ||
135 | return { | |
f8601d61 TO |
136 | require: '^crmUiIdScope', |
137 | restrict: 'EA', | |
489c2674 | 138 | scope: { |
d8356d0b | 139 | // {title, name, help, helpFile} |
c4256f35 | 140 | crmUiField: '=' |
489c2674 TO |
141 | }, |
142 | templateUrl: function(tElement, tAttrs){ | |
143 | var layout = tAttrs.crmLayout ? tAttrs.crmLayout : 'default'; | |
144 | return templateUrls[layout]; | |
145 | }, | |
146 | transclude: true, | |
f8601d61 | 147 | link: function (scope, element, attrs, crmUiIdCtrl) { |
489c2674 | 148 | $(element).addClass('crm-section'); |
563ba527 | 149 | scope.help = null; |
dfc2a868 TO |
150 | scope.$watch('crmUiField', function(crmUiField) { |
151 | if (crmUiField && crmUiField.help) { | |
152 | scope.help = crmUiField.help.clone({}, { | |
153 | title: crmUiField.title | |
154 | }); | |
155 | } | |
156 | }); | |
f8601d61 TO |
157 | } |
158 | }; | |
159 | }) | |
160 | ||
161 | // example: <div ng-form="subform" crm-ui-id-scope><label crm-ui-for="subform.foo">Foo:</label><input crm-ui-id="subform.foo" name="foo"/></div> | |
162 | .directive('crmUiId', function () { | |
163 | return { | |
164 | require: '^crmUiIdScope', | |
165 | restrict: 'EA', | |
3cc9c048 TO |
166 | link: { |
167 | pre: function (scope, element, attrs, crmUiIdCtrl) { | |
168 | var id = crmUiIdCtrl.get(attrs.crmUiId); | |
169 | element.attr('id', id); | |
170 | } | |
f8601d61 TO |
171 | } |
172 | }; | |
173 | }) | |
489c2674 | 174 | |
dfc2a868 TO |
175 | // for example, see crmUiHelp |
176 | .service('crmUiHelp', function(){ | |
177 | // example: var h = new FieldHelp({id: 'foo'}); h.open(); | |
178 | function FieldHelp(options) { | |
179 | this.options = options; | |
180 | } | |
181 | angular.extend(FieldHelp.prototype, { | |
182 | get: function(n) { | |
183 | return this.options[n]; | |
184 | }, | |
185 | open: function open() { | |
dfc2a868 TO |
186 | CRM.help(this.options.title, {id: this.options.id, file: this.options.file}); |
187 | }, | |
188 | clone: function clone(options, defaults) { | |
dfc2a868 TO |
189 | return new FieldHelp(angular.extend({}, defaults, this.options, options)); |
190 | } | |
191 | }); | |
192 | ||
563ba527 | 193 | // example: var hs = crmUiHelp({file: 'CRM/Foo/Bar'}); |
dfc2a868 | 194 | return function(defaults){ |
563ba527 TO |
195 | // example: hs('myfield') |
196 | // example: hs({id: 'myfield', title: 'Foo Bar', file: 'Whiz/Bang'}) | |
dfc2a868 TO |
197 | return function(options) { |
198 | if (_.isString(options)) { | |
199 | options = {id: options}; | |
200 | } | |
201 | return new FieldHelp(angular.extend({}, defaults, options)); | |
6dc9d4ca TO |
202 | }; |
203 | }; | |
dfc2a868 TO |
204 | }) |
205 | ||
206 | // Display a help icon | |
9a593827 | 207 | // Example: Use a default *.hlp file |
563ba527 TO |
208 | // scope.hs = crmUiHelp({file: 'Path/To/Help/File'}); |
209 | // HTML: <a crm-ui-help="hs({title:ts('My Field'), id:'my_field'})"> | |
9a593827 | 210 | // Example: Use an explicit *.hlp file |
563ba527 | 211 | // HTML: <a crm-ui-help="hs({title:ts('My Field'), id:'my_field', file:'CRM/Foo/Bar'})"> |
a517b78a CW |
212 | .directive('crmUiHelp', function() { |
213 | return { | |
214 | restrict: 'EA', | |
563ba527 TO |
215 | link: function(scope, element, attrs) { |
216 | setTimeout(function() { | |
217 | var crmUiHelp = scope.$eval(attrs.crmUiHelp); | |
dfc2a868 TO |
218 | var title = crmUiHelp && crmUiHelp.get('title') ? ts('%1 Help', {1: crmUiHelp.get('title')}) : ts('Help'); |
219 | element.attr('title', title); | |
563ba527 | 220 | }, 50); |
dfc2a868 | 221 | |
a517b78a CW |
222 | element |
223 | .addClass('helpicon') | |
a517b78a CW |
224 | .attr('href', '#') |
225 | .on('click', function(e) { | |
226 | e.preventDefault(); | |
563ba527 | 227 | scope.$eval(attrs.crmUiHelp).open(); |
a517b78a CW |
228 | }); |
229 | } | |
230 | }; | |
231 | }) | |
232 | ||
f8601d61 TO |
233 | // example: <div ng-form="subform" crm-ui-id-scope><label crm-ui-for="subform.foo">Foo:</label><input crm-ui-id="subform.foo" name="foo"/></div> |
234 | .directive('crmUiFor', function ($parse, $timeout) { | |
235 | return { | |
236 | require: '^crmUiIdScope', | |
237 | restrict: 'EA', | |
238 | template: '<span ng-class="cssClasses"><span ng-transclude/><span crm-ui-visible="crmIsRequired" class="crm-marker" title="This field is required.">*</span></span>', | |
239 | transclude: true, | |
240 | link: function (scope, element, attrs, crmUiIdCtrl) { | |
241 | scope.crmIsRequired = false; | |
242 | scope.cssClasses = {}; | |
489c2674 | 243 | |
f8601d61 | 244 | if (!attrs.crmUiFor) return; |
489c2674 | 245 | |
f8601d61 TO |
246 | var id = crmUiIdCtrl.get(attrs.crmUiFor); |
247 | element.attr('for', id); | |
248 | var ngModel = null; | |
489c2674 | 249 | |
f8601d61 TO |
250 | var updateCss = function () { |
251 | scope.cssClasses['crm-error'] = !ngModel.$valid && !ngModel.$pristine; | |
252 | }; | |
489c2674 | 253 | |
f8601d61 TO |
254 | // Note: if target element is dynamically generated (eg via ngInclude), then it may not be available |
255 | // immediately for initialization. Use retries/retryDelay to initialize such elements. | |
256 | var init = function (retries, retryDelay) { | |
257 | var input = $('#' + id); | |
4109d03e | 258 | if (input.length === 0) { |
f8601d61 TO |
259 | if (retries) { |
260 | $timeout(function(){ | |
261 | init(retries-1, retryDelay); | |
262 | }, retryDelay); | |
263 | } | |
264 | return; | |
265 | } | |
489c2674 | 266 | |
f8601d61 TO |
267 | var tgtScope = scope;//.$parent; |
268 | if (attrs.crmDepth) { | |
269 | for (var i = attrs.crmDepth; i > 0; i--) { | |
270 | tgtScope = tgtScope.$parent; | |
271 | } | |
272 | } | |
489c2674 | 273 | |
f8601d61 TO |
274 | if (input.attr('ng-required')) { |
275 | scope.crmIsRequired = scope.$parent.$eval(input.attr('ng-required')); | |
276 | scope.$parent.$watch(input.attr('ng-required'), function (isRequired) { | |
277 | scope.crmIsRequired = isRequired; | |
278 | }); | |
279 | } | |
280 | else { | |
f2bad133 | 281 | scope.crmIsRequired = input.prop('required'); |
f8601d61 | 282 | } |
489c2674 | 283 | |
f8601d61 TO |
284 | ngModel = $parse(attrs.crmUiFor)(tgtScope); |
285 | if (ngModel) { | |
286 | ngModel.$viewChangeListeners.push(updateCss); | |
287 | } | |
288 | }; | |
489c2674 | 289 | |
f8601d61 TO |
290 | $timeout(function(){ |
291 | init(3, 100); | |
489c2674 TO |
292 | }); |
293 | } | |
294 | }; | |
295 | }) | |
296 | ||
d376f33e | 297 | // Define a scope in which a name like "subform.foo" maps to a unique ID. |
f8601d61 TO |
298 | // example: <div ng-form="subform" crm-ui-id-scope><label crm-ui-for="subform.foo">Foo:</label><input crm-ui-id="subform.foo" name="foo"/></div> |
299 | .directive('crmUiIdScope', function () { | |
300 | return { | |
301 | restrict: 'EA', | |
302 | scope: {}, | |
303 | controllerAs: 'crmUiIdCtrl', | |
304 | controller: function($scope) { | |
305 | var ids = {}; | |
306 | this.get = function(name) { | |
307 | if (!ids[name]) { | |
308 | ids[name] = "crmUiId_" + (++uidCount); | |
309 | } | |
310 | return ids[name]; | |
f2bad133 | 311 | }; |
f8601d61 TO |
312 | }, |
313 | link: function (scope, element, attrs) {} | |
314 | }; | |
315 | }) | |
316 | ||
d376f33e | 317 | // Display an HTML blurb inside an IFRAME. |
107c5cc7 | 318 | // example: <iframe crm-ui-iframe="getHtmlContent()"></iframe> |
79cf1116 | 319 | // example: <iframe crm-ui-iframe crm-ui-iframe-src="getUrl()"></iframe> |
107c5cc7 TO |
320 | .directive('crmUiIframe', function ($parse) { |
321 | return { | |
322 | scope: { | |
79cf1116 TO |
323 | crmUiIframeSrc: '@', // expression which evaluates to a URL |
324 | crmUiIframe: '@' // expression which evaluates to HTML content | |
107c5cc7 TO |
325 | }, |
326 | link: function (scope, elm, attrs) { | |
327 | var iframe = $(elm)[0]; | |
328 | iframe.setAttribute('width', '100%'); | |
329 | iframe.setAttribute('frameborder', '0'); | |
330 | ||
331 | var refresh = function () { | |
79cf1116 TO |
332 | if (attrs.crmUiIframeSrc) { |
333 | iframe.setAttribute('src', scope.$parent.$eval(attrs.crmUiIframeSrc)); | |
107c5cc7 | 334 | } |
79cf1116 TO |
335 | else { |
336 | var iframeHtml = scope.$parent.$eval(attrs.crmUiIframe); | |
107c5cc7 | 337 | |
79cf1116 TO |
338 | var doc = iframe.document; |
339 | if (iframe.contentDocument) { | |
340 | doc = iframe.contentDocument; | |
341 | } | |
342 | else if (iframe.contentWindow) { | |
343 | doc = iframe.contentWindow.document; | |
344 | } | |
345 | ||
346 | doc.open(); | |
347 | doc.writeln(iframeHtml); | |
348 | doc.close(); | |
349 | } | |
f2bad133 | 350 | }; |
107c5cc7 | 351 | |
02cd9764 CW |
352 | // If the iframe is in a dialog, respond to resize events |
353 | $(elm).parent().on('dialogresize dialogopen', function(e, ui) { | |
354 | $(this).css({padding: '0', margin: '0', overflow: 'hidden'}); | |
355 | iframe.setAttribute('height', '' + $(this).innerHeight() + 'px'); | |
356 | }); | |
357 | ||
107c5cc7 | 358 | scope.$parent.$watch(attrs.crmUiIframe, refresh); |
107c5cc7 TO |
359 | } |
360 | }; | |
361 | }) | |
362 | ||
f8f85764 TO |
363 | // Example: |
364 | // <a ng-click="$broadcast('my-insert-target', 'some new text')>Insert</a> | |
365 | // <textarea crm-ui-insert-rx='my-insert-target'></textarea> | |
f8f85764 TO |
366 | .directive('crmUiInsertRx', function() { |
367 | return { | |
368 | link: function(scope, element, attrs) { | |
369 | scope.$on(attrs.crmUiInsertRx, function(e, tokenName) { | |
c62731c3 TC |
370 | CRM.wysiwyg.insert(element, tokenName); |
371 | $(element).select2('close').select2('val', ''); | |
f91b1c0c | 372 | CRM.wysiwyg.focus(element); |
f8f85764 TO |
373 | }); |
374 | } | |
375 | }; | |
376 | }) | |
377 | ||
d376f33e | 378 | // Define a rich text editor. |
3cc9c048 TO |
379 | // example: <textarea crm-ui-id="myForm.body_html" crm-ui-richtext name="body_html" ng-model="mailing.body_html"></textarea> |
380 | .directive('crmUiRichtext', function ($timeout) { | |
38737af8 TO |
381 | return { |
382 | require: '?ngModel', | |
383 | link: function (scope, elm, attr, ngModel) { | |
65d3e04c | 384 | |
c62731c3 | 385 | var editor = CRM.wysiwyg.create(elm); |
38737af8 TO |
386 | if (!ngModel) { |
387 | return; | |
388 | } | |
389 | ||
07996588 | 390 | if (attr.ngBlur) { |
f91b1c0c CW |
391 | $(elm).on('blur', function() { |
392 | $timeout(function() { | |
07996588 | 393 | scope.$eval(attr.ngBlur); |
d03e0d13 | 394 | }); |
07996588 TO |
395 | }); |
396 | } | |
397 | ||
f91b1c0c | 398 | ngModel.$render = function(value) { |
c63f9bfb | 399 | editor.done(function() { |
495f94fb | 400 | CRM.wysiwyg.setVal(elm, ngModel.$viewValue || ''); |
c63f9bfb | 401 | }); |
38737af8 TO |
402 | }; |
403 | } | |
404 | }; | |
405 | }) | |
406 | ||
d376f33e | 407 | // Display a lock icon (based on a boolean). |
685acae4 | 408 | // example: <a crm-ui-lock binding="mymodel.boolfield"></a> |
409 | // example: <a crm-ui-lock | |
410 | // binding="mymodel.boolfield" | |
411 | // title-locked="ts('Boolfield is locked')" | |
412 | // title-unlocked="ts('Boolfield is unlocked')"></a> | |
413 | .directive('crmUiLock', function ($parse, $rootScope) { | |
414 | var defaultVal = function (defaultValue) { | |
415 | var f = function (scope) { | |
416 | return defaultValue; | |
f2bad133 | 417 | }; |
685acae4 | 418 | f.assign = function (scope, value) { |
419 | // ignore changes | |
f2bad133 | 420 | }; |
685acae4 | 421 | return f; |
422 | }; | |
423 | ||
424 | // like $parse, but accepts a defaultValue in case expr is undefined | |
425 | var parse = function (expr, defaultValue) { | |
426 | return expr ? $parse(expr) : defaultVal(defaultValue); | |
427 | }; | |
428 | ||
429 | return { | |
430 | template: '', | |
431 | link: function (scope, element, attrs) { | |
f2bad133 TO |
432 | var binding = parse(attrs.binding, true); |
433 | var titleLocked = parse(attrs.titleLocked, ts('Locked')); | |
434 | var titleUnlocked = parse(attrs.titleUnlocked, ts('Unlocked')); | |
685acae4 | 435 | |
77ec5a8d | 436 | $(element).addClass('crm-i lock-button'); |
685acae4 | 437 | var refresh = function () { |
438 | var locked = binding(scope); | |
439 | if (locked) { | |
440 | $(element) | |
77ec5a8d AH |
441 | .removeClass('fa-unlock') |
442 | .addClass('fa-lock') | |
685acae4 | 443 | .prop('title', titleLocked(scope)) |
444 | ; | |
445 | } | |
446 | else { | |
447 | $(element) | |
77ec5a8d AH |
448 | .removeClass('fa-lock') |
449 | .addClass('fa-unlock') | |
685acae4 | 450 | .prop('title', titleUnlocked(scope)) |
451 | ; | |
452 | } | |
453 | }; | |
454 | ||
455 | $(element).click(function () { | |
456 | binding.assign(scope, !binding(scope)); | |
457 | //scope.$digest(); | |
458 | $rootScope.$digest(); | |
459 | }); | |
460 | ||
461 | scope.$watch(attrs.binding, refresh); | |
462 | scope.$watch(attrs.titleLocked, refresh); | |
463 | scope.$watch(attrs.titleUnlocked, refresh); | |
464 | ||
465 | refresh(); | |
466 | } | |
467 | }; | |
468 | }) | |
030dce01 | 469 | |
b21c9cdc TO |
470 | // CrmUiOrderCtrl is a controller class which manages sort orderings. |
471 | // Ex: | |
472 | // JS: $scope.myOrder = new CrmUiOrderCtrl(['+field1', '-field2]); | |
473 | // $scope.myOrder.toggle('field1'); | |
474 | // $scope.myOrder.setDir('field2', ''); | |
475 | // HTML: <tr ng-repeat="... | order:myOrder.get()">...</tr> | |
476 | .service('CrmUiOrderCtrl', function(){ | |
477 | // | |
478 | function CrmUiOrderCtrl(defaults){ | |
479 | this.values = defaults; | |
480 | } | |
481 | angular.extend(CrmUiOrderCtrl.prototype, { | |
482 | get: function get() { | |
483 | return this.values; | |
484 | }, | |
485 | getDir: function getDir(name) { | |
486 | if (this.values.indexOf(name) >= 0 || this.values.indexOf('+' + name) >= 0) { | |
487 | return '+'; | |
488 | } | |
489 | if (this.values.indexOf('-' + name) >= 0) { | |
490 | return '-'; | |
491 | } | |
492 | return ''; | |
493 | }, | |
494 | // @return bool TRUE if something is removed | |
495 | remove: function remove(name) { | |
496 | var idx = this.values.indexOf(name); | |
497 | if (idx >= 0) { | |
498 | this.values.splice(idx, 1); | |
499 | return true; | |
500 | } | |
501 | else { | |
502 | return false; | |
503 | } | |
504 | }, | |
505 | setDir: function setDir(name, dir) { | |
506 | return this.toggle(name, dir); | |
507 | }, | |
508 | // Toggle sort order on a field. | |
509 | // To set a specific order, pass optional parameter 'next' ('+', '-', or ''). | |
510 | toggle: function toggle(name, next) { | |
511 | if (!next && next !== '') { | |
512 | next = '+'; | |
513 | if (this.remove(name) || this.remove('+' + name)) { | |
514 | next = '-'; | |
515 | } | |
516 | if (this.remove('-' + name)) { | |
517 | next = ''; | |
518 | } | |
519 | } | |
520 | ||
521 | if (next == '+') { | |
522 | this.values.unshift('+' + name); | |
523 | } | |
524 | else if (next == '-') { | |
525 | this.values.unshift('-' + name); | |
526 | } | |
527 | } | |
528 | }); | |
529 | return CrmUiOrderCtrl; | |
530 | }) | |
531 | ||
532 | // Define a controller which manages sort order. You may interact with the controller | |
533 | // directly ("myOrder.toggle('fieldname')") order using the helper, crm-ui-order-by. | |
534 | // example: | |
535 | // <span crm-ui-order="{var: 'myOrder', defaults: {'-myField'}}"></span> | |
536 | // <th><a crm-ui-order-by="[myOrder,'myField']">My Field</a></th> | |
537 | // <tr ng-repeat="... | order:myOrder.get()">...</tr> | |
538 | // <button ng-click="myOrder.toggle('myField')"> | |
539 | .directive('crmUiOrder', function(CrmUiOrderCtrl) { | |
540 | return { | |
541 | link: function(scope, element, attrs){ | |
542 | var options = angular.extend({var: 'crmUiOrderBy'}, scope.$eval(attrs.crmUiOrder)); | |
543 | scope[options.var] = new CrmUiOrderCtrl(options.defaults); | |
544 | } | |
545 | }; | |
546 | }) | |
547 | ||
548 | // For usage, see crmUiOrder (above) | |
549 | .directive('crmUiOrderBy', function() { | |
550 | return { | |
551 | link: function(scope, element, attrs) { | |
552 | function updateClass(crmUiOrderCtrl, name) { | |
553 | var dir = crmUiOrderCtrl.getDir(name); | |
554 | element | |
555 | .toggleClass('sorting_asc', dir === '+') | |
556 | .toggleClass('sorting_desc', dir === '-') | |
557 | .toggleClass('sorting', dir === ''); | |
558 | } | |
559 | ||
560 | element.on('click', function(e){ | |
561 | var tgt = scope.$eval(attrs.crmUiOrderBy); | |
562 | tgt[0].toggle(tgt[1]); | |
563 | updateClass(tgt[0], tgt[1]); | |
564 | e.preventDefault(); | |
565 | scope.$digest(); | |
566 | }); | |
567 | ||
568 | var tgt = scope.$eval(attrs.crmUiOrderBy); | |
569 | updateClass(tgt[0], tgt[1]); | |
570 | } | |
571 | }; | |
572 | }) | |
573 | ||
d376f33e | 574 | // Display a fancy SELECT (based on select2). |
ebfe3efb TO |
575 | // usage: <select crm-ui-select="{placeholder:'Something',allowClear:true,...}" ng-model="myobj.field"><option...></select> |
576 | .directive('crmUiSelect', function ($parse, $timeout) { | |
8c632f2b | 577 | return { |
ebfe3efb | 578 | require: '?ngModel', |
8c632f2b | 579 | scope: { |
8674b5ac | 580 | crmUiSelect: '=' |
8c632f2b | 581 | }, |
ebfe3efb | 582 | link: function (scope, element, attrs, ngModel) { |
8c632f2b TO |
583 | // In cases where UI initiates update, there may be an extra |
584 | // call to refreshUI, but it doesn't create a cycle. | |
585 | ||
c81696a6 CW |
586 | if (ngModel) { |
587 | ngModel.$render = function () { | |
588 | $timeout(function () { | |
589 | // ex: msg_template_id adds new item then selects it; use $timeout to ensure that | |
590 | // new item is added before selection is made | |
54a42669 | 591 | element.select2('val', ngModel.$modelValue); |
c81696a6 CW |
592 | }); |
593 | }; | |
594 | } | |
8c632f2b | 595 | function refreshModel() { |
50e25421 | 596 | var oldValue = ngModel.$viewValue, newValue = element.select2('val'); |
8c632f2b | 597 | if (oldValue != newValue) { |
ebfe3efb TO |
598 | scope.$parent.$apply(function () { |
599 | ngModel.$setViewValue(newValue); | |
8c632f2b | 600 | }); |
8c632f2b TO |
601 | } |
602 | } | |
ebfe3efb | 603 | |
8c632f2b TO |
604 | function init() { |
605 | // TODO watch select2-options | |
8c3a97ed | 606 | element.crmSelect2(scope.crmUiSelect || {}); |
c81696a6 CW |
607 | if (ngModel) { |
608 | element.on('change', refreshModel); | |
609 | $timeout(ngModel.$render); | |
610 | } | |
8099bfee CW |
611 | } |
612 | ||
613 | init(); | |
614 | } | |
615 | }; | |
616 | }) | |
617 | ||
618 | // Render a crmEntityRef widget | |
619 | // usage: <input crm-entityref="{entity: 'Contact', select: {allowClear:true}}" ng-model="myobj.field" /> | |
620 | .directive('crmEntityref', function ($parse, $timeout) { | |
621 | return { | |
622 | require: '?ngModel', | |
623 | scope: { | |
624 | crmEntityref: '=' | |
625 | }, | |
626 | link: function (scope, element, attrs, ngModel) { | |
627 | // In cases where UI initiates update, there may be an extra | |
628 | // call to refreshUI, but it doesn't create a cycle. | |
629 | ||
630 | ngModel.$render = function () { | |
631 | $timeout(function () { | |
632 | // ex: msg_template_id adds new item then selects it; use $timeout to ensure that | |
633 | // new item is added before selection is made | |
54a42669 | 634 | element.select2('val', ngModel.$modelValue); |
8099bfee CW |
635 | }); |
636 | }; | |
637 | function refreshModel() { | |
638 | var oldValue = ngModel.$viewValue, newValue = element.select2('val'); | |
639 | if (oldValue != newValue) { | |
640 | scope.$parent.$apply(function () { | |
641 | ngModel.$setViewValue(newValue); | |
642 | }); | |
643 | } | |
644 | } | |
645 | ||
646 | function init() { | |
8099bfee CW |
647 | // TODO can we infer "entity" from model? |
648 | element.crmEntityRef(scope.crmEntityref || {}); | |
649 | element.on('change', refreshModel); | |
650 | $timeout(ngModel.$render); | |
8c632f2b | 651 | } |
ebfe3efb | 652 | |
8c632f2b TO |
653 | init(); |
654 | } | |
655 | }; | |
656 | }) | |
657 | ||
b1f92f72 | 658 | // example <div crm-ui-tab id="tab-1" crm-title="ts('My Title')" count="3">...content...</div> |
5f3568fd | 659 | // WISHLIST: use a full Angular component instead of an incomplete jQuery wrapper |
030dce01 TO |
660 | .directive('crmUiTab', function($parse) { |
661 | return { | |
5f3568fd TO |
662 | require: '^crmUiTabSet', |
663 | restrict: 'EA', | |
030dce01 | 664 | scope: { |
5f3568fd | 665 | crmTitle: '@', |
cf500087 | 666 | crmIcon: '@', |
b1f92f72 | 667 | count: '@', |
5f3568fd | 668 | id: '@' |
030dce01 | 669 | }, |
5f3568fd | 670 | template: '<div ng-transclude></div>', |
030dce01 | 671 | transclude: true, |
5f3568fd TO |
672 | link: function (scope, element, attrs, crmUiTabSetCtrl) { |
673 | crmUiTabSetCtrl.add(scope); | |
674 | } | |
030dce01 TO |
675 | }; |
676 | }) | |
677 | ||
678 | // example: <div crm-ui-tab-set><div crm-ui-tab crm-title="Tab 1">...</div><div crm-ui-tab crm-title="Tab 2">...</div></div> | |
679 | .directive('crmUiTabSet', function() { | |
680 | return { | |
5f3568fd TO |
681 | restrict: 'EA', |
682 | scope: { | |
683 | crmUiTabSet: '@' | |
684 | }, | |
ef5d18a1 | 685 | templateUrl: '~/crmUi/tabset.html', |
030dce01 | 686 | transclude: true, |
5f3568fd TO |
687 | controllerAs: 'crmUiTabSetCtrl', |
688 | controller: function($scope, $parse) { | |
689 | var tabs = $scope.tabs = []; // array<$scope> | |
690 | this.add = function(tab) { | |
691 | if (!tab.id) throw "Tab is missing 'id'"; | |
692 | tabs.push(tab); | |
693 | }; | |
694 | }, | |
030dce01 TO |
695 | link: function (scope, element, attrs) {} |
696 | }; | |
697 | }) | |
698 | ||
d376f33e | 699 | // Generic, field-independent form validator. |
3afb86ef TO |
700 | // example: <span ng-model="placeholder" crm-ui-validate="foo && bar || whiz" /> |
701 | // example: <span ng-model="placeholder" crm-ui-validate="foo && bar || whiz" crm-ui-validate-name="myError" /> | |
3afb86ef TO |
702 | .directive('crmUiValidate', function() { |
703 | return { | |
704 | restrict: 'EA', | |
705 | require: 'ngModel', | |
706 | link: function(scope, element, attrs, ngModel) { | |
707 | var validationKey = attrs.crmUiValidateName ? attrs.crmUiValidateName : 'crmUiValidate'; | |
708 | scope.$watch(attrs.crmUiValidate, function(newValue){ | |
709 | ngModel.$setValidity(validationKey, !!newValue); | |
710 | }); | |
711 | } | |
712 | }; | |
713 | }) | |
714 | ||
e84a11d8 TO |
715 | // like ng-show, but hides/displays elements using "visibility" which maintains positioning |
716 | // example <div crm-ui-visible="false">...content...</div> | |
717 | .directive('crmUiVisible', function($parse) { | |
718 | return { | |
719 | restrict: 'EA', | |
720 | scope: { | |
721 | crmUiVisible: '@' | |
722 | }, | |
723 | link: function (scope, element, attrs) { | |
724 | var model = $parse(attrs.crmUiVisible); | |
725 | function updatecChildren() { | |
726 | element.css('visibility', model(scope.$parent) ? 'inherit' : 'hidden'); | |
727 | } | |
728 | updatecChildren(); | |
729 | scope.$parent.$watch(attrs.crmUiVisible, updatecChildren); | |
730 | } | |
731 | }; | |
732 | }) | |
733 | ||
6717e4b9 TO |
734 | // example: <div crm-ui-wizard="myWizardCtrl"><div crm-ui-wizard-step crm-title="ts('Step 1')">...</div><div crm-ui-wizard-step crm-title="ts('Step 2')">...</div></div> |
735 | // Note: "myWizardCtrl" has various actions/properties like next() and $first(). | |
736 | // WISHLIST: Allow each step to determine if it is "complete" / "valid" / "selectable" | |
737 | // WISHLIST: Allow each step to enable/disable (show/hide) itself | |
030dce01 TO |
738 | .directive('crmUiWizard', function() { |
739 | return { | |
6717e4b9 TO |
740 | restrict: 'EA', |
741 | scope: { | |
742 | crmUiWizard: '@' | |
743 | }, | |
ef5d18a1 | 744 | templateUrl: '~/crmUi/wizard.html', |
030dce01 | 745 | transclude: true, |
6717e4b9 TO |
746 | controllerAs: 'crmUiWizardCtrl', |
747 | controller: function($scope, $parse) { | |
748 | var steps = $scope.steps = []; // array<$scope> | |
749 | var crmUiWizardCtrl = this; | |
750 | var maxVisited = 0; | |
751 | var selectedIndex = null; | |
752 | ||
753 | var findIndex = function() { | |
754 | var found = null; | |
755 | angular.forEach(steps, function(step, stepKey) { | |
756 | if (step.selected) found = stepKey; | |
757 | }); | |
758 | return found; | |
759 | }; | |
760 | ||
761 | /// @return int the index of the current step | |
762 | this.$index = function() { return selectedIndex; }; | |
763 | /// @return bool whether the currentstep is first | |
764 | this.$first = function() { return this.$index() === 0; }; | |
765 | /// @return bool whether the current step is last | |
766 | this.$last = function() { return this.$index() === steps.length -1; }; | |
f2bad133 | 767 | this.$maxVisit = function() { return maxVisited; }; |
3f0da451 | 768 | this.$validStep = function() { |
f8c05c87 | 769 | return steps[selectedIndex] && steps[selectedIndex].isStepValid(); |
3f0da451 | 770 | }; |
6717e4b9 TO |
771 | this.iconFor = function(index) { |
772 | if (index < this.$index()) return '√'; | |
773 | if (index === this.$index()) return '»'; | |
774 | return ' '; | |
f2bad133 | 775 | }; |
6717e4b9 TO |
776 | this.isSelectable = function(step) { |
777 | if (step.selected) return false; | |
778 | var result = false; | |
779 | angular.forEach(steps, function(otherStep, otherKey) { | |
780 | if (step === otherStep && otherKey <= maxVisited) result = true; | |
781 | }); | |
782 | return result; | |
783 | }; | |
784 | ||
785 | /*** @param Object step the $scope of the step */ | |
786 | this.select = function(step) { | |
787 | angular.forEach(steps, function(otherStep, otherKey) { | |
788 | otherStep.selected = (otherStep === step); | |
789 | if (otherStep === step && maxVisited < otherKey) maxVisited = otherKey; | |
790 | }); | |
791 | selectedIndex = findIndex(); | |
792 | }; | |
793 | /*** @param Object step the $scope of the step */ | |
794 | this.add = function(step) { | |
795 | if (steps.length === 0) { | |
796 | step.selected = true; | |
797 | selectedIndex = 0; | |
798 | } | |
799 | steps.push(step); | |
8688b463 TO |
800 | steps.sort(function(a,b){ |
801 | return a.crmUiWizardStep - b.crmUiWizardStep; | |
802 | }); | |
803 | selectedIndex = findIndex(); | |
804 | }; | |
805 | this.remove = function(step) { | |
806 | var key = null; | |
807 | angular.forEach(steps, function(otherStep, otherKey) { | |
808 | if (otherStep === step) key = otherKey; | |
809 | }); | |
4109d03e | 810 | if (key !== null) { |
8688b463 TO |
811 | steps.splice(key, 1); |
812 | } | |
6717e4b9 TO |
813 | }; |
814 | this.goto = function(index) { | |
815 | if (index < 0) index = 0; | |
816 | if (index >= steps.length) index = steps.length-1; | |
817 | this.select(steps[index]); | |
818 | }; | |
819 | this.previous = function() { this.goto(this.$index()-1); }; | |
820 | this.next = function() { this.goto(this.$index()+1); }; | |
821 | if ($scope.crmUiWizard) { | |
f2bad133 | 822 | $parse($scope.crmUiWizard).assign($scope.$parent, this); |
6717e4b9 TO |
823 | } |
824 | }, | |
c4991710 TO |
825 | link: function (scope, element, attrs) { |
826 | scope.ts = CRM.ts(null); | |
827 | } | |
030dce01 TO |
828 | }; |
829 | }) | |
830 | ||
6717e4b9 TO |
831 | // Use this to add extra markup to wizard |
832 | .directive('crmUiWizardButtons', function() { | |
030dce01 | 833 | return { |
6717e4b9 TO |
834 | require: '^crmUiWizard', |
835 | restrict: 'EA', | |
836 | scope: {}, | |
837 | template: '<span ng-transclude></span>', | |
030dce01 | 838 | transclude: true, |
6717e4b9 TO |
839 | link: function (scope, element, attrs, crmUiWizardCtrl) { |
840 | var realButtonsEl = $(element).closest('.crm-wizard').find('.crm-wizard-buttons'); | |
841 | $(element).appendTo(realButtonsEl); | |
842 | } | |
030dce01 TO |
843 | }; |
844 | }) | |
845 | ||
77ec5a8d AH |
846 | // Example for Font Awesome: <button crm-icon="fa-check">Save</button> |
847 | // Example for jQuery UI (deprecated): <button crm-icon="check">Save</button> | |
39f4f54f CW |
848 | .directive('crmIcon', function() { |
849 | return { | |
850 | restrict: 'EA', | |
39f4f54f | 851 | link: function (scope, element, attrs) { |
cf500087 CW |
852 | if (element.is('[crm-ui-tab]')) { |
853 | // handled in crmUiTab ctrl | |
854 | return; | |
855 | } | |
aee84611 AH |
856 | if (attrs.crmIcon.substring(0,3) == 'fa-') { |
857 | $(element).prepend('<i class="crm-i ' + attrs.crmIcon + '"></i> '); | |
858 | } | |
859 | else { | |
860 | $(element).prepend('<span class="icon ui-icon-' + attrs.crmIcon + '"></span> '); | |
861 | } | |
39f4f54f CW |
862 | if ($(element).is('button')) { |
863 | $(element).addClass('crm-button'); | |
864 | } | |
865 | } | |
866 | }; | |
867 | }) | |
868 | ||
3f0da451 | 869 | // example: <div crm-ui-wizard-step crm-title="ts('My Title')" ng-form="mySubForm">...content...</div> |
8688b463 TO |
870 | // If there are any conditional steps, then be sure to set a weight explicitly on *all* steps to maintain ordering. |
871 | // example: <div crm-ui-wizard-step="100" crm-title="..." ng-if="...">...content...</div> | |
030dce01 | 872 | .directive('crmUiWizardStep', function() { |
8688b463 | 873 | var nextWeight = 1; |
030dce01 | 874 | return { |
3f0da451 | 875 | require: ['^crmUiWizard', 'form'], |
6717e4b9 | 876 | restrict: 'EA', |
030dce01 | 877 | scope: { |
8688b463 TO |
878 | crmTitle: '@', // expression, evaluates to a printable string |
879 | crmUiWizardStep: '@' // int, a weight which determines the ordering of the steps | |
030dce01 | 880 | }, |
6717e4b9 | 881 | template: '<div class="crm-wizard-step" ng-show="selected" ng-transclude/></div>', |
030dce01 | 882 | transclude: true, |
3f0da451 TO |
883 | link: function (scope, element, attrs, ctrls) { |
884 | var crmUiWizardCtrl = ctrls[0], form = ctrls[1]; | |
8688b463 TO |
885 | if (scope.crmUiWizardStep) { |
886 | scope.crmUiWizardStep = parseInt(scope.crmUiWizardStep); | |
887 | } else { | |
888 | scope.crmUiWizardStep = nextWeight++; | |
889 | } | |
3f0da451 TO |
890 | scope.isStepValid = function() { |
891 | return form.$valid; | |
892 | }; | |
6717e4b9 | 893 | crmUiWizardCtrl.add(scope); |
8688b463 TO |
894 | element.on('$destroy', function(){ |
895 | crmUiWizardCtrl.remove(scope); | |
896 | }); | |
6717e4b9 | 897 | } |
030dce01 TO |
898 | }; |
899 | }) | |
900 | ||
5fb5b3cf | 901 | // Example: <button crm-confirm="{message: ts('Are you sure you want to continue?')}" on-yes="frobnicate(123)">Frobincate</button> |
4b8c8b42 | 902 | // Example: <button crm-confirm="{type: 'disable', obj: myObject}" on-yes="myObject.is_active=0; myObject.save()">Disable</button> |
6a6d0f41 TO |
903 | // Example: <button crm-confirm="{templateUrl: '~/path/to/view.html', export: {foo: bar}}" on-yes="frobnicate(123)">Frobincate</button> |
904 | .directive('crmConfirm', function ($compile, $rootScope, $templateRequest, $q) { | |
88fcc9f1 | 905 | // Helpers to calculate default options for CRM.confirm() |
4b8c8b42 TO |
906 | var defaultFuncs = { |
907 | 'disable': function (options) { | |
908 | return { | |
909 | message: ts('Are you sure you want to disable this?'), | |
910 | options: {no: ts('Cancel'), yes: ts('Disable')}, | |
911 | width: 300, | |
912 | title: ts('Disable %1?', { | |
913 | 1: options.obj.title || options.obj.label || options.obj.name || ts('the record') | |
914 | }) | |
915 | }; | |
916 | }, | |
470a458e TO |
917 | 'revert': function (options) { |
918 | return { | |
919 | message: ts('Are you sure you want to revert this?'), | |
920 | options: {no: ts('Cancel'), yes: ts('Revert')}, | |
921 | width: 300, | |
922 | title: ts('Revert %1?', { | |
923 | 1: options.obj.title || options.obj.label || options.obj.name || ts('the record') | |
924 | }) | |
925 | }; | |
926 | }, | |
4b8c8b42 TO |
927 | 'delete': function (options) { |
928 | return { | |
929 | message: ts('Are you sure you want to delete this?'), | |
930 | options: {no: ts('Cancel'), yes: ts('Delete')}, | |
931 | width: 300, | |
932 | title: ts('Delete %1?', { | |
933 | 1: options.obj.title || options.obj.label || options.obj.name || ts('the record') | |
934 | }) | |
935 | }; | |
936 | } | |
937 | }; | |
6a6d0f41 | 938 | var confirmCount = 0; |
4b8c8b42 | 939 | return { |
4b8c8b42 TO |
940 | link: function (scope, element, attrs) { |
941 | $(element).click(function () { | |
f2bad133 | 942 | var options = scope.$eval(attrs.crmConfirm); |
b8603a6d CW |
943 | if (attrs.title && !options.title) { |
944 | options.title = attrs.title; | |
945 | } | |
4b8c8b42 | 946 | var defaults = (options.type) ? defaultFuncs[options.type](options) : {}; |
6a6d0f41 TO |
947 | |
948 | var tpl = null, stubId = null; | |
949 | if (!options.message) { | |
950 | if (options.templateUrl) { | |
951 | tpl = $templateRequest(options.templateUrl); | |
952 | } | |
953 | else if (options.template) { | |
954 | tpl = options.template; | |
955 | } | |
956 | if (tpl) { | |
957 | stubId = 'crmUiConfirm_' + (++confirmCount); | |
958 | options.message = '<div id="' + stubId + '"></div>'; | |
959 | } | |
960 | } | |
961 | ||
4b8c8b42 | 962 | CRM.confirm(_.extend(defaults, options)) |
6a6d0f41 TO |
963 | .on('crmConfirm:yes', function() { scope.$apply(attrs.onYes); }) |
964 | .on('crmConfirm:no', function() { scope.$apply(attrs.onNo); }); | |
965 | ||
966 | if (tpl && stubId) { | |
967 | $q.when(tpl, function(html) { | |
968 | var scope = options.scope || $rootScope.$new(); | |
969 | if (options.export) { | |
970 | angular.extend(scope, options.export); | |
971 | } | |
972 | var linker = $compile(html); | |
973 | $('#' + stubId).append($(linker(scope))); | |
974 | }); | |
975 | } | |
4b8c8b42 TO |
976 | }); |
977 | } | |
978 | }; | |
979 | }) | |
835fcb5e | 980 | |
826f5ace | 981 | // Sets document title & page title; attempts to override CMS title markup for the latter |
835fcb5e | 982 | // WARNING: Use only once per route! |
826f5ace CW |
983 | // Example (same title for both): <h1 crm-page-title>{{ts('Hello')}}</h1> |
984 | // Example (separate document title): <h1 crm-document-title="ts('Hello')" crm-page-title><i class="crm-i fa-flag"></i>{{ts('Hello')}}</h1> | |
985 | .directive('crmPageTitle', function($timeout) { | |
835fcb5e | 986 | return { |
826f5ace CW |
987 | scope: { |
988 | crmDocumentTitle: '=' | |
989 | }, | |
835fcb5e CW |
990 | link: function(scope, $el, attrs) { |
991 | function update() { | |
992 | $timeout(function() { | |
826f5ace CW |
993 | var newPageTitle = _.trim($el.html()), |
994 | newDocumentTitle = scope.crmDocumentTitle || $el.text(); | |
995 | document.title = $('title').text().replace(documentTitle, newDocumentTitle); | |
835fcb5e CW |
996 | // If the CMS has already added title markup to the page, use it |
997 | $('h1').not('.crm-container h1').each(function() { | |
826f5ace CW |
998 | if (_.trim($(this).html()) === pageTitle) { |
999 | $(this).html(newPageTitle); | |
835fcb5e CW |
1000 | $el.hide(); |
1001 | } | |
1002 | }); | |
826f5ace CW |
1003 | pageTitle = newPageTitle; |
1004 | documentTitle = newDocumentTitle; | |
835fcb5e CW |
1005 | }); |
1006 | } | |
1007 | ||
826f5ace | 1008 | scope.$watch(function() {return scope.crmDocumentTitle + $el.html();}, update); |
835fcb5e | 1009 | } |
7565f24a | 1010 | }; |
835fcb5e CW |
1011 | }) |
1012 | ||
02308c07 TO |
1013 | .run(function($rootScope, $location) { |
1014 | /// Example: <button ng-click="goto('home')">Go home!</button> | |
1015 | $rootScope.goto = function(path) { | |
1016 | $location.path(path); | |
1017 | }; | |
4b8c8b42 | 1018 | // useful for debugging: $rootScope.log = console.log || function() {}; |
02308c07 | 1019 | }) |
685acae4 | 1020 | ; |
1021 | ||
5fb5b3cf | 1022 | })(angular, CRM.$, CRM._); |