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

Changed list Role Affinity (#199)

* .yaml upgraded

* Changed list Role Affinity
This commit is contained in:
Abel Coronado 2017-02-27 17:27:20 +01:00 committed by Tino Vázquez
parent a94e9d0a03
commit a7bf057d6f
2 changed files with 26 additions and 29 deletions

View File

@ -19,12 +19,9 @@ define(function(require) {
var Locale = require('utils/locale');
var Tips = require('utils/tips');
var GroupRoleAffinity = require('tabs/vmgroup-tab/utils/group-role-affinity');
var TemplateHTML = require('hbs!./affinity-role-tab/html');
var Notifier = require('utils/notifier');
function AffinityRoleTab(list_roles) {
this.list_roles = list_roles;
return this;
@ -39,6 +36,7 @@ define(function(require) {
'refresh': _refresh,
'removeRole': _remove_role
};
AffinityRoleTab.prototype.constructor = AffinityRoleTab;
return AffinityRoleTab;
@ -54,9 +52,9 @@ define(function(require) {
$("#tf_btn_host_anti_affined").bind("click", function(){
var rolesSt = "";
var numRoles = 0;
$(".roles",context).each(function(){
if($(this)[0].checked){
rolesSt+= $(this)[0].id+",";
$(".roles", context).each(function(){
if($(this)[0].selected){
rolesSt += $(this)[0].id + ",";
numRoles++;
}
});
@ -64,17 +62,16 @@ define(function(require) {
_add_group_affinity_box(rolesSt.slice(0,-1), context, group_roles_index, that.group_roles_affinity, "ANTI_AFFINED");
group_roles_index++;
}
else{
else
Notifier.notifyError(Locale.tr("You have to choose at least two roles."));
}
});
$("#tf_btn_host_affined").bind("click", function(){
var rolesSt = "";
var numRoles = 0;
$(".roles",context).each(function(){
if($(this)[0].checked){
rolesSt+= $(this)[0].id+",";
if($(this)[0].selected){
rolesSt += $(this)[0].id + ",";
numRoles++;
}
});
@ -82,13 +79,13 @@ define(function(require) {
_add_group_affinity_box(rolesSt.slice(0,-1), context, group_roles_index, that.group_roles_affinity, "AFFINED");
group_roles_index++;
}
else{
else
Notifier.notifyError(Locale.tr("You have to choose at least two roles."));
}
});
}
function _onShow(){
}
function _retrieve(context){
@ -116,11 +113,11 @@ define(function(require) {
if(affinity == "AFFINED" || affinity == "ANTI_AFFINED"){
if(Array.isArray(value)){
for(dbs in value){
_add_group_affinity_box(value[dbs],context, group_roles_index, that.group_roles_affinity, affinity);
_add_group_affinity_box(value[dbs], context, group_roles_index, that.group_roles_affinity, affinity);
group_roles_index++;
}
}
else{
else {
_add_group_affinity_box(value, context, group_roles_index, that.group_roles_affinity, affinity);
group_roles_index++;
}
@ -133,18 +130,16 @@ define(function(require) {
if(name){
var index_role = this.list_roles.indexOf(oldName);
if(index_role != -1){
var input = $("#list_roles_select #"+oldName);
var input = $("#list_roles_select #" + oldName);
input[0].id = name;
input[0].value = name;
var label = $("#label_"+oldName)[0];
label.id = "label_"+name;
label.innerHTML = name;
input[0].innerHTML = name;
for(group in this.group_roles_affinity){
var index = this.group_roles_affinity[group].equal(oldName);
if(index != -1){
this.group_roles_affinity[group].changeGroup(index, name);
$("#group_role_" + group)[0].innerHTML = this.group_roles_affinity[group].html();
$(".group_roles").on("click", "i.remove_group_affinity", function() {
$(".group_roles").on("click", "i.remove_group_affinity", function() {
$(this.parentElement.parentElement).remove();
delete that.group_roles_affinity[index];
return false;
@ -153,13 +148,15 @@ define(function(require) {
}
this.list_roles[index_role] = name;
}
else{
else {
this.list_roles.push(name);
var html = "<div>\
<input id='"+ name +"' type='checkbox' class='roles' value="+name+" />\
<label id='label_"+name+"'>"+name+"</label>\
</div>";
var html = "<option id='" + name + "' class='roles' value=" + name + "> " + name + "</option>";
$("#list_roles_select").append(html);
$("select #" + name).mousedown(function(e) {
e.preventDefault();
$(this).prop('selected', !$(this).prop('selected'));
return false;
});
}
}
}
@ -168,7 +165,7 @@ define(function(require) {
if(name){
var index_role = this.list_roles.indexOf(name);
if(index_role != -1){
$("#list_roles_select #"+name)[0].parentElement.remove();
$("#list_roles_select #" + name)[0].remove();
delete this.list_roles[index_role];
for(group in this.group_roles_affinity){
var index = this.group_roles_affinity[group].equal(name);
@ -176,7 +173,7 @@ define(function(require) {
if(this.group_roles_affinity[group].changeGroup(index, "") > 1){
$("#group_role_" + group)[0].innerHTML = this.group_roles_affinity[group].html();
}
else{
else {
$("#group_role_" + group).remove();
delete this.group_roles_affinity[group];
}
@ -192,8 +189,8 @@ define(function(require) {
var group_roles_id = 'group_role_' + group_roles_index;
var group_role = new GroupRoleAffinity(group_roles_id, rolesSt, affinity);
group_roles_affinity[group_roles_index] = group_role;
var html = '<div id="'+group_roles_id+'" class="group_role_content" group_role_id="'+group_roles_index+'">' + group_role.html() + '</div>';
$("#group_vm_roles_"+affinity.toLowerCase()).append(html);
var html = '<div id="' + group_roles_id + '" class="group_role_content" group_role_id="' + group_roles_index + '">' + group_role.html() + '</div>';
$("#group_vm_roles_" + affinity.toLowerCase()).append(html);
$(".group_roles").on("click", "i.remove_group_affinity", function() {
$(this.parentElement.parentElement).remove();
delete group_roles_affinity[index];

View File

@ -12,7 +12,7 @@
</legend>
<div class="row">
<div class="medium-3 columns">
<div class="select_role" id="list_roles_select" style="height: 12em; width: 90%; overflow: auto;"></div>
<select multiple="true" size="3" class="select_role" id="list_roles_select" style="height: 100px; width: 90%; overflow: auto;"></select>
</div>
<div class="medium-1 columns"><br/></div>
<div class="medium-4 columns" style="border-left:thin solid #ada8a8; text-align:center;">