jquids 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/MIT-LICENSE +20 -0
- data/README.md +213 -0
- data/Rakefile +44 -0
- data/init.rb +1 -0
- data/jquids.gemspec +17 -0
- data/lib/jquids.rb +9 -0
- data/lib/jquids/constants/formats.rb +74 -0
- data/lib/jquids/constants/jq_versions.rb +3 -0
- data/lib/jquids/constants/styles.rb +29 -0
- data/lib/jquids/constants/timepicker_tags.rb +3 -0
- data/lib/jquids/constants/ui_versions.rb +3 -0
- data/lib/jquids/constants/version.rb +3 -0
- data/lib/jquids/errors/not_a_known_format.rb +8 -0
- data/lib/jquids/errors/not_a_known_style.rb +2 -0
- data/lib/jquids/form_helpers.rb +70 -0
- data/lib/jquids/includes_helper.rb +146 -0
- data/lib/jquids/jquids.rb +126 -0
- data/spec/jquids/form_helpers_spec.rb +343 -0
- data/spec/jquids/includes_helper_spec.rb +649 -0
- data/spec/jquids/jquids_spec.rb +441 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +23 -0
- metadata +90 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
module Jquids
|
2
|
+
module FormHelpers
|
3
|
+
|
4
|
+
def jquids_tag(name, value=nil, options = {})
|
5
|
+
Jquids.jquids_process_options(options)
|
6
|
+
|
7
|
+
jsonify_opts options
|
8
|
+
|
9
|
+
value = Jquids.format_time(value)
|
10
|
+
|
11
|
+
options[:class] ? options[:class] += " #{jquids_class(options)}" : options[:class] = jquids_class(options)
|
12
|
+
|
13
|
+
text_field_tag(name, value, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def jquids(model, method, options ={})
|
17
|
+
obj = options[:object] || instance_variable_get("@#{model}")
|
18
|
+
Jquids.jquids_process_options(options)
|
19
|
+
|
20
|
+
jsonify_opts options
|
21
|
+
|
22
|
+
options[:value] ||=
|
23
|
+
begin
|
24
|
+
obj.send(method).strftime(Jquids.date_format_string(false))
|
25
|
+
rescue
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
|
29
|
+
options[:class] ? options[:class] += " #{jquids_class(options)}" : options[:class] = jquids_class(options)
|
30
|
+
|
31
|
+
text_field(model, method, options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def jsonify_opts(options)
|
35
|
+
unless options[:datepicker_options].nil? and options[:timepicker_options].nil?
|
36
|
+
options[:datepicker_options] ||= {}
|
37
|
+
options[:datepicker_options] = options[:datepicker_options].merge(options.delete(:timepicker_options)) unless options[:timepicker_options].nil?
|
38
|
+
options["data-jquipicker"] =
|
39
|
+
if options[:datepicker_options].respond_to?(:to_json)
|
40
|
+
options.delete(:datepicker_options).to_json
|
41
|
+
else
|
42
|
+
begin
|
43
|
+
JSON.unparse(options.delete(:datepicker_options))
|
44
|
+
rescue
|
45
|
+
""
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def jquids_class(options)
|
52
|
+
result = "jquids_"
|
53
|
+
result << "d" unless options.delete(:calendar) == false
|
54
|
+
result << "t" if options.delete(:time) == true
|
55
|
+
result << "p"
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Helper method for form builders
|
62
|
+
module ActionView
|
63
|
+
module Helpers
|
64
|
+
class FormBuilder
|
65
|
+
def jquids(method, options = {})
|
66
|
+
@template.jquids(@object_name, method, options.merge(:object => @object))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
module Jquids
|
2
|
+
module IncludesHelper
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + "/constants/styles.rb"
|
5
|
+
require File.dirname(__FILE__) + "/constants/jq_versions.rb"
|
6
|
+
require File.dirname(__FILE__) + "/constants/ui_versions.rb"
|
7
|
+
require File.dirname(__FILE__) + "/constants/timepicker_tags.rb"
|
8
|
+
|
9
|
+
def jq_ui_stylesheet(style = :base)
|
10
|
+
raise Jquids::NotAKnownStyle, "Jquids: Unrecognized style specification: #{style}" unless Jquids::STYLES.has_key?(style)
|
11
|
+
"https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/#{Jquids::STYLES[style]}/jquery-ui.css"
|
12
|
+
end
|
13
|
+
|
14
|
+
def jq_ui_javascripts(jq, ui, tp)
|
15
|
+
includes = []
|
16
|
+
unless jq == :none or jq == nil or jq == false
|
17
|
+
jq = Jquids::JQVersions.member?(jq) ? jq : Jquids::JQVersions.last
|
18
|
+
includes << "https://ajax.googleapis.com/ajax/libs/jquery/#{jq}/jquery.min.js"
|
19
|
+
end
|
20
|
+
unless ui == :none or ui == nil or ui == false
|
21
|
+
ui = Jquids::UIVersions.member?(ui) ? ui : Jquids::UIVersions.last
|
22
|
+
includes << "https://ajax.googleapis.com/ajax/libs/jqueryui/#{ui}/jquery-ui.min.js"
|
23
|
+
end
|
24
|
+
unless tp == :none or tp == nil or tp == false
|
25
|
+
tp = Jquids::TimepickerTags.member?(tp) ? tp : Jquids::TimepickerTags.last
|
26
|
+
includes << "https://raw.github.com/trentrichardson/jQuery-Timepicker-Addon/#{tp}/jquery-ui-timepicker-addon.js"
|
27
|
+
end
|
28
|
+
includes
|
29
|
+
end
|
30
|
+
|
31
|
+
# Includes the stylesheets and javescripts into what ever view this is
|
32
|
+
# called to.
|
33
|
+
#
|
34
|
+
# By adding a :datepicker_options hash the options hash, you can change the
|
35
|
+
# defaults styles that are intially applied to all datepicker instances.
|
36
|
+
# Those defaults can be overwritten by each instance of the datepicker.
|
37
|
+
#
|
38
|
+
# To not include the style sheet into the layout, just pass :style => :none
|
39
|
+
# (false or nil will also work)
|
40
|
+
def jquids_includes(options = {})
|
41
|
+
|
42
|
+
# Set the format for the datepickers
|
43
|
+
Jquids.format = options[:format] if options.has_key?(:format)
|
44
|
+
html_out = ""
|
45
|
+
|
46
|
+
if options.has_key?(:style)
|
47
|
+
html_out << stylesheet_link_tag(jq_ui_stylesheet(options[:style])) + "\n" unless options[:style] == nil or options[:style] == :none or options[:style] == false
|
48
|
+
else
|
49
|
+
html_out << stylesheet_link_tag(jq_ui_stylesheet) + "\n"
|
50
|
+
end
|
51
|
+
|
52
|
+
jq_vrs = options.has_key?(:jQuery) ? options[:jQuery] : Jquids::JQVersions.last
|
53
|
+
ui_vrs = options.has_key?(:jQueryUI) ? options[:jQueryUI] : Jquids::UIVersions.last
|
54
|
+
trtp_vrs = options.has_key?(:TRTimepicker) ? options[:TRTimepicker] : :none
|
55
|
+
|
56
|
+
# A little bit of css of the timepicker, and it is not added if the
|
57
|
+
# timepicker javascript file is not included
|
58
|
+
unless trtp_vrs == :none or trtp_vrs == false or trtp_vrs == nil
|
59
|
+
html_out << "<style type=\"text/css\">.ui-timepicker-div .ui-widget-header{margin-bottom:8px;}.ui-timepicker-div dl{text-align:left;}.ui-timepicker-div dl dt{height:25px;}.ui-timepicker-div dl dd{margin:-25px 0 10px 65px;}.ui-timepicker-div td{font-size:90%;}</style>\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
html_out << javascript_include_tag(jq_ui_javascripts(jq_vrs, ui_vrs, trtp_vrs)) + "\n"
|
63
|
+
|
64
|
+
options[:datepicker_options] ||= {}
|
65
|
+
|
66
|
+
# Some opiniated defaults (basically an attempt to make the jQuery
|
67
|
+
# datepicker similar to the calendar_date_select with out making
|
68
|
+
# modifications or having local dependencies)
|
69
|
+
options[:datepicker_options][:showOtherMonths] = true if options[:datepicker_options][:showOtherMonths].nil?
|
70
|
+
options[:datepicker_options][:selectOtherMonths] = true if options[:datepicker_options][:selectOtherMonths].nil?
|
71
|
+
options[:datepicker_options][:changeMonth] = true if options[:datepicker_options][:changeMonth].nil?
|
72
|
+
options[:datepicker_options][:changeYear] = true if options[:datepicker_options][:changeYear].nil?
|
73
|
+
options[:datepicker_options][:dateFormat] = Jquids.format[:js_date]
|
74
|
+
|
75
|
+
Jquids.jquids_process_options(options)
|
76
|
+
|
77
|
+
# Decides whether the 'to_json' method exists (part of rails 3) or if the
|
78
|
+
# gem needs to us the json gem
|
79
|
+
datepicker_options =
|
80
|
+
if options[:datepicker_options].respond_to?(:to_json)
|
81
|
+
options.delete(:datepicker_options).to_json
|
82
|
+
else
|
83
|
+
begin
|
84
|
+
JSON.unparse(options.delete(:datepicker_options))
|
85
|
+
rescue
|
86
|
+
""
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
html_out << '<script type="text/javascript">$.datepicker.setDefaults(' + datepicker_options + ');'
|
91
|
+
|
92
|
+
|
93
|
+
unless trtp_vrs == :none or trtp_vrs == false or trtp_vrs == nil
|
94
|
+
options[:timepicker_options] ||= {}
|
95
|
+
|
96
|
+
# Some opiniated defaults (basically an attempt to make the jQuery
|
97
|
+
# datepicker similar to the calendar_date_select with out making
|
98
|
+
# modifications or having local dependencies)
|
99
|
+
# Sets the time format based off of the current format
|
100
|
+
options[:timepicker_options][:ampm] = Jquids.format[:ampm]
|
101
|
+
options[:timepicker_options][:timeFormat] = Jquids.format[:tr_js_time]
|
102
|
+
|
103
|
+
timepicker_options =
|
104
|
+
if options[:timepicker_options].respond_to?(:to_json)
|
105
|
+
options.delete(:timepicker_options).to_json
|
106
|
+
else
|
107
|
+
begin
|
108
|
+
JSON.unparse(options.delete(:timepicker_options))
|
109
|
+
rescue
|
110
|
+
""
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
html_out << '$.timepicker.setDefaults(' + timepicker_options + ');'
|
115
|
+
end
|
116
|
+
|
117
|
+
# A minified version of this javascript.
|
118
|
+
# <script type="text/javascript">
|
119
|
+
# $(document).ready(function(){
|
120
|
+
# $(".jquids_dp").each(function(){
|
121
|
+
# var s = $(this).attr("data-jquipicker");
|
122
|
+
# $(this).attr("data-jquipicker") ? $(this).datepicker(JSON.parse(s)) : $(this).datepicker();
|
123
|
+
# });
|
124
|
+
# $(".jquids_tp").each(function(){
|
125
|
+
# var s = $(this).attr("data-jquipicker");
|
126
|
+
# $(this).attr("data-jquipicker") ? $(this).timepicker(JSON.parse(s)) : $(this).timepicker();
|
127
|
+
# });
|
128
|
+
# $(".jquids_dtp").each(function(){
|
129
|
+
# var s=$(this).attr("data-jquipicker");
|
130
|
+
# $(this).attr("data-jquipicker")?$(this).datetimepicker(JSON.parse(s)) : $(this).datetimepicker()
|
131
|
+
# })
|
132
|
+
# });
|
133
|
+
# </script>
|
134
|
+
#
|
135
|
+
# Used to parse out options for each datepicker instance
|
136
|
+
html_out << '$(document).ready(function(){$(".jquids_dp").each(function(){var s=$(this).attr("data-jquipicker");$(this).attr("data-jquipicker")?$(this).datepicker(JSON.parse(s)):$(this).datepicker()});$(".jquids_tp").each(function(){var s=$(this).attr("data-jquipicker");$(this).attr("data-jquipicker")?$(this).timepicker(JSON.parse(s)):$(this).timepicker()});$(".jquids_dtp").each(function(){var s=$(this).attr("data-jquipicker");$(this).attr("data-jquipicker")?$(this).datetimepicker(JSON.parse(s)):$(this).datetimepicker()})});</script>'
|
137
|
+
|
138
|
+
if html_out.respond_to?(:html_safe)
|
139
|
+
return html_out.html_safe
|
140
|
+
else
|
141
|
+
return html_out
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
module Jquids
|
2
|
+
|
3
|
+
extend ActionView::Helpers::AssetTagHelper
|
4
|
+
require File.dirname(__FILE__) + "/constants/formats.rb"
|
5
|
+
|
6
|
+
# Sets the format for the jquids class
|
7
|
+
# If a format doesn't exist, and error is through
|
8
|
+
# Else the format variable is set
|
9
|
+
def self.format=(key)
|
10
|
+
raise Jquids::NotAKnownFormat, "Jquids: Unrecognized format specification: #{key}" unless Jquids::FORMATS.has_key?(key)
|
11
|
+
@jquids_format = Jquids::FORMATS[key]
|
12
|
+
end
|
13
|
+
|
14
|
+
# Gets the format variable
|
15
|
+
# If a format is set, it grabs it
|
16
|
+
# Else it will set it to the default format (:natural)
|
17
|
+
def self.format
|
18
|
+
@jquids_format ||= Jquids::FORMATS[:natural]
|
19
|
+
end
|
20
|
+
|
21
|
+
# Gets a format string based off of the current format
|
22
|
+
# The format string will always return the date portion of the format
|
23
|
+
#
|
24
|
+
# If a true is passed for time, the time string will be tacked on to the string
|
25
|
+
# Else it will return just the date string
|
26
|
+
def self.date_format_string(time = false)
|
27
|
+
format[:date] + (time ? format[:time] : "")
|
28
|
+
end
|
29
|
+
|
30
|
+
# Formats a date or datetime/time object to the default format
|
31
|
+
# This method is assumed that you send it a Date, Datetime, or Time object
|
32
|
+
#
|
33
|
+
# If sent a Date, the format will NOT use the time in the format string
|
34
|
+
# Else, it WILL use the time in the format string
|
35
|
+
def self.format_date(date)
|
36
|
+
if date.is_a?(Date) && !date.is_a?(DateTime)
|
37
|
+
date.strftime(date_format_string(false))
|
38
|
+
else
|
39
|
+
date.strftime(date_format_string(true))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns the value that will go in the form builder's input field when the field is
|
44
|
+
# initialized.
|
45
|
+
# This will detect if it is a date or not, and format it if it is
|
46
|
+
#
|
47
|
+
# If the value sent to the method is a Date
|
48
|
+
# If the options hash has :time, format the result with the time included
|
49
|
+
# Else format the result without the time
|
50
|
+
# Else return the given value as the result (with no changes)
|
51
|
+
def self.format_time(value, options = {})
|
52
|
+
return value unless value.respond_to?("strftime")
|
53
|
+
if options[:time]
|
54
|
+
format_date(value)
|
55
|
+
else
|
56
|
+
format_date(value.is_a?(Date) ? value : value.to_date)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
# Processes old CalendarDateSelect options and converts them to the
|
62
|
+
# coresponding jQuery UI options values for the timepicker and datepicker.
|
63
|
+
#
|
64
|
+
# If no keys exist for :timepicker_options or :datepicker options, they are
|
65
|
+
# removed to avoid the client side processing.
|
66
|
+
def self.jquids_process_options(options = {})
|
67
|
+
options[:datepicker_options] ||= {}
|
68
|
+
options[:timepicker_options] ||= {}
|
69
|
+
|
70
|
+
if options.has_key?(:year_range)
|
71
|
+
if options[:year_range].respond_to?(:first)
|
72
|
+
options[:datepicker_options][:yearRange] = options[:year_range].first.respond_to?(:strftime) ?
|
73
|
+
"#{options[:year_range].first.strftime("%Y")}:#{options[:year_range].last.strftime("%Y")}" : "#{options[:year_range].first}:#{options[:year_range].last}"
|
74
|
+
else
|
75
|
+
options[:datepicker_options][:yearRange] = options[:year_range].respond_to?(:strftime) ?
|
76
|
+
"#{options[:year_range].strftime("%Y")}:#{options[:year_range].strftime("%Y")}" : "#{options[:year_range]}:#{options[:year_range]}"
|
77
|
+
end
|
78
|
+
options.delete(:year_range)
|
79
|
+
end
|
80
|
+
|
81
|
+
if options[:month_year] == "dropdowns"
|
82
|
+
options[:datepicker_options][:changeMonth] = true
|
83
|
+
options[:datepicker_options][:changeYear] = true
|
84
|
+
elsif options[:month_year] == "labels"
|
85
|
+
options[:datepicker_options][:changeMonth] = false
|
86
|
+
options[:datepicker_options][:changeYear] = false
|
87
|
+
end
|
88
|
+
options.delete(:month_year)
|
89
|
+
|
90
|
+
if options.has_key?(:minute_interval) and options[:minute_interval].is_a?(Numeric)
|
91
|
+
options[:timepicker_options][:stepMinute] = options[:minute_interval]
|
92
|
+
end
|
93
|
+
options.delete(:minute_interval)
|
94
|
+
|
95
|
+
if options.delete(:popup).to_s == 'force'
|
96
|
+
options[:readonly] = true
|
97
|
+
end
|
98
|
+
|
99
|
+
if default_time = options.delete(:default_time)
|
100
|
+
options[:datepicker_options][:defaultDate] =
|
101
|
+
if default_time.respond_to? :strftime
|
102
|
+
default_time.strftime(Jquids.date_format_string(false))
|
103
|
+
else
|
104
|
+
default_time
|
105
|
+
end
|
106
|
+
if default_time.respond_to?(:hour)
|
107
|
+
options[:timepicker_options][:hour] = default_time.hour
|
108
|
+
options[:timepicker_options][:minute] = default_time.min
|
109
|
+
options[:timepicker_options][:second] = default_time.sec
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
if options.has_key?(:image)
|
114
|
+
options[:datepicker_options][:showOn] ||= 'button'
|
115
|
+
options[:datepicker_options][:buttonImageOnly] = true
|
116
|
+
options[:datepicker_options][:buttonImage] = image_path(options[:image])
|
117
|
+
options.delete(:image)
|
118
|
+
end
|
119
|
+
|
120
|
+
# For slightly trimming unneeded html, and for less client side processing
|
121
|
+
options.delete(:datepicker_options) if options[:datepicker_options].keys.count <= 0
|
122
|
+
options.delete(:timepicker_options) if options[:timepicker_options].keys.count <= 0
|
123
|
+
options
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
@@ -0,0 +1,343 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Jquids::FormHelpers do
|
4
|
+
|
5
|
+
include ActionView::Helpers::FormHelper
|
6
|
+
include ActionView::Helpers::TagHelper
|
7
|
+
include ActionView::Helpers::FormTagHelper
|
8
|
+
include ActionView::Helpers::JavaScriptHelper
|
9
|
+
|
10
|
+
include Jquids::FormHelpers
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
Jquids.instance_variable_set :@jquids_format, nil
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "The jquids function" do
|
17
|
+
|
18
|
+
describe "with a model of 'task' with a 'deadline' field" do
|
19
|
+
|
20
|
+
before(:each) do
|
21
|
+
@task = OpenStruct.new
|
22
|
+
@task.deadline = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "with deadline unassigned" do
|
26
|
+
|
27
|
+
it "returns and input with a class of 'jquids_dp' for the 'deadline' field with no value" do
|
28
|
+
output = jquids(:task, :deadline)
|
29
|
+
output.should == text_field(:task, :deadline, :class => "jquids_dp")
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "with deadline assigned as a date" do
|
35
|
+
|
36
|
+
before(:each) do
|
37
|
+
@task.deadline = "01/02/2001".to_date
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns and input with a class of 'jquids_dp' for the 'deadline' field with a value formated to 'January 02, 2001'" do
|
41
|
+
output = jquids(:task, :deadline)
|
42
|
+
output.should == text_field(:task, :deadline, :class => "jquids_dp", :value => "January 02, 2001")
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "with a format of :finnish" do
|
46
|
+
|
47
|
+
it "returns and input with a class of 'jquids_dp' for the 'deadline' field with a value formated to '02.01.2001'" do
|
48
|
+
Jquids.format=(:finnish)
|
49
|
+
output = jquids(:task, :deadline)
|
50
|
+
output.should == text_field(:task, :deadline, :class => "jquids_dp", :value => "02.01.2001")
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "with datepicker_options of '{:autoSize => true}'" do
|
56
|
+
|
57
|
+
it "returns and input with a class of 'jquids_dp' for the 'deadline' field," +
|
58
|
+
" a value formated to 'January 02, 2001'," +
|
59
|
+
" and a data-jquipicker value of '{\"autoSize\":true}'" do
|
60
|
+
output = jquids(:task, :deadline, :datepicker_options => {:autoSize => true})
|
61
|
+
output.should == text_field(:task, :deadline, :class => "jquids_dp", :value => "January 02, 2001", "data-jquipicker" => '{"autoSize":true}' )
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
describe ":year_range set to [2000..2020]" do
|
67
|
+
|
68
|
+
it "returns and input with a class of 'jquids_dp' for the 'deadline' field," +
|
69
|
+
" a value formated to 'January 02, 2001'," +
|
70
|
+
" and a data-jquipicker value of '{\"yearRange\":\"2000:2020\"}'" do
|
71
|
+
output = jquids(:task, :deadline, :year_range => 2000..2020 )
|
72
|
+
output.should == text_field(:task, :deadline, :class => "jquids_dp", :value => "January 02, 2001", "data-jquipicker" => '{"yearRange":"2000:2020"}' )
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
describe ":time equaling true" do
|
78
|
+
it "returns and input with a class of 'jquids_dtp' for the 'deadline' field with a value formated to 'January 02, 2001'" do
|
79
|
+
output = jquids(:task, :deadline, :time => true)
|
80
|
+
output.should == text_field(:task, :deadline, :class => "jquids_dtp", :value => "January 02, 2001")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "with a differnt object passed in the options hash" do
|
85
|
+
|
86
|
+
before(:each) do
|
87
|
+
@task2 = OpenStruct.new
|
88
|
+
@task2.deadline = "01/03/2001".to_date
|
89
|
+
end
|
90
|
+
|
91
|
+
it "returns and input with a class of 'jquids_dp' for the 'deadline' field with a value formated to 'January 02, 2001'" do
|
92
|
+
output = jquids(:task, :deadline, :object => @task2)
|
93
|
+
output.should == text_field(:task, :deadline, :class => "jquids_dp", :value => "January 03, 2001")
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "with deadline assigned as a time" do
|
101
|
+
|
102
|
+
before(:each) do
|
103
|
+
@task.deadline = Time.parse("01/02/2001")
|
104
|
+
end
|
105
|
+
|
106
|
+
it "returns and input with a class of 'jquids_dp' for the 'deadline' field with a value formated to 'January 02, 2001'" do
|
107
|
+
output = jquids(:task, :deadline)
|
108
|
+
output.should == text_field(:task, :deadline, :class => "jquids_dp", :value => "January 02, 2001")
|
109
|
+
end
|
110
|
+
|
111
|
+
describe ":time equaling true" do
|
112
|
+
|
113
|
+
it "returns and input with a class of 'jquids_dtp' for the 'deadline' field with a value formated to 'January 02, 2001'" do
|
114
|
+
output = jquids(:task, :deadline, :time => true)
|
115
|
+
output.should == text_field(:task, :deadline, :class => "jquids_dtp", :value => "January 02, 2001")
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
describe ":time equaling true and :timepicker_options => {:minuteGrid => 10}" do
|
121
|
+
|
122
|
+
it "returns an input for the 'deadline' field with a class of 'jquids_dtp'," +
|
123
|
+
" a value formated to 'January 02, 2001'," +
|
124
|
+
" and a data-jquipicker with a value of '{\"minuteGrid\"10}'" do
|
125
|
+
output = jquids(:task, :deadline, :time => true, :timepicker_options => {:minuteGrid => 10})
|
126
|
+
output.should == text_field(:task, :deadline, :class => "jquids_dtp", :value => "January 02, 2001", "data-jquipicker" => '{"minuteGrid":10}')
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "with a format of :finnish" do
|
132
|
+
|
133
|
+
it "returns an input for the 'deadline' field with a class of 'jquids_dp' and a value formated to '02.01.2001'" do
|
134
|
+
Jquids.format=(:finnish)
|
135
|
+
output = jquids(:task, :deadline)
|
136
|
+
output.should == text_field(:task, :deadline, :class => "jquids_dp", :value => "02.01.2001")
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
describe "with datepicker_options of '{:autoSize => true}'" do
|
142
|
+
|
143
|
+
it "returns and input with a class of 'jquids_dp' for the 'deadline' field," +
|
144
|
+
" a value formated to 'January 02, 2001'," +
|
145
|
+
" and a data-jquipicker value of '{\"autoSize\":true}'" do
|
146
|
+
output = jquids(:task, :deadline, :datepicker_options => {:autoSize => true})
|
147
|
+
output.should == text_field(:task, :deadline, :class => "jquids_dp", :value => "January 02, 2001", "data-jquipicker" => '{"autoSize":true}' )
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
describe ":year_range set to [2000..2020]" do
|
153
|
+
|
154
|
+
it "returns and input with a class of 'jquids_dp' for the 'deadline' field," +
|
155
|
+
" a value formated to 'January 02, 2001'," +
|
156
|
+
" and a data-jquipicker value of '{\"yearRange\":\"2000:2020\"}'" do
|
157
|
+
output = jquids(:task, :deadline, :year_range => 2000..2020 )
|
158
|
+
output.should == text_field(:task, :deadline, :class => "jquids_dp", :value => "January 02, 2001", "data-jquipicker" => '{"yearRange":"2000:2020"}' )
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "with a differnt object passed in the options hash" do
|
164
|
+
|
165
|
+
before(:each) do
|
166
|
+
@task2 = OpenStruct.new
|
167
|
+
@task2.deadline = "01/03/2001".to_date
|
168
|
+
end
|
169
|
+
|
170
|
+
it "returns and input with a class of 'jquids_dp' for the 'deadline' field with a value formated to 'January 02, 2001'" do
|
171
|
+
output = jquids(:task, :deadline, :object => @task2)
|
172
|
+
output.should == text_field(:task, :deadline, :class => "jquids_dp", :value => "January 03, 2001")
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "The jquids_tag function" do
|
184
|
+
|
185
|
+
describe "with only a name of 'date'" do
|
186
|
+
|
187
|
+
it "should return an input with a class of 'jquids_dp' and a name of 'date'" do
|
188
|
+
jquids_tag("date").should == text_field_tag("date", nil, :class => "jquids_dp")
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
describe "with a name of 'date' and :time = true" do
|
194
|
+
|
195
|
+
it "returns a input with a class of 'jquids_dtp' and a name of 'date'" do
|
196
|
+
jquids_tag("date", nil, :time => true).should == text_field_tag("date", nil, :class => "jquids_dtp")
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "with a name of 'date' and :time = true" do
|
202
|
+
|
203
|
+
it "returns a input with a class of 'jquids_dtp' and a name of 'date'" do
|
204
|
+
jquids_tag("date", nil, :time => true, :timepicker_options => {:minuteGrid => 10}).should == text_field_tag("date", nil, :class => "jquids_dtp", "data-jquipicker" => '{"minuteGrid":10}')
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "with a name of 'date' and a value of '01/01/2001'" do
|
210
|
+
|
211
|
+
it "returns an input with a class of 'jquids_dp', a name of 'date', and a value of 'January 01, 2001'" do
|
212
|
+
jquids_tag("date", "01/01/2001".to_date).should == text_field_tag("date", "January 01, 2001", :class => "jquids_dp")
|
213
|
+
end
|
214
|
+
|
215
|
+
describe "with a format of :finnish" do
|
216
|
+
|
217
|
+
it "returns a inputs with a class of 'jquids_dp', a name of 'date', and a value of '01.01.2001'" do
|
218
|
+
Jquids.format=(:finnish)
|
219
|
+
jquids_tag("date", "01/01/2001".to_date).should == text_field_tag("date", "01.01.2001", :class => "jquids_dp")
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
225
|
+
|
226
|
+
describe "with a name of 'date' and a class of 'date_input'" do
|
227
|
+
|
228
|
+
it "returns an input with a class of 'date_input jquids_dp' and a name of 'date'" do
|
229
|
+
jquids_tag("date", nil, :class => "date_input").should == text_field_tag("date", nil, :class => "date_input jquids_dp")
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
describe "with a name of 'date' and datepicker_options of '{:autoSize => true}'" do
|
235
|
+
|
236
|
+
it "returns an input with a name of 'date' and a data-jquipicker value of '{\"autoSize\":true}'" do
|
237
|
+
jquids_tag("date", nil, :datepicker_options => {:autoSize => true}).should == text_field_tag("date", nil, "data-jquipicker" => '{"autoSize":true}', :class => "jquids_dp")
|
238
|
+
end
|
239
|
+
|
240
|
+
end
|
241
|
+
|
242
|
+
describe "with a name of 'date' and :year_range of 2000..2020" do
|
243
|
+
|
244
|
+
it "returns an input with a name of 'date' and a data-jquipicker value of '{\"yearRange\":\"2000:2020\"}'" do
|
245
|
+
jquids_tag("date", nil, :year_range => 2000..2020).should == text_field_tag("date", nil, "data-jquipicker" => '{"yearRange":"2000:2020"}', :class => "jquids_dp")
|
246
|
+
end
|
247
|
+
|
248
|
+
end
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
describe "The jsonify_opts function" do
|
253
|
+
|
254
|
+
describe "without :datepicker_options or :timepicker_options" do
|
255
|
+
|
256
|
+
it "doesn't change the options hash" do
|
257
|
+
options = {}
|
258
|
+
jsonify_opts(options)
|
259
|
+
options.should == {}
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
|
264
|
+
describe "with some :datepicker_options" do
|
265
|
+
|
266
|
+
it "will add 'data-jquipicker' key and remove the :datepicker_options key" do
|
267
|
+
options = {:datepicker_options => {:autoSize => true}}
|
268
|
+
jsonify_opts(options)
|
269
|
+
options.should == {"data-jquipicker" => '{"autoSize":true}'}
|
270
|
+
end
|
271
|
+
|
272
|
+
end
|
273
|
+
|
274
|
+
describe "with some :timepicker_options and some :datepicker_options" do
|
275
|
+
|
276
|
+
it "will add 'data-jquipicker' key and remove the :timepicker_options and :datepicker_options keys" do
|
277
|
+
options = {:datepicker_options => {:autoSize => true}, :timepicker_options => {:ampm => true}}
|
278
|
+
jsonify_opts(options)
|
279
|
+
options.should == {"data-jquipicker" => '{"autoSize":true,"ampm":true}'}
|
280
|
+
end
|
281
|
+
|
282
|
+
end
|
283
|
+
|
284
|
+
describe "with some :timepicker_options" do
|
285
|
+
|
286
|
+
it "will add 'data-jquipicker' key and remove the :datepicker_options key" do
|
287
|
+
options = {:timepicker_options => {:ampm => true}}
|
288
|
+
jsonify_opts(options)
|
289
|
+
options.should == {"data-jquipicker" => '{"ampm":true}'}
|
290
|
+
end
|
291
|
+
|
292
|
+
end
|
293
|
+
|
294
|
+
end
|
295
|
+
|
296
|
+
describe "The js_ui_ds_class function" do
|
297
|
+
|
298
|
+
describe "with blank options" do
|
299
|
+
|
300
|
+
it "will return 'jquids_dp'" do
|
301
|
+
options = {}
|
302
|
+
jquids_class(options).should == "jquids_dp"
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
describe "with options of :time => true" do
|
308
|
+
|
309
|
+
before(:each) do
|
310
|
+
@options = {:time => true}
|
311
|
+
@result = jquids_class(@options)
|
312
|
+
end
|
313
|
+
|
314
|
+
it "will return 'jquids_dtp'" do
|
315
|
+
@result.should == "jquids_dtp"
|
316
|
+
end
|
317
|
+
|
318
|
+
it "will remove :time from options" do
|
319
|
+
@options.should == {}
|
320
|
+
end
|
321
|
+
|
322
|
+
end
|
323
|
+
|
324
|
+
describe "with options of :calendar => false, :time => true" do
|
325
|
+
|
326
|
+
before(:each) do
|
327
|
+
@options = {:calendar => false, :time => true}
|
328
|
+
@result = jquids_class(@options)
|
329
|
+
end
|
330
|
+
|
331
|
+
it "will return 'jquids_tp'" do
|
332
|
+
@result.should == "jquids_tp"
|
333
|
+
end
|
334
|
+
|
335
|
+
it "will remove :calendar and :time" do
|
336
|
+
@options.should == {}
|
337
|
+
end
|
338
|
+
|
339
|
+
end
|
340
|
+
|
341
|
+
end
|
342
|
+
|
343
|
+
end
|