class SpeedCorrectionController extends BasicController {
    constructor(model) {
        super(model);
    }

    changeCorrection(e) {
        validateRange($(e.target), 1, -20, 20, 0);
        //Column 0 is the Heel Angle column, Row 0 is BSPD row, Row 1 is Heel Angle title row
        this.model.setCorrectionAtIndex($(e.target).closest('tr').index() - 2, $(e.target).closest('td').index() - 1, $(e.target).val());
    }

    clickCancel(e) {
        var url = new URL(window.location.href);
        if (url.searchParams.get("previous") != null) {
            window.location.href = url.searchParams.get("previous") + "?src=" + url.searchParams.get("src") + "&params=" + url.searchParams.get("parameters");
        } else {
            window.location.href = $('#atp-header').find('#' + $(e.target).parents('section').last().attr('data-heading')).attr('href');
        }
    }

    clickOK(e) {
        this.model.persistData().done(function() {
            var url = new URL(window.location.href);
            if (url.searchParams.get("previous") != null) {
                window.location.href = url.searchParams.get("previous") + "?src=" + url.searchParams.get("src") + "&params=" + url.searchParams.get("parameters");
            } else {
                window.location.href = $('#atp-header').find('#' + $(e.target).parents('section').last().attr('data-heading')).attr('href');
            }
        });
    }

    resetCorrections() {
        this.model.resetCorrections();
        this.model.notifyAll();
    }
}
