blob: 124fb05ef3f0416d3bfb30e2712a9ecccd9db91a [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
lombardofr6060dd62019-05-19 12:31:07 +020017
lombardofrb58d5d82019-01-04 15:25:45 +010018function openModalCreatePDU(args) {
19 var select2_groups = $('#pdu_vim_accounts').select2({
20 placeholder: 'Select Vims',
21 width: '100%',
22 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 return {
34 results: vims
35 };
36 }
37 }
38 });
39
40 $('#modal_new_pdu').modal('show');
41}
42
lombardofdd73c0c2018-05-09 10:46:49 +020043function openModalCreateNS(args) {
lombardofdd73c0c2018-05-09 10:46:49 +020044 // load vim account list
45 select2_groups = $('#vimAccountId').select2({
46 placeholder: 'Select VIM',
lombardof74ed51a2018-05-11 01:07:01 +020047 width: '100%',
lombardofdd73c0c2018-05-09 10:46:49 +020048 ajax: {
49 url: args.vim_list_url,
50 dataType: 'json',
51 processResults: function (data) {
52 vims = [];
53 if (data['datacenters']) {
54 for (d in data['datacenters']) {
55 var datacenter = data['datacenters'][d];
lombardofrb58d5d82019-01-04 15:25:45 +010056 vims.push({ id: datacenter['_id'], text: datacenter['name'] })
lombardofdd73c0c2018-05-09 10:46:49 +020057 }
58 }
59
60 return {
61 results: vims
62 };
63 }
64 }
65 });
lombardof07db64f2018-05-11 13:47:10 +020066
lombardofdd73c0c2018-05-09 10:46:49 +020067 // load nsd list
68 select2_groups = $('#nsdId').select2({
69 placeholder: 'Select NSD',
lombardof07db64f2018-05-11 13:47:10 +020070 width: '100%',
lombardofdd73c0c2018-05-09 10:46:49 +020071 ajax: {
72 url: args.nsd_list_url,
73 dataType: 'json',
74 processResults: function (data) {
75 nsd_list = [];
lombardof07db64f2018-05-11 13:47:10 +020076
77 if (data['descriptors']) {
78 for (d in data['descriptors']) {
79 var nsd = data['descriptors'][d];
lombardofrb58d5d82019-01-04 15:25:45 +010080 nsd_list.push({ id: nsd['_id'], text: nsd['name'] })
lombardofdd73c0c2018-05-09 10:46:49 +020081 }
82 }
83
84 return {
85 results: nsd_list
86 };
87 }
88 }
89 });
lombardof07db64f2018-05-11 13:47:10 +020090
lombardofr1e320062018-10-30 22:16:25 +010091 if (args.descriptor_id) {
lombardof07db64f2018-05-11 13:47:10 +020092 // Set the value, creating a new option if necessary
93 if ($('#nsdId').find("option[value='" + args.descriptor_id + "']").length) {
94 $('#nsdId').val(args.descriptor_id).trigger('change');
95 } else {
96 // Create a DOM Option and pre-select by default
97 var newOption = new Option(args.descriptor_name, args.descriptor_id, true, true);
98 // Append it to the select
99 $('#nsdId').append(newOption).trigger('change');
100 }
101 }
102
lombardofdd73c0c2018-05-09 10:46:49 +0200103 $('#modal_new_instance').modal('show');
lombardofrcf3a1f02019-01-21 15:43:52 +0100104}
105function openModalCreateNSI(args) {
106 // load vim account list
107 select2_groups = $('#vimAccountIdNSI').select2({
108 placeholder: 'Select VIM',
109 width: '100%',
110 ajax: {
111 url: args.vim_list_url,
112 dataType: 'json',
113 processResults: function (data) {
114 vims = [];
115 if (data['datacenters']) {
116 for (d in data['datacenters']) {
117 var datacenter = data['datacenters'][d];
118 vims.push({ id: datacenter['_id'], text: datacenter['name'] })
119 }
120 }
121
122 return {
123 results: vims
124 };
125 }
126 }
127 });
128
129 // load nsd list
130 select2_groups = $('#nstId').select2({
131 placeholder: 'Select NST',
132 width: '100%',
133 ajax: {
134 url: args.nst_list_url,
135 dataType: 'json',
136 processResults: function (data) {
137 nst_list = [];
138
139 if (data['templates']) {
140 for (d in data['templates']) {
141 var nst = data['templates'][d];
142 nst_list.push({ id: nst['_id'], text: nst['name'] })
143 }
144 }
145
146 return {
147 results: nst_list
148 };
149 }
150 }
151 });
lombardofr478c2a82019-01-29 17:19:28 +0100152 if (args.template_id) {
lombardofrcf3a1f02019-01-21 15:43:52 +0100153 // Set the value, creating a new option if necessary
lombardofr478c2a82019-01-29 17:19:28 +0100154 if ($('#nstId').find("option[value='" + args.template_id + "']").length) {
155 $('#nstId').val(args.template_id).trigger('change');
lombardofrcf3a1f02019-01-21 15:43:52 +0100156 } else {
157 // Create a DOM Option and pre-select by default
lombardofr478c2a82019-01-29 17:19:28 +0100158 var newOption = new Option(args.template_name, args.template_id, true, true);
lombardofrcf3a1f02019-01-21 15:43:52 +0100159 // 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}