2017-01-11 21:00:12 +00:00
|
|
|
<mk-drive-browser-nav-folder data-draghover={ draghover } onclick={ onclick } ondragover={ ondragover } ondragenter={ ondragenter } ondragleave={ ondragleave } ondrop={ ondrop }><i class="fa fa-cloud" if={ folder == null }></i><span>{ folder == null ? 'ドライブ' : folder.name }</span>
|
2017-02-19 03:31:53 +00:00
|
|
|
<style>
|
2017-01-11 20:55:38 +00:00
|
|
|
:scope
|
|
|
|
&[data-draghover]
|
|
|
|
background #eee
|
|
|
|
|
|
|
|
</style>
|
|
|
|
<script>
|
2017-02-20 00:53:57 +00:00
|
|
|
this.mixin('api');
|
2017-01-11 20:55:38 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// Riotのバグでnullを渡しても""になる
|
|
|
|
// https://github.com/riot/riot/issues/2080
|
|
|
|
#this.folder = this.opts.folder
|
|
|
|
this.folder = if this.opts.folder? and this.opts.folder != '' then this.opts.folder else null
|
|
|
|
this.browser = this.parent
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
this.hover = false
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.onclick = () => {
|
2017-02-20 01:27:44 +00:00
|
|
|
this.browser.move this.folder
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.onmouseover = () => {
|
2017-02-20 00:53:57 +00:00
|
|
|
this.hover = true
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.onmouseout = () => {
|
2017-02-20 00:53:57 +00:00
|
|
|
this.hover = false
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.ondragover = (e) => {
|
2017-02-20 01:27:44 +00:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// このフォルダがルートかつカレントディレクトリならドロップ禁止
|
2017-02-20 01:27:44 +00:00
|
|
|
if this.folder == null and this.browser.folder == null
|
|
|
|
e.dataTransfer.dropEffect = 'none'
|
2017-02-20 00:53:57 +00:00
|
|
|
// ドラッグされてきたものがファイルだったら
|
2017-02-20 02:02:43 +00:00
|
|
|
else if e.dataTransfer.effectAllowed == 'all'
|
2017-02-20 01:27:44 +00:00
|
|
|
e.dataTransfer.dropEffect = 'copy'
|
2017-01-11 20:55:38 +00:00
|
|
|
else
|
2017-02-20 01:27:44 +00:00
|
|
|
e.dataTransfer.dropEffect = 'move'
|
2017-01-11 20:55:38 +00:00
|
|
|
return false
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.ondragenter = () => {
|
2017-02-20 01:27:44 +00:00
|
|
|
if this.folder != null or this.browser.folder != null
|
2017-02-20 00:53:57 +00:00
|
|
|
this.draghover = true
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.ondragleave = () => {
|
2017-02-20 01:27:44 +00:00
|
|
|
if this.folder != null or this.browser.folder != null
|
2017-02-20 00:53:57 +00:00
|
|
|
this.draghover = false
|
2017-01-11 20:55:38 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.ondrop = (e) => {
|
2017-02-20 01:27:44 +00:00
|
|
|
e.stopPropagation();
|
2017-02-20 00:53:57 +00:00
|
|
|
this.draghover = false
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// ファイルだったら
|
2017-02-20 01:27:44 +00:00
|
|
|
if e.dataTransfer.files.length > 0
|
2017-02-20 02:02:43 +00:00
|
|
|
Array.prototype.forEach.call e.dataTransfer.files, (file) =>
|
2017-02-20 01:27:44 +00:00
|
|
|
this.browser.upload file, this.folder
|
2017-01-11 20:55:38 +00:00
|
|
|
return false
|
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// データ取得
|
2017-02-20 01:27:44 +00:00
|
|
|
data = e.dataTransfer.get-data 'text'
|
2017-01-11 20:55:38 +00:00
|
|
|
if !data?
|
|
|
|
return false
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// パース
|
2017-01-11 20:55:38 +00:00
|
|
|
obj = JSON.parse data
|
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// (ドライブの)ファイルだったら
|
|
|
|
if obj.type == 'file'
|
2017-01-11 20:55:38 +00:00
|
|
|
file = obj.id
|
2017-02-20 01:27:44 +00:00
|
|
|
this.browser.remove-file file
|
2017-02-20 00:53:57 +00:00
|
|
|
this.api 'drive/files/update' do
|
2017-01-11 20:55:38 +00:00
|
|
|
file_id: file
|
2017-02-20 01:27:44 +00:00
|
|
|
folder_id: if this.folder? then this.folder.id else null
|
2017-02-20 00:53:57 +00:00
|
|
|
.then =>
|
|
|
|
// something
|
|
|
|
.catch (err, text-status) =>
|
2017-01-11 20:55:38 +00:00
|
|
|
console.error err
|
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// (ドライブの)フォルダーだったら
|
|
|
|
else if obj.type == 'folder'
|
2017-01-11 20:55:38 +00:00
|
|
|
folder = obj.id
|
2017-02-20 00:53:57 +00:00
|
|
|
// 移動先が自分自身ならreject
|
2017-02-20 01:27:44 +00:00
|
|
|
if this.folder? and folder == this.folder.id
|
2017-01-11 20:55:38 +00:00
|
|
|
return false
|
2017-02-20 01:27:44 +00:00
|
|
|
this.browser.remove-folder folder
|
2017-02-20 00:53:57 +00:00
|
|
|
this.api 'drive/folders/update' do
|
2017-01-11 20:55:38 +00:00
|
|
|
folder_id: folder
|
2017-02-20 01:27:44 +00:00
|
|
|
parent_id: if this.folder? then this.folder.id else null
|
2017-02-20 00:53:57 +00:00
|
|
|
.then =>
|
|
|
|
// something
|
|
|
|
.catch (err, text-status) =>
|
2017-01-11 20:55:38 +00:00
|
|
|
console.error err
|
2016-12-28 22:49:51 +00:00
|
|
|
|
|
|
|
return false
|
2017-01-11 20:55:38 +00:00
|
|
|
</script>
|
|
|
|
</mk-drive-browser-nav-folder>
|