compass-jquery-plugin 0.3.0.beta.21 → 0.3.0.beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +212 -211
- data/VERSION.yml +5 -5
- data/compass-jquery-plugin.gemspec +25 -2
- data/gem_tasks/jqtouch.rake +221 -201
- data/gem_tasks/jrails.rake +322 -311
- data/lib/compiler.jar +0 -0
- data/lib/jquery/flash_messages.rb +45 -45
- data/lib/jquery/gridify/grid.rb +147 -147
- data/lib/jquery/gridify/grid_column.rb +134 -134
- data/lib/jquery/gridify/grid_finder.rb +223 -211
- data/lib/jquery/gridify/grid_options.rb +279 -279
- data/lib/jquery/gridify/grid_view.rb +435 -436
- data/lib/jquery/gridify.rb +42 -42
- data/templates/dynatree/jquery.dynatree.min.js +1 -1
- data/templates/jqgrid/i18n/jqgrid/locale-bg.min.js +6 -15
- data/templates/jqgrid/i18n/jqgrid/locale-bg1251.min.js +6 -15
- data/templates/jqgrid/i18n/jqgrid/locale-cat.min.js +5 -6
- data/templates/jqgrid/i18n/jqgrid/locale-cn.min.js +5 -8
- data/templates/jqgrid/i18n/jqgrid/locale-cs.min.js +6 -8
- data/templates/jqgrid/i18n/jqgrid/locale-da.min.js +6 -6
- data/templates/jqgrid/i18n/jqgrid/locale-de.min.js +7 -7
- data/templates/jqgrid/i18n/jqgrid/locale-el.min.js +7 -13
- data/templates/jqgrid/i18n/jqgrid/locale-es.min.js +7 -7
- data/templates/jqgrid/i18n/jqgrid/locale-fa.min.js +6 -12
- data/templates/jqgrid/i18n/jqgrid/locale-fr.min.js +7 -7
- data/templates/jqgrid/i18n/jqgrid/locale-gl.min.js +7 -7
- data/templates/jqgrid/i18n/jqgrid/locale-he.min.js +6 -13
- data/templates/jqgrid/i18n/jqgrid/locale-hu.min.js +6 -8
- data/templates/jqgrid/i18n/jqgrid/locale-is.min.js +6 -7
- data/templates/jqgrid/i18n/jqgrid/locale-it.min.js +4 -4
- data/templates/jqgrid/i18n/jqgrid/locale-ja.min.js +5 -10
- data/templates/jqgrid/i18n/jqgrid/locale-no.min.js +6 -6
- data/templates/jqgrid/i18n/jqgrid/locale-pl.min.js +6 -7
- data/templates/jqgrid/i18n/jqgrid/locale-pt-br.min.js +6 -7
- data/templates/jqgrid/i18n/jqgrid/locale-pt.min.js +4 -5
- data/templates/jqgrid/i18n/jqgrid/locale-ro.min.js +7 -8
- data/templates/jqgrid/i18n/jqgrid/locale-ru.min.js +7 -16
- data/templates/jqgrid/i18n/jqgrid/locale-sk.min.js +6 -8
- data/templates/jqgrid/i18n/jqgrid/locale-sv.min.js +6 -7
- data/templates/jqgrid/i18n/jqgrid/locale-tr.min.js +6 -7
- data/templates/jqgrid/i18n/jqgrid/locale-ua.min.js +7 -16
- data/templates/jqgrid/jquery.jqGrid.js +11567 -11565
- data/templates/jqgrid/jquery.jqGrid.min.js +472 -472
- data/templates/jqical/jquery.jqical.js +5 -9
- data/templates/jqical/jquery.jqical.min.js +44 -44
- data/templates/jqical/jquery.ui/jqical.scss +1 -1
- data/templates/jqtouch/config/initializers/jqtouch.rb +5 -4
- data/templates/jqtouch/jqtouch/apple/activeButton.png +0 -0
- data/templates/jqtouch/jqtouch/default/backButton.png +0 -0
- data/templates/jqtouch/jqtouch/default/backButtonActive.png +0 -0
- data/templates/jqtouch/jqtouch/default/bigButton.png +0 -0
- data/templates/jqtouch/jqtouch/default/bigButtonActive.png +0 -0
- data/templates/jqtouch/jqtouch/default/button.png +0 -0
- data/templates/jqtouch/jqtouch/default/buttonActive.png +0 -0
- data/templates/jqtouch/jqtouch/default/chevron.png +0 -0
- data/templates/jqtouch/jqtouch/default/chevronActive.png +0 -0
- data/templates/jqtouch/jqtouch/default/chevronCircle.png +0 -0
- data/templates/jqtouch/jqtouch/default/chevronCircleActive.png +0 -0
- data/templates/jqtouch/jqtouch/default/loading.gif +0 -0
- data/templates/jqtouch/jqtouch/default/toggleSwitch.png +0 -0
- data/templates/jqtouch/jqtouch/default/toolbarBackground.png +0 -0
- data/templates/jqtouch/jqtouch/jqt/back_button_clicked.png +0 -0
- data/templates/jqtouch/jqtouch/jqt.apple.scss +24 -11
- data/templates/jqtouch/jqtouch/jqt.default.scss +537 -0
- data/templates/jqtouch/jqtouch/jqt.jqt.scss +20 -6
- data/templates/jqtouch/jqtouch/jqtouch.scss +173 -1
- data/templates/jqtouch/jqtouch/photo/btnBack.png +0 -0
- data/templates/jqtouch/jqtouch/photo/loading.gif +0 -0
- data/templates/jqtouch/jqtouch/photo/navNext.png +0 -0
- data/templates/jqtouch/jqtouch/photo/navPause.png +0 -0
- data/templates/jqtouch/jqtouch/photo/navPlay.png +0 -0
- data/templates/jqtouch/jqtouch/photo/navPrev.png +0 -0
- data/templates/jqtouch/jqtouch/photo/toolbar.png +0 -0
- data/templates/jqtouch/jquery.jqtouch.js +8219 -632
- data/templates/jqtouch/jquery.jqtouch.min.js +60 -1
- data/templates/jqtouch/manifest.rb +21 -0
- data/templates/jrails/config/initializers/jrails.rb +1 -0
- data/templates/jrails/haml.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-ar.min.js +2 -4
- data/templates/jrails/i18n/jquery.ui/datepicker-az.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-bg.min.js +2 -4
- data/templates/jrails/i18n/jquery.ui/datepicker-bs.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-cs.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-da.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-de.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-el.min.js +2 -4
- data/templates/jrails/i18n/jquery.ui/datepicker-eo.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-et.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-fa.min.js +2 -3
- data/templates/jrails/i18n/jquery.ui/datepicker-fo.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-fr-CH.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-fr.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-he.min.js +2 -3
- data/templates/jrails/i18n/jquery.ui/datepicker-hr.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-hu.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-hy.min.js +2 -4
- data/templates/jrails/i18n/jquery.ui/datepicker-ja.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-ko.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-kz.min.js +2 -4
- data/templates/jrails/i18n/jquery.ui/datepicker-lt.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-lv.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-nl.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-no.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-pl.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-ro.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-ru.min.js +2 -4
- data/templates/jrails/i18n/jquery.ui/datepicker-sk.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-sq.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-sr-SR.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-sr.min.js +2 -4
- data/templates/jrails/i18n/jquery.ui/datepicker-sv.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-ta.min.js +2 -4
- data/templates/jrails/i18n/jquery.ui/datepicker-th.min.js +2 -4
- data/templates/jrails/i18n/jquery.ui/datepicker-tr.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-uk.min.js +2 -4
- data/templates/jrails/i18n/jquery.ui/datepicker-vi.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-zh-CN.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-zh-HK.min.js +2 -2
- data/templates/jrails/i18n/jquery.ui/datepicker-zh-TW.min.js +2 -2
- data/templates/jrails/jquery-1.4.2.min.js +156 -156
- data/templates/jrails/jquery-ui-1.8.5.js +23753 -23341
- data/templates/jrails/jquery-ui-1.8.5.min.js +823 -808
- data/templates/jrails/jquery.contextMenu.min.js +1 -1
- data/templates/jrails/jquery.sparkline.js +1050 -0
- data/templates/jrails/jquery.sparkline.min.js +31 -0
- data/templates/jrails/jquery.ui/_theme.scss +1699 -1634
- data/templates/jrails/manifest.rb +13 -11
- data/templates/jstree/jquery.jstree.min.js +10 -10
- data/templates/ribbon/jquery.ribbon.min.js +6 -6
- metadata +27 -4
data/lib/compiler.jar
CHANGED
|
Binary file
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
module FlashMessages
|
|
2
|
-
module ControllerMethods
|
|
3
|
-
TYPES = [:success, :notice, :warning, :error]
|
|
4
|
-
|
|
5
|
-
TYPES.each do |type|
|
|
6
|
-
define_method(type) do |msg|
|
|
7
|
-
flash[type] = msg
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
define_method("#{type}_now") do |msg|
|
|
11
|
-
flash.now[type] = msg
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
module Display
|
|
17
|
-
# def flash_messages
|
|
18
|
-
# returning html = String.new do
|
|
19
|
-
# flash.each do |css_class, message|
|
|
20
|
-
# html << content_tag(:div, content_tag(:div, nil, :class => :icon) + message, :class => css_class)
|
|
21
|
-
# end
|
|
22
|
-
# end
|
|
23
|
-
# end
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def message_for_item(message, item = nil)
|
|
38
|
-
if item.is_a?(Array)
|
|
39
|
-
content_tag(:div, nil, :class => :icon) + message % link_to(*item)
|
|
40
|
-
else
|
|
41
|
-
content_tag(:div, nil, :class => :icon) + message % item
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
1
|
+
module FlashMessages
|
|
2
|
+
module ControllerMethods
|
|
3
|
+
TYPES = [:success, :notice, :warning, :error]
|
|
4
|
+
|
|
5
|
+
TYPES.each do |type|
|
|
6
|
+
define_method(type) do |msg|
|
|
7
|
+
flash[type] = msg
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
define_method("#{type}_now") do |msg|
|
|
11
|
+
flash.now[type] = msg
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
module Display
|
|
17
|
+
# def flash_messages
|
|
18
|
+
# returning html = String.new do
|
|
19
|
+
# flash.each do |css_class, message|
|
|
20
|
+
# html << content_tag(:div, content_tag(:div, nil, :class => :icon) + message, :class => css_class)
|
|
21
|
+
# end
|
|
22
|
+
# end
|
|
23
|
+
# end
|
|
24
|
+
|
|
25
|
+
FLASH_NOTICE_KEYS = [:error, :warning, :notice, :success]
|
|
26
|
+
|
|
27
|
+
def flash_messages
|
|
28
|
+
return unless messages = flash.keys.select{|k| FLASH_NOTICE_KEYS.include?(k)}
|
|
29
|
+
formatted_messages = messages.map do |type|
|
|
30
|
+
content_tag(:div, nil, :class => type.to_s + " ui-corner-all") do
|
|
31
|
+
message_for_item(flash[type], flash["#{type}_item".to_sym])
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
formatted_messages.join
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def message_for_item(message, item = nil)
|
|
38
|
+
if item.is_a?(Array)
|
|
39
|
+
content_tag(:div, nil, :class => :icon) + message % link_to(*item)
|
|
40
|
+
else
|
|
41
|
+
content_tag(:div, nil, :class => :icon) + message % item
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/jquery/gridify/grid.rb
CHANGED
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
require 'jquery/gridify/assertions'
|
|
2
|
-
require 'jquery/gridify/grid_options'
|
|
3
|
-
require 'jquery/gridify/grid_view'
|
|
4
|
-
require 'jquery/gridify/grid_column'
|
|
5
|
-
require 'jquery/gridify/grid_finder'
|
|
6
|
-
|
|
7
|
-
# NOTE: for readablity/clarity, native jqGrid options should be string; Ruby ones as syms
|
|
8
|
-
|
|
9
|
-
module Gridify
|
|
10
|
-
class Grid
|
|
11
|
-
include Assertions
|
|
12
|
-
|
|
13
|
-
# todo: change this so klass is optional, decouple from active record
|
|
14
|
-
def initialize( klass, *args, &block )
|
|
15
|
-
#debugger
|
|
16
|
-
options = args.extract_options! # => args.last.is_a?(Hash) ? args.pop : {}
|
|
17
|
-
assert_exclusive_keys( options, :only, :except)
|
|
18
|
-
|
|
19
|
-
@resource = klass.to_s.tableize.pluralize
|
|
20
|
-
@name = args.first || :grid
|
|
21
|
-
|
|
22
|
-
# non-persistent options
|
|
23
|
-
# generate model unless explicitly say no
|
|
24
|
-
build_model = options.delete(:build_model) == false ? false : true
|
|
25
|
-
only = options.delete(:only)
|
|
26
|
-
except = options.delete(:except)
|
|
27
|
-
col_presets = options.delete(:colModel)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
#
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
# TODO: edit
|
|
52
|
-
# TODO:
|
|
53
|
-
# TODO:
|
|
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
|
-
# h
|
|
108
|
-
#
|
|
109
|
-
#
|
|
110
|
-
#
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
#
|
|
114
|
-
#
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
#
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
presets
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
next if
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
:
|
|
134
|
-
:
|
|
135
|
-
:
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
:
|
|
139
|
-
:
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
# create column with default args merged with options given for this column
|
|
143
|
-
GridColumn.new args.merge( presets[ar.name]||{} )
|
|
144
|
-
end.compact
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
end
|
|
1
|
+
require 'jquery/gridify/assertions'
|
|
2
|
+
require 'jquery/gridify/grid_options'
|
|
3
|
+
require 'jquery/gridify/grid_view'
|
|
4
|
+
require 'jquery/gridify/grid_column'
|
|
5
|
+
require 'jquery/gridify/grid_finder'
|
|
6
|
+
|
|
7
|
+
# NOTE: for readablity/clarity, native jqGrid options should be string; Ruby ones as syms
|
|
8
|
+
|
|
9
|
+
module Gridify
|
|
10
|
+
class Grid
|
|
11
|
+
include Assertions
|
|
12
|
+
|
|
13
|
+
# todo: change this so klass is optional, decouple from active record
|
|
14
|
+
def initialize( klass, *args, &block )
|
|
15
|
+
#debugger
|
|
16
|
+
options = args.extract_options! # => args.last.is_a?(Hash) ? args.pop : {}
|
|
17
|
+
assert_exclusive_keys( options, :only, :except)
|
|
18
|
+
|
|
19
|
+
@resource = klass.to_s.tableize.pluralize
|
|
20
|
+
@name = args.first || :grid
|
|
21
|
+
|
|
22
|
+
# non-persistent options
|
|
23
|
+
# generate model unless explicitly say no
|
|
24
|
+
build_model = options.delete(:build_model) == false ? false : true
|
|
25
|
+
only = options.delete(:only)
|
|
26
|
+
except = options.delete(:except)
|
|
27
|
+
col_presets = options.delete(:colModel)
|
|
28
|
+
col_include = options[:colInclude]
|
|
29
|
+
|
|
30
|
+
# assign options
|
|
31
|
+
update options
|
|
32
|
+
|
|
33
|
+
# build columns from ActiveRecord model (klass)
|
|
34
|
+
if klass.present? && build_model
|
|
35
|
+
@model = build_columns(klass, only, except, col_presets, col_include)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
instance_eval(&block) if block
|
|
39
|
+
#(note instance_eval cannot access things outside its scope; otherwise do this:
|
|
40
|
+
#yield self if block_given?
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def update( options )
|
|
44
|
+
options.each {|atr, val| send( "#{atr}=", val )}
|
|
45
|
+
# exception "invalid option..."
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def column( name, options={} )
|
|
49
|
+
name = name.to_s
|
|
50
|
+
klass = resource.classify.constantize
|
|
51
|
+
# TODO: set edit options based on ar_column
|
|
52
|
+
# TODO: edit
|
|
53
|
+
# TODO: handle file input types
|
|
54
|
+
# TODO: custom input types
|
|
55
|
+
if col = columns_hash[name]
|
|
56
|
+
# update an existing column
|
|
57
|
+
col.update options
|
|
58
|
+
|
|
59
|
+
elsif ar = klass.columns.detect {|c| c.name==name}
|
|
60
|
+
#debugger
|
|
61
|
+
# create column from database schema
|
|
62
|
+
edit = editable &&
|
|
63
|
+
# only edit accessible attributes
|
|
64
|
+
(klass.accessible_attributes.nil? || klass.accessible_attributes.include?(ar.name))
|
|
65
|
+
args = {
|
|
66
|
+
:ar_column => ar,
|
|
67
|
+
:name => ar.name,
|
|
68
|
+
:value_type => ar.type,
|
|
69
|
+
:searchable => searchable,
|
|
70
|
+
:sortable => sortable,
|
|
71
|
+
:editable => edit
|
|
72
|
+
}.merge(options)
|
|
73
|
+
colModel << GridColumn.new( args)
|
|
74
|
+
|
|
75
|
+
else
|
|
76
|
+
# create column from scratch
|
|
77
|
+
args = {
|
|
78
|
+
:name => name,
|
|
79
|
+
:value_type => :string,
|
|
80
|
+
:searchable => searchable,
|
|
81
|
+
:sortable => sortable,
|
|
82
|
+
:editable => edit
|
|
83
|
+
}.merge(options)
|
|
84
|
+
colModel << GridColumn.new( args)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def column_names
|
|
89
|
+
colModel.collect {|col| col.name.titleize }
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def column_model
|
|
93
|
+
colModel.collect {|col| col.properties }
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# normally we need to keep columns an ordered array, sometimes its convenient to have a hash
|
|
97
|
+
def columns_hash
|
|
98
|
+
colModel.inject({}) {|h, col| h[col.name] = col; h }
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
protected
|
|
102
|
+
|
|
103
|
+
# # isnt there something in rails to do this already?
|
|
104
|
+
# def parse_options( keys, options )
|
|
105
|
+
# ops = keys.inject({}) do |h, k|
|
|
106
|
+
# val = options.delete(k)
|
|
107
|
+
# h[k] = val unless val.nil?
|
|
108
|
+
# h
|
|
109
|
+
# end
|
|
110
|
+
# ops || {}
|
|
111
|
+
# end
|
|
112
|
+
|
|
113
|
+
# generate list of columns based on AR model
|
|
114
|
+
# option: :only or :except
|
|
115
|
+
# :col_options hash of hash of preset values for columns (eg from cookie) { :title => {:width => 98}}
|
|
116
|
+
def build_columns( klass, only, except, presets, col_include )
|
|
117
|
+
#debugger
|
|
118
|
+
# stringify
|
|
119
|
+
only = Array(only).map {|s| s.to_s }
|
|
120
|
+
except = Array(except).map {|s| s.to_s }
|
|
121
|
+
presets ||= {}
|
|
122
|
+
presets.stringify_keys!
|
|
123
|
+
|
|
124
|
+
self.colModel = klass.columns.collect do |ar|
|
|
125
|
+
#debugger
|
|
126
|
+
next if only.present? && !only.include?(ar.name)
|
|
127
|
+
next if except.present? && except.include?(ar.name)
|
|
128
|
+
is_key = (ar.name=='id')
|
|
129
|
+
edit = editable && !is_key &&
|
|
130
|
+
# only edit accessible attributes
|
|
131
|
+
(klass.accessible_attributes.nil? || klass.accessible_attributes.include?(ar.name))
|
|
132
|
+
args = {
|
|
133
|
+
:ar_column => ar,
|
|
134
|
+
:name => ar.name,
|
|
135
|
+
:value_type => ar.type,
|
|
136
|
+
:key => is_key,
|
|
137
|
+
#:hidden => is_key,
|
|
138
|
+
:searchable => searchable,
|
|
139
|
+
:sortable => sortable,
|
|
140
|
+
:editable => edit
|
|
141
|
+
}
|
|
142
|
+
# create column with default args merged with options given for this column
|
|
143
|
+
GridColumn.new args.merge( presets[ar.name]||{} )
|
|
144
|
+
end.compact
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
@@ -1,134 +1,134 @@
|
|
|
1
|
-
module Gridify
|
|
2
|
-
class GridColumn
|
|
3
|
-
|
|
4
|
-
attr_accessor :name, # attribute name (required)
|
|
5
|
-
:label,
|
|
6
|
-
:ar_column, # active_record column
|
|
7
|
-
:value_type, # active_record data type :string, :text, :integer, :float, :boolean, + :currency
|
|
8
|
-
:key, # true if this is the key (only :id)
|
|
9
|
-
|
|
10
|
-
# column formatting
|
|
11
|
-
:width, # initial width (150)
|
|
12
|
-
:fixed_width, # true = not resized when recalc fit to width
|
|
13
|
-
:formatter, # see jqGrid doc (based on value_type)
|
|
14
|
-
:format_options, # hash, see jqGrid doc (based on value_type)
|
|
15
|
-
:align, # 'left', 'right', 'center' (left for strings, right for numerics)
|
|
16
|
-
#:classes, # optional classes to add to column
|
|
17
|
-
|
|
18
|
-
# column actions
|
|
19
|
-
:resizable, # t/f (true)
|
|
20
|
-
:sortable, # t/f (true) or jqGrid sorttype: :integer, :float, :currency, :date, :text (true)
|
|
21
|
-
:searchable, # true/false (true) or text or select
|
|
22
|
-
#:search_options,
|
|
23
|
-
:editable, # true/false (false),
|
|
24
|
-
:edit_type, # text, textarea, select, checkbox, password, button, image and file (based on value_type)
|
|
25
|
-
:edit_options, # html input field options, depends on editable type (eg {"size" => 10, "maxlength" => 15}) see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules
|
|
26
|
-
:validations, # jqGrid editrules (TODO derive from AR model validations) see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules
|
|
27
|
-
# "required" "integer" "email" "url" etc
|
|
28
|
-
:form_options, # jqGrid formoptions for formatting input forms
|
|
29
|
-
# select types
|
|
30
|
-
#:select_url, # url to dynamically get select options
|
|
31
|
-
|
|
32
|
-
# visiblity
|
|
33
|
-
#:always_hidden, # (false)
|
|
34
|
-
:
|
|
35
|
-
:summary_type,
|
|
36
|
-
:summary_tpl,
|
|
37
|
-
:hidden # initial hide state (false)
|
|
38
|
-
|
|
39
|
-
def initialize(options)
|
|
40
|
-
update options
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def update(options)
|
|
44
|
-
options.each {|atr, val| send( "#{atr}=", val )}
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def to_json
|
|
48
|
-
properties.to_json #_with_js
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def properties
|
|
52
|
-
jqgrid_properties
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def resizable
|
|
56
|
-
if @resizable==false
|
|
57
|
-
false
|
|
58
|
-
else
|
|
59
|
-
# true or nil
|
|
60
|
-
true
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def fixed_width
|
|
65
|
-
if @fixed_width==false
|
|
66
|
-
false
|
|
67
|
-
elsif @fixed_width.nil?
|
|
68
|
-
!resizable
|
|
69
|
-
else
|
|
70
|
-
@fixed_width
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# ----------------
|
|
75
|
-
private
|
|
76
|
-
|
|
77
|
-
def jqgrid_type
|
|
78
|
-
return sortable unless sortable==true
|
|
79
|
-
case value_type
|
|
80
|
-
when :string : 'text'
|
|
81
|
-
when :text : 'text'
|
|
82
|
-
when :integer : 'integer'
|
|
83
|
-
when :float : 'float'
|
|
84
|
-
when :boolean : 'boolean'
|
|
85
|
-
when :datetime : 'date'
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# note, we dont vals[:foo] = foo because dont want to bother generating key if its same as jqGrid default
|
|
90
|
-
def jqgrid_properties
|
|
91
|
-
vals = {
|
|
92
|
-
:name => name,
|
|
93
|
-
:index => name
|
|
94
|
-
}
|
|
95
|
-
#xmlmap not required when same as :name
|
|
96
|
-
# vals[:xmlmap] = name if data_type == :xml
|
|
97
|
-
# vals[:jsonmap] = name if data_type == :json
|
|
98
|
-
|
|
99
|
-
vals[:label] = label || name.titleize
|
|
100
|
-
vals[:resizable] = false if resizable==false
|
|
101
|
-
vals[:fixed] = fixed_width unless fixed_width==false
|
|
102
|
-
vals[:sortable] = false if sortable==false
|
|
103
|
-
vals[:
|
|
104
|
-
vals[:search] = false if searchable==false
|
|
105
|
-
vals[:editable] = true if editable
|
|
106
|
-
vals[:align] = align if align
|
|
107
|
-
#vals[:align] = 'right' if [:integer, :float, :currency].include?(value_type)
|
|
108
|
-
case value_type
|
|
109
|
-
when :datetime
|
|
110
|
-
vals[:formatter] = 'date'
|
|
111
|
-
vals[:formatoptions] = { :srcformat => 'UniversalSortableDateTime', :newformat => 'FullDateTime' }
|
|
112
|
-
end
|
|
113
|
-
vals[:hidden] = true if hidden
|
|
114
|
-
vals[:width] = width if width
|
|
115
|
-
vals[:formatter] = formatter if formatter
|
|
116
|
-
vals[:formatoptions] = format_options if format_options
|
|
117
|
-
vals[:edittype] = edit_type if editable && edit_type
|
|
118
|
-
vals[:formoptions] = form_options if editable && form_options
|
|
119
|
-
vals[:editoptions] = edit_options if editable && edit_options
|
|
120
|
-
vals[:editrules] = validations if editable && validations
|
|
121
|
-
|
|
122
|
-
vals[:
|
|
123
|
-
vals[:summaryType] = summary_type if summary_type
|
|
124
|
-
vals[:summaryTpl] = summary_tpl if summary_tpl
|
|
125
|
-
# and more...
|
|
126
|
-
|
|
127
|
-
vals
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
#<ActiveRecord::ConnectionAdapters::SQLiteColumn:0x2515a98 @sql_type="varchar(255)", @name="title", @precision=nil, @primary=false, @default=nil, @limit=255, @null=true, @type=:string, @scale=nil>
|
|
134
|
-
|
|
1
|
+
module Gridify
|
|
2
|
+
class GridColumn
|
|
3
|
+
|
|
4
|
+
attr_accessor :name, # attribute name (required)
|
|
5
|
+
:label,
|
|
6
|
+
:ar_column, # active_record column
|
|
7
|
+
:value_type, # active_record data type :string, :text, :integer, :float, :boolean, + :currency
|
|
8
|
+
:key, # true if this is the key (only :id)
|
|
9
|
+
|
|
10
|
+
# column formatting
|
|
11
|
+
:width, # initial width (150)
|
|
12
|
+
:fixed_width, # true = not resized when recalc fit to width
|
|
13
|
+
:formatter, # see jqGrid doc (based on value_type)
|
|
14
|
+
:format_options, # hash, see jqGrid doc (based on value_type)
|
|
15
|
+
:align, # 'left', 'right', 'center' (left for strings, right for numerics)
|
|
16
|
+
#:classes, # optional classes to add to column
|
|
17
|
+
|
|
18
|
+
# column actions
|
|
19
|
+
:resizable, # t/f (true)
|
|
20
|
+
:sortable, # t/f (true) or jqGrid sorttype: :integer, :float, :currency, :date, :text (true)
|
|
21
|
+
:searchable, # true/false (true) or text or select
|
|
22
|
+
#:search_options,
|
|
23
|
+
:editable, # true/false (false),
|
|
24
|
+
:edit_type, # text, textarea, select, checkbox, password, button, image and file (based on value_type)
|
|
25
|
+
:edit_options, # html input field options, depends on editable type (eg {"size" => 10, "maxlength" => 15}) see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules
|
|
26
|
+
:validations, # jqGrid editrules (TODO derive from AR model validations) see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules
|
|
27
|
+
# "required" "integer" "email" "url" etc
|
|
28
|
+
:form_options, # jqGrid formoptions for formatting input forms
|
|
29
|
+
# select types
|
|
30
|
+
#:select_url, # url to dynamically get select options
|
|
31
|
+
|
|
32
|
+
# visiblity
|
|
33
|
+
#:always_hidden, # (false)
|
|
34
|
+
:sort_type,
|
|
35
|
+
:summary_type,
|
|
36
|
+
:summary_tpl,
|
|
37
|
+
:hidden # initial hide state (false)
|
|
38
|
+
|
|
39
|
+
def initialize(options)
|
|
40
|
+
update options
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def update(options)
|
|
44
|
+
options.each {|atr, val| send( "#{atr}=", val )}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def to_json
|
|
48
|
+
properties.to_json #_with_js
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def properties
|
|
52
|
+
jqgrid_properties
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def resizable
|
|
56
|
+
if @resizable==false
|
|
57
|
+
false
|
|
58
|
+
else
|
|
59
|
+
# true or nil
|
|
60
|
+
true
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def fixed_width
|
|
65
|
+
if @fixed_width==false
|
|
66
|
+
false
|
|
67
|
+
elsif @fixed_width.nil?
|
|
68
|
+
!resizable
|
|
69
|
+
else
|
|
70
|
+
@fixed_width
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# ----------------
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
def jqgrid_type
|
|
78
|
+
return sortable unless sortable==true
|
|
79
|
+
case value_type
|
|
80
|
+
when :string : 'text'
|
|
81
|
+
when :text : 'text'
|
|
82
|
+
when :integer : 'integer'
|
|
83
|
+
when :float : 'float'
|
|
84
|
+
when :boolean : 'boolean'
|
|
85
|
+
when :datetime : 'date'
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# note, we dont vals[:foo] = foo because dont want to bother generating key if its same as jqGrid default
|
|
90
|
+
def jqgrid_properties
|
|
91
|
+
vals = {
|
|
92
|
+
:name => name,
|
|
93
|
+
:index => name
|
|
94
|
+
}
|
|
95
|
+
#xmlmap not required when same as :name
|
|
96
|
+
# vals[:xmlmap] = name if data_type == :xml
|
|
97
|
+
# vals[:jsonmap] = name if data_type == :json
|
|
98
|
+
|
|
99
|
+
vals[:label] = label || name.titleize
|
|
100
|
+
vals[:resizable] = false if resizable==false
|
|
101
|
+
vals[:fixed] = fixed_width unless fixed_width==false
|
|
102
|
+
vals[:sortable] = false if sortable==false
|
|
103
|
+
vals[:sort_type] = jqgrid_type if sortable
|
|
104
|
+
vals[:search] = false if searchable==false
|
|
105
|
+
vals[:editable] = true if editable
|
|
106
|
+
vals[:align] = align if align
|
|
107
|
+
#vals[:align] = 'right' if [:integer, :float, :currency].include?(value_type)
|
|
108
|
+
case value_type
|
|
109
|
+
when :datetime
|
|
110
|
+
vals[:formatter] = 'date'
|
|
111
|
+
vals[:formatoptions] = { :srcformat => 'UniversalSortableDateTime', :newformat => 'FullDateTime' }
|
|
112
|
+
end
|
|
113
|
+
vals[:hidden] = true if hidden
|
|
114
|
+
vals[:width] = width if width
|
|
115
|
+
vals[:formatter] = formatter if formatter
|
|
116
|
+
vals[:formatoptions] = format_options if format_options
|
|
117
|
+
vals[:edittype] = edit_type if editable && edit_type
|
|
118
|
+
vals[:formoptions] = form_options if editable && form_options
|
|
119
|
+
vals[:editoptions] = edit_options if editable && edit_options
|
|
120
|
+
vals[:editrules] = validations if editable && validations
|
|
121
|
+
|
|
122
|
+
vals[:sort_type] = sort_type if sort_type
|
|
123
|
+
vals[:summaryType] = summary_type if summary_type
|
|
124
|
+
vals[:summaryTpl] = summary_tpl if summary_tpl
|
|
125
|
+
# and more...
|
|
126
|
+
|
|
127
|
+
vals
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
#<ActiveRecord::ConnectionAdapters::SQLiteColumn:0x2515a98 @sql_type="varchar(255)", @name="title", @precision=nil, @primary=false, @default=nil, @limit=255, @null=true, @type=:string, @scale=nil>
|
|
134
|
+
|