widget & frontend field
This commit is contained in:
1 parent
c0cac812c5
commit
d5c55c9697
19 files changed
+604
-100
No files matched your search
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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|
|
||||
|
||||
+19
-1
@@ -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
|
||||
+10
-1
@@ -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
|
||||
@@ -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 %>");
|
||||
$('#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' %>")
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
<span id='widget_style_list'>
|
||||
<%= f.select :widget_style, @widget_style, :selected => @part.widget_style %>
|
||||
<%#= render 'widget_styles' %>
|
||||
</span>
|
||||
|
||||
:
|
||||
@@ -34,14 +33,14 @@
|
||||
</span>
|
||||
|
||||
<span id='widget_field'>
|
||||
|
||||
<%= 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 %> <br />
|
||||
|
||||
<% 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 %> <br />
|
||||
<%# 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} %>
|
||||
</span>
|
||||
|
||||
@@ -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 %> <br />
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
@@ -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 %>
|
||||
@@ -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' %>")
|
||||
@@ -42,15 +42,27 @@
|
||||
<span id="app_page_url">
|
||||
<%= select('page','app_frontend_url', @app_frontend_urls, :selected => @item.app_frontend_url ) rescue ''%>
|
||||
</span>
|
||||
<span id="app_page_frontend_style">
|
||||
<%= select('page','frontend_style', @frontend_style, :selected => @item[:frontend_style], :include_blank => true ) rescue ''%>
|
||||
</span>
|
||||
<span id="app_page_category">
|
||||
<%= select('page','category', @categories.collect{|category| [category.i18n_variable[I18n.locale], category.id]}, :selected => @item[:category], :include_blank => true ) rescue ''%>
|
||||
</span>
|
||||
<span id="app_page_tag">
|
||||
<%= select('page','tag', @tags.collect{|tag| [tag[I18n.locale], tag.id]}, :selected => @item[:tag], :include_blank => true ) rescue ''%>
|
||||
</span>
|
||||
<span id="app_page_frontend_field">
|
||||
<%= render 'frontend_fields' %>
|
||||
</span>
|
||||
<!-- <p class="help-block">In addition to freeform text, any HTML5 text-based input appears like so.</p> -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<%= f.label :frontend_data_count, t('admin.frontend_data_count'), :class => 'control-label' %>
|
||||
<div class="controls">
|
||||
<%= f.text_field :frontend_data_count %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<%= f.label :is_published, "#{t('admin.is_published')} ?", :class => 'control-label' %>
|
||||
<div class="controls">
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
<% if (@module_app && @module_app.widget_fields) %>
|
||||
<%= label_tag('frontend_field & frontend_field_type') %>
|
||||
<% @module_app.widget_fields.each_with_index do |frontend_field, i| %>
|
||||
<%= i+1 %>
|
||||
<%= select_tag "page[frontend_field][]", options_for_select(@module_app.widget_fields.collect{|frontend_field| [frontend_field.humanize, frontend_field]}, (@item[:frontend_field][i][0] if (@item && !@item[:frontend_field].blank? && !@item[:frontend_field][i].blank?)) ), :include_blank => true %>
|
||||
<%= select_tag "page[frontend_field_type][]", options_for_select(LIST[:widget_field_type].collect{|frontend_field| [frontend_field.humanize, frontend_field]}, (@item[:frontend_field][i][1] if (@item && !@item[:frontend_field].blank? && !@item[:frontend_field][i].blank?)) ), :include_blank => true %> <br />
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
|
||||
Reference in new issue
Block a user