[wip] NS instance topology view
[osm/LW-UI.git] / static / src / instancehandler / instance_list.js
index b4c0edc..a2c2003 100644 (file)
    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 exportMetricNs(url) {
-    console.log(url)
+function exportMetricNs(instance_name, instance_id) {
+    var url = '/instances/ns/'+instance_id+'/monitoring/metric';
     $("#formExportMetricNS").attr("action", url);
     $('#modal_instance_export_metric').modal('show');
 }
 
-function newAlarmNs(url) {
+function newAlarmNs(instance_name, instance_id) {
+    var url = '/instances/ns/'+instance_id+'/monitoring/alarm';
     $("#formAlarmNS").attr("action", url);
     $('#modal_instance_new_alarm').modal('show');
 }
 
-function deleteNs(url, force) {
-    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) {
-            if(force)
+            if (force)
                 url = url + '?force=true';
-            location.href = url
+            var dialog = bootbox.dialog({
+                message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
+                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');
+                        location.reload();
+                    }
+                },
+                error: function (error) {
+                    dialog.modal('hide');
+                    bootbox.alert("An error occurred.");
+                }
+            });
         }
     })
 }
@@ -61,7 +87,13 @@ var removeFormGroup = function (event) {
     $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: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
         closeButton: true
@@ -72,10 +104,17 @@ 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');
@@ -135,20 +174,20 @@ $(document).ready(function () {
             },
             contentType: false,
             processData: false
-        }).done(function (response,textStatus, jqXHR) {
+        }).done(function (response, textStatus, jqXHR) {
             $('#modal_instance_new_action').modal('hide');
             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
-                });
+                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
+            });
         });
     });
 
@@ -167,20 +206,20 @@ $(document).ready(function () {
             },
             contentType: false,
             processData: false
-        }).done(function (response,textStatus, jqXHR) {
+        }).done(function (response, textStatus, jqXHR) {
             $('#modal_instance_new_action').modal('hide');
             bootbox.alert({
-                    title: "Metric",
-                    message: "Alarm created."
-                });
-        }).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
-                });
+                title: "Metric",
+                message: "Alarm created."
+            });
+        }).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
+            });
         });
     });
 
@@ -199,20 +238,20 @@ $(document).ready(function () {
             },
             contentType: false,
             processData: false
-        }).done(function (response,textStatus, jqXHR) {
+        }).done(function (response, textStatus, jqXHR) {
             $('#modal_instance_new_action').modal('hide');
             bootbox.alert({
-                    title: "Metric",
-                    message: "Metric exported."
-                });
-        }).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
-                });
+                title: "Metric",
+                message: "Metric exported."
+            });
+        }).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
+            });
         });
     });