App-Office-CMS

 view release on metacpan or  search on metacpan

lib/App/Office/CMS/Controller/Page.pm  view on Meta::CPAN


		if ($message)
		{
			$result = $self -> build_error_result($page, $message, $target_div);
		}
		else
		{
			# Success.
			# Note: If the user typed in a new site name, this will
			# call add for the site (effectively) and add for the design.
			# Note: If the user typed in a new design name, this will
			# call update for the site and add for the design.

			$self -> param('db') -> site -> update($site, $design);

			$page    = $self -> edit($site, $design);
			$message = $self -> param('view') -> page -> edit($site, $design, $page);
			$result  = $self -> build_success_result('display', $page, $message, 'update_page_div');
		}
	}
	catch
	{
		$result = $self -> build_error_result($page, $_, $target_div);
	};

	# update_page_div is always on screen (under the Edit Pages tab).
	# It appears there by virtue of being within Initialize.build_head_init().
	# update_site_message_div is on screen (under the Edit Site tab),
	# because we're displaying a site with an Edit button.
	# It appears there by virtue of being within search.tx.

	return JSON::XS -> new -> utf8 -> encode({results => $result});

} # End of display.

# -----------------------------------------------

sub edit
{
	my($self, $site, $design) = @_;

	$self -> log(debug => 'edit()');

	# Default to homepage, if any.

	my($page) = $self -> param('db') -> page -> get_homepage($$site{id}, $$design{id});

	# We save some data so various other subs have access to it.
	# We don't put these in a hidden form field, to stop tampering.

	$self -> param('session') -> param(edit_design_id => $$design{id});
	$self -> param('session') -> param(edit_page_id   => $$page{id});
	$self -> param('session') -> param(edit_site_id   => $$site{id});

	return $page;

} # End of edit.

# -----------------------------------------------

sub update
{
	my($self) = @_;

	$self -> log(debug => 'update()');

	# These keys are used in the return statement,
	# but should only be displayed in case of error.

	my($page) =
	{
		curent_page => 'N/A',
		homepage    => 'No',
		page_name   => 'N/A',
	};
	my($target_div) = 'update_page_message_div';

	my($result);

	try
	{
		my($asset);
		my($message);

		($message, $page, $asset) = $self -> process_page_form('update');

		if (! $message)
		{
			# Success.
			# Note: If the user typed in a new page name, this will
			# call add for the page.

			$message = $self -> param('db') -> page -> update($page, $asset);
			$result  = $self -> build_success_result('update', $page, $message, $target_div);
		}
	}
	catch
	{
		$result = $self -> build_error_result($page, $_, $target_div);
	};

	# update_page_message_div is on screen (under the Edit Pages tab),
	# because we're displaying a page using page.tx.

	return JSON::XS -> new -> utf8 -> encode({results => $result});

} # End of update.

# -----------------------------------------------

1;



( run in 0.838 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )