Module: Gluttonberg::Admin::Versioning

Included in:
Gluttonberg::Admin
Defined in:
app/helpers/gluttonberg/admin/versioning.rb

Instance Method Summary collapse

Instance Method Details

#auto_save(object) ⇒ Object

Enable auto save on a form



24
25
26
# File 'app/helpers/gluttonberg/admin/versioning.rb', line 24

def auto_save(object)
  "#{auto_save_js_tag(object)} \n #{auto_save_version(object)}".html_safe
end

#auto_save_js_tag(object) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/gluttonberg/admin/versioning.rb', line 28

def auto_save_js_tag(object)
  delay = Gluttonberg::Setting.get_setting('auto_save_time')
  unless delay.blank?
    javascript_tag do
      %{
        $(document).ready(function(){
          AutoSave.save("/admin/autosave/#{object.class.name}/#{object.id}", #{delay});
        });
      }.html_safe
    end
  end
end

#auto_save_version(object) ⇒ Object

it renders a warning box with message and buttons for restoring/cancel (warning about un saved version) if there is any auto save version exists.



6
7
8
9
10
11
# File 'app/helpers/gluttonberg/admin/versioning.rb', line 6

def auto_save_version(object)
  auto_save = AutoSave.where(:auto_save_able_id => object.id, :auto_save_able_type => object.class.name).first
  if !auto_save.blank? && auto_save.updated_at > object.updated_at
    render :partial => "/gluttonberg/admin/shared/auto_save_version" , :locals => {:object => object} , :formats => [:html]
  end
end

#previous_version_warning(versions, selected_version_num) ⇒ Object

It renders warning for if user is viewing older revision of and object



14
15
16
17
18
19
20
21
# File 'app/helpers/gluttonberg/admin/versioning.rb', line 14

def previous_version_warning(versions , selected_version_num)
  if !versions.blank? && !selected_version_num.blank?
    versions = versions.sort{|x,y| y.version <=> x.version}
    if selected_version_num.to_i < versions.first.version
      render :partial => "/gluttonberg/admin/shared/previous_version_warning" , :locals => {:selected_version_num => selected_version_num} , :formats => [:html]
    end
  end
end

#version_alerts(versions, selected_version_num, can_publish) ⇒ Object

It shows 3 kind of warnings depending on case Reviewing Version xx: Submitted for approval Version xx: Waiting for approval Version xx: Unpublished revision



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/helpers/gluttonberg/admin/versioning.rb', line 45

def version_alerts(versions , selected_version_num, can_publish)
  unless versions.blank?
    versions = versions.order("version DESC")
    your_revisions = []
     = []
    published_version = nil
    viewing_waiting_for_approval = nil
    versions.each do |version|
      published_version = version if version.version_status == "published"
      if (published_version.blank? || published_version.version < version.version)
        if version.version != selected_version_num.to_i
           << version if version.version_status == "submitted_for_approval"
          your_revisions << version if version.version_status == "revision" && version.version_user_id == current_user.id
        else
          viewing_waiting_for_approval = version if version.version_status == "submitted_for_approval"
        end
      end
    end
    render :partial => "/gluttonberg/admin/shared/version_alerts", :locals => {
      :submitted_for_approval => ,
      :your_revisions => your_revisions,
      :can_publish => can_publish,
      :viewing_waiting_for_approval => viewing_waiting_for_approval
    }
  end
end

#version_dashboard_notificationsObject

this renders recently submitted contents(max 5 items). Its used on dashboard



84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/helpers/gluttonberg/admin/versioning.rb', line 84

def version_dashboard_notifications
  if current_user.ability.can?(:publish, :any)
     = version_dashboard_notifications_data

    more = (.length > 5)
     = [0..4] if more
    render :partial => "/gluttonberg/admin/shared/version_dashboard_notifications", :locals => {
      :submitted_content => ,
      :more => more
    }
  end
end

#version_dashboard_notifications_dataObject

version_alerts



72
73
74
75
76
77
78
79
80
81
# File 'app/helpers/gluttonberg/admin/versioning.rb', line 72

def version_dashboard_notifications_data
   = []

  _page_version_dashboard_notifications_data()
  _blog_version_dashboard_notifications_data()
  _custom_models_version_dashboard_notifications_data()

  .uniq! unless .blank?
   = .sort{|x,y| y[2].created_at <=>  x[2].created_at }
end