inline_forms 1.6.70 → 2.0

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.
Files changed (53) hide show
  1. data/.gitignore +42 -0
  2. data/bin/inline_forms +419 -40
  3. data/inline_forms.gemspec +1 -1
  4. data/lib/app/assets/images/add.png +0 -0
  5. data/lib/app/assets/images/close.png +0 -0
  6. data/lib/app/assets/images/tooltip-bubble-down-left.png +0 -0
  7. data/lib/app/assets/images/tooltip-bubble-down-right.png +0 -0
  8. data/lib/app/assets/images/tooltip-bubble-up-left.png +0 -0
  9. data/lib/app/assets/images/tooltip-bubble-up-right.png +0 -0
  10. data/lib/app/assets/images/trash.png +0 -0
  11. data/lib/app/assets/javascripts/ckeditor/config.js +40 -39
  12. data/lib/app/assets/javascripts/inline_forms.js +32 -12
  13. data/lib/app/assets/javascripts/inline_forms_application.js +1 -7
  14. data/lib/app/assets/javascripts/jquery.qtip.js +3395 -0
  15. data/lib/app/assets/stylesheets/inline_forms.css +399 -5
  16. data/lib/app/assets/stylesheets/inline_forms_application.css +3 -3
  17. data/lib/app/assets/stylesheets/jquery.qtip.css +567 -0
  18. data/lib/app/controllers/inline_forms_application_controller.rb +2 -1
  19. data/lib/app/controllers/inline_forms_controller.rb +2 -2
  20. data/lib/app/helpers/form_elements/check_list.rb +14 -7
  21. data/lib/app/helpers/form_elements/date.rb +8 -3
  22. data/lib/app/helpers/form_elements/dropdown.rb +1 -1
  23. data/lib/app/helpers/form_elements/dropdown_with_values.rb +1 -1
  24. data/lib/app/helpers/form_elements/plain_text_area.rb +1 -1
  25. data/lib/app/helpers/form_elements/radio_button.rb +6 -5
  26. data/lib/app/helpers/form_elements/slider_with_values.rb +1 -1
  27. data/lib/app/helpers/form_elements/text_area.rb +10 -12
  28. data/lib/app/helpers/form_elements/text_area_without_ckeditor.rb +1 -1
  29. data/lib/app/helpers/form_elements/text_field.rb +2 -2
  30. data/lib/app/helpers/inline_forms_helper.rb +37 -32
  31. data/lib/app/views/inline_forms/_close.html.erb +2 -12
  32. data/lib/app/views/inline_forms/_edit.html.erb +21 -54
  33. data/lib/app/views/inline_forms/_header.html.erb +1 -0
  34. data/lib/app/views/inline_forms/_list.html.erb +24 -28
  35. data/lib/app/views/inline_forms/_new.html.erb +50 -52
  36. data/lib/app/views/inline_forms/_show.html.erb +39 -83
  37. data/lib/app/views/layouts/devise.html.erb +14 -4
  38. data/lib/app/views/layouts/inline_forms.html.erb +23 -15
  39. data/lib/inline_forms/version.rb +1 -1
  40. metadata +41 -23
  41. checksums.yaml +0 -15
  42. data/bin/inline_forms_app_template.rb +0 -16
  43. data/bin/inline_forms_installer_core.rb +0 -423
  44. data/lib/app/helpers/form_elements/decimal_field.rb +0 -15
  45. data/lib/app/helpers/form_elements/dropdown_with_other.rb +0 -153
  46. data/lib/app/helpers/form_elements/info_list.rb +0 -22
  47. data/lib/app/helpers/form_elements/integer_field.rb +0 -15
  48. data/lib/app/helpers/form_elements/kansen_slider.rb +0 -89
  49. data/lib/app/helpers/form_elements/month_year_picker.rb +0 -33
  50. data/lib/app/helpers/form_elements/move.rb +0 -17
  51. data/lib/app/views/inline_forms/_flash.html.erb +0 -13
  52. data/lib/app/views/inline_forms/_new_nested.html.erb +0 -43
  53. data/lib/app/views/inline_forms/_tree.html.erb +0 -46
