fancygrid 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +9 -2
- data/Gemfile +6 -9
- data/Gemfile.lock +88 -103
- data/README.md +226 -0
- data/ROADMAP +0 -1
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/app/views/fancygrid/controls.html.haml +34 -0
- data/app/views/fancygrid/fancygrid.html.haml +18 -0
- data/app/views/fancygrid/search.html.haml +24 -0
- data/app/views/fancygrid/sort.html.haml +8 -0
- data/app/views/fancygrid/table.html.haml +25 -0
- data/config/locales/fancygrid.de.yml +17 -19
- data/config/locales/fancygrid.en.yml +14 -17
- data/fancygrid.gemspec +48 -88
- data/lib/assets/javascripts/fancygrid.js +425 -0
- data/lib/assets/javascripts/fancygrid.min.js +15 -0
- data/lib/assets/stylesheets/fancygrid.css +177 -0
- data/lib/fancygrid.rb +63 -44
- data/lib/fancygrid/column.rb +165 -0
- data/lib/fancygrid/controller/helper.rb +46 -0
- data/lib/fancygrid/grid.rb +171 -317
- data/lib/fancygrid/node.rb +85 -490
- data/lib/fancygrid/object_wrapper.rb +24 -0
- data/lib/fancygrid/orm/active_record.rb +39 -0
- data/lib/fancygrid/orm/sql_generator.rb +127 -0
- data/lib/fancygrid/view/helper.rb +44 -0
- data/lib/fancygrid/view_state.rb +161 -0
- data/spec/column_spec.rb +29 -0
- data/spec/dummy/app/controllers/application_controller.rb +48 -0
- data/spec/dummy/app/views/application/index.html.haml +11 -0
- data/spec/dummy/app/views/layouts/application.html.erb +1 -1
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/environments/development.rb +2 -2
- data/spec/dummy/config/environments/test.rb +2 -2
- data/spec/dummy/config/routes.rb +3 -2
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +26 -0
- data/spec/dummy/public/javascripts/jquery-1.4.2.js +6240 -0
- data/spec/dummy/public/javascripts/jquery-fancygrid.js +425 -0
- data/spec/dummy/public/javascripts/jquery-ui.js +41 -0
- data/spec/dummy/public/stylesheets/fancygrid.css +183 -0
- data/spec/node_spec.rb +79 -301
- data/spec/spec_helper.rb +0 -29
- data/spec/view_state_spec.rb +91 -0
- metadata +124 -137
- data/.bundle/config +0 -2
- data/README.rdoc +0 -299
- data/app/views/fancygrid/_cells.html.haml +0 -13
- data/app/views/fancygrid/base/controls.html.haml +0 -40
- data/app/views/fancygrid/base/list_frame.html.haml +0 -37
- data/app/views/fancygrid/base/search.html.haml +0 -33
- data/app/views/fancygrid/base/sort.html.haml +0 -20
- data/app/views/fancygrid/base/table_frame.html.haml +0 -45
- data/config/initializers/fancygrid.rb +0 -67
- data/lib/fancygrid/helper.rb +0 -129
- data/lib/fancygrid/query_generator.rb +0 -340
- data/lib/fancygrid/view.rb +0 -148
- data/lib/generators/install_generator.rb +0 -61
- data/lib/generators/views_generator.rb +0 -25
- data/lib/version.rb +0 -0
- data/public/images/fancygrid/add.png +0 -0
- data/public/images/fancygrid/clear.png +0 -0
- data/public/images/fancygrid/ddn.png +0 -0
- data/public/images/fancygrid/dn.png +0 -0
- data/public/images/fancygrid/dots.png +0 -0
- data/public/images/fancygrid/loading.gif +0 -0
- data/public/images/fancygrid/magnifier.png +0 -0
- data/public/images/fancygrid/next.png +0 -0
- data/public/images/fancygrid/order.png +0 -0
- data/public/images/fancygrid/prev.png +0 -0
- data/public/images/fancygrid/reload.png +0 -0
- data/public/images/fancygrid/remove.png +0 -0
- data/public/images/fancygrid/spacer.gif +0 -0
- data/public/images/fancygrid/submit.png +0 -0
- data/public/images/fancygrid/th_bg.png +0 -0
- data/public/images/fancygrid/up.png +0 -0
- data/public/images/fancygrid/uup.png +0 -0
- data/public/javascripts/fancygrid.js +0 -477
- data/public/javascripts/fancygrid.min.js +0 -17
- data/public/stylesheets/fancygrid.css +0 -289
- data/public/stylesheets/fancygrid.scss +0 -302
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/production.log +0 -0
- data/spec/dummy/log/server.log +0 -0
- data/spec/dummy/log/test.log +0 -1026
- data/spec/dummy/public/javascripts/application.js +0 -2
- data/spec/dummy/public/javascripts/controls.js +0 -965
- data/spec/dummy/public/javascripts/dragdrop.js +0 -974
- data/spec/dummy/public/javascripts/effects.js +0 -1123
- data/spec/dummy/public/javascripts/prototype.js +0 -6001
- data/spec/dummy/public/javascripts/rails.js +0 -175
- data/spec/grid_spec.rb +0 -15
- data/spec/integration/navigation_spec.rb +0 -9
- data/spec/query_generator_spec.rb +0 -358
data/lib/fancygrid/view.rb
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
require "active_support/hash_with_indifferent_access"
|
2
|
-
|
3
|
-
module Fancygrid#:nodoc:
|
4
|
-
|
5
|
-
class View
|
6
|
-
|
7
|
-
attr_accessor :grid
|
8
|
-
attr_accessor :view
|
9
|
-
|
10
|
-
def initialize(view)
|
11
|
-
load(view)
|
12
|
-
end
|
13
|
-
|
14
|
-
def load(view)
|
15
|
-
raise "'view' must be a hash" unless view.is_a?(Hash)
|
16
|
-
self.view = ActiveSupport::HashWithIndifferentAccess.new(view)
|
17
|
-
end
|
18
|
-
|
19
|
-
def dump
|
20
|
-
return self.view
|
21
|
-
end
|
22
|
-
|
23
|
-
def get_node_view_options(node)
|
24
|
-
opts = self.view[:columns] || {}
|
25
|
-
opts = opts[node.record_table_name] || {}
|
26
|
-
opts[node.name] or {}
|
27
|
-
end
|
28
|
-
|
29
|
-
def get_node_position(node)
|
30
|
-
opts = get_node_view_options(node)[:position]
|
31
|
-
if opts
|
32
|
-
opts.to_i
|
33
|
-
else
|
34
|
-
-1
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def get_node_visibility(node)
|
39
|
-
opts = get_node_view_options(node)[:visible].to_s
|
40
|
-
if %w(true false).include?(opts)
|
41
|
-
opts == "true"
|
42
|
-
else
|
43
|
-
node.visible
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def get_node_search_value(node)
|
48
|
-
hash = get_node_search_conditions(node).first
|
49
|
-
hash and hash[:value]
|
50
|
-
end
|
51
|
-
|
52
|
-
def get_node_search_conditions(node)
|
53
|
-
opts = self.view[:search] || {}
|
54
|
-
opts = self.view[:conditions] || {}
|
55
|
-
opts = opts[node.record_table_name] || {}
|
56
|
-
opts = opts[node.name] || {}
|
57
|
-
|
58
|
-
if opts.is_a?(String)
|
59
|
-
[{
|
60
|
-
:operator => :like,
|
61
|
-
:value => opts
|
62
|
-
}]
|
63
|
-
elsif opts.is_a?(Hash)
|
64
|
-
opts.map { |index, value|
|
65
|
-
if value.is_a?(Hash)
|
66
|
-
{
|
67
|
-
:operator => value[:operator].to_s || :like,
|
68
|
-
:value => value[:value].to_s
|
69
|
-
}
|
70
|
-
else
|
71
|
-
{
|
72
|
-
:operator => :like,
|
73
|
-
:value => value.to_s
|
74
|
-
}
|
75
|
-
end
|
76
|
-
}
|
77
|
-
elsif opts.is_a?(Array)
|
78
|
-
opts
|
79
|
-
else
|
80
|
-
[]
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def get_search_operator
|
85
|
-
opts = self.view[:search] || {}
|
86
|
-
opts = self.view[:operator].to_s
|
87
|
-
return opts if %w(all any).include?(opts)
|
88
|
-
return :any
|
89
|
-
end
|
90
|
-
|
91
|
-
def get_sort_order
|
92
|
-
opts = self.view[:order] || {}
|
93
|
-
if opts[:table] && opts[:column] && opts[:direction]
|
94
|
-
"#{opts[:table]}.#{opts[:column]} #{opts[:direction]}"
|
95
|
-
else
|
96
|
-
nil
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def get_pagination_page
|
101
|
-
opts = self.view[:pagination] || {}
|
102
|
-
opts[:page].to_i
|
103
|
-
end
|
104
|
-
|
105
|
-
def get_pagination_per_page
|
106
|
-
opts = self.view[:pagination] || {}
|
107
|
-
opts[:per_page].to_i
|
108
|
-
end
|
109
|
-
|
110
|
-
def search_visible
|
111
|
-
self.view[:search_visible]
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
# :fancygrid => {
|
118
|
-
# :<grid-name> => {
|
119
|
-
# :columns => {
|
120
|
-
# :<table> => {
|
121
|
-
# :<column> => {
|
122
|
-
# :visible => :<value>,
|
123
|
-
# :position => :<value>
|
124
|
-
# }
|
125
|
-
# }
|
126
|
-
# },
|
127
|
-
# :conditions => {
|
128
|
-
# :<table> => {
|
129
|
-
# :<column> => {
|
130
|
-
# :<number> => {
|
131
|
-
# :operator => :<operator>,
|
132
|
-
# :value => :<value>
|
133
|
-
# }
|
134
|
-
# }
|
135
|
-
# }
|
136
|
-
# },
|
137
|
-
# :operator => :<operator>,
|
138
|
-
# :order => {
|
139
|
-
# :table => :<table>,
|
140
|
-
# :column => :<column>,
|
141
|
-
# :direction => :<direction>
|
142
|
-
# },
|
143
|
-
# :pagination => {
|
144
|
-
# :page => :<value>,
|
145
|
-
# :per_page => :<value>
|
146
|
-
# }
|
147
|
-
# }
|
148
|
-
# }
|
@@ -1,61 +0,0 @@
|
|
1
|
-
module Fancygrid
|
2
|
-
module Generators#:nodoc:
|
3
|
-
|
4
|
-
class InstallGenerator < Rails::Generators::Base#:nodoc:
|
5
|
-
|
6
|
-
def copy_initializer
|
7
|
-
plugin_path = File.join(File.dirname(__FILE__), "../../config/initializers/fancygrid.rb")
|
8
|
-
rails_path = Rails.root.join('config/initializers/fancygrid.rb')
|
9
|
-
copy_file(plugin_path, rails_path)
|
10
|
-
end
|
11
|
-
|
12
|
-
def copy_default_cells_view
|
13
|
-
plugin_path = File.join(File.dirname(__FILE__), "../../app/views/fancygrid/_cells.html.haml")
|
14
|
-
rails_path = Rails.root.join("app/views/fancygrid/_cells.html.haml")
|
15
|
-
copy_file(plugin_path, rails_path)
|
16
|
-
end
|
17
|
-
|
18
|
-
def copy_javascript_source
|
19
|
-
js_source = File.join(File.dirname(__FILE__), '../../public/javascripts/fancygrid.js')
|
20
|
-
js_target = Rails.root.join('public/javascripts/fancygrid.js')
|
21
|
-
copy_file(js_source, js_target)
|
22
|
-
end
|
23
|
-
|
24
|
-
def copy_css
|
25
|
-
%w(css scss).each do |ext|
|
26
|
-
js_source = File.join(File.dirname(__FILE__), "../../public/stylesheets/fancygrid.#{ext}")
|
27
|
-
js_target = Rails.root.join("public/stylesheets/fancygrid.#{ext}")
|
28
|
-
copy_file(js_source, js_target)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def copy_images
|
33
|
-
%w(add.png clear.png ddn.png dn.png dots.png loading.gif magnifier.png next.png order.png prev.png reload.png remove.png spacer.gif submit.png th_bg.png up.png uup.png).each do |filename|
|
34
|
-
plugin_path = File.join(File.dirname(__FILE__), "../../public/images/fancygrid", filename)
|
35
|
-
rails_path = Rails.root.join('public/images/fancygrid', filename)
|
36
|
-
copy_file(plugin_path, rails_path)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def copy_locale
|
41
|
-
%w(de en).each do |locale|
|
42
|
-
plugin_path = File.join(File.dirname(__FILE__), "../../config/locales/fancygrid.#{locale}.yml")
|
43
|
-
rails_path = Rails.root.join("config/locales/fancygrid.#{locale}.yml")
|
44
|
-
copy_file(plugin_path, rails_path)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def print_info
|
49
|
-
puts "====================================================================="
|
50
|
-
puts ""
|
51
|
-
puts " Almost done. Next steps you have to do yourself"
|
52
|
-
puts " -----------------------------------------------"
|
53
|
-
puts " 1 include the javascript file in your layout : \"= javascript_include_tag 'fancygrid'\""
|
54
|
-
puts " 2 include the stylesheet file in your layout : \"= stylesheet_link_tag 'fancygrid'\""
|
55
|
-
puts ""
|
56
|
-
puts "====================================================================="
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Fancygrid
|
2
|
-
module Generators#:nodoc:
|
3
|
-
|
4
|
-
class ViewsGenerator < Rails::Generators::Base#:nodoc:
|
5
|
-
|
6
|
-
def copy_views
|
7
|
-
%w(controls list_frame table_frame search sort).each do |name|
|
8
|
-
plugin_path = File.join(File.dirname(__FILE__), "../../app/views/fancygrid/base/#{name}.html.haml")
|
9
|
-
rails_path = Rails.root.join("app/views/fancygrid/base/#{name}.html.haml")
|
10
|
-
copy_file(plugin_path, rails_path)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def print_info
|
15
|
-
puts "====================================================================="
|
16
|
-
puts ""
|
17
|
-
puts " Views have been copied to #{Rails.root.join('app/views/fancygrid/base')} "
|
18
|
-
puts " You can modify them as you wish"
|
19
|
-
puts ""
|
20
|
-
puts "====================================================================="
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
data/lib/version.rb
DELETED
File without changes
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,477 +0,0 @@
|
|
1
|
-
(function( $ ) {
|
2
|
-
|
3
|
-
$.fn.fancygrid = function(method) {
|
4
|
-
if ( methods[method] ) {
|
5
|
-
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
|
6
|
-
} else if (typeof(method) === 'object' || !method) {
|
7
|
-
return methods.init.apply(this, arguments);
|
8
|
-
} else {
|
9
|
-
$.error( 'Method ' + method + ' does not exist on jQuery.fancygrid' );
|
10
|
-
}
|
11
|
-
};
|
12
|
-
|
13
|
-
var methods = {
|
14
|
-
init : function(options){
|
15
|
-
var settings = {
|
16
|
-
url : "/",
|
17
|
-
ajaxType : "GET",
|
18
|
-
name : "",
|
19
|
-
query : {
|
20
|
-
pagination : {
|
21
|
-
page : (options.paginationPage || 0),
|
22
|
-
per_page : options.paginationPerPage
|
23
|
-
},
|
24
|
-
columns : {},
|
25
|
-
conditions : {},
|
26
|
-
operator : "any",
|
27
|
-
order : {}
|
28
|
-
},
|
29
|
-
searchFadeTime : 25,
|
30
|
-
searchFadeOpac : 0.5,
|
31
|
-
searchType : "simple",
|
32
|
-
queries : 0,
|
33
|
-
isStatic : false,
|
34
|
-
gridType : "table",
|
35
|
-
hideTopControl : false,
|
36
|
-
hideBottomControl : false
|
37
|
-
};
|
38
|
-
options = (options || {});
|
39
|
-
$.extend(settings, options);
|
40
|
-
|
41
|
-
return this.each(function(){
|
42
|
-
var $this = $(this);
|
43
|
-
var data = $this.data('fancygrid');
|
44
|
-
|
45
|
-
if (!data){
|
46
|
-
// initialize fancygrid
|
47
|
-
|
48
|
-
// set data
|
49
|
-
$this.data('fancygrid', settings);
|
50
|
-
|
51
|
-
// Hide the helper stuff
|
52
|
-
$(".fg-sort-window, .fg-sort-content, .fg-search-template").hide();
|
53
|
-
|
54
|
-
// hide search tab and controls if wanted
|
55
|
-
if (!settings.searchVisible){
|
56
|
-
$this.find(".fg-search").hide();
|
57
|
-
} else {
|
58
|
-
settings.searchVisible = true;
|
59
|
-
}
|
60
|
-
|
61
|
-
// bind control buttons with functions
|
62
|
-
|
63
|
-
// search attribute changed/focused
|
64
|
-
$this.find(".fg-search").find("input[type='text'], select").bind("change.fancygrid", function(){
|
65
|
-
$(this).parents(".fg-fancygrid").fancygrid('newSearch');
|
66
|
-
return false;
|
67
|
-
}).bind("focus.fancygrid", function(){
|
68
|
-
$(this).select();
|
69
|
-
return false;
|
70
|
-
});
|
71
|
-
|
72
|
-
// search attribute changed/focused
|
73
|
-
$this.find(".fg-page").bind("change.fancygrid", function(){
|
74
|
-
$(this).parents(".fg-fancygrid").fancygrid('page', $(this).val());
|
75
|
-
return false;
|
76
|
-
}).bind("focus.fancygrid", function(){
|
77
|
-
$(this).select();
|
78
|
-
return false;
|
79
|
-
});
|
80
|
-
|
81
|
-
// previous page click
|
82
|
-
$this.find(".fg-previous").bind("click.fancygrid", function(){
|
83
|
-
$(this).parents(".fg-fancygrid").fancygrid('previousPage');
|
84
|
-
return false;
|
85
|
-
});
|
86
|
-
|
87
|
-
// next page click
|
88
|
-
$this.find(".fg-next").bind("click.fancygrid", function(){
|
89
|
-
$(this).parents(".fg-fancygrid").fancygrid('nextPage');
|
90
|
-
return false;
|
91
|
-
});
|
92
|
-
|
93
|
-
// reload click
|
94
|
-
$this.find(".fg-reload").bind("click.fancygrid", function(){
|
95
|
-
$(this).parents(".fg-fancygrid").fancygrid('reloadPage');
|
96
|
-
return false;
|
97
|
-
});
|
98
|
-
|
99
|
-
// clear click
|
100
|
-
$this.find(".fg-clear").bind("click.fancygrid", function(){
|
101
|
-
$(this).parents(".fg-fancygrid").fancygrid('clearSearch');
|
102
|
-
return false;
|
103
|
-
});
|
104
|
-
|
105
|
-
// per page change
|
106
|
-
$this.find(".fg-per-page").bind("change.fancygrid", function(){
|
107
|
-
$(this).parents(".fg-fancygrid").fancygrid('perPage', $(this).val());
|
108
|
-
return false;
|
109
|
-
});
|
110
|
-
|
111
|
-
// magnifier click
|
112
|
-
$this.find(".fg-magnify").bind("click.fancygrid", function(){
|
113
|
-
$(this).parents(".fg-fancygrid").fancygrid('toggleSearch');
|
114
|
-
return false;
|
115
|
-
});
|
116
|
-
|
117
|
-
// sort click
|
118
|
-
$this.find(".fg-sort").bind("click.fancygrid", function(){
|
119
|
-
$(this).parents(".fg-fancygrid").fancygrid('showSortWindow');
|
120
|
-
return false;
|
121
|
-
});
|
122
|
-
|
123
|
-
//extended search submit
|
124
|
-
$this.find(".fg-search-submit").bind("click.fancygrid", function(){
|
125
|
-
$(this).parents(".fg-fancygrid").fancygrid('newSearch');
|
126
|
-
return false;
|
127
|
-
});
|
128
|
-
|
129
|
-
//button remove
|
130
|
-
$this.find(".fg-search-remove").click(function(){
|
131
|
-
$(this).parents(".fg-search-criterion").remove();
|
132
|
-
});
|
133
|
-
|
134
|
-
//button add new criterion
|
135
|
-
$this.find(".fg-search-add").click(function(){
|
136
|
-
$this.fancygrid("addCriterionRow");
|
137
|
-
});
|
138
|
-
|
139
|
-
// close the sort window if user clicked outside the sortable lists
|
140
|
-
$this.find(".fg-sort-content").click(function(){
|
141
|
-
$this.fancygrid("closeSortWindow");
|
142
|
-
});
|
143
|
-
$this.find(".fg-sortable").click(function(e){
|
144
|
-
e.stopPropagation();
|
145
|
-
});
|
146
|
-
|
147
|
-
} else {
|
148
|
-
// nothing to do when fancygrid is already initialized
|
149
|
-
$.extend(data, options);
|
150
|
-
}
|
151
|
-
});
|
152
|
-
},
|
153
|
-
//
|
154
|
-
// removes the plugin and clears the attached data
|
155
|
-
//
|
156
|
-
destroy : function(){
|
157
|
-
return this.each(function(){
|
158
|
-
var $this = $(this);
|
159
|
-
data = $this.data('fancygrid');
|
160
|
-
$this.unbind('.fancygrid');
|
161
|
-
$this.removeData('fancygrid');
|
162
|
-
});
|
163
|
-
},
|
164
|
-
//
|
165
|
-
// Fills the fancygrid query data with search conditions
|
166
|
-
//
|
167
|
-
setupConditions : function(){
|
168
|
-
var $this = $(this);
|
169
|
-
var data = $this.data('fancygrid');
|
170
|
-
|
171
|
-
data = $this.data('fancygrid');
|
172
|
-
data.query.conditions = {};
|
173
|
-
|
174
|
-
if (data.searchType === "simple"){
|
175
|
-
|
176
|
-
// process simple search
|
177
|
-
data.query.operator = "all";
|
178
|
-
|
179
|
-
$(this).find(".fg-attribute").each(function(){
|
180
|
-
data.query.conditions[$(this).attr("name")] = $(this).val();
|
181
|
-
});
|
182
|
-
} else {
|
183
|
-
|
184
|
-
// process complex search
|
185
|
-
|
186
|
-
data.query.operator = $this.find("#fg-search-conditions:checked").val() || "any";
|
187
|
-
|
188
|
-
$this.find("ul.fg-search-criteria li.fg-search-criterion").each(function(){
|
189
|
-
var column_name = $(this).find("select[name='column_name']").val();
|
190
|
-
var operator = $(this).find("select[name='operator']").val();
|
191
|
-
var value = $(this).find("input[name='column_value']").val();
|
192
|
-
|
193
|
-
if (typeof(data.query.conditions[column_name]) === "undefined"){
|
194
|
-
data.query.conditions[column_name] = [];
|
195
|
-
}
|
196
|
-
|
197
|
-
data.query.conditions[column_name].push({
|
198
|
-
operator : operator,
|
199
|
-
value : value
|
200
|
-
});
|
201
|
-
});
|
202
|
-
}
|
203
|
-
},
|
204
|
-
//
|
205
|
-
// Fills the fancygrid query data with emputy search conditions
|
206
|
-
//
|
207
|
-
setupEmptyConditions : function(){
|
208
|
-
var $this = $(this);
|
209
|
-
var data = $this.data('fancygrid');
|
210
|
-
|
211
|
-
data.query.conditions = {};
|
212
|
-
},
|
213
|
-
//
|
214
|
-
// Fills the fancygrid query data with pagination conditions
|
215
|
-
//
|
216
|
-
setupPagination : function(page, perPage){
|
217
|
-
var $this = $(this);
|
218
|
-
var data = $this.data('fancygrid');
|
219
|
-
|
220
|
-
data.query.pagination = { page : 0, per_page : 20 };
|
221
|
-
if(!isNaN(Number(page)) && Number(page) >= 0){
|
222
|
-
data.query.pagination.page = page;
|
223
|
-
}
|
224
|
-
if (!isNaN(Number(perPage)) && Number(perPage) > 0){
|
225
|
-
data.query.pagination.per_page = perPage;
|
226
|
-
}
|
227
|
-
},
|
228
|
-
setupOrder : function(){
|
229
|
-
var $this = $(this);
|
230
|
-
var data = $this.data('fancygrid');
|
231
|
-
var order = {};
|
232
|
-
var column = $this.find("th.fg-orderable[order='ASC'], th.fg-orderable[order='DESC']");
|
233
|
-
|
234
|
-
if (column.length > 0){
|
235
|
-
order.table = column.attr("table");
|
236
|
-
order.column = column.attr("column");
|
237
|
-
order.direction = column.attr("order");
|
238
|
-
}
|
239
|
-
|
240
|
-
data.query.order = order;
|
241
|
-
},
|
242
|
-
//
|
243
|
-
// Fills the fancygrid query data with column order and column visibility conditions
|
244
|
-
//
|
245
|
-
setupColumns : function(){
|
246
|
-
var $this = $(this);
|
247
|
-
var data = $this.data('fancygrid');
|
248
|
-
var columns = {};
|
249
|
-
|
250
|
-
var visibleArray = $this.find('.fg-sortable-visible li:not(.fg-not-sortable)');
|
251
|
-
var hiddenArray = $this.find('.fg-sortable-hidden li:not(.fg-not-sortable)');
|
252
|
-
|
253
|
-
var index = 0;
|
254
|
-
$(visibleArray).each(function(){
|
255
|
-
columns[$(this).attr("id")] = {
|
256
|
-
visible : true,
|
257
|
-
position : index
|
258
|
-
};
|
259
|
-
index += 1;
|
260
|
-
});
|
261
|
-
$(hiddenArray).each(function(){
|
262
|
-
columns[$(this).attr("id")] = {
|
263
|
-
visible : false,
|
264
|
-
position : index
|
265
|
-
};
|
266
|
-
index += 1;
|
267
|
-
});
|
268
|
-
|
269
|
-
data.query.columns = columns;
|
270
|
-
},
|
271
|
-
order : function(){
|
272
|
-
return "";
|
273
|
-
},
|
274
|
-
search : function(){
|
275
|
-
var $this = $(this);
|
276
|
-
var $content = $this.find(".fg-tablewrapper");
|
277
|
-
var $control = $this.find(".fg-control-bar");
|
278
|
-
var data = $this.data('fancygrid');
|
279
|
-
data.queries += 1;
|
280
|
-
data.query.search_visible = $this.find(".fg-search").is(":visible");
|
281
|
-
|
282
|
-
$control.find(".fg-reload").addClass("loading");
|
283
|
-
$this.fadeTo(data.searchFadeTime, data.searchFadeOpac);
|
284
|
-
|
285
|
-
queryData = { "fancygrid" : {} };
|
286
|
-
queryData.fancygrid[data.name] = data.query;
|
287
|
-
|
288
|
-
$.ajax({
|
289
|
-
type : data.ajaxType,
|
290
|
-
url : data.url,
|
291
|
-
data : queryData,
|
292
|
-
dataType : "html",
|
293
|
-
success : function(result){
|
294
|
-
data.queries -= 1;
|
295
|
-
if(data.queries === 0){
|
296
|
-
$this.fancygrid("replaceContent", $(result).find(".fg-tablewrapper"));
|
297
|
-
|
298
|
-
$control.find(".fg-per-page").val(data.query.pagination.per_page);
|
299
|
-
$control.find(".fg-page").val(Number(data.query.pagination.page) + 1);
|
300
|
-
|
301
|
-
total = (Number($(result).find(".fg-result-total").html()));
|
302
|
-
totalPages = total / data.query.pagination.per_page;
|
303
|
-
totalPages = (totalPages | 0) + 1;
|
304
|
-
|
305
|
-
$control.find(".fg-page-total").text(totalPages);
|
306
|
-
$control.find(".fg-result-total").html(total);
|
307
|
-
|
308
|
-
$this.fadeTo(data.searchFadeTime, 1.0, function(){
|
309
|
-
$control.find(".fg-reload").removeClass("loading");
|
310
|
-
});
|
311
|
-
}
|
312
|
-
$this.trigger("loadSuccess");
|
313
|
-
},
|
314
|
-
error : function(){
|
315
|
-
data.queries -= 1;
|
316
|
-
if(data.queries === 0){
|
317
|
-
$content.find(".fg-row").detach();
|
318
|
-
$this.fadeTo(data.searchFadeTime, 1.0, function(){
|
319
|
-
$control.find(".fg-reload").removeClass("loading");
|
320
|
-
});
|
321
|
-
}
|
322
|
-
$this.trigger("loadError");
|
323
|
-
}
|
324
|
-
});
|
325
|
-
},
|
326
|
-
replaceContent : function(newContent){
|
327
|
-
var $this = $(this);
|
328
|
-
var data = $this.data('fancygrid');
|
329
|
-
|
330
|
-
var focused_id = $this.find("input:focus").attr("id");
|
331
|
-
|
332
|
-
// replace the content
|
333
|
-
$this.find(".fg-tablewrapper").replaceWith(newContent);
|
334
|
-
|
335
|
-
// rebind events to search input fields
|
336
|
-
$this.find(".fg-tablewrapper").find(".fg-search").find("input[type='text'], select").bind("change.fancygrid", function(){
|
337
|
-
$(this).parents(".fg-fancygrid").fancygrid('newSearch');
|
338
|
-
return false;
|
339
|
-
}).bind("focus.fancygrid", function(){
|
340
|
-
$(this).select();
|
341
|
-
return false;
|
342
|
-
});
|
343
|
-
|
344
|
-
$this.find("th.fg-orderable").click(function(){
|
345
|
-
$this.fancygrid("orderBy", $(this));
|
346
|
-
});
|
347
|
-
|
348
|
-
if (data.searchVisible){
|
349
|
-
$this.find(".fg-search").show();
|
350
|
-
} else {
|
351
|
-
$this.find(".fg-search").hide();
|
352
|
-
}
|
353
|
-
|
354
|
-
if (focused_id){
|
355
|
-
$this.find("#" + focused_id).focus();
|
356
|
-
}
|
357
|
-
},
|
358
|
-
nextPage : function(){
|
359
|
-
var $this = $(this);
|
360
|
-
data = $this.data('fancygrid');
|
361
|
-
$this.fancygrid("setupPagination", data.query.pagination.page + 1, data.query.pagination.per_page);
|
362
|
-
$this.fancygrid("search");
|
363
|
-
},
|
364
|
-
previousPage : function(){
|
365
|
-
var $this = $(this);
|
366
|
-
data = $this.data('fancygrid');
|
367
|
-
$this.fancygrid("setupPagination", data.query.pagination.page - 1, data.query.pagination.per_page);
|
368
|
-
$this.fancygrid("search");
|
369
|
-
},
|
370
|
-
perPage : function(perPage){
|
371
|
-
var $this = $(this);
|
372
|
-
data = $this.data('fancygrid');
|
373
|
-
$this.fancygrid("setupPagination", 0, perPage);
|
374
|
-
$this.fancygrid("search");
|
375
|
-
},
|
376
|
-
page : function(page){
|
377
|
-
var $this = $(this);
|
378
|
-
data = $this.data('fancygrid');
|
379
|
-
$this.fancygrid("setupPagination", Number(page) - 1, data.query.pagination.per_page);
|
380
|
-
$this.fancygrid("search");
|
381
|
-
},
|
382
|
-
reloadPage : function(){
|
383
|
-
var $this = $(this);
|
384
|
-
data = $this.data('fancygrid');
|
385
|
-
$this.fancygrid("setupPagination", data.query.pagination.page, data.query.pagination.per_page);
|
386
|
-
$this.fancygrid("setupConditions");
|
387
|
-
$this.fancygrid("setupColumns");
|
388
|
-
$this.fancygrid("setupOrder");
|
389
|
-
$this.fancygrid("search");
|
390
|
-
},
|
391
|
-
newSearch : function(){
|
392
|
-
var $this = $(this);
|
393
|
-
data = $this.data('fancygrid');
|
394
|
-
$this.fancygrid("setupPagination", 0, data.query.pagination.per_page);
|
395
|
-
$this.fancygrid("setupConditions");
|
396
|
-
$this.fancygrid("setupColumns");
|
397
|
-
$this.fancygrid("setupOrder");
|
398
|
-
$this.fancygrid("search");
|
399
|
-
},
|
400
|
-
clearSearch : function(){
|
401
|
-
var $this = $(this);
|
402
|
-
data = $this.data('fancygrid');
|
403
|
-
|
404
|
-
// clear simple search
|
405
|
-
$this.find(".fg-attribute").each(function(){
|
406
|
-
$(this).val("");
|
407
|
-
});
|
408
|
-
|
409
|
-
// clear complex search
|
410
|
-
$this.find("ul.fg-search-criteria li.fg-search-criterion").detach();
|
411
|
-
|
412
|
-
//$this.fancygrid("setupPagination", 0, data.query.pagination.per_page);
|
413
|
-
$this.fancygrid("setupEmptyConditions");
|
414
|
-
$this.fancygrid("search");
|
415
|
-
},
|
416
|
-
toggleSearch : function(){
|
417
|
-
var $this = $(this);
|
418
|
-
data = $this.data('fancygrid');
|
419
|
-
|
420
|
-
// toggle only the simple search
|
421
|
-
$this.find(".fg-search").toggle();
|
422
|
-
data.searchVisible = $this.find(".fg-search").is(":visible");
|
423
|
-
},
|
424
|
-
addCriterionRow : function(){
|
425
|
-
var $this = $(this);
|
426
|
-
var row = $($this.find(".fg-search-template").html());
|
427
|
-
|
428
|
-
// add criterion row
|
429
|
-
$this.find("ul.fg-search-criteria").append(row);
|
430
|
-
|
431
|
-
// button remove
|
432
|
-
row.find(".fg-search-remove").click(function(){
|
433
|
-
$(this).parents(".fg-search-criterion").remove();
|
434
|
-
});
|
435
|
-
|
436
|
-
row.find("input[type='text']").bind("change.fancygrid", function(){
|
437
|
-
$(this).parents(".fg-fancygrid").fancygrid('newSearch');
|
438
|
-
return false;
|
439
|
-
}).bind("focus.fancygrid", function(){
|
440
|
-
$(this).select();
|
441
|
-
return false;
|
442
|
-
});
|
443
|
-
},
|
444
|
-
showSortWindow : function(){
|
445
|
-
var $this = $(this);
|
446
|
-
|
447
|
-
$this.find(".fg-sort-window").show();
|
448
|
-
$this.find(".fg-sort-content").show();
|
449
|
-
|
450
|
-
$this.find(".fg-sortable").sortable({
|
451
|
-
connectWith: ".fg-sortable",
|
452
|
-
items: "li:not(.fg-not-sortable)"
|
453
|
-
});
|
454
|
-
},
|
455
|
-
closeSortWindow : function(){
|
456
|
-
var $this = $(this);
|
457
|
-
$this.find(".fg-sort-window").hide();
|
458
|
-
$this.find(".fg-sort-content").hide();
|
459
|
-
$this.fancygrid("reloadPage");
|
460
|
-
},
|
461
|
-
orderBy : function(column){
|
462
|
-
$this = $(this);
|
463
|
-
|
464
|
-
var old_order = column.attr("order");
|
465
|
-
|
466
|
-
$this.find("th.fg-orderable").removeAttr("order");
|
467
|
-
|
468
|
-
if (old_order === "DESC"){
|
469
|
-
column.attr("order", "ASC");
|
470
|
-
} else {
|
471
|
-
column.attr("order", "DESC");
|
472
|
-
}
|
473
|
-
|
474
|
-
$this.fancygrid("reloadPage");
|
475
|
-
}
|
476
|
-
};
|
477
|
-
})(jQuery);
|