<form id="create-dashboard-form" method="post" action="<%= ApplicationController.root_context -%>/dashboards/create">
  <% if @global %>
    <input type="hidden" name="global" value="true" />
  <% else %>
    <input type="hidden" name="resource" value="<%= h params[:resource] %>"/>
  <% end %>
  <fieldset>
    <div class="modal-head">
      <h2><%= message('dashboard.new_dashboard') -%></h2>
    </div>
    <div class="modal-body">
      <% if @dashboard %>
        <% @dashboard.errors.full_messages.each do |msg| %>
          <p class="error"><%= h msg -%></p>
        <% end %>
      <% end %>
      <div class="modal-field">
        <label for="name"><%= h message('name') -%> <em class="mandatory">*</em></label>
        <input id="name" name="name" type="text" size="50" maxlength="256" value="<%= h @dashboard.name -%>" autofocus="autofocus"/>
      </div>
      <div class="modal-field">
        <label for="description"><%= h message('description') -%></label>
        <input id="description" name="description" type="text" size="50" maxlength="4000" value="<%= h @dashboard.description -%>"/>
      </div>
      <% if has_role?(:shareDashboard) %>
        <div class="modal-field">
          <label for="shared"><%= h message('shared') -%></label>
          <input id="shared" name="shared" type="checkbox" value="true" <%= 'checked' if @dashboard.shared -%>/>
        </div>
      <% end %>
    </div>
    <div class="modal-foot">
      <input type="submit" value="<%= h message('dashboard.create_dashboard') -%>" id="save-submit"/>
      <a href="#" onclick="return closeModalWindow()" id="save-cancel"><%= h message('cancel') -%></a>
    </div>
  </fieldset>
</form>

<script>
  $j("#create-dashboard-form").modalForm({success: function (data) {
    var contextParams = data.trim().length > 0 ? '?resource=' + data.trim() : '';
    window.location = baseUrl + '/dashboards' + contextParams;
  }});
</script>

