| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin Quiz Editor: Question actions. |
| 4 |
* |
| 5 |
* @since 3.0.0 |
| 6 |
*/ |
| 7 |
?> |
| 8 |
|
| 9 |
<script type="text/x-template" id="tmpl-lp-quiz-question-actions"> |
| 10 |
<div class="question-actions table-row" :class="status"> |
| 11 |
<div class="sort lp-sortable-handle"> |
| 12 |
<?php learn_press_admin_view( 'svg-icon' ); ?> |
| 13 |
</div> |
| 14 |
<div class="order">{{index +1}}</div> |
| 15 |
<div class="name" @dblclick="toggle"> |
| 16 |
<input type="text" class="question-title" v-model="question.title" @change="changeTitle" @blur="updateTitle" @keyup.enter="updateTitle" @keyup="keyUp"> |
| 17 |
</div> |
| 18 |
<div class="type"> |
| 19 |
<a>{{question.type.label}}</a> |
| 20 |
<ul> |
| 21 |
<li v-for="(type, key) in questionTypes" :class="active(key)"> |
| 22 |
<a href="" :data-type="key" @click.prevent="changeType(key)">{{type}}</a> |
| 23 |
</li> |
| 24 |
</ul> |
| 25 |
</div> |
| 26 |
<div class="actions"> |
| 27 |
<div class="lp-box-data-actions lp-toolbar-buttons"> |
| 28 |
<div class="lp-toolbar-btn lp-title-attr-tip" v-if="!disableUpdateList" data-content-tip="<?php esc_attr_e( 'Duplicate', 'learnpress' ); ?>"> |
| 29 |
<a href="" class="lp-btn-icon dashicons dashicons-admin-page" @click.prevent="clone"></a> |
| 30 |
</div> |
| 31 |
<div class="lp-toolbar-btn lp-title-attr-tip" data-content-tip="<?php esc_attr_e( 'Edit an item', 'learnpress' ); ?>"> |
| 32 |
<a :href="url" target="_blank" class="lp-btn-icon dashicons dashicons-edit"></a> |
| 33 |
</div> |
| 34 |
<div class="lp-toolbar-btn lp-btn-remove lp-toolbar-btn-dropdown" v-if="!disableUpdateList"> |
| 35 |
<a class="lp-btn-icon dashicons dashicons-trash" @click.prevent="remove"></a> |
| 36 |
<ul> |
| 37 |
<li> |
| 38 |
<a @click.prevent="remove" class="remove"><?php esc_html_e( 'Removed from the quiz', 'learnpress' ); ?></a> |
| 39 |
</li> |
| 40 |
<li> |
| 41 |
<a @click.prevent="deletePermanently" class="delete"><?php esc_html_e( 'Move to trash', 'learnpress' ); ?></a> |
| 42 |
</li> |
| 43 |
</ul> |
| 44 |
</div> |
| 45 |
<span :class="['lp-toolbar-btn lp-btn-toggle', question.open ?'open' : 'close']" @click="toggle"></span> |
| 46 |
</div> |
| 47 |
</div> |
| 48 |
</div> |
| 49 |
</script> |
| 50 |
|
| 51 |
<script type="text/javascript"> |
| 52 |
jQuery( function($) { |
| 53 |
var $Vue = window.$Vue || Vue; |
| 54 |
var $store = window.LP_Quiz_Store; |
| 55 |
|
| 56 |
$Vue.component('lp-quiz-question-actions', { |
| 57 |
template: '#tmpl-lp-quiz-question-actions', |
| 58 |
props: ['question', 'index'], |
| 59 |
data: function() { |
| 60 |
return { |
| 61 |
title: this.question.title, |
| 62 |
changed: false |
| 63 |
}; |
| 64 |
}, |
| 65 |
mounted: function() { |
| 66 |
this.$nextTick(function() { |
| 67 |
var $ = jQuery; |
| 68 |
|
| 69 |
$(this.$el).find('.lp-title-attr-tip').LP('QuickTip', { |
| 70 |
closeInterval: 0, |
| 71 |
arrowOffset: 'el', |
| 72 |
tipClass: 'preview-item-tip' |
| 73 |
}); |
| 74 |
|
| 75 |
$(document).on('mousedown', '.section-item .drag', function(e) { |
| 76 |
$('html, body').addClass('moving'); |
| 77 |
}).on('mouseup', function (e) { |
| 78 |
$('html, body').removeClass('moving'); |
| 79 |
}) |
| 80 |
}) |
| 81 |
}, |
| 82 |
computed: { |
| 83 |
// question status |
| 84 |
status: function() { |
| 85 |
return $store.getters['lqs/statusUpdateQuestionItem'][this.question.id] || ''; |
| 86 |
}, |
| 87 |
// url edit question |
| 88 |
url: function() { |
| 89 |
return 'post.php?post=' + this.question.id + '&action=edit'; |
| 90 |
}, |
| 91 |
// list question types |
| 92 |
questionTypes: function() { |
| 93 |
return $store.getters['questionTypes']; |
| 94 |
}, |
| 95 |
// disable update list questions |
| 96 |
disableUpdateList: function() { |
| 97 |
return $store.getters['lqs/disableUpdateList']; |
| 98 |
} |
| 99 |
}, |
| 100 |
methods: { |
| 101 |
// check question type active |
| 102 |
active: function(type) { |
| 103 |
var classes = ['']; |
| 104 |
|
| 105 |
if (this.question.type.key === type) { |
| 106 |
classes.push('active'); |
| 107 |
} |
| 108 |
|
| 109 |
var supportTypes = $store.getters['lqs/supportAnswerOptions']; |
| 110 |
if (supportTypes.indexOf(type) === -1 || supportTypes.indexOf(this.question.type.key) === -1) { |
| 111 |
classes.push('disabled') |
| 112 |
} |
| 113 |
|
| 114 |
return classes; |
| 115 |
}, |
| 116 |
// onchange question title |
| 117 |
changeTitle: function() { |
| 118 |
this.changed = true; |
| 119 |
}, |
| 120 |
// update question title |
| 121 |
updateTitle: function() { |
| 122 |
if (this.changed) { |
| 123 |
$store.dispatch('lqs/updateQuestionTitle', this.question); |
| 124 |
} |
| 125 |
this.changed = false; |
| 126 |
}, |
| 127 |
// change question type |
| 128 |
changeType: function(type) { |
| 129 |
if (this.question.type.key !== type) { |
| 130 |
$store.dispatch('lqs/changeQuestionType', { |
| 131 |
question_id: this.question.id, |
| 132 |
type: type |
| 133 |
}); |
| 134 |
} |
| 135 |
}, |
| 136 |
// clone question |
| 137 |
clone: function() { |
| 138 |
$store.dispatch('lqs/cloneQuestion', this.question); |
| 139 |
}, |
| 140 |
// remove question from quiz |
| 141 |
remove: function () { |
| 142 |
$store.dispatch('lqs/removeQuestion', this.question); |
| 143 |
}, |
| 144 |
// delete permanently question |
| 145 |
deletePermanently: function() { |
| 146 |
if (!confirm($store.getters['i18n/all'].confirm_trash_question.replace('{{QUESTION_NAME}}', this.question.title))) { |
| 147 |
return; |
| 148 |
} |
| 149 |
$store.dispatch('lqs/deleteQuestion', this.question); |
| 150 |
}, |
| 151 |
// toggle question |
| 152 |
toggle: function() { |
| 153 |
$store.dispatch('lqs/toggleQuestion', this.question); |
| 154 |
}, |
| 155 |
// navigation questions |
| 156 |
keyUp: function(e) { |
| 157 |
var keyCode = e.keyCode; |
| 158 |
// escape update question title |
| 159 |
if (keyCode === 27) { |
| 160 |
this.question.title = this.title; |
| 161 |
} else { |
| 162 |
this.$emit('nav', {key: e.keyCode, order: this.index}); |
| 163 |
} |
| 164 |
}, |
| 165 |
getQuestionsSupportAnswerOptions: function() { |
| 166 |
var supportTypes = $store.getters['lqs/supportAnswerOptions']; |
| 167 |
return supportTypes.indexOf(this.question.type.key) !== -1 ? lodash.pick(this.questionTypes, supportTypes) : false; |
| 168 |
} |
| 169 |
} |
| 170 |
}); |
| 171 |
}); |
| 172 |
</script> |
| 173 |
|