<commit_before>{div, i, button} = React.DOM
{Tooltips}       = require '../constants/app_constants'

ToolboxActions = require './toolbox_actions'
ToolboxMove    = require './toolbox_move'

LayoutActionCreator  = require '../actions/layout_action_creator'
MessageActionCreator = require '../actions/message_action_creator'

RouterMixin = require '../mixins/router_mixin'

module.exports = ActionsToolbarMessagesList = React.createClass
    displayName: 'ActionsToolbarMessagesList'

    mixins: [
        RouterMixin
    ]

    propTypes:
        settings:             React.PropTypes.object.isRequired
        mailboxID:            React.PropTypes.string.isRequired
        mailboxes:            React.PropTypes.object.isRequired
        messages:             React.PropTypes.object.isRequired
        selected:             React.PropTypes.object.isRequired
        displayConversations: React.PropTypes.bool.isRequired
        afterAction:          React.PropTypes.func


    _hasSelection: ->
        Object.keys(@props.selected).length > 0


    _getSelectedAndMode: (applyToConversation) ->
        selected = Object.keys @props.selected
        count = selected.length
        applyToConversation = Boolean applyToConversation
        applyToConversation ?= @props.displayConversations
        if selected.length is 0
            LayoutActionCreator.alertError t 'list mass no message'
            return false

        else if not applyToConversation
            return {count, messageIDs: selected, applyToConversation}

        else
            conversationIDs = selected.map (id) =>
                isMessage = (message) -> message.get('id') is id
                if (message = @props.messages.find isMessage)
                    return message.get('conversationID')

            return {count, conversationIDs, applyToConversation}


    render: ->
        div role: 'group',
            button
                role:                     'menuitem'
                onClick:                  @onDelete
                'aria-disabled':          @_hasSelection()
                'aria-describedby':       Tooltips.DELETE_SELECTION
                'data-tooltip-direction': 'bottom'

                i className: 'fa fa-trash-o'

            unless @props.displayConversations
                ToolboxMove
                    ref:       'listToolboxMove'
                    mailboxes: @props.mailboxes
                    onMove:    @onMove
                    direction: 'left'

            ToolboxActions
                direction:            'left'
                mode: if @props.displayConversations then 'conversation' \
                else 'message'
                mailboxes:            @props.mailboxes
                onMark:               @onMark
                onConversationDelete: @onConversationDelete
                onConversationMark:   @onConversationMark
                onConversationMove:   @onConversationMove


    onDelete: (applyToConversation) ->
        return unless options = @_getSelectedAndMode applyToConversation

        doDelete = =>
            MessageActionCreator.delete options, =>
                if options.count > 0 and @props.messages.size > 0
                    firstMessageID = @props.messages.first().get('id')
                    MessageActionCreator.setCurrent firstMessageID, true

            @props.afterAction() if @props.afterAction?

            # Close Detail Panel for deleted message
            @redirect (url = @buildClosePanelUrl 'second')

        unless @props.settings.get 'messageConfirmDelete'
            doDelete()
        else
            if options.applyToConversation
                msg = 'list delete conv confirm'
            else
                msg = 'list delete confirm'

            modal =
                title       : t 'app confirm delete'
                subtitle    : t msg, smart_count: options.count
                closeLabel  : t 'app cancel'
                actionLabel : t 'app confirm'
                action      : ->
                    doDelete()
                    LayoutActionCreator.hideModal()
            LayoutActionCreator.displayModal modal

    onMove: (to, applyToConversation) ->
        return unless options = @_getSelectedAndMode(applyToConversation)

        from = @props.mailboxID

        MessageActionCreator.move options, from, to, =><commit_msg>suppr with messageListToolbar : Select Previous or Next Message<commit_after>{div, i, button} = React.DOM
{Tooltips}       = require '../constants/app_constants'

ToolboxActions = require './toolbox_actions'
ToolboxMove    = require './toolbox_move'

