aboutsummaryrefslogtreecommitdiffstats
path: root/app/inputs
diff options
context:
space:
mode:
authorZog2017-12-26 16:10:45 +0100
committerZog2017-12-26 16:10:45 +0100
commit8fa785c90a2d0d4d59fdcf0d235871aae86f49ca (patch)
tree070b48d479b3e0535fc0f3a452ba7e59e6bb177e /app/inputs
parent9c1b150c4106b9c1773e7c056ca568f1f69d98bc (diff)
downloadchouette-core-8fa785c90a2d0d4d59fdcf0d235871aae86f49ca.tar.bz2
Refs #5367 @2H; Add a ColorSelectInput
- Added to PurchaseWindow form - Reuse already exisiting JS + CSS - We may want to change the colors names
Diffstat (limited to 'app/inputs')
-rw-r--r--app/inputs/color_select_input.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/app/inputs/color_select_input.rb b/app/inputs/color_select_input.rb
new file mode 100644
index 000000000..963083c08
--- /dev/null
+++ b/app/inputs/color_select_input.rb
@@ -0,0 +1,46 @@
+class ColorSelectInput < SimpleForm::Inputs::CollectionInput
+ enable :placeholder
+
+ def input(wrapper_options = {})
+ # @collection ||= @builder.object.send(attribute_name)
+ label_method, value_method = detect_collection_methods
+ selected_color = object.send(attribute_name)
+ label = if selected_color
+ collection.find{|i| i.is_a?(Enumerable) && i.last == selected_color}.try(:first)
+ end
+
+ out = @builder.hidden_field attribute_name, value: selected_color
+ tag_name = ActionView::Helpers::Tags::Base.new( ActiveModel::Naming.param_key(object), attribute_name, :dummy ).send(:tag_name)
+ select = <<-eos
+ <div class="dropdown color_selector">
+ <button type='button' class="btn btn-default dropdown-toggle" data-toggle='dropdown' aria-haspopup='true' aria-expanded='true'
+ ><span
+ class='fa fa-circle mr-xs'
+ style='color: #{selected_color == nil ? 'transparent' : selected_color}'
+ >
+ </span>
+ #{label}
+ <span class='caret'></span>
+ </button>
+
+ <div class="form-group dropdown-menu" aria-labelledby='dpdwn_color'>
+ eos
+
+ collection.each do |color|
+ name = nil
+ name, color = color if color.is_a?(Enumerable)
+ select += <<-eos
+ <span class="radio" key=#{color} >
+ <label>
+ <input type='radio' class='color_selector' value='#{color}' data-for='#{tag_name}'/>
+ <span class='fa fa-circle mr-xs' style='color: #{color == nil ? 'transparent' : color}'></span>
+ #{name}
+ </label>
+ </span>
+ eos
+ end
+ select += "</div>"
+
+ out + select.html_safe
+ end
+end