2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
23 var creationDialogController = function( COMPONENT, FIELD, PARAMETER, $scope, $http, $timeout, $log,
\r
24 CreationService, UtilityService, DataService,VIDCONFIGURATION) {
\r
26 $scope.isDialogVisible = false;
\r
27 $scope.summaryControl = {};
\r
28 $scope.userProvidedControl = {};
\r
30 var callbackFunction = undefined;
\r
31 var componentId = undefined;
\r
33 $scope.$on(COMPONENT.CREATE_COMPONENT, function(event, request) {
\r
35 $scope.isSpinnerVisible = true;
\r
36 $scope.isErrorVisible = false;
\r
37 $scope.isDataVisible = false;
\r
38 $scope.isConfirmEnabled = false;
\r
39 $scope.isDialogVisible = true;
\r
40 $scope.popup.isVisible = true;
\r
42 callbackFunction = request.callbackFunction;
\r
43 componentId = request.componentId;
\r
44 CreationService.initializeComponent(request.componentId);
\r
46 CreationService.setHttpErrorHandler(function(response) {
\r
47 showError(FIELD.ERROR.SYSTEM_FAILURE, UtilityService
\r
48 .getHttpErrorMessage(response));
\r
51 $scope.componentName = CreationService.getComponentDisplayName();
\r
53 CreationService.getParameters(handleGetParametersResponse);
\r
57 var handleGetParametersResponse = function(parameters) {
\r
58 $scope.summaryControl.setList(parameters.summaryList);
\r
59 $scope.userProvidedControl.setList(parameters.userProvidedList);
\r
61 $scope.isSpinnerVisible = false;
\r
62 $scope.isDataVisible = true;
\r
63 $scope.isConfirmEnabled = true;
\r
66 var validateInstanceName = function(iname) {
\r
67 var patt1 = /^([a-z])+([0-9a-z\-_\.]*)$/i;
\r
69 if ( iname == null ){
\r
72 if ( !iname.match(patt1) ) {
\r
77 var validateMap = function(mname) {
\r
78 var patt1 = /^{(\s*\w+\s*:\s*\w+\s*)(\s*,\s*\w+\s*:\s*\w+\s*)*}$/im;
\r
79 if ( mname == null ){
\r
82 if ( !mname.match(patt1) ) {
\r
88 var validateList = function(lname) {
\r
89 var patt1 = /^\[(\s*\w+\s*)(\s*,\s*\w+\s*)*\]$/i;
\r
90 if ( lname == null ){
\r
93 if ( !lname.match(patt1) ) {
\r
99 $scope.userParameterChanged = function(id) {
\r
100 CreationService.updateUserParameterList(id, $scope.userProvidedControl);
\r
103 $scope.confirm = function() {
\r
105 var requiredFields = $scope.userProvidedControl.getRequiredFields();
\r
106 if (requiredFields !== "") {
\r
107 showError(FIELD.ERROR.MISSING_DATA, requiredFields);
\r
111 var paramList = $scope.userProvidedControl.getList();
\r
112 var instanceName = "";
\r
114 if ( DataService.getALaCarte() ) {
\r
115 if ( paramList != null ) {
\r
116 for (var i = 0; i < paramList.length; i++) {
\r
117 if (paramList[i].id === FIELD.ID.INSTANCE_NAME) {
\r
118 instanceName = paramList[i].value;
\r
123 var isValid = validateInstanceName (instanceName);
\r
125 $scope.isErrorVisible = false;
\r
127 showError(FIELD.ERROR.INVALID_INSTANCE_NAME + instanceName,
\r
128 FIELD.ERROR.INSTANCE_NAME_VALIDATE);
\r
132 var arbitraryParametersList = DataService.getArbitraryParameters();
\r
134 if (UtilityService.hasContents (arbitraryParametersList)) {
\r
135 for (var i = 0; i < arbitraryParametersList.length; i++) {
\r
136 p = arbitraryParametersList[i];
\r
137 if (p.type === PARAMETER.MAP) {
\r
138 //validate a map: { <entry_key_1>: <entry_value_1>, ... , <entry_key_n>: <entry_value_n> }
\r
139 // need to find the value in paramList
\r
140 for (var j = 0; j < paramList.length; j++) {
\r
141 if (paramList[j].id === p.id) {
\r
142 p.value = paramList[j].value;
\r
143 var isValid = validateMap (p.value);
\r
145 $scope.isErrorVisible = false;
\r
149 showError(FIELD.ERROR.INVALID_MAP + p.id,
\r
150 FIELD.ERROR.MAP_VALIDATE);
\r
155 } else if (p.type === PARAMETER.LIST) {
\r
156 //validate a list: { value or a list of comma separated values }
\r
157 // need to find the value in paramList
\r
158 for (var j = 0; j < paramList.length; j++) {
\r
159 if (paramList[j].id === p.id) {
\r
160 p.value = paramList[j].value;
\r
161 var isValid = validateList (p.value);
\r
163 $scope.isErrorVisible = false;
\r
167 showError(FIELD.ERROR.INVALID_LIST + p.id,
\r
168 FIELD.ERROR.LIST_VALIDATE);
\r
176 var requestDetails = CreationService
\r
177 .getMsoRequestDetails($scope.userProvidedControl.getList());
\r
179 $scope.isDialogVisible = false;
\r
181 $scope.$broadcast(COMPONENT.MSO_CREATE_REQ, {
\r
182 url : CreationService.getMsoUrl(),
\r
183 requestDetails : requestDetails,
\r
184 componentId: componentId,
\r
185 callbackFunction : function(response) {
\r
186 if (response.isSuccessful) {
\r
187 $scope.popup.isVisible = false;
\r
188 runCallback(response);
\r
190 $scope.isDialogVisible = false;
\r
191 $scope.popup.isVisible = false;
\r
197 $scope.cancel = function() {
\r
198 $scope.isDialogVisible = false;
\r
199 $scope.popup.isVisible = false;
\r
200 runCallback(false);
\r
203 var runCallback = function(response) {
\r
204 if (angular.isFunction(callbackFunction)) {
\r
206 isSuccessful : response.isSuccessful,
\r
207 control : $scope.userProvidedControl.getList(),
\r
208 instanceId : response.instanceId
\r
213 var showError = function(summary, details) {
\r
214 var message = summary;
\r
215 if (UtilityService.hasContents(details)) {
\r
216 message += " (" + details + ")";
\r
218 $scope.isSpinnerVisible = false;
\r
219 $scope.isErrorVisible = true;
\r
220 $scope.error = message;
\r
225 appDS2.controller("creationDialogController", [ "COMPONENT", "FIELD", "PARAMETER", "$scope", "$http",
\r
226 "$timeout", "$log", "CreationService", "UtilityService", "DataService","VIDCONFIGURATION",
\r
227 creationDialogController ]);
\r