Documents: Add save button inside ckeditor see BT#17378

pull/3308/head
Julio Montoya 6 years ago
parent efd096f9c8
commit fdffabda66
  1. 48
      main/document/create_document.php
  2. 19
      main/document/edit_document.php
  3. 8
      src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/Documents.php

@ -16,6 +16,7 @@ $this_section = SECTION_COURSES;
$groupRights = Session::read('group_member_with_upload_rights');
$htmlHeadXtra[] = '
<script>
$(function() {
$(".scrollbar-light").scrollbar();
@ -29,6 +30,11 @@ $(function() {
CKEDITOR.on("instanceReady", function (e) {
showTemplates();
e.editor.on("beforeCommandExec", function (event) {
if (event.data.name == "save") {
$("#create_document").append("<input type=hidden name=button_ck value=1 />");
}
});
});
});
@ -57,7 +63,6 @@ $(window).on("load", function () {
//I'm in the certification module?
$is_certificate_mode = false;
if (isset($_REQUEST['certificate']) && $_REQUEST['certificate'] == 'true') {
$is_certificate_mode = true;
}
@ -102,14 +107,13 @@ if (!empty($groupId)) {
}
if (empty($document_data)) {
$dir = '/';
$folder_id = 0;
if (api_is_in_group()) {
$document_id = DocumentManager::get_document_id($_course, $group_properties['directory']);
$document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
$dir = $document_data['path'];
$folder_id = $document_data['id'];
} else {
$dir = '/';
$folder_id = 0;
}
} else {
$folder_id = $document_data['id'];
@ -243,7 +247,7 @@ if (isset($group_properties)) {
$display_dir = implode('/', $display_dir);
}
$select_cat = isset($_GET['selectcat']) ? intval($_GET['selectcat']) : null;
$select_cat = isset($_REQUEST['selectcat']) ? (int) $_REQUEST['selectcat'] : null;
$curDirPath = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : null;
// Create a new form
@ -257,7 +261,8 @@ $form = new FormValidator(
// form title
$form->addElement('header', $nameTools);
if ($is_certificate_mode) {//added condition for certicate in gradebook
if ($is_certificate_mode) {
//added condition for certicate in gradebook
$form->addElement(
'hidden',
'certificate',
@ -508,18 +513,9 @@ if ($form->validate()) {
// Setting the title
$title = $values['title'];
// Setting the extension
$extension = 'html';
$content = Security::remove_XSS($values['content'], COURSEMANAGERLOWSECURITY);
/*if (strpos($content, '/css/frames.css') == false) {
$content = str_replace('</head>', '<link rel="stylesheet" href="./css/frames.css" type="text/css" /><style> body{margin:50px;}</style></head>', $content);
}*/
// Don't create file with the same name.
if (file_exists($filepath.$filename.'.'.$extension)) {
Display::addFlash(Display::return_message(get_lang('FileExists').' '.$title, 'error', false));
Display:: display_header($nameTools, 'Doc');
@ -599,17 +595,24 @@ if ($form->validate()) {
$certificate_condition = '&certificate=true&curdirpath=/certificates';
}
Display::addFlash(Display::return_message(get_lang('ItemAdded')));
header('Location: document.php?'.api_get_cidreq().'&id='.$folder_id.$selectcat.$certificate_condition);
$url = 'document.php?'.api_get_cidreq().'&id='.$folder_id.$selectcat.$certificate_condition;
$redirectToEditPage = isset($_POST['button_ck']) && 1 === (int) $_POST['button_ck'];
if ($redirectToEditPage) {
$url = 'edit_document.php?'.api_get_cidreq().'&id='.$document_id.$selectcat.$certificate_condition;
}
header('Location: '.$url);
exit();
} else {
Display::addFlash(Display::return_message(get_lang('Impossible'), 'error'));
Display :: display_header($nameTools, 'Doc');
Display :: display_footer();
Display::display_header($nameTools, 'Doc');
Display::display_footer();
}
} else {
Display::addFlash(Display::return_message(get_lang('Impossible'), 'error'));
Display :: display_header($nameTools, 'Doc');
Display :: display_footer();
Display::display_header($nameTools, 'Doc');
Display::display_footer();
}
} else {
// Copied from document.php
@ -636,10 +639,11 @@ if ($form->validate()) {
Display :: display_header($nameTools, "Doc");
// link back to the documents overview
if ($is_certificate_mode) {
$actionsLeft = '<a href="document.php?'.api_get_cidreq().'&certificate=true&id='.$folder_id.'&selectcat='.Security::remove_XSS($_GET['selectcat']).'">'.
$actionsLeft = '<a href="document.php?'.api_get_cidreq().'&certificate=true&id='.$folder_id.'&selectcat='.$select_cat.'">'.
Display::return_icon('back.png', get_lang('Back').' '.get_lang('To').' '.get_lang('CertificateOverview'), '', ICON_SIZE_MEDIUM).'</a>';
$actionsLeft .= '<a id="hide_bar_template" href="#" role="button">'.
Display::return_icon('expand.png', get_lang('Back'), ['id' => 'expand'], ICON_SIZE_MEDIUM).Display::return_icon('contract.png', get_lang('Back'), ['id' => 'contract', 'class' => 'hide'], ICON_SIZE_MEDIUM).'</a>';
Display::return_icon('expand.png', get_lang('Back'), ['id' => 'expand'], ICON_SIZE_MEDIUM).
Display::return_icon('contract.png', get_lang('Back'), ['id' => 'contract', 'class' => 'hide'], ICON_SIZE_MEDIUM).'</a>';
} else {
$actionsLeft = '<a href="document.php?'.api_get_cidreq().'&curdirpath='.Security::remove_XSS($dir).'">'.
Display::return_icon('back.png', get_lang('Back').' '.get_lang('To').' '.get_lang('DocumentsOverview'), '', ICON_SIZE_MEDIUM).'</a>';

@ -36,7 +36,7 @@ $htmlHeadXtra[] = '
<script>
$(function() {
$(".scrollbar-light").scrollbar();
expandColumnToogle("#hide_bar_template", {
selector: "#template_col",
width: 3
@ -47,6 +47,12 @@ $(function() {
CKEDITOR.on("instanceReady", function (e) {
showTemplates();
e.editor.on("beforeCommandExec", function (event) {
if (event.data.name == "save") {
$("#formEdit").append("<input type=hidden name=button_ck value=1 />");
}
});
});
});
@ -327,7 +333,14 @@ if ($is_allowed_to_edit) {
}
}
header('Location: document.php?id='.$document_data['parent_id'].'&'.api_get_cidreq().($is_certificate_mode ? '&curdirpath=/certificates&selectcat=1' : ''));
$url = 'document.php?id='.$document_data['parent_id'].'&'.api_get_cidreq().($is_certificate_mode ? '&curdirpath=/certificates&selectcat=1' : '');
$redirectToEditPage = isset($_POST['button_ck']) && 1 === (int) $_POST['button_ck'];
if ($redirectToEditPage) {
$url = 'edit_document.php?'.api_get_cidreq().'&id='.$document_id.($is_certificate_mode ? '&curdirpath=/certificates&selectcat=1' : '');
}
header('Location: '.$url);
exit;
}
}
@ -536,7 +549,7 @@ if ($owner_id == api_get_user_id() ||
$(function() {
$("[data-toggle=\'tooltip\']").tooltip(
{
content:
content:
function() {
return $(this).attr("title");
}

@ -97,7 +97,7 @@ class Documents extends Basic
protected function getMaximizedToolbar()
{
return [
$this->getNewPageBlock(),
array_merge(['Save'], $this->getNewPageBlock()),
['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', 'inserthtml'],
['Undo', 'Redo', '-', 'SelectAll', 'Find', '-', 'RemoveFormat'],
['Link', 'Unlink', 'Anchor', 'Glossary'],
@ -133,10 +133,10 @@ class Documents extends Basic
'BGColor',
api_get_configuration_value('translate_html') ? 'Language' : '',
],
[api_get_setting('allow_spellcheck') == 'true' ? 'Scayt' : ''],
[api_get_setting('allow_spellcheck') === 'true' ? 'Scayt' : ''],
['Styles', 'Format', 'Font', 'FontSize'],
['PageBreak', 'ShowBlocks'],
api_get_setting('enabled_wiris') == 'true' ? ['ckeditor_wiris_formulaEditor', 'ckeditor_wiris_formulaEditorChemistry'] : [''],
api_get_setting('enabled_wiris') === 'true' ? ['ckeditor_wiris_formulaEditor', 'ckeditor_wiris_formulaEditorChemistry'] : [''],
['Toolbarswitch', 'Source'],
];
}
@ -149,7 +149,7 @@ class Documents extends Basic
protected function getMinimizedToolbar()
{
return [
$this->getNewPageBlock(),
array_merge(['Save'], $this->getNewPageBlock()),
['Undo', 'Redo'],
[
'Link',

Loading…
Cancel
Save