pdu: list, create, show, delete
[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 }