format :html do
view :history do |args|
load_revisions
if @revision
frame args.merge( :content=>true, :subheader=>_render_revision_subheader ) do
_render_diff
end
end
end
view :diff do |args|
load_revisions
if @show_diff and @previous_revision
diff @previous_revision.content, @revision.content
else
@revision.content
end
end
view :revision_subheader do |args|
%{
#{ revision_menu }
}
end
def load_revisions
unless @revision_number
@revision_number = (params[:rev] || (card.revisions.count - card.drafts.length)).to_i
@revision = card.revisions[@revision_number - 1]
@previous_revision = @revision ? card.previous_revision( @revision.id ) : nil
@show_diff = (params[:mode] != 'false')
end
end
def revision_link text, revision, name, accesskey='', mode=nil
link_to text, path(:view=>:history, :rev=>revision, :mode=>(mode || params[:mode] || true) ),
:class=>"slotter", :remote=>true, :rel=>'nofollow'
end
def rollback to_rev=nil
to_rev ||= @revision_number
if card.ok?(:update) && !(card.current_revision==@revision)
link_to 'Save as current', path(:action=>:rollback, :rev=>to_rev),
:class=>'slotter', :remote=>true
end
end
def revision_menu
revision_menu_items.flatten.map do |item|
"#{item}"
end.join('')
end
def revision_menu_items
items = [back_for_revision, forward, see_or_hide_changes_for_revision]
items << rollback unless Card::Env.recaptcha_on?
items
end
def forward
if @revision_number < card.revisions.count
revision_link('Newer', @revision_number +1, 'to_next_revision', 'F' ) +
raw(" (#{card.revisions.count - @revision_number})")
else
'Newer (0)'
end
end
def back_for_revision
if @revision_number > 1
revision_link('Older',@revision_number - 1, 'to_previous_revision') +
raw("(#{@revision_number - 1})")
else
'Older (0)'
end
end
def see_or_hide_changes_for_revision
revision_link(@show_diff ? 'Hide changes' : 'Show changes',
@revision_number, 'see_changes', 'C', (@show_diff ? 'false' : 'true'))
end
def autosave_revision
revision_link("Autosaved Draft", card.revisions.count, 'to autosave')
end
end