From 17050c32372d6f3f9d9bec94fe7939eb3fca25d1 Mon Sep 17 00:00:00 2001 From: Luji7 Date: Thu, 15 Sep 2016 01:04:10 +0800 Subject: add create service instance event registration Change-Id: Id41cc785f25e454b3cdf569491d69619e17cc329 Signed-off-by: Luji7 --- openo-portal/portal-lifecyclemgr/js/gsolcm.js | 77 +++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'openo-portal/portal-lifecyclemgr/js/gsolcm.js') diff --git a/openo-portal/portal-lifecyclemgr/js/gsolcm.js b/openo-portal/portal-lifecyclemgr/js/gsolcm.js index d66df947..86cc10b0 100644 --- a/openo-portal/portal-lifecyclemgr/js/gsolcm.js +++ b/openo-portal/portal-lifecyclemgr/js/gsolcm.js @@ -24,12 +24,81 @@ var lcmHandler = function(){ lcmHandler.prototype = { _addOwnEvents : function () { $('a[data-toggle="tab"]').on('show.bs.tab', this.beforeParameterTabShow); + $('#createNS').click(this.okAction); }, beforeParameterTabShow : function (event) { renderTemplateParametersTab(); + }, + okAction : function (event) { + var serviceInstance = { + serviceTemplateId: $('#svcTempl').val(), + serviceName: $('#svcName').val(), + serviceDescription: $('#svcDesc').val(), + serviceParameters: collectServiceParameters(templateParameters) + } + var s1ServiceUrl = '/openoapi/servicegateway/v1/services'; + var serviceTemplate = fetchServiceTemplateBy(serviceInstance.serviceTemplateId); + if(serviceTemplate === undefined) { + return; + } + if(serviceTemplate.csarType === 'GSAR') { + serviceInstance.serviceInstanceId = createGsoServiceInstance(s1ServiceUrl, serviceInstance); + }else if(serviceTemplate.csarType === 'NSAR' || serviceTemplate.csarType === 'NFAR') { + serviceInstance.serviceInstanceId = createNfvoServiceInstance(s1ServiceUrl, serviceInstance); + }else if(serviceTemplate.csarType === 'SSAR') { + serviceInstance.serviceInstanceId = createSdnoServiceInstance(s1ServiceUrl, serviceInstance); + } } }; +function collectServiceParameters(parameters) { + var serviceParameters = {}; + var i; + for( i = 0; i < parameters.length; i += 1) { + serviceParameters[parameters.name] = $('#' + parameters[i].id).val(); + } + return serviceParameters; +} + +function fetchServiceTemplateBy(templateId) { + var serviceTemplateUri = '/openoapi/catalog/v1/servicetemplates/'+ templateId; + var template; + $.ajax({ + type : "GET", + async: false, + url : serviceTemplateUri, + contentType : "application/json", + dataType : "json", + success : function(jsonResp) { + template = { + name: jsonResp.templateName, + gsarId: jsonResp.csarId + } + }, + error : function(xhr, ajaxOptions, thrownError) { + alert("Error on page : " + xhr.responseText); + } + }); + if(template === undefined) { + return template; + } + var queryCsarUri = '/openoapi/catalog/v1/csars/' + template.gsarId; + $.ajax({ + type : "GET", + async: false, + url : queryCsarUri, + contentType : "application/json", + dataType : "json", + success : function(jsonResp) { + template.csarType = jsonResp.type + }, + error : function(xhr, ajaxOptions, thrownError) { + alert("Error on page : " + xhr.responseText); + } + }); + return template; +} + function renderTemplateParametersTab() { templateParameters = fetchTemplateParameterDefinitions(templateParameters); var components = transfromToComponents(templateParameters.parameters); @@ -92,6 +161,14 @@ function transfromToComponents(parameters) { return components; } +function generateRequiredLabel(parameter) { + var requiredLabel = ''; + if(parameter.required === 'true') { + requiredLabel = '*'; + } + return requiredLabel; +} + function createGsoServiceInstance(s1ServiceUrl, serviceInstance) { var gsoLcmUri = '/openoapi/lifecyclemgr/v1/services'; var parameter = { -- cgit 1.2.3-korg