Compare commits

..

2 Commits

Author SHA1 Message Date
John Bintz
3ac7775d99 some revert stuff 2012-11-07 18:46:54 -05:00
John Bintz
a604a76e02 start work on revert 2012-11-05 07:48:30 -05:00
5 changed files with 40 additions and 3 deletions

View File

@ -0,0 +1,4 @@
en:
sisyphus:
autosaved_content: You are viewing autosaved content.
revert: Revert to original content

View File

@ -7,8 +7,25 @@ module Sisyphus
mattr_accessor :process mattr_accessor :process
mattr_accessor :app_root mattr_accessor :app_root
mattr_accessor :config mattr_accessor :config
mattr_accessor :form_builder
def self.setup def self.setup
yield self yield self
end end
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 end

View File

@ -28,6 +28,11 @@ module ActionView
end end
alias_method_chain :form_for, :sisyphus alias_method_chain :form_for, :sisyphus
def sisyphus_status
Sisyphus.form_builder.new(self).status
end
end end
end end
end end

View File

@ -6,7 +6,7 @@ module ActionView
buf = ActiveSupport::SafeBuffer.new buf = ActiveSupport::SafeBuffer.new
if options.has_key?(:id) && Sisyphus::process 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>") buf.safe_concat("<script type=\"text/javascript\">$(document).ready(function() {$('##{options[:id]}').sisyphus({onRestore: $.sisyphus.railsRestore, excludeFields: $('input[name=utf8], input[name=_method], input[name=authenticity_token]')});});</script>")
end end
buf << form_tag_without_sisyphus(url_for_options, options, &block) buf << form_tag_without_sisyphus(url_for_options, options, &block)

View File

@ -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;
});
};