From d4f245f51c021e7993817a02665c9c124f0450ee Mon Sep 17 00:00:00 2001 From: syuilo <syuilotan@yahoo.co.jp> Date: Thu, 23 Feb 2017 17:12:09 +0900 Subject: [PATCH] [Client] Fix bug --- src/web/app/desktop/tags/drive/browser.tag | 11 +++++-- src/web/app/desktop/tags/drive/file.tag | 28 +++++----------- .../tags/select-file-from-drive-window.tag | 33 +++++++++++-------- src/web/app/mobile/tags/drive-selector.tag | 2 +- src/web/app/mobile/tags/drive.tag | 2 +- src/web/app/mobile/tags/drive/file.tag | 2 +- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/web/app/desktop/tags/drive/browser.tag b/src/web/app/desktop/tags/drive/browser.tag index 1e8b17cfcd..afaa452ed2 100644 --- a/src/web/app/desktop/tags/drive/browser.tag +++ b/src/web/app/desktop/tags/drive/browser.tag @@ -248,6 +248,7 @@ this.files = []; this.folders = []; this.hierarchyFolders = []; + this.selectedFiles = []; this.uploads = []; @@ -514,8 +515,14 @@ this.refs.uploader.upload(file, folder); }; - this.getSelection = () => { - this.files.filter(file => file._selected); + this.chooseFile = file => { + if (this.selectedFiles.some(f => f.id == file.id)) { + this.selectedFiles = this.selectedFiles.filter(f => f.id != file.id); + } else { + this.selectedFiles.push(file); + } + this.update(); + this.trigger('change-selection', this.selectedFiles); }; this.newWindow = folderId => { diff --git a/src/web/app/desktop/tags/drive/file.tag b/src/web/app/desktop/tags/drive/file.tag index a7502c1001..47416db0bd 100644 --- a/src/web/app/desktop/tags/drive/file.tag +++ b/src/web/app/desktop/tags/drive/file.tag @@ -1,4 +1,4 @@ -<mk-drive-browser-file data-is-selected={ (file._selected || false).toString() } data-is-contextmenu-showing={ isContextmenuShowing.toString() } onclick={ onclick } oncontextmenu={ oncontextmenu } draggable="true" ondragstart={ ondragstart } ondragend={ ondragend } title={ title }> +<mk-drive-browser-file data-is-selected={ isSelected } data-is-contextmenu-showing={ isContextmenuShowing.toString() } onclick={ onclick } oncontextmenu={ oncontextmenu } draggable="true" ondragstart={ ondragstart } ondragend={ ondragend } title={ title }> <div class="label" if={ I.avatar_id == file.id }><img src="/resources/label.svg"/> <p>アバター</p> </div> @@ -38,7 +38,7 @@ &:after background #0b588c - &[data-is-selected='true'] + &[data-is-selected] background $theme-color &:hover @@ -150,28 +150,16 @@ this.file = this.opts.file; this.browser = this.parent; - this.title = `${this.file.name}\n${this.file.type} ${this.bytesToSize(this.file.datasize)}`; - this.isContextmenuShowing = false; + this.isSelected = this.browser.selectedFiles.some(f => f.id == this.file.id); + + this.browser.on('change-selection', selections => { + this.isSelected = selections.some(f => f.id == this.file.id); + }); this.onclick = () => { - if (this.browser.multiple) { - if (this.file._selected != null) { - this.file._selected = !this.file._selected; - } else { - this.file._selected = true; - } - this.browser.trigger('change-selection', this.browser.getSelection()); - } else { - if (this.file._selected) { - this.browser.trigger('selected', this.file); - } else { - this.browser.files.forEach(file => file._selected = false); - this.file._selected = true; - this.browser.trigger('change-selection', this.file); - } - } + this.browser.chooseFile(this.file); }; this.oncontextmenu = e => { diff --git a/src/web/app/desktop/tags/select-file-from-drive-window.tag b/src/web/app/desktop/tags/select-file-from-drive-window.tag index 777073583f..ed1c1bce6c 100644 --- a/src/web/app/desktop/tags/select-file-from-drive-window.tag +++ b/src/web/app/desktop/tags/select-file-from-drive-window.tag @@ -1,13 +1,17 @@ <mk-select-file-from-drive-window> - <mk-window ref="window" is-modal={ true } width={ '800px' } height={ '500px' }><yield to="header"> - <mk-raw content={ parent.title }></mk-raw><span class="count" if={ parent.multiple && parent.file.length > 0 }>({ parent.file.length }ファイル選択中)</span></yield> -<yield to="content"> - <mk-drive-browser ref="browser" multiple={ parent.multiple }></mk-drive-browser> - <div> - <button class="upload" title="PCからドライブにファイルをアップロード" onclick={ parent.upload }><i class="fa fa-upload"></i></button> - <button class="cancel" onclick={ parent.close }>キャンセル</button> - <button class="ok" disabled={ parent.multiple && parent.file.length == 0 } onclick={ parent.ok }>決定</button> - </div></yield> + <mk-window ref="window" is-modal={ true } width={ '800px' } height={ '500px' }> + <yield to="header"> + <mk-raw content={ parent.title }></mk-raw> + <span class="count" if={ parent.multiple && parent.files.length > 0 }>({ parent.files.length }ファイル選択中)</span> + </yield> + <yield to="content"> + <mk-drive-browser ref="browser" multiple={ parent.multiple }></mk-drive-browser> + <div> + <button class="upload" title="PCからドライブにファイルをアップロード" onclick={ parent.upload }><i class="fa fa-upload"></i></button> + <button class="cancel" onclick={ parent.close }>キャンセル</button> + <button class="ok" disabled={ parent.multiple && parent.files.length == 0 } onclick={ parent.ok }>決定</button> + </div> + </yield> </mk-window> <style> :scope @@ -131,20 +135,21 @@ </style> <script> - this.file = []; + this.files = []; this.multiple = this.opts.multiple != null ? this.opts.multiple : false; this.title = this.opts.title || '<i class="fa fa-file-o"></i>ファイルを選択'; this.on('mount', () => { this.refs.window.refs.browser.on('selected', file => { - this.file = file; + this.files = file; this.ok(); }); this.refs.window.refs.browser.on('change-selection', files => { - this.file = files; - this.update(); + this.update({ + files: files + }); }); this.refs.window.on('closed', () => { @@ -161,7 +166,7 @@ }; this.ok = () => { - this.trigger('selected', this.file); + this.trigger('selected', this.files); this.refs.window.close(); }; </script> diff --git a/src/web/app/mobile/tags/drive-selector.tag b/src/web/app/mobile/tags/drive-selector.tag index 753a2c3a9b..0122ad3fc4 100644 --- a/src/web/app/mobile/tags/drive-selector.tag +++ b/src/web/app/mobile/tags/drive-selector.tag @@ -59,7 +59,7 @@ this.files = []; this.on('mount', () => { - this.refs.browser.on('change-selected', files => { + this.refs.browser.on('change-selection', files => { this.update({ files: files }); diff --git a/src/web/app/mobile/tags/drive.tag b/src/web/app/mobile/tags/drive.tag index 35b9b65417..051482ae19 100644 --- a/src/web/app/mobile/tags/drive.tag +++ b/src/web/app/mobile/tags/drive.tag @@ -358,7 +358,7 @@ this.selectedFiles.push(file); } this.update(); - this.trigger('change-selected', this.selectedFiles); + this.trigger('change-selection', this.selectedFiles); } else { this.cf(file); } diff --git a/src/web/app/mobile/tags/drive/file.tag b/src/web/app/mobile/tags/drive/file.tag index 4b8216219b..1ee114fde7 100644 --- a/src/web/app/mobile/tags/drive/file.tag +++ b/src/web/app/mobile/tags/drive/file.tag @@ -128,7 +128,7 @@ this.file = this.opts.file; this.isSelected = this.browser.selectedFiles.some(f => f.id == this.file.id); - this.browser.on('change-selected', selections => { + this.browser.on('change-selection', selections => { this.isSelected = selections.some(f => f.id == this.file.id); });