Detail view/instances section: Fix context, add makeDefault action

-Add 'makeDefault' action to set default NIC

-Fix context passing for multi-actions, which wasn't passing the correct
 nic object previously.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/86a9f276
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/86a9f276
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/86a9f276

Branch: refs/heads/internallb
Commit: 86a9f276924b4df3316b72d17ef3bee7c272297e
Parents: ab245f5
Author: Brian Federle <[email protected]>
Authored: Fri Apr 26 15:21:34 2013 -0700
Committer: Brian Federle <[email protected]>
Committed: Fri Apr 26 15:21:57 2013 -0700

----------------------------------------------------------------------
 ui/scripts/instances.js             |   77 ++++++++++++++++++++++--------
 ui/scripts/ui/widgets/detailView.js |   34 +++++++++----
 2 files changed, 80 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/86a9f276/ui/scripts/instances.js
----------------------------------------------------------------------
diff --git a/ui/scripts/instances.js b/ui/scripts/instances.js
index a3b8abb..751c360 100644
--- a/ui/scripts/instances.js
+++ b/ui/scripts/instances.js
@@ -1490,6 +1490,35 @@
                 notification: { poll: pollAsyncJobResult }
               },
 
+              makeDefault: {
+                label: 'Set default NIC',
+                messages: {
+                  confirm: function() {
+                    return 'Please confirm that you would like to make this 
NIC the default for this VM.';
+                  },
+                  notification: function(args) {
+                    return 'Set default NIC'
+                  }
+                },
+                action: function (args) {
+                  $.ajax({
+                    url: createURL('updateDefaultNicForVirtualMachine'),
+                    data: {
+                      virtualmachineid: args.context.instances[0].id,
+                      nicid: args.context.nics[0].id
+                    },
+                    success: function(json) {
+                      args.response.success({
+                        _custom: { jobId: 
json.updatedefaultnicforvirtualmachineresponse.jobid }
+                      });
+                    }
+                  });
+                },
+                notification: {
+                  poll: pollAsyncJobResult
+                }
+              },
+
               // Remove NIC/Network from VM
               remove: {
                 label: 'label.action.delete.nic',
@@ -1506,7 +1535,7 @@
                     url: createURL('removeNicFromVirtualMachine'),
                     data: {
                       virtualmachineid: args.context.instances[0].id,
-                      nicid: args.context.nics.id
+                      nicid: args.context.nics[0].id
                     },
                     success: function(json) {
                       args.response.success({
@@ -1522,6 +1551,7 @@
             },
             fields: [
               {
+                id: { label: 'ID' },
                 name: { label: 'label.name', header: true },
                 networkname: {label: 'Network Name' },
                 type: { label: 'label.type' },
@@ -1551,26 +1581,33 @@
               }
             },
             dataProvider: function(args) {
-                    $.ajax({
-                     url:createURL("listVirtualMachines&details=nics&id=" + 
args.context.instances[0].id),
-                     dataType: "json",
-                     async:true,
-                     success:function(json) {
-                     // Handling the display of network name for a VM under 
the NICS tabs
-                     args.response.success({
-                     data: 
$.map(json.listvirtualmachinesresponse.virtualmachine[0].nic, function(nic, 
index) {
-                     var name = 'NIC ' + (index + 1);                    
-                     if (nic.isdefault) {
-                          name += ' (' + _l('label.default') + ')';
-                          }
-                     return $.extend(nic, {
+              $.ajax({
+                url:createURL("listVirtualMachines&details=nics&id=" + 
args.context.instances[0].id),
+                dataType: "json",
+                async:true,
+                success:function(json) {
+                  // Handling the display of network name for a VM under the 
NICS tabs
+                  args.response.success({
+                    actionFilter: function(args) {
+                      if (args.context.item.isdefault) {
+                        return [];
+                      } else {
+                        return ['remove', 'makeDefault'];
+                      }
+                    },
+                    data: 
$.map(json.listvirtualmachinesresponse.virtualmachine[0].nic, function(nic, 
index) {
+                      var name = 'NIC ' + (index + 1);
+                      if (nic.isdefault) {
+                        name += ' (' + _l('label.default') + ')';
+                      }
+                      return $.extend(nic, {
                         name: name
-                               });
-                            })
-                        });
-                     }
-                });
-              }
+                      });
+                    })
+                  });
+                }
+              });
+            }
           },
 
            /**

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/86a9f276/ui/scripts/ui/widgets/detailView.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui/widgets/detailView.js 
b/ui/scripts/ui/widgets/detailView.js
index ea6c3a2..122953a 100644
--- a/ui/scripts/ui/widgets/detailView.js
+++ b/ui/scripts/ui/widgets/detailView.js
@@ -70,7 +70,7 @@
             action.notification : {};
       var messages = action.messages;
       var id = args.id;
-      var context = $detailView.data('view-args').context;
+      var context = args.context ? args.context : 
$detailView.data('view-args').context;
       var _custom = $detailView.data('_custom');
       var customAction = action.action.custom;
       var noAdd = action.noAdd;
@@ -180,7 +180,7 @@
             data: data,
             _custom: _custom,
             ref: options.ref,
-            context: $detailView.data('view-args').context,
+            context: context,
             $form: $form,
             response: {
               success: function(args) {
@@ -288,14 +288,14 @@
             after: function(args) {
               performAction(args.data, {
                 ref: args.ref,
-                context: $detailView.data('view-args').context,
+                context: context,
                 $form: args.$form
               });
             },
             ref: {
               id: id
             },
-            context: $detailView.data('view-args').context
+            context: context
           });
         }
       }
@@ -308,7 +308,7 @@
       uiActions.standard($detailView, args, {
         noRefresh: true,
         complete: function(args) {
-          if (isMultiple) {
+          if (isMultiple && $detailView.is(':visible')) {
             $detailView.find('.refresh').click(); // Reload tab
           } else {
             var $browser = $('#browser .container');
@@ -790,12 +790,13 @@
     var detailViewArgs = $detailView.data('view-args');
     var fields = tabData.fields;
     var hiddenFields;
-    var context = detailViewArgs ? detailViewArgs.context : cloudStack.context;
+    var context = $.extend(true, {}, detailViewArgs ? detailViewArgs.context : 
cloudStack.context);
     var isMultiple = tabData.multiple || tabData.isMultiple;
     var actions = tabData.actions;
 
     if (isMultiple) {
-      context[tabData.id] = data;
+      context[tabData.id] = [data];
+      $detailGroups.data('item-context', context);
     }
 
     // Make header
@@ -1087,7 +1088,11 @@
                         tabData.viewAll.path,
                         {
                           updateContext: function(args) {
-                            return { nics: [item] };
+                            var obj = {};
+
+                            obj[targetTabID] = [item];
+
+                            return obj;
                           },
                           title: tabData.viewAll.title
                         }
@@ -1099,9 +1104,11 @@
               // Add action bar
               if (tabData.multiple && tabData.actions) {
                 var $actions = makeActionButtons(tabData.actions, {
-                  actionFilter: tabData.actions.actionFilter,
+                  actionFilter: actionFilter,
                   data: item,
-                  context: $detailView.data('view-args').context,
+                  context: $.extend(true, {}, 
$detailView.data('view-args').context, {
+                    item: [item]
+                  }),
                   ignoreAddAction: true
                 });
 
@@ -1357,9 +1364,10 @@
       var $action = $target.closest('.action').find('[detail-action]');
       var actionName = $action.attr('detail-action');
       var actionCallback = $action.data('detail-view-action-callback');
-      var detailViewArgs = 
$action.closest('div.detail-view').data('view-args');
+      var detailViewArgs = $.extend(true, {}, 
$action.closest('div.detail-view').data('view-args'));
       var additionalArgs = {};
       var actionSet = uiActions;
+      var $details = $action.closest('.details');
 
       var uiCallback = actionSet[actionName];
       if (!uiCallback)
@@ -1367,6 +1375,10 @@
 
       detailViewArgs.actionName = actionName;
 
+      if ($details.data('item-context')) {
+        detailViewArgs.context = $details.data('item-context');
+      }
+
       uiCallback($target.closest('div.detail-view'), detailViewArgs, 
additionalArgs);
 
       return false;

Reply via email to