1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-23 22:50:09 +03:00

feature #3748: Add resize vm dialog

This commit is contained in:
Daniel Molina 2015-06-08 16:57:46 +02:00
parent b8441259a2
commit d9aefcb54e
3 changed files with 140 additions and 0 deletions

View File

@ -0,0 +1,104 @@
define(function(require) {
/*
DEPENDENCIES
*/
var BaseDialog = require('utils/dialogs/dialog');
var TemplateHTML = require('hbs!./resize/html');
var Sunstone = require('sunstone');
var Notifier = require('utils/notifier');
var Tips = require('utils/tips');
var CapacityInputs = require('tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs');
var WizardFields = require('utils/wizard-fields');
/*
CONSTANTS
*/
var DIALOG_ID = require('./resize/dialogId');
var TAB_ID = require('../tabId')
/*
CONSTRUCTOR
*/
function Dialog() {
this.dialogId = DIALOG_ID;
BaseDialog.call(this);
};
Dialog.DIALOG_ID = DIALOG_ID;
Dialog.prototype = Object.create(BaseDialog.prototype);
Dialog.prototype.constructor = Dialog;
Dialog.prototype.html = _html;
Dialog.prototype.onShow = _onShow;
Dialog.prototype.setup = _setup;
Dialog.prototype.setElement = _setElement;
return Dialog;
/*
FUNCTION DEFINITIONS
*/
function _html() {
return TemplateHTML({
'dialogId': this.dialogId,
'capacityInputsHTML': CapacityInputs.html()
});
}
function _setup(context) {
var that = this;
CapacityInputs.setup();
Tips.setup(context);
$('#' + DIALOG_ID + 'Form', context).submit(function() {
var templateJSON = WizardFields.retrieve(context);
if (templateJSON["CPU"] == that.element.TEMPLATE.CPU) {
delete templateJSON["CPU"];
};
if (templateJSON["MEMORY"] == that.element.TEMPLATE.MEMORY) {
delete templateJSON["MEMORY"];
};
if (templateJSON["VCPU"] == that.element.TEMPLATE.VCPU) {
delete templateJSON["VCPU"];
};
var enforce = $("#enforce", this).is(":checked");
var obj = {
"vm_template": templateJSON,
"enforce": enforce,
}
Sunstone.runAction('VM.resize', that.element.ID, obj);
Sunstone.getDialog(DIALOG_ID).hide();
Sunstone.getDialog(DIALOG_ID).reset();
return false;
});
return false;
}
function _onShow(context) {
var that = this;
$('#vm_id', context).text(that.element.ID);
$('#CPU', context).val(that.element.TEMPLATE.CPU);
$('#MEMORY_TMP', context).val(that.element.TEMPLATE.MEMORY);
if (that.element.VCPU) {
$('#VCPU', context).val(that.element.TEMPLATE.VCPU);
}
return false;
}
function _setElement(element) {
this.element = element
}
});

View File

@ -0,0 +1,3 @@
define(function(require) {
return 'resizeVMDialog';
})

View File

@ -0,0 +1,33 @@
<div id="{{dialogId}}" class="reveal-modal large" role="dialog" data-reveal >
<div class="row">
<div class="large-12 columns">
<h3 class="subheader" id="">{{tr "Resize VM capacity"}}</h3>
</div>
</div>
<div class="reveal-body">
<form id="{{dialogId}}Form" action="">
<div class="row centered">
<div class="large-6 columns">
<label for="vm_id">{{tr "Virtual Machine ID"}}:</label>
<label style="border-style: inset; background-color: lightgrey" type="text" name="vm_id" id="vm_id" disabled/>
</div>
<div class="large-6 columns">
<input type="checkbox" name="enforce" id="enforce"/>
<label class="inline" for="vm_id">
{{tr "Enforce"}}
<span class="tip">
{{tr "If it is set to true, the host capacity will be checked. This will only affect oneadmin requests, regular users resize requests will always be enforced"}}
</span>
</label>
</div>
</div>
{{{capacityInputsHTML}}}
<div class="reveal-footer">
<div class="form_buttons">
<button class="button radius right success" id="resize_capacity_button" type="submit" value="VM.resize">{{tr "Resize"}}</button>
</div>
</div>
<a class="close-reveal-modal">&#215;</a>
</form>
</div>
</div>