From 0f6f5aafceea6265cb9f589048c82f5d226dc6a7 Mon Sep 17 00:00:00 2001 From: "Matt K. Fu" Date: Thu, 28 Mar 2013 18:29:24 +0800 Subject: [PATCH] fix for both part and page part settings Conflicts: app/helpers/admin/page_parts_helper.rb app/views/admin/pages/reload_front_end_setting.js.erb app/views/admin/pages/reload_frontend_pages.js.erb --- app/assets/javascripts/page_edit.js.erb | 12 +--- .../admin/page_parts_controller.rb | 10 ++- app/controllers/admin/pages_controller.rb | 15 ++++- app/helpers/admin/page_parts_helper.rb | 64 +++++++++---------- app/models/page.rb | 30 ++++++++- app/models/page_part.rb | 39 +++++++---- .../_default_widget_setting.html.erb | 6 +- .../admin/page_parts/_module_widget.html.erb | 2 +- app/views/admin/pages/_app_selector.html.erb | 1 - app/views/admin/pages/_form.html.erb | 6 +- .../admin/pages/_frontend_fields.html.erb | 2 +- app/views/admin/pages/delete.html.erb | 2 +- .../pages/reload_front_end_setting.js.erb | 6 +- .../admin/pages/reload_frontend_pages.js.erb | 14 ++-- config/mongoid.yml | 2 +- config/routes.rb | 6 +- lib/tasks/migrate.rake | 56 ++++++++++++++++ 17 files changed, 185 insertions(+), 88 deletions(-) diff --git a/app/assets/javascripts/page_edit.js.erb b/app/assets/javascripts/page_edit.js.erb index 09326600..3ab9c18c 100644 --- a/app/assets/javascripts/page_edit.js.erb +++ b/app/assets/javascripts/page_edit.js.erb @@ -2,12 +2,6 @@ function get_part_id(){ return $(".edit_page_part,.edit_page").attr("action").split('/').pop(); } -function get_object_path(){ - a = window.location.href.split('/'); - a.pop(); - return a.join('/'); -} - $("div.editable").live("mouseenter mouseleave", function (event) { $(this).children('.edit_link').toggle(); }); @@ -31,11 +25,11 @@ $("#page_design").live('change', function() { // }); $("#module_app_list select").live('change', function() { - $.getScript(get_object_path() + '/reload_after_module_changed?module_app_id='+$(this).val()); //?part_id=' + get_part_id()); + $.getScript($(this).attr('rel') + '?module_app_id='+$(this).val()); //?part_id=' + get_part_id()); }); $("#widget_list select,#frontend_list select").live('change', function() { - $.getScript(get_object_path() +'/reload_after_list_changed?frontend=' + $(this).val() + '&module_app_id=' + $("#module_app_list select").val() );//+ '&part_id=' + get_part_id()); + $.getScript($(this).attr('rel') +'?frontend=' + $(this).val() + '&module_app_id=' + $("#module_app_list select").val() );//+ '&part_id=' + get_part_id()); }); $("#tag_list select").live('change', function() { @@ -43,7 +37,7 @@ $("#tag_list select").live('change', function() { }); $("select.widget_field_select").live('change', function() { - $.getScript(get_object_path() + '/reload_after_widget_field_changed?widget_field_value='+ $(this).val()+'&dom_id=' + $(this).attr("id") + '&field_seri=' +$(this).attr('field_seri')+ '&module_app_id=' +$("#page_module_app_id,page_part_module_app_id").val()); + $.getScript($(this).attr('rel') + '?widget_field_value='+ $(this).val()+'&dom_id=' + $(this).attr("id") + '&field_seri=' +$(this).attr('field_seri')+ '&module_app_id=' +$("#page_module_app_id,page_part_module_app_id").val()); }); $('.part_kind').live('click', function() { diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index a78f72f5..ed1374cc 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -56,10 +56,9 @@ class Admin::PagePartsController < OrbitBackendController 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_is_link] ) if params[:page_part][:widget_field] - - params[:page_part][:widget_field_type] = nil - params[:page_part][:widget_field_is_link] = nil + + # params[:page_part][:widget_field_type] = nil + # params[:page_part][:widget_field_is_link] = nil if params[:page_part][:module_app].blank? params[:page_part][:module_app] = nil @@ -73,8 +72,7 @@ class Admin::PagePartsController < OrbitBackendController params[:page_part][:category] = [] end - params[:page_part][:widget_field].each{|t| t[2] = (t[2]=="true" ? true : false )} if !params[:page_part][:widget_field].blank? - + # params[:page_part][:widget_field].each{|t| t[2] = (t[2]=="true" ? true : false )} if !params[:page_part][:widget_field].blank? 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') diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index 79831849..7d6de997 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -14,6 +14,7 @@ helper Admin::PagePartsHelper @item = Page.new @item.parent = Item.find(params[:parent_id]) rescue nil @apps = ModuleApp.where(:key.in => OrbitApp::Module::FrontendUtility.all.keys) + @module_apps = ModuleApp.excludes(widgets: nil).where(enable_frontend: true).order_by(:title, :asc) @designs = Design.all.entries @design = Design.first end @@ -76,8 +77,10 @@ helper Admin::PagePartsHelper @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] ) if params[:page][:frontend_field] - params[:page][:frontend_field_type] = nil + # params[:page][:frontend_field] = params[:page][:frontend_field].zip( params[:page][:frontend_field_type], params[:page][:frontend_field_is_link] ) if params[:page][:frontend_field] + + # params[:page][:frontend_field_type] = nil + # params[:page][:frontend_field_is_link] = nil if params[:page][:tag].nil? || params[:page][:tag].include?("nil") params[:page][:tag] = [] @@ -87,6 +90,9 @@ helper Admin::PagePartsHelper params[:page][:category] = [] end + # params[:page][:frontend_field].each{|t| t[2] = (t[2]=="true" ? true : false )} if !params[:page][:frontend_field].blank? + + if @item.update_attributes(params[:page]) flash[:notice] = t('update.success.page') respond_to do |format| @@ -127,6 +133,9 @@ helper Admin::PagePartsHelper @app_frontend_urls = @module_app.nil? ? nil : @module_app.app_pages.each{|name,data| [I18n.t(data["i18n"]),name]} @frontend_styles = @module_app.app_pages[params["frontend"]]["style"] rescue nil + # ======= + # @chosen_frontend = @user_choose = params[:frontend] + # >>>>>>> Stashed changes end def get_categories_and_tags @@ -172,7 +181,7 @@ helper Admin::PagePartsHelper def reload_widget_field @index = params[:field_seri].to_i - @item = Page.find params[:id] + @item = params.has_key?(:id) ? Page.find(params[:id] ) : Page.new @choosen_field = params[:widget_field_value] @module_app = @page.module_app @module_app = ModuleApp.find params[:module_app_id] if @module_app.nil? diff --git a/app/helpers/admin/page_parts_helper.rb b/app/helpers/admin/page_parts_helper.rb index 601da3cd..afe26f80 100644 --- a/app/helpers/admin/page_parts_helper.rb +++ b/app/helpers/admin/page_parts_helper.rb @@ -12,43 +12,42 @@ module Admin::PagePartsHelper def get_widget_field_rel(local_item=nil) local_item = @part if local_item.nil? && @part local_item = @item if local_item.nil? && @item - case local_item when Page - admin_pages_path + reload_after_list_changed_admin_pages_path when PagePart - admin_page_parts_path + reload_after_list_changed_admin_page_part_path end end - def link_to_field_switch(i,object_name,field_name,local_item=nil,prefill_value=nil) #link_to_field is for showing - local_item = @part if local_item.nil? && @part - local_item = @item if local_item.nil? && @item - res = '' - choosen_value = prefill_value || (local_item[field_name][i][0] rescue nil) - - if choosen_value - choosen_field_is_link = (@module_app.widget_fields.select{|t| t[0].to_s==choosen_value}.first)[2]==:link - else - choosen_field_is_link = false - end + def link_to_field_switch( i ,object_name,field_name,local_item=nil,assign_field_name_value=nil) #link_to_field is for showing + field_is_checked = nil + local_item = case + when local_item.nil? && @part + @part + when local_item.nil? && @item + @item + end + field_is_checked = local_item.default_widget_field_sat_to_link?(i) + res = hidden_field_tag "#{object_name}[#{field_name}][][sat_to_link]", 'false' - if choosen_field_is_link - value = case local_item - when Page - local_item[:frontend_field][i][2] rescue false - when PagePart - local_item[:widget_field][i][2] rescue false - end + unless field_is_checked.nil? and assign_field_name_value.nil? + origin_field = nil - res = label_tag '' do - check_box_tag("#{object_name}[#{field_name}_is_link][]", "true", value) + I18n.t("default_widget.field_is_link") - end - else # choosen_field_not_link - res = hidden_field_tag "#{object_name}[#{field_name}_is_link][]", 'false' - end # of if choosen_field_is_link + origin_field = @module_app.widget_fields.select{|t| t.first.to_s==(assign_field_name_value || local_item.default_widget_field_name[i])}.first + if origin_field and origin_field[2]==:link #choosen_field_is_link + + res = label_tag '' do + check_box_tag("#{object_name}[#{field_name}][][sat_to_link]", "true", field_is_checked) + I18n.t("default_widget.field_is_link") + end + else # choosen_field_not_link + return res + end # of if choosen_field_is_link + else + return res + end end def widget_field_options(i,local_item=nil) @@ -59,25 +58,24 @@ module Admin::PagePartsHelper label = I18n.t("#{@module_app.key}.default_widget.#{widget_field[0]}") [label, widget_field[0]] end - case local_item when Page - options_for_select(options, (local_item[:frontend_field][i][0] if (local_item && !local_item[:frontend_field].blank? && !local_item[:frontend_field][i].blank?)) ) + options_for_select(options, (local_item.frontend_field_name[i] if(local_item) )) when PagePart - options_for_select(options, (local_item[:widget_field][i][0] if (local_item && !local_item[:widget_field].blank? && !local_item[:widget_field][i].blank?)) ) + options_for_select(options, (local_item.widget_field_name[i] if(local_item) )) end end - def widget_fiield_type_options(i,local_item=nil) + def widget_fiield_class_options(i,local_item=nil) options = LIST[:widget_field_type].collect{|widget_field| [widget_field.humanize, widget_field]} local_item = @part if local_item.nil? && @part local_item = @item if local_item.nil? && @item case local_item when Page - options_for_select(options, (local_item[:frontend_field][i][1] if (local_item && !local_item[:frontend_field].blank? && !local_item[:frontend_field][i].blank?)) ) + options_for_select(options, (local_item.frontend_class[i] if (local_item) )) when PagePart - options_for_select(options, (local_item[:widget_field][i][1] if (local_item && !local_item[:widget_field].blank? && !local_item[:widget_field][i].blank?)) ) + options_for_select(options, (local_item.widget_class[i] if (local_item) )) end end diff --git a/app/models/page.rb b/app/models/page.rb index be9c02e7..91a76de8 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -14,7 +14,12 @@ class Page < Item field :page_title, localize: true field :frontend_style - field :frontend_field , :type => Array + field :frontend_field , :type => Array,:default => [] + + field :frontend_field_name , :type => Array,:default => [] + field :frontend_class , :type => Array,:default => [] + field :frontend_sat_to_link , :type => Array,:default => [] + field :frontend_data_count belongs_to :design @@ -32,6 +37,29 @@ class Page < Item self.save end + def default_widget_field_sat_to_link?(i) + case frontend_sat_to_link[i] + when 'true' + true + when 'false' + false + else + nil + end + end + + def default_widget_field_name + return frontend_field_name + end + + def frontend_field=(settings) + settings.each_with_index do |setting,index| + self.frontend_field_name[index] = setting["field_name"] + self.frontend_class[index] = setting["class"] + self.frontend_sat_to_link[index] = setting["sat_to_link"] + end + end + protected def create_parts diff --git a/app/models/page_part.rb b/app/models/page_part.rb index 4b0d4a8c..c9e54eed 100644 --- a/app/models/page_part.rb +++ b/app/models/page_part.rb @@ -1,5 +1,4 @@ class PagePart - include Mongoid::Document include Mongoid::Timestamps @@ -15,7 +14,12 @@ class PagePart field :tag, type: Array,:default => [] field :widget_style - field :widget_field , :type => Array + field :widget_field , :type => Array,:default => [] + + field :widget_field_name , :type => Array,:default => [] + field :widget_class , :type => Array,:default => [] + field :widget_sat_to_link , :type => Array,:default => [] + field :widget_options ,:type=>Hash field :widget_data_count @@ -25,15 +29,28 @@ 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 + def default_widget_field_sat_to_link?(i) + case widget_sat_to_link[i] + when 'true' + true + when 'false' + false + else + nil + end + end + + def default_widget_field_name + return widget_field_name + end + + def widget_field=(settings) + settings.each_with_index do |setting,index| + self.widget_field_name[index] = setting["field_name"] + self.widget_class[index] = setting["class"] + self.widget_sat_to_link[index] = setting["sat_to_link"] + end + end protected diff --git a/app/views/admin/page_parts/_default_widget_setting.html.erb b/app/views/admin/page_parts/_default_widget_setting.html.erb index 3e7d2689..1cc31024 100644 --- a/app/views/admin/page_parts/_default_widget_setting.html.erb +++ b/app/views/admin/page_parts/_default_widget_setting.html.erb @@ -2,9 +2,11 @@ <% when PagePart %> <% object_name = 'page_part' %> <% field_name = 'widget_field' %> + <% reload_rel = reload_after_widget_field_changed_admin_page_part_path %> <% when Page %> <% object_name = 'page' %> <% field_name = 'frontend_field' %> + <% reload_rel = reload_after_widget_field_changed_admin_pages_path %> <% end %>
@@ -29,10 +31,10 @@
<%= i+1 %> - <%= select_tag "#{object_name}[#{field_name}][]", widget_field_options(i), :include_blank => true ,:class=>'widget_field_select',:field_seri => i ,:id=>"#{object_name}_#{field_name}_#{i}"%> + <%= select_tag "#{object_name}[#{field_name}][][field_name]", widget_field_options(i), :include_blank => true ,:class=>'widget_field_select',:field_seri => i ,:id=>"#{object_name}_#{field_name}_#{i}",:rel=>reload_rel%> - <%= select_tag "#{object_name}[#{field_name}_type][]", widget_fiield_type_options(i), :include_blank => true %>
+ <%= select_tag "#{object_name}[#{field_name}][][class]", widget_fiield_class_options(i), :include_blank => true %>
<%= link_to_field_switch(i,object_name,field_name) %> diff --git a/app/views/admin/page_parts/_module_widget.html.erb b/app/views/admin/page_parts/_module_widget.html.erb index 0862ae29..195584bf 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, :module_name, :selected => (@module_app.id rescue nil)), {:include_blank => true }, {:rel => admin_page_parts_path,:id=>"page_module_app_id"} %> + <%= f.select :module_app, options_from_collection_for_select(@module_apps, :id, :module_name, :selected => (@module_app.id rescue nil)), {:include_blank => true }, {:rel => reload_after_module_changed_admin_page_part_path,:id=>"page_module_app_id"} %>
diff --git a/app/views/admin/pages/_app_selector.html.erb b/app/views/admin/pages/_app_selector.html.erb index 9cb4c694..e69de29b 100644 --- a/app/views/admin/pages/_app_selector.html.erb +++ b/app/views/admin/pages/_app_selector.html.erb @@ -1 +0,0 @@ -<%= f.select :module_app_id, @apps.collect { |t| [t.module_name, t.id] }, {:include_blank => true} ,{:rel => admin_pages_path } %> diff --git a/app/views/admin/pages/_form.html.erb b/app/views/admin/pages/_form.html.erb index e3eb4244..eb4691d7 100644 --- a/app/views/admin/pages/_form.html.erb +++ b/app/views/admin/pages/_form.html.erb @@ -27,7 +27,7 @@
<%= f.label :name, t(:template_name), :class => 'control-label' %>
- <%= f.collection_select :design, @designs, :id, :title, {:selected => @design.id}, {:rel => admin_pages_path} %> + <%= f.collection_select :design, @designs, :id, :title, {:selected => @design.id}, {:rel => reload_themes_admin_pages_path} %>
@@ -42,14 +42,14 @@
<%= f.label '',t("default_widget.select_module_app"), :class => 'control-label' %>
- <%= render :partial => "app_selector", :locals => { :f => f } %> + <%= f.select :module_app_id, options_from_collection_for_select(@module_apps, :id, :module_name, :selected => (@module_app.id rescue nil)), {:include_blank => true }, {:rel => reload_after_module_changed_admin_pages_path,:id=>"page_module_app_id"} %>
<%= 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 || 'default_widget'),:rel => reload_after_list_changed_admin_pages_path}) rescue ''%>
diff --git a/app/views/admin/pages/_frontend_fields.html.erb b/app/views/admin/pages/_frontend_fields.html.erb index ac4882c8..88cb0c60 100644 --- a/app/views/admin/pages/_frontend_fields.html.erb +++ b/app/views/admin/pages/_frontend_fields.html.erb @@ -4,7 +4,7 @@ <% @module_app.widget_fields.each_with_index do |frontend_field, i| %> <%= i+1 %> <%= select_tag "page[frontend_field][]",widget_field_options(i,@item) , :include_blank => true %> - <%= select_tag "page[frontend_field_type][]", widget_fiield_type_options(i,@item), :include_blank => true %>
+ <%= select_tag "page[frontend_field_type][]", widget_fiield_class_options(i,@item), :include_blank => true %>
<% end %> <% end %> diff --git a/app/views/admin/pages/delete.html.erb b/app/views/admin/pages/delete.html.erb index eb9c55c8..9c58189e 100644 --- a/app/views/admin/pages/delete.html.erb +++ b/app/views/admin/pages/delete.html.erb @@ -1,4 +1,4 @@ -<% form_for :page, :url => admin_page_path(@page), :html => { :method => :delete } do |f| %> +<% form_for :page, :url => admin_page_path(@item), :html => { :method => :delete } do |f| %>

