2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
21 angular.module('ecompApp')
22 .directive('multipleSelect', function ($window) {
25 templateUrl: 'app/directives/multiple-select/multiple-select.tpl.html',
35 link: function(scope, elm, attrs){
36 scope.isExpanded = false;
38 scope.isDisabled = !scope.ngModel || !scope.ngModel.length;
39 scope.$watch('ngModel', function(newVal){
40 scope.isDisabled = !newVal || !newVal.length;
44 let startListening = () => {
45 console.log('listening on $window!');
46 angular.element($window).on('click', function () {
50 angular.element('multiple-select').on('click', function(e) {
51 if($(e.target).closest('multiple-select')[0].attributes['unique-data'].value === attrs.uniqueData){
52 console.log('ignored that..:', attrs.uniqueData);
55 console.log('shouldnt ignore, close expanded!:', attrs.uniqueData);
56 scope.isExpanded = false;
62 let stopListening = function() {
63 if(scope.onDropdownClose){
64 scope.onDropdownClose();
66 scope.isExpanded = false;
68 console.log('stop listening on $window and multiple-element!');
69 angular.element($window).off('click');
70 angular.element('multiple-select').off('click');
73 scope.showCheckboxes = function(){
74 scope.isExpanded = !scope.isExpanded;
79 if(scope.onDropdownClose){
80 scope.onDropdownClose();
85 scope.onCheckboxClicked = function() {
86 console.log('checkbox clicked; unique data: ',attrs.uniqueData);
92 scope.getTitle = function(){
94 if(!scope.ngModel || !scope.ngModel.length) {
97 scope.ngModel.forEach(function(item){
98 if(item[scope.valueAttr]){
99 disp+=item[scope.nameAttr] + ",";
103 disp = disp.slice(0,disp.length-1);
105 disp = scope.placeholder;