Change the parser_front_end to be used in the structure for page edit, new_ui:save_pages must be run

This commit is contained in:
chris 2013-10-20 18:44:04 +08:00
parent 1ea8d9faf9
commit 2530dace02
7 changed files with 79 additions and 28 deletions

View File

@ -5,7 +5,8 @@ class Admin::PagesController < Admin::ItemsController
def show
@item = Page.find(params[:id])
@no_orbit_bar = true
render layout: 'page_layout'
@edit = true
render :text => parse_page_content(@item), :layout => 'page_layout'
end
def new

View File

@ -26,7 +26,13 @@ class PagesController < ApplicationController
when 'Page'
if params[:clicked_field_name]
render_page({"clicked_field_name"=>params["clicked_field_name"]}) unless save_from_no_lang_for_page
elsif params[:edit]
if request.referer && request.referer.ends_with?("admin/items")
redirect_to admin_page_url(@item)
else
render :file => "#{Rails.root}/public/403.html", :status => 403
end
else
render_page(params.except(:controller, :action, :page_name)) unless save_from_no_lang_for_page
end
when 'Link'

View File

@ -17,7 +17,7 @@
<%= link_to node.title, node.url %>
<% end %>
<div class="item-menu">
<%= link_to content_tag(:i, nil, class: "icon-eye-open"), eval("admin_#{node.class.to_s.downcase}_path(node)"), class: "view-page open-slide tip", title: t(:view), data: {title: node.title} if node.class.to_s.eql?('Page') %>
<%= link_to content_tag(:i, nil, class: "icon-eye-open"), "/#{node.path}?edit=true", class: "view-page open-slide tip", title: t(:view), data: {title: node.title} if node.class.to_s.eql?('Page') %>
<%= link_to content_tag(:i, nil, class: "icon-edit"), eval("edit_admin_#{node.class.to_s.downcase}_path(node)"), class: "open-slide tip #{node.class.to_s.downcase} edit", title: t(:edit), data: {title: t(:edit)} %>
<%= link_to content_tag(:i, nil, class: "icons-newspaper"), new_admin_page_path(:parent_id => node.id), class: "open-slide tip page", title: t(:add_page), data: {title: t(:add_page)} if node.class.to_s.eql?('Page') %>
<%= link_to content_tag(:i, nil, class: "icon-link"), new_admin_link_path(:parent_id => node.id), class: "open-slide tip link", title: t(:add_link), data: {title: t(:add_link)} if node.class.to_s.eql?('Page') %>

View File

@ -26,5 +26,20 @@
$('#myModal').modal('show')
</script>
<% end -%>
<% if @edit %>
<script>
$(window).load(function(pageslide, item) {
$('a').not('.nav').on('click', function(e){
e.preventDefault();
});
$('a').not('.nav').css("cursor", "default");
});
</script>
<style>
.body {
margin: 0;
}
</style>
<% end %>
</body>
</html>

View File

@ -272,7 +272,7 @@ module ParserCommon
part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil
part_title = part.title rescue nil
if edit
ret << "<div id='#{content['name']}' part_id='#{part.id}' class='editable'>" if part
ret << "<div class='editable'>" if part
ret << "<div class='edit_link'>"
ret << " <a href='#{edit_admin_page_part_path(part.id)}' class='nav'>#{t(:edit)}</a>" if part
ret << '</div>'

View File

