diff --git a/app/models/item.rb b/app/models/item.rb index fe569141..07da2c8f 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -64,6 +64,10 @@ class Item true end end + + def self.structure_ordered_items + self.get_children(Item.root, []) + end protected @@ -87,5 +91,13 @@ class Item def validates_presence_of_parent_id? true end + + def self.get_children(item, tree) + tree << item + item.children.each do |child| + self.get_children(child, tree) + end + tree + end end diff --git a/vendor/built_in_modules/page_content/app/controllers/panel/page_content/back_end/page_contexts_controller.rb b/vendor/built_in_modules/page_content/app/controllers/panel/page_content/back_end/page_contexts_controller.rb index 53822782..9b67fff0 100644 --- a/vendor/built_in_modules/page_content/app/controllers/panel/page_content/back_end/page_contexts_controller.rb +++ b/vendor/built_in_modules/page_content/app/controllers/panel/page_content/back_end/page_contexts_controller.rb @@ -8,7 +8,7 @@ class Panel::PageContent::BackEnd::PageContextsController < OrbitBackendControll #before_filter :is_admin? def index - @page_contexts = (params.has_key?:sort)? get_sorted_and_filtered("page_contexts", {:archived => false}) : PageContext.where(:archived => false).page(params[:page]).per(10) + @page_contexts = (params.has_key?:sort)? get_sorted_and_filtered("page_contexts", {:archived => false}) : get_sorted_page_from_structure respond_to do |format| format.html # index.html.erb @@ -65,7 +65,8 @@ class Panel::PageContent::BackEnd::PageContextsController < OrbitBackendControll respond_to do |format| if @page_context.save - format.html { redirect_to(panel_page_content_back_end_page_contexts_url, :notice => t('page_content.create_page_content_success')) } + # format.html { redirect_to(panel_page_content_back_end_page_contexts_url, :notice => t('page_content.create_page_content_success')) } + format.html { redirect_to(panel_page_content_back_end_page_contexts_url) } format.xml { render :xml => @page_context, :status => :created, :location => @page_context } else format.html { render :action => "new" } @@ -79,29 +80,24 @@ class Panel::PageContent::BackEnd::PageContextsController < OrbitBackendControll def update @page_context = PageContext.find(params[:id]) - if ( @page_context.version > 0 ) - @create_page_context = PageContext.new(:version => @page_context.version) - @create_page_context = @page_context.clone - @create_page_context.context = @page_context.context.clone - @create_page_context.archived = true - end + if ( @page_context.version > 0 ) + @create_page_context = PageContext.new(:version => @page_context.version) + @create_page_context = @page_context.clone + @create_page_context.context = @page_context.context.clone + @create_page_context.archived = true + end @page_context.update_user_id = current_user.id @page_context.version = @page_context.version + 1 respond_to do |format| if @page_context.update_attributes(params[:page_context]) - - if ( @page_context.version > 1 ) - @create_page_context.save - end - - if !params[:page].blank? - format.html { redirect_to(panel_page_content_back_end_page_contexts_url(:page =>params[:page]), :notice => t('page_content.update_page_content_success')) } - else - format.html { redirect_to(panel_page_content_back_end_page_contexts_url, :notice => t('page_content.update_page_content_success')) } - end - format.js { render 'toggle_enable' } + if ( @page_context.version > 1 ) + @create_page_context.save + end + # format.html { redirect_to(panel_page_content_back_end_page_contexts_url(:page =>params[:page]), :notice => t('page_content.update_page_content_success')) } + format.html { redirect_to(panel_page_content_back_end_page_contexts_url(page: params[:page], sort: params[:sort], direction: params[:direction], sort_options: params[:sort_options])) } + format.js { render 'toggle_enable' } format.xml { head :ok } else format.html { render :action => "edit" } @@ -122,5 +118,13 @@ class Panel::PageContent::BackEnd::PageContextsController < OrbitBackendControll format.js end end + + def get_sorted_page_from_structure + page_contexts = Item.structure_ordered_items.inject([]){ |pages, page| + pages << page.page_contexts.where(archived: false).limit(1)[0] if page.is_a?(Page) && !page.page_contexts.blank? + pages + } + Kaminari.paginate_array(page_contexts).page(params[:page]).per(10) + end end diff --git a/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_form.html.erb b/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_form.html.erb index 726c34e4..caef9632 100644 --- a/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_form.html.erb +++ b/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_form.html.erb @@ -38,6 +38,9 @@