blob: 0bf1dbc384c6b50702b840eb9f8f3d998a6ac877 [file] [log] [blame]
lombardofdd73c0c2018-05-09 10:46:49 +02001/*
2 Copyright 2018 CNIT - Consorzio Nazionale Interuniversitario per le Telecomunicazioni
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17
18function openModalCreateNS(args) {
lombardofdd73c0c2018-05-09 10:46:49 +020019 // load vim account list
20 select2_groups = $('#vimAccountId').select2({
21 placeholder: 'Select VIM',
lombardof74ed51a2018-05-11 01:07:01 +020022 width: '100%',
lombardofdd73c0c2018-05-09 10:46:49 +020023 ajax: {
24 url: args.vim_list_url,
25 dataType: 'json',
26 processResults: function (data) {
27 vims = [];
28 if (data['datacenters']) {
29 for (d in data['datacenters']) {
30 var datacenter = data['datacenters'][d];
31 vims.push({id: datacenter['_id'], text: datacenter['name']})
32 }
33 }
34
35 return {
36 results: vims
37 };
38 }
39 }
40 });
lombardof07db64f2018-05-11 13:47:10 +020041
lombardofdd73c0c2018-05-09 10:46:49 +020042 // load nsd list
43 select2_groups = $('#nsdId').select2({
44 placeholder: 'Select NSD',
lombardof07db64f2018-05-11 13:47:10 +020045 width: '100%',
lombardofdd73c0c2018-05-09 10:46:49 +020046 ajax: {
47 url: args.nsd_list_url,
48 dataType: 'json',
49 processResults: function (data) {
50 nsd_list = [];
lombardof07db64f2018-05-11 13:47:10 +020051
52 if (data['descriptors']) {
53 for (d in data['descriptors']) {
54 var nsd = data['descriptors'][d];
lombardofdd73c0c2018-05-09 10:46:49 +020055 nsd_list.push({id: nsd['_id'], text: nsd['name']})
56 }
57 }
58
59 return {
60 results: nsd_list
61 };
62 }
63 }
64 });
lombardof07db64f2018-05-11 13:47:10 +020065
66 if(args.descriptor_id){
67 // Set the value, creating a new option if necessary
68 if ($('#nsdId').find("option[value='" + args.descriptor_id + "']").length) {
69 $('#nsdId').val(args.descriptor_id).trigger('change');
70 } else {
71 // Create a DOM Option and pre-select by default
72 var newOption = new Option(args.descriptor_name, args.descriptor_id, true, true);
73 // Append it to the select
74 $('#nsdId').append(newOption).trigger('change');
75 }
76 }
77
lombardofdd73c0c2018-05-09 10:46:49 +020078 $('#modal_new_instance').modal('show');
79}