/* -------------------------------------------------------------------------- */
/* 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. */
/* -------------------------------------------------------------------------- */
var create_file_tmpl ='
'
}
Sunstone.addActions(file_actions);
Sunstone.addMainTab('files-tab',files_tab);
Sunstone.addInfoPanel('file_info_panel',file_info_panel);
function fileElements() {
return getSelectedNodes(dataTable_files);
}
// Returns an array containing the values of the file_json and ready
// to be inserted in the dataTable
function fileElementArray(file_json){
//Changing this? It may affect to the is_persistent() functions.
var file = file_json.IMAGE;
// OS || CDROM || DATABLOCK
if (file.TYPE == "0" || file.TYPE == "1" || file.TYPE == "2") {
return false;
}
size_files = size_files + parseInt(file.SIZE);
//add also persistent/non-persistent selects, type select.
return [
'',
file.ID,
file.UNAME,
file.GNAME,
file.NAME,
file.DATASTORE,
file.SIZE,
OpenNebula.Helper.image_type(file.TYPE),
pretty_time(file.REGTIME),
parseInt(file.PERSISTENT) ? "yes" : "no",
OpenNebula.Helper.resource_state("image",file.STATE),
file.RUNNING_VMS,
file.TEMPLATE.TARGET ? file.TEMPLATE.TARGET : '--'
];
}
// Callback to update an element in the dataTable
function updateFileElement(request, file_json){
var id = file_json.IMAGE.ID;
var element = fileElementArray(file_json);
updateSingleElement(element,dataTable_files,'#file_'+id);
}
// Callback to remove an element from the dataTable
function deleteFileElement(req){
deleteElement(dataTable_files,'#file_'+req.request.data);
}
// Callback to add an file element
function addFileElement(request, file_json){
var element = fileElementArray(file_json);
addElement(element,dataTable_files);
}
// Callback to refresh the list of files
function updateFilesView(request, files_list){
var file_list_array = [];
size_files = 0;
$.each(files_list,function(){
var file = fileElementArray(this);
if (file)
file_list_array.push(file);
});
updateView(file_list_array,dataTable_files);
var size = humanize_size_from_mb(size_files)
$(".total_files").text(file_list_array.length);
$(".size_files").text(size);
}
// Callback to update the information panel tabs and pop it up
function updateFileInfo(request,file){
var file_info = file.IMAGE;
var info_tab = {
title : tr("Info"),
icon: "fa-info-circle",
content:
'