var mumuki = mumuki || {};

(function (mumuki) {
  function ResultsBox(submissionsResults) {
    this.submissionsresultsArea = submissionsResults;
    this.processingTemplate = $('#processing-template');
    this.submissionsErrorTemplate = $(".submission-result-error");
  }

  ResultsBox.prototype = {
    waiting: function () {
      this.submissionsresultsArea.html(this.processingTemplate.html());
      this.submissionsErrorTemplate.hide();
    },
    success: function (data) {
      this.submissionsresultsArea.html(data);
    },
    error: function () {
      this.submissionsresultsArea.html('');
      this.submissionsErrorTemplate.show();
    },
    done: function () {
      mumuki.pin.scroll();
    }
  };

  function SubmissionController() {
    this.submitButton = $('.btn-submit');
    this.submissionControls = $('.submission_control');
  }

  SubmissionController.prototype = {
    disable: function () {
      document.prevSubmitState = this.submitButton.html();
      this.submitButton.html('<i class="fa fa-refresh fa-spin"></i> ' + this.submitButton.attr('data-waiting'));
      this.submissionControls.attr('disabled', 'disabled');
    },
    enable: function () {
      this.submitButton.html(document.prevSubmitState);
      this.submissionControls.removeAttr('disabled');
    }
  };

  mumuki.load(function () {
    var submissionsResults = $('.submission-results');
    if (!submissionsResults) return;

    var resultsBox = new ResultsBox(submissionsResults);
    var submissionController = new SubmissionController();

    $('form.new_solution').on('ajax:beforeSend', function (event) {
      submissionController.disable();
      resultsBox.waiting();
    }).on('ajax:complete', function (event) {
      $(document).renderMuComponents();
      resultsBox.done();
      $('#messages-tab').removeClass('hidden');
    }).on('ajax:success', function (event) {
      var data = event.detail[0].body.outerHTML;
      submissionController.enable();
      resultsBox.success(data);
    }).on('ajax:error', function (event) {
      resultsBox.error(submissionController);
      animateTimeoutError(submissionController);
    });
  });

  function animateTimeoutError(submissionController) {
    var image = $('#submission-result-error-animation')[0];
    image.src = mumuki.errors.error_timeout_1;
    setTimeout(function () {
      image.src = mumuki.errors.error_timeout_2;
      setTimeout(function () {
        image.src = mumuki.errors.error_timeout_3;
        submissionController.enable();
      }, 4000);
    }, 10333);
  }

})(mumuki);

@@ -729,31 +729,23 @@
 on Submi
-ssionController
+tButton
 () %7B%0A   
@@ -851,31 +851,23 @@
 %0A  Submi
-ssionController
+tButton
 .prototy
@@ -1482,50 +1482,34 @@
 ubmi
-ssionController = new SubmissionController
+tButton = new SubmitButton
 ();%0A
@@ -1588,31 +1588,23 @@
    submi
-ssionController
+tButton
 .disable
@@ -1895,39 +1895,31 @@
 %0A      submi
-ssionController
+tButton
 .enable();%0A 
@@ -2016,39 +2016,31 @@
 .error(submi
-ssionController
+tButton
 );%0A      ani
@@ -2061,31 +2061,23 @@
 or(submi
-ssionController
+tButton
 );%0A    %7D

rename submission controller por submit button