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 def show
@item = Page.find(params[:id]) @item = Page.find(params[:id])
@no_orbit_bar = true @no_orbit_bar = true
render layout: 'page_layout' @edit = true
render :text => parse_page_content(@item), :layout => 'page_layout'
end end
def new def new

View File

@ -26,6 +26,12 @@ class PagesController < ApplicationController
when 'Page' when 'Page'
if params[:clicked_field_name] if params[:clicked_field_name]
render_page({"clicked_field_name"=>params["clicked_field_name"]}) unless save_from_no_lang_for_page 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 else
render_page(params.except(:controller, :action, :page_name)) unless save_from_no_lang_for_page render_page(params.except(:controller, :action, :page_name)) unless save_from_no_lang_for_page
end end

View File

@ -17,7 +17,7 @@
<%= link_to node.title, node.url %> <%= link_to node.title, node.url %>
<% end %> <% end %>
<div class="item-menu"> <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: "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: "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') %> <%= 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') $('#myModal').modal('show')
</script> </script>
<% end -%> <% 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> </body>
</html> </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 = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil
part_title = part.title rescue nil part_title = part.title rescue nil
if edit 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 << "<div class='edit_link'>"
ret << " <a href='#{edit_admin_page_part_path(part.id)}' class='nav'>#{t(:edit)}</a>" if part ret << " <a href='#{edit_admin_page_part_path(part.id)}' class='nav'>#{t(:edit)}</a>" if part
ret << '</div>' ret << '</div>'

View File

@ -25,6 +25,21 @@ module ParserFrontEnd
# category = params[:category_id].blank? ? page[:category] : params[:category_id] # category = params[:category_id].blank? ? page[:category] : params[:category_id]
body = Nokogiri::HTML(page.content) 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| body.css('orbit_front').each do |front|
if front['value'] if front['value']
fragment = Nokogiri::HTML::DocumentFragment.new(body, "<div id='#{front['id']}' class='#{front['class']}'>#{eval(front['value']).to_s}</div>") 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 end
front.swap(fragment) front.swap(fragment)
end end
body.to_html body.to_html
end end
@ -139,6 +155,8 @@ module ParserFrontEnd
ret << "<orbit_front path='#{url + options}'></div>" ret << "<orbit_front path='#{url + options}'></div>"
else else
part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil
if part
ret << "<div class='page_part' part_id='#{part.id}'>"
case part.kind case part.kind
when 'text' when 'text'
ret << part.content_translations[locale.to_s] rescue '' ret << part.content_translations[locale.to_s] rescue ''
@ -166,7 +184,9 @@ module ParserFrontEnd
ret << send("generate_#{part.public_r_tag}s", part.public_r_tag_object_id, page) ret << send("generate_#{part.public_r_tag}s", part.public_r_tag_object_id, page)
else else
'' ''
end if part end
ret << "</div>"
end
end end
scope = "<#{content.name}" scope = "<#{content.name}"
content.attributes.each_pair do |key, value| content.attributes.each_pair do |key, value|

View File

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