-
-
Save Bartuz/84b40e82c1c3538235ff to your computer and use it in GitHub Desktop.
Change standart rails confirm dialog to custom
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
Call: | |
Set custom options: | |
= link_to talk, method: :delete, class: 'icon-close', data: {confirm: "Вы действительно хотите удалить всю переписку с данным пользователем?", confirm_options: {title: 'Удалить все сообщения', yes: 'Да', no: 'Нифига'}}, remote: true | |
or standart rails way | |
= link_to talk, method: :delete, class: 'icon-close', data: {confirm: "Вы действительно хотите удалить всю переписку с данным пользователем?"}, remote: true |
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
$.rails.allowAction = (link) -> | |
return true unless link.attr('data-confirm') | |
result = link.attr('data-modal-result') | |
if result | |
link.removeAttr('data-modal-result') | |
return result == 'true' | |
else | |
$.rails.showConfirmDialog(link) | |
return false | |
$.rails.showConfirmDialog = (link) -> | |
default_confirm_options = | |
title: 'Подтверждение' | |
yes: 'Подтвердить' | |
no: 'Закрыть' | |
dialog = $('#modal-confirm') | |
dialog_window = dialog.find('.dialog') | |
$('body').css('overflow', 'hidden') | |
if $('body')[0].scrollHeight > $(window).height() | |
$('body').find('#topbar').andSelf().width($('body').width() - getScrollBarWidth()) | |
confirm_options = $.extend {}, default_confirm_options, link.data('confirm-options') | |
dialog.find('.body').text(link.attr 'data-confirm').end() | |
.find('.header').text(confirm_options.title || 'Подтверждение').end() | |
.find("[data-modal-result='true']").text(confirm_options.yes || 'Подтвердить').end() | |
.find("[data-modal-result='false']").text(confirm_options.no || 'Закрыть') | |
dialog.show() | |
dialog_window.css('top', ($(window).height() - dialog_window.height()) / 2) | |
.css('left', ($(window).width() - dialog_window.width()) / 2) | |
dialog.one 'click', '[data-modal-result]', (e) -> | |
link.attr('data-modal-result', $(@).attr('data-modal-result')) | |
$('body').css('overflow', '').find('#topbar').andSelf().css(width: '') | |
dialog.hide() | |
link.trigger 'click.rails' |
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
section#modal-confirm | |
.dialog | |
.header | |
.body | |
.buttons | |
.btn data-modal-result='true' | |
| Подтвердить | |
.btn.gray data-modal-result='false' | |
| Закрыть |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment