From ea440f2593b82344c1b2cc6437a2f7fc9ad68e9b Mon Sep 17 00:00:00 2001 From: Brian Federle Date: Wed, 22 May 2013 15:50:19 -0700 Subject: [PATCH] Add API calls to update ACL item order on drag-and-drop --- ui/scripts/ui/widgets/multiEdit.js | 18 +++++++++++++++++- ui/scripts/vpc.js | 24 +++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/ui/scripts/ui/widgets/multiEdit.js b/ui/scripts/ui/widgets/multiEdit.js index 14f379fcc2b..936c20c48a0 100755 --- a/ui/scripts/ui/widgets/multiEdit.js +++ b/ui/scripts/ui/widgets/multiEdit.js @@ -34,6 +34,7 @@ $item.append($('').append($(''))); $tr = $('').appendTo($item.find('tbody')); + $item.data('json-obj', multiRule); if (itemData) { $tr.data('multi-edit-data', itemData); @@ -828,7 +829,22 @@ $.fn.multiEdit = function(args) { $('
').addClass('reorder').appendTo($thead); $('').addClass('reorder').appendTo($inputForm); $multi.find('.data-body').sortable({ - handle: '.action.moveDrag' + handle: '.action.moveDrag', + + update: function(event, ui) { + reorder.moveDrag.action({ + context: $.extend(true, {}, context, { + // Passes all rules, so that each index can be updated + multiRule: $multi.find('.data-item').map(function(index, item) { + return $(item).data('json-obj'); + }) + }), + response: { + success: function(args) { + } + } + }); + } }); } diff --git a/ui/scripts/vpc.js b/ui/scripts/vpc.js index 5c2f0266d1b..d27e1fc44eb 100644 --- a/ui/scripts/vpc.js +++ b/ui/scripts/vpc.js @@ -30,7 +30,29 @@ reorder: { moveDrag: { action: function(args) { - args.response.success(); + $(args.context.multiRule.toArray().reverse()).map(function(index, rule) { + $.ajax({ + url: createURL('updateNetworkACLItem'), + data: { + id: rule.id, + number: index + 1 + }, + success: function(json) { + var pollTimer = setInterval(function() { + pollAsyncJobResult({ + _custom: { jobId: json.createnetworkaclresponse.jobid }, + complete: function() { + clearInterval(pollTimer); + }, + error: function(errorMsg) { + clearInterval(pollTimer); + cloudStack.dialog.notice(errorMsg); + } + }); + }, 1000); + } + }); + }); } } },