| 1 |
<?php |
| 2 |
/** |
| 3 |
* Section item template. |
| 4 |
* |
| 5 |
* @since 3.0.0 |
| 6 |
*/ |
| 7 |
?> |
| 8 |
|
| 9 |
<script type="text/x-template" id="tmpl-lp-section-item"> |
| 10 |
<li :class="['section-item',item.type, isEmptyItem() ? 'empty-item' : '', {updating: updating, removing: removing}]" |
| 11 |
:data-item-id="item.id" |
| 12 |
:data-item-order="order"> |
| 13 |
<div class="drag lp-sortable-handle"> |
| 14 |
<?php learn_press_admin_view( 'svg-icon' ); ?> |
| 15 |
</div> |
| 16 |
<div class="icon"></div> |
| 17 |
<div class="title"> |
| 18 |
<input v-model="item.title" type="text" @change="changeTitle" @blur="updateTitle" @keyup.enter="updateTitle" @keyup="keyUp"> |
| 19 |
</div> |
| 20 |
|
| 21 |
<div class="item-actions"> |
| 22 |
<div class="actions"> |
| 23 |
<?php do_action( 'learn_press_before_display_item_actions' ); ?> |
| 24 |
<div class="action preview-item lp-title-attr-tip" data-content-tip="<?php esc_attr_e( 'Enable/Disable Preview', 'learnpress' ); ?>"> |
| 25 |
<a class="lp-btn-icon dashicons" :class="previewClass" @click="togglePreview"></a> |
| 26 |
</div> |
| 27 |
<div class="action edit-item lp-title-attr-tip" data-content-tip="<?php esc_attr_e( 'Edit item', 'learnpress' ); ?>"> |
| 28 |
<a :href="url" target="_blank" class="lp-btn-icon dashicons dashicons-edit"></a> |
| 29 |
</div> |
| 30 |
<div class="action delete-item" v-if="!disableCurriculum"> |
| 31 |
<a class="lp-btn-icon dashicons dashicons-trash" @click.prevent="remove"></a> |
| 32 |
<ul> |
| 33 |
<li> |
| 34 |
<a @click.prevent="remove"><?php esc_html_e( 'Remove from course', 'learnpress' ); ?></a> |
| 35 |
</li> |
| 36 |
<li> |
| 37 |
<a @click.prevent="deletePermanently" class="delete-permanently"><?php esc_html_e( 'Move to trash', 'learnpress' ); ?></a> |
| 38 |
</li> |
| 39 |
</ul> |
| 40 |
</div> |
| 41 |
<?php do_action( 'learn_press_after_display_item_actions' ); ?> |
| 42 |
</div> |
| 43 |
</div> |
| 44 |
</li> |
| 45 |
</script> |
| 46 |
|
| 47 |
<script type="text/javascript"> |
| 48 |
window.$Vue = window.$Vue || Vue; |
| 49 |
|
| 50 |
jQuery( function( $ ) { |
| 51 |
( function( $store ) { |
| 52 |
$Vue.component('lp-section-item', { |
| 53 |
template: '#tmpl-lp-section-item', |
| 54 |
props: ['item', 'order', 'disableCurriculum'], |
| 55 |
data: function() { |
| 56 |
return { |
| 57 |
title: this.item.title, |
| 58 |
changed: false, |
| 59 |
removing: false |
| 60 |
}; |
| 61 |
}, |
| 62 |
created: function() { |
| 63 |
this.$ = jQuery; |
| 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 |
}, |
| 76 |
computed: { |
| 77 |
url: function() { |
| 78 |
return $store.getters['ss/urlEdit'] + this.item.id; |
| 79 |
}, |
| 80 |
updating: function() { |
| 81 |
return this.removing || this.saving; |
| 82 |
}, |
| 83 |
status: function() { |
| 84 |
return $store.getters['ss/statusUpdateSectionItem'][this.item.id] || ''; |
| 85 |
}, |
| 86 |
saving: function() { |
| 87 |
return this.status === 'updating'; |
| 88 |
}, |
| 89 |
previewClass: function() { |
| 90 |
return { |
| 91 |
'dashicons-visibility': this.item.preview, |
| 92 |
'dashicons-hidden': !this.item.preview |
| 93 |
} |
| 94 |
} |
| 95 |
}, |
| 96 |
methods: { |
| 97 |
isEmptyItem: function() { |
| 98 |
return isNaN(this.item.id) |
| 99 |
}, |
| 100 |
changeTitle: function() { |
| 101 |
this.changed = true; |
| 102 |
}, |
| 103 |
updateTitle: function() { |
| 104 |
if ( this.changed ) { |
| 105 |
this.$emit( 'update', this.item ); |
| 106 |
this.changed = false; |
| 107 |
} |
| 108 |
}, |
| 109 |
remove: function() { |
| 110 |
this.item.temp_id = LP.uniqueId(); |
| 111 |
this.$emit( 'remove', this.item ); |
| 112 |
}, |
| 113 |
deletePermanently: function() { |
| 114 |
if ( ! confirm( $store.getters['i18n/all'].confirm_trash_item.replace( '{{ITEM_NAME}}', this.item.title ) ) ) { |
| 115 |
return; |
| 116 |
} |
| 117 |
this.item.temp_id = LP.uniqueId(); |
| 118 |
this.$emit('delete', this.item); |
| 119 |
}, |
| 120 |
keyUp: function( event ) { |
| 121 |
var keyCode = event.keyCode; |
| 122 |
|
| 123 |
if ( keyCode === 27 ) { |
| 124 |
this.item.title = this.title; |
| 125 |
} else { |
| 126 |
this.$emit( 'nav', { key: event.keyCode, order: this.order } ); |
| 127 |
} |
| 128 |
}, |
| 129 |
togglePreview: function( evt ) { |
| 130 |
this.item.preview = ! this.item.preview; |
| 131 |
|
| 132 |
this.changed = true; |
| 133 |
this.updateTitle(); |
| 134 |
} |
| 135 |
<?php do_action( 'learn_press_after_section_item_script' ); ?> |
| 136 |
} |
| 137 |
}); |
| 138 |
})( LP_Curriculum_Store ); |
| 139 |
}); |
| 140 |
</script> |
| 141 |
|