/* -------------------------------------------------------------------------- */
/* Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
/*Images tab plugin*/
size_images = 0;
var create_image_tmpl ='
'
}
Sunstone.addActions(image_actions);
Sunstone.addMainTab('images-tab',images_tab);
Sunstone.addInfoPanel('image_info_panel',image_info_panel);
function imageElements() {
return getSelectedNodes(dataTable_images);
}
// Returns an array containing the values of the image_json and ready
// to be inserted in the dataTable
function imageElementArray(image_json){
//Changing this? It may affect to the is_persistent() functions.
var image = image_json.IMAGE;
// KERNEL || RAMDISK || CONTEXT
if (image.TYPE == "3" || image.TYPE == "4" || image.TYPE == "5") {
return false;
}
size_images = size_images + parseInt(image.SIZE);
//add also persistent/non-persistent selects, type select.
return [
'',
image.ID,
image.UNAME,
image.GNAME,
image.NAME,
image.DATASTORE,
image.SIZE,
OpenNebula.Helper.image_type(image.TYPE),
pretty_time(image.REGTIME),
parseInt(image.PERSISTENT) ? "yes" : "no",
OpenNebula.Helper.resource_state("image",image.STATE),
image.RUNNING_VMS,
image.TEMPLATE.TARGET ? image.TEMPLATE.TARGET : '--'
];
}
// Callback to update an element in the dataTable
function updateImageElement(request, image_json){
var id = image_json.IMAGE.ID;
var element = imageElementArray(image_json);
updateSingleElement(element,dataTable_images,'#image_'+id);
}
// Callback to remove an element from the dataTable
function deleteImageElement(req){
deleteElement(dataTable_images,'#image_'+req.request.data);
}
// Callback to add an image element
function addImageElement(request, image_json){
var element = imageElementArray(image_json);
addElement(element,dataTable_images);
}
// Callback to refresh the list of images
function updateImagesView(request, images_list){
var image_list_array = [];
size_images = 0;
$.each(images_list,function(){
var image = imageElementArray(this);
if (image)
image_list_array.push(image);
});
updateView(image_list_array,dataTable_images);
var size = humanize_size_from_mb(size_images)
$(".total_images").text(image_list_array.length);
$(".size_images").text(size);
}
// Callback to update the information panel tabs and pop it up
function updateImageInfo(request,img){
var img_info = img.IMAGE;
var info_tab = {
title : tr("Info"),
icon: "fa-info-circle",
content:
'