Feature #3748: VNet Update AR dialog

This commit is contained in:
Carlos Martín committed 2015-05-27 13:27:06 +02:00
1 parent 86b1adf7c2
commit e01cd07c33
7 files changed
+179 -20

No files matched your search

+2 -1
View File
@@ -8,7 +8,8 @@ define(function(require) {
var DATATABLE_ID = "dataTableVNets";
var _dialogs = [
require('./vnets-tab/dialogs/add-ar')
require('./vnets-tab/dialogs/add-ar'),
require('./vnets-tab/dialogs/update-ar')
];
var _panels = [
@@ -8,6 +8,7 @@ define(function(require) {
var TAB_ID = require('./tabId');
var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId');
var ADD_AR_DIALOG_ID = require('./dialogs/add-ar/dialogId');
var UPDATE_AR_DIALOG_ID = require('./dialogs/update-ar/dialogId');
var _actions = {
"Network.create" : {
@@ -160,12 +161,9 @@ define(function(require) {
type: "single",
call: OpenNebulaNetwork.update_ar,
callback: function(req) {
/* TODO
// Reset the wizard
$update_ar_dialog.foundation('reveal', 'close');
$update_ar_dialog.empty();
setupUpdateARDialog();
*/
Sunstone.getDialog(UPDATE_AR_DIALOG_ID).hide();
Sunstone.getDialog(UPDATE_AR_DIALOG_ID).reset();
Sunstone.runAction("Network.show",req.request.data[0][0]);
},
@@ -0,0 +1,82 @@
define(function(require) {
/*
DEPENDENCIES
*/
var BaseDialog = require('utils/dialogs/dialog');
var TemplateHTML = require('hbs!./update-ar/html');
var ArTab = require('tabs/vnets-tab/utils/ar-tab');
var Sunstone = require('sunstone');
var Notifier = require('utils/notifier');
var Locale = require('utils/locale');
/*
CONSTANTS
*/
var DIALOG_ID = require('./update-ar/dialogId');
/*
CONSTRUCTOR
*/
function Dialog() {
this.dialogId = DIALOG_ID;
this.arTab = new ArTab();
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.setParams = _setParams;
return Dialog;
/*
FUNCTION DEFINITIONS
*/
function _html() {
return TemplateHTML({
'arTabHTML': this.arTab.html("update_ar")
});
}
function _setup(context) {
var that = this;
that.arTab.setup(context, "update_ar");
$('#update_ar_form',context).on('invalid', function () {
Notifier.notifyError(tr("One or more required fields are missing."));
}).on('valid', function () {
var data = that.arTab.retrieve();
data['AR_ID'] = that.arId;
var obj = {AR: data};
Sunstone.runAction('Network.update_ar', that.vnetId, obj);
return false;
});
}
function _onShow(context) {
this.arTab.onShow();
}
function _setParams(params) {
this.vnetId = params.vnetId;
this.arId = params.arId;
$('#vnet_id', this.dialogElement).text(params.vnetId);
$('#ar_id', this.dialogElement).text(params.arId);
this.arTab.fill(params.arData);
}
});
@@ -0,0 +1,3 @@
define(function(require){
return 'update_ar_dialog';
});
@@ -0,0 +1,24 @@
<div id="{{dialogId}}" class="reveal-modal large max-height" data-reveal >
<div class="reveal-body">
<form data-abide="ajax" id="update_ar_form" action="">
<div class="row">
<div class="large-12 columns">
<h3 class="subheader" id="">
{{tr "Virtual Network"}} <span id="vnet_id"/>
<br>
{{tr "Edit Address Range"}} <span id="ar_id"/>
</h3>
</div>
</div>
{{{arTabHTML}}}
<div class="reveal-footer">
<div class="form_buttons">
<button class="button radius right success" id="submit_ar_button" type="submit" value="Network.update_ar">
{{tr "Update"}}
</button>
</div>
</div>
<a class="close-reveal-modal">&#215;</a>
</form>
</div>
</div>
@@ -11,6 +11,8 @@ define(function(require) {
var Utils = require('../utils/common');
var SecurityGroupsTable = require('tabs/secgroups-tab/datatable');
var Sunstone = require('sunstone');
var OpenNebulaNetwork = require('opennebula/network');
var Notifier = require('utils/notifier');
/*
CONSTANTS
@@ -23,6 +25,7 @@ define(function(require) {
var XML_ROOT = "VNET";
var ADD_AR_DIALOG_ID = require('../dialogs/add-ar/dialogId');
var UPDATE_AR_DIALOG_ID = require('../dialogs/update-ar/dialogId');
/*
CONSTRUCTOR
@@ -175,28 +178,34 @@ define(function(require) {
var id = that.element.ID;
var ar_id = $(this).attr('ar_id');
// TODO: update ar dialog
/*
OpenNebula.Network.show({
OpenNebulaNetwork.show({
data : {
id: id
id: id
},
timeout: true,
success: function (request, vn){
var vn_info = vn.VNET;
var vn_info = vn.VNET;
var ar = getAR(vn_info, ar_id);
var ar = getAR(vn_info, ar_id);
if(ar != undefined){
popUpUpdateAR(id, ar);
} else {
notifyError(tr("The Adress Range was not found"));
Sunstone.runAction("Network.show", id);
}
if(ar != undefined){
Sunstone.getDialog(UPDATE_AR_DIALOG_ID).reset();
Sunstone.getDialog(UPDATE_AR_DIALOG_ID).setParams({
'vnetId': id,
'arId': ar_id,
'arData': $.extend({}, ar)
});
Sunstone.getDialog(UPDATE_AR_DIALOG_ID).show();
} else {
Notifier.notifyError(Locale.tr("The Adress Range was not found"));
Sunstone.runAction("Network.show", id);
}
},
error: onError
error: Notifier.onError
});
*/
return false;
});
@@ -3,6 +3,7 @@ define(function(require) {
var Locale = require('utils/locale');
var Tips = require('utils/tips');
var CustomTags = require('utils/form-panels/custom-tags');
var WizardFields = require('utils/wizard-fields');
var SecurityGroupsTable = require('tabs/secgroups-tab/datatable');
var TemplateHTML = require('hbs!./ar-tab');
@@ -15,6 +16,7 @@ define(function(require) {
'html': _generate_ar_tab_content,
'setup': _setup_ar_tab_content,
'onShow': _onShow,
'fill': _fill_ar_tab_data,
'retrieve': _retrieve_ar_tab_data
};
@@ -125,4 +127,44 @@ define(function(require) {
return data;
}
function _fill_ar_tab_data(ar_json){
WizardFields.fill(this.ar_section, ar_json);
var fields = $('[wizard_field]',this.ar_section);
fields.each(function(){
var field = $(this);
var field_name = field.attr('wizard_field');
// Delete so these attributes don't end in the custom tags table also
delete ar_json[field_name];
});
delete ar_json["AR_ID"];
delete ar_json["USED_LEASES"];
delete ar_json["LEASES"];
delete ar_json["MAC_END"];
delete ar_json["IP_END"];
delete ar_json["IP6_ULA"];
delete ar_json["IP6_ULA_END"];
delete ar_json["IP6_GLOBAL"];
delete ar_json["IP6_GLOBAL_END"];
if (ar_json["SECURITY_GROUPS"] != undefined &&
ar_json["SECURITY_GROUPS"].length != 0){
var secgroups = ar_json["SECURITY_GROUPS"].split(",");
this.securityGroupsTable.selectResourceTableSelect({ids: secgroups});
}
delete ar_json["SECURITY_GROUPS"];
CustomTags.fill(this.ar_section, ar_json);
$('input[name$="ar_type"]',this.ar_section).prop("disabled", true);
$('input[wizard_field="IP"]',this.ar_section).prop("disabled", true);
$('input[wizard_field="MAC"]',this.ar_section).prop("disabled", true);
}
});