Compare commits

...

1 Commits

24 changed files with 2033 additions and 121 deletions

View File

@ -47,6 +47,8 @@ group :development do
gem 'rb-fchange', :require=>false
gem 'rb-fsevent', :require=>false
gem 'rb-inotify', :require=>false
gem 'debugger', '>= 1.6.6', group: [:development, :test]
gem "binding_of_caller"
end
#testing gems
@ -55,4 +57,3 @@ group :test do
gem 'minitest-spec-rails'
end
gem 'debugger', '>= 1.6.6', group: [:development, :test]

Binary file not shown.

After

Width:  |  Height:  |  Size: 646 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 872 B

File diff suppressed because it is too large Load Diff

View File

@ -2,26 +2,122 @@ var Items = function(){
var i = this;
this.initialize = function(){
i.bindHandlers();
i.itemQuantity();
i.bindEditAddPageHandlers();
}
this.bindHandlers = function(){
var $openSlide = $('.open-slide'),
$pageslideW;
$(window).width() > 1440 ? $pageslideW = 1024 : $pageslideW = 954;
$(window).resize(function() {
$pageslideW = $(window).width() > 1440 ? 1024 : 954;
$(window).resize(function() {
$(this).width() > 1440 ? $pageslideW = 1024 : $pageslideW = 954;
});
$iFrame = $openSlide.filter('.view-page.open-slide');
$iFrame.pageslide({
W: $pageslideW,
iframe: true
});
});
$('.sortable').nestedSortable({
handle: '.brand',
items: 'li',
maxLevels: 3,
opacity: .6,
disableNesting: 'no-nest',
toleranceElement: '> div',
placeholder: 'placeholder',
startCollapsed: true,
update: function(event, ui) {
var parent = (ui.item.parent().closest('li').length ? ui.item.parent().closest('li') : ui.item.parent().closest('ol')),
children = (parent.hasClass("root") ? parent.find(">li") : parent.find(">ol li")),
children_ids = [];
children.each(function(){
children_ids.push($(this).attr("id"));
})
$.ajax({
url : "<%= Rails.application.routes.url_helpers.pages_update_item_position_path %>",
data : {"parent_id" : parent.attr("id"), "id" : ui.item.attr("id"),"children_ids" : children_ids},
dataType : "json",
type : "post"
})
}
});
}
this.itemQuantity = function(){
var $sortable = $('.sortable'),
$host = $sortable.children('.navbar').eq(0),
$navbar = $('.sortable li').children('.navbar'),
$quantity = $sortable.find('li').length;
$host.find('.badge').text($quantity);
$navbar.each(function(i) {
if($navbar.eq(i).next('ol').length>0) {
var $amount = $navbar.eq(i).next('ol').find('li').length;
$navbar.eq(i).find('.badge').text($amount);
}else{
$navbar.eq(i).find('.badge').text('0');
}
$navbar.eq(i).find('.badge').text()>0 ? $navbar.eq(i).find('.badge').addClass('badge-info'):$navbar.eq(i).find('.badge').removeClass('badge-info');
})
}
this.reBindHandlers = function(){
$.pageslide.close();
window.openSlide();
i.bindHandlers();
}
this.bindEditAddPageHandlers = function(){
var sidePanel = $(".view-page .content");
sidePanel.on("click","#categories_list input[type=checkbox]",function(){
if($(this).is(":checked") && $(this).hasClass("checkbox-all")){
$(".view-page .content #categories_list input[type=checkbox]").not($(this)).removeAttr("checked");
}else{
$(".view-page .content #categories_list input[type=checkbox].checkbox-all").removeAttr("checked");
}
})
sidePanel.on("click","#enable-menu .main-enable-parent",function(e){
if(!$(this).is(":checked")){
$(this).parent().parent().find(".main-enable-child").removeAttr("checked");
}
})
sidePanel.on("click","#enable-menu .main-enable-child",function(e){
if(!$("input[for=checkbox_for_"+ $(this).val() +"]").is(":checked")){
$(this).removeAttr("checked");
}
})
sidePanel.on("change","select.module_select", function(){
var this_value = $(this).val(),
categories_list = $("#categories_list");
categories_list.html("");
if(this_value){
$.ajax({
url : "<%= Rails.application.routes.url_helpers.pages_get_categories_path %>",
data : {"module" : this_value},
type : "get",
dataType : "json"
}).done(function(categories){
var controlDiv = $("<div class='controls'></div>");
if(categories.categories.length){
categories_list.parent().find("label.control-label").prepend("Category List :");
var checkbox = $("<label class='checkbox'><input type='checkbox' value='all' name='page[categories][]' class='checkbox-all' /> All </label>");
controlDiv.append(checkbox);
}
$.each(categories.categories,function(i,category){
var checkbox = $("<label class='checkbox'><input type='checkbox' value='"+ category.id +"' name='page[categories][]' /> " + category.title + " </label>");
controlDiv.append(checkbox);
})
categories_list.append(controlDiv);
})
}
})
}
i.initialize();
}

