<!-- Vote Ajax -->
<div id="load-content">
    <h4><i class="fa fa-question-circle text-warning"></i> Poll:   {{$poll_text}} </h4>
    <?php
    $total = 0;
    foreach ($poll as $p) {
        $total += isset($p->number) ? $p->number : 0;
    }
    ?>
    @foreach($poll as $p)

    <?php
    $percent = 0;
    if (isset($p->number) && !empty($p->number)) {
        $percent = $p->number / $total * 100;
        $percent = number_format((float) $percent, 0, '.', '');  // Outputs -> 105.00
    }
    ?>

    <strong>{{$p->poll_option_text}}</strong><span class="pull-right">{{$percent}}%</span>
    <div class="progress vote-now"  style="cursor: pointer" poll-option-id="{{$p->poll_option_id}}" poll-id="{{$poll[0]->poll_id}}">
        <div class="progress-bar {{Util::getColor($percent)}}" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: {{$percent}}%">
            <span class="sr-only">{{$percent}}% Complete (success)</span>
        </div>
    </div>
    @endforeach
    <h4><span id="msg"></span></h4>
</div>
<script>
    $('.vote-now').click(function(e) {
        $('#msg').html('');// Clear content
        $('#msg').html('Voting .... <i class="fa fa-spinner fa-spin"></i>');
        var poll_option_id = $(this).attr('poll-option-id');
        var poll_id = $(this).attr('poll-id');
        $.ajax('/user/vote', {'method': 'POST', data: {'poll_option_id': poll_option_id, 'poll_id': poll_id}}).done(function(d) {
            if (d.success == 1)
            {
                $('#msg').html(d.msg);
                $.ajax('/user/poll-form/' + poll_id).done(function(d) {
                    $('#load-content').html(d.msg);
                    return false;
                });
            } else
            {
                $('#msg').html(d.msg);
            }

        });

    });
</script>
<!-- // Vote Ajax -->
