Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
3ac7775d99 | ||
|
a604a76e02 |
4
config/locales/sisyphus.en.yml
Normal file
4
config/locales/sisyphus.en.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
en:
|
||||||
|
sisyphus:
|
||||||
|
autosaved_content: You are viewing autosaved content.
|
||||||
|
revert: Revert to original content
|
@ -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
|
@ -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
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
11
vendor/assets/javascripts/sisyphus/rails.js
vendored
Normal file
11
vendor/assets/javascripts/sisyphus/rails.js
vendored
Normal 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;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user