0bf1dbc384c6b50702b840eb9f8f3d998a6ac877
[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 openModalCreateNS(args) {
19 // load vim account list
20 select2_groups = $('#vimAccountId').select2({
21 placeholder: 'Select VIM',
22 width: '100%',
23 ajax: {
24 url: args.vim_list_url,
25 dataType: 'json',
26 processResults: function (data) {
27 vims = [];
28 if (data['datacenters']) {
29 for (d in data['datacenters']) {
30 var datacenter = data['datacenters'][d];
31 vims.push({id: datacenter['_id'], text: datacenter['name']})
32 }
33 }
34
35 return {
36 results: vims
37 };
38 }
39 }
40 });
41
42 // load nsd list
43 select2_groups = $('#nsdId').select2({
44 placeholder: 'Select NSD',
45 width: '100%',
46 ajax: {
47 url: args.nsd_list_url,
48 dataType: 'json',
49 processResults: function (data) {
50 nsd_list = [];
51
52 if (data['descriptors']) {
53 for (d in data['descriptors']) {
54 var nsd = data['descriptors'][d];
55 nsd_list.push({id: nsd['_id'], text: nsd['name']})
56 }
57 }
58
59 return {
60 results: nsd_list
61 };
62 }
63 }
64 });
65
66 if(args.descriptor_id){
67 // Set the value, creating a new option if necessary
68 if ($('#nsdId').find("option[value='" + args.descriptor_id + "']").length) {
69 $('#nsdId').val(args.descriptor_id).trigger('change');
70 } else {
71 // Create a DOM Option and pre-select by default
72 var newOption = new Option(args.descriptor_name, args.descriptor_id, true, true);
73 // Append it to the select
74 $('#nsdId').append(newOption).trigger('change');
75 }
76 }
77
78 $('#modal_new_instance').modal('show');
79 }