jquery-ui-form 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jquery-ui-form (0.1.0)
4
+ jquery-ui-form (0.1.1)
5
5
  jquery-ui-form
6
6
 
7
7
  GEM
File without changes
data/README.textile ADDED
@@ -0,0 +1,103 @@
1
+ h1. jQuery-UI-formbuilder
2
+
3
+ jQuery-UI-formbuilder is a Ruby on Rails FormBuilder DSL powered by jQuery-UI.
4
+ A lot of inspiration comes from https://github.com/justinfrench/formtastic.
5
+
6
+ h2. Prerequisites
7
+ * HAML
8
+ * SASS
9
+ * jQuery theme recomended - http://jqueryui.com/themeroller/
10
+
11
+ h2. Input Types
12
+ * boolean - check box
13
+ ** checked_value => "1"
14
+ ** unchecked_value => "0"
15
+ * check_boxes - list of checkboxes
16
+ ** buttonset => true|false
17
+ ** collection => Array | relation
18
+ * date - text field with jQuery calendar
19
+ * email - email field
20
+ * file - file field
21
+ * hidden - hidden field
22
+ * number - number field
23
+ ** min => in
24
+ ** max => int
25
+ ** step => int
26
+ * password - password field
27
+ * phone - phone field
28
+ * radio - radio button
29
+ ** collection => Array | relation
30
+ * range - range field
31
+ ** min => in
32
+ ** max => int
33
+ ** step => int
34
+ * search - search field
35
+ * select - select field
36
+ ** collection => Array | relation
37
+ * string - text field
38
+ * text - text area
39
+ * url - url field
40
+
41
+ h2. Common Options
42
+ * label => Input label
43
+ * as => input type
44
+ * required => true | false
45
+ * hint => "Text" (output as placeholder)
46
+ * collection => ["Value"] | [["ID","Value"]] | object_relation
47
+ ** label_method => Method to get label from collection
48
+ ** value_method => Method to get label from collection
49
+
50
+ h2. Sample
51
+ <pre>
52
+ = jquery_form_for :sample do |f|
53
+ =f.input :sample_id, :as => :hidden
54
+ =f.fieldset "Person" do
55
+ =f.row do
56
+ =f.input :full_name, :hint => "First name, Last name", :required => true
57
+ =f.input :funny, :as => :boolean, :hint => "Is this person funny?"
58
+ =f.input :date_of_birth, :as => :date, "data-calendar" => {:dateFormat => "dd.mm.yy"}
59
+ =f.row do
60
+ =f.input :email, :as => :email, :hint => "Can I send You an email?"
61
+ =f.input :phone, :as => :phone, :hint => "(xx)-xxx-xxx-xx"
62
+ =f.input :mobile, :as => :phone, :hint => "(xx)-xxx-xxx-xx"
63
+ =f.input :age, :as => :number, :min => 18, :max => 99, :step => 1, :hint => "What is your age"
64
+ =f.input :homepage, :as => :url, :hint => "Your website"
65
+ =f.row do
66
+ =f.input :photo, :as => :file, :hint => "Upload Your picture"
67
+ =f.input :pet, :as => :select, :collection => ["Cat","Dog","Hamster"]
68
+ =f.input :stars, :as => :range
69
+ =f.input :sex, :as => :radio, :collection => [["M", "Male"],["F","Female"]], :value => "M"
70
+ =f.input :skills_simple, :as => :check_boxes, :collection => ["Ruby","PHP", "Perl", "Java", ".NET", "OjectiveC"], :values => ["Ruby",".NET"]
71
+ =f.input :skills, :as => :check_boxes, :buttonset => true, :collection => ["Ruby","PHP", "Perl", "Java", ".NET", "OjectiveC"], :values => ["Ruby",".NET"]
72
+ =f.input :friends, :as => :check_boxes, :buttonset => true, :collection => [[1,"Carl"],[2,"Mary"], [3,"John"], [4,"James"], [5,"Anete"], [6,"Jane"]], :values => [5,2], :hint => "Who are Your friends?"
73
+ =f.fieldset "Misc" do
74
+ =f.input :search_history, :as => :search, :hint => "Search Your history"
75
+ =f.buttons do
76
+ =f.submit
77
+ =f.cancel :icon => "trash"
78
+
79
+ </pre>
80
+
81
+ h2. TODO
82
+
83
+ * Date field dateFormat from rails
84
+ * autocomplete tag
85
+ * Tabs
86
+ * Write documentation and samples
87
+ * input[range] to jQuery slider?
88
+ * confirmation to dialog
89
+
90
+ h2. Contributing to jquery-ui-formbuilder
91
+
92
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
93
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
94
+ * Fork the project
95
+ * Start a feature/bugfix branch
96
+ * Commit and push until you are happy with your contribution
97
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
98
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
99
+
100
+ h2. Copyright
101
+
102
+ Copyright (c) 2011 Aivars Akots, released under the MIT license.
103
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,24 +5,23 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jquery-ui-form}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aivars Akots"]
12
- s.date = %q{2011-04-19}
12
+ s.date = %q{2011-04-20}
13
13
  s.description = %q{longer description of your gem}
