|
|
|
(function ($, _, OC, t, Gallery) { |
|
"use strict"; |
|
|
|
var TEMPLATE_ADDBUTTON = '<a href="#" class="button new"><img src="{{iconUrl}}" alt="{{addText}}"></img></a>'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
var View = function () { |
|
this.element = $('#gallery'); |
|
this.loadVisibleRows.loading = false; |
|
this._setupUploader(); |
|
this.breadcrumb = new Gallery.Breadcrumb(); |
|
this.emptyContentElement = $('#emptycontent'); |
|
this.controlsElement = $('#controls'); |
|
}; |
|
|
|
View.prototype = { |
|
element: null, |
|
breadcrumb: null, |
|
requestId: -1, |
|
emptyContentElement: null, |
|
controlsElement: null, |
|
|
|
|
|
|
|
|
|
clear: function () { |
|
this.loadVisibleRows.processing = false; |
|
this.loadVisibleRows.loading = null; |
|
|
|
this.element.children().detach(); |
|
this.showLoading(); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
init: function (albumPath, errorMessage) { |
|
|
|
if (this.requestId === -1) { |
|
this._initButtons(); |
|
this._blankUrl(); |
|
} |
|
if ($.isEmptyObject(Gallery.imageMap)) { |
|
Gallery.view.showEmptyFolder(albumPath, errorMessage); |
|
} else { |
|
this.viewAlbum(albumPath); |
|
} |
|
|
|
this._setBackgroundColour(); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
startSlideshow: function (path, albumPath) { |
|
var album = Gallery.albumMap[albumPath]; |
|
var images = album.images; |
|
var startImage = Gallery.imageMap[path]; |
|
Gallery.slideShow(images, startImage, false); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
viewAlbum: function (albumPath) { |
|
albumPath = albumPath || ''; |
|
if (!Gallery.albumMap[albumPath]) { |
|
return; |
|
} |
|
|
|
this.clear(); |
|
|
|
if (albumPath !== Gallery.currentAlbum |
|
|| (albumPath === Gallery.currentAlbum && |
|
Gallery.albumMap[albumPath].etag !== Gallery.currentEtag)) { |
|
Gallery.currentAlbum = albumPath; |
|
Gallery.currentEtag = Gallery.albumMap[albumPath].etag; |
|
this._setupButtons(albumPath); |
|
} |
|
|
|
Gallery.albumMap[albumPath].viewedItems = 0; |
|
Gallery.albumMap[albumPath].preloadOffset = 0; |
|
|
|
|
|
this.requestId = Math.random(); |
|
Gallery.albumMap[Gallery.currentAlbum].requestId = this.requestId; |
|
|
|
|
|
setTimeout(function () { |
|
this.loadVisibleRows.activeIndex = 0; |
|
this.loadVisibleRows(Gallery.albumMap[Gallery.currentAlbum]); |
|
}.bind(this), 0); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sortControlsSetup: function (sortType, sortOrder) { |
|
var reverseSortType = 'date'; |
|
if (sortType === 'date') { |
|
reverseSortType = 'name'; |
|
} |
|
this._setSortButton(sortType, sortOrder, true); |
|
this._setSortButton(reverseSortType, 'asc', false); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loadVisibleRows: function (album) { |
|
var view = this; |
|
|
|
if (this.loadVisibleRows.processing) { |
|
return; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
var scroll = $('#content-wrapper').scrollTop() + $(window).scrollTop(); |
|
|
|
|
|
var targetHeight = ($(window).height() * 2) + scroll; |
|
|
|
|
|
var showRows = _.throttle(function (album) { |
|
|
|
|
|
if (!(album.viewedItems < album.subAlbums.length + album.images.length)) { |
|
view.loadVisibleRows.processing = false; |
|
view.loadVisibleRows.loading = null; |
|
return; |
|
} |
|
|
|
|
|
if (view.requestId !== album.requestId) { |
|
return; |
|
} |
|
|
|
|
|
var row = album.getRow($(window).width()); |
|
var rowDom = row.getDom(); |
|
view.element.append(rowDom); |
|
|
|
return album.fillNextRow(row).then(function () { |
|
if (album.viewedItems < album.subAlbums.length + album.images.length && |
|
view.element.height() < targetHeight) { |
|
return showRows(album); |
|
} |
|
|
|
view.loadVisibleRows.processing = false; |
|
view.loadVisibleRows.loading = null; |
|
}, function () { |
|
|
|
view.loadVisibleRows.processing = false; |
|
view.loadVisibleRows.loading = null; |
|
}); |
|
}, 100); |
|
if (this.element.height() < targetHeight) { |
|
this._showNormal(); |
|
this.loadVisibleRows.processing = true; |
|
album.requestId = view.requestId; |
|
this.loadVisibleRows.loading = showRows(album); |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
showEmptyFolder: function (albumPath, errorMessage) { |
|
var message = '<div class="icon-gallery"></div>'; |
|
var uploadAllowed = true; |
|
|
|
this.element.children().detach(); |
|
this.removeLoading(); |
|
|
|
if (!_.isUndefined(errorMessage) && errorMessage !== null) { |
|
message += '<h2>' + t('gallery', |
|
'Album cannot be shown') + '</h2>'; |
|
|
|
|
|
|
|
message += '<p>' + escapeHTML(errorMessage) + '</p>'; |
|
uploadAllowed = false; |
|
} else { |
|
message += '<h2>' + t('gallery', |
|
'No media files found') + '</h2>'; |
|
|
|
if (Gallery.token) { |
|
message += '<p>' + t('gallery', |
|
'Upload pictures in the files app to display them here') + '</p>'; |
|
} else { |
|
message += '<p>' + t('gallery', |
|
'Upload new files via drag and drop or by using the [+] button above') + |
|
'</p>'; |
|
} |
|
} |
|
this.emptyContentElement.html(message); |
|
this.emptyContentElement.removeClass('hidden'); |
|
|
|
this._hideButtons(uploadAllowed); |
|
Gallery.currentAlbum = albumPath; |
|
var availableWidth = $(window).width() - Gallery.buttonsWidth; |
|
this.breadcrumb.init(albumPath, availableWidth); |
|
Gallery.config.albumDesign = null; |
|
}, |
|
|
|
|
|
|
|
|
|
dimControls: function () { |
|
|
|
var $mask = this.controlsElement.find('.mask'); |
|
if ($mask.exists()) { |
|
return; |
|
} |
|
$mask = $('<div class="mask transparent"></div>'); |
|
this.controlsElement.append($mask); |
|
$mask.removeClass('transparent'); |
|
}, |
|
|
|
|
|
|
|
|
|
showLoading: function () { |
|
this.emptyContentElement.addClass('hidden'); |
|
this.controlsElement.removeClass('hidden'); |
|
$('#content').addClass('icon-loading'); |
|
this.dimControls(); |
|
}, |
|
|
|
|
|
|
|
|
|
removeLoading: function () { |
|
$('#content').removeClass('icon-loading'); |
|
this.controlsElement.find('.mask').remove(); |
|
}, |
|
|
|
|
|
|
|
|
|
_showNormal: function () { |
|
this.emptyContentElement.addClass('hidden'); |
|
this.controlsElement.removeClass('hidden'); |
|
this.removeLoading(); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_setupUploader: function () { |
|
$('#file_upload_start').on('fileuploaddone', function (e, data) { |
|
if (data.files[0] === data.originalFiles[data.originalFiles.length - 1] |
|
&& data.files[0].relativePath) { |
|
|
|
|
|
Gallery.getFiles(Gallery.currentAlbum).done(function () { |
|
Gallery.view.init(Gallery.currentAlbum); |
|
}); |
|
} |
|
}); |
|
|
|
|
|
if (OC.Upload) { |
|
OC.Upload._isReceivedSharedFile = function (file) { |
|
var path = file.name; |
|
var sharedWith = false; |
|
|
|
if (Gallery.currentAlbum !== '' && Gallery.currentAlbum !== '/') { |
|
path = Gallery.currentAlbum + '/' + path; |
|
} |
|
if (Gallery.imageMap[path] && Gallery.imageMap[path].sharedWithUser) { |
|
sharedWith = true; |
|
} |
|
|
|
return sharedWith; |
|
}; |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
_initButtons: function () { |
|
this.element.on("contextmenu", function(e) { e.preventDefault(); }); |
|
$('#filelist-button').click(Gallery.switchToFilesView); |
|
$('#download').click(Gallery.download); |
|
$('#share-button').click(Gallery.share); |
|
Gallery.infoBox = new Gallery.InfoBox(); |
|
$('#album-info-button').click(Gallery.showInfo); |
|
$('#sort-name-button').click(Gallery.sorter); |
|
$('#sort-date-button').click(Gallery.sorter); |
|
$('#save #save-button').click(Gallery.showSaveForm); |
|
$('.save-form').submit(Gallery.saveForm); |
|
this._renderNewButton(); |
|
|
|
$('#uploadprogresswrapper .stop').on('click', function () { |
|
OC.Upload.cancelUploads(); |
|
}); |
|
this.requestId = Math.random(); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_setupButtons: function (albumPath) { |
|
this._shareButtonSetup(albumPath); |
|
this._infoButtonSetup(); |
|
|
|
var availableWidth = $(window).width() - Gallery.buttonsWidth; |
|
this.breadcrumb.init(albumPath, availableWidth); |
|
var album = Gallery.albumMap[albumPath]; |
|
|
|
var sum = album.images.length + album.subAlbums.length; |
|
|
|
if(sum > 1) |
|
{ |
|
$('#sort-name-button').show(); |
|
$('#sort-date-button').show(); |
|
} |
|
else |
|
{ |
|
$('#sort-name-button').hide(); |
|
$('#sort-date-button').hide(); |
|
} |
|
var currentSort = Gallery.config.albumSorting; |
|
this.sortControlsSetup(currentSort.type, currentSort.order); |
|
Gallery.albumMap[Gallery.currentAlbum].images.sort( |
|
Gallery.utility.sortBy(currentSort.type, |
|
currentSort.order)); |
|
Gallery.albumMap[Gallery.currentAlbum].subAlbums.sort(Gallery.utility.sortBy('name', |
|
currentSort.albumOrder)); |
|
|
|
$('#save-button').show(); |
|
$('#download').show(); |
|
$('a.button.new').show(); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
_hideButtons: function (uploadAllowed) { |
|
$('#album-info-button').hide(); |
|
$('#share-button').hide(); |
|
$('#sort-name-button').hide(); |
|
$('#sort-date-button').hide(); |
|
$('#save-button').hide(); |
|
$('#download').hide(); |
|
|
|
if (!uploadAllowed) { |
|
$('a.button.new').hide(); |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_shareButtonSetup: function (albumPath) { |
|
var shareButton = $('#share-button'); |
|
if (albumPath === '' || Gallery.token) { |
|
shareButton.hide(); |
|
} else { |
|
shareButton.show(); |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
_infoButtonSetup: function () { |
|
var infoButton = $('#album-info-button'); |
|
infoButton.find('span').hide(); |
|
var infoContentContainer = $('.album-info-container'); |
|
infoContentContainer.slideUp(); |
|
infoContentContainer.css('max-height', |
|
$(window).height() - Gallery.browserToolbarHeight); |
|
var albumInfo = Gallery.config.albumInfo; |
|
if (Gallery.config.albumError) { |
|
infoButton.hide(); |
|
var text = '<strong>' + t('gallery', 'Configuration error') + '</strong></br>' + |
|
Gallery.config.albumError.message + '</br></br>'; |
|
Gallery.utility.showHtmlNotification(text, 7); |
|
} else if ($.isEmptyObject(albumInfo)) { |
|
infoButton.hide(); |
|
} else { |
|
infoButton.show(); |
|
if (albumInfo.inherit !== 'yes' || albumInfo.level === 0) { |
|
infoButton.find('span').delay(1000).slideDown(); |
|
} |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
_setBackgroundColour: function () { |
|
var wrapper = $('#content-wrapper'); |
|
var albumDesign = Gallery.config.albumDesign; |
|
if (!$.isEmptyObject(albumDesign) && albumDesign.background) { |
|
wrapper.css('background-color', albumDesign.background); |
|
} else { |
|
wrapper.css('background-color', '#fff'); |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_setSortButton: function (sortType, sortOrder, active) { |
|
var button = $('#sort-' + sortType + '-button'); |
|
|
|
button.removeClass('active-button'); |
|
button.find('img').removeClass('front'); |
|
button.find('img').removeClass('back'); |
|
|
|
|
|
var reverseSortOrder = 'des'; |
|
if (sortOrder === 'des') { |
|
reverseSortOrder = 'asc'; |
|
} |
|
|
|
|
|
button.find('img.' + sortOrder).addClass('front'); |
|
button.find('img.' + reverseSortOrder).addClass('back'); |
|
|
|
|
|
if (active) { |
|
button.addClass('active-button'); |
|
if (button.is(":hover")) { |
|
button.removeClass('hover'); |
|
} |
|
|
|
button.hover(function () { |
|
$(this).addClass('hover'); |
|
}, |
|
function () { |
|
$(this).removeClass('hover'); |
|
}); |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
_blankUrl: function() { |
|
$('#remote_address').on("change keyup paste", function() { |
|
if ($(this).val() === '') { |
|
$('#save-button-confirm').prop('disabled', true); |
|
} else { |
|
$('#save-button-confirm').prop('disabled', false); |
|
} |
|
}); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_renderNewButton: function () { |
|
|
|
var $actionsContainer = $('.actions'); |
|
if (!$actionsContainer.length) { |
|
return; |
|
} |
|
if (!this._addButtonTemplate) { |
|
this._addButtonTemplate = Handlebars.compile(TEMPLATE_ADDBUTTON); |
|
} |
|
var $newButton = $(this._addButtonTemplate({ |
|
addText: t('gallery', 'New'), |
|
iconUrl: OC.imagePath('core', 'actions/add') |
|
})); |
|
|
|
$actionsContainer.prepend($newButton); |
|
$newButton.tooltip({'placement': 'bottom'}); |
|
|
|
$newButton.click(_.bind(this._onClickNewButton, this)); |
|
this._newButton = $newButton; |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_onClickNewButton: function (event) { |
|
var $target = $(event.target); |
|
if (!$target.hasClass('.button')) { |
|
$target = $target.closest('.button'); |
|
} |
|
this._newButton.tooltip('hide'); |
|
event.preventDefault(); |
|
if ($target.hasClass('disabled')) { |
|
return false; |
|
} |
|
if (!this._newFileMenu) { |
|
this._newFileMenu = new Gallery.NewFileMenu(); |
|
$('body').append(this._newFileMenu.$el); |
|
} |
|
this._newFileMenu.showAt($target); |
|
|
|
if (Gallery.currentAlbum === '') { |
|
$('.menuitem[data-action="hideAlbum"]').parent().hide(); |
|
} |
|
return false; |
|
} |
|
}; |
|
|
|
Gallery.View = View; |
|
})(jQuery, _, OC, t, Gallery); |
|
|