summaryrefslogtreecommitdiffstats
path: root/app/views/queries/_form.html.erb
blob: 27391e8ef9dcc1ed6d7c0f1957ddd39df13c1770 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<%= error_messages_for 'query' %>

<div class="box">
<div class="tabular">
<%= hidden_field_tag 'gantt', '1' if params[:gantt] %>
<%= hidden_field_tag 'calendar', '1' if params[:calendar] %>
<%= hidden_field_tag 'admin_projects', '1' if params[:admin_projects] %>

<p><label for="query_name"><%=l(:field_name)%></label>
<%= text_field 'query', 'name', :size => 80 %></p>
<p><label for="query_description"><%=l(:field_description)%></label>
<%= text_field 'query', 'description', :size => 80 %></p>

<% if User.current.admin? ||
      User.current.allowed_to?(:manage_public_queries, @query.project) %>
<p><label><%=l(:field_visible)%></label>
  <label class="block"><%= radio_button 'query', 'visibility', Query::VISIBILITY_PRIVATE %> <%= l(:label_visibility_private) %></label>
  <label class="block"><%= radio_button 'query', 'visibility', Query::VISIBILITY_PUBLIC %> <%= l(:label_visibility_public) %></label>
  <% unless @query.type == 'ProjectQuery' %>
    <label class="block"><%= radio_button 'query', 'visibility', Query::VISIBILITY_ROLES %> <%= l(:label_visibility_roles) %>:</label>
      <% Role.givable.sorted.each do |role| %>
        <label class="block role-visibility"><%= check_box_tag 'query[role_ids][]', role.id, @query.roles.include?(role), :id => nil %> <%= role.name %></label>
      <% end %>
      <%= hidden_field_tag 'query[role_ids][]', '' %>
  <% end %>
</p>
<% end %>

<% unless @query.type == 'ProjectQuery' %>
  <p><label for="query_is_for_all"><%=l(:field_is_for_all)%></label>
  <%= check_box_tag 'query_is_for_all', 1, @query.project.nil?, :class => (User.current.admin? ? '' : 'disable-unless-private') %></p>
<% end %>

<% unless params[:calendar] %>
  <fieldset id="options"><legend><%= l(:label_options) %></legend>
    <% if @query.available_display_types.size > 1 %>
      <p><label for='display_type'><%= l(:label_display_type) %></label>
        <%= available_display_types_tags(@query) %>
      </p>
    <% elsif @query.available_display_types.size == 1 %>
      <%= hidden_field_tag 'query[display_type]', @query.available_display_types.first %>
    <% end %>

    <p id ="default_columns"><label for="query_default_columns"><%=l(:label_default_columns)%></label>
    <%= check_box_tag 'default_columns', 1, @query.has_default_columns?, :id => 'query_default_columns',
          :data => {:disables => "#columns, .block_columns input"} %></p>

    <% unless params[:gantt] %>
      <p id="group_by"><label for="query_group_by"><%= l(:field_group_by) %></label>
      <%= select 'query', 'group_by', @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, :include_blank => true %></p>

      <% unless @query.available_block_columns.empty? %>
        <p class="block_columns"><label><%= l(:button_show) %></label>
        <%= available_block_columns_tags(@query) %></p>
      <% end %>

      <% unless @query.available_totalable_columns.empty? %>
        <p class="totable_columns"><label><%= l(:label_total_plural) %></label>
        <%= available_totalable_columns_tags(@query) %></p>
      <% end %>
    <% else %>
      <p><label><%= l(:button_show) %></label>
      <%= hidden_field_tag 'query[draw_relations]', '0' %>
      <%= hidden_field_tag 'query[draw_progress_line]', '0' %>
      <%= hidden_field_tag 'query[draw_selected_columns]', '0' %>
      <label class="inline"><%= check_box_tag "query[draw_relations]", "1", @query.draw_relations %> <%= l(:label_related_issues) %></label>
      <label class="inline"><%= check_box_tag "query[draw_progress_line]", "1", @query.draw_progress_line %> <%= l(:label_gantt_progress_line) %></label>
      <label class="inline"><%= check_box_tag "query[draw_selected_columns]", "1", @query.draw_selected_columns, :data => { :enables => 'span.query-columns select, span.query-columns input'} %> <%= l(:description_selected_columns) %></label>
      </p>
    <% end %>
  </fieldset>
<% end %>
</div>

<fieldset id="filters"><legend><%= l(:label_filter_plural) %></legend>
<%= render :partial => 'queries/filters', :locals => {:query => query}%>
</fieldset>

<% if params[:calendar].nil? && params[:gantt].nil? %>
  <fieldset id="sort"><legend><%= l(:label_sort) %></legend>
    <% 3.times do |i| %>
    <%= content_tag(:span, "#{i+1}:", :class => 'query_sort_criteria_count')%>
    <%= label_tag "query_sort_criteria_attribute_" + i.to_s,
                  l(:description_query_sort_criteria_attribute), :class => "hidden-for-sighted" %>
    <%= select_tag("query[sort_criteria][#{i}][]",
                  options_for_select([[]] + query.available_columns.select(&:sortable?).collect {|column| [column.caption, column.name.to_s]}, @query.sort_criteria_key(i)),
                  :id => "query_sort_criteria_attribute_" + i.to_s)%>
    <%= label_tag "query_sort_criteria_direction_" + i.to_s,
                  l(:description_query_sort_criteria_direction), :class => "hidden-for-sighted" %>
    <%= select_tag("query[sort_criteria][#{i}][]",
                    options_for_select([[], [l(:label_ascending), 'asc'], [l(:label_descending), 'desc']], @query.sort_criteria_order(i)),
                    :id => "query_sort_criteria_direction_" + i.to_s) %>
    <br />
    <% end %>
  </fieldset>
<% end %>

<% unless params[:calendar] %>
  <%= content_tag 'fieldset', :id => 'columns' do %>
  <legend><%= l(:field_column_names) %></legend>
  <div id="list-definition">
    <div>
      <%= render_query_columns_selection(query) %>
    </div>
  </div>
  <% end %>
<% end %>

</div>

<%= javascript_tag do %>
$(document).ready(function(){
  $("input[name='query[visibility]']").change(function(){
    var roles_checked = $('#query_visibility_1').is(':checked');
    var private_checked = $('#query_visibility_0').is(':checked');
    $("input[name='query[role_ids][]'][type=checkbox]").attr('disabled', !roles_checked);
    if (!private_checked) $("input.disable-unless-private").attr('checked', false);
    $("input.disable-unless-private").attr('disabled', !private_checked);
  }).trigger('change');
});

$(function ($) {
  $('input[name=display_type]').change(function () {
    var option = $('input[name=display_type]:checked').val();
    if (option == 'board') {
      $('fieldset#columns, fieldset#sort, p#default_columns, p#group_by').hide();
    } else {
      $('fieldset#columns, fieldset#sort, p#default_columns, p#group_by').show();
    }
  }).change();
});
<% end %>