14
14
  s.email = %q{aivars.akots@gmail.com}
15
15
  s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.rdoc"
16
+ "README.textile"
18
17
  ]
19
18
  s.files = [
20
19
  ".document",
21
20
  ".rvmrc",
22
21
  "Gemfile",
23
22
  "Gemfile.lock",
24
- "LICENSE.txt",
25
- "README.rdoc",
23
+ "MIT.txt",
24
+ "README.textile",
26
25
  "Rakefile",
27
26
  "VERSION",
28
27
  "jquery-ui-form.gemspec",
@@ -11,7 +11,7 @@ $(function(){
11
11
  });
12
12
  $(".ui-radio-input fieldset.to-buttonset").buttonset();
13
13
  $(".ui-check_boxes-input fieldset.to-buttonset").buttonset();
14
- $("input[type='date'].ui-date-input" ).each(function(){
14
+ $("input[type='date'].ui-date-input, input[type='text'].ui-date-input" ).each(function(){
15
15
  var options = {};
16
16
  if($(this).attr('data-calendar') != "") {
17
17
  options = $.parseJSON($(this).attr('data-calendar'));
@@ -1,5 +1,5 @@
1
1
  JqueryUiForm::FormBuilder.use_i18n = false
2
2
  JqueryUiForm::FormBuilder.required_string = proc{"<abbr>*</abbr>"}
3
3
  JqueryUiForm::FormBuilder.html5_inputs = true
4
- JqueryUiForm::FormBuilder.placeholder_elements = %w(date email file number password phone search string text url)
4
+ JqueryUiForm::FormBuilder.placeholder_elements = %w(date email password phone search string text url)
5
5
  JqueryUiForm::FormBuilder.use_autofocus = true
@@ -77,14 +77,20 @@
77
77
  position: absolute
78
78
  top: 5px
79
79
  left: 129px
80
- font-size: 80%
81
- opacity: .45
82
- filter: Alpha(Opacity = 45)
80
+ font-size: 100%
81
+ opacity: .40
82
+ filter: Alpha(Opacity = 40)
83
83
  .ui-check_boxes-input .ui-input-hint, .ui-radio-input .ui-input-hint
84
84
  top: 27px
85
85
  left: 21px
86
+ .ui-check_boxes-input .ui-buttonset .ui-input-hint
87
+ position: relative
88
+ top: -4px
86
89
  .ui-boolean-input .ui-input-hint
87
90
  left: 139px
91
+ .ui-file-input .ui-input-hint
92
+ position: relative
93
+ left: 126px
88
94
  label
89
95
  width: 120px
90
96
  float: left
@@ -103,10 +103,7 @@ module JqueryUiForm
103
103
  when :text
104
104
  return :text
105
105
  end
106
-
107
- # Try look for hints in options hash. Quite common senario: Enum keys stored as string in the database.
108
106
  return :select if column.type == :string && options.key?(:collection)
109
- # Try 3: Assume the input name will be the same as the column type (e.g. string_input).
110
107
  return column.type
111
108
  else
112
109
  if @object
@@ -5,7 +5,7 @@ module JqueryUiForm
5
5
  def check_boxes_input(method, options = {})
6
6
  # radio_button(method, tag_value, options)
7
7
  legend, options = label_text(method, options)
8
- current_values = current_values_from_association(method)
8
+ current_values = options.delete(:values) || current_values_from_association(method)
9
9
  collection = options.delete(:collection) || collection_from_association(method)
10
10
  label_options = options.delete(:html_label) || {}
11
11
 
@@ -25,7 +25,7 @@ module JqueryUiForm
25
25
  collection.each do |row|
26
26
  label_text = label_from_association(row,label_method)
27
27
  value_text = value_from_association(row,value_method)
28
- checked = current_values.include?(value_text.to_s)
28
+ checked = current_values.include?(value_text)
29
29
  if buttonset
30
30
  template.concat(template.check_box_tag("#{@object_name}[#{method}][]", value_text, checked, options.merge(:id => name_to_id("#{@object_name}_#{method}_#{value_text}"))))
31
31
  template.concat(label(name_to_id("#{method}_#{value_text}"), label_text, label_options))
@@ -40,23 +40,34 @@ module JqueryUiForm
40
40
  end
41
41
 
42
42
  def label_from_association(row, label_method)
43
- return row[0] unless row.respond_to?(label_method)
44
- return row[0] if row.is_a?(Array)
45
- row.send(label_method)
43
+ return row[1] if row.is_a?(Array)
44
+ return row if row.is_a?(String)
45
+ if row.respond_to?(label_method)
46
+ row.send(label_method)
47
+ else
48
+ row
49
+ end
50
+
46
51
  end
47
52
 
48
53
  def value_from_association(row, value_method)
49
- return row[1] unless row.respond_to?(value_method)
50
- return row[1] if row.is_a?(Array)
51
- row.send(value_method)
54
+ return row[0] if row.is_a?(Array)
55
+ return row if row.is_a?(String)
56
+ if row.respond_to?(value_method)
57
+ row.send(value_method)
58
+ else
59
+ row
60
+ end
52
61
  end
53
62
 
54
63
  def current_values_from_association(method)
64
+ return [] unless @object || @object.respond_to?(method)
55
65
  return [] unless @object.send(method).is_a?(Array)
56
66
  @object.send(method).map{|row| row.id.to_s}
57
67
  end
58
68
 
59
69
  def collection_from_association(method)
70
+ return [] unless @object || @object.respond_to?(method)
60
71
  return [] unless @object.send(method).is_a?(Array)
61
72
  if target = @object.send(method).first
62
73
  target.class.all
@@ -15,13 +15,19 @@ module JqueryUiForm
15
15
  template.concat(inline_hint(options.delete(:hint)))
16
16
  template.concat(inline_error(method))
17
17
  collection.each do |row|
18
+ id, value = (row.is_a?(Array) ? row : [row, row])
19
+ if @object
20
+ checked = @object.send(method) == id
21
+ else
22
+ checked = options[:value] == id
23
+ end
18
24
  if buttonset
19
- template.concat(radio_button(method, row[1], options.merge(:checked => @object.send(method) == row[1])))
20
- template.concat(label(name_to_id("#{method}_#{row[1]}"), row[0], label_options))
25
+ template.concat(radio_button(method, id, options.merge(:checked => checked)))
26
+ template.concat(label(name_to_id("#{method}_#{id}"), value, label_options))
21
27
  else
22
28
  template.concat(column do
23
- template.concat(label(name_to_id("#{method}_#{row[1]}"), row[0], label_options))
24
- template.concat(radio_button(method, row[1], options.merge(:checked => @object.send(method) == row[1])))
29
+ template.concat(label(name_to_id("#{method}_#{id}"), value, label_options))
30
+ template.concat(radio_button(method, id, options.merge(:checked => checked)))
25
31
  end)
26
32
  end
27
33
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-ui-form
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aivars Akots
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-19 00:00:00 +03:00
18
+ date: 2011-04-20 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -145,15 +145,14 @@ executables: []
145
145
  extensions: []
146
146
 
147
147
  extra_rdoc_files:
148
- - LICENSE.txt
149
- - README.rdoc
148
+ - README.textile
150
149
  files:
151
150
  - .document
152
151
  - .rvmrc
153
152
  - Gemfile
154
153
  - Gemfile.lock
155
- - LICENSE.txt
156
- - README.rdoc
154
+ - MIT.txt
155
+ - README.textile
157
156
  - Rakefile
158
157
  - VERSION
159
158
  - jquery-ui-form.gemspec
data/README.rdoc DELETED
@@ -1,25 +0,0 @@
1
- = jquery-ui-formbuilder
2
-
3
- Description goes here.
4
- == TODO
5
- * autocomplete tag
6
- * Implenent tabs
7
- * Write documentation and samples
8
- * input[range] to jQuery slider?
9
- * confirmation to dialog
10
-
11
- == Contributing to jquery-ui-formbuilder
12
-
13
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
14
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
15
- * Fork the project
16
- * Start a feature/bugfix branch
17
- * Commit and push until you are happy with your contribution
18
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
19
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
20
-
21
- == Copyright
22
-
23
- Copyright (c) 2011 Aivars Akots. See LICENSE.txt for
24
- further details.
25
-