nkuht-donate/app/assets/javascripts/check_nkuht_donate_set_unit...

79 lines
2.5 KiB
Plaintext
Executable File

function checkTagsQuantity() {
var $tagLead = $('.tag-lead'),
$tagsGroups = $('.tags-groups');
$tagsGroups.each(function(i) {
var $children = $(this).children().length;
$tagLead.eq(i).children('.badge').text($children);
})
}
function checkedLength() {
var $tagsList = $('#tags-list'),
$defaultTags,
ids;
function reload_links() {
var _checked = 0;
ids = [];
$defaultTags = $('li.default input[type="checkbox"]');
$defaultTags.each(function(index, el) {
if($(el).prop('checked')) {
_checked ++;
ids.push($(el).val())
}
});
console.log(_checked,ids)
if(_checked > 0) {
$('#deselect').removeClass('hide');
$('#deselect').on('click', deselect);
$('#deleteUnits').attr('rel', "<%= Rails.application.routes.url_helpers.delete_units_admin_nkuht_donate_units_path %>" + "?ids=" + ids);
$('#deleteUnits').removeClass('hide');
} else {
$('#deselect').addClass('hide');
$('#deleteUnits').attr('rel', "");
$('#deleteUnits').addClass('hide');
$('#deselect').off('click', deselect);
};
}
$tagsList.on('click', '.card', function(event) {
reload_links();
});
$('#selectAllTags').on('click', function() {
$('.filter-item:not(".mark") input[type="checkbox"]').prop('checked', true);
$('.filter-item:not(".mark") .card').addClass('active');
reload_links();
});
$('#deleteUnits').on('click', function() {
$('#delete_nkuht_donate_units .tags-groups').empty();
$('#delete_nkuht_donate_units a.delete-tags').attr("href", $(this).attr("rel"));
if(ids.length) {
$('.filter-item').children('.card.active').each(function(i, e) {
console.log($(e))
$(e).parents('.filter-item').clone().appendTo('#delete_nkuht_donate_units .tags-groups');
$('#delete_nkuht_donate_units .tags-groups .filter-item').addClass('def');
});
}
$('#delete_nkuht_donate_units').modal('show', cleanTagInputs());
function cleanTagInputs(){
var $tagsDelete = $('#delete_nkuht_donate_units'),
$filterItem = $tagsDelete.find('.filter-item');
$filterItem.find('.card, .amount').remove();
$filterItem.find('a').removeAttr('class');
$filterItem.find('a').removeAttr('href');
}
});
function deselect() {
$('.tags input[type="checkbox"]').prop('checked', false);
$('.card').removeClass('active');
$('.bottomnav .toggable').not('.open-slide').addClass('hide');
$('#deleteUnits').attr('rel', "");
}
}
$(function() {
checkedLength();
});