module BootstrapFormExtensions::Scheduler

Public Class Methods

serializer(to: :yaml, default_selection: true) click to toggle source
# File lib/bootstrap_form_extensions/scheduler.rb, line 7
def self.serializer to: :yaml, default_selection: true
  BootstrapFormExtensions::Scheduler::Serializer.new to, default_selection
end

Public Instance Methods

scheduler(method, **options) click to toggle source
# File lib/bootstrap_form_extensions/scheduler.rb, line 11
def scheduler method, **options
  schedule = object.send method
  hidden   = hidden_field method, value: JSON.dump(schedule), class: 'scheduler-hidden-field'
  options[:wrapper] ||= {}
  options[:wrapper][:data] ||= {}
  options[:wrapper][:data][:scheduler] = true
  form_group_builder(method, options) { hidden + schedule_to_table(schedule) }
end

Private Instance Methods

schedule_to_table(schedule) click to toggle source
# File lib/bootstrap_form_extensions/scheduler.rb, line 22
def schedule_to_table schedule
  content_tag :table, class: 'scheduler-badge' do
    content_tag :tbody do
      schedule.each.with_index.inject(''.html_safe) do |rows, (day_array, day_index)|
        rows << content_tag(:tr) do
          day_array.each.with_index.inject(''.html_safe) do |columns, (value, hour_index)|
            columns << content_tag(:td, '&nbsp;'.html_safe, class: (true?(value) ? 'on' : 'off'), data: { day: day_index, hour: hour_index })
          end
        end
      end
    end
  end
end