/// crmUi: Sundry UI helpers
(function (angular, $, _) {
- var uidCount = 0;
+ var uidCount = 0,
+ pageTitle = 'CiviCRM',
+ documentTitle = 'CiviCRM';
angular.module('crmUi', [])
requiredLength = 8;
}
ngModel.$setValidity('incompleteDateTime', !($(this).val().length && $(this).val().length !== requiredLength));
- var d = new Date(),
- month = '' + (d.getMonth() + 1),
- day = '' + d.getDate(),
- year = d.getFullYear();
- if (month.length < 2) month = '0' + month;
- if (day.length < 2) day = '0' + day;
- currentDate = [year, month, day].join('-');
- ngModel.$setValidity('dateTimeInThePast', !($(this).val().length && $(this).val() < currentDate));
- if ($(this).val().length && $(this).val() < currentDate){
- crmUiAlert({
- text: ts('The Scheulded date and time is in the past'),
- title: ts('Error')
- });
- }
});
}
};
}
ngModel.$render = function(value) {
- CRM.wysiwyg.setVal(elm, ngModel.$viewValue);
+ editor.done(function() {
+ CRM.wysiwyg.setVal(elm, ngModel.$viewValue || '');
+ });
};
}
};
function init() {
// TODO watch select2-options
- element.select2(scope.crmUiSelect || {});
+ element.crmSelect2(scope.crmUiSelect || {});
if (ngModel) {
element.on('change', refreshModel);
$timeout(ngModel.$render);
};
})
- // example <div crm-ui-tab crm-title="ts('My Title')">...content...</div>
+ // example <div crm-ui-tab id="tab-1" crm-title="ts('My Title')" count="3">...content...</div>
// WISHLIST: use a full Angular component instead of an incomplete jQuery wrapper
.directive('crmUiTab', function($parse) {
return {
restrict: 'EA',
scope: {
crmTitle: '@',
+ crmIcon: '@',
+ count: '@',
id: '@'
},
template: '<div ng-transclude></div>',
.directive('crmIcon', function() {
return {
restrict: 'EA',
- scope: {},
link: function (scope, element, attrs) {
+ if (element.is('[crm-ui-tab]')) {
+ // handled in crmUiTab ctrl
+ return;
+ }
if (attrs.crmIcon.substring(0,3) == 'fa-') {
$(element).prepend('<i class="crm-i ' + attrs.crmIcon + '"></i> ');
}
}
};
})
+
+ // Sets document title & page title; attempts to override CMS title markup for the latter
+ // WARNING: Use only once per route!
+ // Example (same title for both): <h1 crm-page-title>{{ts('Hello')}}</h1>
+ // Example (separate document title): <h1 crm-document-title="ts('Hello')" crm-page-title><i class="crm-i fa-flag"></i>{{ts('Hello')}}</h1>
+ .directive('crmPageTitle', function($timeout) {
+ return {
+ scope: {
+ crmDocumentTitle: '='
+ },
+ link: function(scope, $el, attrs) {
+ function update() {
+ $timeout(function() {
+ var newPageTitle = _.trim($el.html()),
+ newDocumentTitle = scope.crmDocumentTitle || $el.text();
+ document.title = $('title').text().replace(documentTitle, newDocumentTitle);
+ // If the CMS has already added title markup to the page, use it
+ $('h1').not('.crm-container h1').each(function() {
+ if (_.trim($(this).html()) === pageTitle) {
+ $(this).html(newPageTitle);
+ $el.hide();
+ }
+ });
+ pageTitle = newPageTitle;
+ documentTitle = newDocumentTitle;
+ });
+ }
+
+ scope.$watch(function() {return scope.crmDocumentTitle + $el.html();}, update);
+ }
+ };
+ })
+
.run(function($rootScope, $location) {
/// Example: <button ng-click="goto('home')">Go home!</button>
$rootScope.goto = function(path) {