diff --git a/app/controllers/admin/module_apps_controller.rb b/app/controllers/admin/module_apps_controller.rb
index 1393bf32..3d0fd896 100644
--- a/app/controllers/admin/module_apps_controller.rb
+++ b/app/controllers/admin/module_apps_controller.rb
@@ -11,6 +11,11 @@ class Admin::ModuleAppsController < ApplicationController
def reload_frontend_pages
@module_app = ModuleApp.find(params[:id])
+
+ @frontend_path = @module_app.widgets.keys[0] if ( !@module_app.widgets.blank? && @module_app.widgets[0].blank? )
+
+ @frontend_style = @module_app.widgets[@frontend_path] if ( !@frontend_path.blank? )
+
case @module_app.key
when 'announcement'
@categories = BulletinCategory.all
diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb
index d75b54aa..294715da 100644
--- a/app/controllers/admin/page_parts_controller.rb
+++ b/app/controllers/admin/page_parts_controller.rb
@@ -49,6 +49,10 @@ class Admin::PagePartsController < ApplicationController
def update
@part = PagePart.find(params[:id])
+
+ params[:page_part][:widget_field] = params[:page_part][:widget_field].zip( params[:page_part][:widget_field_type] )
+ params[:page_part][:widget_field_type] = nil
+
if @part.update_attributes(params[:page_part])
set_children_sub_menu(@part) if @part.public_r_tag && @part.public_r_tag.eql?('sub_menu')
flash.now[:notice] = t('admin.update_success_content')
@@ -74,11 +78,12 @@ class Admin::PagePartsController < ApplicationController
def reload_widgets
@module_app = ModuleApp.find(params[:id])
- @widget_path = @module_app.widgets.keys[0]
- @widget_style = @module_app.widgets[@widget_path]
+ @widget_path = @module_app.widgets.keys[0] if ( @module_app.widgets[0].blank? )
+
+ @widget_style = @module_app.widgets[@widget_path] if ( !@widget_path.blank? )
+
case @module_app.key
when 'announcement'
- # @widget_style = @module_app.widgets['index']
@categories = BulletinCategory.all
@tags = AnnouncementTag.all
when 'news'
diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb
index 5fc6cb77..26a29795 100644
--- a/app/controllers/admin/pages_controller.rb
+++ b/app/controllers/admin/pages_controller.rb
@@ -28,10 +28,19 @@ class Admin::PagesController < ApplicationController
def edit
@item = Page.find(params[:id])
@apps = ModuleApp.excludes(app_pages: nil).entries
+
+ @module_apps = ModuleApp.excludes(widgets: nil).where(enable_frontend: true).order_by(:title, :asc)
+
@designs = Design.all.entries
@design = @item.design ? @item.design : @designs.first
@app_frontend_urls = @item.module_app.app_pages if @item.module_app
+
if @item.module_app
+ @module_app = @item.module_app
+
+ @frontend_path = @item.app_frontend_url ? @item.app_frontend_url : @module_app.widgets.keys[0]
+ @frontend_style = @module_app.widgets[@frontend_path] if !@frontend_path.blank? && !@module_app.widgets.blank?
+
case @item.module_app.key
when 'announcement'
@categories = BulletinCategory.all
@@ -45,6 +54,7 @@ class Admin::PagesController < ApplicationController
end
else
@categories = nil
+ @module_app = @module_apps[0]
end
end
@@ -79,6 +89,9 @@ class Admin::PagesController < ApplicationController
@item.page_contexts.build(:create_user_id => current_user.id, :update_user_id => current_user.id )
end
+ params[:page][:frontend_field] = params[:page][:frontend_field].zip( params[:page][:frontend_field_type] )
+ params[:page][:frontend_field_type] = nil
+
if @item.update_attributes(params[:page])
flash[:notice] = t('admin.update_success_page')
respond_to do |format|
diff --git a/app/models/page.rb b/app/models/page.rb
index 970df4cf..9c7a7e30 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -10,6 +10,10 @@ class Page < Item
field :tag
field :view_count, :type => Integer, :default => 0
+ field :frontend_style
+ field :frontend_field , :type => Array
+ field :frontend_data_count
+
belongs_to :design
belongs_to :module_app
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
@@ -18,7 +22,7 @@ class Page < Item
has_many :page_metas, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :page_parts, :allow_destroy => true
- before_save :create_parts, :set_key
+ before_save :create_parts, :set_key , :delete_empty_frontend_field
# embeds_many :custom_images, :class_name => 'Image', as: :design_image
@@ -53,4 +57,18 @@ class Page < Item
end
end
+ def delete_empty_frontend_field
+
+ if self.frontend_field
+ self.frontend_field.reject! { |ff| (ff[0].blank? || ff[1].blank?) }
+ # self.frontend_field.each do | ff |
+ # if ff[0].blank? || ff[1].blank?
+ # self.frontend_field.delete("") if self.frontend_field
+ # self.frontend_field.delete(ff)
+ # end
+ # end
+ end
+
+ end
+
end
diff --git a/app/models/page_part.rb b/app/models/page_part.rb
index 4d75dbbf..8226426c 100644
--- a/app/models/page_part.rb
+++ b/app/models/page_part.rb
@@ -10,6 +10,7 @@ class PagePart
field :public_r_tag_object_id, :default => nil
field :public_r_tag_option, :default => nil
field :widget_path
+
field :widget_style
field :widget_field , :type => Array
field :widget_data_count
@@ -20,7 +21,7 @@ class PagePart
belongs_to :page
belongs_to :module_app
- before_save :set_key
+ before_save :set_key, :delete_empty_widget_field
def i18n_variable
@i18n_variable ||= I18nVariable.first(:conditions => {:key => 'i18n_variable', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
@@ -36,5 +37,13 @@ class PagePart
title.key = 'title' if title && (title.key.blank? rescue true)
i18n_variable.key = 'i18n_variable' if i18n_variable && (i18n_variable.key.blank? rescue true)
end
+
+ def delete_empty_widget_field
+
+ if self.widget_field
+ self.widget_field.reject! { |wf| (wf[0].blank? || wf[1].blank?) }
+ end
+ # self.widget_field.delete("") if self.widget_field
+ end
end
\ No newline at end of file
diff --git a/app/views/admin/module_apps/reload_frontend_pages.js.erb b/app/views/admin/module_apps/reload_frontend_pages.js.erb
index 2fc90b8e..863e64b2 100644
--- a/app/views/admin/module_apps/reload_frontend_pages.js.erb
+++ b/app/views/admin/module_apps/reload_frontend_pages.js.erb
@@ -1,3 +1,5 @@
$('#app_page_url').html("<%= escape_javascript(select 'page', 'app_frontend_url', @module_app.app_pages) %>");
+$('#app_page_frontend_style').html("<%= escape_javascript(select 'page', 'frontend_style', @module_app.widgets[@frontend_path]) if !@frontend_path.blank? %>");
$('#app_page_category').html("<%= j (select 'page', 'category', @categories.collect{|category| [category.i18n_variable[I18n.locale], category.id]}, {:include_blank => true}) if @categories %>");
-$('#app_page_tag').html("<%= j (select 'page', 'tag', @tags.collect{|tag| [tag[I18n.locale], tag.id]}, {:include_blank => true}) if @tags %>");
\ No newline at end of file
+$('#app_page_tag').html("<%= j (select 'page', 'tag', @tags.collect{|tag| [tag[I18n.locale], tag.id]}, {:include_blank => true}) if @tags %>");
+$('#app_page_frontend_field').html("<%= j render '../admin/pages/frontend_fields' %>")
\ No newline at end of file
diff --git a/app/views/admin/page_parts/_module_widget.html.erb b/app/views/admin/page_parts/_module_widget.html.erb
index 279ba62e..76f06db8 100644
--- a/app/views/admin/page_parts/_module_widget.html.erb
+++ b/app/views/admin/page_parts/_module_widget.html.erb
@@ -20,7 +20,6 @@
<%= f.select :widget_style, @widget_style, :selected => @part.widget_style %>
- <%#= render 'widget_styles' %>
:
@@ -34,14 +33,14 @@
-
- <%= f.label :widget_field %>
- <% @module_app.widget_fields.each_with_index do |widget_field, i| %>
- <%= i+1 %>
- <%= select_tag "page_part[widget_field][]", options_for_select(@module_app.widget_fields.collect{|widget_field| [widget_field.humanize, widget_field]}, (@part.widget_field ? @part.widget_field[i] : nil) ), :include_blank => true %>
-
- <% end %>
+ <%= render 'widget_fields' %>
+
+ <%#= f.label :widget_field %>
+ <%# @module_app.widget_fields.each_with_index do |widget_field, i| %>
+ <%#= i+1 %>
+ <%#= select_tag "page_part[widget_field][]", options_for_select(@module_app.widget_fields.collect{|widget_field| [widget_field.humanize, widget_field]}, (@part.widget_field ? @part.widget_field[i] : nil) ), :include_blank => true %>
+ <%# end %>
<%#= select_tag "page_part[widget_field][]", options_for_select(@module_app.widget_fields.collect{|widget_field| [widget_field.humanize, widget_field]}, @part.widget_field.collect{|widget_field| widget_field}), {:multiple => :multiple, :size => 6} %>
diff --git a/app/views/admin/page_parts/_widget_fields.html.erb b/app/views/admin/page_parts/_widget_fields.html.erb
new file mode 100644
index 00000000..21196b5b
--- /dev/null
+++ b/app/views/admin/page_parts/_widget_fields.html.erb
@@ -0,0 +1,12 @@
+
+ <% if (@module_app && @module_app.widget_fields) %>
+
+ <%= label_tag('widget_field') %>
+
+ <% @module_app.widget_fields.each_with_index do |widget_field, i| %>
+ <%= i+1 %>
+ <%= select_tag "page_part[widget_field][]", options_for_select(@module_app.widget_fields.collect{|widget_field| [widget_field.humanize, widget_field]}, (@part[:widget_field][i][0] if (@part && !@part[:widget_field].blank? && !@part[:widget_field][i].blank?)) ), :include_blank => true %>
+ <%= select_tag "page_part[widget_field_type][]", options_for_select(LIST[:widget_field_type].collect{|widget_field| [widget_field.humanize, widget_field]}, (@part[:widget_field][i][1] if (@part && !@part[:widget_field].blank? && !@part[:widget_field][i].blank?)) ), :include_blank => true %>
+ <% end %>
+
+ <% end %>
\ No newline at end of file
diff --git a/app/views/admin/page_parts/_widget_styles.html.erb b/app/views/admin/page_parts/_widget_styles.html.erb
deleted file mode 100644
index 1f9ef84f..00000000
--- a/app/views/admin/page_parts/_widget_styles.html.erb
+++ /dev/null
@@ -1 +0,0 @@
- <%= select 'page_part', 'widget_style', @widget_style, :selected => (@part ? @part[:widget_style] : nil), :include_blank => true if @widget_style && @widget_style.size > 0 %>
\ No newline at end of file
diff --git a/app/views/admin/page_parts/reload_widgets.js.erb b/app/views/admin/page_parts/reload_widgets.js.erb
index 8dca2040..6d41a9b7 100644
--- a/app/views/admin/page_parts/reload_widgets.js.erb
+++ b/app/views/admin/page_parts/reload_widgets.js.erb
@@ -1,4 +1,5 @@
$('#widget_list select').html("<%= j options_for_select(@module_app.widgets.collect{|k,v| k}) %>")
-$('#widget_style_list select').html("<%= j options_for_select(@module_app.widgets[@widget_path]) %>")
+$('#widget_style_list select').html("<%= j options_for_select( @module_app.widgets[@widget_path] ) if !@widget_path.blank? %>")
+$('#widget_field').html("<%= j render 'widget_fields' %>")
$('#widget_category').html("<%= j render 'widget_categories' %>")
$('#widget_tag').html("<%= j render 'widget_tags' %>")
\ 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 eff3e4df..8b429e55 100644
--- a/app/views/admin/pages/_form.html.erb
+++ b/app/views/admin/pages/_form.html.erb
@@ -42,15 +42,27 @@
<%= select('page','app_frontend_url', @app_frontend_urls, :selected => @item.app_frontend_url ) rescue ''%>
+
+ <%= select('page','frontend_style', @frontend_style, :selected => @item[:frontend_style], :include_blank => true ) rescue ''%>
+
<%= select('page','category', @categories.collect{|category| [category.i18n_variable[I18n.locale], category.id]}, :selected => @item[:category], :include_blank => true ) rescue ''%>
<%= select('page','tag', @tags.collect{|tag| [tag[I18n.locale], tag.id]}, :selected => @item[:tag], :include_blank => true ) rescue ''%>
+
+ <%= render 'frontend_fields' %>
+
+
<%= t('announcement.bulletin.category') %> | -<%= t('announcement.bulletin.title') %> | -<%= t('announcement.bulletin.postdate') %> | -
---|
<%= t("announcement.bulletin.#{ff[0]}") if !ff[0].blank? %> | + <% end %> +
---|
+
+ <% if ff[1] == 'title' %>
+ <%= link_to post.send("#{ff[0]}")[I18n.locale], panel_announcement_front_end_bulletin_path(post, :category_id => post.send("#{post.class.to_s.underscore}_category_id")) %>
+ <% elsif ff[1] == 'date' %>
+ <%= display_date(post.send(ff[0])) %>
+ <% elsif ff[1] == 'category' %>
+ <%= post.send("#{post.class.to_s.underscore}_#{ff[0]}").i18n_variable[I18n.locale] rescue nil %>
+ <% elsif ff[1] == 'img' %>
+ <%= image_tag(post.image.url) %>
+ <% elsif ff[1] == 'text' %>
+ <%#= post.send("#{ff[0]}[#{I18n.locale}]").html_safe %>
+ <%= post.send("#{ff[0]}")[I18n.locale].html_safe %>
+ <% elsif ff[1] == 'status' %>
+ <% if post.is_top? %>
+ <%= t(:top) %>
+ <% end %>
+ <% if post.is_hot? %>
+ <%= t(:hot) %>
+ <% end %>
+ <% elsif ff[1] == 'link' %>
+ <% elsif ff[1] == 'file' %>
+ <% elsif ff[1] == 'tag' %>
+ <% elsif ff[1] == 'viewcount' %>
+ <%= dislpay_view_count(post) %>
+ <% elsif ff[1] == 'host' %>
+ <%= User.from_id(post.update_user_id).name rescue ''%>
+ <% end %>
+
+ |
+
<%= t('announcement.bulletin.category') %> | +<%= t('announcement.bulletin.title') %> | +<%= t('announcement.bulletin.postdate') %> | +
---|---|---|
<%= post.bulletin_category.i18n_variable[I18n.locale] rescue nil %> | +<%= link_to post.title[I18n.locale], panel_announcement_front_end_bulletin_path(post, :category_id => post.bulletin_category_id) %> + <%#= link_to post.title, panel_announcement_back_end_bulletin_path(post) %> + | +<%= display_date_time(post.postdate) %> | +
========== 1 ==========
-<%= t("announcement.bulletin.#{wf[0]}") if !wf[0].blank? %> | <% end %> - - +
---|
+
+ <% if wf[1] == 'title' %>
+ <%= link_to post.send("#{wf[0]}")[I18n.locale], panel_announcement_front_end_bulletin_path(post, :category_id => post.send("#{post.class.to_s.underscore}_category_id")) %>
+ <% elsif wf[1] == 'date' %>
+ <%= display_date(post.send(wf[0])) %>
+ <% elsif wf[1] == 'category' %>
+ <%= post.send("#{post.class.to_s.underscore}_#{wf[0]}").i18n_variable[I18n.locale] rescue nil %>
+ <% elsif wf[1] == 'img' %>
+ <%= image_tag(post.send(wf[0]).url) %>
+ <% elsif wf[1] == 'text' %>
+ <%#= post.send("#{wf[0]}[#{I18n.locale}]").html_safe %>
+ <%= post.send("#{wf[0]}")[I18n.locale].html_safe %>
+ <% elsif wf[1] == 'status' %>
+ <% if post.is_top? %>
+ <%= t(:top) %>
+ <% end %>
+ <% if post.is_hot? %>
+ <%= t(:hot) %>
+ <% end %>
+ <% elsif wf[1] == 'link' %>
+ <% elsif wf[1] == 'file' %>
+ <% elsif wf[1] == 'tag' %>
+ <% elsif wf[1] == 'viewcount' %>
+ <%= dislpay_view_count(post) %>
+ <% elsif wf[1] == 'host' %>
+ <%= User.from_id(post.update_user_id).name rescue ''%>
+ <% end %>
+
+ |
+
========== 2 ==========
-