From 9c218f3212711d1679b6b61cf2c195ab8b5d00d4 Mon Sep 17 00:00:00 2001 From: eknoes Date: Fri, 8 Apr 2016 23:45:55 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Adapted:=20Allow=20apps=20to=20add=20new=20?= =?UTF-8?q?items=20in=20the=20=E2=80=9CNew=E2=80=9D=20filemenu=20&=20Imple?= =?UTF-8?q?mented=20"Hide=20Album"=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adapted owncloud/core@d386168 Hide Album function will create a .nomedia file in the current album and refreshs after creating .nomedia file --- js/newfilemenuplugins.js | 19 +++++++++ js/upload-helper.js | 65 +++++++++++++++++++++++++++++++ js/vendor/owncloud/newfilemenu.js | 52 +++++++++++++++++++++++-- templates/part.content.php | 3 +- 4 files changed, 135 insertions(+), 4 deletions(-) create mode 100644 js/newfilemenuplugins.js 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..70b2b51665 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,50 @@ /** * 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(); + } 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(); + } + }, + + + /** + * 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 +113,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( From 681640065f02bb30c323594bdd3981d8c9255c04 Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Sat, 18 Jun 2016 01:32:00 +0200 Subject: [PATCH 2/3] Hide the hide album button when on top album --- js/galleryview.js | 3 +++ 1 file changed, 3 insertions(+) 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; } }; From 27a81cbd8a7a2a77e6efaa9930a13d9863ae18c8 Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Sat, 18 Jun 2016 01:43:43 +0200 Subject: [PATCH 3/3] Minor fixes to newfilemenu --- js/vendor/owncloud/newfilemenu.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/js/vendor/owncloud/newfilemenu.js b/js/vendor/owncloud/newfilemenu.js index 70b2b51665..6fa1697b6a 100644 --- a/js/vendor/owncloud/newfilemenu.js +++ b/js/vendor/owncloud/newfilemenu.js @@ -48,7 +48,7 @@ console.warn('Missing upload element "file_upload_start"'); } this._menuItems = []; - OC.Plugins.attach('Gallery.NewFileMenu', this); + OC.Plugins.attach('Gallery.NewFileMenu', this); }, template: function (data) { @@ -72,21 +72,22 @@ // which itself triggers the upload dialog. // Currently the upload logic is still in file-upload.js and filelist.js if (action === 'upload') { - OC.hideMenus(); + 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) + if (this._menuItems[i].id === action) { actionItem = this._menuItems[i]; break; // Return as soon as the object is found + } } - if(actionItem != null) { + if (actionItem !== null) { actionItem.actionHandler(); } - OC.hideMenus(); + OC.hideMenus(null); } }, @@ -98,7 +99,7 @@ * * @param {Object} actionSpec item’s properties */ - addMenuEntry: function(actionSpec) { + addMenuEntry: function (actionSpec) { this._menuItems.push({ 'id': actionSpec.id, 'displayName': actionSpec.displayName,