Class: Grapple::AjaxDataGridBuilder

Inherits:
DataGridBuilder show all
Defined in:
lib/grapple/ajax_data_grid_builder.rb

Constant Summary collapse

CONTAINER_CLASSES =
'grapple grapple-ajax grapple-ajax-loading'
@@next_id =
1000

Instance Attribute Summary

Attributes inherited from BaseTableBuilder

#columns, #namespace, #params, #records, #template

Instance Method Summary collapse

Methods inherited from HtmlTableBuilder

#before_container, #container, #table

Methods inherited from BaseTableBuilder

#before_table, configure, #container, #default_options, helper, #initialize

Constructor Details

This class inherits a constructor from Grapple::BaseTableBuilder

Instance Method Details

#after_containerObject


37
38
39
40
41
# File 'lib/grapple/ajax_data_grid_builder.rb', line 37

def after_container
	selector = '#' + @options[:id]
	js = "$(#{selector.to_json}).grapple();"
	return template.javascript_tag(js)
end

#after_tableObject


32
33
34
35
# File 'lib/grapple/ajax_data_grid_builder.rb', line 32

def after_table
	style = 'background-image: url(' + template.image_path("grapple/loading-bar.gif") + ')'
	template. :div, '', class: 'loading-overlay', style: style
end

#container_attributesObject


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/grapple/ajax_data_grid_builder.rb', line 8

def container_attributes	
	@@next_id += 1
	@options[:id] ||= "grapple_ajax_table_#{@@next_id}"
	css = CONTAINER_CLASSES
	css += " #{@options[:container_class]}" unless @options[:container_class].nil?

	data = {
		"grapple-ajax-url" => @options[:url] || template.url_for(action: 'table'),
		# History is disabled by default, override container_attributes
		# in an initializer to enable it by default
		"grapple-ajax-history" => @options[:history] == true ? '1' : '0'
	}
	
	# The namespace allows the query parameters to be namespaced so 
	# multiple tables can exist on the same page
	data["grapple-ajax-namespace"] = @options[:namespace] unless @options[:namespace].nil?
	
	return {
		:id => @options[:id],
		:class => css,
		:data => data
	}
end