MessageStore = require '../stores/message_store'

LayoutActionCreator  = require '../actions/layout_action_creator'
MessageActionCreator = require '../actions/message_action_creator'

RouterMixin = require '../mixins/router_mixin'

module.exports = ActionsToolbarMessagesList = React.createClass
    displayName: 'ActionsToolbarMessagesList'

    mixins: [
        RouterMixin
    ]

    propTypes:
        settings:             React.PropTypes.object.isRequired
        mailboxID:            React.PropTypes.string.isRequired
        mailboxes:            React.PropTypes.object.isRequired
        messages:             React.PropTypes.object.isRequired
        selected:             React.PropTypes.object.isRequired
        displayConversations: React.PropTypes.bool.isRequired
        afterAction:          React.PropTypes.func


    _hasSelection: ->
        Object.keys(@props.selected).length > 0


    _getSelectedAndMode: (applyToConversation) ->
        selected = Object.keys @props.selected
        count = selected.length
        applyToConversation = Boolean applyToConversation
        applyToConversation ?= @props.displayConversations
        if selected.length is 0
            LayoutActionCreator.alertError t 'list mass no message'
            return false

        else if not applyToConversation
            return {count, messageIDs: selected, applyToConversation}

        else
            conversationIDs = selected.map (id) =>
                isMessage = (message) -> message.get('id') is id
                if (message = @props.messages.find isMessage)
                    return message.get('conversationID')

            return {count, conversationIDs, applyToConversation}


    render: ->
        div role: 'group',
            button
                role:                     'menuitem'
                onClick:                  @onDelete
                'aria-disabled':          @_hasSelection()
                'aria-describedby':       Tooltips.DELETE_SELECTION
                'data-tooltip-direction': 'bottom'

                i className: 'fa fa-trash-o'

            unless @props.displayConversations
                ToolboxMove
                    ref:       'listToolboxMove'
                    mailboxes: @props.mailboxes
                    onMove:    @onMove
                    direction: 'left'

            ToolboxActions
                direction:            'left'
                mode: if @props.displayConversations then 'conversation' \
                else 'message'
                mailboxes:            @props.mailboxes
                onMark:               @onMark
                onConversationDelete: @onConversationDelete
                onConversationMark:   @onConversationMark
                onConversationMove:   @onConversationMove


    onDelete: (applyToConversation) ->
        return unless options = @_getSelectedAndMode applyToConversation

        doDelete = =>
            # Get next focus conversation
            nextConversation = MessageStore.getPreviousConversation()
            nextConversation = MessageStore.getNextConversation() unless nextConversation.size

            MessageActionCreator.delete options

            @props.afterAction() if @props.afterAction?

            unless nextConversation.size
                # Close 2nd panel : no next conversation found
                @redirect (url = @buildClosePanelUrl 'second')
            else
                # Goto to next conversation
                @redirect
                    direction: 'second',
                    action: 'conversation',
                    parameters:
                        messageID: nextConversation.get('id')
                        conversationID: nextConversation.get('conversationID')


        unless @props.settings.get 'messageConfirmDelete'
            doDelete()
        else
            if options.applyToConversation
                msg = 'list delete conv confirm'
            else
                msg = 'list delete confirm'

            modal =
                title       : t 'app confirm delete'
                subtitle    : t msg, smart_count: options.count
                closeLabel  : t 'app cancel'
                actionLabel : t 'app confirm'
                action      : ->
                    doDelete()
                    LayoutActionCreator.hideModal()
            LayoutActionCreator.displayModal modal

    onMove: (to, applyToConversation) ->
        return unless options = @_getSelectedAndMode(applyToConversation)

        from = @props.mailboxID

        MessageActionCreator.move options, from, to, =>
{'fraction_non_alphanumeric': 0.07330806713589605, 'fraction_numerical': 0.0007579859231185707, 'mean_word_length': 1.7077103488712988, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2888772', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2168, 'n_words': 501}