<commit_before>{Mail} = require "models/mail"
{MailView} = require "views/mail"
{MailboxForm} = require "views/mailboxes_list_form"
{Mailbox} = require "models/mailbox"

class exports.MainRouter extends Backbone.Router

    routes:
        ''                          : 'rainbow'
        'rainbow'                   : 'rainbow'
        'rainbow/mail/:id'          : 'rainbowmail'
        'folder/:id'                : 'folder'
        'folder/:id/mail/:mid'      : 'foldermail'

        'config'                    : 'config'
        'config/mailboxes'          : 'config'
        'config/mailboxes/new'      : 'newMailbox'
        'config/mailboxes/:id'      : 'editMailbox'


    clear: ->
        app.views.mailboxList.activate null
        app.views.mailList.activate null
        app.views.mailList.$el.hide()
        app.views.mailboxList.$el.hide()
        app.views.mail?.remove()
        app.views.mailboxform?.remove()
        app.views.mail = null
        app.views.mailboxform = null


    rainbow : (callback) =>
        @clear()

        app.views.menu.select 'rainbow-button'
        app.views.mailboxList.$el.hide()
        app.views.mailList.$el.show()
        app.mails.fetchRainbow(100).then ->
            setTimeout ->
                $("#mailboxes").niceScroll()
            , 200
            callback?()


    rainbowmail: (mailid) =>

        if app.mails.folderId is 'rainbow'
            @mail mailid
        else
            @rainbow => @mail mailid, 'rainbow'


    folder: (folderid, callback) ->
        @clear()

        # if app.mails.length is 0
        #     app.mails.once 'sync', => @folder(folderid)

        app.views.menu.select 'rainbow-button'
        app.views.mailboxList.$el.hide()
        app.views.mailList.$el.show()
        app.mails.fetchFolder(folderid, 100).then callback


    foldermail: (folderid, mailid) =>
        if app.mails.folderId is folderid
            @mail mailid
        else
            @folder folderid, => @mail mailid, "folder/#{folderid}"

    mail: (id, list) ->
        if model = app.mails.get(id)
            app.views.mail?.remove()
            app.views.mail = new MailView model: model
            app.views.mail.$el.appendTo $('body')

            app.views.mail.render()
            $("#mailboxes").niceScroll()

        else
            @navigate list, true

    config: ->

        @clear()

        app.views.menu.select 'config-button'
        app.views.mailList.$el.hide()
        app.views.mailboxList.$el.show()

    newMailbox: ->
        @config()

        app.views.mailboxform = new MailboxForm(model: new Mailbox())
        app.views.mailboxform.$el.appendTo $('body')
        app.views.mailboxform.render()

    editMailbox: (id) ->

        unless model = app.mailboxes.get id
            return @navigate 'config/mailboxes', true

        @config()

        app.views.mailboxList.activate id
        app.views.mailboxform = new MailboxForm model: model
        app.views.mailboxform.$el.appendTo $('body')
        app.views.mailboxform.render()<commit_msg>remove nice scroll stuf from router<commit_after>{Mail} = require "models/mail"
{MailView} = require "views/mail"
{MailboxForm} = require "views/mailboxes_list_form"
{Mailbox} = require "models/mailbox"

class exports.MainRouter extends Backbone.Router

    routes:
        ''                          : 'rainbow'
        'rainbow'                   : 'rainbow'
        'rainbow/mail/:id'          : 'rainbowmail'
        'folder/:id'                : 'folder'
        'folder/:id/mail/:mid'      : 'foldermail'

        'config'                    : 'config'
        'config/mailboxes'          : 'config'
        'config/mailboxes/new'      : 'newMailbox'
        'config/mailboxes/:id'      : 'editMailbox'


    clear: ->
        app.views.mailboxList.activate null
        app.views.mailList.activate null
        app.views.mailList.$el.hide()
        app.views.mailboxList.$el.hide()
        app.views.mail?.remove()
        app.views.mailboxform?.remove()
        app.views.mail = null
        app.views.mailboxform = null


    rainbow : (callback) =>
        @clear()

        app.views.menu.select 'rainbow-button'
        app.views.mailboxList.$el.hide()
        app.views.mailList.$el.show()
        app.views.mailList.showLoading()

        app.mails.fetchRainbow(100).then ->
            app.views.mailList.hideLoading()
            callback?()


    rainbowmail: (mailid) =>

        if app.mails.folderId is 'rainbow'
            @mail mailid
        else
            @rainbow => @mail mailid, 'rainbow'


    folder: (folderid, callback) ->
        @clear()

        # if app.mails.length is 0
        #     app.mails.once 'sync', => @folder(folderid)

        app.views.menu.select 'rainbow-button'
        app.views.mailboxList.$el.hide()
        app.views.mailList.$el.show()
        app.views.mailList.showLoading()

        app.mails.fetchFolder(folderid, 100).then ->
            app.views.mailList.hideLoading()
            callback()


    foldermail: (folderid, mailid) =>
        if app.mails.folderId is folderid
            @mail mailid
        else
            @folder folderid, => @mail mailid, "folder/#{folderid}"


    mail: (id, list) ->
        if model = app.mails.get(id)
            app.views.mail?.remove()
            app.views.mail = new MailView model: model
            app.views.mail.$el.appendTo $('body')

            app.views.mail.render()

        else
            @navigate list, true

    config: ->

        @clear()

        $("#add_mailbox").removeClass 'pressed'
        app.views.menu.select 'config-button'
        app.views.mailList.$el.hide()
        app.views.mailboxList.$el.show()

    newMailbox: ->
        @config()

        $("#add_mailbox").addClass 'pressed'
        app.views.mailboxform = new MailboxForm(model: new Mailbox())
        app.views.mailboxform.$el.appendTo $('body')
        app.views.mailboxform.render()

    editMailbox: (id) ->

        unless model = app.mailboxes.get id
            return @navigate 'config/mailboxes', true

        @config()

        $("#add_mailbox").removeClass 'pressed'
        app.views.mailboxList.activate id
        app.views.mailboxform = new MailboxForm model: model
        app.views.mailboxform.$el.appendTo $('body')
        app.views.mailboxform.render()
{'fraction_non_alphanumeric': 0.1339864117554116, 'fraction_numerical': 0.00268604834887028, 'mean_word_length': 1.814584259670965, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '958580', 'n_tokens_mistral': 1996, 'n_tokens_neox': 1888, 'n_words': 334}