<commit_before>define([
    'jquery',
    'underscore',
    'backbone',
    'collections/uploads',
    'views/fileselect',
    'app',
    'text!templates/runworkflow.html'
], function ($, _, Backbone, Uploads, FileSelectView, app, runWorkflowTpl) {
    var RunWorkflowView = Backbone.View.extend({
        el: '#run-modal',
        template: _.template(runWorkflowTpl),

        render: function () {
            $('#run-modal-title').html(this.model.get('title'));
            $('#run-modal-body').html(this.template(this.model.toJSON()));

            this.$('.fileinput').each(function () {
                var uploads = new Uploads();
                uploads.url = jsRoutes.controllers.Users.listUploads(app.session.get('uid')).url;

                var fileSelectView = new FileSelectView({fieldName: $(this).attr('id'), collection: uploads});
                $(this).html(fileSelectView.el);
            });

            $('#run-workflow').submit(function (event) {
                event.preventDefault();

                //grab all form data
                var formData = new FormData($(this)[0]);

                $.ajax({
                    url: $(this).attr('action'),
                    type: 'POST',
                    data: formData,
                    async: false,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (data) {
                        $('.progress').hide();
                    }
                });

                return this;
            });

            $('#run-modal').on('hidden.bs.modal', function (e) {
                app.router.navigate("#", {trigger: true});
            });

            $('#run-btn').on('click', function (e) {

                $('#run-modal').on('hidden.bs.modal', function (e) {
                    app.router.navigate("status", {trigger: true});
                });

                $('.progress').show();
                $('#run-workflow').submit();
                $('#run-modal').modal('toggle');

            });

            $('#run-modal').modal({show: true});

            // TODO: fix autocomplete and add support for file upload selection
            /*$('#inputfile').on("change", function(){

             var myfile = $('#inputfile input')[0].files[0];

             console.log(myfile);

             Papa.parse(myfile, {
             preview: 1,
             complete: function(results) {
             var header = results.data[0];
             console.log(header);

             $('#tokenfield').tokenfield({
             autocomplete: {
             source: header,
             delay: 100,
             },
             showAutocompleteOnFocus: true
             });
             }
             });
             });*/

            //this.$el.html(this.template(this.model.toJSON()));
        }
    });

    return RunWorkflowView;
});<commit_msg>Fixing intermittent bug that submits a workflow run twice<commit_after>define([
    'jquery',
    'underscore',
    'backbone',
    'collections/uploads',
    'views/fileselect',
    'app',
    'text!templates/runworkflow.html'
], function ($, _, Backbone, Uploads, FileSelectView, app, runWorkflowTpl) {
    var RunWorkflowView = Backbone.View.extend({
        el: '#run-modal',
        template: _.template(runWorkflowTpl),

        events: {
            'submit #run-workflow': 'runWorkflow'
        },

        render: function () {
            $('#run-modal-title').html(this.model.get('title'));
            $('#run-modal-body').html(this.template(this.model.toJSON()));

            this.$('.fileinput').each(function () {
                var uploads = new Uploads();
                uploads.url = jsRoutes.controllers.Users.listUploads(app.session.get('uid')).url;

                var fileSelectView = new FileSelectView({fieldName: $(this).attr('id'), collection: uploads});
                $(this).html(fileSelectView.el);
            });

            // TODO: refactor these as events in backbone
            $('#run-modal').on('hidden.bs.modal', function (e) {
                app.router.navigate("#", {trigger: true});
            });

            $('#run-btn').on('click', function (e) {

                $('#run-modal').on('hidden.bs.modal', function (e) {
                    app.router.navigate("status", {trigger: true});
                });

                $('.progress').show();
                $('#run-workflow').submit();
                $('#run-modal').modal('toggle');

            });

            $('#run-modal').modal({show: true});

            // TODO: fix autocomplete and add support for file upload selection
            /*$('#inputfile').on("change", function(){

             var myfile = $('#inputfile input')[0].files[0];

             console.log(myfile);

             Papa.parse(myfile, {
             preview: 1,
             complete: function(results) {
             var header = results.data[0];
             console.log(header);

             $('#tokenfield').tokenfield({
             autocomplete: {
             source: header,
             delay: 100,
             },
             showAutocompleteOnFocus: true
             });
             }
             });
             });*/

            //this.$el.html(this.template(this.model.toJSON()));
        },

        runWorkflow: function (event) {
            console.log("submit");

            event.preventDefault();

            //grab all form data
            var formData = new FormData(event.target);

            var name = this.model.get('name');
            console.log(name);

            $.ajax({
                url: jsRoutes.controllers.Workflows.runWorkflow(name).url,
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (data) {
                    $('.progress').hide();
                }
            });

            return this;
        }
    });

    return RunWorkflowView;
});
{'fraction_non_alphanumeric': 0.1574119574119574, 'fraction_numerical': 0.002457002457002457, 'mean_word_length': 1.4780844155844155, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6187860', 'n_tokens_mistral': 1647, 'n_tokens_neox': 1557, 'n_words': 283}