},
template: function() {
var args = $location.search();
- return (args && args.angularDebug) ? '<div crm-ui-accordion=\'{title: ts("Debug (%1)", {1: crmUiDebug}), collapsed: true}\'><pre>{{data|json}}</pre></div>' : '';
+ if (args && args.angularDebug) {
+ var jsonTpl = (CRM.angular.modules.indexOf('jsonFormatter') < 0) ? '<pre>{{data|json}}</pre>' : '<json-formatter json="data" open="1"></json-formatter>';
+ return '<div crm-ui-accordion=\'{title: ts("Debug (%1)", {1: crmUiDebug}), collapsed: true}\'>' + jsonTpl + '</div>';
+ }
+ return '';
},
link: function(scope, element, attrs) {
var args = $location.search();
};
})
+ // Use a select2 widget as a pick-list. Instead of updating ngModel, the select2 widget will fire an event.
+ // This similar to ngModel+ngChange, except that value is never stored in a model. It is only fired in the event.
+ // usage: <select crm-ui-select='{...}' on-crm-ui-select="alert("User picked this item: " + selection)"></select>
+ .directive('onCrmUiSelect', function () {
+ return {
+ priority: 10,
+ link: function (scope, element, attrs) {
+ element.on('select2-selecting', function(e) {
+ e.preventDefault();
+ element.select2('close').select2('val', '');
+ scope.$apply(function() {
+ scope.$eval(attrs.onCrmUiSelect, {selection: e.val});
+ });
+ });
+ }
+ };
+ })
+
// Render a crmEntityRef widget
// usage: <input crm-entityref="{entity: 'Contact', select: {allowClear:true}}" ng-model="myobj.field" />
.directive('crmEntityref', function ($parse, $timeout) {
})
// Example for Font Awesome: <button crm-icon="fa-check">Save</button>
- // Example for jQuery UI (deprecated): <button crm-icon="check">Save</button>
+ // Example for jQuery UI (deprecated): <button crm-icon="fa-check">Save</button>
.directive('crmIcon', function() {
return {
restrict: 'EA',
else {
$(element).prepend('<span class="icon ui-icon-' + attrs.crmIcon + '"></span> ');
}
- if ($(element).is('button')) {
+ // Add crm-* class to non-bootstrap buttons
+ if ($(element).is('button:not(.btn)')) {
$(element).addClass('crm-button');
}
}
function update() {
$timeout(function() {
var newPageTitle = _.trim($el.html()),
- newDocumentTitle = scope.crmDocumentTitle || $el.text();
+ newDocumentTitle = scope.crmDocumentTitle || $el.text(),
+ h1Count = 0;
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) {
+ if ($(this).hasClass('crm-page-title') || _.trim($(this).html()) === pageTitle) {
$(this).addClass('crm-page-title').html(newPageTitle);
$el.hide();
+ ++h1Count;
}
});
+ if (!h1Count) {
+ $el.show();
+ }
pageTitle = newPageTitle;
documentTitle = newDocumentTitle;
});
};
})
+ // Editable text using ngModel & html5 contenteditable
+ // Usage: <span crm-ui-editable ng-model="my.data">{{ my.data }}</span>
+ .directive("crmUiEditable", function() {
+ return {
+ restrict: "A",
+ require: "ngModel",
+ scope: {
+ defaultValue: '='
+ },
+ link: function(scope, element, attrs, ngModel) {
+ var ts = CRM.ts();
+
+ function read() {
+ var htmlVal = element.html();
+ if (!htmlVal) {
+ htmlVal = scope.defaultValue || '';
+ element.text(htmlVal);
+ }
+ ngModel.$setViewValue(htmlVal);
+ }
+
+ ngModel.$render = function() {
+ element.text(ngModel.$viewValue || scope.defaultValue || '');
+ };
+
+ // Special handling for enter and escape keys
+ element.on('keydown', function(e) {
+ // Enter: prevent line break and save
+ if (e.which === 13) {
+ e.preventDefault();
+ element.blur();
+ }
+ // Escape: undo
+ if (e.which === 27) {
+ element.text(ngModel.$viewValue || scope.defaultValue || '');
+ element.blur();
+ }
+ });
+
+ element.on("blur change", function() {
+ scope.$apply(read);
+ });
+
+ element.attr('contenteditable', 'true').addClass('crm-editable-enabled');
+ }
+ };
+ })
+
.run(function($rootScope, $location) {
/// Example: <button ng-click="goto('home')">Go home!</button>
$rootScope.goto = function(path) {
$location.path(path);
};
// useful for debugging: $rootScope.log = console.log || function() {};
- })
- ;
+ });
})(angular, CRM.$, CRM._);