On Fri, Jan 21, 2011 at 9:05 AM, WhyNotSmile <[email protected]> wrote:
> In my admin area, I would like to give the user the option to
> 'Preview' the page they are creating or editing. I just can't quite
> get my head around how to do it, so wondered if anyone can advise me.
>
> Ideally, here's what I'd like: the user is editing a page in the admin
> area, and at any time can click a button which says 'Preview'. This
> opens a new window which shows what the page would look like if the
> current information was saved. The user can close the window, edit
> the page some more, and preview it as much as they want.
>
> The issue is this:
>> If I use a 'Preview' button, I can send the current data to the controller
>> and show a page with that data. However, this doesn't let me open the page
>> in a new window. I don't really want the user to have to use the back
>> button, as that interrupts the flow of the process.
>> If I use a Preview link, I can open a new window, but cannot send the data
>> to the page for display.
>
> Has anyone done this before, and can you suggest how I might go about
> it? Would I need to use javascript or ajax? I haven't used Ajax
> before, although I'm happy enough with javascript.
I've done this. It was for an HTML newsletter (yuk!) and I included a
preview button which did exactly this. I used JQuery and the form
plugin to submit the form with AJAX.
$('#newsletter_preview_btn').click(function(e)
{
showIndicator('body');
/* allow editor to update itself
*/
$.wymeditors(0).update();
$(this).parents('form').ajaxSubmit({
url: '/admin/newsletter/preview',
error: function(XMLHttpRequest, textStatus, errorThrown)
{
alert(textStatus);
},
success: function(responseText)
{
hideIndicator();
$('#newsletter_modal').jqmShow().find('#newsletter_modal_content').html(responseText);
}
});
e.preventDefault();
});
So, here, I was using WYMEditor for the markup and JQModal for the
pop-up. Not what I'd use today but this was quite a while ago.
public function admin_preview($id = null)
{
Configure::write('debug', 0);
$this->layout = 'email/html/newsletter';
$this->viewPath = 'elements/email/html';
if (!empty($this->data))
{
$this->Newsletter->save($this->data);
$newsletter = $this->Newsletter->read(null, $id);
}
else if (isset($id))
{
$newsletter = $this->Newsletter->read(null, $id);
}
else
{
return null;
}
$this->set(
'newsletter',
$this->Newsletter->prepareForDelivery($newsletter)
);
$this->render('newsletter');
}
The prepareForDelivery() method just did a bunch of str_replace() to
add inline CSS, etc. I really loathe HTML email.
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php