forked from Wavyzz/dolibarr
NEW preview exemple page in website when create page
This commit is contained in:
@@ -175,7 +175,6 @@ class FormWebsite
|
||||
$langs->load("admin");
|
||||
|
||||
$listofsamples = dol_dir_list(DOL_DOCUMENT_ROOT.'/website/samples', 'files', 0, '^page-sample-.*\.html$');
|
||||
|
||||
$arrayofsamples = array();
|
||||
$arrayofsamples['empty'] = 'EmptyPage'; // Always this one first
|
||||
foreach ($listofsamples as $sample) {
|
||||
@@ -189,6 +188,7 @@ class FormWebsite
|
||||
$arrayofsamples[$key] = $labelkey;
|
||||
}
|
||||
}
|
||||
var_dump($arrayofsamples);exit;
|
||||
|
||||
$out = '';
|
||||
$out .= '<select id="select'.$htmlname.'" class="selectSampleOfContainer'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
|
||||
@@ -307,4 +307,87 @@ class FormWebsite
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return HTML code for selection of page layout
|
||||
* @param string $htmlContent HTML name of WYSIWIG field
|
||||
* @return string HTML for model page boxes
|
||||
*/
|
||||
public function getContentPageTemplate($htmlContent = 'message')
|
||||
{
|
||||
global $user, $langs;
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/emaillayout.lib.php';
|
||||
|
||||
$listofsamples = dol_dir_list(DOL_DOCUMENT_ROOT.'/website/samples', 'files', 0, '^page-sample-.*\.html$');
|
||||
$arrayofsamples = array();
|
||||
$arrayofsamples['empty'] = 'EmptyPage'; // Always this one first
|
||||
foreach ($listofsamples as $sample) {
|
||||
$reg = array();
|
||||
if (preg_match('/^page-sample-(.*)\.html$/', $sample['name'], $reg)) {
|
||||
$key = $reg[1];
|
||||
$labelkey = ucfirst($key);
|
||||
if ($key == 'empty') {
|
||||
$labelkey = 'EmptyPage';
|
||||
}
|
||||
$arrayofsamples[$key] = $labelkey;
|
||||
}
|
||||
}
|
||||
|
||||
$out = '<div id="template-selector" class="template-container hidden">';
|
||||
|
||||
$templates = array(
|
||||
'empty' => 'empty',
|
||||
'text' => 'dynamic',
|
||||
'basic' => 'basic',
|
||||
'news' => 'news',
|
||||
'commerce' => 'commerce',
|
||||
);
|
||||
|
||||
|
||||
|
||||
foreach ($templates as $template => $templateFunction) {
|
||||
if ($template == 'text') {
|
||||
$substitutionarray = array();
|
||||
$substitutionarray['__WEBSITE_CREATE_BY__'] = $user->getFullName($langs);
|
||||
|
||||
$pathtoTemplateFile = DOL_DOCUMENT_ROOT.'/website/samples/page-sample-'.dol_sanitizeFileName(strtolower($arrayofsamples['dynamiccontent'])).'.html';
|
||||
$contentHtml = file_exists($pathtoTemplateFile) ? make_substitutions(@file_get_contents($pathtoTemplateFile), $substitutionarray) : '';
|
||||
} else {
|
||||
$contentHtml = getHtmlOfLayout($template);
|
||||
}
|
||||
|
||||
$out .= '<div class="template-option" data-template="'.$template.'" data-content="'.htmlentities($contentHtml).'">';
|
||||
$out .= '<img class="maillayout" alt="'.$template.'" src="'.DOL_URL_ROOT.'/theme/common/maillayout/'.$template.'.png" />';
|
||||
if ($template == 'text') {
|
||||
$out .= '<input type="hidden" name="sample" value="'.$arrayofsamples['dynamiccontent'].'" />';
|
||||
}
|
||||
if ($template == 'empty') {
|
||||
$out .= '<input type="hidden" name="sample" value="" />';
|
||||
}
|
||||
$out .= '<span class="template-option-text">'.($template != 'text' ? ucfirst($template) : ucfirst($templateFunction)).'</span>';
|
||||
$out .= '</div>';
|
||||
}
|
||||
$out .= '</div>';
|
||||
|
||||
$out .= "<script type='text/javascript'>
|
||||
$(document).ready(function() {
|
||||
$('.template-option').click(function() {
|
||||
$('.template-option').removeClass('selected');
|
||||
$(this).addClass('selected');
|
||||
|
||||
var template = $(this).data('template');
|
||||
var contentHtml = $(this).data('content');
|
||||
|
||||
var editorInstance = CKEDITOR.instances.".$htmlContent.";
|
||||
if (editorInstance) {
|
||||
editorInstance.setData(contentHtml);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>";
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,3 +235,4 @@ WebPortalPartnership=Partnership
|
||||
WebPortalPropal=Proposal
|
||||
WebPortalGroupMenuAdmin=Administration
|
||||
WebPortalGroupMenuTechnical=System
|
||||
PreviewPageContent=Page content
|
||||
|
||||
@@ -51,6 +51,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||
|
||||
|
||||
// Load translation files required by the page
|
||||
$langs->loadLangs(array("admin", "other", "website", "errors"));
|
||||
@@ -1183,8 +1185,7 @@ if ($action == 'addcontainer' && $usercanedit) {
|
||||
$sample = 'empty';
|
||||
}
|
||||
|
||||
$pathtosample = DOL_DOCUMENT_ROOT.'/website/samples/page-sample-'.dol_sanitizeFileName($sample).'.html';
|
||||
|
||||
$pathtosample = DOL_DOCUMENT_ROOT.'/website/samples/page-sample-'.dol_sanitizeFileName(strtolower($sample)).'.html';
|
||||
// Init content with content into pagetemplate.html, blogposttempltate.html, ...
|
||||
$objectpage->content = make_substitutions(@file_get_contents($pathtosample), $substitutionarray);
|
||||
}
|
||||
@@ -4288,10 +4289,68 @@ if ($action == 'editmeta' || $action == 'createcontainer') { // Edit properties
|
||||
|
||||
// Example/templates of page
|
||||
if ($action == 'createcontainer') {
|
||||
$formmail = new FormMail($db);
|
||||
$formmail->withaiprompt = 'html';
|
||||
|
||||
|
||||
print '<tr><td class="titlefield fieldrequired">';
|
||||
print $langs->trans('WEBSITE_PAGE_EXAMPLE');
|
||||
print '</td><td>';
|
||||
print $formwebsite->selectSampleOfContainer('sample', (GETPOSTISSET('sample') ? GETPOST('sample', 'alpha') : 'empty'), 0, '', 1, 'minwidth300');
|
||||
|
||||
$out = '';
|
||||
// Add link to add layout
|
||||
$out .= '<a href="#" id="linkforlayouttemplates" class="reposition notasortlink inline-block alink marginrightonly">';
|
||||
$out .= img_picto($langs->trans("FillMessageWithALayout"), 'layout', 'class="paddingrightonly"');
|
||||
$out .= $langs->trans("FillMessageWithALayout").'...';
|
||||
$out .= '</a> ';
|
||||
|
||||
$out .= '<script>
|
||||
$(document).ready(function() {
|
||||
$("#linkforlayouttemplates").click(function() {
|
||||
console.log("We click on linkforlayouttemplates");
|
||||
event.preventDefault();
|
||||
jQuery("#template-selector").toggle();
|
||||
//jQuery("#template-selector").attr("style", "aaa");
|
||||
jQuery("#ai_input").hide();
|
||||
jQuery("#pageContent").show();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
';
|
||||
|
||||
// Add link to add AI content
|
||||
if ($formmail->withaiprompt && isModEnabled('ai')) {
|
||||
$out .= '<a href="#" id="linkforaiprompt" class="reposition notasortlink inline-block alink marginrightonly">';
|
||||
$out .= img_picto($langs->trans("FillMessageWithAIContent"), 'ai', 'class="paddingrightonly"');
|
||||
$out .= $langs->trans("FillMessageWithAIContent").'...';
|
||||
$out .= '</a>';
|
||||
$out .= '<script>
|
||||
$(document).ready(function() {
|
||||
$("#linkforaiprompt").click(function() {
|
||||
console.log("We click on linkforaiprompt");
|
||||
event.preventDefault();
|
||||
jQuery("#ai_input").toggle();
|
||||
jQuery("#template-selector").hide();
|
||||
if (!jQuery("ai_input").is(":hidden")) {
|
||||
console.log("Set focus on input field");
|
||||
jQuery("#ai_instructions").focus();
|
||||
if (!jQuery("pageContent").is(":hidden")) {
|
||||
jQuery("#pageContent").show();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
$out .= $formwebsite->getContentPageTemplate('content', $objectpage->content);
|
||||
|
||||
if ($formmail->withaiprompt && isModEnabled('ai')) {
|
||||
$out .= $formmail->getSectionForAIPrompt('', 'content');
|
||||
}
|
||||
print $out;
|
||||
//var_dump(GETPOST('sample'));
|
||||
//print $formwebsite->selectSampleOfContainer('sample', (GETPOSTISSET('sample') ? GETPOST('sample', 'alpha') : 'empty'), 0, '', 1, 'minwidth300');
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
@@ -4521,6 +4580,13 @@ if ($action == 'editmeta' || $action == 'createcontainer') { // Edit properties
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
print '<tr id="pageContent" class="hideobject"><td>';
|
||||
print $langs->trans('PreviewPageContent');
|
||||
print '</td><td>';
|
||||
$doleditor = new DolEditor('content', GETPOST('content', 'restricthtmlallowunvalid'), '', 600, 'dolibarr_mailings', '', true, true, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '90%');
|
||||
$doleditor->Create();
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td class="tdhtmlheader tdtop">';
|
||||
$htmlhelp = $langs->trans("EditTheWebSiteForACommonHeader").'<br><br>';
|
||||
$htmlhelp .= $langs->trans("Example").' :<br>';
|
||||
|
||||
Reference in New Issue
Block a user