';
- if (edit_enabled) {
- quotas_html +=
- '
\
-
\
- \
- \
- \
- \
- \
-
\
-
';
- }
+ if (edit_enabled) {
+ quotas_html +=
+ '
\
+
\
+ \
+ \
+ \
+ \
+ \
+
\
+
';
+ }
if (emptyQuotas(resource_info)) {
quotas_html +=
@@ -2918,178 +2918,174 @@ function initQuotaInputValue(input){
}
}
-function setupQuotasPanel(resource_info, parent_container, edit_enabled, resource_name){
- if (edit_enabled) {
- $(parent_container).off("click", "#edit_quotas_button");
- $(parent_container).on("click", "#edit_quotas_button", function() {
- $(parent_container+" #edit_quotas_button").hide();
- $(parent_container+" #cancel_quotas_button").show();
- $(parent_container+" #submit_quotas_button").show();
+function quotasPanelEditAction(parent_container){
+ $("#edit_quotas_button", parent_container).hide();
+ $("#cancel_quotas_button", parent_container).show();
+ $("#submit_quotas_button", parent_container).show();
- $.each($(parent_container+" div.quotabar_container input"), function(){
- initQuotaInputValue(this);
+ $.each($("div.quotabar_container input", parent_container), function(){
+ initQuotaInputValue(this);
+ });
+
+ $(".editable_quota", parent_container).show();
+ $(".non_editable_quota", parent_container).hide();
+
+ return false;
+}
+
+function setupQuotasBarButtons(resource_info, parent_container){
+ parent_container.off("click", ".quotabar_edit_btn");
+ parent_container.on("click", ".quotabar_edit_btn", function() {
+ var input = $(this).parents(".quotabar_container").find("input");
+
+ if(input.attr("quota_mode") != "edit"){
+ input.attr("quota_mode", "edit");
+ input.attr("disabled", false);
+ input.val( input.attr("quota_limit") >= 0 ? input.attr("quota_limit") : "0" );
+ }
+
+ return false;
+ });
+
+ parent_container.off("click", ".quotabar_default_btn");
+ parent_container.on("click", ".quotabar_default_btn", function() {
+ var input = $(this).parents(".quotabar_container").find("input");
+
+ var default_value = input.attr("quota_default");
+
+ if (default_value == QUOTA_LIMIT_UNLIMITED) {
+ default_value = "∞";
+ }
+
+ input.val( tr("Default") + " (" + default_value + ")" );
+ input.attr("quota_mode", "default");
+ input.attr("disabled", "disabled");
+
+ return false;
+ });
+
+ parent_container.off("click", ".quotabar_unlimited_btn");
+ parent_container.on("click", ".quotabar_unlimited_btn", function() {
+ var input = $(this).parents(".quotabar_container").find("input");
+
+ input.val(tr("Unlimited"));
+ input.attr("quota_mode", "unlimited");
+ input.attr("disabled", "disabled");
+
+ return false;
+ });
+}
+
+function retrieveQuotasValues(parent_container){
+ var obj = {};
+
+ obj["VM"] = {
+ "CPU" : input_val( $("div[quota_name=VM_CPU] input", parent_container) ),
+ "MEMORY" : input_val( $("div[quota_name=VM_MEMORY] input", parent_container) ),
+ "VMS" : input_val( $("div[quota_name=VM_VMS] input", parent_container) ),
+ "VOLATILE_SIZE" : input_val( $("div[quota_name=VM_VOLATILE_SIZE] input", parent_container) )
+ };
+
+ $.each($("tr.image_quota_tr", parent_container), function(){
+ if($(this).attr("quota_id") != "-1"){
+ if (obj["IMAGE"] == undefined) {
+ obj["IMAGE"] = [];
+ }
+
+ obj["IMAGE"].push({
+ "ID" : $(this).attr("quota_id"),
+ "RVMS" : input_val( $("div[quota_name=IMAGE_RVMS] input", this) )
});
+ }
+ });
- $(parent_container+" .editable_quota").show();
- $(parent_container+" .non_editable_quota").hide();
+ $.each($("tr.network_quota_tr", parent_container), function(){
+ if($(this).attr("quota_id") != "-1"){
+ if (obj["NETWORK"] == undefined) {
+ obj["NETWORK"] = [];
+ }
- return false;
+ obj["NETWORK"].push({
+ "ID" : $(this).attr("quota_id"),
+ "LEASES": input_val( $("div[quota_name=NETWORK_LEASES] input", this) )
+ });
+ }
+ });
+
+ $.each($("tr.ds_quota_tr", parent_container), function(){
+ if($(this).attr("quota_id") != "-1"){
+ if (obj["DATASTORE"] == undefined) {
+ obj["DATASTORE"] = [];
+ }
+
+ obj["DATASTORE"].push({
+ "ID" : $(this).attr("quota_id"),
+ "IMAGES": input_val( $("div[quota_name=DS_IMAGES] input", this) ),
+ "SIZE" : input_val( $("div[quota_name=DS_SIZE] input", this) )
+ });
+ }
+ });
+
+ return obj;
+}
+
+function setupQuotasPanel(resource_info, parent_id_str, edit_enabled, resource_name){
+ if (edit_enabled) {
+ $(parent_id_str).off("click", "#edit_quotas_button");
+ $(parent_id_str).on("click", "#edit_quotas_button", function() {
+ return quotasPanelEditAction($(parent_id_str));
});
- $(parent_container).off("click", "#cancel_quotas_button");
- $(parent_container).on("click", "#cancel_quotas_button", function() {
+ $(parent_id_str).off("click", "#cancel_quotas_button");
+ $(parent_id_str).on("click", "#cancel_quotas_button", function() {
Sunstone.runAction(resource_name+".show", resource_info.ID);
return false;
});
- $(parent_container).off("click", "#submit_quotas_button");
- $(parent_container).on("click", "#submit_quotas_button", function() {
- var obj = {};
-
- obj["VM"] = {
- "CPU" : input_val( $(parent_container+" div[quota_name=VM_CPU] input") ),
- "MEMORY" : input_val( $(parent_container+" div[quota_name=VM_MEMORY] input") ),
- "VMS" : input_val( $(parent_container+" div[quota_name=VM_VMS] input") ),
- "VOLATILE_SIZE" : input_val( $(parent_container+" div[quota_name=VM_VOLATILE_SIZE] input") )
- };
-
- $.each($(parent_container+" tr.image_quota_tr"), function(){
- if($(this).attr("quota_id") != "-1"){
- if (obj["IMAGE"] == undefined) {
- obj["IMAGE"] = [];
- }
-
- obj["IMAGE"].push({
- "ID" : $(this).attr("quota_id"),
- "RVMS" : input_val( $("div[quota_name=IMAGE_RVMS] input", this) )
- });
- }
- });
-
- $.each($(parent_container+" tr.network_quota_tr"), function(){
- if($(this).attr("quota_id") != "-1"){
- if (obj["NETWORK"] == undefined) {
- obj["NETWORK"] = [];
- }
-
- obj["NETWORK"].push({
- "ID" : $(this).attr("quota_id"),
- "LEASES": input_val( $("div[quota_name=NETWORK_LEASES] input", this) )
- });
- }
- });
-
- $.each($(parent_container+" tr.ds_quota_tr"), function(){
- if($(this).attr("quota_id") != "-1"){
- if (obj["DATASTORE"] == undefined) {
- obj["DATASTORE"] = [];
- }
-
- obj["DATASTORE"].push({
- "ID" : $(this).attr("quota_id"),
- "IMAGES": input_val( $("div[quota_name=DS_IMAGES] input", this) ),
- "SIZE" : input_val( $("div[quota_name=DS_SIZE] input", this) )
- });
- }
- });
-
+ $(parent_id_str).off("click", "#submit_quotas_button");
+ $(parent_id_str).on("click", "#submit_quotas_button", function() {
+ var obj = retrieveQuotasValues($(parent_id_str));
Sunstone.runAction(resource_name+".set_quota", [resource_info.ID], obj);
return false;
});
- $(parent_container).off("click", ".quotabar_edit_btn");
- $(parent_container).on("click", ".quotabar_edit_btn", function() {
- var input = $(this).parents(".quotabar_container").find("input");
-
- if(input.attr("quota_mode") != "edit"){
- input.attr("quota_mode", "edit");
- input.attr("disabled", false);
- input.val( input.attr("quota_limit") >= 0 ? input.attr("quota_limit") : "0" );
- }
-
- return false;
- });
-
- $(parent_container).off("click", ".quotabar_default_btn");
- $(parent_container).on("click", ".quotabar_default_btn", function() {
- var input = $(this).parents(".quotabar_container").find("input");
-
- var default_value = input.attr("quota_default");
-
- if (default_value == QUOTA_LIMIT_UNLIMITED) {
- default_value = "∞";
- }
-
- input.val( tr("Default") + " (" + default_value + ")" );
- input.attr("quota_mode", "default");
- input.attr("disabled", "disabled");
-
- return false;
- });
-
- $(parent_container).off("click", ".quotabar_unlimited_btn");
- $(parent_container).on("click", ".quotabar_unlimited_btn", function() {
- var input = $(this).parents(".quotabar_container").find("input");
-
- input.val(tr("Unlimited"));
- input.attr("quota_mode", "unlimited");
- input.attr("disabled", "disabled");
-
- return false;
- });
+ setupQuotasBarButtons(resource_info, $(parent_id_str));
}
}
+function quotas_tmpl(){
+ return '
\
+
\
+
\
+
\
+
\
+
\
+
\
+
\
+
\
+
\
+
\
+
\
+
';
+}
// Sets up a dialog to edit and update user and group quotas
// Called from user/group plugins
function setupQuotasDialog(dialog){
dialog.addClass("reveal-modal large max-height").attr("data-reveal", "");
- $('#add_quota_button',dialog).click(function(){
- var sel = $('.tabs-content div.content.active',dialog).attr("id");
- var fields = $('div#'+sel+' input,div#'+sel+' select',dialog);
- var json = {};
-
- for (var i = 0; i < fields.length; i++){
- var field = $(fields[i]);
- var name = field.attr('name');
- var value = field.val();
- if (name == 'ID' && !value.length){
- notifyError(tr("Please select an element"));
- return false;
- };
- if (!value) value = QUOTA_LIMIT_DEFAULT;
- json[name] = value;
- };
-
- json['TYPE'] = sel.split("_quota")[0].toUpperCase();
-
- if (json['TYPE'] == "VM" &&
- $('.current_quotas table tbody tr.vm_quota', dialog).length){
- notifyError("Only 1 VM quota is allowed")
- return false;
- }
-
-
- var tr = quotaListItem(json)
- $('.current_quotas table tbody',dialog).append($(tr).hide().fadeIn());
- return false;
- });
-
$('form', dialog).submit(function(){
- var obj = {};
- $('table tbody tr',this).each(function(){
- var json = JSON.parse($(this).attr('quota'));
- var type = json['TYPE'];
- delete json['TYPE'];
- if (typeof obj[type.toUpperCase()] == "undefined") {
- obj[type.toUpperCase()] = [];
- }
- obj[type.toUpperCase()].push(json);
- });
-
+ var obj = retrieveQuotasValues(dialog);
var action = $('div.form_buttons button',this).val();
var sel_elems = SunstoneCfg["actions"][action].elements();
Sunstone.runAction(action,sel_elems,obj);
@@ -3098,25 +3094,53 @@ function setupQuotasDialog(dialog){
});
}
-function popUpQuotasDialog(dialog, resource, sel_elems){
- insertSelectOptions("#image_quota select", dialog, "Image", null, true);
- insertSelectOptions("#network_quota select", dialog, "Network", null, true);
- insertSelectOptions("#datastore_quota select", dialog, "Datastore",null, true);
-
- $('table tbody',dialog).empty();
- //If only one user is selected we fecth the user's quotas, otherwise we do nothing.
+function popUpQuotasDialog(dialog, resource, sel_elems, default_quotas, parent_id_str){
+ //If only one user is selected we fecth the user's quotas
if (sel_elems.length == 1){
var id = sel_elems[0];
Sunstone.runAction(resource + '.fetch_quotas',id);
- };
-
- $('input[value="vm"]', dialog).click();
-
- dialog.foundation().foundation('reveal', 'open');
-
- $("input[name='VMS']",dialog).focus();
+ } else {
+ // More than one, populate with '0' usage
+ populateQuotasDialog({}, default_quotas, parent_id_str, dialog);
+ }
}
+function populateQuotasDialog(resource_info, default_quotas, parent_id_str, dialog){
+ var vms_quota = Quotas.vms(resource_info, default_quotas);
+ var cpu_quota = Quotas.cpu(resource_info, default_quotas);
+ var memory_quota = Quotas.memory(resource_info, default_quotas);
+ var volatile_size_quota = Quotas.volatile_size(resource_info, default_quotas);
+
+ var image_quota = Quotas.image(
+ resource_info, default_quotas, {parent_id_str: parent_id_str});
+
+ var network_quota = Quotas.network(
+ resource_info, default_quotas, {parent_id_str: parent_id_str});
+
+ var datastore_quota = Quotas.datastore(
+ resource_info, default_quotas, {parent_id_str: parent_id_str});
+
+ $(parent_id_str+" #vm_quota").html(
+ '
' + vms_quota + '
\
+
' + cpu_quota + '
\
+
' + memory_quota + '
\
+
' + volatile_size_quota+ '
');
+
+ $(parent_id_str+" #datastore_quota").html(
+ '
' + datastore_quota + '
');
+
+ $(parent_id_str+" #image_quota").html(
+ '
' + image_quota + '
');
+
+ $(parent_id_str+" #network_quota").html(
+ '
' + network_quota + '
');
+
+ setupQuotasBarButtons(resource_info, dialog);
+
+ quotasPanelEditAction(dialog);
+
+ dialog.foundation().foundation('reveal', 'open');
+}
//Action to be performed when an edit quota icon is clicked.
function setupQuotaIcons(){
@@ -3151,100 +3175,6 @@ function setupQuotaIcons(){
});
}
-// Returns an object with quota information in form of list items
-function parseQuotas(elem, formatter_f){
- var quotas = [];
- var results = {
- VM : "",
- DATASTORE : "",
- IMAGE : "",
- NETWORK : ""
- }
- //max 1 vm quota
- if (!$.isEmptyObject(elem.VM_QUOTA)){
- elem.VM_QUOTA.VM.TYPE = 'VM'
- quotas.push(elem.VM_QUOTA.VM)
- }
-
- var ds_arr = []
- if ($.isArray(elem.DATASTORE_QUOTA.DATASTORE)){
- ds_arr = elem.DATASTORE_QUOTA.DATASTORE
- } else if (!$.isEmptyObject(elem.DATASTORE_QUOTA)){
- ds_arr = [elem.DATASTORE_QUOTA.DATASTORE]
- }
-
- for (var i = 0; i < ds_arr.length; i++){
- ds_arr[i].TYPE = 'DATASTORE';
- quotas.push(ds_arr[i]);
- }
-
- var im_arr = []
- if ($.isArray(elem.IMAGE_QUOTA.IMAGE)){
- im_arr = elem.IMAGE_QUOTA.IMAGE
- } else if (!$.isEmptyObject(elem.IMAGE_QUOTA)){
- im_arr = [elem.IMAGE_QUOTA.IMAGE]
- }
-
- for (var i = 0; i < im_arr.length; i++){
- im_arr[i].TYPE = 'IMAGE';
- quotas.push(im_arr[i]);
- }
-
- var vn_arr = []
- if ($.isArray(elem.NETWORK_QUOTA.NETWORK)){
- vn_arr = elem.NETWORK_QUOTA.NETWORK
- } else if (!$.isEmptyObject(elem.NETWORK_QUOTA)){
- vn_arr = [elem.NETWORK_QUOTA.NETWORK]
- }
-
- for (var i = 0; i < vn_arr.length; i++){
- vn_arr[i].TYPE = 'NETWORK';
- quotas.push(vn_arr[i]);
- }
-
- for (var i = 0; i < quotas.length; i++){
- var tr = formatter_f(quotas[i]);
- results[quotas[i].TYPE] += tr;
- }
- return results;
-}
-
-//Receives a quota json object. Returns a nice string out of it.
-function quotaListItem(quota_json){
- var value = JSON.stringify(quota_json)
- var str = '
| '+
- quota_json.TYPE+
- ' | ';
- switch(quota_json.TYPE){
- case "VM":
- str += 'VMs: ' + quota_json.VMS + (quota_json.VMS_USED ? ' (' + quota_json.VMS_USED + '). ' : ". ") + ' ' +
- 'Memory: ' + quota_json.MEMORY + (quota_json.MEMORY_USED ? ' MB (' + quota_json.MEMORY_USED + ' MB). ' : " MB. ") + ' ' +
- 'CPU: ' + quota_json.CPU + (quota_json.CPU_USED ? ' (' + quota_json.CPU_USED + '). ' : ". ") + ' ' +
- 'Volatile disks: ' + quota_json.VOLATILE_SIZE + (quota_json.VOLATILE_SIZE_USED ? ' MB (' + quota_json.VOLATILE_SIZE_USED + ' MB). ' : " MB. ");
- break;
- case "DATASTORE":
- str += 'ID/Name: ' + getDatastoreName(quota_json.ID) + '. ' + ' ' +
- 'Size: ' + quota_json.SIZE + (quota_json.SIZE_USED ? ' MB (' + quota_json.SIZE_USED + ' MB). ' : " MB. ") + ' ' +
- 'Images: ' + quota_json.IMAGES + (quota_json.IMAGES_USED ? ' (' + quota_json.IMAGES_USED + '). ' : ".");
- break;
- case "IMAGE":
- str += 'ID/Name: ' + getImageName(quota_json.ID) + '. ' + ' ' +
- 'RVMs: ' + quota_json.RVMS + (quota_json.RVMS_USED ? ' (' + quota_json.RVMS_USED + '). ' : ". ");
- break;
- case "NETWORK":
- str += 'ID/Name: ' + getVNetName(quota_json.ID) + '. ' + ' ' +
- 'Leases: ' + quota_json.LEASES + (quota_json.LEASES_USED ? ' (' + quota_json.LEASES_USED + '). ': ". ");
- break;
- }
- str += ' | |
';
- return str;
-}
-
/* Returns the code of a jquery progress bar
Options: object with width, height, label and fontSize as keys
*/