forked from saurabh/orbit4-5
now page view shows realtime page...and allows you to edit it
This commit is contained in:
parent
c37976c62e
commit
98efc38566
|
@ -1,50 +1,5 @@
|
|||
(function(){
|
||||
var getUrlVars = function(){
|
||||
var vars = [], hash;
|
||||
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
|
||||
for(var i = 0; i < hashes.length; i++){
|
||||
hash = hashes[i].split('=');
|
||||
vars.push(decodeURIComponent(hash[0]));
|
||||
vars[decodeURIComponent(hash[0])] = decodeURIComponent(hash[1]);
|
||||
}
|
||||
if(vars[0] == window.location.href){
|
||||
vars =[];
|
||||
}
|
||||
return vars;
|
||||
}
|
||||
var page_params = getUrlVars();
|
||||
$(document).ready(function(){
|
||||
$("head").append("<link href='/assets/pp-add-edit.css?body=1' media='screen' rel='stylesheet' /> ");
|
||||
var dataObject = (page_params['mobile_view'] ? {"page_id" : page_params["id"],"mobile_view" : 1} : {"page_id" : page_params["id"]})
|
||||
$.ajax({
|
||||
url : "/page_parts/info",
|
||||
dataType : "json",
|
||||
type : "get",
|
||||
data : dataObject
|
||||
}).done(function(data){
|
||||
$.each(data.parts,function(i,part){
|
||||
var page_part = $("*[" + part.name + "]");
|
||||
$.each(part.subparts,function(x,subpart){
|
||||
var newsub = (subpart.kind == "module_widget" ? $("<div data-partid='" + part.id + "' data-ps='" + subpart.id + "'>" + subpart.module + "/" + subpart.widget + "</div>") : $("<div data-partid='" + part.id + "' data-ps='" + subpart.id + "'>Text</div>"));
|
||||
page_part.prepend(newsub);
|
||||
newsub.click(function(){
|
||||
window.location.href = "/page_parts/edit_sub_part?page_id=" + page_params["id"] + "&part_id=" + $(this).data("partid") + "&sub_part_id=" + $(this).data("ps")+(page_params["mobile_view"] ? "&mobile_view=1": "");
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
$("*[data-pp]").each(function(){
|
||||
var add_btn = $("<p class='add-ps'></p>"),
|
||||
part = $(this);
|
||||
add_btn.click(function(){
|
||||
if(part.find("*[data-ps]").length){
|
||||
window.location.href = "/page_parts/" + part.data("pp") + "/edit?page_id=" + page_params["id"]+(page_params["mobile_view"] ? "&mobile_view=1": "");
|
||||
}else{
|
||||
window.location.href = "/page_parts/new?part=" + part.data("pp") + "&page_id=" + page_params["id"]+(page_params["mobile_view"] ? "&mobile_view=1": "");
|
||||
}
|
||||
})
|
||||
part.append(add_btn);
|
||||
})
|
||||
})
|
||||
})();
|
|
@ -8,63 +8,84 @@
|
|||
margin: 0 auto;
|
||||
position: relative;
|
||||
}
|
||||
*[data-pp] > *[data-ps] {
|
||||
padding: 3px;
|
||||
height: 50px;
|
||||
outline: thin dotted #EBB666;
|
||||
cursor: pointer;
|
||||
*[data-pp] > .editmode-ps {
|
||||
position: relative;
|
||||
min-height: 150px;
|
||||
outline: 2px dotted #EBB666;
|
||||
cursor: pointer;
|
||||
}
|
||||
*[data-pp] > *[data-ps]:before {
|
||||
content: "";
|
||||
line-height: 100%;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
background-color: #a1a1a1;
|
||||
opacity: 0.6;
|
||||
filter: alpha(opacity=60);
|
||||
}
|
||||
*[data-pp] > *[data-ps]:after {
|
||||
font-size: 1rem;
|
||||
font-weight: 300;
|
||||
content: "Edit";
|
||||
text-align: center;
|
||||
margin-top: -0.7rem;
|
||||
*[data-pp] > .editmode-ps:before {
|
||||
content: attr(title);
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: 0;
|
||||
left: 0;
|
||||
}
|
||||
*[data-pp] > *[data-ps]:hover:before {
|
||||
opacity: 0.8;
|
||||
filter: alpha(opacity=80);
|
||||
}
|
||||
*[data-pp] > *[data-ps]:hover:after {
|
||||
font-weight: 400;
|
||||
}
|
||||
*[data-pp] > .add-ps {
|
||||
text-align: center;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
min-height: 2rem;
|
||||
line-height: 2rem;
|
||||
cursor: pointer;
|
||||
color: #47bab5;
|
||||
margin-top: 10px;
|
||||
text-align: center;
|
||||
font-size: 1.3em;
|
||||
z-index: 778;
|
||||
}
|
||||
*[data-pp] > .add-ps:after {
|
||||
font-size: 1rem;
|
||||
font-weight: 300;
|
||||
content: "Add";
|
||||
*[data-pp] > .editmode-ps > a {
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
background-color: #e0dbcb;
|
||||
background-color: rgba(255, 255, 255, .5);
|
||||
z-index: 777;
|
||||
}
|
||||
*[data-pp] > .add-ps:hover:after {
|
||||
font-weight: 400;
|
||||
background-color: #923132;
|
||||
*[data-pp] > .editmode-ps > a:before {
|
||||
content: "\f044";
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
font-size: 3.4em;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
margin: -30px 0 0 -20px;
|
||||
display: inline-block;
|
||||
font-family: FontAwesome;
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
line-height: 1;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
*[data-pp] > .editmode-ps:hover:before {
|
||||
color: #FFF;
|
||||
}
|
||||
*[data-pp] > .editmode-ps:hover > a {
|
||||
color: #FFF;
|
||||
background-color: rgba(17, 117, 184, .8);
|
||||
}
|
||||
*[data-pp] > a {
|
||||
position: relative;
|
||||
display: block;
|
||||
height: 40px;
|
||||
margin: 10px 0;
|
||||
border-radius: 5px;
|
||||
color: #8DE2FD;
|
||||
background-color: #14A1AD;
|
||||
}
|
||||
*[data-pp] > a:before {
|
||||
content: "\f055";
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
font-size: 1.5em;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
margin: -10px 0 0 -10px;
|
||||
display: inline-block;
|
||||
font-family: FontAwesome;
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
line-height: 1;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
*[data-pp] > a:hover {
|
||||
color: #FFF;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ class PagesController < ApplicationController
|
|||
include PagesHelper
|
||||
before_filter :check_frontend_open, :only => [:home,:show]
|
||||
before_filter :check_authorization, :except => [:home,:show]
|
||||
before_filter :set_edit_mode
|
||||
|
||||
def index
|
||||
@pages = Page.all
|
||||
|
@ -17,8 +18,6 @@ class PagesController < ApplicationController
|
|||
def edit_view
|
||||
@manifest = @key
|
||||
@dataApi = "edit"
|
||||
|
||||
# @qq = render_to_string(:partial => @p, :layout => false)
|
||||
view = get_view
|
||||
if File.exists?(view)
|
||||
render view
|
||||
|
@ -27,7 +26,6 @@ class PagesController < ApplicationController
|
|||
|
||||
def home
|
||||
@manifest = @key
|
||||
@dataApi = nil
|
||||
page = Page.first
|
||||
impressionist(page)
|
||||
OrbitHelper.set_params params
|
||||
|
@ -74,7 +72,6 @@ class PagesController < ApplicationController
|
|||
params[:url] = page.url
|
||||
|
||||
@manifest = @key
|
||||
@dataApi = nil
|
||||
OrbitHelper.set_params params
|
||||
OrbitHelper.set_site_locale locale
|
||||
OrbitHelper.set_this_module_app module_app.singularize
|
||||
|
@ -267,10 +264,18 @@ class PagesController < ApplicationController
|
|||
custom_value = subpart.custom_string_field || subpart.custom_array_field rescue nil
|
||||
if !custom_value.nil?
|
||||
OrbitHelper.set_widget_custom_value custom_value
|
||||
end
|
||||
partials << render_widget_for_frontend(subpart.module,subpart.widget_method,subpart.widget_type)
|
||||
end
|
||||
if @editmode
|
||||
partials << "<div class='editmode-ps' title='#{subpart.module}'> " + render_widget_for_frontend(subpart.module,subpart.widget_method,subpart.widget_type) + "<a href='/page_parts/edit_sub_part?page_id=#{page.id.to_s}&part_id=#{part.id.to_s}&sub_part_id=#{subpart.id.to_s}#{(params[:mobile_view] ? '&mobile_view=1' : '')}'> </a></div>"
|
||||
else
|
||||
partials << render_widget_for_frontend(subpart.module,subpart.widget_method,subpart.widget_type)
|
||||
end
|
||||
elsif subpart.kind == "text"
|
||||
partials << subpart.content
|
||||
if @editmode
|
||||
partials << "<div class='editmode-ps' title='text'> " + subpart.content + "<a href='/page_parts/edit_sub_part?page_id=#{part.page_id.to_s}&part_id=#{part.id.to_s}&sub_part_id=#{subpart.id.to_s}#{(params[:mobile_view] ? '&mobile_view=1' : '')}'> </a></div>"
|
||||
else
|
||||
partials << subpart.content
|
||||
end
|
||||
end
|
||||
end
|
||||
@part_partials["data-pp='#{part.part_id}'"] = partials
|
||||
|
@ -298,6 +303,19 @@ class PagesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
if @editmode
|
||||
pps = doc.css("*[data-pp]")
|
||||
pps.each do |pp|
|
||||
number = pp.attributes["data-pp"].value
|
||||
if pp.inner_html == ""
|
||||
pp.inner_html = "<a href='/page_parts/new?part=#{number}&page_id=#{page.id.to_s}'> </a>"
|
||||
else
|
||||
inner_html = pp.inner_html
|
||||
pp.inner_html = inner_html + "<a href='/page_parts/#{number}/edit?page_id=#{page.id.to_s}'> </a>"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if original_view != "home"
|
||||
viewarea = doc.css("*[data-content='true']")[0]
|
||||
viewarea.inner_html = render_to_string(original_view) rescue "<div></div>"
|
||||
|
@ -385,6 +403,21 @@ class PagesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def set_edit_mode
|
||||
if !current_user.nil? and current_user.is_admin?
|
||||
if params[:editmode] == "on"
|
||||
@editmode = true
|
||||
@dataApi = "edit"
|
||||
else
|
||||
@dataApi = nil
|
||||
@editmode = false
|
||||
end
|
||||
else
|
||||
@dataApi = nil
|
||||
@editmode = false
|
||||
end
|
||||
end
|
||||
|
||||
def change_to_language(final_html)
|
||||
if session[:zh_cn]
|
||||
final_html = ZhConv.convert("zh-cn", final_html)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<%= link_to node.name, node.external_url %>
|
||||
<% end %>
|
||||
<div class="item-menu">
|
||||
<%= link_to content_tag(:i, nil, class: "icon-eye-open"), pages_edit_view_path(:id => node.id.to_s), class: "view-page open-slide tip", title: "View", data: {title: node.name} if node.page_type.eql?('page') %>
|
||||
<%= link_to content_tag(:i, nil, class: "icon-eye-open"), (node.root? ? "/?editmode=on" : "/" + I18n.locale.to_s + node.url + "?editmode=on"), class: "view-page open-slide tip", title: "View", data: {title: node.name} if node.page_type.eql?('page') %>
|
||||
<%= link_to content_tag(:i, nil, class: "icons-mobile"), pages_edit_view_path(:id => node.id.to_s, :mobile_view=>1), class: "view-page open-slide tip mobile-view-btn", title: "Edit Mobile Page", data: {title: "Edit Mobile Page"} if node.page_type.eql?("page") && current_site.mobile_on && node.enabled_for_mobile %>
|
||||
<% unless name.eql? "sitemap" %>
|
||||
<%= link_to content_tag(:i, nil, class: "icon-edit"), edit_page_path(node.id,:type => node.page_type), class: "open-slide tip page edit", title: "Edit #{node.page_type.capitalize}", data: {title: "Edit #{node.page_type.capitalize}"} if node.class.to_s.downcase.eql?("page") && !node.root? %>
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
}
|
||||
})
|
||||
$("form").on("ajax:success",function(){
|
||||
window.location.href = "/pages/edit_view?id=<%= params[:page_id] %><%= OrbitHelper.is_mobile_view ? '&mobile_view=1'.html_safe : '' %>";
|
||||
var url = "/<%= I18n.locale.to_s %><%= Page.find(params[:page_id]).url %>?editmode=on<%= OrbitHelper.is_mobile_view ? '&mobile_view=1'.html_safe : '' %>";
|
||||
window.location.href = url;
|
||||
})
|
||||
</script>
|
|
@ -26,6 +26,7 @@
|
|||
}
|
||||
})
|
||||
$("form").on("ajax:success",function(){
|
||||
window.location.href = "/pages/edit_view?id=<%= params[:page_id] %><%= OrbitHelper.is_mobile_view ? '&mobile_view=1'.html_safe : '' %>";
|
||||
var url = "/<%= I18n.locale.to_s %><%= Page.find(params[:page_id]).url %>?editmode=on<%= OrbitHelper.is_mobile_view ? '&mobile_view=1'.html_safe : '' %>";
|
||||
window.location.href = url;
|
||||
})
|
||||
</script>
|
|
@ -26,6 +26,7 @@
|
|||
}
|
||||
})
|
||||
$("form").on("ajax:success",function(){
|
||||
window.location.href = "/pages/edit_view?id=<%= params[:page_id] %><%= OrbitHelper.is_mobile_view ? '&mobile_view=1'.html_safe : '' %>";
|
||||
var url = "/<%= I18n.locale.to_s %><%= Page.find(params[:page_id]).url %>?editmode=on<%= OrbitHelper.is_mobile_view ? '&mobile_view=1'.html_safe : '' %>";
|
||||
window.location.href = url;
|
||||
})
|
||||
</script>
|
Loading…
Reference in New Issue