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