Skip to content

Commit

Permalink
Merge pull request #418 from plural/collection-card-updates
Browse files Browse the repository at this point in the history
Properly update the collection filters when using the collection shortcuts
  • Loading branch information
plural authored Feb 17, 2020
2 parents 87e70ad + e4ac7e1 commit 9a258ac
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions web/js/deck.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,21 @@ function create_collection_tab(initialPackSelection) {
$('#pack_code').find(':checkbox').each(function() {
$(this).prop('checked', !(rotated_cycles[$(this).prop('name')] || rotated_packs[$(this).prop('name')]));
});
update_collection_packs();
});
$('#collection_all').on('click', function(event) {
event.preventDefault();
$('#pack_code').find(':checkbox').each(function(){
$(this).prop('checked', true);
});
update_collection_packs();
});
$('#collection_none').on('click', function(event) {
event.preventDefault();
$('#pack_code').find(':checkbox').each(function(){
$(this).prop('checked', false);
});
update_collection_packs();
});

var sets_in_deck = {};
Expand Down Expand Up @@ -519,27 +522,45 @@ function handle_header_click(event) {
Order > 0 ? '' : 'dropup');
refresh_collection();
}

function update_collection_packs() {
var div = $('#pack_code')
var arr = [];
div.find("input[type=checkbox]").each(function(index, elt) {
var name = $(elt).attr('name');

if (name && $(elt).prop('checked')) {
arr.push(name);
}

var key = 'pack_code_' + name, value = $(elt).prop('checked') ? "on" : "off";
localforage.setItem(key, value);
});
Filters['pack_code'] = arr;
FilterQuery = get_filter_query(Filters);
refresh_collection();
}

function handle_input_change(event) {
var div = $(this).closest('.filter');
var columnName = div.attr('id');
if (columnName == 'pack_code') {
update_collection_packs();
return;
}
var arr = [];
div.find("input[type=checkbox]").each(function(index, elt) {
var name = $(elt).attr('name');

if (name && $(elt).prop('checked')) {
arr.push(name);
}

if (columnName == "pack_code") {
var key = 'pack_code_' + name,
value = $(elt).prop('checked') ? "on" : "off";
localforage.setItem(key, value);
}
});
Filters[columnName] = arr;
FilterQuery = get_filter_query(Filters);
refresh_collection();
}

function get_deck_content() {
return _.reduce(
NRDB.data.cards.find({indeck:{'$gt':0}}),
Expand Down

0 comments on commit 9a258ac

Please sign in to comment.