Support sorting of templates/isos and offerings

status 7883: resolved fixed
This commit is contained in:
bfederle 2011-12-21 13:30:52 -08:00
parent 61eab674d2
commit b4ca2c1a13
4 changed files with 139 additions and 76 deletions

View File

@ -17,6 +17,8 @@
displaytext: { label: 'Description' }
},
reorder: cloudStack.api.actions.sort('updateServiceOffering', 'serviceOfferings'),
actions: {
add: {
label: 'Add service offering',
@ -314,6 +316,8 @@
displaytext: { label: 'Description' }
},
reorder: cloudStack.api.actions.sort('updateServiceOffering', 'systemServiceOfferings'),
actions: {
add: {
label: 'Add system service offering',
@ -605,21 +609,24 @@
label: 'Disk offerings',
fields: {
name: { label: 'Name' },
displaytext: { label: 'Description' },
iscustomized: {
label: 'Custom disk size',
converter: cloudStack.converters.toBooleanText
},
disksize: {
label: 'Disk Size',
converter: function(args) {
if(args != 0)
return args + " GB";
else
return "N/A";
}
}
displaytext: { label: 'Description' },
iscustomized: {
label: 'Custom disk size',
converter: cloudStack.converters.toBooleanText
},
disksize: {
label: 'Disk Size',
converter: function(args) {
if(args != 0)
return args + " GB";
else
return "N/A";
}
}
},
reorder: cloudStack.api.actions.sort('updateDiskOffering', 'diskOfferings'),
dataProvider: function(args) {
$.ajax({
url: createURL("listDiskOfferings&page="+args.page+"&pagesize="+pageSize),
@ -816,7 +823,7 @@
},
disksize: {
label: 'Disk Size',
converter: function(args) {
converter: function(args) {
if(args != 0)
return args + " GB";
else
@ -841,7 +848,7 @@
}
}
},
hypervisorCapabilities: {
type: 'select',
title: 'Hypervisor capabilities',
@ -870,48 +877,48 @@
detailView: {
name: 'Details',
actions: {
actions: {
edit: {
label: 'Edit',
action: function(args) {
var array1 = [];
array1.push("&maxguestslimit=" + todb(args.data.maxguestslimit));
action: function(args) {
var array1 = [];
array1.push("&maxguestslimit=" + todb(args.data.maxguestslimit));
$.ajax({
url: createURL("updateHypervisorCapabilities&id=" + args.context.hypervisorCapabilities[0].id + array1.join("")),
dataType: "json",
success: function(json) {
success: function(json) {
var item = json.updatehypervisorcapabilitiesresponse['null'];
args.response.success({data: item});
},
error: function(data) {
args.response.error(parseXMLHttpResponse(data));
}
});
});
}
}
}
},
tabs: {
details: {
title: 'Details',
fields: [
fields: [
{
id: { label: 'ID' },
id: { label: 'ID' },
hypervisor: { label: 'Hypervisor' },
hypervisorversion: { label: 'Hypervisor version' },
maxguestslimit: {
maxguestslimit: {
label: 'Max guest limit',
isEditable: true
},
securitygroupenabled: {
label: 'Security group enabled',
converter: cloudStack.converters.toBooleanText
}
}
}
],
dataProvider: function(args) {
dataProvider: function(args) {
args.response.success(
{
{
data:args.context.hypervisorCapabilities[0]
}
);
@ -921,7 +928,7 @@
}
}
},
networkOfferings: {
type: 'select',
title: 'Network offerings',
@ -929,11 +936,10 @@
id: 'networkOfferings',
label: 'Network offerings',
fields: {
name: { label: 'Name' },
guestiptype: { label: 'Guest type' },
availability: { label: 'Availability' },
name: { label: 'Name' },
state: { label: 'State', indicator: { 'Enabled': 'on', 'Disabled': 'off', 'Destroyed': 'off' }}
},
dataProvider: function(args) {
$.ajax({
url: createURL('listNetworkOfferings'),
@ -975,7 +981,7 @@
services[serviceData[1]] = formData[
'service.' + serviceData[1] + '.provider'
];
}
}
} else if (value != '') { // Normal data
inputData[key] = value;
}
@ -1025,7 +1031,7 @@
name: { label: 'Name', validation: { required: true } },
displayText: { label: 'Display Text', validation: { required: true } },
networkRate: { label: 'Network Rate' },
trafficType: {
@ -1087,7 +1093,7 @@
};
})
)
});
});
},
error: function(data) {
args.response.error(parseXMLHttpResponse(data));
@ -1097,8 +1103,8 @@
},
specifyVlan: { label: 'Specify VLAN', isBoolean: true },
supportedServices: {
supportedServices: {
label: 'Supported Services',
dynamic: function(args) {
@ -1112,7 +1118,7 @@
$(networkServices).each(function() {
var name = this.name;
var providers = this.provider;
var id = {
isEnabled: 'service' + '.' + name + '.' + 'isEnabled',
capabilities: 'service' + '.' + name + '.' + 'capabilities',
@ -1120,7 +1126,7 @@
};
fields[id.isEnabled] = { label: name, isBoolean: true };
fields[id.provider] = {
fields[id.provider] = {
label: name + ' Provider',
isHidden: true,
dependsOn: id.isEnabled,
@ -1159,7 +1165,7 @@
});
}
},
messages: {
notification: function(args) {
return 'Added network offering';
@ -1264,6 +1270,8 @@
}
},
reorder: cloudStack.api.actions.sort('updateNetworkOffering', 'networkOfferings'),
detailView: {
name: 'Network offering details',
actions: {
@ -1285,7 +1293,7 @@
services[serviceData[1]] = formData[
'service.' + serviceData[1] + '.provider'
];
}
}
} else if (value != '') { // Normal data
inputData[key] = value;
}
@ -1334,7 +1342,7 @@
name: { label: 'Name', validation: { required: true } },
displayText: { label: 'Display Text', validation: { required: true } },
networkRate: { label: 'Network Rate' },
trafficType: {
@ -1396,7 +1404,7 @@
};
})
)
});
});
},
error: function(data) {
args.response.error(parseXMLHttpResponse(data));
@ -1406,8 +1414,8 @@
},
specifyVlan: { label: 'Specify VLAN', isBoolean: true },
supportedServices: {
supportedServices: {
label: 'Supported Services',
dynamic: function(args) {
@ -1421,7 +1429,7 @@
$(networkServices).each(function() {
var name = this.name;
var providers = this.provider;
var id = {
isEnabled: 'service' + '.' + name + '.' + 'isEnabled',
capabilities: 'service' + '.' + name + '.' + 'capabilities',
@ -1429,7 +1437,7 @@
};
fields[id.isEnabled] = { label: name, isBoolean: true };
fields[id.provider] = {
fields[id.provider] = {
label: name + ' Provider',
isHidden: true,
dependsOn: id.isEnabled,
@ -1460,7 +1468,7 @@
tags: { label: 'Tags' }
}
},
messages: {
notification: function(args) {
return 'Added network offering';
@ -1668,7 +1676,7 @@
if (jsonObj.state == 'Destroyed' || jsonObj.isdefault) {
return [];
}
var allowedActions = ['destroy'];
allowedActions.push("edit");
if(jsonObj.state == "Enabled")

View File

@ -394,3 +394,45 @@ timezoneMap['Australia/Brisbane']='[UTC+10:00] Eastern Standard Time (Queensland
timezoneMap['Australia/Canberra']='[UTC+10:00] Eastern Standard Time (New South Wales)';
timezoneMap['Pacific/Guam']='[UTC+10:00] Chamorro Standard Time';
timezoneMap['Pacific/Auckland']='[UTC+12:00] New Zealand Standard Time';
// CloudStack common API helpers
cloudStack.api = {
actions: {
sort: function(updateCommand, objType) {
var action = function(args) {
$.ajax({
url: createURL(updateCommand),
data: {
id: args.context[objType].id,
sortKey: args.index
},
success: function(json) {
args.response.success();
},
error: function(json) {
args.response.error(parseXMLHttpResponse(json));
}
});
};
return {
moveTop: {
action: action
},
moveBottom: {
action: action
},
moveUp: {
action: action
},
moveDown: {
action: action
},
moveDrag: {
action: action
}
}
}
}
};

View File

@ -24,6 +24,7 @@
zonename: { label: 'Zone' },
hypervisor: { label: 'Hypervisor' }
},
reorder: cloudStack.api.actions.sort('updateTemplate', 'templates'),
actions: {
add: {
label: 'Create template',
@ -832,6 +833,9 @@
size: { label: 'Size' },
zonename: { label: 'Zone' }
},
reorder: cloudStack.api.actions.sort('updateIso', 'isos'),
actions: {
add: {
label: 'Create ISO',

View File

@ -561,6 +561,12 @@
$th.html(field.label);
});
if (reorder) {
$thead.append(
$('<th>').html('Order').addClass('reorder-actions reduced-hide')
);
}
if (actions && renderActionCol(actions)) {
$thead.append(
$('<th></th>')
@ -569,12 +575,6 @@
);
}
if (reorder) {
$thead.append(
$('<th>').html('Order').addClass('reorder-actions reduced-hide')
);
}
return $thead;
};
@ -788,6 +788,30 @@
// Add reorder actions
if (reorder) {
var sort = function($tr, action) {
var $listView = $tr.closest('.list-view');
var viewArgs = $listView.data('view-args');
var context = $.extend(
true, {},
$tr.closest('.list-view').data('view-args').context
);
var rowIndex = $tr.closest('tbody').find('tr').size() - ($tr.index());
context[viewArgs.activeSection] = $tr.data('json-obj');
action.action({
context: context,
index: rowIndex,
response: {
success: function(args) {},
error: function(args) {
// Move back to previous position
rowActions.moveTo($tr, rowIndex);
}
}
});
};
$('<td>').addClass('actions reorder').appendTo($tr).append(function() {
var $td = $(this);
@ -812,20 +836,11 @@
.click(function() {
if (actionName == 'moveDrag') return false;
var rowIndex = $tr.index();
rowActions[actionName]($tr);
action.action({
response: {
success: function(args) {
$tr.closest('.data-table').dataTable('selectRow', $tr.index());
},
error: function(args) {
// Move back to previous position
rowActions.moveTo($tr, rowIndex);
}
}
$tr.closest('tbody').find('tr').each(function() {
sort($(this), action);
});
$tr.closest('.data-table').dataTable('selectRow', $tr.index());
return false;
});
@ -844,14 +859,8 @@
stop: function(event, ui) {
rowActions._std($tr, function() {});
reorder.moveDrag.action({
response: {
success: function(args) {},
error: function(args) {
$tr.closest('tbody').sortable('cancel');
rowActions._std($tr, function() {});
}
}
$tr.closest('tbody').find('tr').each(function() {
sort($(this), reorder.moveDrag);
});
}
});