NEW Include a color syntaxed HTML editor for emailing edition.

This commit is contained in:
Laurent Destailleur 2017-09-01 13:09:13 +02:00
parent 9a0576ff79
commit 61cf69f2bb
5 changed files with 61 additions and 38 deletions

View File

@ -463,7 +463,7 @@ if (empty($reshook))
$object->email_errorsto = trim($_POST["errorsto"]);
$object->titre = trim($_POST["titre"]);
$object->sujet = trim($_POST["sujet"]);
$object->body = trim($_POST["body"]);
$object->body = trim($_POST["bodyemail"]);
$object->bgcolor = trim($_POST["bgcolor"]);
$object->bgimage = trim($_POST["bgimage"]);
@ -560,7 +560,7 @@ if (empty($reshook))
$mesgs = array();
$object->sujet = trim($_POST["sujet"]);
$object->body = trim($_POST["body"]);
$object->body = trim($_POST["bodyemail"]);
$object->bgcolor = trim($_POST["bgcolor"]);
$object->bgimage = trim($_POST["bgimage"]);
@ -686,7 +686,13 @@ $form = new Form($db);
$htmlother = new FormOther($db);
$help_url='EN:Module_EMailing|FR:Module_Mailing|ES:Módulo_Mailing';
llxHeader('',$langs->trans("Mailing"),$help_url);
llxHeader('', $langs->trans("Mailing"), $help_url, '', 0, 0,
array(
'/includes/ace/ace.js',
'/includes/ace/ext-statusbar.js',
'/includes/ace/ext-language_tools.js',
//'/includes/ace/ext-chromevox.js'
), array());
if ($action == 'create')
{
@ -740,7 +746,7 @@ if ($action == 'create')
print '<div style="padding-top: 10px">';
// Editeur wysiwyg
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor=new DolEditor('body',$_POST['body'],'',600,'dolibarr_mailings','',true,true,$conf->global->FCKEDITOR_ENABLE_MAILING,20,'90%');
$doleditor=new DolEditor('bodyemail',GETPOST('bodyemail','none'),'',600,'dolibarr_mailings','',true,true,$conf->global->FCKEDITOR_ENABLE_MAILING,20,'90%');
$doleditor->Create();
print '</div>';
@ -780,7 +786,7 @@ else
}
if ($action != 'edit')
if ($action != 'edit' && $action != 'edithtml')
{
dol_fiche_head($head, 'card', $langs->trans("Mailing"), -1, 'email');
@ -935,7 +941,9 @@ else
if (($object->statut == 0 || $object->statut == 1) && $user->rights->mailing->creer)
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("EditMailing").'</a>';
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("EditWithEditor").'</a>';
if (! empty($conf->use_javascript_ajax)) print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edithtml&amp;id='.$object->id.'">'.$langs->trans("EditHTMLSource").'</a>';
}
//print '<a class="butAction" href="card.php?action=test&amp;id='.$object->id.'">'.$langs->trans("PreviewMailing").'</a>';
@ -1095,7 +1103,7 @@ else
$readonly=1;
// Editeur wysiwyg
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor=new DolEditor('body',$object->body,'',600,'dolibarr_mailings','',false,true,empty($conf->global->FCKEDITOR_ENABLE_MAILING)?0:1,20,120,$readonly);
$doleditor=new DolEditor('bodyemail',$object->body,'',600,'dolibarr_mailings','',false,true,empty($conf->global->FCKEDITOR_ENABLE_MAILING)?0:1,20,120,$readonly);
$doleditor->Create();
}
else print dol_htmlentitiesbr($object->body);
@ -1107,7 +1115,7 @@ else
else
{
/*
* Mailing en mode edition
* Mailing en mode edition (CKeditor or HTML source)
*/
dol_fiche_head($head, 'card', $langs->trans("Mailing"), -1, 'email');
@ -1187,7 +1195,8 @@ else
// Print mail content
print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'emailsubstitionhelp'), 'title_generic');
dol_fiche_head();
dol_fiche_head(null, '', '', -1);
print '<table class="border" width="100%">';
@ -1203,6 +1212,7 @@ else
print '<td colspan="3">';
// List of files
$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
// TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
$out.= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
$out.= '<script type="text/javascript" language="javascript">';
@ -1242,17 +1252,29 @@ else
// Message
print '<div style="padding-top: 10px">';
// Editeur wysiwyg
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor=new DolEditor('body',$object->body,'',600,'dolibarr_mailings','',true,true,$conf->global->FCKEDITOR_ENABLE_MAILING,20,'90%');
$doleditor->Create();
if ($action == 'edit')
{
// Editeur wysiwyg
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor=new DolEditor('bodyemail',$object->body,'',600,'dolibarr_mailings','',true,true,$conf->global->FCKEDITOR_ENABLE_MAILING,20,'90%');
$doleditor->Create();
}
if ($action == 'edithtml')
{
// Editor HTML source
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor=new DolEditor('bodyemail',$object->body,'',600,'dolibarr_mailings','',true,true,'ace',20,'90%');
$doleditor->Create(0, '', false, 'HTML Source', 'php');
}
print '</div>';
dol_fiche_end();
print '<div class="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Save").'" name="save">';
print '<input type="submit" class="button buttonforacesave" value="'.$langs->trans("Save").'" name="save">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input type="submit" class="button" value="'.$langs->trans("Cancel").'" name="cancel">';
print '</div>';

View File

