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
This commit is contained in:
Brian Federle 2012-02-17 13:55:38 -08:00
parent 51be2a7913
commit e7e5ff79cd
2 changed files with 107 additions and 51 deletions

View File

@ -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) {

View File

@ -202,10 +202,69 @@
.append($('<span>').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 = $('<div>').addClass('loading-overlay').prependTo($dataItem);
performAction({ data: args.data, complete: function() {
$multi.multiEdit('refresh');
} });
}
});
}
})
);
});