| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin Quiz Editor: List questions. |
| 4 |
* |
| 5 |
* @since 3.0.0 |
| 6 |
*/ |
| 7 |
|
| 8 |
learn_press_admin_view( 'quiz/question' ); |
| 9 |
?> |
| 10 |
|
| 11 |
<script type="text/x-template" id="tmpl-lp-quiz-questions"> |
| 12 |
<div class="main"> |
| 13 |
<lp-quiz-question-item v-for="(question, index) in questions" :question="question" :index="index" :key="index"></lp-quiz-question-item> |
| 14 |
</div> |
| 15 |
</script> |
| 16 |
|
| 17 |
<script type="text/javascript"> |
| 18 |
jQuery( function($) { |
| 19 |
var $Vue = window.$Vue || Vue; |
| 20 |
var $store = window.LP_Quiz_Store; |
| 21 |
|
| 22 |
$Vue.component('lp-quiz-questions', { |
| 23 |
template: '#tmpl-lp-quiz-questions', |
| 24 |
computed: { |
| 25 |
questions: function() { |
| 26 |
return $store.getters['lqs/listQuestions']; |
| 27 |
} |
| 28 |
}, |
| 29 |
mounted: function() { |
| 30 |
var _self = this; |
| 31 |
setTimeout(function() { |
| 32 |
var $el = $('.lp-list-questions .main'); |
| 33 |
|
| 34 |
$el.sortable({ |
| 35 |
handle: '.question-actions .sort', |
| 36 |
axis: 'y', |
| 37 |
update: function () { |
| 38 |
_self.sort(); |
| 39 |
} |
| 40 |
}); |
| 41 |
}, 1000) |
| 42 |
}, |
| 43 |
methods: { |
| 44 |
sort: function() { |
| 45 |
var _items = $('.lp-list-questions .main>div.question-item'); |
| 46 |
var _order = []; |
| 47 |
|
| 48 |
_items.each(function (index, item) { |
| 49 |
$(item).find('.question-actions .order').text(index + 1); |
| 50 |
_order.push($(item).data('item-id')); |
| 51 |
}); |
| 52 |
|
| 53 |
$store.dispatch('lqs/updateQuestionsOrder', _order); |
| 54 |
} |
| 55 |
} |
| 56 |
}); |
| 57 |
}); |
| 58 |
</script> |
| 59 |
|