pages_helper.rb
8.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
module Kanjai
module Admin::PagesHelper
def get_html_by_json(page_data, client_view = false)
json_data = page_data.template_content
html = ''
json_data.each do |row|
row['attributes'] ||= {}
class_name = 'row-fluid row'
class_name += ' row-element-block' if row['attributes']['type'] == 'block'
class_name += ' row-element-row' if row['attributes']['type'] == 'row'
html_attributes = {}
html_attributes[:class] = class_name
html_attributes['data-status'] = row['attributes']['status'].to_s == 'enabled' || row['attributes']['status'].to_s.empty? ? 'enabled' : 'disabled'
row_html = ''
if client_view == false and row['attributes']['type'] == 'block'
html_attributes['data-id'] = row['attributes']['id']
page_content = page_data.page_contents.where(:structure_id => row['attributes']['id']).first
row_html = '<div class="col-html">' + (page_content.nil? ? '' : page_content.get_content) + '</div>'
end
html += ActionController::Base.helpers.content_tag(:div, '', html_attributes) do
ActionController::Base.helpers.concat(row_html.html_safe)
row["cells"].each do |cell|
page_content = page_data.page_contents.where(:structure_id => cell['id']).first
html = page_content.nil? ? '' : page_content.get_content
cell_class_name = ''
ActionController::Base.helpers.concat(ActionController::Base.helpers.content_tag(:div, html.html_safe, :class => "col-md-#{cell['size']} col #{cell_class_name}", 'data-size' => cell['size'], 'data-offset' => cell['offset'], 'data-id' => cell['id'], 'data-page_data_id' => page_data.id , 'data-class' => cell['className'], 'data-status' => cell['status'].to_s == 'enabled' || cell['status'].to_s.empty? ? 'enabled' : 'disabled' ))
end
end
end
html
end
def get_html_by_json_client(page_data)
json_data = page_data.template_content
html = ''
#row_template = File.open("#{Rails.root}/app/view/kanjai/pages/templates/row.html.erb").read
#cell_template = File.open("#{Rails.root}/app/view/kanjai/pages/templates/cell.html.erb").read
json_data.each do |row|
row['attributes'] ||= {}
if row['attributes']['type'] == 'block'
if row['attributes']['status'].to_s == 'enabled' || row['attributes']['status'].to_s.empty?
#show direct content
structure_id = row['attributes']['id']
page_content = page_data.page_contents.where(:structure_id => structure_id).first
if page_content
html_attributes = {}
html_attributes[:class] = 'col'
html_attributes['data-id'] = row['attributes']['id']
html_attributes['data-page_data_id'] = page_data.id
if page_content.type_content.split('-').include?('wrapper')
html += (page_content.get_simple_content).html_safe
else
cells = page_content.nil? ? '' : page_content.get_content_frontend
data_attributes = [
"data-id=#{row['attributes']['id']}",
"data-page_data_id=#{page_data.id}"
]
html += ApplicationController.render(file: 'kanjai/pages/templates/block', assigns: {content: cells.html_safe, data_attributes: data_attributes.join(' ')}, layout: false).html_safe
#html += ActionController::Base.helpers.content_tag(:div, '', html_attributes) do
# ActionController::Base.helpers.concat((page_content.nil? ? '' : page_content.get_content_frontend).html_safe)
#end
end
end
end
else
=begin
class_name = 'row-fluid clearfix'
html_attributes = {}
html_attributes[:class] = class_name
html += ActionController::Base.helpers.content_tag(:div, '', html_attributes) do
cells = ''
row["cells"].each do |cell|
page_content = page_data.page_contents.where(:structure_id => cell['id']).first
html = page_content.nil? ? '' : page_content.get_content_frontend
cell_class_name = cell['className']
data_attributes = [
"data-size='#{cell['size']}'",
"data-offset='#{cell['offset']}'",
"data-id='#{cell['id']}'",
"data-page_data_id='#{page_data.id}'",
"data-class='#{cell['className']}'",
]
cells += ApplicationController.render assigns: {content: html.html_safe, cell: cell, class_name: cell_class_name, data_attributes: data_attributes.join(' ')}, inline: template
ActionController::Base.helpers.concat(ActionController::Base.helpers.content_tag(:div, html.html_safe, :class => "col-md-#{cell['size']} col #{cell_class_name}", 'data-size' => cell['size'], 'data-offset' => cell['offset'], 'data-id' => cell['id'], 'data-page_data_id' => page_data.id , 'data-class' => cell['className']))
end
end
=end
if row['attributes']['status'].to_s == 'enabled' || row['attributes']['status'].to_s.empty?
cells = ''
row["cells"].each do |cell|
if cell['status'].to_s == 'enabled' || cell['status'].to_s.empty?
page_content = page_data.page_contents.where(:structure_id => cell['id']).first
html_content = page_content.nil? ? '' : page_content.get_content_frontend
cell_class_name = cell['className']
data_attributes = [
"data-size=#{cell['size']}",
"data-offset=#{cell['offset']}",
"data-id=#{cell['id']}",
"data-page_data_id=#{page_data.id}",
"data-class=#{cell['className']}",
]
cells += ApplicationController.render file: 'kanjai/pages/templates/cell', assigns: {content: html_content.html_safe, cell: cell, class_name: cell_class_name, data_attributes: data_attributes.join(' ')}, layout: false
end
end
html += ApplicationController.render(file: 'kanjai/pages/templates/row', assigns: {content: cells.html_safe}, layout: false).html_safe
end
end
end
#html = '<div class="container">' + html.to_s + '</div>'
html.to_s
end
def get_html_by_json_client_url(url, locale)
page_data = PageDatum.where(:url => url, lang: locale).first
get_html_by_json_client(page_data)
end
def make_navigation(parent_id, level)
html = ''
if level > 0
html += ActionController::Base.helpers.content_tag(:ul, class: 'nav navbar-nav') do
Page.where(:parent_id => parent_id).order(:position).each do |page|
if page.children.count > 0
ActionController::Base.helpers.concat(
ActionController::Base.helpers.content_tag(:li) do
ActionController::Base.helpers.concat(
ActionController::Base.helpers.link_to (page.lang_attributes(PageLang.default(page.domain), :title) + '<span class="caret"></span>').html_safe, page.menu_url(session[:scheme], lang = nil), :class => 'dropdown-toggle', 'data-toggle' => "dropdown", 'role' => "button", 'aria-haspopup' => "true", 'aria-expanded' => "false"
)
ActionController::Base.helpers.concat(
ActionController::Base.helpers.content_tag(:ul) do
ActionController::Base.helpers.concat(make_navigation(page.id, level - 1))
end
)
end
)
else
ActionController::Base.helpers.concat(
ActionController::Base.helpers.content_tag(:li) do
ActionController::Base.helpers.concat(
ActionController::Base.helpers.link_to page.lang_attributes(PageLang.default(page.domain), :title), page.menu_url(session[:scheme], lang = nil)
)
end
)
end
end
end
end
html.html_safe
end
end
end