diff --git a/app/assets/javascripts/page_edit.js b/app/assets/javascripts/page_edit.js
index 25348105b..e151b4bfb 100644
--- a/app/assets/javascripts/page_edit.js
+++ b/app/assets/javascripts/page_edit.js
@@ -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();
+});
diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb
index 71e39ae19..1c6b9c563 100644
--- a/app/controllers/admin/page_parts_controller.rb
+++ b/app/controllers/admin/page_parts_controller.rb
@@ -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
diff --git a/app/models/design/theme.rb b/app/models/design/theme.rb
index dd4a6b01f..8aca324b5 100644
--- a/app/models/design/theme.rb
+++ b/app/models/design/theme.rb
@@ -1,7 +1,8 @@
class Theme < Stylesheet
- embedded_in :design
field :name
+ embedded_in :design
+
before_save :set_name
protected
diff --git a/app/models/item.rb b/app/models/item.rb
index dbb86c74b..6bda52090 100644
--- a/app/models/item.rb
+++ b/app/models/item.rb
@@ -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
diff --git a/app/models/module_app.rb b/app/models/module_app.rb
index d96ca6363..5d885cd1d 100644
--- a/app/models/module_app.rb
+++ b/app/models/module_app.rb
@@ -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
diff --git a/app/models/page.rb b/app/models/page.rb
index 3c376b977..59f5e6912 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -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
diff --git a/app/models/page_part.rb b/app/models/page_part.rb
index 667eea48b..9fe91e861 100644
--- a/app/models/page_part.rb
+++ b/app/models/page_part.rb
@@ -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 << "
- <%= f.submit t(:update) %> <%= link_back %> -
-<% end %> \ No newline at end of file diff --git a/app/views/admin/page_parts/_form.html.erb b/app/views/admin/page_parts/_form.html.erb deleted file mode 100644 index 610aeada8..000000000 --- a/app/views/admin/page_parts/_form.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= f.error_messages %> - -<%= f.cktext_area locale, :toolbar=>'Full', :width=>'700px', :height=>'200px'%> \ No newline at end of file diff --git a/app/views/admin/page_parts/edit.html.erb b/app/views/admin/page_parts/edit.html.erb index a03e7ca61..907cc7eb0 100644 --- a/app/views/admin/page_parts/edit.html.erb +++ b/app/views/admin/page_parts/edit.html.erb @@ -2,4 +2,4 @@ <%= render 'admin/items/site_map_left_bar' %> <% end -%> -<%= render @partial %> \ No newline at end of file +<%= render 'edit' %> \ No newline at end of file diff --git a/app/views/admin/page_parts/edit.js.erb b/app/views/admin/page_parts/edit.js.erb index 37367ef26..5dd8351c7 100644 --- a/app/views/admin/page_parts/edit.js.erb +++ b/app/views/admin/page_parts/edit.js.erb @@ -1 +1 @@ -$('#back_main').html("<%= escape_javascript(render(:partial => @partial)) %>"); \ No newline at end of file +$('#back_main').html("<%= j render(:partial => 'edit') %>"); \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index d2d020898..3a7fb91f4 100644 --- a/config/application.rb +++ b/config/application.rb @@ -6,6 +6,7 @@ require "action_controller/railtie" require "action_mailer/railtie" require "active_resource/railtie" require "rails/test_unit/railtie" +require 'sprockets/railtie' # If you have a Gemfile, require the default gems, the ones in the # current environment and also include :assets gems if in development diff --git a/config/list.yml b/config/list.yml index e7e8c41d3..9b3a1a961 100644 --- a/config/list.yml +++ b/config/list.yml @@ -6,3 +6,11 @@ forbidden_item_names: markups: - text_field - select + +public_r_tags: + - ad_banner + +page_part_kinds: + - text + - public_r_tag + - module_widget \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ca6a02fb5..cd3921f00 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -66,7 +66,11 @@ PrototypeR4::Application.routes.draw do get 'reload_frontend_pages' end end - resources :page_parts + resources :page_parts do + member do + get 'reload_widgets' + end + end resources :purchases do collection do get 'install_app' diff --git a/lib/fraisier/layout.html b/lib/fraisier/layout.html index ac6d3c6b3..1f5456312 100644 --- a/lib/fraisier/layout.html +++ b/lib/fraisier/layout.html @@ -18,19 +18,17 @@