diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index e3d8b88a1..4336c2886 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -25,14 +25,14 @@ class Admin::PagePartsController < ApplicationController def edit @part = PagePart.find(params[:id]) @module_apps = ModuleApp.excludes(widgets: nil).where(enable_frontend: true).order_by(:title, :asc) - @module_app = @part.module_app ? @part.module_app : @module_apps[0] + @module_app = @part.module_app ? @part.module_app : nil @user_choose = @part.widget_path @r_tag = @part.public_r_tag.blank? ? LIST[:public_r_tags][0] : @part.public_r_tag @tag_objects = @r_tag.classify.constantize.all rescue nil - @widget_path = @part.widget_path ? @part.widget_path : @module_app.widgets.keys[0] + @widget_path = @part.widget_path ? @part.widget_path : (@module_app.widgets.keys[0] rescue nil) - if @module_app.widgets.any?{|b| b.class == Array} + if @module_app && @module_app.widgets.any?{|b| b.class == Array} @widget_style = @module_app.widgets[@widget_path] if !@widget_path.blank? && !@module_app.widgets.blank? end @@ -49,7 +49,7 @@ class Admin::PagePartsController < ApplicationController when 'archive' @categories = ArchiveFileCategory.all @tags = ArchiveTag.all - end + end if @module_app end def create @@ -61,7 +61,11 @@ class Admin::PagePartsController < ApplicationController params[:page_part][:widget_field] = params[:page_part][:widget_field].zip( params[:page_part][:widget_field_type] ) if params[:page_part][:widget_field] params[:page_part][:widget_field_type] = nil - + + if params[:page_part][:module_app].blank? + params[:page_part][:module_app] = nil + params[:page_part][:kind] = nil + end 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('update.success.content') @@ -93,12 +97,11 @@ class Admin::PagePartsController < ApplicationController def reload_widgets @part = PagePart.find params[:id] @categories =[] - @module_app = ModuleApp.find(params[:module_app_id]) + @module_app = ModuleApp.find(params[:module_app_id]) rescue nil - @widget_path = @module_app.widgets.keys[0] if ( @module_app.widgets[0].blank? ) + @widget_path = @module_app.widgets.keys[0] if (@module_app && @module_app.widgets[0].blank? ) @widget_style = @module_app.widgets[@widget_path] if ( !@widget_path.blank? ) - case @module_app.key when 'announcement' @categories = BulletinCategory.all @@ -112,9 +115,9 @@ class Admin::PagePartsController < ApplicationController when 'archive' @categories = ArchiveFileCategory.all @tags = ArchiveTag.all - end + end if @module_app - @part.widget_path = @module_app.widgets.first if @module_app.needs_to_widget_option? + @part.widget_path = @module_app.widgets.first if( @module_app && @module_app.needs_to_widget_option?) respond_to do |format| format.js {} end diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index bd3dad6ff..e1cd0c0da 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -137,15 +137,15 @@ helper Admin::PagePartsHelper end def reload_frontend_pages - @page = Page.find params[:id] + @page = Page.find params[:id] rescue nil # @categories =[] - @module_app = ModuleApp.find(params[:module_app_id]) + @module_app = ModuleApp.find(params[:module_app_id]) rescue nil - @app_frontend_urls = @module_app.app_pages - @app_frontend_urls << 'default_widget' if @module_app.has_default_widget? + @app_frontend_urls = @module_app.nil? ? nil : @module_app.app_pages + @app_frontend_urls << 'default_widget' if(@module_app && @module_app.has_default_widget?) - case @module_app.key + case (@module_app.nil? ? nil : @module_app.key ) when 'announcement' @categories = BulletinCategory.all @tags = AnnouncementTag.all diff --git a/app/helpers/admin/page_parts_helper.rb b/app/helpers/admin/page_parts_helper.rb index b92531120..36e586051 100644 --- a/app/helpers/admin/page_parts_helper.rb +++ b/app/helpers/admin/page_parts_helper.rb @@ -36,20 +36,35 @@ module Admin::PagePartsHelper end def tag_checked_value(part,radio_value) - part and (part[:tag] == radio_value.to_s) ? true : false + if radio_value.blank? + part[:tag].blank?? true : false + else + part and (part[:tag] == radio_value.to_s) ? true : false + end end - def category_checked_value(part,radio_value) - part and (part[:category] == radio_value.to_s) ? true : false + if radio_value.blank? + part[:category].blank?? true : false + else + part and (part[:category] == radio_value.to_s) ? true : false + end end def style_checked_value(part,radio_value) case part when Page - (part.frontend_style == radio_value) ? true : false + if part.frontend_style.nil? && radio_value == "typeA" + true + else + (part.frontend_style == radio_value) ? true : false + end when PagePart - (part.widget_style == radio_value) ? true : false + if part.widget_style.nil? && radio_value == "typeA" + true + else + (part.widget_style == radio_value) ? true : false + end when nil false end @@ -69,7 +84,7 @@ module Admin::PagePartsHelper end def show_default_widget_setting_panel - if @module_app.has_default_widget? && (!@user_choose.nil? && @user_choose== 'default_widget') #&& @part.widget_path == 'default_widget' + if @module_app && @module_app.has_default_widget? && (!@user_choose.nil? && @user_choose== 'default_widget') #&& @part.widget_path == 'default_widget' true else false diff --git a/app/helpers/default_widget_helper.rb b/app/helpers/default_widget_helper.rb index acab557c5..645f50f07 100644 --- a/app/helpers/default_widget_helper.rb +++ b/app/helpers/default_widget_helper.rb @@ -49,7 +49,8 @@ module DefaultWidgetHelper when nil eval method_entry else - eval("#{method_entry}('#{object}')" ) + object = "'#{object.to_s}'" if object.class == BSON::ObjectId + eval("#{method_entry}(#{object})" ) end end diff --git a/app/models/page_part.rb b/app/models/page_part.rb index ebaac6847..b48c80605 100644 --- a/app/models/page_part.rb +++ b/app/models/page_part.rb @@ -23,6 +23,15 @@ class PagePart before_save :delete_empty_widget_field after_save :update_parent + # def module_app + # if self[:module_app] + # self[:module_app] + # elsif self[:kind] == 'module_widget' + # self.page.module_app + # else + # nil + # end + # end protected @@ -37,5 +46,4 @@ class PagePart self.page.save end - end \ No newline at end of file diff --git a/app/views/admin/page_parts/_custom_widget_setting.html.erb b/app/views/admin/page_parts/_custom_widget_setting.html.erb index 8d1ca8f83..33615e5b6 100644 --- a/app/views/admin/page_parts/_custom_widget_setting.html.erb +++ b/app/views/admin/page_parts/_custom_widget_setting.html.erb @@ -3,14 +3,14 @@ <%= t("default_widget.select_widget_style") %>
- <% if @module_app.widgets.nil? || (@module_app.widgets[@widget_path].blank? rescue true) %> + <% if @module_app.nil? || @module_app.widgets.nil? || (@module_app.widgets[@widget_path].blank? rescue true) %> <%= t("default_widget.no_support_setting")%> <%else%> <%= select('page_part', 'widget_style', @module_app.widgets[@widget_path]) %> <% end %>
- <% if(@module_app.widget_options && @module_app.widget_options.has_key?(@widget_path)) %> + <% if(@module_app && @module_app.widget_options && @module_app.widget_options.has_key?(@widget_path)) %>
diff --git a/app/views/admin/page_parts/_edit.html.erb b/app/views/admin/page_parts/_edit.html.erb index ac44a619e..812f50c77 100644 --- a/app/views/admin/page_parts/_edit.html.erb +++ b/app/views/admin/page_parts/_edit.html.erb @@ -1,10 +1,11 @@ <%= stylesheet_link_tag "admin/default_widget_setting" %> <%= form_for @part, :url => admin_page_part_path(@part),:html=>{:class=>"clear form-horizontal edit_page_part"} do |f| %> - <% LIST[:page_part_kinds].each do |kind| %> + <%= label_tag '',:class=>'checkbox inline' do %> <%= f.radio_button :kind, kind, :class => 'part_kind' %> <%= t(kind, :scope => 'page_part_kinds') %> + <% end %> <% end %> <% LIST[:page_part_kinds].each do |kind| %>
diff --git a/app/views/admin/page_parts/_module_widget.html.erb b/app/views/admin/page_parts/_module_widget.html.erb index 4693e05da..6b62194d7 100644 --- a/app/views/admin/page_parts/_module_widget.html.erb +++ b/app/views/admin/page_parts/_module_widget.html.erb @@ -17,7 +17,7 @@ <%= t "default_widget.select_module_app" %>
- <%= f.select :module_app, options_from_collection_for_select(@module_apps, :id, :title, :selected => @module_app.id), {}, {:rel => admin_page_parts_path,:id=>"page_module_app_id"} %> + <%= f.select :module_app, options_from_collection_for_select(@module_apps, :id, :title, :selected => (@module_app.id rescue nil)), {:include_blank => true }, {:rel => admin_page_parts_path,:id=>"page_module_app_id"} %>
@@ -26,7 +26,7 @@ <%= t "default_widget.select_widget_path" %>
- <%= f.select :widget_path, @module_app.widgets.collect{|k,v| [k.humanize, k]}, {}, { :selected => @part.widget_path, :rel => admin_page_parts_path } %> + <%= f.select :widget_path, @module_app ? @module_app.widgets.collect{|k,v| [k.humanize, k]} : [], {}, { :selected => @part.widget_path, :rel => admin_page_parts_path } %>
diff --git a/app/views/admin/page_parts/_reset.html.erb b/app/views/admin/page_parts/_reset.html.erb new file mode 100644 index 000000000..3698d0f5a --- /dev/null +++ b/app/views/admin/page_parts/_reset.html.erb @@ -0,0 +1,8 @@ +
+ +
+ <%= t('default_widget.no_support_setting') %> +
+
\ 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 c0133f38a..4ac362c61 100644 --- a/app/views/admin/page_parts/reload_widgets.js.erb +++ b/app/views/admin/page_parts/reload_widgets.js.erb @@ -1,13 +1,20 @@ -$('#widget_list select').html("<%= j options_for_select(@module_app.widgets.collect{|k,v| k},@part.widget_path) %>"); -$("#widget_data_source_category").html("<%= j render :partial => 'widget_data_source_category',:locals=>{:object=>@part} %>"); -$("#widget_data_source_tag").html("<%= j render :partial => 'widget_data_source_tag',:locals=>{:object=>@part} %>"); +<% if @module_app%> + $('#widget_list select').html("<%= j options_for_select(@module_app.widgets.collect{|k,v| k},@part.widget_path) %>"); + $("#widget_data_source_category").html("<%= j render :partial => 'widget_data_source_category',:locals=>{:object=>@part} %>"); + $("#widget_data_source_tag").html("<%= j render :partial => 'widget_data_source_tag',:locals=>{:object=>@part} %>"); -<% if !@part.widget_path.blank? %> - <% if show_default_widget_setting_panel %> - $('#widget_setting').html("<%= j render :partial => 'default_widget_style_panel' %>"); - $('#widget_setting').append("<%= j render :partial => 'default_widget_setting',:locals=>{:object=>@part} %>"); - <% elsif show_custom_widget_setting_panel %> - $('#widget_setting').html("<%= j render :partial => 'custom_widget_setting' %>"); + <% if @part %> + <% if show_default_widget_setting_panel %> + $('#widget_setting').html("<%= j render :partial => 'default_widget_style_panel' %>"); + $('#widget_setting').append("<%= j render :partial => 'default_widget_setting',:locals=>{:object=>@part} %>"); + <% elsif show_custom_widget_setting_panel %> + $('#widget_setting').html("<%= j render :partial => 'custom_widget_setting' %>"); + <% end %> <% end %> + <% else %> + $('#widget_option').find("div.well.controls").html("<%= t('default_widget.no_support_setting')%>"); + $('#widget_setting').html("<%=j render :partial=> 'reset',:locals=>{:label_i18n=>'default_widget.select_widget_style'}%>"); + $('#widget_list select').html("<%= j options_for_select([]) %>"); <% end %> + diff --git a/app/views/admin/pages/_custom_frontend_setting.html.erb b/app/views/admin/pages/_custom_frontend_setting.html.erb new file mode 100644 index 000000000..8b52708e5 --- /dev/null +++ b/app/views/admin/pages/_custom_frontend_setting.html.erb @@ -0,0 +1,8 @@ +
+ +
+ <%= t("default_widget.no_support_setting")%> +
+
diff --git a/app/views/admin/pages/_form.html.erb b/app/views/admin/pages/_form.html.erb index 90f32d720..8198cda6b 100644 --- a/app/views/admin/pages/_form.html.erb +++ b/app/views/admin/pages/_form.html.erb @@ -2,9 +2,12 @@ <%= f.hidden_field :parent, :value => (@item.parent.id rescue nil) %>
- <%= f.label :name, t(:name), :class => 'control-label' %> + <%= f.label :name, '*'+t(:name), :class => 'control-label' %> + +
<%= f.text_field :name, :class => 'text input-xlarge' %> + 請輸入數字或英文,不可使用空白
@@ -44,19 +47,12 @@
- <%= f.label '', t("page.select_app_url"), :class => 'control-label' %> + <%= f.label '', t("front_page.select_app_url"), :class => 'control-label' %>
- <%= select('page','app_frontend_url', @app_frontend_urls, :selected => @item.app_frontend_url ) rescue ''%> + <%= select('page','app_frontend_url', @app_frontend_urls || [], :selected => @item.app_frontend_url ) rescue ''%>
-
<%= render :partial=>"admin/page_parts/widget_data_source_category",:locals=>{:object=>@item} %> @@ -72,7 +68,7 @@
- <%= f.label :is_published, "#{t(:is_published)} ?", :class => 'control-label' %> + <%= f.label :is_published, "#{t('front_page.is_published')} ?", :class => 'control-label' %>
- <%= f.label :menu_enabled_for, "#{t(:menu_enabled_for)}:", :class => 'control-label' %> + <%= f.label :menu_enabled_for, "#{t('front_page.menu_enable_lang')}:", :class => 'control-label' %>
<% @site_valid_locales.each do |valid_locale| %>
- <%= f.label :enabled_for, "#{t(:enabled_for)}:", :class => 'control-label' %> + <%= f.label :enabled_for, "#{t('front_page.link_enable_lang')}:", :class => 'control-label' %>
<% @site_valid_locales.each do |valid_locale| %>