diff --git a/js/galleryview.js b/js/galleryview.js index ef94fda88a..55e5589241 100644 --- a/js/galleryview.js +++ b/js/galleryview.js @@ -552,6 +552,9 @@ } this._newFileMenu.showAt($target); + if (Gallery.currentAlbum === '') { + $('.menuitem[data-action="hideAlbum"]').parent().hide(); + } return false; } }; diff --git a/js/newfilemenuplugins.js b/js/newfilemenuplugins.js new file mode 100644 index 0000000000..243c2ffb1e --- /dev/null +++ b/js/newfilemenuplugins.js @@ -0,0 +1,19 @@ +var galleryMenuHideAlbum = { + attach: function (menu) { + menu.addMenuEntry({ + 'id': 'hideAlbum', + 'displayName': t('gallery', 'Hide Album'), + 'iconClass': 'icon-close', + 'actionHandler': function () { + FileList.createFile('.nomedia') + .then(function() { + window.location.reload(); + }) + .fail(function() { + OC.Notification.showTemporary(t('gallery', 'Could not hide album')); + }); + } + }); + } +}; +OC.Plugins.register('Gallery.NewFileMenu', galleryMenuHideAlbum); diff --git a/js/upload-helper.js b/js/upload-helper.js index d7ecf789dc..32731f0064 100644 --- a/js/upload-helper.js +++ b/js/upload-helper.js @@ -69,6 +69,71 @@ var FileList = { }); }, + /** + * Create an empty file inside the current album. + * + * @param {string} name name of the file + * + * @return {Promise} promise that will be resolved after the + * file was created + * + */ + createFile: function(name) { + var self = this; + var deferred = $.Deferred(); + var promise = deferred.promise(); + + OCA.Files.isFileNameValid(name); + + var targetPath = this.getCurrentDirectory() + '/' + name; + + //Check if file already exists + if(Gallery.imageMap[targetPath]) { + OC.Notification.showTemporary( + t('files', 'Could not create file "{file}" because it already exists', {file: name}) + ); + deferred.reject(); + return promise; + } + + Gallery.filesClient.putFileContents( + targetPath, + '', + { + contentType: 'text/plain', + overwrite: true + } + ) + .done(function() { + // TODO: error handling / conflicts + Gallery.filesClient.getFileInfo( + targetPath, { + properties: self.findFile(targetPath) + } + ) + .then(function(status, data) { + deferred.resolve(status, data); + }) + .fail(function(status) { + OC.Notification.showTemporary(t('files', 'Could not create file "{file}"', {file: name})); + deferred.reject(status); + }); + }) + .fail(function(status) { + if (status === 412) { + OC.Notification.showTemporary( + t('files', 'Could not create file "{file}" because it already exists', {file: name}) + ); + } else { + OC.Notification.showTemporary(t('files', 'Could not create file "{file}"', {file: name})); + } + deferred.reject(status); + }); + + return promise; + }, + + /** * Retrieves the current album * diff --git a/js/vendor/owncloud/newfilemenu.js b/js/vendor/owncloud/newfilemenu.js index a3dbd748f5..6fa1697b6a 100644 --- a/js/vendor/owncloud/newfilemenu.js +++ b/js/vendor/owncloud/newfilemenu.js @@ -16,6 +16,11 @@ '