{% extends 'base.html' %}
{% load i18n %}
{% block title %}{% trans "Data Processing" %}{% endblock %}

{% block page_header %}
{% include "horizon/common/_page_header.html" with title=_("Jobs") %}
{% endblock page_header %}

{% block main %}
<style type="text/css">
    .job_origin_main, .job_origin_lib {
    width: 200px !important; }
    .job_binary_add_button, .job_binary_remove_button {
    width: 80px !important;
    margin-left: 5px; }
    .form-help-block {
    float: left;
    text-align: left;
    width: 300px; }
    .lib-input-div {
    float:left;
    width:320px; }
    .job-libs-display {
    float:left; }
</style>
<div class="job_origins">
    {{ jobs_table.render }}
</div>

<script type="text/javascript">
        addHorizonLoadEvent(function () {
            horizon.modals.addModalInitFunction(function (modal) {
                hide_extra_fields();

                function hide_extra_fields() {
                    for(i=2; i <= $("[name=extra_locations]").val(); i++) {
                      $("[name=job_main_" + i + "]").closest(".form-group").hide();
                      $("[name=job_lib_" + i + "]").closest(".form-group").hide();
                    }
                }

                if ($(modal).find(".nav-tabs").find("li").size() == 1) {
                    // hide tab bar for plugin/version modal wizard
                   $('div#modal_wrapper ul.nav-tabs').hide();
                }

                $(".hidden_nodegroups_field").val("");
                $(".hidden_configure_field").val("");

                lower_limit = 0;
                $(".count-field").change();
                if ($(modal).find(".hidden_create_field").length > 0) {
                    var form = $(".hidden_create_field").closest("form");
                    var successful = false;
                    form.submit(function (e) {
                            var oldHref = $(".create_job_class")[0].href;
                            var plugin = $("#id_plugin_name option:selected").val();
                            var version = $("#id_" + plugin + "_version option:selected").val();
                            var job_id = $("#id_job_id").val();
                            form.find(".close").click();
                            $(".create_job_class")[0].href = "launch-job-new-cluster?" +
                                    "plugin_name=" + encodeURIComponent(plugin) +
                                    "&hadoop_version=" + encodeURIComponent(version) +
                                    "&job_id=" + encodeURIComponent(job_id);
                            $(".create_job_class").click();
                            $(".create_job_class")[0].href = oldHref;
                            return false;
                    });
                    $(".plugin_version_choice").closest(".form-group").hide();
                }

                //display version for selected plugin
                $(document).on('change', '.plugin_name_choice', switch_versions);
                function switch_versions() {
                    $(".plugin_version_choice").closest(".form-group").hide();
                    var plugin = $(this);
                    $("." + plugin.val() + "_version_choice").closest(".form-group").show();
                }
                $(".plugin_name_choice").change();

                $(document).on('change', '#id_job_type', switch_job_type);
                function switch_job_type() {
                  job_type = $("#id_job_type").val();
                  if ($.inArray(job_type, ["MapReduce", "Java"]) != -1) {
                    $("#id_main_binary").closest(".form-group").hide();
                  } else {
                    $("#id_main_binary").closest(".form-group").show();
                  }
                }
                $("#id_job_type").change();
            });
        });

        addExtraBinary = function (where_from) {
          var loc_type = where_from.previousSibling.name.contains("main") ? "main" : "lib";
          for(i=2; i <= $("[name=extra_locations]").val(); i++) {
            if (!$("[name=job_" + loc_type + "_" + i + "]").closest(".form-group").is(":visible")) {
                $("[name=job_" + loc_type + "_" + i + "]").closest(".form-group").show();
                break;
            }
          }
        };
</script>
{% include "project/data_processing.job_binaries/job_binaries_form_script.html" %}

{% endblock %}
