Вход Регистрация
Файл: style/web/static/ui/js/projects/vote.js
Строк: 81
<?php
$(document).ready(function(){
    var 
project_id_to_vote location.search.split('voting=')[1];

    if (
project_id_to_vote && window.user) {
        var 
$btn = $('.openVoteModal[data-project-id="' project_id_to_vote '"]');
        var 
project_name $btn.data('project-name');

        
openVoteModal(project_id_to_voteproject_name);
    }

    $(
'.openVoteModal').click(function() {
        var 
$btn = $(this);
        var 
project_id $btn.data('project-id');
        var 
project_name $btn.data('project-name');
        
        
openVoteModal(project_idproject_name);
    });

    function 
openVoteModal(project_idproject_name) {
        var 
$vote_modal = $('#voteModal');

        
$vote_modal.modal('show').one('hidden.bs.modal', function() {
            var 
$nick $vote_modal.find('[name="nick"]');
            var 
$vote_btn $vote_modal.find('.voteBtn');

            
$nick
                
.tooltip('destroy')
                .
val('');
            
$vote_btn.tooltip('destroy');
        });
        
$vote_modal.find('.projectName').text(project_name);
        
$vote_modal.find('[name="project_id"]').val(project_id);
    }

    $(
'.voteForm').submit(function(e) {
        
e.preventDefault();

        var 
$vote_form = $(this);
        var 
$vote_modal = $('#voteModal');
        var 
$nick $vote_form.find('[name="nick"]');

        if (!
$nick.val()) {
            
$nick.tooltip({
                
title'Обязательное поле.',
                
position'top',
                
trigger'manual'
            
}).tooltip('show').one('click focus change', function() {
                $(
this).tooltip('destroy');
            });
            return 
false;
        }

        $.
ajax({
            
url'/projects/vote/',
            
type"POST",
            
data$vote_form.serialize(),
            
success: function(data) {
                var 
$project_vote_btn = $('.openVoteModal[data-project-id="' data.project_id '"]');

                
$vote_modal.modal('hide');
                
$project_vote_btn.tooltip({
                    
title'Спасибо за Ваш голос, Вы сможете повторно проголосовать завтра.',
                    
position'top',
                    
trigger'manual'
                
}).tooltip('show');
                
setTimeout(function() {
                  
$project_vote_btn.tooltip('destroy');
                }, 
10000);
            },
            
error: function(response) {
                var 
$vote_btn $vote_form.find('.voteBtn');
                var 
error_text;

                if (
response.status === 500) {
                    
error_text 'Ошибка.'
                
} else {
                    
error_text 'Сегодня Вы уже голосовали.'
                
}

                
$vote_btn.tooltip({
                    
titleerror_text,
                    
position'top',
                    
trigger'manual'
                
}).tooltip('show');
            },
        });
    });
});
?>
Онлайн: 0
Реклама