Module: Mokio::Backend::MenuHelper

Includes:
Haml::Helpers
Defined in:
app/helpers/mokio/backend/menu_helper.rb

Instance Method Summary collapse

Instance Method Details

#dual_select_box(col_left, left_id, left_name, col_right, right_id, right_name, label, html_id, field, useFilters, showColTitle, always, editable) ⇒ Object

html for dual select box



32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/mokio/backend/menu_helper.rb', line 32

def dual_select_box(col_left, left_id, left_name, col_right, right_id, right_name, label, html_id, field, useFilters, showColTitle, always, editable)
  html = dual_select_open(label, html_id, useFilters)              
  html << dual_select_left_box(html_id, col_left, editable, left_name, left_id)

  if editable
    html << dual_select_buttons(html_id, useFilters)
    html << dual_select_right_box(html_id, useFilters, editable, col_right, right_id, right_name, always, field)
  end

  html << dual_select_close
  html.html_safe
end

#dual_select_buttons(html_id, useFilters) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/mokio/backend/menu_helper.rb', line 57

def dual_select_buttons(html_id, useFilters)
  "<div id='#{useFilters ? 'button-group-filter' : 'button-group'}' class='dualBtn'>
    <div class='container_btn'>
      <button id='to2#{html_id}' class='btn' type='button'><span class='icon12 minia-icon-arrow-right-3'></span></button>
      <button id='allTo2#{html_id}' class='btn' type='button'><span class='icon12 iconic-icon-last'></span></button>
      <button id='to1real#{html_id}' class='btn marginT5' type='button'><span class='icon12 minia-icon-arrow-left-3'></span></button>
      <button id='to1#{html_id}' class='btn marginT5 fake' type='button'></button>
      <button id='allTo1#{html_id}' class='btn marginT5 fake' type='button'></button>
      <button id='allTo1real#{html_id}' class='btn marginT5' type='button'><span class='icon12 iconic-icon-first'></span></button>
    </div>
  </div>"
end

#dual_select_closeObject



49
50
51
# File 'app/helpers/mokio/backend/menu_helper.rb', line 49

def dual_select_close
  "</div></div></div></div>"
end

#dual_select_left_box(html_id, col_left, editable, left_name, left_id) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'app/helpers/mokio/backend/menu_helper.rb', line 70

def dual_select_left_box(html_id, col_left, editable, left_name, left_id)
  "<div class='leftBox'>
    #{select_tag(:all_articles, options_for_select(col_left.collect{|elt| [elt.send(left_name), elt.send(left_id),{class: "displayed_#{elt.displayed?}"}]}), multiple: true, class: 'multiple nostyle form-control select-box', id: 'box1View' + html_id, disabled: !editable)}
    <span id='box1Counter#{html_id}' class='count fake'></span>
    <div class='dn'>
      <select id='box1Storage#{html_id}' class='nostyle' name='box1Storage'></select>
    </div>
  </div>"
end

#dual_select_open(label, html_id, useFilters) ⇒ Object



45
46
47
# File 'app/helpers/mokio/backend/menu_helper.rb', line 45

def dual_select_open(label, html_id, useFilters)
  "<div class='row-fluid'><label class='form-label span2'>#{label}</label><div class='panel-body span10'><div class='form-group'>#{dual_select_search_box(html_id) if useFilters}<div class='col-lg-12'>"
end

#dual_select_right_box(html_id, useFilters, editable, col_right, right_id, right_name, always, field) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/helpers/mokio/backend/menu_helper.rb', line 80

