Changes into page_part edition.
Can choose between 'text', 'public_r_tag' and 'widget'
This commit is contained in:
1 parent
7ea1745f73
commit
e0accbecaa
25 files changed
+119
-179
No files matched your search
@@ -19,3 +19,12 @@ $("#page_module_app_id").live('change', function() {
|
||||
$("#app_page_url").children().remove();
|
||||
}
|
||||
});
|
||||
|
||||
$("#module_app_list select").live('change', function() {
|
||||
$.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_widgets');
|
||||
});
|
||||
|
||||
$('.part_kind').live('click', function() {
|
||||
$('.part_kind_partial').hide();
|
||||
$('#part_' + $(this).attr('value')).show();
|
||||
});
|
||||
@@ -22,15 +22,10 @@ class Admin::PagePartsController < ApplicationController
|
||||
|
||||
def edit
|
||||
@part = PagePart.find(params[:id])
|
||||
case @part.kind
|
||||
when 'text'
|
||||
@i18n_variable = @part.i18n_variable
|
||||
@partial = 'edit_text'
|
||||
@part_locale = params[:part_locale] || I18n.locale.to_s
|
||||
when 'module'
|
||||
@plugins=[{:module=>"Blog",:widgets=>[{:name=>"Blog",:path=>"panel/new_blog/widget_latest_post"},{:name=>"Blog",:path=>"panel/new_blog/widget_index"}]}]
|
||||
when 'snippet'
|
||||
end
|
||||
@module_apps = ModuleApp.all(:conditions => {:enable_frontend => true})
|
||||
@module_app = @part.module_app ? @part.module_app : @module_apps[0]
|
||||
@r_tag = @part.public_r_tag.blank? ? LIST[:public_r_tags][0] : @part.public_r_tag
|
||||
@tag_objects = @r_tag.classify.constantize.all
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -41,7 +36,6 @@ 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 {
|
||||
@@ -59,9 +53,14 @@ class Admin::PagePartsController < ApplicationController
|
||||
def destroy
|
||||
@item = Page.find(params[:id])
|
||||
@item.destroy
|
||||
@item.destroy_i18n_variable
|
||||
|
||||
redirect_to admin_items_url( :parent_id => @item.parent_id )
|
||||
end
|
||||
|
||||
def reload_widgets
|
||||
@module_app = ModuleApp.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.js {}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,7 +1,8 @@
|
||||
class Theme < Stylesheet
|
||||
embedded_in :design
|
||||
field :name
|
||||
|
||||
embedded_in :design
|
||||
|
||||
before_save :set_name
|
||||
|
||||
protected
|
||||
|
||||
+1
-22
@@ -5,7 +5,6 @@ class Item
|
||||
|
||||
field :name, :index => true
|
||||
field :full_name, :index => true
|
||||
field :i18n_variable_id, :type => BSON::ObjectId
|
||||
field :parent_id, :index => true
|
||||
field :parent_name
|
||||
field :position, :type => Integer
|
||||
@@ -17,15 +16,11 @@ class Item
|
||||
validates_presence_of :name, :full_name, :position, :is_published
|
||||
|
||||
belongs_to :parent, :class_name => "Item"
|
||||
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
has_many :children, :class_name => "Item", :as => 'parent'
|
||||
|
||||
before_validation :setup_default_value
|
||||
|
||||
# Destroy the i18n_variable
|
||||
def destroy_i18n_variable
|
||||
self.i18n_variable.destroy rescue nil
|
||||
end
|
||||
|
||||
def self.find_by_name(item_name)
|
||||
Item.first(:conditions => { :name => item_name, :is_published => true })
|
||||
end
|
||||
@@ -37,22 +32,6 @@ class Item
|
||||
nodes.reverse
|
||||
end
|
||||
|
||||
# Update or create the i18n_variable record
|
||||
def i18n_variable=(attr)
|
||||
if self.i18n_variable_id
|
||||
self.i18n_variable.update_attributes(attr) rescue nil
|
||||
else
|
||||
var = I18nVariable.new(attr.merge({:key => self.name, :document_class => self.class}))
|
||||
var.save
|
||||
self.i18n_variable_id = var.id
|
||||
end
|
||||
end
|
||||
|
||||
# Get the i18n_variable
|
||||
def i18n_variable
|
||||
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
|
||||
end
|
||||
|
||||
# Build the url from the array of ancestors
|
||||
def url
|
||||
urls = ancestors.map{ |a| a.name } << self.name
|
||||
|
||||
@@ -10,7 +10,7 @@ class ModuleApp
|
||||
field :intro
|
||||
field :update_info
|
||||
field :create_date
|
||||
field :enable_frontend,type: Boolean
|
||||
field :enable_frontend, type: Boolean, :default => true
|
||||
|
||||
field :app_pages ,type: Array
|
||||
field :widgets ,type: Array
|
||||
@@ -19,6 +19,8 @@ class ModuleApp
|
||||
has_many :sub_managers,as: :sub_managing_app ,:class_name => "AppManager"#, :dependent => :destroy,:foreign_key => "sub_managing_app_id",:inverse_of => :sub_managing_app
|
||||
|
||||
has_many :tags
|
||||
has_many :page_parts
|
||||
has_many :pages
|
||||
|
||||
has_one :app_auth,dependent: :delete
|
||||
|
||||
|
||||
+4
-11
@@ -5,23 +5,16 @@ class Page < Item
|
||||
field :theme_id, :type => BSON::ObjectId, :default => nil
|
||||
|
||||
belongs_to :design
|
||||
has_many :page_parts
|
||||
belongs_to :module_app
|
||||
has_many :page_parts, :autosave => true, :dependent => :destroy
|
||||
accepts_nested_attributes_for :page_parts, :allow_destroy => true
|
||||
|
||||
embeds_many :custom_images, :class_name => 'Image', as: :design_image
|
||||
# embeds_many :custom_images, :class_name => 'Image', as: :design_image
|
||||
|
||||
def create_parts
|
||||
page_design = self.design
|
||||
page_design.layout.layout_parts.each do |p|
|
||||
self.page_parts.create( :name => p.name, :i18n_variable_id => I18nVariable.create.id, :kind => 'text' ) if p.editable?
|
||||
end
|
||||
end
|
||||
|
||||
# Destroy the page_parts
|
||||
def destroy_page_parts
|
||||
self.page_parts.each do |part|
|
||||
part.destroy_i18n_variable
|
||||
part.destroy
|
||||
self.page_parts.create( :name => p.name, :i18n_variable => I18nVariable.create, :kind => 'text' ) if p.editable?
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+6
-34
@@ -6,41 +6,13 @@ class PagePart
|
||||
field :name
|
||||
field :content
|
||||
field :kind
|
||||
field :i18n_variable_id, :type => BSON::ObjectId
|
||||
field :public_r_tag
|
||||
field :public_r_tag_object_id, :type => BSON::ObjectId, :default => nil
|
||||
field :widget_path
|
||||
|
||||
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
|
||||
belongs_to :page
|
||||
|
||||
# Get the i18n_variable
|
||||
def i18n_variable
|
||||
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
|
||||
end
|
||||
|
||||
# Update or create the i18n_variable record
|
||||
def i18n_variable=(attr)
|
||||
if self.i18n_variable_id
|
||||
self.i18n_variable.update_attributes(attr)
|
||||
else
|
||||
var = I18nVariable.new(attr.merge({:key => self.name, :document_class => self.class, :parent_id => self.page.i18n_variable_id}))
|
||||
var.save
|
||||
self.i18n_variable_id = var.id
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_i18n_variable
|
||||
self.i18n_variable.destroy rescue nil
|
||||
end
|
||||
|
||||
# Build the content from the i18n_variable
|
||||
def build_content(locales)
|
||||
res = ''
|
||||
res << "<r:multi_lang i18n_id='#{i18n_variable.id}'>"
|
||||
locales.each do |locale|
|
||||
res << "<r:lang name='#{locale.to_s}'>"
|
||||
res << i18n_variable[locale.to_s]
|
||||
res << "</r:lang>"
|
||||
end
|
||||
res << "</r:multi_lang>"
|
||||
self.content = res
|
||||
end
|
||||
belongs_to :module_app
|
||||
|
||||
end
|
||||
@@ -1 +1 @@
|
||||
<%= f.select :module_app_id, @apps.collect { |t| [t.title.capitalize, t.id] }, {:include_blank => true} ,{:rel => admin_module_apps_path } %>
|
||||
<%= f.select :module_app_id, @apps.collect { |t| [t.title.capitalize, t.id] }, {}, {:rel => admin_module_apps_path } %>
|
||||
@@ -1,17 +0,0 @@
|
||||
<%= flash_messages %>
|
||||
|
||||
<%= render 'language_bar' %>
|
||||
|
||||
|
||||
<%= form_for @part, :url => admin_page_part_path(@part), :html => { :class => 'form' } do |f| %>
|
||||
<%= fields_for "page_part[i18n_variable]", @i18n_variable, :index => nil do |f| %>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<div class="ckeditor_locale" style="display:<%= @part_locale.eql?(locale) ? 'block' : 'none' %>">
|
||||
<%= render :partial => "admin/page_parts/form", :locals => { :f => f, :locale => locale } %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<p>
|
||||
<%= f.submit t(:update) %> <%= link_back %>
|
||||
</p>
|
||||
<% end %>
|
||||
@@ -1,3 +0,0 @@
|
||||
<%= f.error_messages %>
|
||||
|
||||
<%= f.cktext_area locale, :toolbar=>'Full', :width=>'700px', :height=>'200px'%>
|
||||
@@ -2,4 +2,4 @@
|
||||
<%= render 'admin/items/site_map_left_bar' %>
|
||||
<% end -%>
|
||||
|
||||
<%= render @partial %>
|
||||
<%= render 'edit' %>
|
||||
@@ -1 +1 @@
|
||||
$('#back_main').html("<%= escape_javascript(render(:partial => @partial)) %>");
|
||||
$('#back_main').html("<%= j render(:partial => 'edit') %>");
|
||||
Reference in new issue
Block a user