<commit_before># Copyright 2010-2012 RethinkDB, all rights reserved.

module 'Modals', ->
    class @AddDatabaseModal extends UIComponents.AbstractModal
        template: Handlebars.templates['add_database-modal-template']
        templates:
            error: Handlebars.templates['error_input-template']

        class: 'add-database'

        initialize: (databases) =>
            super
            @databases = databases


        render: =>
            super
                modal_title: "Add database"
                btn_primary_text: "Add"
            @$('.focus_new_name').focus()

        on_submit: =>
            super
            @formdata = form_data_as_object($('form', @$modal))

            error = null

            # Validate input
            if @formdata.name is ''
                # Empty name is not valid
                error = true
                @$('.alert_modal').html @templates.error
                    database_is_empty: true
            else if /^[a-zA-Z0-9_]+$/.test(@formdata.name) is false
                # Only alphanumeric char + underscore are allowed
                error = true
                @$('.alert_modal').html @templates.error
                    special_char_detected: true
                    type: 'database'
            else
                # Check if it's a duplicate
                for database in @databases.models
                    if database.get('db') is @formdata.name
                        error = true
                        @$('.alert_modal').html @templates.error
                            database_exists: true
                        break

            if error is null
                driver.run_once r.db(system_db).table("db_config").insert({name: @formdata.name}), (err, result) =>
                    if (err)
                        @on_error(err)
                    else
                        if result.inserted is 1
                            @databases.add new Database
                                id: result.generated_keys[0]
                                name: @formdata.name
                                tables: []
                            @on_success()
                        else
                            @on_error(new Error(result.first_error or "Unknown error"))
            else
                $('.alert_modal_content').slideDown 'fast'
                @reset_buttons()

        on_success: (response) =>
            super()
            window.app.current_view.render_message "The database #{@formdata.name} was successfully created."

    class @RemoveDatabaseModal extends UIComponents.AbstractModal
        template: Handlebars.templates['remove_database-modal-template']
        class: 'remove_database-dialog'

        render: (database_to_delete) ->
            @database_to_delete = database_to_delete

            # Call render of AbstractModal with the data for the template
            super
                modal_title: 'Delete database'
                btn_primary_text: 'Delete'

            @$('.verification_name').focus()


        on_submit: =>
            if @$('.verification_name').val() isnt @database_to_delete.get('name')
                if @$('.mismatch_container').css('display') is 'none'
                    @$('.mismatch_container').slideDown('fast')
                else
                    @$('.mismatch_container').hide()
                    @$('.mismatch_container').fadeIn()
                @reset_buttons()
                return true

            super

            driver.run_once r.dbDrop(@database_to_delete.get('name')), (err, result) =>
                if (err)
                    @on_error(err)
                else
                    if result?.dropped is 1
                        @on_success()
                    else
                        @on_error(new Error("The return result was not `{dropped: 1}`"))

        on_success: (response) =>
            super()
            if Backbone.history.fragment is 'tables'
                @database_to_delete.destroy()
            else
                # If the user was on a database view, we have to redirect him
                # If he was on #tables, we are just refreshing
                main_view.router.navigate '#tables', {trigger: true}

            window.app.current_view.render_message "The database #{@database_to_delete.get('name')} was successfully deleted."

    class @AddTableModal extends UIComponents.AbstractModal
        template: Handlebars.templates['add_table-modal-template']
        templates:
            error: Handlebars.templates['error_input-template']
        class: 'add-table'

        initialize: (data) =>
            super
            @databases = data.databases
            @container = data.container
<commit_msg>Reflect renamed field dropped -> dbs_dropped in web UI code. Reviewd by @deontologician. Closes #3532.<commit_after># Copyright 2010-2012 RethinkDB, all rights reserved.

module 'Modals', ->
    class @AddDatabaseModal extends UIComponents.AbstractModal
        template: Handlebars.templates['add_database-modal-template']
        templates:
            error: Handlebars.templates['error_input-template']

        class: 'add-database'

        initialize: (databases) =>
            super
            @databases = databases


        render: =>
            super
                modal_title: "Add database"
                btn_primary_text: "Add"
            @$('.focus_new_name').focus()

        on_submit: =>
            super
            @formdata = form_data_as_object($('form', @$modal))

            error = null

            # Validate input
            if @formdata.name is ''
                # Empty name is not valid
                error = true
                @$('.alert_modal').html @templates.error
                    database_is_empty: true
            else if /^[a-zA-Z0-9_]+$/.test(@formdata.name) is false
                # Only alphanumeric char + underscore are allowed
                error = true
                @$('.alert_modal').html @templates.error
                    special_char_detected: true
                    type: 'database'
            else
                # Check if it's a duplicate
                for database in @databases.models
                    if database.get('db') is @formdata.name
                        error = true
                        @$('.alert_modal').html @templates.error
                            database_exists: true
                        break

            if error is null
                driver.run_once r.db(system_db).table("db_config").insert({name: @formdata.name}), (err, result) =>
                    if (err)
                        @on_error(err)
                    else
                        if result.inserted is 1
                            @databases.add new Database
                                id: result.generated_keys[0]
                                name: @formdata.name
                                tables: []
                            @on_success()
                        else
                            @on_error(new Error(result.first_error or "Unknown error"))
            else
                $('.alert_modal_content').slideDown 'fast'
                @reset_buttons()

        on_success: (response) =>
            super()
            window.app.current_view.render_message "The database #{@formdata.name} was successfully created."

    class @RemoveDatabaseModal extends UIComponents.AbstractModal
        template: Handlebars.templates['remove_database-modal-template']
        class: 'remove_database-dialog'

        render: (database_to_delete) ->
            @database_to_delete = database_to_delete

            # Call render of AbstractModal with the data for the template
            super
                modal_title: 'Delete database'
                btn_primary_text: 'Delete'

            @$('.verification_name').focus()


        on_submit: =>
            if @$('.verification_name').val() isnt @database_to_delete.get('name')
                if @$('.mismatch_container').css('display') is 'none'
                    @$('.mismatch_container').slideDown('fast')
                else
                    @$('.mismatch_container').hide()
                    @$('.mismatch_container').fadeIn()
                @reset_buttons()
                return true

            super

            driver.run_once r.dbDrop(@database_to_delete.get('name')), (err, result) =>
                if (err)
                    @on_error(err)
                else
                    if result?.dbs_dropped is 1
                        @on_success()
                    else
                        @on_error(new Error("The return result was not `{dbs_dropped: 1}`"))

        on_success: (response) =>
            super()
            if Backbone.history.fragment is 'tables'
                @database_to_delete.destroy()
            else
                # If the user was on a database view, we have to redirect him
                # If he was on #tables, we are just refreshing
                main_view.router.navigate '#tables', {trigger: true}

            window.app.current_view.render_message "The database #{@database_to_delete.get('name')} was successfully deleted."

    class @AddTableModal extends UIComponents.AbstractModal
        template: Handlebars.templates['add_table-modal-template']
        templates:
            error: Handlebars.templates['error_input-template']
        class: 'add-table'

        initialize: (data) =>
            super
            @databases = data.databases
            @container = data.container

{'fraction_non_alphanumeric': 0.09476750234058047, 'fraction_numerical': 0.0033288255487360866, 'mean_word_length': 1.434540389972145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '4870907', 'n_tokens_mistral': 2442, 'n_tokens_neox': 2285, 'n_words': 553}