| 1 |
<?php |
| 2 |
/** |
| 3 |
* @author ThimPress |
| 4 |
* @package LearnPress/Admin/Views |
| 5 |
* @version 3.0.0 |
| 6 |
*/ |
| 7 |
|
| 8 |
defined( 'ABSPATH' ) or die(); |
| 9 |
|
| 10 |
?> |
| 11 |
<div id="learn-press-reset-user-item" class="card"> |
| 12 |
<h2><?php _e( 'Reset Item Progress', 'learnpress' ); ?></h2> |
| 13 |
<div class="description"> |
| 14 |
<?php _e( 'This action will reset progress of a specific lesson or quiz.', 'learnpress' ); ?> |
| 15 |
</div> |
| 16 |
<div class="content"> |
| 17 |
<p> |
| 18 |
<input type="text" v-model="user_id" @keyup="update($event)" placeholder="<?php _e( 'User ID or Email', 'learnpress' ); ?>"> |
| 19 |
</p> |
| 20 |
<p> |
| 21 |
<input type="text" v-model="item_id" @keyup="update($event)" placeholder="<?php _e( 'ID of quiz or lesson', 'learnpress' ); ?>"> |
| 22 |
</p> |
| 23 |
</div> |
| 24 |
<p v-if="message">{{message}}</p> |
| 25 |
<button class="button" @click="reset($event)" |
| 26 |
:disabled="resetting || !isValid()"><?php _e( 'Reset', 'learnpress' ); ?></button> |
| 27 |
</div> |
| 28 |
|
| 29 |
<?php |
| 30 |
|
| 31 |
// Translation |
| 32 |
$localize = array( |
| 33 |
'reset_course_users' => __( 'Are you sure to reset progress of this item?', 'learnpress' ), |
| 34 |
); |
| 35 |
?> |
| 36 |
<script> |
| 37 |
window.$Vue = window.$Vue || Vue; |
| 38 |
|
| 39 |
jQuery(function ($) { |
| 40 |
var js_localize = <?php echo wp_json_encode( $localize ); ?> |
| 41 |
|
| 42 |
new $Vue({ |
| 43 |
el: '#learn-press-reset-user-item', |
| 44 |
data: { |
| 45 |
user_id: '', |
| 46 |
item_id: '', |
| 47 |
resetting: false, |
| 48 |
message: '' |
| 49 |
}, |
| 50 |
watch: {}, |
| 51 |
created: function () { |
| 52 |
|
| 53 |
}, |
| 54 |
mounted: function () { |
| 55 |
$(this.$el).closest('form').on('submit', function () { |
| 56 |
return false; |
| 57 |
}) |
| 58 |
}, |
| 59 |
methods: { |
| 60 |
reset: function (e) { |
| 61 |
e.preventDefault(); |
| 62 |
if (!this.user_id || !this.item_id) { |
| 63 |
return; |
| 64 |
} |
| 65 |
if (!confirm(js_localize.reset_course_users)) { |
| 66 |
return; |
| 67 |
} |
| 68 |
var that = this; |
| 69 |
this.resetting = true; |
| 70 |
this.message = ''; |
| 71 |
$.ajax({ |
| 72 |
url: '', |
| 73 |
data: { |
| 74 |
'lp-ajax': 'rs-reset-user-item', |
| 75 |
user_id: this.user_id, |
| 76 |
item_id: this.item_id, |
| 77 |
nonce: lpGlobalSettings.nonce |
| 78 |
}, |
| 79 |
success: function (response) { |
| 80 |
that.resetting = false; |
| 81 |
that.message = response; |
| 82 |
} |
| 83 |
}) |
| 84 |
}, |
| 85 |
update: function (e) { |
| 86 |
e.preventDefault(); |
| 87 |
}, |
| 88 |
isValid: function () { |
| 89 |
return this.user_id && this.item_id; |
| 90 |
} |
| 91 |
} |
| 92 |
}); |
| 93 |
}); |
| 94 |
|
| 95 |
</script> |
| 96 |
|