From: Tim Otten Date: Mon, 2 Jun 2014 22:41:23 +0000 (-0700) Subject: CRM-14480 - crmCaseType - Use select2. Fix autocomplete in Chrome. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=bafce1dbfa8cb20423405662171d7c20c0422617;p=civicrm-core.git CRM-14480 - crmCaseType - Use select2. Fix autocomplete in Chrome. --- diff --git a/js/angular-crmCaseType.js b/js/angular-crmCaseType.js index e83e488e07..617f6726c7 100644 --- a/js/angular-crmCaseType.js +++ b/js/angular-crmCaseType.js @@ -59,12 +59,38 @@ crmCaseType.directive('crmAddName', function() { return { restrict: 'AE', - scope: { - crmOptions: '=', - crmVar: '=', - crmOnAdd: '&' - }, - templateUrl: partialUrl('addName.html') + template: '', + link: function(scope, element, attrs) { + /// Format list of options for select2's "data" + var getFormattedOptions = function() { + return { + results: _.map(scope[attrs.crmOptions], function(option){ + return {id: option, text: option}; + }) + }; + }; + + var input = $('input', element); + + scope._resetSelection = function() { + $(input).select2('close'); + $(input).select2('val', ''); + scope[attrs.crmVar] = ''; + }; + + $(input).select2({ + data: getFormattedOptions, + createSearchChoice: function(term) { + return {id: term, text: term}; + } + }); + $(input).on('select2-selecting', function(e) { + scope[attrs.crmVar] = e.val; + scope.$evalAsync(attrs.crmOnAdd); + scope.$evalAsync('_resetSelection()'); + e.preventDefault(); + }); + } }; }); @@ -124,9 +150,12 @@ /// Add a new role $scope.addRole = function(roles, roleName) { - roles.push({ - name: roleName - }); + var names = _.pluck($scope.caseType.definition.caseRoles, 'name'); + if (!_.contains(names, roleName)) { + roles.push({ + name: roleName + }); + } }; $scope.onManagerChange = function(managerRole) { diff --git a/partials/crmCaseType/addName.html b/partials/crmCaseType/addName.html deleted file mode 100644 index 5850ef6d21..0000000000 --- a/partials/crmCaseType/addName.html +++ /dev/null @@ -1,17 +0,0 @@ - -Add: - - -