Added model based include/exclude through config file.
Added global on/off switch.
This commit is contained in:
parent
7bc17ca3ec
commit
973928ef21
@ -55,8 +55,7 @@ To stop Sisyphus from initializing on a form include the *with_sisyphus* option
|
||||
- Tests
|
||||
- Move away from form_tag_helper, should be able to do it all from form_helper? Script tag can go at the end anyhow. Why aren't we doing that right now? We don't seem to have access to the same variables that the regular form_for does. Also the options array gets muddied by the FormHelper form_for call -> it removes the [:html] section (we need the id of the form for sisyphus).
|
||||
- conflict resolution... i.e. you have an object edit form, the fields are populated from the DB but if you have local browser changes they may get overridden. We need a way to resolve conflicts between local and remote data -> could use a jquery based modal dialog to present the diff?
|
||||
- Model/Object based exclusions via config or activerecord extension?
|
||||
- Env. based and global on/off switches
|
||||
- Model based exclusions via activerecord extension?
|
||||
- block based options (this would allow us to easily and neatly implement Sisyphus options)
|
||||
|
||||
<%= form_for User.new do |f| %>
|
||||
|
@ -2,9 +2,10 @@ production:
|
||||
# globally enable or disable sisyphus form protection
|
||||
sisyphus_enabled: true
|
||||
# models to exclude from the default enabled state
|
||||
# exclude_models: User,Post
|
||||
# note that lower case singular is used
|
||||
# exclude_models: user,post
|
||||
# models to include from the default disbaled state
|
||||
# include_models: User,Post
|
||||
# include_models: user,post
|
||||
|
||||
development:
|
||||
sisyphus_enabled: true
|
||||
|
@ -13,16 +13,16 @@ module Sisyphus
|
||||
config = YAML.load_file("#{::Rails.root}/config/sisyphus.yml")
|
||||
config = config[::Rails.env]
|
||||
|
||||
Sisyphus.config["SISYPHUS_ENABLED"] = config['organization_id'] if config['sisyphus_enabled'].present?
|
||||
Sisyphus.config["EXCLUDE_MODELS"] = config['exclude_models'].split(',') if config['exclude_models'].present?
|
||||
Sisyphus.config["INCLUDE_MODELS"] = config['include_models'].split(',') if config['include_models'].present?
|
||||
Sisyphus.config["SISYPHUS_ENABLED"] = config['sisyphus_enabled'] if config.include?('sisyphus_enabled')
|
||||
Sisyphus.config["EXCLUDE_MODELS"] = config['exclude_models'].split(',') if config.include?('exclude_models')
|
||||
Sisyphus.config["INCLUDE_MODELS"] = config['include_models'].split(',') if config.include?('include_models')
|
||||
|
||||
end
|
||||
|
||||
#if we have ENV flags prefer them
|
||||
Sisyphus.config["SISYPHUS_ENABLED"] = ENV["SISYPHUS_ENABLED"] if ENV.include? "SISYPHUS_ENABLED"
|
||||
Sisyphus.config["EXCLUDE_MODELS"] = ENV["EXCLUDE_MODELS"].split(',') if ENV["EXCLUDE_MODELS"]
|
||||
Sisyphus.config["INCLUDE_MODELS"] = ENV["INCLUDE_MODELS"].split(',') if ENV["INCLUDE_MODELS"]
|
||||
Sisyphus.config["SISYPHUS_ENABLED"] = ENV["SISYPHUS_ENABLED"] if ENV.include?("SISYPHUS_ENABLED")
|
||||
Sisyphus.config["EXCLUDE_MODELS"] = ENV["EXCLUDE_MODELS"].split(',') if ENV.include?("EXCLUDE_MODELS")
|
||||
Sisyphus.config["INCLUDE_MODELS"] = ENV["INCLUDE_MODELS"].split(',') if ENV.include?("INCLUDE_MODELS")
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -3,19 +3,26 @@ module ActionView
|
||||
module FormHelper
|
||||
def form_for_with_sisyphus(record, options = {}, &proc)
|
||||
|
||||
case record
|
||||
when String, Symbol
|
||||
object_name = record
|
||||
else
|
||||
object = record.is_a?(Array) ? record.last : record
|
||||
object_name = options[:as] || ActiveModel::Naming.param_key(object)
|
||||
end
|
||||
|
||||
|
||||
# There is an order of precedence debugger
|
||||
Sisyphus::process = true
|
||||
|
||||
Sisyphus::process = Sisyphus::config["SISYPHUS_ENABLED"] if Sisyphus::config["SISYPHUS_ENABLED"].present?
|
||||
Sisyphus::process = Sisyphus::config["SISYPHUS_ENABLED"] if Sisyphus::config.include?("SISYPHUS_ENABLED")
|
||||
|
||||
# if Sisyphus::config["EXCLUDE_MODELS"].present?
|
||||
# Sisyphus::process = false if Sisyphus::config["EXCLUDE_MODELS"].include?(model_name_from_record_or_class(record))
|
||||
# end
|
||||
|
||||
if options[:with_sisyphus] == false
|
||||
Sisyphus::process = false
|
||||
if Sisyphus::config["EXCLUDE_MODELS"].present?
|
||||
Sisyphus::process = false if Sisyphus::config["EXCLUDE_MODELS"].include?(model_name_from_record_or_class(object_name))
|
||||
end
|
||||
|
||||
Sisyphus::process = options[:with_sisyphus] if options.include?(:with_sisyphus)
|
||||
|
||||
#strip all the sisyphus options from the options hash before moving on
|
||||
form_for_without_sisyphus(record, options.reject{|k,v| k =~ /sisyphus(.*)/}, &proc)
|
||||
end
|
||||
|
@ -5,8 +5,6 @@ module ActionView
|
||||
def form_tag_with_sisyphus(url_for_options = {}, options = {}, &block)
|
||||
buf = ActiveSupport::SafeBuffer.new
|
||||
|
||||
buf.safe_concat(Sisyphus::config.to_s)
|
||||
|
||||
if options.has_key?(:id) && Sisyphus::process
|
||||
buf.safe_concat("<script type=\"text/javascript\">$(document).ready(function() {$('##{options[:id]}').sisyphus({excludeFields: $('input[name=utf8], input[name=_method], input[name=authenticity_token]')});});</script>")
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user