View File

@ -0,0 +1,430 @@
/* @group Base */
.chosen-container {
position: relative;
display: inline-block;
vertical-align: middle;
font-size: 13px;
zoom: 1;
*display: inline;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
.chosen-container .chosen-drop {
position: absolute;
top: 100%;
left: -9999px;
z-index: 1010;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
width: 100%;
border: 1px solid #aaa;
border-top: 0;
background: #fff;
box-shadow: 0 4px 5px rgba(0, 0, 0, 0.15);
}
.chosen-container.chosen-with-drop .chosen-drop {
left: 0;
}
.chosen-container a {
cursor: pointer;
}
/* @end */
/* @group Single Chosen */
.chosen-container-single .chosen-single {
position: relative;
display: block;
overflow: hidden;
padding: 0 0 0 8px;
height: 23px;
border: 1px solid #aaa;
border-radius: 5px;
background-color: #fff;
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #ffffff), color-stop(50%, #f6f6f6), color-stop(52%, #eeeeee), color-stop(100%, #f4f4f4));
background: -webkit-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
background: -moz-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
background: -o-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
background: linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
background-clip: padding-box;
box-shadow: 0 0 3px white inset, 0 1px 1px rgba(0, 0, 0, 0.1);
color: #444;
text-decoration: none;
white-space: nowrap;
line-height: 24px;
}
.chosen-container-single .chosen-default {
color: #999;
}
.chosen-container-single .chosen-single span {
display: block;
overflow: hidden;
margin-right: 26px;
text-overflow: ellipsis;
white-space: nowrap;
}
.chosen-container-single .chosen-single-with-deselect span {
margin-right: 38px;
}
.chosen-container-single .chosen-single abbr {
position: absolute;
top: 6px;
right: 26px;
display: block;
width: 12px;
height: 12px;
background: url("<%= asset_path 'chosen/chosen-sprite.png' %>") -42px 1px no-repeat;
font-size: 1px;
}
.chosen-container-single .chosen-single abbr:hover {
background-position: -42px -10px;
}
.chosen-container-single.chosen-disabled .chosen-single abbr:hover {
background-position: -42px -10px;
}
.chosen-container-single .chosen-single div {
position: absolute;
top: 0;
right: 0;
display: block;
width: 18px;
height: 100%;
}
.chosen-container-single .chosen-single div b {
display: block;
width: 100%;
height: 100%;
background: url("<%= asset_path 'chosen/chosen-sprite.png' %>") no-repeat 0px 2px;
}
.chosen-container-single .chosen-search {
position: relative;
z-index: 1010;
margin: 0;
padding: 3px 4px;
white-space: nowrap;
}
.chosen-container-single .chosen-search input[type="text"] {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 1px 0;
padding: 4px 20px 4px 5px;
width: 100%;
height: auto;
outline: 0;
border: 1px solid #aaa;
background: white url("<%= asset_path 'chosen/chosen-sprite.png' %>") no-repeat 100% -20px;
background: url("<%= asset_path 'chosen/chosen-sprite.png' %>") no-repeat 100% -20px, -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff));
background: url("<%= asset_path 'chosen/chosen-sprite.png' %>") no-repeat 100% -20px, -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%);
background: url("<%= asset_path 'chosen/chosen-sprite.png' %>") no-repeat 100% -20px, -moz-linear-gradient(#eeeeee 1%, #ffffff 15%);
background: url("<%= asset_path 'chosen/chosen-sprite.png' %>") no-repeat 100% -20px, -o-linear-gradient(#eeeeee 1%, #ffffff 15%);
background: url("<%= asset_path 'chosen/chosen-sprite.png' %>") no-repeat 100% -20px, linear-gradient(#eeeeee 1%, #ffffff 15%);
font-size: 1em;
font-family: sans-serif;
line-height: normal;
border-radius: 0;
}
.chosen-container-single .chosen-drop {
margin-top: -1px;
border-radius: 0 0 4px 4px;
background-clip: padding-box;
}
.chosen-container-single.chosen-container-single-nosearch .chosen-search {
position: absolute;
left: -9999px;
}
/* @end */
/* @group Results */
.chosen-container .chosen-results {
position: relative;
overflow-x: hidden;
overflow-y: auto;
margin: 0 4px 4px 0;
padding: 0 0 0 4px;
max-height: 240px;
-webkit-overflow-scrolling: touch;
}
.chosen-container .chosen-results li {
display: none;
margin: 0;
padding: 5px 6px;
list-style: none;
line-height: 15px;
}
.chosen-container .chosen-results li.active-result {
display: list-item;
cursor: pointer;
}
.chosen-container .chosen-results li.disabled-result {
display: list-item;
color: #ccc;
cursor: default;
}
.chosen-container .chosen-results li.highlighted {
background-color: #3875d7;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #3875d7), color-stop(90%, #2a62bc));
background-image: -webkit-linear-gradient(#3875d7 20%, #2a62bc 90%);
background-image: -moz-linear-gradient(#3875d7 20%, #2a62bc 90%);
background-image: -o-linear-gradient(#3875d7 20%, #2a62bc 90%);
background-image: linear-gradient(#3875d7 20%, #2a62bc 90%);
color: #fff;
}
.chosen-container .chosen-results li.no-results {
display: list-item;
background: #f4f4f4;
}
.chosen-container .chosen-results li.group-result {
display: list-item;
font-weight: bold;
cursor: default;
}
.chosen-container .chosen-results li.group-option {
padding-left: 15px;
}
.chosen-container .chosen-results li em {
font-style: normal;
text-decoration: underline;
}
/* @end */
/* @group Multi Chosen */
.chosen-container-multi .chosen-choices {
position: relative;
overflow: hidden;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
width: 100%;
height: auto !important;
height: 1%;
border: 1px solid #aaa;
background-color: #fff;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff));
background-image: -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%);
background-image: -moz-linear-gradient(#eeeeee 1%, #ffffff 15%);
background-image: -o-linear-gradient(#eeeeee 1%, #ffffff 15%);
background-image: linear-gradient(#eeeeee 1%, #ffffff 15%);
cursor: text;
}
.chosen-container-multi .chosen-choices li {
float: left;
list-style: none;
}
.chosen-container-multi .chosen-choices li.search-field {
margin: 0;
padding: 0;
white-space: nowrap;
}
.chosen-container-multi .chosen-choices li.search-field input[type="text"] {
margin: 1px 0;
padding: 5px;
height: 15px;
outline: 0;
border: 0 !important;
background: transparent !important;
box-shadow: none;
color: #666;
font-size: 100%;
font-family: sans-serif;
line-height: normal;
border-radius: 0;
}
.chosen-container-multi .chosen-choices li.search-field .default {
color: #999;
}
.chosen-container-multi .chosen-choices li.search-choice {
position: relative;
margin: 3px 0 3px 5px;
padding: 3px 20px 3px 5px;
border: 1px solid #aaa;
border-radius: 3px;
background-color: #e4e4e4;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eeeeee));
background-image: -webkit-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
background-image: -moz-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
background-image: -o-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
background-image: linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
background-clip: padding-box;
box-shadow: 0 0 2px white inset, 0 1px 0 rgba(0, 0, 0, 0.05);
color: #333;
line-height: 13px;
cursor: default;
}
.chosen-container-multi .chosen-choices li.search-choice .search-choice-close {
position: absolute;
top: 4px;
right: 3px;
display: block;
width: 12px;
height: 12px;
background: url("<%= asset_path 'chosen/chosen-sprite.png' %>") -42px 1px no-repeat;
font-size: 1px;
}
.chosen-container-multi .chosen-choices li.search-choice .search-choice-close:hover {
background-position: -42px -10px;
}
.chosen-container-multi .chosen-choices li.search-choice-disabled {
padding-right: 5px;
border: 1px solid #ccc;
background-color: #e4e4e4;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eeeeee));
background-image: -webkit-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
background-image: -moz-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
background-image: -o-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
background-image: linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
color: #666;
}
.chosen-container-multi .chosen-choices li.search-choice-focus {
background: #d4d4d4;
}
.chosen-container-multi .chosen-choices li.search-choice-focus .search-choice-close {
background-position: -42px -10px;
}
.chosen-container-multi .chosen-results {
margin: 0;
padding: 0;
}
.chosen-container-multi .chosen-drop .result-selected {
display: list-item;
color: #ccc;
cursor: default;
}
/* @end */
/* @group Active */
.chosen-container-active .chosen-single {
border: 1px solid #5897fb;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
.chosen-container-active.chosen-with-drop .chosen-single {
border: 1px solid #aaa;
-moz-border-radius-bottomright: 0;
border-bottom-right-radius: 0;
-moz-border-radius-bottomleft: 0;
border-bottom-left-radius: 0;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #eeeeee), color-stop(80%, #ffffff));
background-image: -webkit-linear-gradient(#eeeeee 20%, #ffffff 80%);
background-image: -moz-linear-gradient(#eeeeee 20%, #ffffff 80%);
background-image: -o-linear-gradient(#eeeeee 20%, #ffffff 80%);
background-image: linear-gradient(#eeeeee 20%, #ffffff 80%);
box-shadow: 0 1px 0 #fff inset;
}
.chosen-container-active.chosen-with-drop .chosen-single div {
border-left: none;
background: transparent;
}
.chosen-container-active.chosen-with-drop .chosen-single div b {
background-position: -18px 2px;
}
.chosen-container-active .chosen-choices {
border: 1px solid #5897fb;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
.chosen-container-active .chosen-choices li.search-field input[type="text"] {
color: #111 !important;
}
/* @end */
/* @group Disabled Support */
.chosen-disabled {
opacity: 0.5 !important;
cursor: default;
}
.chosen-disabled .chosen-single {
cursor: default;
}
.chosen-disabled .chosen-choices .search-choice .search-choice-close {
cursor: default;
}
/* @end */
/* @group Right to Left */
.chosen-rtl {
text-align: right;
}
.chosen-rtl .chosen-single {
overflow: visible;
padding: 0 8px 0 0;
}
.chosen-rtl .chosen-single span {
margin-right: 0;
margin-left: 26px;
direction: rtl;
}
.chosen-rtl .chosen-single-with-deselect span {
margin-left: 38px;
}
.chosen-rtl .chosen-single div {
right: auto;
left: 3px;
}
.chosen-rtl .chosen-single abbr {
right: auto;
left: 26px;
}
.chosen-rtl .chosen-choices li {
float: right;
}
.chosen-rtl .chosen-choices li.search-field input[type="text"] {
direction: rtl;
}
.chosen-rtl .chosen-choices li.search-choice {
margin: 3px 5px 3px 0;
padding: 3px 5px 3px 19px;
}
.chosen-rtl .chosen-choices li.search-choice .search-choice-close {
right: auto;
left: 4px;
}
.chosen-rtl.chosen-container-single-nosearch .chosen-search,
.chosen-rtl .chosen-drop {
left: 9999px;
}
.chosen-rtl.chosen-container-single .chosen-results {
margin: 0 0 4px 4px;
padding: 0 4px 0 0;
}
.chosen-rtl .chosen-results li.group-option {
padding-right: 15px;
padding-left: 0;
}
.chosen-rtl.chosen-container-active.chosen-with-drop .chosen-single div {
border-right: none;
}
.chosen-rtl .chosen-search input[type="text"] {
padding: 4px 5px 4px 20px;
background: white url("<%= asset_path 'chosen/chosen-sprite.png' %>") no-repeat -30px -20px;
background: url("<%= asset_path 'chosen/chosen-sprite.png' %>") no-repeat -30px -20px, -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff));
background: url("<%= asset_path 'chosen/chosen-sprite.png' %>") no-repeat -30px -20px, -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%);
background: url("<%= asset_path 'chosen/chosen-sprite.png' %>") no-repeat -30px -20px, -moz-linear-gradient(#eeeeee 1%, #ffffff 15%);
background: url("<%= asset_path 'chosen/chosen-sprite.png' %>") no-repeat -30px -20px, -o-linear-gradient(#eeeeee 1%, #ffffff 15%);
background: url("<%= asset_path 'chosen/chosen-sprite.png' %>") no-repeat -30px -20px, linear-gradient(#eeeeee 1%, #ffffff 15%);
direction: rtl;
}
.chosen-rtl.chosen-container-single .chosen-single div b {
background-position: 6px 2px;
}
.chosen-rtl.chosen-container-single.chosen-with-drop .chosen-single div b {
background-position: -12px 2px;
}
/* @end */
/* @group Retina compatibility */
@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-resolution: 144dpi) {
.chosen-rtl .chosen-search input[type="text"],
.chosen-container-single .chosen-single abbr,
.chosen-container-single .chosen-single div b,
.chosen-container-single .chosen-search input[type="text"],
.chosen-container-multi .chosen-choices .search-choice .search-choice-close,
.chosen-container .chosen-results-scroll-down span,
.chosen-container .chosen-results-scroll-up span {
background-image: url("<%= asset_path 'chosen/chosen-sprite@2x.png' %>") !important;
background-size: 52px 37px !important;
background-repeat: no-repeat !important;
}
}
/* @end */

View File

@ -43,21 +43,58 @@ class PagesController < ApplicationController
end
page = Page.find_by_param(params[:page_id])
module_app = page.module.downcase.pluralize
params[:target_controller] = "#{module_app}"
params[:url] = page.url
if !page.nil?
if page.enabled_for.include? I18n.locale.to_s
module_app = page.module.downcase.pluralize
params[:target_controller] = "#{module_app}"
params[:url] = page.url
@manifest = @key
@dataApi = nil
@manifest = @key
@dataApi = nil
OrbitHelper.set_params params
OrbitHelper.set_site_locale locale
# render render_final_page("#{module_app}/#{params[:target_action]}",page)
render :html => render_final_page("#{module_app}/#{params[:target_action]}",page).html_safe
OrbitHelper.set_params params
OrbitHelper.set_site_locale locale
OrbitHelper.set_page_categories page.categories || []
OrbitHelper.set_page_data_count page.data_count
# render render_final_page("#{module_app}/#{params[:target_action]}",page)
render :html => render_final_page("#{module_app}/#{params[:target_action]}",page).html_safe
else
render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found
end
else
render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found
end
end
end
def update_item_position
@page = Page.find(params[:id])
new_parent_page = Page.find(params[:parent_id])
old_parent_page_id = @page.parent_page_id
@page.parent_page_id = new_parent_page.id
if new_parent_page.id != old_parent_page_id
url = (new_parent_page.url == "/" ? "" : new_parent_page.url)
@page.url = url + "/#{@page.page_id}"
end
@page.save
params["children_ids"].each_with_index do |child,i|
page = Page.find(child)
page.number = i
page.save
end
if new_parent_page.id != old_parent_page_id
old_parent_page = Page.find(old_parent_page_id)
old_parent_page.child_page.each_with_index do |page,i|
page.number = i
page.save
end
end
render :json => {"success"=>true}.to_json
end
def preview
render render_final_page
end
@ -70,7 +107,17 @@ class PagesController < ApplicationController
end
end
def get_categories
module_app = ModuleApp.find_by_key(params[:module]);
@categories = module_app.categories.collect do |cat|
{
"title" => cat.title,
"id" => cat.id.to_s
}
end
render :json => {"categories" => @categories}.to_json
end
def new
@page = Page.new
@ -79,6 +126,24 @@ class PagesController < ApplicationController
end
def edit
@page = Page.find(params[:id])
@pages = Page.where(:page_id.ne => "" , :page_id.exists => true)
@modules = ModuleApp.all
module_app = ModuleApp.find_by_key(@page.module);
@categories = module_app.categories
end
def update
@page = Page.find(params[:id])
@page.update_attributes(page_update_params)
@page.save
respond_to do |format|
format.js
end
end
def create
@page = Page.new(page_params)
@page.save!
@ -153,19 +218,26 @@ class PagesController < ApplicationController
end
def page_params
if params[:page][:parent_page] == ""
params[:page][:parent_page] = nil
@url = "/#{params[:page][:page_id]}"
else
# if params[:page][:parent_page] == ""
# params[:page][:parent_page] = nil
# @url = "/#{params[:page][:page_id]}"
# else
page = Page.find(params[:page][:parent_page])
page.url = page.url.nil? ? "" : page.url
@url = page.url + "/#{params[:page][:page_id]}"
end
p = params.require(:page).permit(:number, :page_id, :module, :parent_page, name_translations: [:en, :zh_tw])
# end
p = params.require(:page).permit(:number, :page_id, :module, :parent_page, :data_count, enabled_for: [], menu_enabled_for: [], categories: [], name_translations: [:en, :zh_tw])
p["url"] = @url
p
end
def page_update_params
p = params.require(:page).permit(:number, :page_id, :module, :parent_page, :data_count, enabled_for: [],menu_enabled_for: [], categories: [], name_translations: [:en, :zh_tw])
p["enabled_for"] = p["enabled_for"] || []
p["menu_enabled_for"] = p["menu_enabled_for"] || []
p
end
def get_layout
if request[:action] == "edit_view"
page = Page.find(params[:id])

View File

@ -10,7 +10,7 @@ class SessionsController < ApplicationController
session[:user_id] = user.id
redirect_to admin_dashboards_path, :notice => "Logged in!"
else
flash.now.alert = "Invalid email or password"
flash.now.alert = "Invalid username or password"
render "new"
end
end

View File

@ -13,13 +13,13 @@ module ApplicationHelper
def render_menu
# json_file = File.read(File.join(Rails.root, 'public', "menu.json"))
# @items = JSON.parse(json_file)
@pages = Page.where(:parent_page_id.ne => "" , :parent_page_id.exists => false).first.child_page
@pages = Page.where(:parent_page_id.ne => "" , :parent_page_id.exists => false).first.sorted_published_child_pages
def create_json(pages)
item = {}
pages.each do |page|
if page.child_page.size > 0
item["#{page.name}"] = {"url"=> "/#{locale.to_s}" + page.url, "children"=>create_json(page.child_page)}
item["#{page.name}"] = {"url"=> "/#{locale.to_s}" + page.url, "children"=>create_json(page.sorted_published_child_pages)}
else
item["#{page.name}"] = {"url"=> "/#{locale.to_s}" + page.url}
end
@ -27,7 +27,6 @@ module ApplicationHelper
item
end
@items = create_json(@pages)
key = Template::KEY
menu_file = File.open(File.join(Rails.root, 'app', 'templates', "#{key}", '/home/menu.html.erb'))
doc = Nokogiri::HTML(menu_file, nil, "UTF-8")
@ -63,7 +62,7 @@ module ApplicationHelper
items.each do |key,item|
li = @menus_items[level].gsub("href_here",item["url"])
li = li.gsub("{{link_name}}",key)
if item["children"]
if item["children"] && !item["children"].empty?
li = li.gsub("{{level}}",create_menu(item["children"],level + 1))
else
li = li.gsub("{{level}}","")
@ -84,7 +83,7 @@ module ApplicationHelper
doc = Nokogiri::HTML(file, nil, "UTF-8")
file.close
wrap_elements = doc.css("*[data-module]")
controller = "#{params[:target_controller].capitalize}Controller".classify.constantize.new
controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new
data = controller.send("#{params[:target_action]}")
keys = data.keys
wrap_elements.each do |wrap_element|
@ -115,7 +114,7 @@ module ApplicationHelper
file.close
wrap_element_html = doc.to_s
html_to_render = ""
controller = "#{params[:target_controller].capitalize}Controller".classify.constantize.new
controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new
data = controller.send("#{params[:target_action]}")
el = wrap_element_html
data.each do |key,value|

View File

@ -3,10 +3,27 @@ module OrbitHelper
@params = params
end
def self.get_params
def self.set_page_categories(categories)
@categories = categories;
end
def self.set_page_data_count(data_count)
@data_count = data_count
end
def self.page_data_count
@data_count
end
def self.page_categories
@categories
end
def self.params
@params
end
def self.url_to_show(slug)
if @params[:url]
"/#{@site_locale}#{@params[:url]}/#{slug}"

View File

@ -0,0 +1,10 @@
module Filter
extend ActiveSupport::Concern
included do
end
def filter_by_categories(categories=[])
categories = OrbitHelper.page_categories if categories.blank?
self.where(:category_id.in => categories) rescue []
end
end

View File

@ -7,26 +7,38 @@ class Page
field :module
field :url
field :page_id
field :is_published, type: Boolean, default: true
field :data_count, type: Integer, default: 10
field :enabled_for, type: Array, default: []
field :menu_enabled_for, type: Array, default: []
field :categories, type: Array, :default => []
has_many :page_parts, :autosave => true, :dependent => :destroy
has_many :child_page, :class_name => 'Page', :inverse_of => :parent_page, :dependent => :destroy
belongs_to :parent_page, :class_name => 'Page', :inverse_of => :child_page
def to_param
page_id.parameterize
end
page_id.parameterize
end
def self.find_by_param(input)
self.find_by(page_id: input) rescue nil
end
def self.find_by_param(input)
self.find_by(page_id: input) rescue nil
end
def self.root
self.where(:parent_page_id.ne => "" , :parent_page_id.exists => false).first
end
def self.root
self.where(:parent_page_id.ne => "" , :parent_page_id.exists => false).first
end
def root?
self.parent_page_id.nil?
end
def root?
self.parent_page_id.nil?
end
def sorted_published_child_pages
self.child_page.where(:menu_enabled_for => I18n.locale).asc(:number)
end
def published_child_pages
self.child_page.where(:menu_enabled_for => I18n.locale)
end
end

View File

@ -18,8 +18,7 @@
<% 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.class.to_s.eql?('Page') %>
<%# if node.class.to_s.downcase.eql?("page") %>
<%#= link_to content_tag(:i, nil, class: "icon-edit"), "#page", class: "open-slide tip page edit", title: t('editing.page'), data: {title: t('editing.page'), id: node.id.to_s, parent: node.parent_id.to_s, form: {name: node.name}.merge(node.title_translations)} %>
<%= link_to content_tag(:i, nil, class: "icon-edit"), edit_page_path(node.id), class: "open-slide tip page edit", title: "Edit Page", data: {title: "Edit Page"} if node.class.to_s.downcase.eql?("page") && !node.root? %>
<%# elsif node.class.to_s.downcase.eql?("link") %>
<%#= link_to content_tag(:i, nil, class: "icon-edit"), "#link", class: "open-slide tip link edit", title: t('editing.link'), data: {title: t('editing.link'), id: node.id.to_s, parent: node.parent_id.to_s, form: {name: node.name}.merge(node.title_translations).merge(node.urls)} %>
<%# end %>
@ -29,12 +28,12 @@
</div>
</div>
<div class="item-info pull-right">
<%# @site_in_use_locales.each do |valid_locale| %>
<%# if node.enabled_for && node.enabled_for.include?(valid_locale) %>
<!-- <span class="label label-warning"><%#= I18nVariable.from_locale(valid_locale) %></span> -->
<% I18n.available_locales.each do |valid_locale| %>
<% if node.enabled_for.include?(valid_locale.to_s) %>
<span class="label label-warning"><%= t(valid_locale.to_s) %></span>
<%# end %>
<%# end %>
<% end %>
<% end %>
<span class="badge <%= 'badge-inverse' if node.root? %>"></span>
</div>
</div>

View File

@ -1,12 +1,12 @@
<% unless node.root? %>
<li id='<%= node.id %>' class="<%= 'disabled' unless node.is_published %> <%= 'no-nest' if node.class.to_s.eql?('Link') %>" >
<li id='<%= node.id %>' class="<%= 'disabled' unless !node.enabled_for.empty? %> <%= 'no-nest' if node.class.to_s.eql?('Link') %>" >
<% end %>
<%= render 'node', {node: node, level: level} rescue render 'admin/items/node', {node: node, level: level} %>
<% unless node.child_page.blank? %>
<% unless node.root? %>
<ol>
<% end %>
<% node.child_page.each do |child| %>
<% node.child_page.asc(:number).each do |child| %>
<%= render 'node_and_children', {node: child, level: level + 1} rescue render 'admin/items/node_and_children', {node: child, level: level + 1} %>
<% end %>
<% unless node.root? %>

View File

@ -1,7 +1,6 @@
<% node = Page.root %>
<% unless node.nil? %>
<ol id='<%= node.id %>' class="sortable item-groups">
<ol id='<%= node.id %>' class="sortable item-groups root">
<%= render 'node_and_children', {node: node, level: 0} %>
</ol>
<% end %>
@ -9,4 +8,4 @@
<%#= render 'form_page' %>
<%#= render 'form_link' %>
<%= javascript_include_tag "lib/pageslide.js" %>
<%= javascript_include_tag "lib/items/items" %>
<%= javascript_include_tag "lib/items/items" %>

View File

@ -0,0 +1,73 @@
<div class="control-group">
<% I18n.available_locales.each do |locale| %>
<label class="control-label">Page name <%= locale.to_s %> :</label>
<div class="controls">
<%= f.fields_for :name_translations do |n| %>
<%= n.text_field locale, :value=>@page.name_translations[locale] rescue nil %>
<% end %>
</div>
<% end %>
</div>
<div class="control-group">
<label class="control-label">Page id :</label>
<div class="controls">
<%= f.text_field :page_id %>
</div>
<label class="control-label">Module :</label>
<div class="controls">
<%= f.select(:module, @modules.map{|m| [m.title,m.key]},{:include_blank => true},:class=>"module_select") %>
<%= f.hidden_field :parent_page, value: (params[:parent_page] || @page.parent_page_id) %>
</div>
</div>
<div class="control-group">
<label class="control-label"><%= "Category List :" if params[:action] == "edit" %></label>
<div id="categories_list">
<% if params[:action] == "edit" %>
<div class="controls">
<% if !@categories.blank? %>
<label class="checkbox">
<input type="checkbox" value="all" class="checkbox-all" name="page[categories][]" <%= "checked='checked'" if (@page.categories.include? "all") %> >
All
</label>
<% end %>
<% @categories.each do |category| %>
<label class="checkbox">
<input type="checkbox" name="page[categories][]" value="<%= category.id.to_s %>" <%= "checked='checked'" if (@page.categories.include? category.id.to_s) %> />
<%= category.title %>
</label>
<% end %>
</div>
<% end %>
</div>
</div>
<div class="control-group">
<label class="control-label">Data Count :</label>
<div class="controls">
<select name="page[data_count]" id="data-count" class="span1">
<% 10.times do |i| %>
<option value="<%= i + 1 %>" <%= "selected='selected'" if i+1 == @page.data_count %> ><%= i + 1 %></option>
<% end %>
</select>
</div>
</div>
<div class="control-group" id="enable-menu">
<div class="controls">
<label class="control-label">Enabled for :</label>
<% I18n.available_locales.each do |locale| %>
<label class="checkbox">
<input type="checkbox" name="page[enabled_for][]" value="<%= locale.to_s %>" class="main-enable-parent" for="<%= "checkbox_for_#{locale}" %>" <%= "checked" if @page.enabled_for.include? locale.to_s %> />
<%= t(locale.to_s) %>
</label>
<div style="margin-left:25px;">
<label class="checkbox">
Enable menu
<input type="checkbox" name="page[menu_enabled_for][]" class="main-enable-child" value="<%= locale.to_s %>" <%= "checked" if @page.menu_enabled_for.include? locale.to_s %> />
</label>
</div>
<% end %>
</div>
</div>

View File

@ -0,0 +1,8 @@
<%= form_for @page, url: {action: "update"},:class =>"form-horizontal", remote: true do |f| %>
<%= render "form", {:f=> f} %>
<div class="control-group">
<div class="controls">
<%= f.submit "Update Page",:class=>"btn btn-primary" %>
</div>
</div>
<% end %>

View File

@ -1,16 +1,8 @@
<%= form_for @page, url: {action: "create"}, remote: true do |f| %>
<% I18n.available_locales.each do |locale| %>
Page name <%= locale.to_s %>:
<%= f.fields_for :name_translations do |n| %>
<%= n.text_field locale %>
<% end %>
<% end %>
Page id:
<%= f.text_field :page_id %>
Module :
<%= f.select(:module, @modules.map{|m| [m.title,m.key]},{:include_blank => true}) %>
<%#= f.select(:parent_page, @pages.map{|page| [page.name, page.id]},{:include_blank => true}) %>
<%= f.hidden_field :parent_page, value: params[:parent_page] %>
<%#= f.text_field :number %>
<%= f.submit "Create Page" %>
<%= form_for @page, url: {action: "create"},:class =>"form-horizontal", remote: true do |f| %>
<%= render "form", {:f=> f} %>
<div class="control-group">
<div class="controls">
<%= f.submit "Create Page", :class=>"btn btn-primary" %>
</div>
</div>
<% end %>

View File

@ -0,0 +1,3 @@
$("#main-wrap ol.sortable").html("<%= j render 'admin/items/node_and_children', {node: Page.root, level: 0} %>");
$.pageslide.close();
itemsLibrary.reBindHandlers();

View File

@ -21,6 +21,8 @@
en:
_locale: English
en: English
zh_tw: Chinese
more: "More"
site_: Site
site_info: Site Info

View File

@ -7,6 +7,8 @@ Orbit::Application.routes.draw do
get "/pages/edit_view" => "pages#edit_view"
get "/pages/preview" => "pages#preview"
get "/pages/get_categories" => "pages#get_categories"
post "/pages/update_item_position" => "pages#update_item_position"
get "/page_parts/getwidgets" => "page_parts#getwidgets"
get "/page_parts/info" => "page_parts#info"

View File

@ -1,7 +1,26 @@
module OrbitCategory
module Categorizable
def self.included(base)
base.extend ClassMethods
base.field :category_id, type: BSON::ObjectId
base.class_eval "filter_by_categories"
end
module ClassMethods
def filter_by_categories(categories=[])
class_eval do
categories = OrbitHelper.page_categories if categories.blank?
if !categories.blank?
if categories.first == "all"
self.all.limit(OrbitHelper.page_data_count)
else
self.where(:category_id.in => categories).limit(OrbitHelper.page_data_count) rescue []
end
else
[]
end
end
end
end
def category
@ -15,5 +34,6 @@ module OrbitCategory
def disable?
Category.find(self.category_id).disable? rescue nil
end
end
end

View File

@ -1,58 +1,28 @@
<!DOCTYPE html>
<html>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<title>The page you were looking for doesn't exist (404)</title>
<style>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="stylesheets/error-pages.css" media="all"/>
</head>
<body>
<style type="text/css">
body {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
}
div.dialog {
width: 25em;
margin: 4em auto 0 auto;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 4em 0 4em;
}
h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}
body > p {
width: 33em;
margin: 0 auto 1em;
padding: 1em 0;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
margin: 0;
padding: 40px 0 0 0;
background-color: #F3F3F3;
}
</style>
</head>
<body>
<!-- This file lives in public/404.html -->
<div class="dialog">
<h1>The page you were looking for doesn't exist.</h1>
<p>You may have mistyped the address or the page may have moved.</p>
<!-- Error Pages Start Here -->
<div id="error-page">
<div class="card">
<div class="figure code-404"></div>
<div class="message">
<h1>Page not found!!!</h1>
<p>The page you were looking for doesnt exist.</p>
</div>
</div>
</div>
<p>If you are the application owner check the logs for more information.</p>
<!-- Error Pages End Here -->
</body>
</html>
</html>

View File

@ -0,0 +1,41 @@
@import url(http://fonts.googleapis.com/css?family=Roboto+Condensed);
#error-page {
width: 820px;
margin: 160px auto 0 auto;
}
#error-page .card {
overflow: hidden;
}
#error-page .figure {
width: 460px;
height: 260px;
float: left;
}
#error-page .figure.code-403 { background: url(../img/403.png) center bottom no-repeat; }
#error-page .figure.code-404 { background: url(../img/404.png) center bottom no-repeat; }
#error-page .figure.code-500 { background: url(../img/500.png) center bottom no-repeat; }
#error-page .message {
float: right;
width: 330px;
margin: 60px 0 0 0;
padding: 16px 0;
border: solid 3px #D8D8D8;
border-left: 0;
border-right: 0;
text-align: center;
}
#error-page .message > * {
margin: 0;
}
#error-page .message h1 {
color: #333;
font-size: 52px;
font-family: 'Roboto Condensed', sans-serif;
}
#error-page .message p {
color: #999;
font-size: 15px;
font-family: sans-serif;
padding: 16px 0;
}