<commit_before>
# This file extends the UIComponents module with commonly used modal
# dialog boxes.
module 'UIComponents', ->
    # Modal that allows for form submission
    class @AbstractModal extends Backbone.View
        template_outer: Handlebars.compile $('#abstract-modal-outer-template').html()
        error_template: Handlebars.compile $('#error_input-template').html()

        events:
            'click .cancel': 'cancel_modal'
            'click .close': 'cancel_modal'
            'click .btn-primary': 'abstract_submit'
            'keypress input': 'check_keypress_is_enter'
            'click .close_error': 'close_error'

        close_error: (event) ->
            event.preventDefault()
            $(event.currentTarget).parent().slideUp('fast', -> $(this).remove())


        initialize: ->
            @$container = $('#modal-dialog')
            @custom_buttons = []

        # Render and show the modal.
        #   validator_options: object that defines form behavior and validation rules
        #   template_json: json to pass to the template for the modal
        render: (template_data) =>

            # Add the modal generated from the template to the container, and show it
            template_data = {} if not template_data?
            template_data = _.extend template_data,
                modal_class: @class
            @$container.html @template_outer template_data
            $('.modal-body', @$container).html @template template_data

            # Note: Bootstrap's modal JS moves the modal from the container element to the end of the body tag in the DOM
            @$modal = $('.modal', @$container).modal
                'show': true
                'backdrop': true
                'keyboard': true
            .on 'hidden', =>
                # Removes the modal dialog from the DOM
                @$modal.remove()

            # Define @el to be the modal (the root of the view), make sure events perform on it
            @.setElement @$modal
            @.delegateEvents()

            for btn in @custom_buttons
                @.$('.custom_btn_placeholder').append("<button class='btn #{ btn.class_str }' data-loading-text='#{ btn.data_loading_text }'>#{ btn.main_text }</button>")
                @.$('.custom_btn_placeholder > .' + btn.class_str).click (e) =>
                    btn.on_click(e)
                @.$('.custom_btn_placeholder > .' + btn.class_str).button()

            register_modal @

        hide_modal: ->
            @$modal.modal('hide') if @$modal?

        cancel_modal: (e) ->
            @.hide_modal()
            e.preventDefault()

        check_keypress_is_enter: (event) =>
            if event.which is 13
                event.preventDefault()
                @abstract_submit(event)<commit_msg>Add destroy() when hiding modal<commit_after>
# This file extends the UIComponents module with commonly used modal
# dialog boxes.
module 'UIComponents', ->
    # Modal that allows for form submission
    class @AbstractModal extends Backbone.View
        template_outer: Handlebars.compile $('#abstract-modal-outer-template').html()
        error_template: Handlebars.compile $('#error_input-template').html()

        events:
            'click .cancel': 'cancel_modal'
            'click .close': 'cancel_modal'
            'click .btn-primary': 'abstract_submit'
            'keypress input': 'check_keypress_is_enter'
            'click .close_error': 'close_error'

        close_error: (event) ->
            event.preventDefault()
            $(event.currentTarget).parent().slideUp('fast', -> $(this).remove())


        initialize: ->
            @$container = $('#modal-dialog')
            @custom_buttons = []

        # Render and show the modal.
        #   validator_options: object that defines form behavior and validation rules
        #   template_json: json to pass to the template for the modal
        render: (template_data) =>

            # Add the modal generated from the template to the container, and show it
            template_data = {} if not template_data?
            template_data = _.extend template_data,
                modal_class: @class
            @$container.html @template_outer template_data
            $('.modal-body', @$container).html @template template_data

            # Note: Bootstrap's modal JS moves the modal from the container element to the end of the body tag in the DOM
            @$modal = $('.modal', @$container).modal
                'show': true
                'backdrop': true
                'keyboard': true
            .on 'hidden', =>
                # Removes the modal dialog from the DOM
                @$modal.remove()

            # Define @el to be the modal (the root of the view), make sure events perform on it
            @.setElement @$modal
            @.delegateEvents()

            for btn in @custom_buttons
                @.$('.custom_btn_placeholder').append("<button class='btn #{ btn.class_str }' data-loading-text='#{ btn.data_loading_text }'>#{ btn.main_text }</button>")
                @.$('.custom_btn_placeholder > .' + btn.class_str).click (e) =>
                    btn.on_click(e)
                @.$('.custom_btn_placeholder > .' + btn.class_str).button()

            register_modal @

        hide_modal: =>
            @$modal.modal('hide') if @$modal?
            @destroy()

        cancel_modal: (e) ->
            @.hide_modal()
            e.preventDefault()

        check_keypress_is_enter: (event) =>
            if event.which is 13
                event.preventDefault()
                @abstract_submit(event)
{'fraction_non_alphanumeric': 0.11372130272290443, 'fraction_numerical': 0.0007118704395799964, 'mean_word_length': 1.9814323607427056, 'pattern_counts': {'":': 0, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5992895', 'n_tokens_mistral': 1463, 'n_tokens_neox': 1421, 'n_words': 414}