/**
* Load the files page
*/
function loadFilesPage() {
var tabId = 'filesTab';
$('#' + tabId).empty();
// Set padding for page
$('#' + tabId).css('padding', '10px 30px');
// Create info bar
var info = $('#' + tabId).find('.ui-state-highlight');
// If there is no info bar
if (!info.length) {
var infoBar = createInfoBar('Below is a listing of the xCAT repository. ' +
'Upload any file or package into the repository using the Upload button. ' +
'Go into any subdirectories by specifying the directory path and clicking on Go.');
var directoryFS = $('
');
var dirLegend = $('');
directoryFS.append(dirLegend);
// Division to hold directory actions
var actions = $('');
directoryFS.append(actions);
// Create button to create a directory
var folderBtn = createButton('New folder');
folderBtn.click(function() {
var deleteFolderBtn = $('');
var createFolderBtn = createButton('Create');
// Create a new directory
var newFolder = $('
');
newFolder.prepend(deleteFolderBtn);
newFolder.append(createFolderBtn);
$('#repo_content ul').append(newFolder);
// Delete new folder on-click
deleteFolderBtn.click(function() {
$(this).parents('li').remove();
});
// Create folder on-click
createFolderBtn.click(function() {
var directory = $('#' + tabId + ' input[name="repo_directory"]');
var newFolderPath = $('#' + tabId + ' input[name="new_folder"]').val();
if (newFolderPath) {
$.ajax({
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'webrun',
tgt : '',
args : 'createfolder;' + directory.val() + '/' + newFolderPath,
msg : ''
},
success:function(data) {
data = decodeRsp(data);
openDialog('info', data.rsp[0]);
}
});
$(this).parents('li').remove();
} else {
openDialog('warn', 'You must specify the folder name');
}
});
});
// Create button to upload files
var uploadBtn = createButton('Upload');
uploadBtn.click(function() {
var directory = $('#' + tabId + ' input[name="repo_directory"]');
openUploadDialog(directory.val());
});
// Create button to go into a directory path
var dirPath = $('');
var goBtn = createButton('Go');
goBtn.click(function() {
var directory = $('#' + tabId + ' input[name="repo_directory"]');
loadPath(directory.val());
});
goBtn.attr('id', 'go_to_path');
var space = $('');
var content = $('');
actions.append(folderBtn, uploadBtn, dirPath, goBtn);
directoryFS.append(space, content);
$('#' + tabId).append(infoBar, directoryFS);
}
// Retrieve repository space
getRepositorySpace();
// Retrieve files from /install
loadPath('/install');
}
/**
* Get the repository space
*/
function getRepositorySpace() {
// Grab repository space
$.ajax({
url : 'lib/cmd.php',
dataType : 'json',
async: false,
data : {
cmd : 'webrun',
tgt : '',
args : 'getrepospace',
msg : ''
},
success: function(data) {
data = decodeRsp(data);
$('#repo_space').children().remove();
// Data returned is: size, used, available, used %, mount
// Data could be in a different format in CMO, where it puts the directory on the line
// "rsp":["\/data\/xcat\/install 28G 6.0G 20G 24% \/install"],"msg":null}
var space = data.rsp[0].split(' ');
if (space.length == 6) {
space.splice(0,1);
}
var spaceLabel = $('');
$('#repo_space').append(spaceLabel);
}
});
}
/**
* Open a dialog to upload files into the repository
*
* @param destDirectory The destination directory
*/
function openUploadDialog(destDirectory) {
// Create info bar
var info = createInfoBar('Select a file to upload onto ' + destDirectory + '.');
var dialog = $('');
dialog.append(info);
// Upload file
var upload = $('');
var label = $('');
var file = $('');
var subBtn = createButton('Upload');
upload.append(label, file, subBtn);
dialog.append(upload);
upload.submit(function() {
// Create status bar, hide on load
var statBarId = 'uploadStatusBar';
var statBar = createStatusBar(statBarId);
var loader = createLoader('');
statBar.find('div').append('Do not close this dialog while the file is being uploaded ');
statBar.find('div').append(loader);
statBar.prependTo($('#upload_file_dg'));
var data = new FormData($('#upload_file')[0]);
$.ajax({
type: 'POST',
url : 'lib/uploadfile.php?destination=' + destDirectory,
data: data,
success: function(data) {
$('#uploadStatusBar').find('img').hide();
$('#uploadStatusBar').find('div').empty();
$('#uploadStatusBar').find('div').append(data);
// Refresh directory contents
$('#go_to_path').click();
getRepositorySpace();
},
cache: false,
contentType: false,
processData: false
});
return false;
});
// Create dialog
dialog.dialog({
modal: true,
title: 'Upload',
width: 500,
close: function() {$(this).remove();}
});
}
/**
* Load the directory path structure
*
* @path The directory path
*/
function loadPath(path) {
// Limit access to only /install
if (path.substring(0, 9).indexOf("install") == -1) {
openDialog('warn', 'You are not authorized to browse outside the repository');
return;
}
var tabId = 'filesTab';
var directory = $('#' + tabId + ' input[name="repo_directory"]');
directory.val(path);
// Un-ordered list containing directories and files
var contentId = 'repo_content';
$('#' + contentId).empty();
var itemsList = $('
');
$('#' + contentId).append(itemsList);
// Back button to go up a directory
var item = $('
..
');
itemsList.append(item);
item.dblclick(function() {
if (path.lastIndexOf('/') > 1)
path = path.substring(0, path.lastIndexOf('/'));
loadPath(path);
});
$.ajax({
type: 'POST',
url : 'lib/getpath.php',
dataType : 'json',
data: {
action: 'browse',
path: path,
time: new Date().getTime()
},
beforeSend: function() {
// Show loading image
},
success: function(files) {
$.each(files, function(index, file) {
if (!file.path || file.path.indexOf("undefined"))
file.path = "";
var fullPath = file.path + "/" + file.name;
// Create a list showing the directories and files
var item;
if (file.isFolder) {
var deleteFolderBtn = $('');
item = $('