Commit e97fecdc authored by Nigel McNie's avatar Nigel McNie
Browse files

Named the site pages page more consistently - it's now 'edit site pages'....

Named the site pages page more consistently - it's now 'edit site pages'. Deleted the inline javascript, it's now in a separate file.
parent 42b47ab6
......@@ -33,46 +33,44 @@ define('SECTION_PAGE', 'sitepages');
require(dirname(dirname(dirname(__FILE__))).'/init.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('sitepages', 'admin'));
define('TITLE', get_string('editsitepages', 'admin'));
$sitepages = get_records_array('site_content');
$pageoptions = array();
foreach ($sitepages as $page) {
$pageoptions[$page->name] = get_string($page->name,'admin');
$pageoptions[$page->name] = get_string($page->name, 'admin');
}
asort($pageoptions);
$getstring = array('discardpageedits' => json_encode(get_string('discardpageedits','admin')));
$getstring = array('discardpageedits' => json_encode(get_string('discardpageedits', 'admin')));
$f = array(
'name' => 'editsitepage',
'jsform' => true,
'jssuccesscallback' => 'contentSaved',
'elements' => array(
'pagename' => array(
$form = pieform(array(
'name' => 'editsitepage',
'jsform' => true,
'jssuccesscallback' => 'contentSaved',
'elements' => array(
'pagename' => array(
'type' => 'select',
'title' => get_string('pagename','admin'),
'defaultvalue' => 'home',
'title' => get_string('pagename', 'admin'),
'defaultvalue' => 'home',
'options' => $pageoptions
),
'pagetext' => array(
'name' => 'pagetext',
'type' => 'wysiwyg',
'rows' => 20,
'rows' => 20, // TODO: make rows/cols bigger. But only once the CSS style to force the width of the wysiwyg editor dies!
'cols' => 80,
'title' => get_string('pagetext','admin'),
'description' => get_string('pagecontents','admin'),
'title' => get_string('pagetext', 'admin'),
'rules' => array(
'required' => true
)
),
'submit' => array(
'type' => 'submit',
'value' => get_string('savechanges','admin')
'value' => get_string('savechanges', 'admin')
),
)
);
$form = pieform($f);
));
function editsitepage_submit(Pieform $form, $values) {
......@@ -86,87 +84,13 @@ function editsitepage_submit(Pieform $form, $values) {
update_record('site_content', $data, 'name');
}
catch (SQLException $e) {
$form->json_reply(PIEFORM_ERR, get_string('savefailed','admin'));
$form->reply(PIEFORM_ERR, get_string('savefailed', 'admin'));
}
$form->json_reply(PIEFORM_OK, get_string('pagesaved','admin'));
$form->reply(PIEFORM_OK, get_string('pagesaved', 'admin'));
}
$ijs = <<< EOJS
// global stuff, set in onLoad().
var oldpagename = '';
var originalcontent = '';
function requestPageText() {
// Allow the user to abort change if changes have been made in the editor.
if (getEditorContent() != originalcontent) {
if (!confirm({$getstring['discardpageedits']})) {
$('editsitepage_pagename').value = oldpagename;
return;
}
}
editsitepage_remove_all_errors();
sendjsonrequest('editchangepage.json.php', {'pagename':$('editsitepage_pagename').value}, 'POST',
function(data) {
if (!data.error) {
setEditorContent(data.content);
originalcontent = data.content;
oldpagename = $('editsitepage_pagename').value;
}
});
}
// Called from submitForm on successful page save.
function contentSaved (form, data) {
formSuccess(form, data);
// @todo something might need to be done here
//callLater(2, function() { removeElement('messages'); });
originalcontent = getEditorContent();
}
function onLoad() {
if (typeof(tinyMCE) != 'undefined') {
setEditorContent = function (c) {
if (navigator.userAgent.indexOf('Firefox/') != -1) {
// Firefox won't let you use the delete key unless you
// put this stuff in:
tinyMCE.removeMCEControl('mce_editor_0');
tinyMCE.idCounter = 0;
$('editsitepage_pagetext').value = c;
tinyMCE.execCommand('mceAddControl', true, 'editsitepage_pagetext');
} else {
tinyMCE.setContent(c);
}
tinyMCE.execCommand('mceFocus', false, 'mce_editor_0');
}
getEditorContent = tinyMCE.getContent;
}
else {
setEditorContent = function (c) { $('editsitepage_pagetext').value = c; };
getEditorContent = function () { return $('editsitepage_pagetext').value; };
}
// IE seems to need this but I don't know why.
callLater(0.001,function() {
originalcontent = getEditorContent();
requestPageText();
});
connect('editsitepage_pagename', 'onchange', requestPageText);
connect('editsitepage_pagename', 'onkeydown', function(e) {
if (e.key().code == 9 && !e.modifier().shift) {
tinyMCE.execCommand('mceFocus',false,'mce_editor_0');
e.stop();
}
});
}
addLoadEvent(onLoad);
EOJS;
$smarty = smarty();
$smarty = smarty(array('adminsitepages'), array(), array('admin' => array('discardpageedits')));
$smarty->assign('pageeditform', $form);
$smarty->assign('INLINEJAVASCRIPT', $ijs);
$smarty->display('admin/site/pages.tpl');
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment