<% content_for :body_bottom do %>
  <%=
    if params['combine_by_pipeline'].nil?
      if Rails.env.development? && ENV['DART'] == '1'
        javascript_include_tag('http://localhost:8080/main.dart', type: 'application/dart')
      else
        javascript_include_tag('dart.min.js', defer: true)
      end
    else
      if params['combine_by_pipeline'] == 'false'
        javascript_include_tag('http://localhost:8080/main.dart', type: 'application/dart')
      elsif params['combine_by_pipeline'] == 'true'
        javascript_include_tag('dart.min.js', defer: true)
      else
        javascript_include_tag('dart.js', defer: true)
      end
    end
  %>
<% end %>

<% content_for :header_tags do %>
    <%= stylesheet_link_tag('angular_commons.css', plugin: 'easy_extensions') %>
    <%
      standard_lang_files = [
          :notice_successful_create,
          :notice_successful_update,
          :notice_successful_delete,
          :error_default_server_error,
          :notice_not_implemented,
          :notice_service_unavailable,
          :notice_not_authorized,
          :notice_not_acceptable,
          :label_updated_on,

          :field_created_on,
          :field_updated_on,
          :field_tracker,
          :field_description,
          :field_assigned_to,
          :field_status,
          :field_fixed_version,
          :field_done_ratio,
          :field_start_date,
          :field_due_date,
          :field_estimated_hours,
          :field_homepage,
          :field_author,
          :field_spent_hours,
          :field_priority,
          :field_activity,
          :field_category,

          :button_save,
          :button_delete,
          :button_submit,
          :label_expand_editor,
          :label_collapse_editor,
          :text_are_you_sure,
          :general_text_Yes,
          :general_text_No,
          :button_cancel,
          :button_print,
          :button_edit,
          :button_close,
          :label_favorite,
          :label_unfavorite,
          :button_fullscreen,
          :label_no_entity_selected,
          :date
      ]

      user = User.current

      front_end_commons = {
          global_settings: {
              locale: I18n.locale,
              date_format: Setting.date_format,
              html5_dates: EasySetting.value('html5_dates'),
              ckeditor_toolbar_config:  EasySetting.value('ckeditor_toolbar_config') || 'Basic',
              show_issue_id: EasySetting.value('show_issue_id')
          },
          user: {
              id: User.current.id,
              name: User.current.name,
              avatar_url: avatar_url(user)
          },
          urls:{
              project: {
                  available_trackers: easy_autocomplete_path(action: "allowed_issue_trackers", project_id: "__projectID", format: "json"),
                  get: projects_path(:project_id=> "__projectID", format: "json")
              },
              issue:{
                  available_values: url_for(controller: :easy_issues, action: :form_fields_v2, project_id: "__projectID", id: "__issueID", format: "json"),
                  available_values_no_id: url_for(controller: :easy_issues, action: :form_fields_v2, project_id: "__projectID", id: nil, format: "json")

              }
          },
          standard_lang_files: Hash[ *standard_lang_files.collect { |v| [ v, l(v) ] }.flatten ]
      }

    %>
    <script>
        window.frontEndCommons = <%= front_end_commons.to_json.html_safe %>;

        function interopAdapterForLookupCustomFieldDialog(url, closeButtonLabel, submitButtonLabel, fieldId, selectedValues, onClose) {
            $.post(url, {'selected_values': selectedValues}, function (data) {
                var ajaxModal = $("#ajax-modal");
                if ($('#easy_modal').length === 0) {
                    ajaxModal.parent().append($("<div/>").attr({id: "easy_modal"}).hide());
                }
                var modal = $('#easy_modal');
                modal.html(data);

                EASY.modalSelector.showEasyModal(function () {
                    return [url + '&' + $('#modal_selector_query_form, .modal-selected-values form').serialize() + '&page=', ''];
                });

                var btns = [];

                btns.push({
                    text: closeButtonLabel,
                    click: function () {
                        $(this).dialog('close');
                    },
                    'class': 'button'
                });

                btns.push({
                    text: submitButtonLabel,
                    click: function () {
                        EASY.modalSelector.saveAndCloseModal(fieldId);
                        onClose();
                    },
                    'class': 'button-positive'
                });

                modal.dialog({title: $("#" + fieldId + "_lookup_trigger_container").prev("label").text(), buttons: btns});
            });
        }

    </script>
<% end %>
