Created
December 7, 2014 15:39
-
-
Save kakawka/fb12af830e87b8d4845e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var blockid = 0; | |
$(document).on('click', '.js-add-room', function (ev) { | |
// ev.preventDefault(); | |
if ($('.js-step-room-input').filter(function() { return $(this).val() == ""; }).length > 0) { | |
return; | |
} | |
blockid++; | |
var block = $(this).parents('.js-room-fields'), | |
name = block.find('.js-name').val(); | |
if (name == '') { | |
name = ' '; | |
} | |
block.hide(); | |
if (block.hasClass('-added')) { | |
var item = $('.js-item-' + block.data('blockid')); | |
console.log(item); | |
if (item.length) { | |
$(item).find('span').html(name); | |
} | |
$('.js-added-rooms').show(); | |
} | |
else { | |
block.data('blockid', blockid); | |
$('.js-added-rooms').append( | |
'<div class="hotel_form-added-room js-item js-item-' + blockid + '"><span>' + name + '</span>' + | |
'<a class="hotel_form-delete-room js-delete-room" href="#">Удалить</a>' + | |
'<a class="hotel_form-edit-room js-edit-room" href="#">Редактировать</a>' + | |
'</div>' | |
).show(); | |
block.addClass('-added'); | |
$('.js-added-rooms .js-item').last().data('block', block); | |
} | |
$('.js-add-room-link').show(); | |
$('.js-hotel-finish').show(); | |
}); | |
$(document).on('click', '.js-delete-room', function (ev) { | |
ev.preventDefault(); | |
if (confirm('Вы уверены?')) { | |
var block = $(this).parents('.js-item').data('block'); | |
block.find('.js-remove-assoc').click(); | |
$(this).parents('.js-item').remove(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment