From e7e5ff79cd45d2d4cfa5dcbe9344487639675b26 Mon Sep 17 00:00:00 2001 From: Brian Federle Date: Fri, 17 Feb 2012 13:55:38 -0800 Subject: [PATCH] bug 12253: Allow editing of LB rule name/algorithm -- This also introduced a new capability -- edit rule -- into the multiEdit widget. If isEditable: true is set for any fields, then a dialog will popup allowing editing of those properties. status 12253: resolved fixed reviewed-by: jessica --- ui/scripts/network.js | 29 ++++++- ui/scripts/ui/widgets/multiEdit.js | 129 ++++++++++++++++++----------- 2 files changed, 107 insertions(+), 51 deletions(-) diff --git a/ui/scripts/network.js b/ui/scripts/network.js index 1de821ee762..eca86dcd50f 100644 --- a/ui/scripts/network.js +++ b/ui/scripts/network.js @@ -1737,17 +1737,18 @@ }), multipleAdd: true, fields: { - 'name': { edit: true, label: 'label.name' }, + 'name': { edit: true, label: 'label.name', isEditable: true }, 'publicport': { edit: true, label: 'label.public.port' }, 'privateport': { edit: true, label: 'label.private.port' }, 'algorithm': { label: 'label.algorithm', + isEditable: true, select: function(args) { args.response.success({ data: [ - { name: 'roundrobin', description: _l('label.round.robin') }, - { name: 'leastconn', description: _l('label.least.connections') }, - { name: 'source', description: _l('label.source') } + { id: 'roundrobin', name: 'roundrobin', description: _l('label.round.robin') }, + { id: 'leastconn', name: 'leastconn', description: _l('label.least.connections') }, + { id: 'source', name: 'source', description: _l('label.source') } ] }); } @@ -1855,6 +1856,26 @@ } }, actions: { + edit: { + label: 'label.edit', + action: function(args) { + $.ajax({ + url: createURL('updateLoadBalancerRule'), + data: $.extend(args.data, { + id: args.context.multiRule[0].id + }), + success: function(json) { + args.response.success({ + _custom: { jobId: json.updateloadbalancerruleresponse.jobid }, + notification: { + label: 'Edit LB rule', + poll: pollAsyncJobResult + } + }); + } + }); + } + }, destroy: { label: 'label.action.delete.load.balancer', action: function(args) { diff --git a/ui/scripts/ui/widgets/multiEdit.js b/ui/scripts/ui/widgets/multiEdit.js index 3c073ab6b80..0fd68bef95b 100644 --- a/ui/scripts/ui/widgets/multiEdit.js +++ b/ui/scripts/ui/widgets/multiEdit.js @@ -202,10 +202,69 @@ .append($('').addClass('icon')) .attr({ title: _l(action.label) }) .click(function() { + var performAction = function(options) { + if (!options) options = {}; + + action.action({ + context: $.extend(true, {}, options.context, { + multiRule: [data] + }), + data: options.data, + response: { + success: function(args) { + var notification = args ? args.notification : null; + var _custom = args ? args._custom : null; + if (notification) { + $('.notifications').notifications('add', { + section: 'network', + desc: notification.label, + interval: 3000, + _custom: _custom, + poll: function(args) { + var complete = args.complete; + var error = args.error; + + notification.poll({ + _custom: args._custom, + complete: function(args) { + if (isDestroy) { + $loading.remove(); + $dataItem.remove(); + } else { + $multi.trigger('refresh'); + } + + complete(); + + if (options.complete) options.complete(); + }, + error: function(args) { + error(args); + $loading.remove(); + $dataItem.show(); + + return cloudStack.dialog.error; + } + }); + } + }); + } else { + $loading.remove(); + if (isDestroy) { + $dataItem.remove(); + } + } + }, + error: cloudStack.dialog.error + } + }); + }; + var $target = $(this); var $dataItem = $target.closest('.data-item'); var $expandable = $dataItem.find('.expandable-listing'); var isDestroy = $target.hasClass('destroy'); + var isEdit = $target.hasClass('edit'); if (isDestroy) { var $loading = _medit.loadingItem($multi, _l('label.removing') + '...'); @@ -222,56 +281,32 @@ } } - action.action({ - context: $.extend(true, {}, options.context, { - multiRule: [data] - }), - response: { - success: function(args) { - var notification = args ? args.notification : null; - var _custom = args ? args._custom : null; - if (notification) { - $('.notifications').notifications('add', { - section: 'network', - desc: notification.label, - interval: 3000, - _custom: _custom, - poll: function(args) { - var complete = args.complete; - var error = args.error; + if (!isEdit) { + performAction(); + } else { + // Get editable fields + var editableFields = {}; - notification.poll({ - _custom: args._custom, - complete: function(args) { - if (isDestroy) { - $loading.remove(); - $dataItem.remove(); - } else { - $multi.trigger('refresh'); - } + $.each(fields, function(key, field) { + if (field.isEditable) editableFields[key] = $.extend(true, {}, field, { + defaultValue: data[key] + }); + }); - complete(); - }, - error: function(args) { - error(args); - $loading.remove(); - $dataItem.show(); - - return cloudStack.dialog.error; - } - }); - } - }); - } else { - $loading.remove(); - if (isDestroy) { - $dataItem.remove(); - } - } + cloudStack.dialog.createForm({ + form: { + title: 'Edit rule', + desc: '', + fields: editableFields }, - error: cloudStack.dialog.error - } - }); + after: function(args) { + var $loading = $('
').addClass('loading-overlay').prependTo($dataItem); + performAction({ data: args.data, complete: function() { + $multi.multiEdit('refresh'); + } }); + } + }); + } }) ); });