diff options
author | Olivier Paroz <github@oparoz.com> | 2015-04-04 01:59:01 +0300 |
---|---|---|
committer | Olivier Paroz <github@oparoz.com> | 2015-04-04 01:59:01 +0300 |
commit | d7b8a33d5027e30098bbe5fbfb2b040121ff7a9b (patch) | |
tree | e2d0cd21afefc5bd657d39f7cbac2915e007205e /js | |
parent | 046783374ca01a30494ff5c3e1d906f716311e8f (diff) |
Add inheritance support to the album configuration
Diffstat (limited to 'js')
-rw-r--r-- | js/gallery.js | 63 | ||||
-rw-r--r-- | js/galleryconfig.js | 125 | ||||
-rw-r--r-- | js/galleryview.js | 2 |
3 files changed, 150 insertions, 40 deletions
diff --git a/js/gallery.js b/js/gallery.js index 89e29748..02841d33 100644 --- a/js/gallery.js +++ b/js/gallery.js @@ -1,19 +1,18 @@ -/* global OC, $, _, t, Album, GalleryImage, SlideShow, oc_requesttoken, marked */ +/* global OC, $, _, t, GalleryConfig, Album, GalleryImage, SlideShow, oc_requesttoken, marked */ var Gallery = {}; Gallery.mediaTypes = {}; Gallery.images = []; Gallery.currentAlbum = null; Gallery.users = []; -Gallery.albumsInfo = {}; +Gallery.albumConfig = {}; Gallery.albumMap = {}; Gallery.imageMap = {}; Gallery.appName = 'galleryplus'; Gallery.token = undefined; -Gallery.currentSort = {}; /** * Returns a list of supported media types - * + * * @returns {string} */ Gallery.getMediaTypes = function () { @@ -78,6 +77,7 @@ Gallery.getFiles = function () { Gallery.images = []; Gallery.albumMap = {}; Gallery.imageMap = {}; + Gallery.albumConfig = null; var currentLocation = window.location.href.split('#')[1] || ''; var params = { location: currentLocation, @@ -91,14 +91,10 @@ Gallery.getFiles = function () { var mimeType = null; var mTime = null; var files = data.files; + var albumInfo = data.albuminfo; - Gallery.albumsInfo[albumInfo.path] = { - fileid: albumInfo.fileid, - permissions: albumInfo.permissions, - description: albumInfo.description, - copyright: albumInfo.copyright, - copyrightLink: albumInfo.copyright_link - }; + Gallery.albumConfig = new GalleryConfig(albumInfo); + for (var i = 0; i < files.length; i++) { path = files[i].path; fileId = files[i].fileid; @@ -116,27 +112,13 @@ Gallery.getFiles = function () { album.images.push(image); Gallery.imageMap[image.path] = image; } - var sortType = 'name'; - var sortOrder = 'asc'; - var albumSortOrder = 'asc'; - if (!$.isEmptyObject(albumInfo.sorting)) { - sortType = albumInfo.sorting; - } - if (!$.isEmptyObject(albumInfo.sort_order)) { - sortOrder = albumInfo.sort_order; - if (sortType === 'name') { - albumSortOrder = sortOrder; - } - } - - Gallery.currentSort = { - type: sortType, - order: sortOrder - }; + var currentSort = Gallery.albumConfig.getAlbumSorting(); for (var j = 0, keys = Object.keys(Gallery.albumMap); j < keys.length; j++) { - Gallery.albumMap[keys[j]].images.sort(Gallery.sortBy(sortType, sortOrder)); - Gallery.albumMap[keys[j]].subAlbums.sort(Gallery.sortBy('name', albumSortOrder)); + Gallery.albumMap[keys[j]].images.sort(Gallery.sortBy(currentSort.type, + currentSort.order)); + Gallery.albumMap[keys[j]].subAlbums.sort(Gallery.sortBy('name', + currentSort.albumOrder)); } }, function () { // Triggered if we couldn't find a working folder @@ -224,9 +206,9 @@ Gallery.share = function (event) { }; })(); - var albumInfo = Gallery.albumsInfo[Gallery.currentAlbum]; - $('a.share').data('item', albumInfo.fileid).data('link', true) - .data('possible-permissions', albumInfo.permissions). + var albumPermissions = Gallery.albumConfig.getAlbumPermissions(Gallery.currentAlbum); + $('a.share').data('item', albumPermissions.fileid).data('link', true) + .data('possible-permissions', albumPermissions.permissions). click(); if (!$('#linkCheckbox').is(':checked')) { $('#linkText').hide(); @@ -292,7 +274,7 @@ Gallery.showInfo = function (event) { if (infoContentElement.is(':visible')) { infoContentElement.slideUp(); } else { - var albumInfo = Gallery.albumsInfo[Gallery.currentAlbum]; + var albumInfo = Gallery.albumConfig.getAlbumInfo(); if (!albumInfo.infoLoaded) { infoContentElement.addClass('icon-loading'); infoContentElement.empty(); @@ -300,7 +282,7 @@ Gallery.showInfo = function (event) { infoContentElement.slideDown(); if (!$.isEmptyObject(albumInfo.description)) { var params = { - file: Gallery.currentAlbum + '/' + albumInfo.description + file: albumInfo.filePath + '/' + albumInfo.description }; var descriptionUrl = Gallery.buildUrl('download', '', params); $.get(descriptionUrl).done(function (data) { @@ -319,7 +301,8 @@ Gallery.showInfo = function (event) { Gallery.showCopyright(albumInfo, infoContentElement); adjustHeight(); } - albumInfo.infoLoaded = true; + Gallery.albumConfig.setInfoLoaded(); + } else { infoContentElement.slideDown(); } @@ -349,7 +332,7 @@ Gallery.showCopyright = function (albumInfo, infoContentElement) { if (!$.isEmptyObject(albumInfo.copyrightLink)) { var subUrl = ''; var params = { - path: '/' + Gallery.currentAlbum, + path: '/' + albumInfo.filePath, files: albumInfo.copyrightLink }; if (Gallery.token) { @@ -547,10 +530,12 @@ $(document).ready(function () { }); $(window).scroll(function () { - Gallery.view.loadVisibleRows(Gallery.albumMap[Gallery.currentAlbum], Gallery.currentAlbum); + Gallery.view.loadVisibleRows(Gallery.albumMap[Gallery.currentAlbum], + Gallery.currentAlbum); }); $('#content-wrapper').scroll(function () { - Gallery.view.loadVisibleRows(Gallery.albumMap[Gallery.currentAlbum], Gallery.currentAlbum); + Gallery.view.loadVisibleRows(Gallery.albumMap[Gallery.currentAlbum], + Gallery.currentAlbum); }); // A shorter delay avoids redrawing the view in the middle of a previous request, but it diff --git a/js/galleryconfig.js b/js/galleryconfig.js new file mode 100644 index 00000000..f95739bd --- /dev/null +++ b/js/galleryconfig.js @@ -0,0 +1,125 @@ +/* global $ */ +/** + * Stores the configuration about the current album + * @constructor + */ +var GalleryConfig = function (albumConfig) { + this.albumPermissions = this.setAlbumPermissions(albumConfig); + this.albumInfo = this.setAlbumInfo(albumConfig); + this.sorting = this.setAlbumSorting(albumConfig); +}; + +GalleryConfig.prototype = { + /** + * Saves the permissions for the current album + * + * @param albumConfig + * + * @returns {{fileid: *, permissions: *}} + */ + setAlbumPermissions: function (albumConfig) { + return { + fileid: albumConfig.fileid, + permissions: albumConfig.permissions + }; + }, + + /** + * Saves the description and copyright information for the current album + * + * @param albumConfig + * + * @returns {{}} + */ + setAlbumInfo: function (albumConfig) { + var albumPath = albumConfig.path; + var albumInfo = albumConfig.information; + var params = {}; + if (!$.isEmptyObject(albumInfo)) { + var docPath = albumPath; + var level = albumInfo.level; + if (level > 0) { + if (docPath.indexOf('/') !== -1) { + var folders = docPath.split('/'); + folders = folders.slice(-0, -level); + docPath = folders.join('/') + '/'; + } else { + docPath = ''; + } + } + + params = { + description: albumInfo.description, + copyright: albumInfo.copyright, + copyrightLink: albumInfo.copyright_link, + filePath: docPath + }; + } + + return params; + }, + + /** + * Saves the sorting configuration for the current album + * + * @param albumConfig + * + * @returns {{type: string, order: string, albumOrder: string}} + */ + setAlbumSorting: function (albumConfig) { + var sortType = 'name'; + var sortOrder = 'asc'; + var albumSortOrder = 'asc'; + if (!$.isEmptyObject(albumConfig.sorting)) { + if (!$.isEmptyObject(albumConfig.sorting.type)) { + sortType = albumConfig.sorting.type; + } + if (!$.isEmptyObject(albumConfig.sorting.order)) { + sortOrder = albumConfig.sorting.order; + if (sortType === 'name') { + albumSortOrder = sortOrder; + } + } + } + + return { + type: sortType, + order: sortOrder, + albumOrder: albumSortOrder + }; + }, + + /** + * Saves the fact that the description has been successfully loaded + */ + setInfoLoaded: function () { + this.albumInfo.infoLoaded = true; + }, + + /** + * Retrieves the permissions for the current album + * + * @returns {*|{fileid, permissions}|{fileid: *, permissions: *}} + */ + getAlbumPermissions: function () { + return this.albumPermissions; + }, + + /** + * Retrieves the description and copyright information for the current album + * + * @returns {*|{}} + */ + getAlbumInfo: function () { + return this.albumInfo; + }, + + /** + * Retrieves the sorting configuration for the current album + * + * @returns {*|{type, order, albumOrder}|{type: string, order: string, albumOrder: string}} + */ + getAlbumSorting: function () { + return this.sorting; + } +};
\ No newline at end of file diff --git a/js/galleryview.js b/js/galleryview.js index f829a8ed..d2e26cc1 100644 --- a/js/galleryview.js +++ b/js/galleryview.js @@ -101,7 +101,7 @@ Gallery.view.infoButtonSetup = function () { var infoContentElement = $('.album-info-content'); infoContentElement.slideUp(); infoContentElement.css('max-height', $(window).height() - 150); - var albumInfo = Gallery.albumsInfo[Gallery.currentAlbum]; + var albumInfo = Gallery.albumConfig.getAlbumInfo(); if ($.isEmptyObject(albumInfo.description) && $.isEmptyObject(albumInfo.copyright) && $.isEmptyObject(albumInfo.copyrightLink)) { |