Module: Admin::PagesHelper

Includes:
NodeHelper, ReferencesHelper
Defined in:
app/helpers/admin/pages_helper.rb

Instance Method Summary collapse

Instance Method Details

#class_of_pageObject



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

def class_of_page
  if @page
    @page.class
  else
    @page_class ||= (params[:class_name].presence || 'Page').constantize
  end
end

#default_filter_nameObject



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

def default_filter_name
  @page.parts.empty? ? "" : @page.parts[0].filter_id
end

#filterObject



13
14
15
16
17
18
19
20
21
22
# File 'app/helpers/admin/pages_helper.rb', line 13

def filter
  if @page
    @page.parts.empty? ? nil : @page.parts.first.filter
  else
    @filter ||= begin
      filter_name = params[:filter_name]
      (filter_name.gsub(" ", "") + "Filter").constantize unless filter_name.blank?
    end
  end
end

#homepageObject



28
29
30
# File 'app/helpers/admin/pages_helper.rb', line 28

def homepage
  @homepage ||= Page.find_by_parent_id(nil)
end

#page_edit_javascriptsObject



39
40
41
42
43
44
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/helpers/admin/pages_helper.rb', line 39

def page_edit_javascripts
  (<<-CODE).html_safe
  function addPart(form) {
     if (validPartName()) {
      new Ajax.Updater(
        $('tab_control').down('.pages'),
        '#{admin_page_parts_path}',
        {
          asynchronous: true,
          evalScripts: true,
          insertion: 'bottom',
          onComplete: function(request){ partAdded() },
          onLoading: function(request){ partLoading() },
          parameters: Form.serialize(form)
        }
      );
    }
  }
  function removePart() {
    if(confirm('Remove the current part?')) {
      TabControls['tab_control'].removeSelected();
    }
  }
  function partAdded() {
    var tabControl = TabControls['tab_control'];
    $('add_part_busy').hide();
    $('add_part_button').disabled = false;
    $('add_part_popup').closePopup();
    $('part_name_field').value = '';
    tabControl.updateTabs();
    tabControl.select(tabControl.tabs.last());
  }
  function partLoading() {
    $('add_part_button').disabled = true;
    $('add_part_busy').appear();
  }
  function validPartName() {
    var partNameField = $('part_name_field');
    var name = partNameField.value.downcase();
    if (name.blank()) {
      alert('Part name cannot be empty.');
      return false;
    }
    if (TabControls['tab_control'].findTabByCaption(name)) {
      alert('Part name must be unique.');
      return false;
    }
    return true;
  }

  var lastPageType = '#{@page.class.name}';
  var tagReferenceWindows = {};
  function loadTagReference(part) {
    var pageType = $F('page_class_name');
    if (!tagReferenceWindows[pageType])
      tagReferenceWindows[pageType] = new Popup.AjaxWindow("#{admin_reference_path('tags')}?class_name=" + encodeURIComponent(pageType), {reload: false});
    var window = tagReferenceWindows[pageType];
    if(lastPageType != pageType) {
      $('tag_reference_link_' + part).highlight();
      window.show();
    } else {
      window.toggle();
    }
    lastPageType = pageType;
    return false;
  }

  var lastFilter = '#{default_filter_name}';
  var filterWindows = {};
  function loadFilterReference(part) {
    var filter = $F("part_" + part + "_filter_id");
    if (filter != "") {
      if (!filterWindows[filter]) filterWindows[filter] = new Popup.AjaxWindow("#{admin_reference_path('filters')}?filter_name="+encodeURIComponent(filter), {reload: false});
      var window = filterWindows[filter];
      if(lastFilter != filter) {
        window.show();
      } else {
        window.toggle();
      }
      lastFilter = filter;
    } else {
      alert('No documentation for filter.');
    }
    return false;
  }
  CODE
end

#status_to_displayObject



32
33
34
35
36
37
# File 'app/helpers/admin/pages_helper.rb', line 32

def status_to_display
  @page.status_id = 100 if @page.status_id == 90
  @display_status = []
  Status.find_all.each { |s| @display_status <<  [t(s.name.downcase), s.id] unless s.name == 'Scheduled' }
  return @display_status
end