| lombardof | dd73c0c | 2018-05-09 10:46:49 +0200 | [diff] [blame] | 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 | |
| lombardof | dd73c0c | 2018-05-09 10:46:49 +0200 | [diff] [blame] | 17 | function openModalCreateNS(args) { |
| lombardof | dd73c0c | 2018-05-09 10:46:49 +0200 | [diff] [blame] | 18 | // load vim account list |
| 19 | select2_groups = $('#vimAccountId').select2({ |
| 20 | placeholder: 'Select VIM', |
| lombardof | 74ed51a | 2018-05-11 01:07:01 +0200 | [diff] [blame] | 21 | width: '100%', |
| lombardof | dd73c0c | 2018-05-09 10:46:49 +0200 | [diff] [blame] | 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 | }); |
| lombardof | 07db64f | 2018-05-11 13:47:10 +0200 | [diff] [blame] | 40 | |
| lombardof | dd73c0c | 2018-05-09 10:46:49 +0200 | [diff] [blame] | 41 | // load nsd list |
| 42 | select2_groups = $('#nsdId').select2({ |
| 43 | placeholder: 'Select NSD', |
| lombardof | 07db64f | 2018-05-11 13:47:10 +0200 | [diff] [blame] | 44 | width: '100%', |
| lombardof | dd73c0c | 2018-05-09 10:46:49 +0200 | [diff] [blame] | 45 | ajax: { |
| 46 | url: args.nsd_list_url, |
| 47 | dataType: 'json', |
| 48 | processResults: function (data) { |
| 49 | nsd_list = []; |
| lombardof | 07db64f | 2018-05-11 13:47:10 +0200 | [diff] [blame] | 50 | |
| 51 | if (data['descriptors']) { |
| 52 | for (d in data['descriptors']) { |
| 53 | var nsd = data['descriptors'][d]; |
| lombardof | dd73c0c | 2018-05-09 10:46:49 +0200 | [diff] [blame] | 54 | nsd_list.push({id: nsd['_id'], text: nsd['name']}) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | return { |
| 59 | results: nsd_list |
| 60 | }; |
| 61 | } |
| 62 | } |
| 63 | }); |
| lombardof | 07db64f | 2018-05-11 13:47:10 +0200 | [diff] [blame] | 64 | |
| lombardofr | 1e32006 | 2018-10-30 22:16:25 +0100 | [diff] [blame^] | 65 | if (args.descriptor_id) { |
| lombardof | 07db64f | 2018-05-11 13:47:10 +0200 | [diff] [blame] | 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 | |
| lombardof | dd73c0c | 2018-05-09 10:46:49 +0200 | [diff] [blame] | 77 | $('#modal_new_instance').modal('show'); |
| 78 | } |