<commit_before>define [
    "underscore"
    "views/proto/common"
    "views/quest/completed"
    "views/realm/submenu", "views/quest/big", "views/comment/collection"
    "models/comment-collection", "models/current-user", "models/shared-models"
    "text!templates/quest/page.html"
    "jquery.typeahead"
], (_, Common, QuestCompleted, RealmSubmenu, QuestBig, CommentCollection, CommentCollectionModel, currentUser, sharedModels, html) ->
    class extends Common
        activated: false
        template: _.template(html)
        events:
            "click .quest-page-action .complete": "close"
            "click .quest-page-action .abandon": "abandon"
            "click .quest-page-action .leave": "leave"
            "click .quest-page-action .resurrect": "resurrect"
            "click .quest-page-action .reopen": "reopen"
            "click .invite": "inviteDialog"
            "click .uninvite": "uninviteAction"
            "click .join": "joinAction"
            "click .like": -> @model.like()
            "click .unlike": -> @model.unlike()
            "click .watch": -> @model.act "watch"
            "click .unwatch": -> @model.act "unwatch"
            "keyup #inputInvitee": "inviteAction"

        realm: -> @model.get "realm"
        pageTitle: -> @model.get "name"

        realmModel: -> sharedModels.realms.findWhere id: @realm()

        subviews:
            ".realm-submenu-sv": ->
                new RealmSubmenu model: @realmModel()

            ".quest-big": ->
                new QuestBig(model: @model)

            ".comments": ->
                commentsModel = new CommentCollectionModel([],
                    entity: 'quest'
                    eid: @model.id
                )
                commentsModel.fetch()
                new CommentCollection(
                    collection: commentsModel
                    realm: @realm()
                    object: @model
                    reply: @options.reply
                )

        inviteDialog: ->
            @$(".invite.button").hide()
            @$(".invite-dialog").show 0, =>
                @$(".invite-dialog input").typeahead
                    name: "users"
                    remote: "/api/user/%QUERY/autocomplete"
                @$(".invite-dialog input").focus()


        inviteAction: (e) ->

            # escape
            if e.keyCode is 27
                @$(".invite-dialog input").typeahead "destroy"
                @$(".invite-dialog").hide()
                @$(".invite-dialog input").val ""
                @$(".invite.button").show()
                return

            # enter
            @model.invite @$("#inputInvitee").val()  if e.keyCode is 13
            return

        uninviteAction: (e) ->
            @model.uninvite $(e.target).parent().attr("data-login")

        joinAction: ->
            @model.join()

        close: ->
            @model.close()
            modal = new QuestCompleted(model: @model)
            modal.start()

        abandon: -> @model.abandon()
        leave: -> @model.leave()
        resurrect: -> @model.resurrect()
        reopen: -> @model.reopen()
<commit_msg>quest-page view: more consistent method naming<commit_after>define [
    "underscore"
    "views/proto/common"
    "views/quest/completed"
    "views/realm/submenu", "views/quest/big", "views/comment/collection"
    "models/comment-collection", "models/current-user", "models/shared-models"
    "text!templates/quest/page.html"
    "jquery.typeahead"
], (_, Common, QuestCompleted, RealmSubmenu, QuestBig, CommentCollection, CommentCollectionModel, currentUser, sharedModels, html) ->
    class extends Common
        activated: false
        template: _.template(html)
        events:
            "click .quest-page-action .complete": "close"
            "click .quest-page-action .abandon": "abandon"
            "click .quest-page-action .leave": "leave"
            "click .quest-page-action .resurrect": "resurrect"
            "click .quest-page-action .reopen": "reopen"
            "click .invite": "inviteDialog"
            "click .uninvite": "uninvite"
            "click .join": "joinAction"
            "click .like": -> @model.like()
            "click .unlike": -> @model.unlike()
            "click .watch": -> @model.act "watch"
            "click .unwatch": -> @model.act "unwatch"
            "keyup #inputInvitee": "inviteAction"

        realm: -> @model.get "realm"
        pageTitle: -> @model.get "name"

        realmModel: -> sharedModels.realms.findWhere id: @realm()

        subviews:
            ".realm-submenu-sv": ->
                new RealmSubmenu model: @realmModel()

            ".quest-big": ->
                new QuestBig(model: @model)

            ".comments": ->
                commentsModel = new CommentCollectionModel([],
                    entity: 'quest'
                    eid: @model.id
                )
                commentsModel.fetch()
                new CommentCollection(
                    collection: commentsModel
                    realm: @realm()
                    object: @model
                    reply: @options.reply
                )

        inviteDialog: ->
            @$(".invite.button").hide()
            @$(".invite-dialog").show 0, =>
                @$(".invite-dialog input").typeahead
                    name: "users"
                    remote: "/api/user/%QUERY/autocomplete"
                @$(".invite-dialog input").focus()


        inviteAction: (e) ->

            # escape
            if e.keyCode is 27
                @$(".invite-dialog input").typeahead "destroy"
                @$(".invite-dialog").hide()
                @$(".invite-dialog input").val ""
                @$(".invite.button").show()
                return

            # enter
            @model.invite @$("#inputInvitee").val()  if e.keyCode is 13
            return

        uninvite: (e) ->
            @model.uninvite $(e.target).parent().attr("data-login")

        close: ->
            @model.close()
            modal = new QuestCompleted(model: @model)
            modal.start()

        reopen: -> @model.reopen()

        abandon: -> @model.abandon()
        resurrect: -> @model.resurrect()
        leave: -> @model.leave()
        join: -> @model.join()

{'fraction_non_alphanumeric': 0.14465509001115182, 'fraction_numerical': 0.0015931177314003505, 'mean_word_length': 1.5676891615541921, 'pattern_counts': {'":': 32, '<': 3, '<?xml version=': 0, '>': 45, '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': '6865107', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1719, 'n_words': 345}