\
+
\
+
\
+
\
+
\
+
\
+
Allows hosts belonging to other VDCs to be re-added to this one. They will appear marked with * in the list.
\
+
\
+
\
+
\
+
\
+
\
+ \
+
\
+';
+
var dataTable_vdcs;
+var $update_vdc_dialog;
function vdcSelectedNodes() {
return getSelectedNodes(dataTable_vdcs);
@@ -88,7 +117,7 @@ var vdc_actions = {
},
"VDC.update" : {
- type: "create",
+ type: "single",
call: oZones.VDC.update,
callback: updateVDCElement,
error: onError,
@@ -142,6 +171,12 @@ var vdc_actions = {
call: oZones.Zone.host,
callback: fillHostList,
error: onError
+ },
+ "VDC.update_zone_hosts" : {
+ type: "single",
+ call: oZones.Zone.host,
+ callback: fillUpdateHostList,
+ error: onError
}
};
@@ -156,6 +191,10 @@ var vdc_buttons = {
text: "+ New",
alwaysActive:true
},
+ "VDC.update_dialog" : {
+ type: "action",
+ text: "Add/Remove hosts",
+ },
"VDC.delete" : {
type: "action",
text: "Delete",
@@ -213,6 +252,12 @@ function addVDCElement(req,vdc_json){
addElement(element,dataTable_vdcs);
}
+function updateVDCElement(request, vdc_json){
+ var id = vdc_json.VDC.id;
+ var element = vdcElementArray(vdc_json);
+ updateSingleElement(element,dataTable_vdcs,'#vdc_'+id);
+}
+
function updateVDCsView(req,vdc_list){
var vdc_list_array = [];
@@ -287,6 +332,52 @@ function fillHostList(req, host_list_json){
$('div#create_vdc_dialog #vdc_available_hosts_list').html(list);
}
+//return the array of hosts
+function isHostMine(host_id,vdc_id){
+ //locate myself
+ var vdcs = dataTable_vdcs.fnGetData();
+ var my_hosts=null;
+ for (var i=0; i < vdcs.length; i++){
+ if (vdcs[i][1]==vdc_id){
+ my_hosts = vdcs[i][4].split(',');
+ break;
+ }
+ };
+ if (!my_hosts) return false;
+ return $.inArray(host_id,my_hosts) >= 0;
+}
+
+function fillUpdateHostList(req, host_list_json){
+ var list = "";
+ var list_mine = "";
+ var vdc_id = $('#vdc_update_id',$update_vdc_dialog).val();
+ var force = $('#vdc_update_force_hosts:checked',$update_vdc_dialog).length ?
+ true : false;
+
+ var zone_id = req.request.data[0];
+ var free,li;
+
+ $.each(host_list_json,function(){
+ //if mine, put in mine_list
+ if (isHostMine(this.HOST.ID,vdc_id)){
+ list_mine+='
'+this.HOST.NAME+'';
+ return true; //continue
+ }
+ //otherwise, check if its free etc...
+ free = isHostFree(this.HOST.ID,zone_id);
+
+ if (force || free){
+ list+='
'+(free? this.HOST.NAME : this.HOST.NAME+'*')+'';
+ }
+ });
+
+
+
+ $('#vdc_update_available_hosts_list',$update_vdc_dialog).html(list);
+ $('#vdc_update_selected_hosts_list',$update_vdc_dialog).html(list_mine);
+
+}
+
function isHostFree(id,zone_id){//strings
var data = dataTable_vdcs.fnGetData();
var result = true;
@@ -326,8 +417,8 @@ function setupCreateVDCDialog(){
containment: dialog
});
- $('input#vdc_force_hosts').change(function(){
- select = $('select#zoneid');
+ $('input#vdc_force_hosts',dialog).change(function(){
+ select = $('select#zoneid',$('#create_vdc_dialog'));
if (select.val().length){
select.trigger("change");
}
@@ -355,10 +446,10 @@ function setupCreateVDCDialog(){
var vdcadminname = $('#vdcadminname',$(this)).val();
var vdcadminpass = $('#vdcadminpass',$(this)).val();
var zoneid = $('select#zoneid',$(this)).val();
- var force = $('#vdc_force_hosts',$(this)).length ? "yes" : "please no";
+ var force = $('#vdc_force_hosts:checked',$(this)).length ? "yes" : "please no";
if (!name.length || !vdcadminname.length
|| !vdcadminpass.length || !zoneid.length){
- notifyError("Name, administrator credentials or zones are missing");
+ notifyError("Name, administrator credentials or zone are missing");
return false;
}
var hosts="";
@@ -396,6 +487,119 @@ function openCreateVDCDialog(){
dialog.dialog('open');
}
+function setupUpdateVDCDialog(){
+ $('div#dialogs').append('
');
+ $update_vdc_dialog=$('div#update_vdc_dialog',dialogs_context);
+ var dialog = $update_vdc_dialog;
+ dialog.html(update_vdc_tmpl);
+ dialog.dialog({
+ autoOpen: false,
+ modal: true,
+ width: 500
+ });
+
+ $('button',dialog).button();
+ $('#vdc_update_available_hosts_list',dialog).sortable({
+ connectWith : '#vdc_update_selected_hosts_list',
+ containment: dialog
+ });
+ $('#vdc_update_selected_hosts_list',dialog).sortable({
+ connectWith : '#vdc_update_available_hosts_list',
+ containment: dialog
+ });
+
+ $('#vdc_update_force_hosts',dialog).change(function(){
+ select = $('select#vdc_update_id',$update_vdc_dialog);
+ if (select.val().length){
+ select.trigger("change");
+ }
+ });
+
+ $('select#vdc_update_id').change(function(){
+ var id = $(this).val();
+ var zone_id = $('option:selected',this).attr("zone_id");
+ var av_hosts=
+ $('#vdc_update_available_hosts_list',$update_vdc_dialog);
+ var sel_hosts=
+ $('#vdc_update_selected_hosts_list',$update_vdc_dialog);
+
+ if (!id || !id.length) {
+ av_hosts.empty();
+ sel_hosts.empty();
+ return true;
+ };
+ //A VDC has been selected
+ //Fill in available hosts column
+ //move current hosts to current
+ av_hosts.html('
'+spinner+'');
+ sel_hosts.empty();
+ Sunstone.runAction("VDC.update_zone_hosts",zone_id);
+ });
+
+ $('#update_vdc_form').submit(function(){
+ var force = $('#vdc_update_force_hosts',this).length ? "yes" : "nein";
+ var id = $('#vdc_update_id',this).val();
+
+ var hosts="";
+ $('#vdc_update_selected_hosts_list li',this).each(function(){
+ hosts+=$(this).attr("host_id")+',';
+ });
+ if (hosts.length){
+ hosts= hosts.slice(0,-1);
+ };
+
+ var vdc_json = {
+ "vdc" : {
+ "id": id,
+ "force": force,
+ "hosts": hosts
+ }
+ };
+
+ if (hosts.length){
+ vdc_json["vdc"]["hosts"]=hosts;
+ };
+ Sunstone.runAction("VDC.update",id,vdc_json);
+ dialog.dialog('close');
+ return false;
+ });
+
+}
+
+function openUpdateVDCDialog(){
+ var selected_elems = getSelectedNodes(dataTable_vdcs);
+ //populate select
+ var dialog = $update_vdc_dialog;
+ var options = "";
+ var vdcs = dataTable_vdcs.fnGetData();
+ for (var i = 0; i < vdcs.length; i++){
+ //if this VDC is among the selected
+ if ($.inArray(vdcs[i][1].toString(),selected_elems) >= 0){
+ options += '
';
+ };
+ };
+
+ $('#vdc_update_available_hosts_list',dialog).empty();
+ $('#vdc_update_selected_hosts_list',dialog).empty();
+
+ $('select#vdc_update_id',dialog).html(options);
+ if (selected_elems.length == 1){
+ $('select#vdc_update_id',dialog).html(options);
+ $('select#vdc_update_id option',dialog).attr("checked","checked");
+ $('select#vdc_update_id').trigger("change");
+ } else {
+ $('select#vdc_update_id',dialog).html('
'+
+ options);
+ };
+
+ dialog.dialog('open');
+}
+
function setVDCAutorefresh() {
setInterval(function(){
var checked = $('input:checked',dataTable_zones.fnGetNodes());
@@ -426,6 +630,8 @@ $(document).ready(function(){
setupCreateVDCDialog();
setupTips($('#create_vdc_dialog'));
+ setupUpdateVDCDialog();
+ setupTips($('#update_vdc_dialog'));
setVDCAutorefresh();
initCheckAllBoxes(dataTable_vdcs);
tableCheckboxesListener(dataTable_vdcs);