Sharkey/src/web/app/desktop/views/components/drive-nav-folder.vue

109 lines
2.6 KiB
Vue
Raw Normal View History

2018-02-14 11:21:15 +01:00
<template>
<div class="mk-drive-nav-folder"
:data-draghover="draghover"
@click="onClick"
@dragover.prevent.stop="onDragover"
@dragenter="onDragenter"
@dragleave="onDragleave"
@drop.stop="onDrop"
>
<template v-if="folder == null">%fa:cloud%</template>
<span>{{ folder == null ? '%i18n:desktop.tags.mk-drive-browser-nav-folder.drive%' : folder.name }}</span>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
export default Vue.extend({
2018-02-18 14:14:51 +01:00
props: ['folder'],
2018-02-14 11:21:15 +01:00
data() {
return {
hover: false,
draghover: false
2017-02-21 09:52:10 +01:00
};
2018-02-14 11:21:15 +01:00
},
2018-02-18 14:14:51 +01:00
computed: {
browser(): any {
return this.$parent;
}
},
2018-02-14 11:21:15 +01:00
methods: {
onClick() {
this.browser.move(this.folder);
},
onMouseover() {
this.hover = true;
},
onMouseout() {
this.hover = false;
},
onDragover(e) {
2017-02-20 01:53:57 +01:00
// このフォルダがルートかつカレントディレクトリならドロップ禁止
2017-02-21 09:52:10 +01:00
if (this.folder == null && this.browser.folder == null) {
e.dataTransfer.dropEffect = 'none';
2017-02-20 01:53:57 +01:00
// ドラッグされてきたものがファイルだったら
2017-02-21 09:52:10 +01:00
} else if (e.dataTransfer.effectAllowed == 'all') {
e.dataTransfer.dropEffect = 'copy';
} else {
e.dataTransfer.dropEffect = 'move';
}
return false;
2018-02-14 11:21:15 +01:00
},
onDragenter() {
2017-02-21 09:52:10 +01:00
if (this.folder || this.browser.folder) this.draghover = true;
2018-02-14 11:21:15 +01:00
},
onDragleave() {
2017-02-21 09:52:10 +01:00
if (this.folder || this.browser.folder) this.draghover = false;
2018-02-14 11:21:15 +01:00
},
onDrop(e) {
2017-02-21 09:52:10 +01:00
this.draghover = false;
2016-12-28 23:49:51 +01:00
2017-02-20 01:53:57 +01:00
// ファイルだったら
2017-02-21 09:52:10 +01:00
if (e.dataTransfer.files.length > 0) {
2017-11-13 10:05:35 +01:00
Array.from(e.dataTransfer.files).forEach(file => {
2017-02-21 09:52:10 +01:00
this.browser.upload(file, this.folder);
});
return false;
};
2017-01-11 21:55:38 +01:00
2017-02-20 01:53:57 +01:00
// データ取得
2017-02-21 09:52:10 +01:00
const data = e.dataTransfer.getData('text');
if (data == null) return false;
2016-12-28 23:49:51 +01:00
2017-02-20 01:53:57 +01:00
// パース
2017-02-21 09:52:10 +01:00
// TODO: Validate JSON
const obj = JSON.parse(data);
2017-01-11 21:55:38 +01:00
2017-02-20 01:53:57 +01:00
// (ドライブの)ファイルだったら
2017-02-21 09:52:10 +01:00
if (obj.type == 'file') {
const file = obj.id;
this.browser.removeFile(file);
2018-02-18 04:35:18 +01:00
(this as any).api('drive/files/update', {
2017-02-21 09:52:10 +01:00
file_id: file,
folder_id: this.folder ? this.folder.id : null
});
2017-02-20 01:53:57 +01:00
// (ドライブの)フォルダーだったら
2017-02-21 09:52:10 +01:00
} else if (obj.type == 'folder') {
const folder = obj.id;
2017-02-20 01:53:57 +01:00
// 移動先が自分自身ならreject
2017-02-21 09:52:10 +01:00
if (this.folder && folder == this.folder.id) return false;
this.browser.removeFolder(folder);
2018-02-18 04:35:18 +01:00
(this as any).api('drive/folders/update', {
2017-02-21 09:52:10 +01:00
folder_id: folder,
parent_id: this.folder ? this.folder.id : null
});
}
return false;
2018-02-14 11:21:15 +01:00
}
}
});
</script>
<style lang="stylus" scoped>
.mk-drive-nav-folder
&[data-draghover]
background #eee
</style>