/* flickrlicense -- A thingy to update Flickr photo licenses
* Copyright (C) 2017 Douglas Thrift
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
$(function() {
var errorTag = $('#error');
var reloadPhotosTag = $('#reload_photos');
var showLicenseTag = $('#show_license');
var showLicenseVal = showLicenseTag.val();
var showPrivacyTag = $('#show_privacy');
var showPrivacyVal = showPrivacyTag.val();
var showIgnoredTag = $('#show_ignored');
var showIgnoredVal = showIgnoredTag.val();
var photosTag = $('#photos');
var selectLicenseTag = $('#select_license');
var applyLicenseTag = $('#apply_license');
var licenseLinkTag = $('#license_link');
var selectedCountTag = $('#selected_count');
var selectedNounTag = $('#selected_noun');
function controlsDisabled(disabled) {
reloadPhotosTag.prop('disabled', disabled);
showLicenseTag.prop('disabled', disabled);
showPrivacyTag.prop('disabled', disabled);
showIgnoredTag.prop('disabled', disabled);
selectLicenseTag.prop('disabled', disabled);
photosTag.find('.photo button').prop('disabled', disabled);
}
function filterPhotos() {
var count = 0;
photosTag.children('.photo').each(function(index, element) {
var photoTag = $(element);
var show = true;
var ignore = photoTag.hasClass('ignored');
if (showLicenseVal != '' && !photoTag.hasClass('license-' + showLicenseVal)) {
show = false;
}
if (showPrivacyVal != 'all' && !photoTag.hasClass(showPrivacyVal)) {
show = false;
}
if (showIgnoredVal != 'true' && ignore) {
show = false;
}
if (show) {
if (!ignore) {
count++;
}
photoTag.show();
} else {
photoTag.hide();
}
});
selectedCountTag.text(count);
selectedNounTag.text(count == 1 ? "photo" : "photos");
}
function reloadPhotos(params = {}, path = '/photos/1') {
controlsDisabled(true);
$.getJSON(path, params, function(data) {
photosTag.children('.spinner').remove();
for (let photo of data.photos) {
let privacy;
let privacyTag = $('');
if (photo.public) {
privacy = 'public';
privacyTag.text('public');
} else if (photo.friend && photo.family) {
privacy = 'friends_family';
privacyTag.text('friends&family');
} else if (photo.friend) {
privacy = 'friends';
privacyTag.text('friends');
} else if (photo.family) {
privacy = 'family';
privacyTag.text('family');
} else {
privacy = 'private';
privacyTag.text('private');
}
let photoTag = $('
').addClass('license-' + photo.license).addClass(privacy).data('photo', photo);
let ignoreTag = $('