import { downloadVideoAndAddRowToTable } from '../table/table';

export var init = function () {
    const $body = $('body');
    const $form = $body.find('form');
    const $inputGroup = $form.find('.input-group');
    const $input = $inputGroup.find('input');
    const $submit = $form.find('button');
    const $icon = $submit.find('span');

    $input.on('input', function () {
        if ($inputGroup.hasClass('has-danger')) {
            $inputGroup.removeClass('has-danger');
        }
    });

    $form.on('submit', function (event) {
        $icon.addClass('fa-spin');
        $submit.prop('disabled', true);

        downloadVideoAndAddRowToTable($input.val(), onError, onSuccess);

        event.preventDefault();

        function onError(error) {
            console.log(error);
            $inputGroup.addClass('has-danger');
        }

        function onSuccess() {
            $input.val('').focus();
            $icon.removeClass('fa-spin');
            $submit.prop('disabled', false);
            $body.removeClass('center-vertical');
        }
    });
};

@@ -826,32 +826,65 @@
 ('has-danger');%0A
+            resetSubmitButton();%0A
         %7D%0A%0A     
@@ -939,16 +939,8 @@
 ('')
-.focus()
 ;%0A  
@@ -950,20 +950,20 @@
        $
-icon
+body
 .removeC
@@ -964,31 +964,39 @@
 emoveClass('
-fa-spin
+center-vertical
 ');%0A        
@@ -1003,40 +1003,78 @@
     
-$submit.prop('disabled', false);
+resetSubmitButton();%0A        %7D%0A%0A        function resetSubmitButton() %7B
 %0A   
@@ -1075,36 +1075,36 @@
  %7B%0A            $
-body
+icon
 .removeClass('ce
@@ -1101,32 +1101,77 @@
 eClass('
-center-vertical'
+fa-spin').focus();%0A            $submit.prop('disabled', false
 );%0A     

Fix error handling