From 3ac7775d9984dec2d2d1d152f03041044c814caa Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 7 Nov 2012 18:46:54 -0500 Subject: [PATCH] some revert stuff --- config/locales/sisyphus.en.yml | 4 ++++ lib/sisyphus-rails.rb | 19 ++++++++++++++++++- lib/sisyphus-rails/form_helper.rb | 20 ++------------------ lib/sisyphus-rails/form_tag_helper.rb | 2 +- vendor/assets/javascripts/sisyphus/rails.js | 11 +++++++++++ 5 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 vendor/assets/javascripts/sisyphus/rails.js diff --git a/config/locales/sisyphus.en.yml b/config/locales/sisyphus.en.yml index e69de29..0d557ec 100644 --- a/config/locales/sisyphus.en.yml +++ b/config/locales/sisyphus.en.yml @@ -0,0 +1,4 @@ +en: + sisyphus: + autosaved_content: You are viewing autosaved content. + revert: Revert to original content diff --git a/lib/sisyphus-rails.rb b/lib/sisyphus-rails.rb index d87d321..4922b0e 100644 --- a/lib/sisyphus-rails.rb +++ b/lib/sisyphus-rails.rb @@ -7,8 +7,25 @@ module Sisyphus mattr_accessor :process mattr_accessor :app_root mattr_accessor :config + mattr_accessor :form_builder def self.setup yield self end -end \ No newline at end of file + + class FormBuilder + def initialize(template) + @template = template + end + + def status + @template.content_tag(:div, message.html_safe, :class => 'sisyphus_status', :style => 'display: none') + end + + def message + @template.t('sisyphus.autosaved_content') << @template.content_tag(:button, @template.t('sisyphus.revert')) + end + end + + Sisyphus.form_builder = Sisyphus::FormBuilder +end diff --git a/lib/sisyphus-rails/form_helper.rb b/lib/sisyphus-rails/form_helper.rb index 0842802..ec78bd3 100644 --- a/lib/sisyphus-rails/form_helper.rb +++ b/lib/sisyphus-rails/form_helper.rb @@ -30,25 +30,9 @@ module ActionView alias_method_chain :form_for, :sisyphus def sisyphus_status - buf = ActiveSupport::SafeBuffer.new - - buf.safe_concat <<-JS - - - JS - - buf + Sisyphus.form_builder.new(self).status end end end end + diff --git a/lib/sisyphus-rails/form_tag_helper.rb b/lib/sisyphus-rails/form_tag_helper.rb index 5a98156..77eb304 100644 --- a/lib/sisyphus-rails/form_tag_helper.rb +++ b/lib/sisyphus-rails/form_tag_helper.rb @@ -6,7 +6,7 @@ module ActionView buf = ActiveSupport::SafeBuffer.new if options.has_key?(:id) && Sisyphus::process - buf.safe_concat("") + buf.safe_concat("") end buf << form_tag_without_sisyphus(url_for_options, options, &block) diff --git a/vendor/assets/javascripts/sisyphus/rails.js b/vendor/assets/javascripts/sisyphus/rails.js new file mode 100644 index 0000000..898fea4 --- /dev/null +++ b/vendor/assets/javascripts/sisyphus/rails.js @@ -0,0 +1,11 @@ +//= require sisyphus +//= require_self + +$.sisyphus.railsRestore = function() { + $('.sisyphus_status').show().find('button').unbind().click(function() { + $.sisyphus().manuallyReleaseData(); + window.location.href = window.location.href; + return false; + }); +}; +