fix js bug when changing layout in page editing + improve nav tag

This commit is contained in:
dinedine 2010-07-22 01:35:30 +02:00
parent c4f4979203
commit 35e0120cab
10 changed files with 156 additions and 143 deletions

18
Gemfile
View File

@ -13,7 +13,7 @@ gem 'mongoid_acts_as_tree', '0.1.5'
gem 'mongo_session_store', '2.0.0.pre' gem 'mongo_session_store', '2.0.0.pre'
gem 'warden' gem 'warden'
gem 'devise', '1.1.rc1' gem 'devise', '1.1.rc1'
gem 'haml', '3.0.1' gem 'haml', '3.0.13'
gem 'rmagick', '2.12.2' gem 'rmagick', '2.12.2'
gem 'aws' gem 'aws'
gem 'mimetype-fu', :require => 'mimetype_fu' gem 'mimetype-fu', :require => 'mimetype_fu'
@ -36,12 +36,12 @@ group :development do
end end
group :test do group :test do
gem 'rspec-rails', '2.0.0.beta.11' gem 'rspec-rails', '2.0.0.beta.11'
gem 'factory_girl_rails' gem 'factory_girl_rails'
gem 'capybara' gem 'capybara'
gem 'cucumber' gem 'cucumber'
gem 'cucumber-rails' gem 'cucumber-rails'
gem 'spork' gem 'spork'
gem 'launchy' gem 'launchy'
gem 'mocha', :git => 'git://github.com/floehopper/mocha.git' gem 'mocha', :git => 'git://github.com/floehopper/mocha.git'
end end

View File

@ -3,9 +3,12 @@ module Admin
layout nil layout nil
respond_to :json
def index def index
parts = current_site.layouts.find(params[:layout_id]).parts parts = current_site.layouts.find(params[:layout_id]).parts
render :json => { :parts => parts }
respond_with parts.collect(&:attributes)
end end
end end

View File

@ -3,7 +3,7 @@ module Admin
sections 'contents' sections 'contents'
respond_to :json, :only => [:update, :sort] respond_to :json, :only => [:update, :sort, :get_path]
def index def index
@pages = current_site.pages.roots @pages = current_site.pages.roots

View File

@ -34,9 +34,6 @@ class Site
named_scope :match_domain, lambda { |domain| { :where => { :domains => domain } } } 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 } } } 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 ## ## methods ##
def accounts def accounts

View File

@ -5,5 +5,5 @@ site.memberships.build :account => account, :admin => true
site.save! site.save!
puts "Your first website has been created !" 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" puts "Crendetials: admin@example.com / locomotive"

View 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

View File