@@ -1,15 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- InlineForms::SPECIAL_COLUMN_TYPES[:decimal_field]=:string
3
-
4
- def decimal_field_show(object, attribute)
5
- link_to_inline_edit object, attribute, object[attribute].nil? ? "<i class='fi-plus'></i>".html_safe : object[attribute]
6
- end
7
-
8
- def decimal_field_edit(object, attribute)
9
- text_field_tag attribute, (object.send attribute.to_sym), :class => 'input_decimal_field' # for abide: , :required => true
10
- end
11
-
12
- def decimal_field_update(object, attribute)
13
- object.send :write_attribute, attribute.to_sym, params[attribute.to_sym]
14
- end
15
-
@@ -1,153 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- InlineForms::SPECIAL_COLUMN_TYPES[:dropdown_with_other]=:belongs_to
3
-
4
- # dropdown
5
- def dropdown_with_other_show(object, attribute)
6
- attribute = attribute.to_s
7
- foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.foreign_key.to_sym
8
- id = object[foreign_key]
9
- if id == 0
10
- attribute_value = object[attribute + '_other']
11
- attribute_value = "<i class='fi-plus'></i>".html_safe if attribute_value.nil? || attribute_value.empty?
12
- else
13
- attribute_value = object.send(attribute)._presentation rescue "<i class='fi-plus'></i>".html_safe
14
- end
15
- link_to_inline_edit object, attribute, attribute_value
16
- end
17
-
18
- def dropdown_with_other_edit(object, attribute)
19
- attribute = attribute.to_s
20
- foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.foreign_key.to_sym
21
- o = attribute.camelcase.constantize
22
- values = o.all
23
- values = o.accessible_by(current_ability) if cancan_enabled?
24
- values.each do |v|
25
- v.name = v._presentation
26
- end
27
- # values.sort_by! &:name
28
-
29
- collection = values.map {|v|[v.name, v.id]}
30
- collection << [object[attribute + '_other'], 0] unless object[attribute + '_other'].nil? || object[attribute + '_other'].empty?
31
- out = '<div class="ui-widget">'
32
- out << select('_' + object.class.to_s.underscore, foreign_key.to_sym, collection, {selected: object[foreign_key.to_sym]}, {id: '_' + object.class.to_s.underscore + '_' + object.id.to_s + '_' + foreign_key.to_s})
33
- out << '</div>
34
- <script>
35
- (function( $ ) {
36
- $.widget( "custom.combobox", {
37
- _create: function() {
38
- this.wrapper = $( "<span>" )
39
- .addClass( "custom-combobox" )
40
- .insertAfter( this.element );
41
-
42
- this.element.hide();
43
- this._createAutocomplete();
44
- this._createShowAllButton();
45
- },
46
-
47
- _createAutocomplete: function() {
48
- var selected = this.element.children( ":selected" ),
49
- value = selected.val() ? selected.text() : "";
50
-
51
- this.input = $( "<input name=\''
52
-
53
- out << '_' + object.class.to_s.underscore + '[' + attribute + '_other]'
54
-
55
- out << '\'>" )
56
- .appendTo( this.wrapper )
57
- .val( value )
58
- .attr( "title", "" )
59
- .addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" )
60
- .autocomplete({
61
- delay: 0,
62
- minLength: 0,
63
- source: $.proxy( this, "_source" )
64
- })
65
- .tooltip({
66
- tooltipClass: "ui-state-highlight"
67
- });
68
-
69
- this._on( this.input, {
70
- autocompleteselect: function( event, ui ) {
71
- ui.item.option.selected = true;
72
- this._trigger( "select", event, {
73
- item: ui.item.option
74
- });
75
- }
76
- });
77
- },
78
-
79
- _createShowAllButton: function() {
80
- var input = this.input,
81
- wasOpen = false;
82
-
83
- $( "<a>" )
84
- .attr( "tabIndex", -1 )
85
- .attr( "title", "Show All Items" )
86
- .tooltip()
87
- .appendTo( this.wrapper )
88
- .button({
89
- icons: {
90
- primary: "ui-icon-triangle-1-s"
91
- },
92
- text: false
93
- })
94
- .removeClass( "ui-corner-all" )
95
- .addClass( "custom-combobox-toggle ui-corner-right" )
96
- .mousedown(function() {
97
- wasOpen = input.autocomplete( "widget" ).is( ":visible" );
98
- })
99
- .click(function() {
100
- input.focus();
101
-
102
- // Close if already visible
103
- if ( wasOpen ) {
104
- return;
105
- }
106
-
107
- // Pass empty string as value to search for, displaying all results
108
- input.autocomplete( "search", "" );
109
- });
110
- },
111
-
112
- _source: function( request, response ) {
113
- var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
114
- response( this.element.children( "option" ).map(function() {
115
- var text = $( this ).text();
116
- if ( this.value && ( !request.term || matcher.test(text) ) )
117
- return {
118
- label: text,
119
- value: text,
120
- option: this
121
- };
122
- }) );
123
- },
124
- });
125
- })( jQuery );
126
-
127
- $(function() {
128
- $( "'
129
- out << '#_' + object.class.to_s.underscore + '_' + object.id.to_s + '_' + attribute.foreign_key.to_s
130
- out << '" ).combobox();
131
- });
132
- </script>'
133
- out.html_safe
134
-
135
-
136
- end
137
-
138
- def dropdown_with_other_update(object, attribute)
139
- attribute = attribute.to_s
140
- foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.foreign_key.to_sym
141
- # if there is an attribute attr, then there must be an attribute attr_other
142
- other = params[('_' + object.class.to_s.underscore).to_sym][(attribute + "_other").to_sym]
143
- # see if it matches anything (but we need to look at I18n too!
144
- lookup_model = attribute.camelcase.constantize
145
- name_field = 'name_' + I18n.locale.to_s
146
- name_field = 'name' unless lookup_model.new.respond_to? name_field
147
- puts 'XXXXXXXXXXXXXXXXXXXX ' + name_field.inspect
148
- match = lookup_model.where(name_field.to_sym => other).first # problem if there are dupes!
149
- puts 'XXXXXXXXXXXXXXXXXXXX ' + match.inspect
150
- match.nil? ? object[foreign_key] = 0 : object[foreign_key] = match.id # problem if there is a record with id: 0 !
151
- match.nil? ? object[attribute + '_other'] = other : object[attribute + '_other'] = nil
152
- end
153
-
@@ -1,22 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- # not needed here, since this is only used in the views InlineForms::SPECIAL_COLUMN_TYPES[:info]=:string
3
-
4
- def info_list_show(object, attribute)
5
- # we would expect
6
- out = ''
7
- out = "<div class='row #{cycle('odd', 'even')}'>--</div>" if object.send(attribute).empty?
8
- object.send(attribute).sort.each do | item |
9
- out << "<div class='row #{cycle('odd', 'even')}'>"
10
- out << item._presentation
11
- out << '</div>'
12
- end
13
- out.html_safe
14
- end
15
-
16
- def info_list_edit(object, attribute)
17
- # we should raise an error
18
- end
19
-
20
- def info_list_update(object, attribute)
21
- # we should raise an errror
22
- end
@@ -1,15 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- InlineForms::SPECIAL_COLUMN_TYPES[:integer_field]=:integer
3
-
4
- def integer_field_show(object, attribute)
5
- link_to_inline_edit object, attribute, object[attribute].nil? ? "<i class='fi-plus'></i>".html_safe : object[attribute]
6
- end
7
-
8
- def integer_field_edit(object, attribute)
9
- number_field_tag attribute, (object.send attribute.to_sym), :class => 'input_integer_field' # for abide: , :required => true
10
- end
11
-
12
- def integer_field_update(object, attribute)
13
- object.send :write_attribute, attribute.to_sym, params[attribute.to_sym]
14
- end
15
-
@@ -1,89 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- InlineForms::SPECIAL_COLUMN_TYPES[:kansen_slider]=:integer
3
-
4
- # kansen_slider
5
- def kansen_slider_show(object, attribute)
6
- values = attribute_values(object, attribute)
7
- value = object.send(attribute).to_i # should be an int
8
- display_value = values.assoc(value)[1] # values should be [ [ 0, value ], [ 3, value2 ] .... ] and we lookup the key, not the place in the array!
9
- css_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}"
10
- if value == 0 || value > 5
11
- out = display_value
12
- else
13
- out = "<div class='row collapse'>".html_safe
14
- out << "<div class='small-5 column slider_value' id='value_#{css_id}'>#{display_value}</div>".html_safe
15
- out << "<div class='small-7 column kansen_slider_show slider slider_#{attribute.to_s}' id='slider_#{css_id}'></div>".html_safe
16
- out << "<input type='hidden' name='_#{object.class.to_s.underscore}[#{attribute}]' value='0' id='input_#{css_id}' />".html_safe
17
- out << ('<script>
18
- $(function() {
19
- var displayvalues = ' + values.collect {|x| x[1]}.inspect + ';
20
- $( "#slider_' + css_id + '" ).slider(
21
- {
22
- value:' + value.to_s + ',
23
- disabled: true,
24
- min: 1,
25
- max: 5,
26
- step: 1,
27
- }
28
- );
29
- });
30
- </script>').html_safe
31
- out << "</div>".html_safe
32
- end
33
- link_to_inline_edit object, attribute, out
34
- end
35
-
36
- def kansen_slider_edit(object, attribute)
37
- # the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form!
38
- values = attribute_values(object, attribute)
39
- value = object.send(attribute).to_i # should be an int, will be 0 if nil
40
- css_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}"
41
- display_value = values.assoc(value)[1] # values should be [ [ 0, value ], [ 3, value2 ] .... ] and we lookup the key, not the place in the array!
42
- out = "<div class='row collapse'>".html_safe
43
- out << "<div class='small-5 column kansen_slider_value' id='value_#{css_id}'>#{display_value}</div>".html_safe
44
- out << "<div class='small-7 column kansen_slider_edit slider slider_#{attribute.to_s}' id='slider_#{css_id}'></div>".html_safe
45
- out << "<input type='hidden' name='_#{object.class.to_s.underscore}[#{attribute}]' value='0' id='input_#{css_id}' />".html_safe
46
- out << ('<script>
47
- $(function() {
48
- var displayvalues = ' + values.collect {|x| x[1]}.inspect + ';
49
- $( "#slider_' + css_id + '" ).slider(
50
- {
51
- value:' + value.to_s + ',
52
- min: 0,
53
- max: ' + (values.length - 1 ).to_s + ',
54
- step: 1,
55
- slide: function( event, ui ) {
56
- $( "#input_' + css_id + '" ).val( ui.value );
57
- $( "#value_' + css_id + '" ).html( displayvalues[ui.value] );
58
- }
59
- }
60
- );').html_safe
61
- out << ('$( "#value_' + css_id + '" ).html(displayvalues[' + value.to_s + ']);').html_safe
62
- out << ('$( "#input_' + css_id + '" ).val(' + value.to_s + ');').html_safe
63
- out << ('});
64
- </script>').html_safe
65
- out << '</div>'.html_safe
66
- out
67
- end
68
-
69
- def kansen_slider_update(object, attribute)
70
- object[attribute.to_sym] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_sym]
71
- end
72
-
73
- #<style>
74
- # #demo-frame > div.demo { padding: 10px !important; };
75
- # </style>
76
- #
77
- #
78
- #
79
- #<div class="demo">
80
- #
81
- #<p>
82
- # <label for="amount">Donation amount ($50 increments):</label>
83
- # <input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;" />
84
- #</p>
85
- #
86
- #<div id="slider"></div>
87
- #
88
- #</div><!-- End demo -->
89
- #
@@ -1,33 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- InlineForms::SPECIAL_COLUMN_TYPES[:month_year_picker]=:date
3
-
4
- # date
5
- def month_year_picker_show(object, attribute)
6
- link_to_inline_edit object, attribute, object.send(attribute).nil? ? "<i class='fi-plus'></i>".html_safe : object.send(attribute).strftime("%B %Y")
7
- end
8
-
9
- def month_year_picker_edit(object, attribute)
10
- css_id = 'datepicker_' + object.class.to_s.underscore + '_' + object.id.to_s + '_' + attribute.to_s
11
- out = text_field_tag attribute, ( object.send(attribute).nil? ? "" : object.send(attribute).strftime("%B %Y") ), :id => css_id, :class =>'datepicker'
12
- #out << (hidden_field_tag "hidden_" + attribute.to_s, ( object.send(attribute).nil? ? "" : object.send(attribute).strftime("%d-%m-%Y") ), :id => "hiddden_" + css_id)
13
- # http://jsfiddle.net/bopperben/DBpJe/
14
- out << "<script>$('##{css_id}').datepicker( {
15
- changeMonth: true,
16
- changeYear: true,
17
- showButtonPanel: true,
18
- dateFormat: 'MM yy',
19
- regional: '',
20
- onClose: function(dateText, inst) {
21
- var month = $('#ui-datepicker-div .ui-datepicker-month :selected').val();
22
- var year = $('#ui-datepicker-div .ui-datepicker-year :selected').val();
23
- $(this).datepicker('setDate', new Date(year, month, 1));
24
- }
25
- });</script>".html_safe
26
- end
27
-
28
- def month_year_picker_update(object, attribute)
29
- puts 'XXXXXXXXXXXXXXXXXXXXXXXXXX' + object[attribute.to_sym].inspect
30
- puts 'XXXXXXXXXXXXXXXXXXXXXXXXXX' + Date.parse(params[attribute.to_sym].to_s).strftime("%F").to_s
31
- object[attribute.to_sym] = Date.parse(params[attribute.to_sym].to_s).strftime("%F").to_s
32
- puts 'XXXXXXXXXXXXXXXXXXXXXXXXXX' + object[attribute.to_sym].inspect
33
- end
@@ -1,17 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- #InlineForms::SPECIAL_COLUMN_TYPES[:text_field]=:string
3
-
4
- def move_show(object, attribute)
5
- link_to_inline_edit object, attribute, "<i class='fi-plus'></i>".html_safe
6
- end
7
-
8
- def move_edit(object, attribute)
9
- values = object.class.send :hash_tree_to_collection
10
- select( ('_' + object.class.to_s.underscore).to_sym, attribute, values, :selected => object.id )
11
- end
12
-
13
- def move_update(object, attribute)
14
- parent = object.class.find_by_id(params['_' + object.class.to_s.underscore][attribute.to_sym])
15
- parent.add_child(object) if parent
16
- end
17
-
@@ -1,13 +0,0 @@
1
- <% unless flash.empty? %>
2
- <% identifier = Time.now.to_i.to_s %>
3
- <div class="row" id="flash_<%= identifier %>">
4
- <% flash.each do |key, value| %>
5
- <%= value %>
6
- <% end %>
7
- <script>
8
- $("#<%= "#{update_span}_auto_header" %>").ScrollTo();
9
- $("#flash_<%= identifier %>").delay(1000).fadeToggle('2000');
10
- </script>
11
- </div>
12
- <% end %>
13
-
@@ -1,43 +0,0 @@
1
- This goes in _new.html.erb
2
- <% if form_element.to_sym == :associated -%>
3
- <% @nested_model = @object.send(attribute) %>
4
- <%= render 'new_nested' %>
5
- <% end %>
6
- ********
7
-
8
- <% @nested_object = @nested_model.build %>
9
-
10
- <div class="new_nested_record">
11
- <div class="row" >
12
- <div class="large-12 column object_presentation" >
13
- <%= t('inline_forms.view.add_new', :model => @nested_object.class ) -%>
14
- </div>
15
- </div>
16
- <% nested_attributes = @nested_object.inline_forms_attribute_list -%>
17
- <% nested_attributes.each do | nested_attribute, nested_name, nested_form_element | -%>
18
- <% @nested_form_element = nested_form_element %>
19
- <% @nested_attribute = nested_attribute %>
20
- <% unless @nested_form_element.to_sym == :associated -%>
21
- <% if @nested_form_element == :header %>
22
- <div class="row form_element_header" >
23
- <div class='large-12 column' >
24
- <%= @nested_object.class.human_attribute_name(@nested_attribute) -%>
25
- </div>
26
- </div>
27
- <% else %>
28
- <div class="row <%= cycle('odd', 'even') %>">
29
- <div class='medium-3 large-3 column' >
30
- <%= @nested_object.class.human_attribute_name(@nested_attribute) -%>
31
- </div>
32
- <div class='medium-9 large-9 column' >
33
- <%= send("#{@nested_form_element}_edit", @nested_object, @nested_attribute) -%>
34
- </div>
35
- </div>
36
- <% end -%>
37
- <% end -%>
38
- <% end -%>
39
- <% if @nested_form_element.to_sym == :associated -%>
40
- <%= render 'new_nested' %>
41
- <% end %>
42
- <div class="row record_footer"></div>
43
- </div>
@@ -1,46 +0,0 @@
1
- <% # here we come from _show %>
2
- <% update_span = "#{parent_class.to_s.underscore}_#{parent_id}_#{attribute}_list" -%>
3
- <% path_to_new='new_' + parent_class.to_s.underscore.singularize + '_path' %>
4
- <% model = parent_class %>
5
- <% objects = parent_class.find(parent_id).children %>
6
- <% objects = parent_class.find(parent_id).children.accessible_by(current_ability) if cancan_enabled? %>
7
- <% objects = objects.paginate :page => params[:page], :per_page => @PER_PAGE || 5 %>
8
-
9
- <div class="list_container" id="<%= update_span %>">
10
-
11
- <!-- # list of objects -->
12
- <% for object in objects %>
13
- <% css_class_id = parent_class.to_s.underscore + '_' + parent_id.to_s + '_' + attribute.to_s.singularize.underscore + "_" + object.id.to_s -%>
14
- <% path_to_object = parent_class.to_s.singularize.underscore + "_path" %>
15
- <div class="row <%= cycle('odd', 'even') %><%= " top-level" if parent_class.nil? %>" id="<%= css_class_id -%>">
16
- <% if cancan_disabled? || ( can? :delete, object ) %>
17
- <div class="small-1 column">
18
- <%= link_to_destroy(object, css_class_id) -%>
19
- </div>
20
- <div class="small-11 column">
21
- <%= link_to h(object._presentation),
22
- send( path_to_object, object, :update => css_class_id),
23
- :remote => true -%>
24
- </div>
25
- <% else %>
26
- <div class="small-12 column">
27
- <%= link_to h(object._presentation),
28
- send( path_to_object, object, :update => css_class_id),
29
- :remote => true -%>
30
- </div>
31
- <% end %>
32
- </div>
33
- <% end -%>
34
- <!-- # pagination -->
35
- <% if parent_id.nil? -%>
36
- <% pagination = will_paginate objects -%>
37
- <% else %>
38
- <% pagination = will_paginate objects, :remote => true, :params => {:controller => attribute, :action => :index, :id => nil, :parent_class => parent_class, :parent_id => parent_id, :update => "#{parent_class.to_s.underscore}_#{parent_id}_#{attribute}", :ul_needed => true } -%>
39
- <% end %>
40
- <% if pagination %>
41
- <div class="row <%= cycle('odd', 'even') %>">
42
- <div class='small-11 small-centered column'>
43
- <%= raw pagination %>
44
- </div>
45
- </div>
46
- <% end %>