Class: EditAction

Inherits:
WebAction show all
Includes:
Assert, Localization
Defined in:
lib/ribit/action.rb

Constant Summary collapse

ID =
'edit'

Constants included from Localization

Localization::ACTION_CATEGORY_CREATION_NOTICE, Localization::ACTION_DEFAULT_PAGE_FAILED, Localization::ACTION_EDIT_CANCELED, Localization::ACTION_NEW_PAGE_OK, Localization::ACTION_SAVE_CATEGORY_OK, Localization::ACTION_SAVE_OK, Localization::NO_PARENT_OPTION, Localization::TITLE_CATEGORIES_PAGE, Localization::TITLE_NEW_CATEGORY, Localization::TITLE_NEW_PAGE

Instance Attribute Summary

Attributes inherited from WebAction

#id

Instance Method Summary collapse

Methods included from Localization

#get_localized, #ribitData_defined?

Methods included from Assert

assert, #assert, assert_nil, #assert_nil, #assert_not_nil, assert_not_nil, raise_exception

Methods inherited from WebAction

#add_headers

Constructor Details

#initialize(ribitData, ribitConfig) ⇒ EditAction

Returns a new instance of EditAction.



609
610
611
612
613
614
615
616
617
# File 'lib/ribit/action.rb', line 609

def initialize( ribitData, ribitConfig )
  assert_not_nil( ribitData, 'RibitData is nil' )
  assert_not_nil( ribitConfig, 'RibitConfig' )
  
  @id = ID
  @ribitData = ribitData
  @ribitConfig = ribitConfig
  @logger = RibitLogger.new( EditAction )
end

Instance Method Details

#run(pageRequest, pageResponse) ⇒ Object



620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
# File 'lib/ribit/action.rb', line 620

def run( pageRequest, pageResponse )
  super( pageRequest, pageResponse )
  
  # get page id and show the edit page
  pageID = pageRequest.get_requested_page_id
  
  if ( pageID == nil )
    raise RibitException, 'No page ID defined for EditAction', caller
  end
  
  if ( pageID == Constants::NEW_PAGE_ID )
    # we don't have data in ribitData, so we need add necessary stuff form
    # - name
    # - category
    @logger.debug( 'building edit page for non-existent page' )
    
    # build empty page
    previousPageID = pageRequest.get_request_param( Constants::PREV_REQUEST_PARAM_NAME )
    page = EditPage.new( @ribitData, pageID, previousPageID, @ribitConfig )
    
    # add name + category info
    name = pageRequest.get_request_param( Constants::PAGE_NAME_REQUEST_PARAM_NAME )
    if ( name == nil )
      raise RibitException, 'No \'name\' defined in request', caller
    end
    
    category = pageRequest.get_request_param( Constants::CATEGORY_REQUEST_PARAM_NAME )
    if ( category == nil )
      raise RibitException, 'No \'category\' defined in request', caller
    end
    
    page.add_form_action_params( Constants::PAGE_NAME_REQUEST_PARAM_NAME, name  );
    page.add_form_action_params( Constants::CATEGORY_REQUEST_PARAM_NAME, category );
    
    if ( @ribitData.get_category_by_full_name( category ) == nil )
      page.set_message( get_localized( ACTION_CATEGORY_CREATION_NOTICE, {'category' => category } ) )
    end
  
  elsif ( @ribitData.get_page_by_id( pageID ) == nil )
    raise RibitException, "No page for ID=#{pageID}", caller
  else
    @logger.debug( "building edit page for ID=#{pageID}" )
    page = EditPage.new( @ribitData, pageID, pageID, @ribitConfig )  
  end
  
  add_headers( page )
  page.output_page( pageResponse )
  
end