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 @@ '
  • ' + '' + '
  • ' + + '{{#each items}}' + + '
  • ' + + '{{displayName}}' + + '
  • ' + + '{{/each}}' + ''; /** @@ -42,6 +47,8 @@ } else { console.warn('Missing upload element "file_upload_start"'); } + this._menuItems = []; + OC.Plugins.attach('Gallery.NewFileMenu', this); }, template: function (data) { @@ -54,12 +61,51 @@ /** * Event handler whenever the upload button has been clicked within the menu */ - _onClickAction: function () { + _onClickAction: function (event) { + var $target = $(event.target); + if (!$target.hasClass('menuitem')) { + $target = $target.closest('.menuitem'); + } + var action = $target.attr('data-action'); // note: clicking the upload label will automatically // set the focus on the "file_upload_start" hidden field // which itself triggers the upload dialog. // Currently the upload logic is still in file-upload.js and filelist.js - OC.hideMenus(); + if (action === 'upload') { + OC.hideMenus(null); + } else { + event.preventDefault(); + this.$el.find('.menuitem.active').removeClass('active'); + $target.addClass('active'); + var actionItem; + for (var i = 0, len = this._menuItems.length; i < len; i++) { + if (this._menuItems[i].id === action) { + actionItem = this._menuItems[i]; + break; // Return as soon as the object is found + } + } + if (actionItem !== null) { + actionItem.actionHandler(); + } + OC.hideMenus(null); + } + }, + + + /** + * Add a new item menu entry in the “New” file menu (in + * last position). By clicking on the item, the + * `actionHandler` function is called. + * + * @param {Object} actionSpec item’s properties + */ + addMenuEntry: function (actionSpec) { + this._menuItems.push({ + 'id': actionSpec.id, + 'displayName': actionSpec.displayName, + 'iconClass': actionSpec.iconClass, + 'actionHandler': actionSpec.actionHandler, + }); }, /** @@ -68,7 +114,8 @@ render: function () { this.$el.html(this.template({ uploadMaxHumanFileSize: 'TODO', - uploadLabel: t('gallery', 'Upload') + uploadLabel: t('gallery', 'Upload'), + items: this._menuItems })); }, diff --git a/templates/part.content.php b/templates/part.content.php index 15ebe1da2d..174567359f 100644 --- a/templates/part.content.php +++ b/templates/part.content.php @@ -31,7 +31,8 @@ 'slideshowcontrols', 'slideshowzoomablepreview', 'upload-helper', - 'vendor/owncloud/newfilemenu' + 'vendor/owncloud/newfilemenu', + 'newfilemenuplugins' ] ); script(