Sha256: 94bcb12cd77d697306c89b11cd684aca2a2bb9ee5abb0f79450e84c074fb7038
Contents?: true
Size: 1.21 KB
Versions: 3
Compression:
Stored size: 1.21 KB
Contents
module CrowdaiAdmin class ToggleBooleans < CustomBuilder def render raise ArgumentError, 'Block should not be used in toggle bool columns' if block return if conditional_eval_hide? context.div class: 'toggle-bool-switches-container' do context.span toggle end end def toggle toggle_classes = 'toggle-bool-switch' toggle_classes += ' on' if data toggle_classes += ' notify-success' if options[:success_message] context.span( '', id: "toggle-#{class_name}-#{model.id}-#{attribute}", class: toggle_classes, 'data-model' => class_name, 'data-object_id' => model.id, 'data-field' => attribute, 'data-value' => data, 'data-url' => context.auto_url_for(model), 'data-success_message' => options[:success_message] ) end def conditional_eval_hide? [:if, :unless].any? do |cond| if options[cond] raise ArgumentError, "'#{cond}' option should be a proc" unless options[cond].is_a?(Proc) result = options[cond].call(model) cond == :if ? !result : result end end end end end CrowdaiAdmin::ToggleBooleans.create_view_methods
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
crowdai_admin-1.0.2 | lib/crowdai_admin/toggle_booleans.rb |
crowdai_admin-1.0.1 | lib/crowdai_admin/toggle_booleans.rb |
crowdai_admin-1.0.0 | lib/crowdai_admin/toggle_booleans.rb |