1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- /**
- * @var $model \app\models\News
- * @var $key
- * @var $index
- * @var $widget
- */
- use yii\web\View;
- $do = $model->getPart(); //уже голосовал если сделать обход кэша можно попробовать использовать
- ?>
- <div class="col-md-4">
- <div class="inquirer-item">
- <div class="meta">
- <div class="rubric">
- <a href="/inquirer">Опрос</a>
- </div>
- <div class="title">
- <a href="/inquirer/<?=$model->id?>">
- <?=$model->text?>
- </a>
- </div>
- </div>
- <div class="answer p-3" key="<?=$model->id?>">
- <?
- $answers = $model->getAnswers();
- if( $model->show == 'N' ){
- echo $this->render('_ask_item', ['answers'=>$answers]);
- }else{
- foreach($answers as $item){
- ?>
- <div class="form-check-main">
- <input class="form-check-input" type="radio" id="Radio<?=$item->id?>" name="ask_<?=$model->id?>" value="<?=$item->id?>">
- <label class="form-check-label" for="Radio<?=$item->id?>">
- <?=$item->text?>
- </label>
- </div>
- <?
- }
- ?>
- <button class="btn btn-primary mt-4" onclick="sendask(<?=$model->id?>)">Голосовать</button>
- <?
- $bghtml = str_replace(["\r", "\n", "'"], "", $this->render('_ask_item', ['answers'=>$answers]));
- ?>
- <script>
- window.bghtml || (window.bghtml = []);
- window.bghtml[<?=$model->id?>] = '<?=$bghtml?>';
- </script>
- <?
- $filterurl = \yii\helpers\Url::base('https')."/inquirer/ajax";
- $this->registerJs(
- <<<JS
- function sendask(idq){
- ask = $('input:checked[name=ask_'+idq+']').val()
- $.post( "$filterurl", { 'idq': idq, 'ask': ask }, function( data ) {
- if( data.status == 'ok' ){
- //document.location.reload();
- console.log(data.status);
- $(".answer[key='"+idq+"']").html(window.bghtml[idq]);
- }
- });
- }
- JS
- ,
- View::POS_END, 'sendask'
- );
- }
- ?>
- </div>
- </div>
- </div>
|