]> source.dussan.org Git - nextcloud-server.git/commitdiff
notifications are now shown/hidden using the js functions hideNotification and showNo...
authorThomas Mueller <thomas.mueller@tmit.eu>
Wed, 2 Jan 2013 14:09:40 +0000 (15:09 +0100)
committerThomas Mueller <thomas.mueller@tmit.eu>
Wed, 2 Jan 2013 14:09:40 +0000 (15:09 +0100)
storage warnings are displayed in a notification.
as soon as a notification is hidden the storage warning will come back.

apps/files/js/filelist.js
apps/files/js/files.js

index 96dd0323d29a4b463ca96d2f6c789fc63a0deb91..031c58e724c00f852ca19cf2536e68f2226fe43d 100644 (file)
@@ -195,15 +195,14 @@ var FileList={
        },
        checkName:function(oldName, newName, isNewFile) {
                if (isNewFile || $('tr').filterAttr('data-file', newName).length > 0) {
-                       if (isNewFile) {
-                               $('#notification').html(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 {
-                               $('#notification').html(t('files', '{new_name} already exists', {new_name: escapeHTML(newName)})+'<span class="replace">'+t('files', 'replace')+'</span><span class="cancel">'+t('files', 'cancel')+'</span>');
-                       }
                        $('#notification').data('oldName', oldName);
                        $('#notification').data('newName', newName);
                        $('#notification').data('isNewFile', isNewFile);
-                       $('#notification').fadeIn();
+            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>');
+            } 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>');
+            }
                        return true;
                } else {
                        return false;
@@ -245,11 +244,10 @@ var FileList={
                        FileList.finishReplace();
                };
                if (isNewFile) {
-                       $('#notification').html(t('files', 'replaced {new_name}', {new_name: newName})+'<span class="undo">'+t('files', 'undo')+'</span>');
+                       Files.showHtmlNotification(t('files', 'replaced {new_name}', {new_name: newName})+'<span class="undo">'+t('files', 'undo')+'</span>');
                } else {
-                       $('#notification').html(t('files', 'replaced {new_name} with {old_name}', {new_name: newName}, {old_name: oldName})+'<span class="undo">'+t('files', 'undo')+'</span>');
+            Files.showHtmlNotification(t('files', 'replaced {new_name} with {old_name}', {new_name: newName}, {old_name: oldName})+'<span class="undo">'+t('files', 'undo')+'</span>');
                }
-               $('#notification').fadeIn();
        },
        finishReplace:function() {
                if (!FileList.replaceCanceled && FileList.replaceOldName && FileList.replaceNewName) {
@@ -279,11 +277,10 @@ var FileList={
                } else {
                        // NOTE: Temporary fix to change the text to unshared for files in root of Shared folder
                        if ($('#dir').val() == '/Shared') {
-                               $('#notification').html(t('files', 'unshared {files}', {'files': escapeHTML(files)})+'<span class="undo">'+t('files', 'undo')+'</span>');
+                               Files.showHtmlNotification(t('files', 'unshared {files}', {'files': escapeHTML(files)})+'<span class="undo">'+t('files', 'undo')+'</span>');
                        } else {
-                               $('#notification').html(t('files', 'deleted {files}', {'files': escapeHTML(files)})+'<span class="undo">'+t('files', 'undo')+'</span>');
+                Files.showHtmlNotification(t('files', 'deleted {files}', {'files': escapeHTML(files)})+'<span class="undo">'+t('files', 'undo')+'</span>');
                        }
-                       $('#notification').fadeIn();
                }
        },
        finishDelete:function(ready,sync){
@@ -296,7 +293,7 @@ var FileList={
                                data: {dir:$('#dir').val(),files:fileNames},
                                complete: function(data){
                                        boolOperationFinished(data, function(){
-                                               $('#notification').fadeOut('400');
+                        Files.hideNotification();
                                                $.each(FileList.deleteFiles,function(index,file){
                                                        FileList.remove(file);
                                                });
@@ -356,16 +353,16 @@ $(document).ready(function(){
                        FileList.replaceIsNewFile = null;
                }
                FileList.lastAction = null;
-               $('#notification').fadeOut('400');
+        Files.hideNotification();
        });
        $('#notification .replace').live('click', function() {
-               $('#notification').fadeOut('400', function() {
-                       FileList.replace($('#notification').data('oldName'), $('#notification').data('newName'), $('#notification').data('isNewFile'));
-               });
+        Files.hideNotification(function() {
+            FileList.replace($('#notification').data('oldName'), $('#notification').data('newName'), $('#notification').data('isNewFile'));
+        });
        });
        $('#notification .suggest').live('click', function() {
                $('tr').filterAttr('data-file', $('#notification').data('oldName')).show();
-               $('#notification').fadeOut('400');
+        Files.hideNotification();
        });
        $('#notification .cancel').live('click', function() {
                if ($('#notification').data('isNewFile')) {
index 6a37d9e7f538fdebcb0760d81b80da01019e2ee9..6023cf78e797c3fb7289e3c37e36dee53ffe3869 100644 (file)
@@ -30,14 +30,45 @@ Files={
                var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*'];
                for (var i = 0; i < invalid_characters.length; i++) {
                        if (name.indexOf(invalid_characters[i]) != -1) {
-                               $('#notification').text(t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed."));
-                               $('#notification').fadeIn();
+                               Files.showNotification(t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed."));
                                return true;
                        }
                }
-               $('#notification').fadeOut();
+        Files.hideNotification();
                return false;
-       }
+       },
+    displayStorageWarnings: function() {
+        var usedSpacePercent = $('#usedSpacePercent').val();
+        if (usedSpacePercent > 98) {
+            Files.showNotification(t('files', 'Your storage is full, files can not be updated or synced anymore!'));
+            return;
+        }
+        if (usedSpacePercent > 90) {
+            Files.showNotification(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() {
        Files.bindKeyboardShortcuts(document, jQuery); 
@@ -171,8 +202,7 @@ $(document).ready(function() {
        $('.download').click('click',function(event) {
                var files=getSelectedFiles('name').join(';');
                var dir=$('#dir').val()||'/';
-               $('#notification').text(t('files','generating ZIP-file, it may take some time.'));
-               $('#notification').fadeIn();
+        Files.showNotification(t('files','generating ZIP-file, it may take some time.'));
                // use special download URL if provided, e.g. for public shared files
                if ( (downloadURL = document.getElementById("downloadURL")) ) {
                        window.location=downloadURL.value+"&download&files="+files;
@@ -301,8 +331,7 @@ $(document).ready(function() {
                                                                                        var response;
                                                                                        response=jQuery.parseJSON(result);
                                                                                        if(response[0] == undefined || response[0].status != 'success') {
-                                                                                               $('#notification').text(t('files', response.data.message));
-                                                                                               $('#notification').fadeIn();
+                                                Files.showNotification(t('files', response.data.message));
                                                                                        }
                                                                                        var file=response[0];
                                             // TODO: this doesn't work if the file name has been changed server side
@@ -339,9 +368,7 @@ $(document).ready(function() {
                                                                                } else {
                                                                                        uploadtext.text(t('files', '{count} files uploading', {count: currentUploads}));
                                                                                }
-                                                                               $('#notification').hide();
-                                                                               $('#notification').text(t('files', 'Upload cancelled.'));
-                                                                               $('#notification').fadeIn();
+                                        Files.showNotification(t('files', 'Upload cancelled.'));
                                                                        }
                                                                });
                                                                //TODO test with filenames containing slashes
@@ -364,17 +391,14 @@ $(document).ready(function() {
                                                                                                }
                                                                                                FileList.loadingDone(file.name, file.id);
                                                                                        } else {
-                                                                                               $('#notification').text(t('files', response.data.message));
-                                                                                               $('#notification').fadeIn();
+                                                Files.showNotification(t('files', response.data.message));
                                                                                                $('#fileList > tr').not('[data-mime]').fadeOut();
                                                                                                $('#fileList > tr').not('[data-mime]').remove();
                                                                                        }
                                                                                })
                                                                .error(function(jqXHR, textStatus, errorThrown) {
                                                                        if(errorThrown === 'abort') {
-                                                                               $('#notification').hide();
-                                                                               $('#notification').text(t('files', 'Upload cancelled.'));
-                                                                               $('#notification').fadeIn();
+                                        Files.showNotification(t('files', 'Upload cancelled.'));
                                                                        }
                                                                });
                                                                uploadingFiles[uniqueName] = jqXHR;
@@ -394,8 +418,7 @@ $(document).ready(function() {
                                                                }
                                                                FileList.loadingDone(file.name, file.id);
                                                        } else {
-                                                               $('#notification').text(t('files', response.data.message));
-                                                               $('#notification').fadeIn();
+                                Files.showNotification(t('files', response.data.message));
                                                                $('#fileList > tr').not('[data-mime]').fadeOut();
                                                                $('#fileList > tr').not('[data-mime]').remove();
                                                        }
@@ -512,8 +535,7 @@ $(document).ready(function() {
                        if (type != 'web' && Files.containsInvalidCharacters($(this).val())) {
                                return;
                        } else if( type == 'folder' && $('#dir').val() == '/' && $(this).val() == 'Shared') {
-                               $('#notification').text(t('files','Invalid folder name. Usage of "Shared" is reserved by Owncloud'));
-                               $('#notification').fadeIn();
+                Files.showNotification(t('files','Invalid folder name. Usage of "Shared" is reserved by Owncloud'));
                                return;
                        }
                        if (FileList.lastAction) {
@@ -683,6 +705,9 @@ $(document).ready(function() {
        });
 
        resizeBreadcrumbs(true);
+
+    // display storage warnings
+    setTimeout ( "Files.displayStorageWarnings()", 100 );
 });
 
 function scanFiles(force,dir){