<% locals = { owner: @owner,
              show_user_selection: @exceeded_limits[:active_user_limit_exceeded],
              show_project_selection: @exceeded_limits[:active_project_limit_exceeded],
              projects: @projects,
              users: @users,
              user_limit: @user_limit,
              project_limit: @project_limit,
              form_path: @form_path} %>


$modal = $('#ajax-modal');
$modal.html("<%= j(render partial: @partial_name, locals: locals, formats: [:html]) %>");
var el = $modal;
//      if (el.length === 0 || el.is(':visible')) {return;}
var mh = ERUI.topMenu.outerHeight();
var wh = window.innerHeight;
maxHeight = wh - mh - 200;
$modal.dialog({
  width: '650px',
  modal: true,
  resizable: false,
  dialogClass: 'modal easy-trial-expiration',
  maxHeight: maxHeight,
  maxWidth: '100%',
//        title: title,
  closeOnEscape: false,
  open: function( event, ui ) {
    ERUI.body.addClass('modal-opened');
//          initEasyAutocomplete();
    EasyToggler.ensureToggle();
    <% if User.current == @owner %>
      var buttons = [{text: '<%=j l(:button_save) %>', 'id' : 'modal_button_save', 'class': 'button-positive', 'onclick': "$('#ajax-modal').find('form').submit()"}];
      <% if @multiple_limits_exceeded %>
        buttons.push({text: '<%= l(:button_save) %>', 'id': 'modal_button_next', 'class': 'button-positive', 'onclick': "EASY.trialExpiration.showProjectSelection()"});
      <% end %>

      $modal.siblings('.ui-dialog-titlebar').html("<%= j(render partial: 'easy_trial_expiration/deactivate_entities/titlebar', locals: @exceeded_limits, formats: [:html]) %>");
      $modal.dialog("option", {
        buttons: buttons
      });
      $modal.siblings('.ui-dialog-buttonpane').append("<%= j(render partial: 'easy_trial_expiration/deactivate_entities/buttonpane', formats: [:html]) %>");

      <% if @multiple_limits_exceeded %>
        $('#modal_button_save').hide();
      <% end %>
    <% else %>
      $modal.siblings('.ui-dialog-titlebar').hide();
    <% end %>
  },
  close: function( event, ui ) {
    return false;
//          ERUI.body.removeClass('modal-opened');
//          $(this).dialog("destroy");
  }
});
ERUI.document.trigger( "erui_interface_change_modal" );
showModal('ajax-modal', 650);
