1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-08 21:17:43 +03:00

feature #3197: Add browser check for uploader functionality

This commit is contained in:
Daniel Molina 2014-10-23 17:59:10 +02:00
parent d41c34b7ab
commit d4b528f8ad
4 changed files with 140 additions and 111 deletions

View File

@ -624,66 +624,71 @@ function setupCreateFileDialog(){
var file_obj;
var file_uploader = new Resumable({
target: '/upload_chunk',
chunkSize: 10*1024*1024,
maxFiles: 1,
testChunks: false,
query: {
csrftoken: csrftoken
}
});
file_uploader.assignBrowse($('#files_file-uploader-input',dialog)[0]);
if (getInternetExplorerVersion() > -1) {
$("#file_uploader").attr("disabled", "disabled");
} else {
var file_uploader = new Resumable({
target: '/upload_chunk',
chunkSize: 10*1024*1024,
maxFiles: 1,
testChunks: false,
query: {
csrftoken: csrftoken
}
});
var fileName = '';
var file_input = false;
file_uploader.assignBrowse($('#files_file-uploader-input',dialog)[0]);
file_uploader.on('fileAdded', function(file){
fileName = file.fileName;
file_input = fileName;
});
var fileName = '';
var file_input = false;
file_uploader.on('uploadStart', function() {
$('#files_upload_progress_bars').append('<div id="files-'+fileName+'-progressBar" class="row" style="margin-bottom:10px">\
<div id="files-'+fileName+'-info" class="large-2 columns dataTables_info">\
'+tr("Uploading...")+'\
</div>\
<div class="large-10 columns">\
<div id="upload_progress_container" class="progress nine radius" style="height:25px !important">\
<span class="meter" style="width:0%"></span>\
file_uploader.on('fileAdded', function(file){
fileName = file.fileName;
file_input = fileName;
});
file_uploader.on('uploadStart', function() {
$('#files_upload_progress_bars').append('<div id="files-'+fileName+'-progressBar" class="row" style="margin-bottom:10px">\
<div id="files-'+fileName+'-info" class="large-2 columns dataTables_info">\
'+tr("Uploading...")+'\
</div>\
<div class="progress-text" style="margin-left:15px">'+fileName+'</div>\
</div>\
</div>');
});
<div class="large-10 columns">\
<div id="upload_progress_container" class="progress nine radius" style="height:25px !important">\
<span class="meter" style="width:0%"></span>\
</div>\
<div class="progress-text" style="margin-left:15px">'+fileName+'</div>\
</div>\
</div>');
});
file_uploader.on('progress', function() {
$('span.meter', $('div[id="files-'+fileName+'-progressBar"]')).css('width', file_uploader.progress()*100.0+'%')
});
file_uploader.on('progress', function() {
$('span.meter', $('div[id="files-'+fileName+'-progressBar"]')).css('width', file_uploader.progress()*100.0+'%')
});
file_uploader.on('fileSuccess', function(file) {
$('div[id="files-'+fileName+'-info"]').text(tr('Registering in OpenNebula'));
$.ajax({
url: '/upload',
type: "POST",
data: {
csrftoken: csrftoken,
img : JSON.stringify(file_obj),
file: fileName,
tempfile: file.uniqueIdentifier
},
success: function(){
notifyMessage("File uploaded correctly");
$('div[id="files-'+fileName+'-progressBar"]').remove();
Sunstone.runAction("File.refresh");
},
error: function(response){
onError({}, OpenNebula.Error(response));
$('div[id="files-'+fileName+'-progressBar"]').remove();
}
});
});
file_uploader.on('fileSuccess', function(file) {
$('div[id="files-'+fileName+'-info"]').text(tr('Registering in OpenNebula'));
$.ajax({
url: '/upload',
type: "POST",
data: {
csrftoken: csrftoken,
img : JSON.stringify(file_obj),
file: fileName,
tempfile: file.uniqueIdentifier
},
success: function(){
notifyMessage("File uploaded correctly");
$('div[id="files-'+fileName+'-progressBar"]').remove();
Sunstone.runAction("File.refresh");
},
error: function(response){
onError({}, OpenNebula.Error(response));
$('div[id="files-'+fileName+'-progressBar"]').remove();
}
});
});
}
$('#create_file_form_easy',dialog).submit(function(){
var upload = false;

View File

@ -926,66 +926,70 @@ function initialize_create_image_dialog(dialog) {
var img_obj;
var uploader = new Resumable({
target: '/upload_chunk',
chunkSize: 10*1024*1024,
maxFiles: 1,
testChunks: false,
query: {
csrftoken: csrftoken
}
});
if (getInternetExplorerVersion() > -1) {
$("#upload_image").attr("disabled", "disabled");
} else {
var uploader = new Resumable({
target: '/upload_chunk',
chunkSize: 10*1024*1024,
maxFiles: 1,
testChunks: false,
query: {
csrftoken: csrftoken
}
});
uploader.assignBrowse($('#file-uploader-input',dialog));
uploader.assignBrowse($('#file-uploader-input',dialog));
var fileName = '';
var file_input = false;
var fileName = '';
var file_input = false;
uploader.on('fileAdded', function(file){
fileName = file.fileName;
file_input = fileName;
});
uploader.on('fileAdded', function(file){
fileName = file.fileName;
file_input = fileName;
});
uploader.on('uploadStart', function() {
$('#upload_progress_bars').append('<div id="'+fileName+'progressBar" class="row" style="margin-bottom:10px">\
<div id="'+fileName+'-info" class="large-2 columns dataTables_info">\
'+tr("Uploading...")+'\
</div>\
<div class="large-10 columns">\
<div id="upload_progress_container" class="progress nine radius" style="height:25px !important">\
<span class="meter" style="width:0%"></span>\
uploader.on('uploadStart', function() {
$('#upload_progress_bars').append('<div id="'+fileName+'progressBar" class="row" style="margin-bottom:10px">\
<div id="'+fileName+'-info" class="large-2 columns dataTables_info">\
'+tr("Uploading...")+'\
</div>\
<div class="progress-text" style="margin-left:15px">'+fileName+'</div>\
</div>\
</div>');
});
<div class="large-10 columns">\
<div id="upload_progress_container" class="progress nine radius" style="height:25px !important">\
<span class="meter" style="width:0%"></span>\
</div>\
<div class="progress-text" style="margin-left:15px">'+fileName+'</div>\
</div>\
</div>');
});
uploader.on('progress', function() {
$('span.meter', $('div[id="'+fileName+'progressBar"]')).css('width', uploader.progress()*100.0+'%')
});
uploader.on('progress', function() {
$('span.meter', $('div[id="'+fileName+'progressBar"]')).css('width', uploader.progress()*100.0+'%')
});
uploader.on('fileSuccess', function(file) {
$('div[id="'+fileName+'-info"]').text(tr('Registering in OpenNebula'));
$.ajax({
url: '/upload',
type: "POST",
data: {
csrftoken: csrftoken,
img : JSON.stringify(img_obj),
file: fileName,
tempfile: file.uniqueIdentifier
},
success: function(){
notifyMessage("Image uploaded correctly");
$('div[id="'+fileName+'progressBar"]').remove();
Sunstone.runAction("Image.refresh");
},
error: function(response){
onError({}, OpenNebula.Error(response));
$('div[id="'+fileName+'progressBar"]').remove();
}
});
});
uploader.on('fileSuccess', function(file) {
$('div[id="'+fileName+'-info"]').text(tr('Registering in OpenNebula'));
$.ajax({
url: '/upload',
type: "POST",
data: {
csrftoken: csrftoken,
img : JSON.stringify(img_obj),
file: fileName,
tempfile: file.uniqueIdentifier
},
success: function(){
notifyMessage("Image uploaded correctly");
$('div[id="'+fileName+'progressBar"]').remove();
Sunstone.runAction("Image.refresh");
},
error: function(response){
onError({}, OpenNebula.Error(response));
$('div[id="'+fileName+'progressBar"]').remove();
}
});
});
}
$('#create_image',dialog).submit(function(){
$create_image_dialog = dialog;

View File

@ -130,10 +130,10 @@ var support_actions = {
type: "custom",
call: function(){
Sunstone.popUpFormPanel(
"create_support_request_form",
"support-tab",
"create",
false,
"create_support_request_form",
"support-tab",
"create",
false,
function(context){});
}
},
@ -209,7 +209,7 @@ var support_buttons = {
var support_tab = {
//title: '<i class="fa fa-lg fa-fw fa-support"></i>&emsp;Support"),
title:
title:
'<span class="support_title"><i class="fa fa-lg fa-fw fa-support"></i> Support</span>' +
'<br>'+
'<div class="support_info" style="display: none;">'+
@ -352,6 +352,10 @@ function setup_upload_support_file_dialog() {
dialog.addClass("reveal-modal").attr("data-reveal", "");
$vnc_dialog.foundation();
if (getInternetExplorerVersion() > -1) {
$(".upload_support_file_form_button").text("Uploading files through IE is not supported");
$(".upload_support_file_form_button").attr("disabled", "disabled");
} else {
var uploader = new Resumable({
target: '/upload_chunk',
chunkSize: 10*1024*1024,
@ -420,6 +424,7 @@ function setup_upload_support_file_dialog() {
$upload_support_file.foundation("reveal", "close")
return false;
})
}
}
function initialize_create_support_request_dialog() {

View File

@ -6614,3 +6614,18 @@ function generateAdvancedSection(opts){
'</div>'+
'</div>';
}
function getInternetExplorerVersion(){
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
return rv;
}