javascript notification functions have been moved to js.js for common use

This commit is contained in:
Thomas Mueller 2013-01-04 23:34:09 +01:00
parent 48f6dccdb7
commit ba475d4862
3 changed files with 52 additions and 43 deletions

View File

@ -199,9 +199,9 @@ var FileList={
$('#notification').data('newName', newName); $('#notification').data('newName', newName);
$('#notification').data('isNewFile', isNewFile); $('#notification').data('isNewFile', isNewFile);
if (isNewFile) { if (isNewFile) {
Files.showHtmlNotification(t('files', '{new_name} already exists', {new_name: escapeHTML(newName)})+'<span class="replace">'+t('files', 'replace')+'</span><span class="suggest">'+t('files', 'suggest name')+'</span><span class="cancel">'+t('files', 'cancel')+'</span>'); OC.Notification.showHtml(t('files', '{new_name} already exists', {new_name: escapeHTML(newName)})+'<span class="replace">'+t('files', 'replace')+'</span><span class="suggest">'+t('files', 'suggest name')+'</span><span class="cancel">'+t('files', 'cancel')+'</span>');
} else { } else {
Files.showHtmlNotification(t('files', '{new_name} already exists', {new_name: escapeHTML(newName)})+'<span class="replace">'+t('files', 'replace')+'</span><span class="cancel">'+t('files', 'cancel')+'</span>'); OC.Notification.showHtml(t('files', '{new_name} already exists', {new_name: escapeHTML(newName)})+'<span class="replace">'+t('files', 'replace')+'</span><span class="cancel">'+t('files', 'cancel')+'</span>');
} }
return true; return true;
} else { } else {
@ -244,9 +244,9 @@ var FileList={
FileList.finishReplace(); FileList.finishReplace();
}; };
if (isNewFile) { if (isNewFile) {
Files.showHtmlNotification(t('files', 'replaced {new_name}', {new_name: newName})+'<span class="undo">'+t('files', 'undo')+'</span>'); OC.Notification.showHtml(t('files', 'replaced {new_name}', {new_name: newName})+'<span class="undo">'+t('files', 'undo')+'</span>');
} else { } else {
Files.showHtmlNotification(t('files', 'replaced {new_name} with {old_name}', {new_name: newName}, {old_name: oldName})+'<span class="undo">'+t('files', 'undo')+'</span>'); OC.Notification.showHtml(t('files', 'replaced {new_name} with {old_name}', {new_name: newName}, {old_name: oldName})+'<span class="undo">'+t('files', 'undo')+'</span>');
} }
}, },
finishReplace:function() { finishReplace:function() {
@ -277,9 +277,9 @@ var FileList={
} else { } else {
// NOTE: Temporary fix to change the text to unshared for files in root of Shared folder // NOTE: Temporary fix to change the text to unshared for files in root of Shared folder
if ($('#dir').val() == '/Shared') { if ($('#dir').val() == '/Shared') {
Files.showHtmlNotification(t('files', 'unshared {files}', {'files': escapeHTML(files)})+'<span class="undo">'+t('files', 'undo')+'</span>'); OC.Notification.showHtml(t('files', 'unshared {files}', {'files': escapeHTML(files)})+'<span class="undo">'+t('files', 'undo')+'</span>');
} else { } else {
Files.showHtmlNotification(t('files', 'deleted {files}', {'files': escapeHTML(files)})+'<span class="undo">'+t('files', 'undo')+'</span>'); OC.Notification.showHtml(t('files', 'deleted {files}', {'files': escapeHTML(files)})+'<span class="undo">'+t('files', 'undo')+'</span>');
} }
} }
}, },
@ -293,7 +293,7 @@ var FileList={
data: {dir:$('#dir').val(),files:fileNames}, data: {dir:$('#dir').val(),files:fileNames},
complete: function(data){ complete: function(data){
boolOperationFinished(data, function(){ boolOperationFinished(data, function(){
Files.hideNotification(); OC.Notification.hide();
$.each(FileList.deleteFiles,function(index,file){ $.each(FileList.deleteFiles,function(index,file){
FileList.remove(file); FileList.remove(file);
}); });
@ -353,16 +353,16 @@ $(document).ready(function(){
FileList.replaceIsNewFile = null; FileList.replaceIsNewFile = null;
} }
FileList.lastAction = null; FileList.lastAction = null;
Files.hideNotification(); OC.Notification.hide();
}); });
$('#notification .replace').live('click', function() { $('#notification .replace').live('click', function() {
Files.hideNotification(function() { OC.Notification.hide(function() {
FileList.replace($('#notification').data('oldName'), $('#notification').data('newName'), $('#notification').data('isNewFile')); FileList.replace($('#notification').data('oldName'), $('#notification').data('newName'), $('#notification').data('isNewFile'));
}); });
}); });
$('#notification .suggest').live('click', function() { $('#notification .suggest').live('click', function() {
$('tr').filterAttr('data-file', $('#notification').data('oldName')).show(); $('tr').filterAttr('data-file', $('#notification').data('oldName')).show();
Files.hideNotification(); OC.Notification.hide();
}); });
$('#notification .cancel').live('click', function() { $('#notification .cancel').live('click', function() {
if ($('#notification').data('isNewFile')) { if ($('#notification').data('isNewFile')) {

View File

@ -30,45 +30,23 @@ Files={
var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*']; var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*'];
for (var i = 0; i < invalid_characters.length; i++) { for (var i = 0; i < invalid_characters.length; i++) {
if (name.indexOf(invalid_characters[i]) != -1) { if (name.indexOf(invalid_characters[i]) != -1) {
Files.showNotification(t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed.")); OC.Notification.show(t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed."));
return true; return true;
} }
} }
Files.hideNotification(); OC.Notification.hide();
return false; return false;
}, },
displayStorageWarnings: function() { displayStorageWarnings: function() {
var usedSpacePercent = $('#usedSpacePercent').val(); var usedSpacePercent = $('#usedSpacePercent').val();
if (usedSpacePercent > 98) { if (usedSpacePercent > 98) {
Files.showNotification(t('files', 'Your storage is full, files can not be updated or synced anymore!')); OC.Notification.show(t('files', 'Your storage is full, files can not be updated or synced anymore!'));
return; return;
} }
if (usedSpacePercent > 90) { if (usedSpacePercent > 90) {
Files.showNotification(t('files', 'Your storage is almost full ({usedSpacePercent}%)', {usedSpacePercent: usedSpacePercent})); OC.Notification.show(t('files', 'Your storage is almost full ({usedSpacePercent}%)', {usedSpacePercent: usedSpacePercent}));
} }
},
hideNotification: function(callback) {
$("#notification").text('');
$('#notification').fadeOut('400', function(){
if ($("#notification").text() === '') {
Files.displayStorageWarnings();
}
if (callback) {
callback.call();
}
});
},
showHtmlNotification: function(html) {
$('#notification').hide();
$("#notification").html(html);
$("#notification").fadeIn();
},
showNotification: function(text) {
$('#notification').hide();
$("#notification").text(text);
$("#notification").fadeIn();
} }
}; };
$(document).ready(function() { $(document).ready(function() {
Files.bindKeyboardShortcuts(document, jQuery); Files.bindKeyboardShortcuts(document, jQuery);
@ -202,7 +180,7 @@ $(document).ready(function() {
$('.download').click('click',function(event) { $('.download').click('click',function(event) {
var files=getSelectedFiles('name').join(';'); var files=getSelectedFiles('name').join(';');
var dir=$('#dir').val()||'/'; var dir=$('#dir').val()||'/';
Files.showNotification(t('files','generating ZIP-file, it may take some time.')); OC.Notification.show(t('files','generating ZIP-file, it may take some time.'));
// use special download URL if provided, e.g. for public shared files // use special download URL if provided, e.g. for public shared files
if ( (downloadURL = document.getElementById("downloadURL")) ) { if ( (downloadURL = document.getElementById("downloadURL")) ) {
window.location=downloadURL.value+"&download&files="+files; window.location=downloadURL.value+"&download&files="+files;
@ -331,7 +309,7 @@ $(document).ready(function() {
var response; var response;
response=jQuery.parseJSON(result); response=jQuery.parseJSON(result);
if(response[0] == undefined || response[0].status != 'success') { if(response[0] == undefined || response[0].status != 'success') {
Files.showNotification(t('files', response.data.message)); OC.Notification.show(t('files', response.data.message));
} }
var file=response[0]; var file=response[0];
// TODO: this doesn't work if the file name has been changed server side // TODO: this doesn't work if the file name has been changed server side
@ -368,7 +346,7 @@ $(document).ready(function() {
} else { } else {
uploadtext.text(t('files', '{count} files uploading', {count: currentUploads})); uploadtext.text(t('files', '{count} files uploading', {count: currentUploads}));
} }
Files.showNotification(t('files', 'Upload cancelled.')); OC.Notification.show(t('files', 'Upload cancelled.'));
} }
}); });
//TODO test with filenames containing slashes //TODO test with filenames containing slashes
@ -391,14 +369,14 @@ $(document).ready(function() {
} }
FileList.loadingDone(file.name, file.id); FileList.loadingDone(file.name, file.id);
} else { } else {
Files.showNotification(t('files', response.data.message)); OC.Notification.show(t('files', response.data.message));
$('#fileList > tr').not('[data-mime]').fadeOut(); $('#fileList > tr').not('[data-mime]').fadeOut();
$('#fileList > tr').not('[data-mime]').remove(); $('#fileList > tr').not('[data-mime]').remove();
} }
}) })
.error(function(jqXHR, textStatus, errorThrown) { .error(function(jqXHR, textStatus, errorThrown) {
if(errorThrown === 'abort') { if(errorThrown === 'abort') {
Files.showNotification(t('files', 'Upload cancelled.')); OC.Notification.show(t('files', 'Upload cancelled.'));
} }
}); });
uploadingFiles[uniqueName] = jqXHR; uploadingFiles[uniqueName] = jqXHR;
@ -418,7 +396,7 @@ $(document).ready(function() {
} }
FileList.loadingDone(file.name, file.id); FileList.loadingDone(file.name, file.id);
} else { } else {
Files.showNotification(t('files', response.data.message)); OC.Notification.show(t('files', response.data.message));
$('#fileList > tr').not('[data-mime]').fadeOut(); $('#fileList > tr').not('[data-mime]').fadeOut();
$('#fileList > tr').not('[data-mime]').remove(); $('#fileList > tr').not('[data-mime]').remove();
} }
@ -535,7 +513,7 @@ $(document).ready(function() {
if (type != 'web' && Files.containsInvalidCharacters($(this).val())) { if (type != 'web' && Files.containsInvalidCharacters($(this).val())) {
return; return;
} else if( type == 'folder' && $('#dir').val() == '/' && $(this).val() == 'Shared') { } else if( type == 'folder' && $('#dir').val() == '/' && $(this).val() == 'Shared') {
Files.showNotification(t('files','Invalid folder name. Usage of "Shared" is reserved by Owncloud')); OC.Notification.show(t('files','Invalid folder name. Usage of "Shared" is reserved by Owncloud'));
return; return;
} }
if (FileList.lastAction) { if (FileList.lastAction) {
@ -708,6 +686,7 @@ $(document).ready(function() {
// display storage warnings // display storage warnings
setTimeout ( "Files.displayStorageWarnings()", 100 ); setTimeout ( "Files.displayStorageWarnings()", 100 );
OC.Notification.setDefault(Files.displayStorageWarnings);
}); });
function scanFiles(force,dir){ function scanFiles(force,dir){

View File

@ -289,6 +289,36 @@ OC.search.lastResults={};
OC.addStyle.loaded=[]; OC.addStyle.loaded=[];
OC.addScript.loaded=[]; OC.addScript.loaded=[];
OC.Notification={
getDefaultNotificationFunction: null,
setDefault: function(callback) {
OC.Notification.getDefaultNotificationFunction = callback;
},
hide: function(callback) {
$("#notification").text('');
$('#notification').fadeOut('400', function(){
if ($("#notification").text() === '') {
if (OC.Notification.getDefaultNotificationFunction) {
OC.Notification.getDefaultNotificationFunction.call();
}
}
if (callback) {
callback.call();
}
});
},
showHtml: function(html) {
$('#notification').hide();
$('#notification').html(html);
$('#notification').fadeIn();
},
show: function(text) {
$('#notification').hide();
$('#notification').text(text);
$('#notification').fadeIn();
}
};
OC.Breadcrumb={ OC.Breadcrumb={
container:null, container:null,
crumbs:[], crumbs:[],