X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=static%2Fsrc%2Finstancehandler%2Finstance_list.js;h=db22bc26b03e4b574d03c185c3350f2e0e48aff5;hb=e59fb021913a2160fac39f487c05faa1efe15b70;hp=161cc51bcda803a1432ba6e7793968e260450a3d;hpb=fb37bca4b7e8178c65df2f1496afe372c1d55e78;p=osm%2FLW-UI.git diff --git a/static/src/instancehandler/instance_list.js b/static/src/instancehandler/instance_list.js index 161cc51..db22bc2 100644 --- a/static/src/instancehandler/instance_list.js +++ b/static/src/instancehandler/instance_list.js @@ -14,15 +14,126 @@ limitations under the License. */ -function performAction(url) { +function performAction(instance_name, instance_id) { + var url = '/instances/ns/'+instance_id+'/action'; $("#formActionNS").attr("action", url); $('#modal_instance_new_action').modal('show'); } -function deleteNs(url) { - bootbox.confirm("Are you sure want to delete?", function (result) { +function deleteNs(instance_name, instance_id, force) { + var url = '/instances/ns/'+instance_id+'/delete'; + bootbox.confirm("Are you sure want to delete " + instance_name + "?", function (result) { if (result) { - location.href = url + if (force) + url = url + '?force=true'; + var dialog = bootbox.dialog({ + message: '
Loading...
', + closeButton: true + }); + $.ajax({ + url: url, + type: 'GET', + dataType: "json", + contentType: "application/json;charset=utf-8", + success: function (result) { + if (result['error'] == true){ + dialog.modal('hide'); + bootbox.alert("An error occurred."); + } + else { + dialog.modal('hide'); + table.ajax.reload(); + } + }, + error: function (result) { + dialog.modal('hide'); + var data = result.responseJSON; + var title = "Error " + (data && data.code ? data.code : 'unknown'); + var message = data && data.detail ? data.detail : 'No detail available.'; + bootbox.alert({ + title: title, + message: message + }); + } + }); + } + }) +} +function deleteNsi(instance_name, instance_id, force) { + var url = '/instances/nsi/'+instance_id+'/delete'; + bootbox.confirm("Are you sure want to delete " + instance_name + "?", function (result) { + if (result) { + if (force) + url = url + '?force=true'; + var dialog = bootbox.dialog({ + message: '
Loading...
', + closeButton: true + }); + $.ajax({ + url: url, + type: 'GET', + dataType: "json", + contentType: "application/json;charset=utf-8", + success: function (result) { + console.log(result) + if (result['error'] == true){ + dialog.modal('hide'); + var data = result.responseJSON; + var title = "Error " + (data && data.code ? data.code : 'unknown'); + var message = data && data.detail ? data.detail : 'No detail available.'; + bootbox.alert({ + title: title, + message: message + }); + } + else { + dialog.modal('hide'); + table.ajax.reload(); + } + }, + error: function (result) { + dialog.modal('hide'); + var data = result.responseJSON; + var title = "Error " + (data && data.code ? data.code : 'unknown'); + var message = data && data.detail ? data.detail : 'No detail available.'; + bootbox.alert({ + title: title, + message: message + }); + } + }); + } + }) +} + +function deletePDU(instance_name, instance_id) { + var url = '/instances/pdu/'+instance_id+'/delete'; + bootbox.confirm("Are you sure want to delete " + instance_name + "?", function (result) { + if (result) { + var dialog = bootbox.dialog({ + message: '
Loading...
', + closeButton: true + }); + $.ajax({ + url: url, + type: 'GET', + dataType: "json", + contentType: "application/json;charset=utf-8", + success: function (result) { + if (result['error'] == true){ + dialog.modal('hide'); + bootbox.alert("An error occurred."); + } + else { + dialog.modal('hide'); + table.ajax.reload(); + } + }, + error: function (error) { + dialog.modal('hide'); + bootbox.alert("An error occurred."); + } + }); } }) } @@ -33,6 +144,25 @@ var addFormGroup = function (event) { var $formGroup = $(this).closest('.form-group'); var $formGroupClone = $formGroup.clone(); + $formGroupClone.find('input').val(''); + $formGroupClone.find('button').toggleClass('btn-success btn-add btn-danger btn-remove'); + $formGroupClone.find('button').text('–'); + $formGroupClone.insertAfter($formGroup); + +}; + +var removeFormGroup = function (event) { + event.preventDefault(); + var $formGroup = $(this).closest('.form-group'); + $formGroup.remove(); +}; + +var addInterfaceGroup = function (event) { + event.preventDefault(); + + var $formGroup = $(this).closest('.interface-group'); + var $formGroupClone = $formGroup.clone(); + $(this) .toggleClass('btn-success btn-add btn-danger btn-remove') .html('–'); @@ -42,13 +172,19 @@ var addFormGroup = function (event) { }; -var removeFormGroup = function (event) { +var removeInterfaceGroup = function (event) { event.preventDefault(); - var $formGroup = $(this).closest('.form-group'); + var $formGroup = $(this).closest('.interface-group'); $formGroup.remove(); }; -function showInstanceDetails(url_info) { +function showTopology(type, instance_id) { + var url = '/instances/'+type+'/'+instance_id+'/topology'; + window.location = url; +} + +function showInstanceDetails(type, instance_id) { + var url_info = '/instances/'+type+'/'+instance_id; var dialog = bootbox.dialog({ message: '
Loading...
', closeButton: true @@ -59,14 +195,21 @@ function showInstanceDetails(url_info) { dataType: "json", contentType: "application/json;charset=utf-8", success: function (result) { - editorJSON.setValue(JSON.stringify(result, null, "\t")); - editorJSON.setOption("autoRefresh", true); - dialog.modal('hide'); - $('#modal_show_instance').modal('show'); + + if (result['data'] !== undefined) { + editorJSON.setValue(JSON.stringify(result['data'], null, "\t")); + editorJSON.setOption("autoRefresh", true); + dialog.modal('hide'); + $('#modal_show_instance').modal('show'); + } + else { + dialog.modal('hide'); + bootbox.alert("An error occurred while retrieving the information."); + } }, error: function (result) { dialog.modal('hide'); - bootbox.alert("An error occurred while retrieving the information for the NS"); + bootbox.alert("An error occurred while retrieving the information."); } }); } @@ -104,8 +247,68 @@ $(document).ready(function () { }, json_editor_settings); - $(document).on('click', '.btn-add', addFormGroup); - $(document).on('click', '.btn-remove', removeFormGroup); + $(document).on('click', '.primitive-group .btn-add', addFormGroup); + $(document).on('click', '.primitive-group .btn-remove', removeFormGroup); + + $(document).on('click', '.interface-group .btn-add', addInterfaceGroup); + $(document).on('click', '.interface-group .btn-remove', removeInterfaceGroup); + + + $("#formCreateNS").submit(function (event) { + event.preventDefault(); //prevent default action + var post_url = $(this).attr("action"); //get form action url + var request_method = $(this).attr("method"); //get form GET/POST method + var form_data = new FormData(this); //Encode form elements for submission + $.ajax({ + url: post_url, + type: request_method, + data: form_data, + headers: { + "Accept": 'application/json' + }, + contentType: false, + processData: false + }).done(function (response, textStatus, jqXHR) { + table.ajax.reload(); + $('#modal_new_instance').modal('hide'); + }).fail(function (result) { + var data = result.responseJSON; + var title = "Error " + (data.code ? data.code : 'unknown'); + var message = data.detail ? data.detail : 'No detail available.'; + bootbox.alert({ + title: title, + message: message + }); + }); + }); + + $("#formCreatePDU").submit(function (event) { + event.preventDefault(); //prevent default action + var post_url = $(this).attr("action"); //get form action url + var request_method = $(this).attr("method"); //get form GET/POST method + var form_data = new FormData(this); //Encode form elements for submission + $.ajax({ + url: post_url, + type: request_method, + data: form_data, + headers: { + "Accept": 'application/json' + }, + contentType: false, + processData: false + }).done(function (response, textStatus, jqXHR) { + table.ajax.reload(); + $('#modal_new_pdu').modal('hide'); + }).fail(function (result) { + var data = result.responseJSON; + var title = "Error " + (data.code ? data.code : 'unknown'); + var message = data.detail ? data.detail : 'No detail available.'; + bootbox.alert({ + title: title, + message: message + }); + }); + }); $("#formActionNS").submit(function (event) { event.preventDefault(); //prevent default action @@ -122,16 +325,20 @@ $(document).ready(function () { }, contentType: false, processData: false - }).done(function (response,textStatus, jqXHR) { + }).done(function (response, textStatus, jqXHR) { $('#modal_instance_new_action').modal('hide'); - }).fail(function(result){ - var data = result.responseJSON; - var title = "Error " + (data.code ? data.code: 'unknown'); - var message = data.detail ? data.detail: 'No detail available.'; - bootbox.alert({ - title: title, - message: message - }); + bootbox.alert({ + title: "Action", + message: "Action received." + }); + }).fail(function (result) { + var data = result.responseJSON; + var title = "Error " + (data.code ? data.code : 'unknown'); + var message = data.detail ? data.detail : 'No detail available.'; + bootbox.alert({ + title: title, + message: message + }); }); });