diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index dc062448..cde4a425 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -40,6 +40,8 @@ class Admin::PagePartsController < ApplicationController @part = PagePart.find(params[:id]) if @part.update_attributes(params[:page_part]) flash.now[:notice] = t('admin.update_success_content') + @part.build_content(@site_valid_locales) + @part.save respond_to do |format| format.html { redirect_to admin_page_url( @part.page ) diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index 87eedbea..811ed6d4 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -31,12 +31,20 @@ class Admin::PagesController < ApplicationController def create @item = Page.new(params[:page]) - @item.content = parse_content(@item.content, {:locale => 'create'}) if @item.save - flash[:notice] = t('admin.create_success_page') - redirect_to admin_items_url( :parent_id => @item.parent_id ) + @item.create_parts + @item.save + flash.now[:notice] = t('admin.create_success_page') + respond_to do |format| + format.html { + redirect_to admin_item_url(@item) + } + format.js {} + end else - render :action => "new" + flash.now[:error] = t('admin.create_error_page') + @i18n_variable = @item.i18n_variable + render :action => "new" end end diff --git a/app/helpers/admin/item_helper.rb b/app/helpers/admin/item_helper.rb new file mode 100644 index 00000000..816e6a58 --- /dev/null +++ b/app/helpers/admin/item_helper.rb @@ -0,0 +1,23 @@ +module Admin::ItemHelper + + def render_node_and_children(node) + ret = '' + if node + case node._type + when 'Page' + dest = admin_page_path(node) + when 'Link' + dest = admin_link_path(node) + end + ret << "
  • " + ret << (link_to node.name, dest) + ret << ' | ' << (link_to t('admin.new_page'), new_admin_page_path(:parent_id => node.id)) if node._type.eql?('Page') + ret << ' | ' << (link_to t('admin.new_link'), new_admin_link_path(:parent_id => node.id)) if node._type.eql?('Page') + ret << ' | ' << (link_to t(:delete), delete_admin_link_path(node, :authenticity_token => form_authenticity_token), :confirm => t('sure?'), :class => 'delete') if node._type.eql?('Link') + ret << render_children(node) + ret << "
  • " + end + ret.html_safe + end + +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6c81e647..3514b515 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -49,25 +49,6 @@ module ApplicationHelper end end - def render_node_and_children(node) - ret = '' - if node - case node._type - when 'Page' - dest = admin_page_path(node) - when 'Link' - dest = admin_link_path(node) - end - ret << "
  • " - ret << (link_to node.name, dest) - ret << ' | ' << (link_to 'new_link', new_admin_link_path(:parent_id => node.id)) if node._type.eql?('Page') - ret << ' | ' << (link_to t(:delete), delete_admin_link_path(node, :authenticity_token => form_authenticity_token), :confirm => t('sure?'), :class => 'delete') if node._type.eql?('Link') - ret << render_children(node) - ret << "
  • " - end - ret.html_safe - end - def render_children(parent) if children = parent.children ret = '' diff --git a/app/models/i18n_variable.rb b/app/models/i18n_variable.rb index b59588e7..e6835347 100644 --- a/app/models/i18n_variable.rb +++ b/app/models/i18n_variable.rb @@ -7,4 +7,8 @@ class I18nVariable field :document_class, :type => String field :parent_id, :type => BSON::ObjectId, :index => true + def method_missing(field) + self[field] + end + end diff --git a/app/models/page.rb b/app/models/page.rb index 927cb874..fe85ba9d 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -11,13 +11,24 @@ class Page < Item referenced_in :layout has_many :page_parts + def create_parts + page_layout = self.get_layout + page_layout.layout_parts.each do |p| + self.page_parts.create( :name => p.name, :i18n_variable_id => I18nVariable.create.id, :kind => 'text' ) + end + end + + def get_layout + Layout.find(layout_id) + end + protected def setup_default_value super if self.layout_id - self.layout_name = Layout.find(layout_id).name + self.layout_name = get_layout.name end end diff --git a/app/models/page_part.rb b/app/models/page_part.rb index e4860990..39ce1b80 100644 --- a/app/models/page_part.rb +++ b/app/models/page_part.rb @@ -25,5 +25,18 @@ class PagePart self.i18n_variable_id = var.id end end + + # Build the content from the i18n_variable + def build_content(locales) + res = '' + res << "" + locales.each do |locale| + res << "" + res << i18n_variable[locale.to_s] + res << "" + end + res << "" + self.content = res + end end \ No newline at end of file diff --git a/app/views/admin/pages/_form.html.erb b/app/views/admin/pages/_form.html.erb index f6f8c567..89c56e69 100644 --- a/app/views/admin/pages/_form.html.erb +++ b/app/views/admin/pages/_form.html.erb @@ -1,3 +1,4 @@ +<%= f.error_messages %> <%= f.hidden_field :parent_id %>

    @@ -18,11 +19,6 @@ <%= f.select :layout_id, Layout.all.map{ |l| [l.description, l.id] } %>

    -

    -<%= f.label "content", t('admin.content') %> -<%= f.text_area "content", :size => '100x30' %> -

    -

    <%= f.label :is_published, "#{t('admin.is_published')} ?" %> <%= f.radio_button :is_published, true %>Yes <%= f.radio_button :is_published, false %> No diff --git a/app/views/admin/pages/_new.html.erb b/app/views/admin/pages/_new.html.erb new file mode 100644 index 00000000..a2991bec --- /dev/null +++ b/app/views/admin/pages/_new.html.erb @@ -0,0 +1,13 @@ +

    <%= t('admin.new_page') %>

    + +<%= flash_messages %> + +<%= form_for @item, :url => admin_pages_path, :html => { :class => 'form' } do |f| %> + + <%= render :partial => "form", :locals => { :f => f } %> + +

    + <%= f.submit t('create') %> <%= link_back %> +

    + +<% end %> \ No newline at end of file diff --git a/app/views/admin/pages/create.js.erb b/app/views/admin/pages/create.js.erb new file mode 100644 index 00000000..5d59fd1d --- /dev/null +++ b/app/views/admin/pages/create.js.erb @@ -0,0 +1,2 @@ +$('#sidebar').html("<%= escape_javascript(render(:partial => 'admin/items/site_map_left_bar')) %>"); +$('#main').html("<%= escape_javascript(render(:partial => 'admin/pages/show')) %>"); \ No newline at end of file diff --git a/app/views/admin/pages/new.html.erb b/app/views/admin/pages/new.html.erb index 5ba7cae0..cf930b91 100644 --- a/app/views/admin/pages/new.html.erb +++ b/app/views/admin/pages/new.html.erb @@ -1,11 +1,5 @@ -

    <%= t('admin.new_page') %>

    +<% content_for :sidebar do %> + +<% end -%> -<%= form_for :page, :url => admin_pages_path do |f| %> - <%= f.error_messages %> - <%= render :partial => "form", :locals => { :f => f } %> - -

    - <%= f.submit t('create') %> <%= link_back %> -

    - -<% end %> +<%= render 'new' %> \ No newline at end of file diff --git a/app/views/admin/pages/new.js.erb b/app/views/admin/pages/new.js.erb new file mode 100644 index 00000000..7dd4e048 --- /dev/null +++ b/app/views/admin/pages/new.js.erb @@ -0,0 +1 @@ +$('#main').html("<%= escape_javascript(render(:partial => 'admin/pages/new')) %>"); \ No newline at end of file diff --git a/app/views/layouts/content.html.erb b/app/views/layouts/content.html.erb index f3e8d4db..c69eb22a 100644 --- a/app/views/layouts/content.html.erb +++ b/app/views/layouts/content.html.erb @@ -9,8 +9,7 @@ <%= stylesheet_link_tag "easyprint", :media => "print" %> <%= javascript_include_tag :ckeditor %> - <%= javascript_include_tag "jquery", "jquery-ui", "rails", "easy", :cache => 'all' %> - <%= javascript_include_tag "application", :cache => 'all' %> + <%= javascript_include_tag "jquery", "jquery-ui", "rails", "easy", "application", :cache => 'all' %> <%= yield :page_specific_javascript %>