fix js bug when changing layout in page editing + improve nav tag
This commit is contained in:
parent
c4f4979203
commit
35e0120cab
18
Gemfile
18
Gemfile
@ -13,7 +13,7 @@ gem 'mongoid_acts_as_tree', '0.1.5'
|
||||
gem 'mongo_session_store', '2.0.0.pre'
|
||||
gem 'warden'
|
||||
gem 'devise', '1.1.rc1'
|
||||
gem 'haml', '3.0.1'
|
||||
gem 'haml', '3.0.13'
|
||||
gem 'rmagick', '2.12.2'
|
||||
gem 'aws'
|
||||
gem 'mimetype-fu', :require => 'mimetype_fu'
|
||||
@ -36,12 +36,12 @@ group :development do
|
||||
end
|
||||
|
||||
group :test do
|
||||
gem 'rspec-rails', '2.0.0.beta.11'
|
||||
gem 'factory_girl_rails'
|
||||
gem 'capybara'
|
||||
gem 'cucumber'
|
||||
gem 'cucumber-rails'
|
||||
gem 'spork'
|
||||
gem 'launchy'
|
||||
gem 'mocha', :git => 'git://github.com/floehopper/mocha.git'
|
||||
gem 'rspec-rails', '2.0.0.beta.11'
|
||||
gem 'factory_girl_rails'
|
||||
gem 'capybara'
|
||||
gem 'cucumber'
|
||||
gem 'cucumber-rails'
|
||||
gem 'spork'
|
||||
gem 'launchy'
|
||||
gem 'mocha', :git => 'git://github.com/floehopper/mocha.git'
|
||||
end
|
@ -3,9 +3,12 @@ module Admin
|
||||
|
||||
layout nil
|
||||
|
||||
respond_to :json
|
||||
|
||||
def index
|
||||
parts = current_site.layouts.find(params[:layout_id]).parts
|
||||
render :json => { :parts => parts }
|
||||
|
||||
respond_with parts.collect(&:attributes)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -3,7 +3,7 @@ module Admin
|
||||
|
||||
sections 'contents'
|
||||
|
||||
respond_to :json, :only => [:update, :sort]
|
||||
respond_to :json, :only => [:update, :sort, :get_path]
|
||||
|
||||
def index
|
||||
@pages = current_site.pages.roots
|
||||
|
@ -34,9 +34,6 @@ class Site
|
||||
named_scope :match_domain, lambda { |domain| { :where => { :domains => domain } } }
|
||||
named_scope :match_domain_with_exclusion_of, lambda { |domain, site| { :where => { :domains => domain, :_id.ne => site.id } } }
|
||||
|
||||
## behaviours ##
|
||||
liquid_methods :name, :meta_keywords, :meta_description
|
||||
|
||||
## methods ##
|
||||
|
||||
def accounts
|
||||
|
@ -5,5 +5,5 @@ site.memberships.build :account => account, :admin => true
|
||||
site.save!
|
||||
|
||||
puts "Your first website has been created !"
|
||||
puts "Admin url: http://test.example.com/admin"
|
||||
puts "Admin url: http://test.example.com:3000/admin"
|
||||
puts "Crendetials: admin@example.com / locomotive"
|
15
lib/locomotive/liquid/drops/site.rb
Normal file
15
lib/locomotive/liquid/drops/site.rb
Normal file
@ -0,0 +1,15 @@
|
||||
module Locomotive
|
||||
module Liquid
|
||||
module Drops
|
||||
class Site < Base
|
||||
|
||||
liquid_attributes << :name << :meta_keywords << :meta_description
|
||||
|
||||
def index
|
||||
@index ||= @source.pages.index.first
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -28,8 +28,6 @@ module Locomotive
|
||||
path = [path, File.join(dirname, 'content_type_template').gsub(/^\//, '')]
|
||||
end
|
||||
|
||||
# TODO: path is not correctly built + find content instance in order to render a 404 page if not found
|
||||
|
||||
if page = current_site.pages.any_in(:fullpath => [*path]).first
|
||||
if not page.published? and current_admin.nil?
|
||||
page = nil
|
||||
|
@ -1,88 +1,88 @@
|
||||
$(document).ready(function() {
|
||||
|
||||
// slider
|
||||
var resetSlider = function() {
|
||||
$('#page-parts .wrapper ul').wslide({
|
||||
width: 880,
|
||||
height: 400,
|
||||
autolink: false,
|
||||
duration: 300,
|
||||
horiz: true
|
||||
});
|
||||
}
|
||||
// slider
|
||||
var resetSlider = function() {
|
||||
$('#page-parts .wrapper ul').wslide({
|
||||
width: 880,
|
||||
height: 400,
|
||||
autolink: false,
|
||||
duration: 300,
|
||||
horiz: true
|
||||
});
|
||||
}
|
||||
|
||||
resetSlider();
|
||||
resetSlider();
|
||||
|
||||
// codemirror
|
||||
$('#parts code textarea').each(function() { addCodeMirrorEditor('liquid', $(this)); });
|
||||
// codemirror
|
||||
$('#parts code textarea').each(function() { addCodeMirrorEditor('liquid', $(this)); });
|
||||
|
||||
var refreshParts = function(parts) {
|
||||
// console.log('refreshParts');
|
||||
$('#page-parts .nav a').removeClass('enabled');
|
||||
var refreshParts = function(parts) {
|
||||
// console.log('refreshParts');
|
||||
$('#page-parts .nav a').removeClass('enabled');
|
||||
|
||||
$(parts).each(function() {
|
||||
// console.log("iterating..." + this.slug);
|
||||
var control = $('#control-part-' + this.slug);
|
||||
$(parts).each(function() {
|
||||
// console.log("iterating..." + this.slug);
|
||||
var control = $('#control-part-' + this.slug);
|
||||
|
||||
// adding missing part
|
||||
if (control.size() == 0) {
|
||||
// console.log('adding part');
|
||||
var nbParts = $('#page-parts .nav a').size();
|
||||
$('#page-parts .nav .clear').before('<a id="control-part-' + this.slug + '" class="enabled part-' + nbParts + '" href="#parts-' + (nbParts + 1) + '"><span>' + this.name + '</span></a>');
|
||||
// adding missing part
|
||||
if (control.size() == 0) {
|
||||
// console.log('adding part');
|
||||
var nbParts = $('#page-parts .nav a').size();
|
||||
$('#page-parts .nav .clear').before('<a id="control-part-' + this.slug + '" class="enabled part-' + nbParts + '" href="#parts-' + (nbParts + 1) + '"><span>' + this.name + '</span></a>');
|
||||
|
||||
var textareaInput = '<textarea rows="20" name="page[parts_attributes][' + nbParts + '][value]" id="page_parts_attributes_' + nbParts + '_value"/>';
|
||||
var hiddenInputs = '<input type="hidden" name="page[parts_attributes][' + nbParts + '][name]" value="' + this.name + '" />'
|
||||
hiddenInputs += '<input type="hidden" name="page[parts_attributes][' + nbParts + '][slug]" value="' + this.slug + '" />'
|
||||
$('#page-parts .wrapper ul').append('<li id="part-' + nbParts + '" class="new"><code>' + textareaInput + '</code>' + hiddenInputs + '</li>');
|
||||
var textareaInput = '<textarea rows="20" name="page[parts_attributes][' + nbParts + '][value]" id="page_parts_attributes_' + nbParts + '_value"/>';
|
||||
var hiddenInputs = '<input type="hidden" name="page[parts_attributes][' + nbParts + '][name]" value="' + this.name + '" />'
|
||||
hiddenInputs += '<input type="hidden" name="page[parts_attributes][' + nbParts + '][slug]" value="' + this.slug + '" />'
|
||||
$('#page-parts .wrapper ul').append('<li id="part-' + nbParts + '" class="new"><code>' + textareaInput + '</code>' + hiddenInputs + '</li>');
|
||||
|
||||
resetSlider();
|
||||
$('#parts li:last code textarea').each(function() { addCodeMirrorEditor('liquid', $(this)); });
|
||||
} else {
|
||||
var index = parseInt(control.attr('class').match(/part-(.+)/)[1]) + 1;
|
||||
var wrapper = $('#parts-' + index);
|
||||
resetSlider();
|
||||
$('#parts li:last code textarea').each(function() { addCodeMirrorEditor('liquid', $(this)); });
|
||||
} else {
|
||||
var index = parseInt(control.attr('class').match(/part-(.+)/)[1]) + 1;
|
||||
var wrapper = $('#parts-' + index);
|
||||
|
||||
// updating part
|
||||
wrapper.find('input.disabled').val(this.disabled == true ? 'true' : 'false');
|
||||
if (this.disabled == false) {
|
||||
control.html('<span>' + this.name + '</span>').addClass('enabled').show();
|
||||
wrapper.show();
|
||||
} else {
|
||||
control.hide();
|
||||
wrapper.hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
// updating part
|
||||
wrapper.find('input.disabled').val(this.disabled == true ? 'true' : 'false');
|
||||
if (this.disabled == false) {
|
||||
control.html('<span>' + this.name + '</span>').addClass('enabled').show();
|
||||
wrapper.show();
|
||||
} else {
|
||||
control.hide();
|
||||
wrapper.hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// removing or hiding parts
|
||||
$('#page-parts .nav a:not(.enabled)').each(function() {
|
||||
var index = parseInt($(this).attr('class').match(/part-(.+)/)[1]) + 1;
|
||||
var wrapper = $('#parts-' + index);
|
||||
if (wrapper.hasClass('new')) {
|
||||
$(this).remove(); wrapper.remove();
|
||||
} else {
|
||||
wrapper.find('input.disabled').val('true');
|
||||
$(this).hide(); wrapper.hide();
|
||||
}
|
||||
});
|
||||
// removing or hiding parts
|
||||
$('#page-parts .nav a:not(.enabled)').each(function() {
|
||||
var index = parseInt($(this).attr('class').match(/part-(.+)/)[1]) + 1;
|
||||
var wrapper = $('#parts-' + index);
|
||||
if (wrapper.hasClass('new')) {
|
||||
$(this).remove(); wrapper.remove();
|
||||
} else {
|
||||
wrapper.find('input.disabled').val('true');
|
||||
$(this).hide(); wrapper.hide();
|
||||
}
|
||||
});
|
||||
|
||||
// go to the first one if we hid the selected wrapper
|
||||
var selectedNav = $('#page-parts .nav a.on');
|
||||
if (selectedNav.size() == 1) {
|
||||
var index = parseInt(selectedNav.attr('class').match(/part-(.+)/)[1]) + 1;
|
||||
if ($('#parts-' + index + ':visible').size() == 0)
|
||||
$('#page-parts .nav a:first').click();
|
||||
} else
|
||||
$('#page-parts .nav a:first').click();
|
||||
}
|
||||
// go to the first one if we hide the selected wrapper
|
||||
var selectedNav = $('#page-parts .nav a.on');
|
||||
if (selectedNav.size() == 1) {
|
||||
var index = parseInt(selectedNav.attr('class').match(/part-(.+)/)[1]) + 1;
|
||||
if ($('#parts-' + index + ':visible').size() == 0)
|
||||
$('#page-parts .nav a:first').click();
|
||||
} else
|
||||
$('#page-parts .nav a:first').click();
|
||||
}
|
||||
|
||||
var loadPartsFromLayout = function() {
|
||||
if ($('#page_layout_id').val() == '')
|
||||
return ;
|
||||
var loadPartsFromLayout = function() {
|
||||
if ($('#page_layout_id').val() == '')
|
||||
return ;
|
||||
|
||||
var url = $('#page_layout_id').attr('data_url').replace('_id_to_replace_', $('#page_layout_id').val());
|
||||
$.get(url, '', function(data) { refreshParts(data.parts); }, 'json');
|
||||
}
|
||||
var url = $('#page_layout_id').attr('data_url').replace('_id_to_replace_', $('#page_layout_id').val());
|
||||
$.get(url, '', function(data) { refreshParts(data); }, 'json');
|
||||
}
|
||||
|
||||
$('#page_layout_id').change(loadPartsFromLayout);
|
||||
$('#page_layout_id').change(loadPartsFromLayout);
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user