$angularModules = array();
$angularModules['ui.utils'] = array('ext' => 'civicrm', 'js' => array('packages/bower_components/angular-ui-utils/ui-utils.min.js'));
$angularModules['ui.sortable'] = array('ext' => 'civicrm', 'js' => array('packages/bower_components/angular-ui-sortable/sortable.min.js'));
+ $angularModules['crmUi'] = array('ext' => 'civicrm', 'js' => array('js/angular-crm-ui.js'));
foreach (CRM_Core_Component::getEnabledComponents() as $component) {
$angularModules = array_merge($angularModules, $component->getAngularModules());
--- /dev/null
+/// crmUi: Sundry UI helpers
+(function (angular, $, _) {
+
+ angular.module('crmUi', [])
+
+ // example: <a crm-ui-lock binding="mymodel.boolfield"></a>
+ // example: <a crm-ui-lock
+ // binding="mymodel.boolfield"
+ // title-locked="ts('Boolfield is locked')"
+ // title-unlocked="ts('Boolfield is unlocked')"></a>
+ .directive('crmUiLock', function ($parse, $rootScope) {
+ var defaultVal = function (defaultValue) {
+ var f = function (scope) {
+ return defaultValue;
+ }
+ f.assign = function (scope, value) {
+ // ignore changes
+ }
+ return f;
+ };
+
+ // like $parse, but accepts a defaultValue in case expr is undefined
+ var parse = function (expr, defaultValue) {
+ return expr ? $parse(expr) : defaultVal(defaultValue);
+ };
+
+ return {
+ template: '',
+ link: function (scope, element, attrs) {
+ var binding = parse(attrs['binding'], true);
+ var titleLocked = parse(attrs['titleLocked'], ts('Locked'));
+ var titleUnlocked = parse(attrs['titleUnlocked'], ts('Unlocked'));
+
+ $(element).addClass('ui-icon lock-button');
+ var refresh = function () {
+ var locked = binding(scope);
+ if (locked) {
+ $(element)
+ .removeClass('ui-icon-unlocked')
+ .addClass('ui-icon-locked')
+ .prop('title', titleLocked(scope))
+ ;
+ }
+ else {
+ $(element)
+ .removeClass('ui-icon-locked')
+ .addClass('ui-icon-unlocked')
+ .prop('title', titleUnlocked(scope))
+ ;
+ }
+ };
+
+ $(element).click(function () {
+ binding.assign(scope, !binding(scope));
+ //scope.$digest();
+ $rootScope.$digest();
+ });
+
+ scope.$watch(attrs.binding, refresh);
+ scope.$watch(attrs.titleLocked, refresh);
+ scope.$watch(attrs.titleUnlocked, refresh);
+
+ refresh();
+ }
+ };
+ })
+ ;
+
+})(angular, CRM.$, CRM._);
\ No newline at end of file
return CRM.resourceUrls['civicrm'] + '/partials/crmCaseType/' + relPath;
};
- var crmCaseType = angular.module('crmCaseType', ['ngRoute', 'ui.utils']);
+ var crmCaseType = angular.module('crmCaseType', ['ngRoute', 'ui.utils', 'crmUi']);
var newCaseTypeDefinitionTemplate = {
activityTypes: [
$scope.activityTypes = CRM.crmCaseType.actTypes;
$scope.activityTypeNames = _.pluck(CRM.crmCaseType.actTypes, 'name');
$scope.relationshipTypeNames = _.pluck(CRM.crmCaseType.relTypes, 'label_b_a'); // label_b_a is CRM_Case_XMLProcessor::REL_TYPE_CNAME
+ $scope.locks = {caseTypeName: true};
$scope.workflows = {
'timeline': 'Timeline',
$('.crmCaseType-acttab').tabs('refresh');
});
});
+
+ var updateCaseTypeName = function () {
+ if (!$scope.caseType.id && $scope.locks.caseTypeName) {
+ // Should we do some filtering? Lowercase? Strip whitespace?
+ $scope.caseType.name = $scope.caseType.title;
+ }
+ };
+ $scope.$watch('locks.caseTypeName', updateCaseTypeName);
+ $scope.$watch('caseType.title', updateCaseTypeName);
});
crmCaseType.controller('CaseTypeListCtrl', function($scope, crmApi, caseTypes) {