Files
Pinry/pinry-spa/src/components/editors/PinEditorUI.vue

129 lines
3.0 KiB
Vue
Raw Normal View History

2019-12-07 13:09:22 +08:00
<template>
<div class="editor">
<div class="editor-buttons">
2019-12-07 17:14:15 +08:00
<span class="icon-container" v-if="inOwnedBoard" @click="removeFromBoard">
2019-12-07 13:09:22 +08:00
<b-icon
type="is-light"
icon="minus-box"
custom-size="mdi-24px">
</b-icon>
</span>
2019-12-07 18:08:26 +08:00
<span class="icon-container" @click="addToBoar">
<b-icon
type="is-light"
icon="plus-box"
2019-12-07 13:09:22 +08:00
custom-size="mdi-24px">
</b-icon>
</span>
<span class="icon-container" @click="deletePin" v-if="isOwner">
2019-12-07 13:09:22 +08:00
<b-icon
type="is-light"
icon="delete"
custom-size="mdi-24px">
</b-icon>
</span>
2019-12-07 20:59:03 +08:00
<span class="icon-container" v-if="isOwner" @click="editPin">
2019-12-07 13:09:22 +08:00
<b-icon
type="is-light"
icon="pencil"
custom-size="mdi-24px">
</b-icon>
</span>
</div>
</div>
</template>
<script>
2019-12-07 13:38:09 +08:00
import API from '../api';
2019-12-07 18:08:26 +08:00
import modals from '../modals';
2019-12-07 13:32:20 +08:00
2019-12-07 13:09:22 +08:00
export default {
name: 'Editor',
props: {
2019-12-07 17:14:15 +08:00
currentBoard: {
type: Object,
default() {
return {};
},
},
currentUsername: {
2019-12-07 17:14:15 +08:00
default: null,
type: String,
},
2019-12-07 13:32:20 +08:00
pin: {
default() {
return {};
},
type: Object,
},
},
computed: {
isOwner() {
return this.pin.author === this.currentUsername;
},
2019-12-07 17:14:15 +08:00
inOwnedBoard() {
return (
Object.values(this.currentBoard).length !== 0
&& this.currentBoard.submitter.username === this.currentUsername
);
},
},
2019-12-07 13:32:20 +08:00
methods: {
2019-12-07 18:08:26 +08:00
addToBoar() {
modals.openAdd2Board(this, this.pin, this.currentUsername);
},
removeFromBoard() {
this.$buefy.dialog.confirm({
message: 'Remove Pin from Board?',
onConfirm: () => {
2019-12-07 17:14:15 +08:00
API.Board.removeFromBoard(this.currentBoard.id, [this.pin.id]).then(
() => {
this.$buefy.toast.open('Pin removed');
this.$emit('pin-remove-from-board-succeed', this.pin.id);
},
() => {
this.$buefy.toast.open(
{ type: 'is-danger', message: 'Failed to Remove Pin' },
);
},
);
},
});
},
2019-12-07 20:59:03 +08:00
editPin() {
const props = {
username: this.currentUsername,
existedPin: this.pin,
isEdit: true,
};
modals.openPinEdit(
this,
props,
);
},
2019-12-07 13:32:20 +08:00
deletePin() {
this.$buefy.dialog.confirm({
message: 'Delete this Pin?',
onConfirm: () => {
API.Pin.deleteById(this.pin.id).then(
() => {
this.$buefy.toast.open('Pin deleted');
this.$emit('pin-delete-succeed', this.pin.id);
},
() => {
this.$buefy.toast.open(
{ type: 'is-danger', message: 'Failed to delete Pin' },
);
2019-12-07 13:32:20 +08:00
},
);
},
});
2019-12-07 13:09:22 +08:00
},
},
};
</script>
<style lang="scss" scoped>
2019-12-07 14:15:05 +08:00
@import './editor';
2019-12-07 13:09:22 +08:00
</style>