2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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 * ============LICENSE_END=========================================================
23 var creationDialogController = function( COMPONENT, FIELD, $scope, $http, $timeout, $log,
24 CreationService, UtilityService) {
26 $scope.isDialogVisible = false;
27 $scope.summaryControl = {};
28 $scope.userProvidedControl = {};
30 var callbackFunction = undefined;
31 var componentId = undefined;
33 $scope.$on("createComponent", function(event, request) {
35 $scope.isSpinnerVisible = true;
36 $scope.isErrorVisible = false;
37 $scope.isDataVisible = false;
38 $scope.isConfirmEnabled = false;
39 $scope.isDialogVisible = true;
40 $scope.popup.isVisible = true;
42 callbackFunction = request.callbackFunction;
43 componentId = request.componentId;
44 CreationService.initializeComponent(request.componentId);
46 CreationService.setHttpErrorHandler(function(response) {
47 showError("System failure", UtilityService
48 .getHttpErrorMessage(response));
51 $scope.componentName = CreationService.getComponentDisplayName();
53 CreationService.getParameters(handleGetParametersResponse);
57 var handleGetParametersResponse = function(parameters) {
58 $scope.summaryControl.setList(parameters.summaryList);
59 $scope.userProvidedControl.setList(parameters.userProvidedList);
61 $scope.isSpinnerVisible = false;
62 $scope.isDataVisible = true;
63 $scope.isConfirmEnabled = true;
66 var validateInstanceName = function(iname) {
67 var patt1 = /^([a-z])+([0-9a-z\-_]*)$/i;
72 if ( !iname.match(patt1) ) {
78 $scope.userParameterChanged = function(id) {
79 CreationService.updateUserParameterList(id, $scope.userProvidedControl);
82 $scope.confirm = function() {
84 var requiredFields = $scope.userProvidedControl.getRequiredFields();
85 if (requiredFields !== "") {
86 showError("Missing data", requiredFields);
89 // validate the instance names for volumeGroup, vfModule, network
91 if ( componentId != COMPONENT.SERVICE ) {
92 var paramList = $scope.userProvidedControl.getList();
93 var instanceName = "";
95 if ( paramList != null ) {
96 for (var i = 0; i < paramList.length; i++) {
97 if (paramList[i].id === FIELD.ID.INSTANCE_NAME) {
98 instanceName = paramList[i].value;
103 var isValid = validateInstanceName (instanceName);
105 $scope.isErrorVisible = false;
107 showError("Invalid instance name: " + instanceName,
108 "The instance name must contain only alphanumeric or \"_-.\" characters, and must start with an alphabetic character");
112 var requestDetails = CreationService
113 .getMsoRequestDetails($scope.userProvidedControl.getList());
115 $scope.isDialogVisible = false;
117 $scope.$broadcast("createInstance", {
118 url : CreationService.getMsoUrl(),
119 requestDetails : requestDetails,
120 callbackFunction : function(response) {
121 if (response.isSuccessful) {
122 $scope.popup.isVisible = false;
123 runCallback(response);
125 $scope.isDialogVisible = true;
131 $scope.cancel = function() {
132 $scope.isDialogVisible = false;
133 $scope.popup.isVisible = false;
137 var runCallback = function(response) {
138 if (angular.isFunction(callbackFunction)) {
140 isSuccessful : response.isSuccessful,
141 control : $scope.userProvidedControl.getList(),
142 instanceId : response.instanceId
147 var showError = function(summary, details) {
148 var message = summary;
149 if (UtilityService.hasContents(details)) {
150 message += " (" + details + ")";
152 $scope.isSpinnerVisible = false;
153 $scope.isErrorVisible = true;
154 $scope.error = message;
160 .controller("creationDialogController", [ "COMPONENT", "FIELD", "$scope", "$http",
161 "$timeout", "$log", "CreationService", "UtilityService",
162 creationDialogController ]);