[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-FE-common / client / app / views / widget-onboarding / widget-details-dialog / widget-details.controller.js
index 0a9dd12..ad88c02 100644 (file)
-/*-\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
-'use strict';\r
-(function () {\r
-    class WidgetOnboardingDetailsModalCtrl {\r
-        constructor($scope, $log, $interval, applicationsService, adminsService, microserviceService, widgetsCatalogService, errorMessageByCode, ECOMP_URL_REGEX, $window,userProfileService, confirmBoxService, $cookies) {\r
-           \r
-           this.appUpdate = function(){\r
-               this.hasSelectedApp = false;\r
-               this.appCounter = 0;\r
-               for(var i = 0; i < this.availableApps.length; i++){\r
-                       if(this.availableApps[i].isSelected){\r
-                               this.appCounter++;\r
-                               if(!this.hasSelectedApp)\r
-                                       this.hasSelectedApp = true;\r
-                       }\r
-                       if(this.availableApps[i].isSelected\r
-                       && this.availableApps[i].roles.length == 0){\r
-                               var index = i;\r
-                               this.availableRoles = [];    \r
-                               adminsService.getRolesByApp(this.availableApps[i].id).then(roles => {\r
-                                          for(var i = 0; i < roles.length; i++){\r
-                                                  this.availableRoles.push({\r
-                                                          id: roles[i].id,\r
-                                                  name: roles[i].name,\r
-                                                  isSelected: false,\r
-                                                  }); \r
-                                          }\r
-                                          this.availableApps[index].roles = this.availableRoles;\r
-                               });\r
-                       }\r
-                           }\r
-               this.allRoleSelected = true;\r
-               this.checkRoleSelected();\r
-           }\r
-           \r
-           this.roleUpdate = function(app){\r
-                       this.allRoleSelected = true;\r
-               for(var i = 0; i < app.roles.length; i++){\r
-                       if(app.roles[i].isSelected){\r
-                               app.roleSelected = true;\r
-                               this.checkRoleSelected();\r
-                               return;\r
-                       }\r
-               }\r
-                       app.roleSelected = false;\r
-                       this.checkRoleSelected();\r
-           }\r
-           \r
-           this.checkRoleSelected = function(){\r
-               for(var i = 0; i < this.availableApps.length; i++){\r
-                       if(this.availableApps[i].isSelected\r
-                       && !this.availableApps[i].roleSelected){\r
-                               this.allRoleSelected = false;\r
-                               return;\r
-                       }\r
-               }\r
-           }\r
-                  \r
-           this.getAppName = function(appId){\r
-                for(var i = 0; i < this.availableApps.length; i++){\r
-                        if(this.availableApps[i].id == appId){\r
-                                return this.availableApps[i].name;\r
-                        }\r
-                }\r
-           }\r
-           \r
-            let newWidgetModel = {\r
-                name: null,\r
-                roleId: null,\r
-                roleName: null,\r
-                appId: null,\r
-                appName: null,\r
-                url: null,\r
-                showAppOptions: false,\r
-                showRoleOptions: false,\r
-                hasSelectedApp: false\r
-            };\r
-          \r
-            let getAvailableApps = () => {             \r
-               \r
-               if(this.isEditMode == false){   \r
-                       applicationsService.getAppsForSuperAdminAndAccountAdmin().then(apps => {\r
-                               this.availableApps=[];\r
-                               for(var i=0;i<apps.length;i++) {\r
-                               if (!apps[i].restrictedApp) {\r
-                            this.availableApps.push({\r
-                                id: apps[i].id,\r
-                                name: apps[i].name,\r
-                                roles: [],\r
-                                roleSelected: false,\r
-                                isSelected: false,\r
-                            });\r
-                               }\r
-                           }\r
-                       }).catch(err => {\r
-                           $log.error(err);\r
-                       });\r
-               }\r
-               else if(this.isEditMode == true){\r
-                       if(this.widget.allowAllUser == "Y")\r
-                               this.widget.allUser = true;\r
-                       applicationsService.getAppsForSuperAdminAndAccountAdmin().then(apps => {\r
-                               this.availableApps=[];\r
-                               let selectedApps = {};\r
-                               var availableApps = this.availableApps;  \r
-                               this.allRoleSelected = true;\r
-                               for(var i=0; i < this.widget.widgetRoles.length; i++){\r
-                                       if(selectedApps[this.widget.widgetRoles[i].app.appId] != undefined)\r
-                                               selectedApps[this.widget.widgetRoles[i].app.appId] += this.widget.widgetRoles[i].roleId + ";" + this.widget.widgetRoles[i].roleName + ";"; \r
-                                       else{\r
-                                               selectedApps[this.widget.widgetRoles[i].app.appId] = this.widget.widgetRoles[i].roleId + ";" + this.widget.widgetRoles[i].roleName + ";";                       \r
-                                               this.appCounter++;\r
-                                       }\r
-                               }                       \r
-                               apps.forEach(function(app, index){\r
-                                               availableApps.push({\r
-                                      id: app.id,\r
-                                      name: app.name,\r
-                                      roles: [],\r
-                                      roleSelected: false,\r
-                                      isSelected: false,\r
-                                               });\r
-                                               if(selectedApps[app.id] != undefined){\r
-                                                       adminsService.getRolesByApp(app.id).then(roles => {\r
-                                                       var role = selectedApps[app.id].split(';');\r
-                                               var selectedRoles = [];\r
-                                               var n = 0;\r
-                                               while((n+1) < role.length){\r
-                                                       selectedRoles.push({\r
-                                                                          id: role[n++],\r
-                                                                  name: role[n++],\r
-                                                                  isSelected: true,\r
-                                                               });\r
-                                               }                                       \r
-                                                       for(var m = 0; m < roles.length; m++){\r
-                                                               var hasSelected = true;\r
-                                                               for(var n = 0; n < selectedRoles.length; n++){\r
-                                                                       if(selectedRoles[n].id == roles[m].id){\r
-                                                                               hasSelected = false;\r
-                                                                               break;\r
-                                                                       }\r
-                                                               }\r
-                                                               if(hasSelected){\r
-                                                                  selectedRoles.push({\r
-                                                                          id: roles[m].id,\r
-                                                                  name: roles[m].name,\r
-                                                                  isSelected: false,\r
-                                                                  }); \r
-                                                               }          \r
-                                                       }  \r
-                                                       availableApps[index].roleSelected = true;\r
-                                                       availableApps[index].isSelected = true;\r
-                                                       availableApps[index].roles = selectedRoles;\r
-                                                       });\r
-                                               }\r
-                               })\r
-                       })\r
-               }\r
-            };\r
-            \r
-            let getAvailableServices = () =>{\r
-               microserviceService.getServiceList().then(services => {\r
-                       this.availableServices = [];\r
-                       for(var i = 0; i < services.length; i++){\r
-                               this.availableServices.push({\r
-                                       id: services[i].id,\r
-                                       name: services[i].name,\r
-                                       option: services[i].name + ": " + services[i].url\r
-                               });\r
-                               \r
-                               if(this.widget.service != null && this.widget.service.id == services[i].id){\r
-                                       this.widget.serviceURL = this.availableServices[i];\r
-                               }\r
-                       }\r
-                }).catch(err => {\r
-                   $log.error(err);\r
-                });\r
-            }\r
-            \r
-\r
-            let init = () => {\r
-               $log.info('WidgetOnboardingDetailsModalCtrl::init');\r
-                this.widgetsList = [];\r
-                this.duplicatedName = true;\r
-                this.allRoleSelected = false;\r
-                this.appCounter = 0;\r
-               this.isSaving = false;\r
-               this.allUser = false;\r
-               this.emptyWidgetName = false;\r
-               \r
-                if ($scope.ngDialogData && $scope.ngDialogData.widget) {\r
-                    this.isEditMode = true;\r
-                       this.allRoleSelected = true;\r
-                    this.widget = _.clone($scope.ngDialogData.widget);\r
-                } else {\r
-                    this.isEditMode = false;\r
-                    this.widget = _.clone(newWidgetModel);\r
-                }\r
-                \r
-                widgetsCatalogService.getManagedWidgets().then(res => {\r
-                       for(var i = 0; i < res.length; i++){\r
-                               this.widgetsList.push(res[i].name);\r
-                       }\r
-                 }).catch(err => {\r
-                     $log.error('WidgetOnboardingDetailsModalCtrl::init error: ' + err);\r
-                 }).finally(()=> {\r
-                     this.isLoadingTable = false;\r
-                 });\r
-                 getAvailableApps();\r
-                 getAvailableServices();\r
-            };\r
-            this.ECOMP_URL_REGEX = ECOMP_URL_REGEX;\r
-            this.conflictMessages = {};\r
-            this.scrollApi = {};\r
-\r
-            let resetConflict = fieldName => {\r
-                delete this.conflictMessages[fieldName];\r
-                if($scope.widgetForm[fieldName]){\r
-                    $scope.widgetForm[fieldName].$setValidity('conflict', true);\r
-                }\r
-            };\r
-            \r
-            this.updateSelectedRole = () => {\r
-                if (!this.selectedRole) {\r
-                    return;\r
-                }\r
-                this.widget.RoleId = this.selectedRole.id;\r
-                this.widget.RoleName = this.selectedRole.name;\r
-            };\r
-            \r
-            let emptyCookies = () => {\r
-                userProfileService.getUserProfile()\r
-                .then(profile=> {\r
-                    $log.info('AppDetailsModalCtrl::emptyCookies profile: ', profile);\r
-                    $scope.orgUserId = profile.orgUserId;\r
-                    $log.info('user has the following orgUserId: ' + profile.orgUserId);\r
-                    if ($cookies.getObject($scope.orgUserId + '_widget') != undefined && $cookies.getObject($scope.orgUserId + '_widget') != null) {\r
-                        $cookies.remove($scope.orgUserId + '_widget');\r
-                    }\r
-                });\r
-            };\r
-              \r
-            this.updateWidgetName = () => {\r
-               for(var i = 0; i < this.widgetsList.length; i++){\r
-                       if(this.widget.name.toUpperCase() == this.widgetsList[i].toUpperCase()){\r
-                               this.duplicatedName = false;\r
-                               return;\r
-                       }\r
-               }\r
-               this.duplicatedName = true;\r
-            };\r
-            \r
-            this.saveChanges = () => {     \r
-               \r
-               if(!this.isEditMode)\r
-                       this.updateWidgetName();\r
-               \r
-               if(this.duplicatedName == false \r
-                  || this.widget.name == ''\r
-                  || this.widget.name == undefined){\r
-                       this.emptyWidgetName = true;\r
-                       return;\r
-                }\r
-               \r
-               if((this.widget.file == undefined && !this.isEditMode) ||\r
-               (!this.widget.allUser && this.appCounter == 0) ||\r
-               this.widget.name == null ||\r
-               (!this.widget.allUser && !this.allRoleSelected) ||\r
-               this.widget.saving == true)\r
-                       return; \r
-               \r
-               \r
-                       this.widget.saving = true;\r
-               var selectedRoles = [];\r
-               if(!this.widget.allUser){\r
-                       for(var i = 0; i < this.availableApps.length; i++){\r
-                               if(this.availableApps[i].isSelected){\r
-                                               for(var n = 0; n < this.availableApps[i].roles.length; n++) {\r
-                                                       if(this.availableApps[i].roles[n].isSelected){\r
-                                                       var role = {\r
-                                                               app: {\r
-                                                                       appId: this.availableApps[i].id\r
-                                                               },\r
-                                                               roleId: this.availableApps[i].roles[n].id,\r
-                                                               roleName: this.availableApps[i].roles[n].name,\r
-                                                               };\r
-                                                       selectedRoles.push(role);\r
-                                                       }\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-               \r
-               var allowAllUser = 0;\r
-               if(this.widget.allUser)\r
-                       allowAllUser = 1;       \r
-               \r
-               var serviceId = null;\r
-               if(this.widget.serviceURL != null &&\r
-               this.widget.serviceURL != undefined){\r
-                       serviceId = this.widget.serviceURL.id;\r
-               }\r
-               \r
-               \r
-               var file_loc = this.widget.name + ".zip";\r
-               var newWidget = {\r
-                               name: this.widget.name,\r
-                               desc: this.widget.desc,\r
-                               widgetRoles: selectedRoles,\r
-                               fileLocation: file_loc,\r
-                               allowAllUser: allowAllUser,\r
-                               serviceId: serviceId\r
-               };\r
-               \r
-               if(this.isEditMode){\r
-                       \r
-                       if(this.widget.file != undefined){\r
-                               widgetsCatalogService.updateWidgetWithFile(this.widget.file, this.widget.id, newWidget).then(res => {\r
-                                       if(!res.valid){\r
-                                               if(!res.error){\r
-                                                       confirmBoxService.showInformation("Could not save. Please retry.");\r
-                                                       this.widget.saving = false;\r
-                                                       return;\r
-                                               }\r
-                                               confirmBoxService.showInformation(res.error);\r
-                                               this.widget.saving = false;\r
-                                               return;\r
-                                       }\r
-                                       $scope.closeThisDialog(true);\r
-                               this.widget.saving = false;\r
-                               });     \r
-                       }\r
-                       else{\r
-                               widgetsCatalogService.updateWidget(this.widget.id, newWidget)\r
-                               .then(() => {\r
-                                       $scope.closeThisDialog(true); \r
-                           });\r
-                       }\r
-               }\r
-               else{\r
-                       widgetsCatalogService.createWidget(newWidget, this.widget.file).then(res => {\r
-                               if(!res.valid){\r
-                                               if(!res.error)\r
-                                                       confirmBoxService.showInformation("Could not save. Please retry.");\r
-                                               else\r
-                                                       confirmBoxService.showInformation(res.error);\r
-                                               this.widget.saving = false;\r
-                                               return;\r
-                                       }\r
-                               $scope.closeThisDialog(true);\r
-                               this.widget.saving = false;\r
-                       });\r
-               }\r
-            };\r
-            init();\r
-            $scope.$on('$stateChangeStart', e => {\r
-                e.preventDefault();\r
-            });\r
-        }\r
-    }\r
-    WidgetOnboardingDetailsModalCtrl.$inject = ['$scope', '$log', '$interval', 'applicationsService', 'adminsService', 'microserviceService', 'widgetsCatalogService', 'errorMessageByCode', 'ECOMP_URL_REGEX', '$window','userProfileService', 'confirmBoxService', '$cookies'];\r
-    angular.module('ecompApp').controller('WidgetOnboardingDetailsModalCtrl', WidgetOnboardingDetailsModalCtrl);\r
-})(); \r
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file 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.
+ * ================================================================================
+ */
+'use strict';
+(function () {
+    class WidgetOnboardingDetailsModalCtrl {
+        constructor($scope, $log, $interval, applicationsService, adminsService, microserviceService, widgetsCatalogService, errorMessageByCode, ECOMP_URL_REGEX, $window,userProfileService, confirmBoxService, $cookies) {
+           
+           this.appUpdate = function(){
+               this.hasSelectedApp = false;
+               this.appCounter = 0;
+               for(var i = 0; i < this.availableApps.length; i++){
+                       if(this.availableApps[i].isSelected){
+                               this.appCounter++;
+                               if(!this.hasSelectedApp)
+                                       this.hasSelectedApp = true;
+                       }
+                       if(this.availableApps[i].isSelected
+                       && this.availableApps[i].roles.length == 0){
+                               var index = i;
+                               this.availableRoles = [];    
+                               adminsService.getRolesByApp(this.availableApps[i].id).then(roles => {
+                                          for(var i = 0; i < roles.length; i++){
+                                                  this.availableRoles.push({
+                                                          id: roles[i].id,
+                                                  name: roles[i].name,
+                                                  isSelected: false,
+                                                  }); 
+                                          }
+                                          this.availableApps[index].roles = this.availableRoles;
+                               });
+                       }
+                           }
+               this.allRoleSelected = true;
+               this.checkRoleSelected();
+           }
+           
+           this.roleUpdate = function(app){
+                       this.allRoleSelected = true;
+               for(var i = 0; i < app.roles.length; i++){
+                       if(app.roles[i].isSelected){
+                               app.roleSelected = true;
+                               this.checkRoleSelected();
+                               return;
+                       }
+               }
+                       app.roleSelected = false;
+                       this.checkRoleSelected();
+           }
+           
+           this.checkRoleSelected = function(){
+               for(var i = 0; i < this.availableApps.length; i++){
+                       if(this.availableApps[i].isSelected
+                       && !this.availableApps[i].roleSelected){
+                               this.allRoleSelected = false;
+                               return;
+                       }
+               }
+           }
+                  
+           this.getAppName = function(appId){
+                for(var i = 0; i < this.availableApps.length; i++){
+                        if(this.availableApps[i].id == appId){
+                                return this.availableApps[i].name;
+                        }
+                }
+           }
+           
+            let newWidgetModel = {
+                name: null,
+                roleId: null,
+                roleName: null,
+                appId: null,
+                appName: null,
+                url: null,
+                showAppOptions: false,
+                showRoleOptions: false,
+                hasSelectedApp: false
+            };
+          
+            let getAvailableApps = () => {             
+               
+               if(this.isEditMode == false){   
+                       applicationsService.getAppsForSuperAdminAndAccountAdmin().then(apps => {
+                               this.availableApps=[];
+                               for(var i=0;i<apps.length;i++) {
+                               if (!apps[i].restrictedApp) {
+                            this.availableApps.push({
+                                id: apps[i].id,
+                                name: apps[i].name,
+                                roles: [],
+                                roleSelected: false,
+                                isSelected: false,
+                            });
+                               }
+                           }
+                       }).catch(err => {
+                           $log.error(err);
+                       });
+               }
+               else if(this.isEditMode == true){
+                       if(this.widget.allowAllUser == "Y")
+                               this.widget.allUser = true;
+                       applicationsService.getAppsForSuperAdminAndAccountAdmin().then(apps => {
+                               this.availableApps=[];
+                               let selectedApps = {};
+                               var availableApps = this.availableApps;  
+                               this.allRoleSelected = true;
+                               for(var i=0; i < this.widget.widgetRoles.length; i++){
+                                       if(selectedApps[this.widget.widgetRoles[i].app.appId] != undefined)
+                                               selectedApps[this.widget.widgetRoles[i].app.appId] += this.widget.widgetRoles[i].roleId + ";" + this.widget.widgetRoles[i].roleName + ";"; 
+                                       else{
+                                               selectedApps[this.widget.widgetRoles[i].app.appId] = this.widget.widgetRoles[i].roleId + ";" + this.widget.widgetRoles[i].roleName + ";";                       
+                                               this.appCounter++;
+                                       }
+                               }                       
+                               apps.forEach(function(app, index){
+                                               availableApps.push({
+                                      id: app.id,
+                                      name: app.name,
+                                      roles: [],
+                                      roleSelected: false,
+                                      isSelected: false,
+                                               });
+                                               if(selectedApps[app.id] != undefined){
+                                                       adminsService.getRolesByApp(app.id).then(roles => {
+                                                       var role = selectedApps[app.id].split(';');
+                                               var selectedRoles = [];
+                                               var n = 0;
+                                               while((n+1) < role.length){
+                                                       selectedRoles.push({
+                                                                          id: role[n++],
+                                                                  name: role[n++],
+                                                                  isSelected: true,
+                                                               });
+                                               }                                       
+                                                       for(var m = 0; m < roles.length; m++){
+                                                               var hasSelected = true;
+                                                               for(var n = 0; n < selectedRoles.length; n++){
+                                                                       if(selectedRoles[n].id == roles[m].id){
+                                                                               hasSelected = false;
+                                                                               break;
+                                                                       }
+                                                               }
+                                                               if(hasSelected){
+                                                                  selectedRoles.push({
+                                                                          id: roles[m].id,
+                                                                  name: roles[m].name,
+                                                                  isSelected: false,
+                                                                  }); 
+                                                               }          
+                                                       }  
+                                                       availableApps[index].roleSelected = true;
+                                                       availableApps[index].isSelected = true;
+                                                       availableApps[index].roles = selectedRoles;
+                                                       });
+                                               }
+                               })
+                       })
+               }
+            };
+            
+            let getAvailableServices = () =>{
+               microserviceService.getServiceList().then(services => {
+                       this.availableServices = [];
+                       for(var i = 0; i < services.length; i++){
+                               this.availableServices.push({
+                                       id: services[i].id,
+                                       name: services[i].name,
+                                       option: services[i].name + ": " + services[i].url
+                               });
+                               
+                               if(this.widget.serviceId != null && this.widget.serviceId == services[i].id){
+                                       this.widget.serviceURL = this.availableServices[i];
+                               }
+                       }
+                }).catch(err => {
+                   $log.error(err);
+                });
+            }
+            
+
+            let init = () => {
+               $log.info('WidgetOnboardingDetailsModalCtrl::init');
+                this.widgetsList = [];
+                this.duplicatedName = true;
+                this.allRoleSelected = false;
+                this.appCounter = 0;
+               this.isSaving = false;
+               this.allUser = false;
+               this.emptyWidgetName = false;
+               
+                if ($scope.ngDialogData && $scope.ngDialogData.widget) {
+                    this.isEditMode = true;
+                       this.allRoleSelected = true;
+                    this.widget = _.clone($scope.ngDialogData.widget);
+                } else {
+                    this.isEditMode = false;
+                    this.widget = _.clone(newWidgetModel);
+                }
+                
+                widgetsCatalogService.getManagedWidgets().then(res => {
+                       for(var i = 0; i < res.length; i++){
+                               this.widgetsList.push(res[i].name);
+                       }
+                 }).catch(err => {
+                     $log.error('WidgetOnboardingDetailsModalCtrl::init error: ' + err);
+                 }).finally(()=> {
+                     this.isLoadingTable = false;
+                 });
+                 getAvailableApps();
+                 getAvailableServices();
+            };
+            this.ECOMP_URL_REGEX = ECOMP_URL_REGEX;
+            this.conflictMessages = {};
+            this.scrollApi = {};
+
+            let resetConflict = fieldName => {
+                delete this.conflictMessages[fieldName];
+                if($scope.widgetForm[fieldName]){
+                    $scope.widgetForm[fieldName].$setValidity('conflict', true);
+                }
+            };
+            
+            this.updateSelectedRole = () => {
+                if (!this.selectedRole) {
+                    return;
+                }
+                this.widget.RoleId = this.selectedRole.id;
+                this.widget.RoleName = this.selectedRole.name;
+            };
+            
+            let emptyCookies = () => {
+                userProfileService.getUserProfile()
+                .then(profile=> {
+                    $log.info('AppDetailsModalCtrl::emptyCookies profile: ', profile);
+                    $scope.orgUserId = profile.orgUserId;
+                    $log.info('user has the following orgUserId: ' + profile.orgUserId);
+                    if ($cookies.getObject($scope.orgUserId + '_widget') != undefined && $cookies.getObject($scope.orgUserId + '_widget') != null) {
+                        $cookies.remove($scope.orgUserId + '_widget');
+                    }
+                });
+            };
+              
+            this.updateWidgetName = () => {
+               for(var i = 0; i < this.widgetsList.length; i++){
+                       if(this.widget.name.toUpperCase() == this.widgetsList[i].toUpperCase()){
+                               this.duplicatedName = false;
+                               return;
+                       }
+               }
+               this.duplicatedName = true;
+            };
+            
+            this.saveChanges = () => {     
+               
+               if(!this.isEditMode)
+                       this.updateWidgetName();
+               
+               if(this.duplicatedName == false 
+                  || this.widget.name == ''
+                  || this.widget.name == undefined){
+                       this.emptyWidgetName = true;
+                       return;
+                }
+               
+               if((this.widget.file == undefined && !this.isEditMode) ||
+               (!this.widget.allUser && this.appCounter == 0) ||
+               this.widget.name == null ||
+               (!this.widget.allUser && !this.allRoleSelected) ||
+               this.widget.saving == true)
+                       return; 
+               
+               
+                       this.widget.saving = true;
+               var selectedRoles = [];
+               if(!this.widget.allUser){
+                       for(var i = 0; i < this.availableApps.length; i++){
+                               if(this.availableApps[i].isSelected){
+                                               for(var n = 0; n < this.availableApps[i].roles.length; n++) {
+                                                       if(this.availableApps[i].roles[n].isSelected){
+                                                       var role = {
+                                                               app: {
+                                                                       appId: this.availableApps[i].id
+                                                               },
+                                                               roleId: this.availableApps[i].roles[n].id,
+                                                               roleName: this.availableApps[i].roles[n].name,
+                                                               };
+                                                       selectedRoles.push(role);
+                                                       }
+                                       }
+                               }
+                       }
+               }
+               
+               var allowAllUser = 0;
+               if(this.widget.allUser)
+                       allowAllUser = 1;       
+               
+               var serviceId = null;
+               if(this.widget.serviceURL != null &&
+               this.widget.serviceURL != undefined){
+                       serviceId = this.widget.serviceURL.id;
+               }
+               
+               
+               var file_loc = this.widget.name + ".zip";
+               var newWidget = {
+                               name: this.widget.name,
+                               desc: this.widget.desc,
+                               widgetRoles: selectedRoles,
+                               fileLocation: file_loc,
+                               allowAllUser: allowAllUser,
+                               serviceId: serviceId
+               };
+               
+               if(this.isEditMode){
+                       
+                       if(this.widget.file != undefined){
+                               widgetsCatalogService.updateWidgetWithFile(this.widget.file, this.widget.id, newWidget).then(res => {
+                                       if(!res.valid){
+                                               if(!res.error){
+                                                       confirmBoxService.showInformation("Could not save. Please retry.");
+                                                       this.widget.saving = false;
+                                                       return;
+                                               }
+                                               confirmBoxService.showInformation(res.error);
+                                               this.widget.saving = false;
+                                               return;
+                                       }
+                                       $scope.closeThisDialog(true);
+                               this.widget.saving = false;
+                               });     
+                       }
+                       else{
+                               widgetsCatalogService.updateWidget(this.widget.id, newWidget)
+                               .then(() => {
+                                       $scope.closeThisDialog(true); 
+                           });
+                       }
+               }
+               else{
+                       widgetsCatalogService.createWidget(newWidget, this.widget.file).then(res => {
+                               if(!res.valid){
+                                               if(!res.error)
+                                                       confirmBoxService.showInformation("Could not save. Please retry.");
+                                               else
+                                                       confirmBoxService.showInformation(res.error);
+                                               this.widget.saving = false;
+                                               return;
+                                       }
+                               $scope.closeThisDialog(true);
+                               this.widget.saving = false;
+                       });
+               }
+            };
+            init();
+            $scope.$on('$stateChangeStart', e => {
+                e.preventDefault();
+            });
+        }
+    }
+    WidgetOnboardingDetailsModalCtrl.$inject = ['$scope', '$log', '$interval', 'applicationsService', 'adminsService', 'microserviceService', 'widgetsCatalogService', 'errorMessageByCode', 'ECOMP_URL_REGEX', '$window','userProfileService', 'confirmBoxService', '$cookies'];
+    angular.module('ecompApp').controller('WidgetOnboardingDetailsModalCtrl', WidgetOnboardingDetailsModalCtrl);
+})();