def dual_select_right_box(html_id, useFilters, editable, col_right, right_id, right_name, always, field)
  html = "<div class='rightBox'>"
  html << dual_select_right_box_search(html_id) if useFilters
  html << "#{select_tag(field, options_from_collection_for_select(col_right, right_id, right_name), multiple: true, class: 'multiple nostyle form-control sortableSelect fake', id: 'box2View' + html_id, disabled: !editable)}"
  html << "<div class='list-wrapper'><ul id='fake-select#{html_id}' class='ui-sortable fake-select'>"

  col_right.each do |elt|
    always_class = ""
    always_class = "always_#{elt.static_module.always_displayed}" if always
    lang_all_class = ""
    lang_all_class = "all_lang" if elt.lang_id.nil?

    html << "<li class='displayed_#{elt.displayed?} #{always_class} #{lang_all_class}' id='art#{html_id}_#{elt.send(right_id)}'>#{elt.send("#{right_name}".to_sym)}</li>"
  end

  html << "</ul><span id='box2Counter#{html_id}' class='count fake'></span>"
  html << "<div class='dn'><select id='box2Storage#{html_id}' class='nostyle fake' name='box2Storage'></select></div></div></div>"
end

#dual_select_right_box_search(html_id) ⇒ Object



99
100
101
102
103
104
# File 'app/helpers/mokio/backend/menu_helper.rb', line 99

def dual_select_right_box_search(html_id)
  "<div class='searchBox'>
    <input id='livefilter-input#{html_id}' class='searchField form-control fake' placeholder='filter ...' type='text'></input>
    <input id='box2Filter#{html_id}' class='searchField form-control fake' placeholder='filter ...' type='text'></input>
  </div>"
end

#dual_select_search_box(html_id) ⇒ Object



53
54
55
# File 'app/helpers/mokio/backend/menu_helper.rb', line 53

def dual_select_search_box(html_id)
  "<div class='searchBox'><input id='box1Filter#{html_id}' class='searchField form-control' placeholder='#{t("menus.filter")}' type='text'></input></div>"
end

def menu_select_grouped(obj)

obj.map do |pos, sub_pos|
  pos.name = ('- ' * pos.depth) + pos.name
  obj = menu_select_grouped(sub_pos) unless sub_pos.blank?
end
obj

end



205
206
207
208
209
210
211
212
213
# File 'app/helpers/mokio/backend/menu_helper.rb', line 205

def menu_select_grouped(obj)
  arr = []
  obj.map do |pos, sub_pos|
      pos.name =  ('- ' * pos.depth) + pos.name
      arr << pos
      arr += menu_select_grouped(sub_pos) unless sub_pos.blank?
    end
  arr
end

#replace_available_modules(menu) ⇒ Object

generates code that replaces available modules after lang change



184
185
186
187
188
189
190
191
192
193
194
# File 'app/helpers/mokio/backend/menu_helper.rb', line 184

def replace_available_modules(menu)
  str = ""
  ModulePosition.all.each do |mp|
    if !menu.available_modules_by_pos[mp.id].nil?
      str += "$('#box1View_" + mp.id.to_s + "').html('" +  ( j(options_for_select(menu.available_modules_by_pos[mp.id].collect{|elt| [elt.module_title, elt.id, {class: 'displayed_' + elt.displayed?.to_s}]}))) + "');"
    else
      str += "$('#box1View_" + mp.id.to_s + "').html('');"
    end
  end
  str.html_safe
end

#tree_menu(menus, sortable) ⇒ Object

dispays drag & drop tree for menus



21
22
23
24
25
26
27
# File 'app/helpers/mokio/backend/menu_helper.rb', line 21

def tree_menu(menus, sortable)
  menus.map do |menu, sub_menu|
       :li, :id => dom_id(menu), :class => "sortable_#{sortable}" do
        render(menu) + ((:ol, tree_menu(sub_menu, true)) if sub_menu.present?)
      end
  end.join.html_safe
end

#tree_menu_breadcrumbs(menu) ⇒ Object

displays breadcrumb to current menu element



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/mokio/backend/menu_helper.rb', line 7

def tree_menu_breadcrumbs(menu)
  unless menu.nil?
    @tree_nodes = menu.ancestors.to_a << menu
    @tree_nodes.map do |m|
      if m.present? and m != menu
        link_to(m.name, edit_menu_path(m)) + " -> "
      elsif m.present? and m == menu
        link_to(m.name, edit_menu_path(m)) unless m.id.nil?
      end
    end.join.html_safe
  end
end