@ -48,20 +48,21 @@ class DolEditor
/**
* Create an object to build an HTML area to edit a large string content
*
* @param string $htmlname HTML name of WYSIWIG field
* @param string $content Content of WYSIWIG field
* @param int $width Width in pixel of edit area (auto by default)
* @param int $height Height in pixel of edit area (200px by default)
* @param string $toolbarname Name of bar set to use ('Full', 'dolibarr_notes[_encoded]', 'dolibarr_details[_encoded]'=the less featured, 'dolibarr_mailings[_encoded]', 'dolibarr_readonly', 'ace').
* @param string $toolbarlocation Where bar is stored :
* 'In' each window has its own toolbar
* 'Out:name' share toolbar into the div called 'name'
* @param boolean $toolbarstartexpanded Bar is visible or not at start
* @param int $uselocalbrowser Enabled to add links to local object with local browser. If false, only external images can be added in content.
* @param boolean|string $okforextendededitor True=Allow usage of extended editor tool if qualified (like fckeditor). If 'textarea', force use of simple textarea. If 'ace', force use of Ace.
* @param int $rows Size of rows for textarea tool
* @param string $cols Size of cols for textarea tool (textarea number of cols '70' or percent 'x%')
* @param int $readonly 0=Read/Edit, 1=Read only
* @param string $htmlname HTML name of WYSIWIG field
* @param string $content Content of WYSIWIG field
* @param int $width Width in pixel of edit area (auto by default)
* @param int $height Height in pixel of edit area (200px by default)
* @param string $toolbarname Name of bar set to use ('Full', 'dolibarr_notes[_encoded]', 'dolibarr_details[_encoded]'=the less featured, 'dolibarr_mailings[_encoded]', 'dolibarr_readonly').
* @param string $toolbarlocation Where bar is stored :
* 'In' each window has its own toolbar
* 'Out:name' share toolbar into the div called 'name'
* @param boolean $toolbarstartexpanded Bar is visible or not at start
* @param int $uselocalbrowser Enabled to add links to local object with local browser. If false, only external images can be added in content.
* @param boolean|string $okforextendededitor True=Allow usage of extended editor tool if qualified (like ckeditor). If 'textarea', force use of simple textarea. If 'ace', force use of Ace.
* Warning: If you use 'ace', don't forget to also include ace.js in page header. Also, the button "save" must have class="buttonforacesave".
* @param int $rows Size of rows for textarea tool
* @param string $cols Size of cols for textarea tool (textarea number of cols '70' or percent 'x%')
* @param int $readonly 0=Read/Edit, 1=Read only
*/
function __construct($htmlname, $content, $width='', $height=200, $toolbarname='Basic', $toolbarlocation='In', $toolbarstartexpanded=false, $uselocalbrowser=true, $okforextendededitor=true, $rows=0, $cols=0, $readonly=0)
{
@ -310,7 +311,7 @@ class DolEditor
'."\n";
$out.= 'jQuery(document).ready(function() {
jQuery("#savefile").click(function() {
jQuery(".buttonforacesave").click(function() {
console.log("We click on savefile button for component '.$this->htmlname.'");
var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid")
console.log(aceEditor.getSession().getValue());

View File

@ -707,6 +707,8 @@ LinkToIntervention=Link to intervention
CreateDraft=Create draft
SetToDraft=Back to draft
ClickToEdit=Click to edit
EditWithEditor=Edit with CKEditor
EditHTMLSource=Edit HTML Source
ObjectDeleted=Object %s deleted
ByCountry=By country
ByTown=By town

View File

@ -15,8 +15,6 @@ EditCss=Edit Style/CSS or HTML header
EditMenu=Edit menu
EditMedias=Edit medias
EditPageMeta=Edit Meta
EditPageSource=Edit HTML Source
EditPageContent=Edit with CKEditor
Website=Web site
AddWebsite=Add website
Webpage=Web page/container

View File

@ -759,7 +759,7 @@ if (($action == 'updatesource' || $action == 'updatecontent' || $action == 'conf
{
$db->begin();
$objectpage->content = GETPOST('PAGE_CONTENT');
$objectpage->content = GETPOST('PAGE_CONTENT','none');
// Clean data. We remove all the head section.
$objectpage->content = preg_replace('/<head>.*<\/head>/s', '', $objectpage->content);
@ -1010,8 +1010,8 @@ if (count($object->records) > 0)
if (in_array($action, array('editcss','editmenu','editmedias')))
{
if (preg_match('/^create/',$action) && $action != 'editmedias') print '<input type="submit" id="savefile" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
if (preg_match('/^edit/',$action) && $action != 'editmedias') print '<input type="submit" id="savefile" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
if (preg_match('/^create/',$action) && $action != 'editmedias') print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
if (preg_match('/^edit/',$action) && $action != 'editmedias') print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
if ($action != 'preview') print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="preview">';
}
@ -1118,8 +1118,8 @@ if (count($object->records) > 0)
print ' &nbsp; ';
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'" name="editmeta">';
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageSource")).'" name="editsource">';
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageContent")).'" name="editcontent">';
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditWithEditor")).'" name="editcontent">';
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditHTMLSource")).'" name="editsource">';
if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print '<input type="submit" class="button" disabled="disabled" value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
else print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("ClonePage")).'" name="createpagefromclone">';
@ -1160,8 +1160,8 @@ if (count($object->records) > 0)
}
if (! in_array($action, array('editcss','editmenu','editmedias','createsite','create','createpagefromclone')))
{
if (preg_match('/^create/',$action)) print '<input type="submit" id="savefile" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
if (preg_match('/^edit/',$action)) print '<input type="submit" id="savefile" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
if (preg_match('/^create/',$action)) print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
if (preg_match('/^edit/',$action)) print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
if ($action != 'preview') print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="preview">';
}