47cba12a216eb0e138928353ca2c398f9d96e571
[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 openModalCreateNS(args) {
18 // load vim account list
19 select2_groups = $('#vimAccountId').select2({
20 placeholder: 'Select VIM',
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
34 return {
35 results: vims
36 };
37 }
38 }
39 });
40
41 // load nsd list
42 select2_groups = $('#nsdId').select2({
43 placeholder: 'Select NSD',
44 width: '100%',
45 ajax: {
46 url: args.nsd_list_url,
47 dataType: 'json',
48 processResults: function (data) {
49 nsd_list = [];
50
51 if (data['descriptors']) {
52 for (d in data['descriptors']) {
53 var nsd = data['descriptors'][d];
54 nsd_list.push({id: nsd['_id'], text: nsd['name']})
55 }
56 }
57
58 return {
59 results: nsd_list
60 };
61 }
62 }
63 });
64
65 if (args.descriptor_id) {
66 // 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
77 $('#modal_new_instance').modal('show');
78 }