Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Add email-preview cmp
Browse files Browse the repository at this point in the history
  • Loading branch information
njam committed May 11, 2014
1 parent f40525b commit ae42edb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions layout/default/Component/EmailPreview/default.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<iframe class="htmlPreview" src="" width="100%" height="530" frameborder="1"></iframe>
<hr />
<pre>
{$plainText}
</pre>
14 changes: 14 additions & 0 deletions library/CM/Component/EmailPreview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @class CM_Component_EmailPreview
* @extends CM_Component_Abstract
*/
var CM_Component_EmailPreview = CM_Component_Abstract.extend({
_class: 'CM_Component_EmailPreview',

html: null,

ready: function() {
var $iframe = this.$('.htmlPreview');
$iframe.attr('src', 'data:text/html;charset=utf-8,' + encodeURI(this.html));
}
});
21 changes: 21 additions & 0 deletions library/CM/Component/EmailPreview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

class CM_Component_EmailPreview extends CM_Component_Abstract {

public function checkAccessible(CM_Render $render) {
}

public function prepare() {
$email = $this->_params->get('email');
if (!$email instanceof CM_Mail) {
throw new CM_Exception_InvalidParam('Invalid `email` param');
}
$userDefault = $this->_getViewer();
$user = $this->_params->has('user') ? $this->_params->getUser('user') : $userDefault;

$render = new CM_Render(null, $user);
list($subject, $html, $plainText) = $render->render($email);
$this->setTplParam('plainText', $plainText);
$this->_setJsParam('html', $html);
}
}

0 comments on commit ae42edb

Please sign in to comment.