-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-/**\r
- * Created by nnaffar on 12/21/15.+\r
- */\r
-angular.module('ecompApp')\r
- .directive('multipleSelect', function ($window) {\r
- return {\r
- restrict: 'E',\r
- templateUrl: 'app/directives/multiple-select/multiple-select.tpl.html',\r
- scope: {\r
- onChange: '&',\r
- nameAttr: '@',\r
- valueAttr: '@',\r
- ngModel: '=',\r
- placeholder: '@',\r
- uniqueData: '@?',\r
- onDropdownClose: '&?'\r
- },\r
- link: function(scope, elm, attrs){\r
- scope.isExpanded = false;\r
-\r
- scope.isDisabled = !scope.ngModel || !scope.ngModel.length;\r
- scope.$watch('ngModel', function(newVal){\r
- scope.isDisabled = !newVal || !newVal.length;\r
- });\r
-\r
-\r
- let startListening = () => {\r
- console.log('listening on $window!');\r
- angular.element($window).on('click', function () {\r
- stopListening();\r
- });\r
-\r
- angular.element('multiple-select').on('click', function(e) {\r
- if($(e.target).closest('multiple-select')[0].attributes['unique-data'].value === attrs.uniqueData){\r
- console.log('ignored that..:', attrs.uniqueData);\r
- e.stopPropagation();\r
- }else{\r
- console.log('shouldnt ignore, close expanded!:', attrs.uniqueData);\r
- scope.isExpanded = false;\r
- scope.$applyAsync();\r
- }\r
- });\r
- };\r
-\r
- let stopListening = function() {\r
- if(scope.onDropdownClose){\r
- scope.onDropdownClose();\r
- }\r
- scope.isExpanded = false;\r
- scope.$applyAsync();\r
- console.log('stop listening on $window and multiple-element!');\r
- angular.element($window).off('click');\r
- angular.element('multiple-select').off('click');\r
- };\r
-\r
- scope.showCheckboxes = function(){\r
- scope.isExpanded = !scope.isExpanded;\r
- if(scope.isExpanded){\r
- startListening();\r
- }else{\r
- stopListening();\r
- if(scope.onDropdownClose){\r
- scope.onDropdownClose();\r
- }\r
- }\r
- };\r
-\r
- scope.onCheckboxClicked = function() {\r
- console.log('checkbox clicked; unique data: ',attrs.uniqueData);\r
- if(scope.onChange) {\r
- scope.onChange();\r
- }\r
- }\r
-\r
- scope.getTitle = function(){\r
- var disp = '';\r
- if(!scope.ngModel || !scope.ngModel.length) {\r
- return disp;\r
- }\r
- scope.ngModel.forEach(function(item){\r
- if(item[scope.valueAttr]){\r
- disp+=item[scope.nameAttr] + ',';\r
- }\r
- });\r
- if(disp!==''){\r
- disp = disp.slice(0,disp.length-1);\r
- }else{\r
- disp = scope.placeholder;\r
- }\r
- return disp;\r
- };\r
- }\r
- };\r
- });\r
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+/**
+ * Created by nnaffar on 12/21/15.+
+ */
+angular.module('ecompApp')
+ .directive('multipleSelect', function ($window) {
+ return {
+ restrict: 'E',
+ templateUrl: 'app/directives/multiple-select/multiple-select.tpl.html',
+ scope: {
+ onChange: '&',
+ nameAttr: '@',
+ valueAttr: '@',
+ ngModel: '=',
+ placeholder: '@',
+ uniqueData: '@?',
+ onDropdownClose: '&?'
+ },
+ link: function(scope, elm, attrs){
+ scope.isExpanded = false;
+
+ scope.isDisabled = !scope.ngModel || !scope.ngModel.length;
+ scope.$watch('ngModel', function(newVal){
+ scope.isDisabled = !newVal || !newVal.length;
+ });
+
+
+ let startListening = () => {
+ console.log('listening on $window!');
+ angular.element($window).on('click', function () {
+ stopListening();
+ });
+
+ angular.element('multiple-select').on('click', function(e) {
+ if($(e.target).closest('multiple-select')[0].attributes['unique-data'].value === attrs.uniqueData){
+ console.log('ignored that..:', attrs.uniqueData);
+ e.stopPropagation();
+ }else{
+ console.log('shouldnt ignore, close expanded!:', attrs.uniqueData);
+ scope.isExpanded = false;
+ scope.$applyAsync();
+ }
+ });
+ };
+
+ let stopListening = function() {
+ if(scope.onDropdownClose){
+ scope.onDropdownClose();
+ }
+ scope.isExpanded = false;
+ scope.$applyAsync();
+ console.log('stop listening on $window and multiple-element!');
+ angular.element($window).off('click');
+ angular.element('multiple-select').off('click');
+ };
+
+ scope.showCheckboxes = function(){
+ scope.isExpanded = !scope.isExpanded;
+ if(scope.isExpanded){
+ startListening();
+ }else{
+ stopListening();
+ if(scope.onDropdownClose){
+ scope.onDropdownClose();
+ }
+ }
+ };
+
+ scope.onCheckboxClicked = function() {
+ console.log('checkbox clicked; unique data: ',attrs.uniqueData);
+ if(scope.onChange) {
+ scope.onChange();
+ }
+ }
+
+ scope.getTitle = function(){
+ var disp = '';
+ if(!scope.ngModel || !scope.ngModel.length) {
+ return disp;
+ }
+ scope.ngModel.forEach(function(item){
+ if(item[scope.valueAttr]){
+ disp+=item[scope.nameAttr] + ',';
+ }
+ });
+ if(disp!==''){
+ disp = disp.slice(0,disp.length-1);
+ }else{
+ disp = scope.placeholder;
+ }
+ return disp;
+ };
+
+ scope.getIdTitle = function(){
+ var disp = '';
+ if(!scope.ngModel || !scope.ngModel.length) {
+ return disp;
+ }
+ scope.ngModel.forEach(function(item){
+ if(item[scope.valueAttr]){
+ disp+=item[scope.nameAttr] + ',';
+ }
+ });
+ if(disp!==''){
+ disp = disp.slice(0,disp.length-1);
+ }else{
+ disp = scope.placeholder;
+ }
+ return disp+attrs.uniqueData;
+ };
+ }
+ };
+ });