<%= t('sure?') %>

<%= submit_tag t(:delete_) %> diff --git a/app/views/admin/pages/reload_front_end_setting.js.erb b/app/views/admin/pages/reload_front_end_setting.js.erb index ea5cb336..521f0ce6 100644 --- a/app/views/admin/pages/reload_front_end_setting.js.erb +++ b/app/views/admin/pages/reload_front_end_setting.js.erb @@ -1,8 +1,6 @@ <% if show_default_widget_setting_panel %> - // $('#app_page_tag').html("<%= j render :partial => 'admin/page_parts/widget_data_source_tag',:locals=>{:object=>@page} %>"); - - $('#frontend_setting').html("<%= j render :partial => 'admin/page_parts/default_widget_style_panel',:locals=>{:object=>@page} %>"); - $('#frontend_setting').append("<%= j render :partial => 'admin/page_parts/default_widget_setting',:locals=>{:object=>@page} %>"); + $('#frontend_setting').html("<%= j render :partial => 'admin/page_parts/default_widget_style_panel',:locals=>{:object=>@item} %>"); + $('#frontend_setting').append("<%= j render :partial => 'admin/page_parts/default_widget_setting',:locals=>{:object=>@item} %>"); <% else %> $('#frontend_setting').html("<%= j render :partial => 'custom_frontend_setting' %>"); <% end %> \ No newline at end of file diff --git a/app/views/admin/pages/reload_frontend_pages.js.erb b/app/views/admin/pages/reload_frontend_pages.js.erb index f262a753..d5e99459 100644 --- a/app/views/admin/pages/reload_frontend_pages.js.erb +++ b/app/views/admin/pages/reload_frontend_pages.js.erb @@ -1,12 +1,12 @@ <% if @module_app %> - $('#app_page_category').html("<%= j render :partial => 'admin/page_parts/widget_data_source_category' ,:locals=>{:object=>@page}%>"); - $('#app_page_tag').html("<%= j render :partial => 'admin/page_parts/widget_data_source_tag',:locals=>{:object=>@page} %>"); - $("#data_count").html("<%= j render :partial => 'admin/pages/data_count_field',:locals=>{:field_name=>'page[frontend_data_count]',:field_value=>(@page.frontend_data_count rescue nil)} %>"); + $('#app_page_category').html("<%= j render :partial => 'admin/page_parts/widget_data_source_category' ,:locals=>{:object=>@item}%>"); + $('#app_page_tag').html("<%= j render :partial => 'admin/page_parts/widget_data_source_tag',:locals=>{:object=>@item} %>"); + $("#data_count").html("<%= j render :partial => 'admin/pages/data_count_field',:locals=>{:field_name=>'page[frontend_data_count]',:field_value=>(@item.frontend_data_count rescue nil)} %>"); - <% if !@module_app.app_pages.blank? %> - $('#app_page_url').html("<%= escape_javascript(select 'page', 'app_frontend_url', options_for_select(@app_frontend_urls, @app_frontend_urls.first)) %>"); - <%else %> - $('#app_page_url').html("<%= t('default_widget.no_support_setting')%>"); + <% if !@module_app.app_pages.blank? or @module_app.has_default_widget? %> + $('#app_page_url').html("<%= escape_javascript(select 'page', 'app_frontend_url', options_for_select(@app_frontend_urls, (@item.app_frontend_url || 'default_widget')),{},{:rel => reload_after_list_changed_admin_pages_path}) %>"); + <% else %> + $('#app_page_url').html("

