Sha256: 64bc8d7cb9bd21e1d0e70a422a67d30dcff7f3c9a6b86e8c9e4255ace81e33f9
Contents?: true
Size: 1.77 KB
Versions: 3
Compression:
Stored size: 1.77 KB
Contents
require 'builder' module RailsAdmin module Config module Fields module Types class State < RailsAdmin::Config::Fields::Base # Register field type for the type loader RailsAdmin::Config::Fields::Types::register(self) include RailsAdmin::Engine.routes.url_helpers register_instance_option :pretty_value do @state_machine_options = ::RailsAdminState::Configuration.new @abstract_model state = bindings[:object].send(name) state_class = @state_machine_options.state(state) s = bindings[:object].class.state_machines[name.to_sym].states[state.to_sym] ret = [ '<div class="label ' + state_class + '">' + s.human_name + '</div>', '<div style="height: 10px;"></div>' ] events = bindings[:object].class.state_machines[name.to_sym].events bindings[:object].send("#{name}_events".to_sym).each do |event| event_class = @state_machine_options.event(event) ret << bindings[:view].link_to( events[event].human_name, state_path(model_name: @abstract_model, id: bindings[:object].id, event: event, attr: name), method: :post, class: "btn btn-mini #{event_class}", style: 'margin-bottom: 5px;' ) end ('<div style="white-space: normal;">' + ret.join(' ') + '</div>').html_safe end register_instance_option :formatted_value do pretty_value end register_instance_option :partial do :form_state end register_instance_option :multiple? do false end end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rails_admin_state-1.1.1 | lib/rails_admin_state/field.rb |
rails_admin_state-1.0.2 | lib/rails_admin_state/field.rb |
rails_admin_state-1.0.1 | lib/rails_admin_state/field.rb |