Basic fixes for drag and drop

This commit is contained in:
Ben Gotow 2016-01-27 11:45:02 -08:00
parent 470fbae6a3
commit 53390fbd5c
5 changed files with 34 additions and 46 deletions

View file

@ -60,15 +60,26 @@ class SidebarItem
dataTransferType: 'nylas-thread-ids' dataTransferType: 'nylas-thread-ids'
onDelete: onDeleteItem onDelete: onDeleteItem
onToggleCollapsed: toggleItemCollapsed onToggleCollapsed: toggleItemCollapsed
onDrop: (item, ids) -> onDrop: (item, event) ->
jsonString = event.dataTransfer.getData(item.dataTransferType)
ids = null
try
ids = JSON.parse(jsonString);
catch err
console.error('OutlineViewItem onDrop: JSON parse #{err}');
return unless ids return unless ids
item.perspective.applyToThreads(ids) item.perspective.applyToThreads(ids)
shouldAcceptDrop: (item, event) -> shouldAcceptDrop: (item, event) ->
perspective = item.perspective target = item.perspective
return false unless perspective current = FocusedPerspectiveStore.current()
return false if perspective.isEqual(FocusedPerspectiveStore.current())
return false unless perspective.canApplyToThreads() return false unless target
item.dataTransferType in event.dataTransfer.types return false if target.isEqual(current)
return false unless _.isEqual(target.accountIds, current.accountIds)
return false unless target.canApplyToThreads()
return item.dataTransferType in event.dataTransfer.types
onSelect: (item) -> onSelect: (item) ->
Actions.selectRootSheet(WorkspaceStore.Sheet.Threads) Actions.selectRootSheet(WorkspaceStore.Sheet.Threads)
Actions.focusMailboxPerspective(item.perspective) Actions.focusMailboxPerspective(item.perspective)

View file

@ -108,6 +108,8 @@ class ListTabular extends React.Component
@setState(@buildStateForRange(start: rangeStart, end: rangeEnd)) @setState(@buildStateForRange(start: rangeStart, end: rangeEnd))
render: => render: =>
otherProps = _.omit(@props, _.keys(@constructor.propTypes))
innerStyles = innerStyles =
height: @state.count * @props.itemHeight height: @state.count * @props.itemHeight
@ -122,7 +124,7 @@ class ListTabular extends React.Component
tabIndex="-1" tabIndex="-1"
className="list-container list-tabular" className="list-container list-tabular"
scrollTooltipComponent={@props.scrollTooltipComponent}> scrollTooltipComponent={@props.scrollTooltipComponent}>
<div className="list-rows" style={innerStyles}> <div className="list-rows" style={innerStyles} {...otherProps}>
{@_rows()} {@_rows()}
</div> </div>
</ScrollRegion> </ScrollRegion>

View file

@ -64,8 +64,9 @@ class OutlineViewItem extends Component {
_runCallback = (method, ...args)=> { _runCallback = (method, ...args)=> {
const item = this.props.item; const item = this.props.item;
if (item[method]) { if (item[method]) {
item[method](item, ...args); return item[method](item, ...args);
} }
return undefined;
} }
@ -76,17 +77,7 @@ class OutlineViewItem extends Component {
} }
_onDrop = (event)=> { _onDrop = (event)=> {
const item = this.props.item; this._runCallback('onDrop', event);
const jsonString = event.dataTransfer.getData(item.dataTransferType);
let ids;
try {
ids = JSON.parse(jsonString);
} catch (err) {
console.error('OutlineViewItem onDrop: JSON parse #{err}');
}
if (!ids) return;
this._runCallback('onDrop', ids);
} }
_onToggleCollapsed = ()=> { _onToggleCollapsed = ()=> {
@ -103,7 +94,7 @@ class OutlineViewItem extends Component {
} }
_shouldAcceptDrop = (event)=> { _shouldAcceptDrop = (event)=> {
this._runCallback('shouldAcceptDrop', event); return this._runCallback('shouldAcceptDrop', event);
} }
_onShowContextMenu = ()=> { _onShowContextMenu = ()=> {

View file

@ -96,7 +96,7 @@ class QueryResultSet
if @_idToIndexHash is null if @_idToIndexHash is null
@buildIdToIndexHash() @buildIdToIndexHash()
if @_idToIndexHash[id] if @_idToIndexHash[id] isnt undefined
return @_idToIndexHash[id] + @_offset return @_idToIndexHash[id] + @_offset
else else
return -1 return -1

View file

@ -1,5 +1,6 @@
_ = require 'underscore' _ = require 'underscore'
TaskFactory = require './flux/tasks/task-factory'
AccountStore = require './flux/stores/account-store' AccountStore = require './flux/stores/account-store'
CategoryStore = require './flux/stores/category-store' CategoryStore = require './flux/stores/category-store'
DatabaseStore = require './flux/stores/database-store' DatabaseStore = require './flux/stores/database-store'
@ -233,31 +234,14 @@ class CategoryMailboxPerspective extends MailboxPerspective
super super
applyToThreads: (threadsOrIds) => applyToThreads: (threadsOrIds) =>
# TODO: FocusedPerspectiveStore = require './flux/stores/focused-perspective-store'
# categoryToApplyForAccount = {} currentCategories = FocusedPerspectiveStore.current().categories()
# for cat in @_categories
# categoryToApplyForAccount[cat.accountId] = cat
#
# @_categories.forEach (cat) ->
#
# if @account.usesLabels()
# FocusedPerspectiveStore = require './flux/stores/focused-perspective-store'
# currentLabel = FocusedPerspectiveStore.current().category
# if currentLabel and not (currentLabel.isLockedCategory())
# labelsToRemove = [currentLabel]
#
# ChangeLabelsTask = require './flux/tasks/change-labels-task'
# task = new ChangeLabelsTask
# threads: threadsOrIds
# labelsToAdd: [@category]
# labelsToRemove: labelsToRemove
# else
# ChangeFolderTask = require './flux/tasks/change-folder-task'
# task = new ChangeFolderTask
# threads: threadsOrIds
# folder: @category
#
# Actions.queueTask(task)
DatabaseStore.modelify(Thread, threadsOrIds).then (threads) =>
tasks = TaskFactory.tasksForApplyingCategories
threads: threads
categoriesToRemove: (accountId) -> _.filter(currentCategories, _.matcher({accountId}))
categoryToAdd: (accountId) => _.findWhere(@_categories, {accountId})
Actions.queueTasks(tasks)
module.exports = MailboxPerspective module.exports = MailboxPerspective