blob: 3cce0c4401596881d349669863c7333891d5ad5d [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
lombardofrb58d5d82019-01-04 15:25:45 +010017function openModalCreatePDU(args) {
18 var select2_groups = $('#pdu_vim_accounts').select2({
19 placeholder: 'Select Vims',
20 width: '100%',
21 ajax: {
22 url: args.vim_list_url,
23 dataType: 'json',
24 processResults: function (data) {
25 vims = [];
26 if (data['datacenters']) {
27 for (d in data['datacenters']) {
28 var datacenter = data['datacenters'][d];
29 vims.push({ id: datacenter['_id'], text: datacenter['name'] })
30 }
31 }
32 return {
33 results: vims
34 };
35 }
36 }
37 });
38
39 $('#modal_new_pdu').modal('show');
40}
41
lombardofdd73c0c2018-05-09 10:46:49 +020042function openModalCreateNS(args) {
lombardofdd73c0c2018-05-09 10:46:49 +020043 // load vim account list
44 select2_groups = $('#vimAccountId').select2({
45 placeholder: 'Select VIM',
lombardof74ed51a2018-05-11 01:07:01 +020046 width: '100%',
lombardofdd73c0c2018-05-09 10:46:49 +020047 ajax: {
48 url: args.vim_list_url,
49 dataType: 'json',
50 processResults: function (data) {
51 vims = [];
52 if (data['datacenters']) {
53 for (d in data['datacenters']) {
54 var datacenter = data['datacenters'][d];
lombardofrb58d5d82019-01-04 15:25:45 +010055 vims.push({ id: datacenter['_id'], text: datacenter['name'] })
lombardofdd73c0c2018-05-09 10:46:49 +020056 }
57 }
58
59 return {
60 results: vims
61 };
62 }
63 }
64 });
lombardof07db64f2018-05-11 13:47:10 +020065
lombardofdd73c0c2018-05-09 10:46:49 +020066 // load nsd list
67 select2_groups = $('#nsdId').select2({
68 placeholder: 'Select NSD',
lombardof07db64f2018-05-11 13:47:10 +020069 width: '100%',
lombardofdd73c0c2018-05-09 10:46:49 +020070 ajax: {
71 url: args.nsd_list_url,
72 dataType: 'json',
73 processResults: function (data) {
74 nsd_list = [];
lombardof07db64f2018-05-11 13:47:10 +020075
76 if (data['descriptors']) {
77 for (d in data['descriptors']) {
78 var nsd = data['descriptors'][d];
lombardofrb58d5d82019-01-04 15:25:45 +010079 nsd_list.push({ id: nsd['_id'], text: nsd['name'] })
lombardofdd73c0c2018-05-09 10:46:49 +020080 }
81 }
82
83 return {
84 results: nsd_list
85 };
86 }
87 }
88 });
lombardof07db64f2018-05-11 13:47:10 +020089
lombardofr1e320062018-10-30 22:16:25 +010090 if (args.descriptor_id) {
lombardof07db64f2018-05-11 13:47:10 +020091 // Set the value, creating a new option if necessary
92 if ($('#nsdId').find("option[value='" + args.descriptor_id + "']").length) {
93 $('#nsdId').val(args.descriptor_id).trigger('change');
94 } else {
95 // Create a DOM Option and pre-select by default
96 var newOption = new Option(args.descriptor_name, args.descriptor_id, true, true);
97 // Append it to the select
98 $('#nsdId').append(newOption).trigger('change');
99 }
100 }
101
lombardofdd73c0c2018-05-09 10:46:49 +0200102 $('#modal_new_instance').modal('show');
lombardofrcf3a1f02019-01-21 15:43:52 +0100103}
104function openModalCreateNSI(args) {
105 // load vim account list
106 select2_groups = $('#vimAccountIdNSI').select2({
107 placeholder: 'Select VIM',
108 width: '100%',
109 ajax: {
110 url: args.vim_list_url,
111 dataType: 'json',
112 processResults: function (data) {
113 vims = [];
114 if (data['datacenters']) {
115 for (d in data['datacenters']) {
116 var datacenter = data['datacenters'][d];
117 vims.push({ id: datacenter['_id'], text: datacenter['name'] })
118 }
119 }
120
121 return {
122 results: vims
123 };
124 }
125 }
126 });
127
128 // load nsd list
129 select2_groups = $('#nstId').select2({
130 placeholder: 'Select NST',
131 width: '100%',
132 ajax: {
133 url: args.nst_list_url,
134 dataType: 'json',
135 processResults: function (data) {
136 nst_list = [];
137
138 if (data['templates']) {
139 for (d in data['templates']) {
140 var nst = data['templates'][d];
141 nst_list.push({ id: nst['_id'], text: nst['name'] })
142 }
143 }
144
145 return {
146 results: nst_list
147 };
148 }
149 }
150 });
151
152 if (args.descriptor_id) {
153 // Set the value, creating a new option if necessary
154 if ($('#nstId').find("option[value='" + args.descriptor_id + "']").length) {
155 $('#nstId').val(args.descriptor_id).trigger('change');
156 } else {
157 // Create a DOM Option and pre-select by default
158 var newOption = new Option(args.descriptor_name, args.descriptor_id, true, true);
159 // Append it to the select
160 $('#nstId').append(newOption).trigger('change');
161 }
162 }
163
164 $('#modal_new_nsi').modal('show');
lombardofdd73c0c2018-05-09 10:46:49 +0200165}