<%= t('default_widget.no_support_setting')%>
"); <% end %> <% if @app_frontend_urls.first =='default_widget' %> diff --git a/config/mongoid.yml b/config/mongoid.yml index 2fa55a36..ac9bf557 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -1,5 +1,5 @@ defaults: &defaults - host: localhost + host: 192.168.1.105 # slaves: # - host: slave1.local port: 27017 diff --git a/config/routes.rb b/config/routes.rb index 058c213d..2e2dc8a5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -82,15 +82,13 @@ Orbit::Application.routes.draw do resources :pages do collection do + get 'reload_themes' get 'reload_after_module_changed', :action=>'reload_frontend_pages' get 'reload_after_list_changed',:action=> 'reload_front_end_setting' + get 'reload_after_widget_field_changed',:action=> 'reload_widget_field' end member do get 'delete' - get 'reload_themes' - get 'reload_after_module_changed',:action=>'reload_frontend_pages' - get 'reload_after_list_changed',:action=> 'reload_front_end_setting' - get 'reload_after_widget_field_changed',:action=> 'reload_widget_field' end end diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake index 1c3e35ab..69658869 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -246,4 +246,60 @@ namespace :migrate do end end + task :backup_page_frontend_setting => :environment do + Page.all.each do |page| + if page.frontend_field and page.frontend_field.collect{|t| t.class}.include?(Array) + page["temp_frontend_setting"] = page.frontend_field + end + page.save + end + end + + # task :correct_page_frontend_setting => :environment do + # Page.all.each do |page| + # page.frontend_field = {} + # if page["temp_frontend_setting"] and page["temp_frontend_setting"].collect{|t| t.class}.include?(Array) + # page["temp_frontend_setting"].each_with_index do |old_frontend_setting,index| + # for_a_field={ + # :field_name=>old_frontend_setting[0], + # :field_type=> old_frontend_setting[1], + # :set_to_link=>old_frontend_setting[2] + # } + # page.frontend_field << for_a_field + # end #of each_with_index + # end # of if Array + # binding.pry unless page.frontend_field.blank? + # page.save + # end #of each page + # end #of task + + task :migrate_from_one_frontend_field_to_three_fields => :environment do + Page.all.each do |page| + page.frontend_field_name = [] + page.frontend_class = [] + page.frontend_sat_to_link = [] + if page.frontend_field and page.frontend_field.collect{|t| t.class}.include?(Array) + page.frontend_field.each_with_index do |old_frontend_setting,index| + page.frontend_field_name << old_frontend_setting[0] + page.frontend_class << old_frontend_setting[1] + page.frontend_sat_to_link << old_frontend_setting[2] + end + end + page.save + end + end + + task :clean_page_frontend_setting => :environment do + Page.all.each do |page| + if page.frontend_field and page.frontend_field.collect{|t| t.class}.include?(Array) + + else + page.frontend_field = [] + end + + page.unset :temp_frontend_setting + page.unset :frontend_field_is_link + page.save + end + end end