Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions js/galleryview.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@
}
this._newFileMenu.showAt($target);

if (Gallery.currentAlbum === '') {
$('.menuitem[data-action="hideAlbum"]').parent().hide();
}
return false;
}
};
Expand Down
19 changes: 19 additions & 0 deletions js/newfilemenuplugins.js
Original file line number Diff line number Diff line change
@@ -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);
65 changes: 65 additions & 0 deletions js/upload-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
53 changes: 50 additions & 3 deletions js/vendor/owncloud/newfilemenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
'<li>' +
'<label for="file_upload_start" class="menuitem" data-action="upload" title="{{uploadMaxHumanFilesize}}"><span class="svg icon icon-upload"></span><span class="displayname">{{uploadLabel}}</span></label>' +
'</li>' +
'{{#each items}}' +
'<li>' +
'<a href="#" class="menuitem" data-action="{{id}}"><span class="icon {{iconClass}} svg"></span><span class="displayname">{{displayName}}</span></a>' +
'</li>' +
'{{/each}}' +
'</ul>';

/**
Expand All @@ -42,6 +47,8 @@
} else {
console.warn('Missing upload element "file_upload_start"');
}
this._menuItems = [];
OC.Plugins.attach('Gallery.NewFileMenu', this);
},

template: function (data) {
Expand All @@ -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,
});
},

/**
Expand All @@ -68,7 +114,8 @@
render: function () {
this.$el.html(this.template({
uploadMaxHumanFileSize: 'TODO',
uploadLabel: t('gallery', 'Upload')
uploadLabel: t('gallery', 'Upload'),
items: this._menuItems
}));
},

Expand Down
3 changes: 2 additions & 1 deletion templates/part.content.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
'slideshowcontrols',
'slideshowzoomablepreview',
'upload-helper',
'vendor/owncloud/newfilemenu'
'vendor/owncloud/newfilemenu',
'newfilemenuplugins'
]
);
script(
Expand Down