filter.execute(self, :user => current_user)
@widget_title = link_to h(filter.name), {:controller => 'measures', :action => 'filter', :id => filter.id, :display => 'list'}
%>
- <%= render :partial => "measures/display_#{filter.display.key}", :locals => {:edit_mode => false, :widget => widget, :filter => filter} %>
+ <%= render :partial => "measures/display_#{filter.display.key}", :locals => {:edit_mode => false, :filter => filter, :widget_id => widget.id} -%>
<%
end
else
if filter
url_options = {:controller => 'measures', :action => 'filter', :id => filter.id, :display => 'treemap'}
filter.load_criteria_from_data
- filter.set_criteria_value('display', 'treemap')
+ filter.set_criteria_value(:display, 'treemap')
if size_metric
- filter.set_criteria_value('tmSize', size_metric.key)
- url_options['tmSize']=size_metric.key
+ filter.set_criteria_value(:tmSize, size_metric.key)
+ url_options[:tmSize]=size_metric.key
end
if color_metric
- filter.set_criteria_value('tmColor', color_metric.key)
- url_options['tmColor']=color_metric.key
+ filter.set_criteria_value(:tmColor, color_metric.key)
+ url_options[:tmColor]=color_metric.key
end
if !filter.require_authentication? || logged_in?
@widget_title = link_to h(filter.name), url_options
%>
- <%= render :partial => "measures/display_#{filter.display.key}", :locals => {:edit_mode => false, :widget => widget, :filter => filter} %>
+ <%= render :partial => "measures/display_#{filter.display.key}", :locals => {:edit_mode => false, :widget_id => widget.id, :filter => filter} %>
<%
end
else
else
@filter = MeasureFilter.new
end
- @filter.criteria=(params)
+ @filter.criteria=(params.merge({:controller => nil, :action => nil, :search => nil, :widget_id => nil}))
@filter.enable_default_display
@filter.execute(self, :user => current_user)
+
+ if request.xhr?
+ render :partial => 'measures/display', :locals => {:filter => @filter, :edit_mode => false, :widget_id => params[:widget_id]}
+ end
end
# Load existing filter
"<a href='#{url}' modal-width='#{width}' class='open-modal #{clazz}' #{id}>#{h label}</a>"
end
+ def link_to_function_if(condition, name, *args)
+ condition ? link_to_function(name, args) : name
+ end
end
#
module MeasuresHelper
- def list_column_html(filter, column)
+ def list_column_html(filter, column, widget_id)
if column.sort?
- html = link_to_function(h(column.title_label), "reloadParameters({asc:'#{(!filter.sort_asc?).to_s}', sort:'#{column.key}'})", :title => h(column.tooltip))
+ html = link_to_function(h(column.title_label), "sortList#{widget_id}('#{escape_javascript column.key}',#{!filter.sort_asc?})", :title => h(column.tooltip))
else
html=h(column.title_label)
end
--- /dev/null
+<% if filter.security_exclusions %>
+ <p class="notes"><%= message('results_not_display_due_to_security') -%></p>
+<% end %>
+
+<% if !filter.errors.empty? %>
+ <% filter.errors.full_messages.each do |message| %>
+ <div class="warning"><%= h message %></div>
+ <% end %>
+<% elsif filter.rows && filter.display %>
+ <%= render :partial => "measures/display_#{filter.display.class::KEY}", :locals => {:filter => filter, :edit_mode => edit_mode, :widget_id => widget_id} -%>
+<% end %>
+<div id="measure_filter_list<%= widget_id -%>">
+<% content_for :script do %>
+ <script>
+ function refreshUrl<%= widget_id -%>(url) {
+ $j('#measure_filter_foot<%= widget_id -%>_pages').hide();
+ $j('#measure_filter_foot<%= widget_id -%>_loading').show();
+ <% if widget_id %>
+ $j('#measure_filter_list<%= widget_id -%>').load(url);
+ <% else %>
+ window.location = url;
+ <% end %>
+ return false;
+ }
+ function sortList<%= widget_id -%>(sort, asc) {
+ var url = decodeURI('<%= url_for filter.criteria.merge(:controller => 'measures', :action => 'search', :sort => nil, :asc => nil, :search => nil, :widget_id => widget_id, :trailing_slash => true) -%>');
+ url += '&sort=' + sort + '&asc=' + asc;
+ return refreshUrl<%= widget_id -%>(url);
+ }
+ function pageList<%= widget_id -%>(page) {
+ var url = decodeURI('<%= url_for filter.criteria.merge(:controller => 'measures', :action => 'search', :page => nil, :search => nil, :widget_id => widget_id, :trailing_slash => true) -%>');
+ url += '&page=' + page;
+ return refreshUrl<%= widget_id -%>(url);
+ }
+ </script>
<%
+ end
+
display_favourites = logged_in?
colspan = filter.display.columns.size
colspan += 1 if display_favourites
td1.remove();
});
}
+ $j(document).ready(function () {
+ $j("#select-metric").on("change", function (e) {
+ var selectedKey = $j("#select-metric option:selected").val();
+ if (selectedKey.indexOf('metric:') == 0) {
+ if (selectedKey.indexOf('metric:new_') == 0) {
+ $j('#select-period option :eq(0)').attr('disabled', 'disabled');
+ $j('#select-period ').val('1');
+ } else {
+ $j('#select-period option :eq(0)').removeAttr('disabled');
+ $j('#select-period').val('');
+ }
+ $j('#select-period').show();
+ } else {
+ $j('#select-period').hide();
+ }
+ $j("#add-metric").removeAttr('disabled');
+
+ });
+ $j("#add-metric").on("click", function (e) {
+ var columnKey = $j("#select-metric option:selected").val();
+ var period = $j("#select-period option:selected").val();
+ if (period.length > 0) {
+ columnKey += ':' + period;
+ }
+ cols.push(columnKey);
+ window.location = removeUrlAttr(decodeURI(window.location.href), 'cols\\[\\]') + '&' + $j.map(cols,function (a) {
+ return a ? 'cols[]=' + a : null;
+ }).join('&');
+ });
+ $j("#exit-edit").on("click", function (e) {
+ var url = removeUrlAttr(decodeURI(window.location.href), 'cols\\[\\]');
+ url = removeUrlAttr(url, 'edit');
+ url += '&' + $j.map(cols,function (a) {
+ return a ? 'cols[]=' + a : null;
+ }).join('&');
+ window.location = url;
+ });
+ });
</script>
<%
end
- end
%>
-
-<% if edit_mode %>
<table class="spaced width100 box">
<tr>
<td>
</td>
</tr>
</table>
- <script>
- $j("#select-metric").on("change", function (e) {
- var selectedKey = $j("#select-metric option:selected").val();
- if (selectedKey.indexOf('metric:') == 0) {
- if (selectedKey.indexOf('metric:new_') == 0) {
- $j('#select-period option :eq(0)').attr('disabled', 'disabled');
- $j('#select-period ').val('1');
- } else {
- $j('#select-period option :eq(0)').removeAttr('disabled');
- $j('#select-period').val('');
- }
- $j('#select-period').show();
- } else {
- $j('#select-period').hide();
- }
- $j("#add-metric").removeAttr('disabled');
-
- });
- $j("#add-metric").on("click", function (e) {
- var columnKey = $j("#select-metric option:selected").val();
- var period = $j("#select-period option:selected").val();
- if (period.length > 0) {
- columnKey += ':' + period;
- }
- cols.push(columnKey);
- window.location = removeUrlAttr(decodeURI(window.location.href), 'cols\\[\\]') + '&' + $j.map(cols,function (a) {
- return a ? 'cols[]=' + a : null;
- }).join('&');
- });
- $j("#exit-edit").on("click", function (e) {
- var url = removeUrlAttr(decodeURI(window.location.href), 'cols\\[\\]');
- url = removeUrlAttr(url, 'edit');
- url += '&' + $j.map(cols,function (a) {
- return a ? 'cols[]=' + a : null;
- }).join('&');
- window.location = url;
- });
- </script>
-<% end %>
+<%
+ end
+%>
<table class="data" id="measures-table">
<thead>
<th class="thin"></th>
<% end %>
<% filter.display.columns.each do |column| %>
- <%= list_column_html(filter, column) -%>
+ <%= list_column_html(filter, column, widget_id) -%>
<% end %>
</tr>
</thead>
<% end %>
</tbody>
- <%= render :partial => 'utils/tfoot_pagination', :locals => {:pagination => filter.pagination, :colspan => colspan} %>
-</table>
\ No newline at end of file
+ <% pagination_partial = widget_id ? 'utils/tfoot_ajax_pagination' : 'utils/tfoot_pagination' %>
+ <%= render :partial => pagination_partial, :locals => {
+ :pagination => filter.pagination,
+ :colspan => colspan,
+ :id => "measure_filter_foot#{widget_id}",
+ :include_loading => true,
+ :js_function => "pageList#{widget_id}"
+ } -%>
+</table>
+</div>
\ No newline at end of file
</div>
</div>
- <% if @filter.security_exclusions %>
- <p class="notes"><%= message('results_not_display_due_to_security') -%></p>
- <% end %>
-
- <% if !@filter.errors.empty? %>
- <% @filter.errors.full_messages.each do |message| %>
- <div class="warning"><%= h message %></div>
- <% end %>
- <% elsif @filter.rows && @filter.display %>
- <%= render :partial => "measures/display_#{@filter.display.class::KEY}", :locals => {:filter => @filter, :edit_mode => edit_mode} -%>
- <% end %>
+ <%= render :partial => 'measures/display', :locals => {:filter => @filter, :edit_mode => edit_mode, :widget_id => nil} -%>
</div>
</div>
<% end %>
--- /dev/null
+<tfoot <%= "id=#{id}" if id -%>>
+<tr>
+ <td colspan="<%= colspan || 1 -%>">
+ <div <%= "id=#{id}_pages" if id -%>>
+ <% if pagination.count > 0 %>
+ <%= message('x_results', :params => [pagination.count]) -%>
+ <% end %>
+ <%
+ if pagination.pages > 1
+ max_pages = pagination.pages
+ current_page = pagination.page
+ start_page = 1
+ end_page = max_pages
+ if max_pages > 20
+ if current_page < 12
+ start_page = 1
+ end_page = 20
+ elsif current_page > max_pages-10
+ start_page = max_pages-20
+ end_page = max_pages
+ else
+ start_page = current_page-10
+ end_page = current_page+9
+ end
+ end
+ %>
+ |
+ <% if max_pages > 20 && start_page > 1 %>
+ <%= link_to_function_if current_page != 1, message('paging_first'), "#{js_function}(1)" -%>
+ <% end %>
+ <%= link_to_function_if pagination.previous?, message('paging_previous'), "#{js_function}(#{current_page-1})" -%>
+ <% for index in start_page..end_page %>
+ <%= link_to_function_if index != current_page, index.to_s, "#{js_function}(#{index})" -%>
+ <% end %>
+ <%= link_to_function_if pagination.next?, message('paging_next'), "#{js_function}(#{current_page+1})" -%>
+ <% if max_pages > 20 && end_page < max_pages %>
+ <%= link_to_function_if current_page != max_pages, message('paging_last'), "#{js_function}(#{max_pages})" -%>
+ <%
+ end
+ end
+ %>
+ </div>
+ <% if id && local_assigns[:include_loading] %>
+ <img src="<%= ApplicationController.root_context -%>/images/loading-small.gif" style="display: none" id="<%= id -%>_loading">
+ <% end %>
+ </td>
+</tr>
+</tfoot>
\ No newline at end of file
-<tfoot>
+<tfoot <%= "id=#{id}" if id -%>>
<tr>
<td colspan="<%= colspan || 1 -%>">
+ <div <%= "id=#{id}_pages" if id -%>>
<% if pagination.count > 0 %>
<%= message('x_results', :params => [pagination.count]) -%>
<% end %>
%>
|
<% if max_pages > 20 && start_page > 1 %>
- <%= link_to_if current_page != 1, message('paging_first'), params.merge(:page => 1) %>
+ <%= link_to_if current_page != 1, message('paging_first'), params.merge(:page => 1) %>
<% end %>
<%= link_to_if pagination.previous?, message('paging_previous'), params.merge(:page => current_page-1) %>
<% for index in start_page..end_page %>
<% end %>
<%= link_to_if pagination.next?, message('paging_next'), params.merge(:page => current_page+1) %>
<% if max_pages > 20 && end_page < max_pages %>
- <%= link_to_if current_page != max_pages, message('paging_last'), params.merge(:page => max_pages) %>
+ <%= link_to_if current_page != max_pages, message('paging_last'), params.merge(:page => max_pages) %>
<% end %>
- <%
+ <%
end
%>
+ </div>
+ <% if id && local_assigns[:include_loading] %>
+ <img src="<%= ApplicationController.root_context -%>/images/loading-small.gif" style="display: none" id="<%= id -%>_loading">
+ <% end %>
</td>
</tr>
</tfoot>
\ No newline at end of file