fd6ecfa09d6ecb90189a78f19971b6866da2d462
[osm/LW-UI.git] / static / src / instancehandler / instance_create.js
1 /*
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 function 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
42 function openModalCreateNS(args) {
43 // load vim account list
44 select2_groups = $('#vimAccountId').select2({
45 placeholder: 'Select VIM',
46 width: '100%',
47 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];
55 vims.push({ id: datacenter['_id'], text: datacenter['name'] })
56 }
57 }
58
59 return {
60 results: vims
61 };
62 }
63 }
64 });
65
66 // load nsd list
67 select2_groups = $('#nsdId').select2({
68 placeholder: 'Select NSD',
69 width: '100%',
70 ajax: {
71 url: args.nsd_list_url,
72 dataType: 'json',
73 processResults: function (data) {
74 nsd_list = [];
75
76 if (data['descriptors']) {
77 for (d in data['descriptors']) {
78 var nsd = data['descriptors'][d];
79 nsd_list.push({ id: nsd['_id'], text: nsd['name'] })
80 }
81 }
82
83 return {
84 results: nsd_list
85 };
86 }
87 }
88 });
89
90 if (args.descriptor_id) {
91 // 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
102 $('#modal_new_instance').modal('show');
103 }
104 function 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 if (args.template_id) {
152 // Set the value, creating a new option if necessary
153 if ($('#nstId').find("option[value='" + args.template_id + "']").length) {
154 $('#nstId').val(args.template_id).trigger('change');
155 } else {
156 // Create a DOM Option and pre-select by default
157 var newOption = new Option(args.template_name, args.template_id, true, true);
158 // Append it to the select
159 $('#nstId').append(newOption).trigger('change');
160 }
161 }
162
163 $('#modal_new_nsi').modal('show');
164 }