# encoding: UTF-8 module Wice module GridViewHelper # View helper to render the list of saved queries and the form to create a new query. # Parameters: # * :extra_parameters - a hash of additional parameters to use when creating a new query object. # * :confirm - A boolean value which turns on or off the JS confirm dialogs when deleting saved queries. # Read section "Adding Application Specific Logic to Saving/Restoring Queries" in README for more details. def saved_queries_panel(grid, opts = {}) unless grid.kind_of? WiceGrid raise WiceGridArgumentError.new("saved_queries_panel: the parameter must be a WiceGrid instance.") end options = {:extra_parameters => {}, :confirm => 1} opts.assert_valid_keys(options.keys) options.merge!(opts) grid_name = grid.name input_field_name = "#{grid_name}_saved_query_name" base_path_to_query_controller = create_serialized_query_url(:grid_name => grid_name, :confirm => options[:confirm]) parameters = grid.get_state_as_parameter_value_pairs options[:extra_parameters].each do |k, v| parameters << [ CGI.unescape({:extra => {k => ''}}.to_query.sub(/=$/,'')) , v.to_s ] end parameters << ['authenticity_token', form_authenticity_token] notification_messages_id = "#{grid_name}_notification_messages" (%!

#{NlMessage['saved_query_panel_title']}

! + saved_queries_list(grid_name, grid.saved_query, options[:extra_parameters], options[:confirm]) + %!
! + if block_given? view, ids = yield view else '' end + '
'+ text_field_tag(input_field_name, '', :onkeydown=>'', :class => 'wice-grid-save-query-field form-control ') + button_tag( NlMessage['save_query_button_label'], :class => 'wice-grid-save-query-button btn btn-primary', 'data-grid-name' => grid_name, 'data-base-path-to-query-controller' => base_path_to_query_controller, 'data-parameters' => parameters.to_json, 'data-ids' => ids.to_json ) + '
' ).html_safe end def saved_queries_list(grid_name, saved_query = nil, extra_parameters = {}, confirm = 1) #:nodoc: link_title = NlMessage['saved_query_link_title'] deletion_confirmation = confirm ? NlMessage['saved_query_deletion_confirmation'] : nil deletion_link_title = NlMessage['saved_query_deletion_link_title'] query_store_model = ::Wice::get_query_store_model currently_loaded_query_id = saved_query ? saved_query.id : nil with = extra_parameters.nil? ? nil : "'" + {:extra => extra_parameters}.to_query + "'" %!' end end end