@ -25,6 +25,21 @@ module ParserFrontEnd
# category = params[:category_id].blank? ? page[:category] : params[:category_id]
body = Nokogiri::HTML(page.content)
if @edit
body.css('.page_part').each do |page_part|
ret = ''
ret << "<div class='editable'>"
ret << "<div class='edit_link'>"
ret << "<a href='#{edit_admin_page_part_path(page_part['part_id'])}' class='nav'>#{t(:edit)}</a>"
ret << '</div>'
ret << page_part.child.to_html rescue nil
ret << '</div>'
fragment = Nokogiri::HTML::DocumentFragment.new(body, ret)
page_part.swap(fragment)
end
end
body.css('orbit_front').each do |front|
if front['value']
fragment = Nokogiri::HTML::DocumentFragment.new(body, "<div id='#{front['id']}' class='#{front['class']}'>#{eval(front['value']).to_s}</div>")
@ -43,6 +58,7 @@ module ParserFrontEnd
end
front.swap(fragment)
end
body.to_html
end
@ -139,34 +155,38 @@ module ParserFrontEnd
ret << "<orbit_front path='#{url + options}'></div>"
else
part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil
case part.kind
when 'text'
ret << part.content_translations[locale.to_s] rescue ''
when 'module_widget'
# url = "/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true"
# options = "&part_id=\#{part.id}&category_id=\#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=\#{!part[:tag].blank? ? part[:tag] : tag}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}"
# ret << "<orbit_front path='#{url + options}' part_id=#{part.id}></div>"
url = case part.widget_path
when 'default_widget'
"/panel/orbit_app/widget/\#{part.widget_style}?inner=true"
else
"/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true"
end
if part
ret << "<div class='page_part' part_id='#{part.id}'>"
case part.kind
when 'text'
ret << part.content_translations[locale.to_s] rescue ''
when 'module_widget'
# url = "/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true"
# options = "&part_id=\#{part.id}&category_id=\#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=\#{!part[:tag].blank? ? part[:tag] : tag}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}"
# ret << "<orbit_front path='#{url + options}' part_id=#{part.id}></div>"
url = case part.widget_path
when 'default_widget'
"/panel/orbit_app/widget/\#{part.widget_style}?inner=true"
else
"/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true"
end
categories_str=part[:category].collect{|t| "base_category_id[]=#{t}"}.join('&')
tags_str=part[:tag].collect{|t| "base_tag_id[]=#{t}"}.join('&')
categories_str = "&#{categories_str}" unless categories_str.blank?
tags_str = "&#{tags_str}" unless tags_str.blank?
categories_str=part[:category].collect{|t| "base_category_id[]=#{t}"}.join('&')
tags_str=part[:tag].collect{|t| "base_tag_id[]=#{t}"}.join('&')
categories_str = "&#{categories_str}" unless categories_str.blank?
tags_str = "&#{tags_str}" unless tags_str.blank?
options = "&part_id=\#{part.id}#{categories_str}#{tags_str}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&clicked_field_name=\#{params[:clicked_field_name]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}&item_type=page_part&tag_id=\#{params[:tag_id]}&category_id=\#{params[:category_id]}"
options = "&part_id=\#{part.id}#{categories_str}#{tags_str}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&clicked_field_name=\#{params[:clicked_field_name]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}&item_type=page_part&tag_id=\#{params[:tag_id]}&category_id=\#{params[:category_id]}"
ret << "<orbit_front path='#{url + options}' part_id=#{part.id} class='dymanic_load widget'></orbit_front>"
when 'public_r_tag'
ret << send("generate_#{part.public_r_tag}s", part.public_r_tag_object_id, page)
else
''
end if part
ret << "<orbit_front path='#{url + options}' part_id=#{part.id} class='dymanic_load widget'></orbit_front>"
when 'public_r_tag'
ret << send("generate_#{part.public_r_tag}s", part.public_r_tag_object_id, page)
else
''
end
ret << "</div>"
end
end
scope = "<#{content.name}"
content.attributes.each_pair do |key, value|

View File

@ -24,6 +24,7 @@ namespace :new_ui do
migrate_approval_on_object
migrate_managers
migrate_ad_images_dates
migrate_ad_banners
end
# :category_name is optional, depends on the naming of the category model: if no conventional, specify it
@ -47,6 +48,10 @@ namespace :new_ui do
migrate_ad_banners
end
task :save_pages => :environment do
save_pages
end
def migrate_categories(args = nil)
if args && args[:app_key] && args[:model_name]
migrate_category(args[:app_key], args[:model_name], args[:category_name])
@ -232,4 +237,8 @@ namespace :new_ui do
end
end
def save_pages
Page.all(&:save)
end
end