blob: 47cba12a216eb0e138928353ca2c398f9d96e571 [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
lombardofdd73c0c2018-05-09 10:46:49 +020017function openModalCreateNS(args) {
lombardofdd73c0c2018-05-09 10:46:49 +020018 // load vim account list
19 select2_groups = $('#vimAccountId').select2({
20 placeholder: 'Select VIM',
lombardof74ed51a2018-05-11 01:07:01 +020021 width: '100%',
lombardofdd73c0c2018-05-09 10:46:49 +020022 ajax: {
23 url: args.vim_list_url,
24 dataType: 'json',
25 processResults: function (data) {
26 vims = [];
27 if (data['datacenters']) {
28 for (d in data['datacenters']) {
29 var datacenter = data['datacenters'][d];
30 vims.push({id: datacenter['_id'], text: datacenter['name']})
31 }
32 }
33
34 return {
35 results: vims
36 };
37 }
38 }
39 });
lombardof07db64f2018-05-11 13:47:10 +020040
lombardofdd73c0c2018-05-09 10:46:49 +020041 // load nsd list
42 select2_groups = $('#nsdId').select2({
43 placeholder: 'Select NSD',
lombardof07db64f2018-05-11 13:47:10 +020044 width: '100%',
lombardofdd73c0c2018-05-09 10:46:49 +020045 ajax: {
46 url: args.nsd_list_url,
47 dataType: 'json',
48 processResults: function (data) {
49 nsd_list = [];
lombardof07db64f2018-05-11 13:47:10 +020050
51 if (data['descriptors']) {
52 for (d in data['descriptors']) {
53 var nsd = data['descriptors'][d];
lombardofdd73c0c2018-05-09 10:46:49 +020054 nsd_list.push({id: nsd['_id'], text: nsd['name']})
55 }
56 }
57
58 return {
59 results: nsd_list
60 };
61 }
62 }
63 });
lombardof07db64f2018-05-11 13:47:10 +020064
lombardofr1e320062018-10-30 22:16:25 +010065 if (args.descriptor_id) {
lombardof07db64f2018-05-11 13:47:10 +020066 // Set the value, creating a new option if necessary
67 if ($('#nsdId').find("option[value='" + args.descriptor_id + "']").length) {
68 $('#nsdId').val(args.descriptor_id).trigger('change');
69 } else {
70 // Create a DOM Option and pre-select by default
71 var newOption = new Option(args.descriptor_name, args.descriptor_id, true, true);
72 // Append it to the select
73 $('#nsdId').append(newOption).trigger('change');
74 }
75 }
76
lombardofdd73c0c2018-05-09 10:46:49 +020077 $('#modal_new_instance').modal('show');
78}