@ -28,8 +28,6 @@ module Locomotive
path = [path, File.join(dirname, 'content_type_template').gsub(/^\//, '')] path = [path, File.join(dirname, 'content_type_template').gsub(/^\//, '')]
end 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 page = current_site.pages.any_in(:fullpath => [*path]).first
if not page.published? and current_admin.nil? if not page.published? and current_admin.nil?
page = nil page = nil

View File

@ -1,88 +1,88 @@
$(document).ready(function() { $(document).ready(function() {
// slider // slider
var resetSlider = function() { var resetSlider = function() {
$('#page-parts .wrapper ul').wslide({ $('#page-parts .wrapper ul').wslide({
width: 880, width: 880,
height: 400, height: 400,
autolink: false, autolink: false,
duration: 300, duration: 300,
horiz: true horiz: true
}); });
} }
resetSlider(); resetSlider();
// codemirror // codemirror
$('#parts code textarea').each(function() { addCodeMirrorEditor('liquid', $(this)); }); $('#parts code textarea').each(function() { addCodeMirrorEditor('liquid', $(this)); });
var refreshParts = function(parts) { var refreshParts = function(parts) {
// console.log('refreshParts'); // console.log('refreshParts');
$('#page-parts .nav a').removeClass('enabled'); $('#page-parts .nav a').removeClass('enabled');
$(parts).each(function() { $(parts).each(function() {
// console.log("iterating..." + this.slug); // console.log("iterating..." + this.slug);
var control = $('#control-part-' + this.slug); var control = $('#control-part-' + this.slug);
// adding missing part // adding missing part
if (control.size() == 0) { if (control.size() == 0) {
// console.log('adding part'); // console.log('adding part');
var nbParts = $('#page-parts .nav a').size(); 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>'); $('#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 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 + '" />' 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 + '" />' 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>'); $('#page-parts .wrapper ul').append('<li id="part-' + nbParts + '" class="new"><code>' + textareaInput + '</code>' + hiddenInputs + '</li>');
resetSlider(); resetSlider();
$('#parts li:last code textarea').each(function() { addCodeMirrorEditor('liquid', $(this)); }); $('#parts li:last code textarea').each(function() { addCodeMirrorEditor('liquid', $(this)); });
} else { } else {
var index = parseInt(control.attr('class').match(/part-(.+)/)[1]) + 1; var index = parseInt(control.attr('class').match(/part-(.+)/)[1]) + 1;
var wrapper = $('#parts-' + index); var wrapper = $('#parts-' + index);
// updating part // updating part
wrapper.find('input.disabled').val(this.disabled == true ? 'true' : 'false'); wrapper.find('input.disabled').val(this.disabled == true ? 'true' : 'false');
if (this.disabled == false) { if (this.disabled == false) {
control.html('<span>' + this.name + '</span>').addClass('enabled').show(); control.html('<span>' + this.name + '</span>').addClass('enabled').show();
wrapper.show(); wrapper.show();
} else { } else {
control.hide(); control.hide();
wrapper.hide(); wrapper.hide();
} }
} }
}); });
// removing or hiding parts // removing or hiding parts
$('#page-parts .nav a:not(.enabled)').each(function() { $('#page-parts .nav a:not(.enabled)').each(function() {
var index = parseInt($(this).attr('class').match(/part-(.+)/)[1]) + 1; var index = parseInt($(this).attr('class').match(/part-(.+)/)[1]) + 1;
var wrapper = $('#parts-' + index); var wrapper = $('#parts-' + index);
if (wrapper.hasClass('new')) { if (wrapper.hasClass('new')) {
$(this).remove(); wrapper.remove(); $(this).remove(); wrapper.remove();
} else { } else {
wrapper.find('input.disabled').val('true'); wrapper.find('input.disabled').val('true');
$(this).hide(); wrapper.hide(); $(this).hide(); wrapper.hide();
} }
}); });
// go to the first one if we hid the selected wrapper // go to the first one if we hide the selected wrapper
var selectedNav = $('#page-parts .nav a.on'); var selectedNav = $('#page-parts .nav a.on');
if (selectedNav.size() == 1) { if (selectedNav.size() == 1) {
var index = parseInt(selectedNav.attr('class').match(/part-(.+)/)[1]) + 1; var index = parseInt(selectedNav.attr('class').match(/part-(.+)/)[1]) + 1;
if ($('#parts-' + index + ':visible').size() == 0) if ($('#parts-' + index + ':visible').size() == 0)
$('#page-parts .nav a:first').click(); $('#page-parts .nav a:first').click();
} else } else
$('#page-parts .nav a:first').click(); $('#page-parts .nav a:first').click();
} }
var loadPartsFromLayout = function() { var loadPartsFromLayout = function() {
if ($('#page_layout_id').val() == '') if ($('#page_layout_id').val() == '')
return ; return ;
var url = $('#page_layout_id').attr('data_url').replace('_id_to_replace_', $('#page_layout_id').val()); var url = $('#page_layout_id').attr('data_url').replace('_id_to_replace_', $('#page_layout_id').val());
$.get(url, '', function(data) { refreshParts(data.parts); }, 'json'); $.get(url, '', function(data) { refreshParts(data); }, 'json');
} }
$('#page_layout_id').change(loadPartsFromLayout); $('#page_layout_id').change(loadPartsFromLayout);
}); });