venue_management/app/assets/javascripts/check_seminar_set_items.js.erb

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);
$('#deleteItems').attr('rel', "<%= Rails.application.routes.url_helpers.delete_items_admin_seminar_items_path %>" + "?ids=" + ids);
$('#deleteItems').removeClass('hide');
} else {
$('#deselect').addClass('hide');
$('#deleteItems').attr('rel', "");
$('#deleteItems').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();
});
$('#deleteItems').on('click', function() {
$('#delete_seminar_items .tags-groups').empty();
$('#delete_seminar_items 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_seminar_items .tags-groups');
$('#delete_seminar_items .tags-groups .filter-item').addClass('def');
});
}
$('#delete_seminar_items').modal('show', cleanTagInputs());
function cleanTagInputs(){
var $tagsDelete = $('#delete_seminar_items'),
$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');
$('#deleteItems').attr('rel', "");
}
}
$(function() {
checkedLength();
});