Commit 7538d3c9 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

Changed most forms to be pieforms 0.2.0 compliant. A _huge_ change! It's

likely some stuff still doesn't work properly...
parent 1f2db621
...@@ -75,7 +75,7 @@ $elements['submit'] = array( ...@@ -75,7 +75,7 @@ $elements['submit'] = array(
$prefsform = array( $prefsform = array(
'name' => 'activityprefs', 'name' => 'activityprefs',
'method' => 'post', 'method' => 'post',
'ajaxpost' => true, 'jsform' => true,
'renderer' => 'table', 'renderer' => 'table',
'plugintype ' => 'core', 'plugintype ' => 'core',
'pluginname' => 'account', 'pluginname' => 'account',
...@@ -87,7 +87,7 @@ $smarty->assign('prefsdescr', get_string('prefsdescr', 'activity')); ...@@ -87,7 +87,7 @@ $smarty->assign('prefsdescr', get_string('prefsdescr', 'activity'));
$smarty->assign('form', pieform($prefsform)); $smarty->assign('form', pieform($prefsform));
$smarty->display('account/activity/preferences/index.tpl'); $smarty->display('account/activity/preferences/index.tpl');
function activityprefs_submit($values, Pieform $form) { function activityprefs_submit(Pieform $form, $values) {
global $activitytypes, $admintypes, $USER; global $activitytypes, $admintypes, $USER;
$userid = $USER->get('id'); $userid = $USER->get('id');
......
...@@ -129,10 +129,10 @@ $elements['submit'] = array( ...@@ -129,10 +129,10 @@ $elements['submit'] = array(
$prefsform = array( $prefsform = array(
'name' => 'accountprefs', 'name' => 'accountprefs',
'method' => 'post', 'method' => 'post',
'ajaxpost' => true, 'jsform' => true,
'plugintype' => 'core', 'plugintype' => 'core',
'pluginname' => 'account', 'pluginname' => 'account',
'ajaxsuccessfunction' => 'clearPasswords', 'jssuccesscallback' => 'clearPasswords',
'elements' => $elements 'elements' => $elements
); );
...@@ -140,7 +140,8 @@ $prefsform = array( ...@@ -140,7 +140,8 @@ $prefsform = array(
$smarty = smarty(); $smarty = smarty();
$smarty->assign('form', pieform($prefsform)); $smarty->assign('form', pieform($prefsform));
$smarty->assign('INLINEJAVASCRIPT', " $smarty->assign('INLINEJAVASCRIPT', "
function clearPasswords() { function clearPasswords(form, data) {
formSuccess(form, data);
$('accountprefs_oldpassword').value = ''; $('accountprefs_oldpassword').value = '';
$('accountprefs_password1').value = ''; $('accountprefs_password1').value = '';
$('accountprefs_password2').value = ''; $('accountprefs_password2').value = '';
...@@ -161,7 +162,7 @@ function accountprefs_validate(Pieform $form, $values) { ...@@ -161,7 +162,7 @@ function accountprefs_validate(Pieform $form, $values) {
} }
} }
function accountprefs_submit($values, Pieform $form) { function accountprefs_submit(Pieform $form, $values) {
global $USER; global $USER;
db_begin(); db_begin();
......
...@@ -57,8 +57,9 @@ if (isset($form['validatefunction'])) { ...@@ -57,8 +57,9 @@ if (isset($form['validatefunction'])) {
$validatefunction = $form['validatefunction']; $validatefunction = $form['validatefunction'];
} }
$form['submitfunction'] = 'pluginconfig_submit'; $form['jsform'] = true;
$form['validatefunction'] = 'pluginconfig_validate'; $form['successcallback'] = 'pluginconfig_submit';
$form['validatecallback'] = 'pluginconfig_validate';
$form['elements']['plugintype'] = array( $form['elements']['plugintype'] = array(
'type' => 'hidden', 'type' => 'hidden',
'value' => $plugintype 'value' => $plugintype
...@@ -80,7 +81,7 @@ $smarty->assign('type', $type); ...@@ -80,7 +81,7 @@ $smarty->assign('type', $type);
$smarty->display('admin/extensions/pluginconfig.tpl'); $smarty->display('admin/extensions/pluginconfig.tpl');
function pluginconfig_submit($values) { function pluginconfig_submit(Pieform $form, $values) {
$success = false; $success = false;
global $submitfunction, $plugintype, $pluginname, $classname; global $submitfunction, $plugintype, $pluginname, $classname;
if (!empty($submitfunction)) { if (!empty($submitfunction)) {
...@@ -95,11 +96,12 @@ function pluginconfig_submit($values) { ...@@ -95,11 +96,12 @@ function pluginconfig_submit($values) {
else { else {
// call set_plugin_config and stuffs // call set_plugin_config and stuffs
} }
if ($success) { if ($success) {
json_reply(false, get_string('settingssaved')); $form->json_reply(PIEFORM_OK, get_string('settingssaved'));
} }
else { else {
json_reply('local', get_string('settingssavefailed')); $form->json_reply(PIEFORM_ERR, array('message' => get_string('settingssavefailed')));
} }
} }
......
...@@ -39,7 +39,7 @@ $yesno = array(true => get_string('yes'), ...@@ -39,7 +39,7 @@ $yesno = array(true => get_string('yes'),
$siteoptionform = pieform(array( $siteoptionform = pieform(array(
'name' => 'siteoptions', 'name' => 'siteoptions',
'ajaxpost' => true, 'jsform' => true,
'renderer' => 'table', 'renderer' => 'table',
'elements' => array( 'elements' => array(
'sitename' => array( 'sitename' => array(
...@@ -103,25 +103,25 @@ $siteoptionform = pieform(array( ...@@ -103,25 +103,25 @@ $siteoptionform = pieform(array(
) )
)); ));
function siteoptions_fail($field, Pieform $form) { function siteoptions_fail(Pieform $form, $field) {
$form->json_reply(PIEFORM_ERR, get_string('siteoptionsfailed','admin', get_string($field)), array($field => get_string($field . 'invalid', 'admin'))); $form->json_reply(PIEFORM_ERR, get_string('siteoptionsfailed','admin', get_string($field)), array($field => get_string($field . 'invalid', 'admin')));
} }
function siteoptions_submit($values, Pieform $form) { function siteoptions_submit(Pieform $form, $values) {
$fields = array('sitename','language','theme','pathtoclam', $fields = array('sitename','language','theme','pathtoclam',
'allowpublicviews','artefactviewinactivitytime'); 'allowpublicviews','artefactviewinactivitytime');
foreach ($fields as $field) { foreach ($fields as $field) {
if (!set_config($field, $values[$field])) { if (!set_config($field, $values[$field])) {
siteoptions_fail($field); siteoptions_fail($form, $field);
} }
} }
// submitted sessionlifetime is in minutes; db entry session_timeout is in seconds // submitted sessionlifetime is in minutes; db entry session_timeout is in seconds
if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) { if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) {
siteoptions_fail('sessionlifetime', $form); siteoptions_fail($form, 'sessionlifetime');
} }
// Submitted value is on/off; database entry should be 1/0 // Submitted value is on/off; database entry should be 1/0
if (!set_config('viruschecking', (int) ($values['viruschecking'] == 'on'))) { if (!set_config('viruschecking', (int) ($values['viruschecking'] == 'on'))) {
siteoptions_fail('viruschecking', $form); siteoptions_fail($form, 'viruschecking');
} }
$form->json_reply(PIEFORM_OK, get_string('siteoptionsset','admin')); $form->json_reply(PIEFORM_OK, get_string('siteoptionsset','admin'));
} }
......
...@@ -42,8 +42,8 @@ $getstring = array('discardpageedits' => "'" . get_string('discardpageedits','ad ...@@ -42,8 +42,8 @@ $getstring = array('discardpageedits' => "'" . get_string('discardpageedits','ad
$f = array( $f = array(
'name' => 'editsitepage', 'name' => 'editsitepage',
'ajaxpost' => true, 'jsform' => true,
'ajaxsuccessfunction' => 'contentSaved', 'jssuccescallback' => 'contentSaved',
'elements' => array( 'elements' => array(
'pagename' => array( 'pagename' => array(
'type' => 'select', 'type' => 'select',
...@@ -71,7 +71,7 @@ $f = array( ...@@ -71,7 +71,7 @@ $f = array(
$form = pieform($f); $form = pieform($f);
function editsitepage_submit($values, Pieform $form) { function editsitepage_submit(Pieform $form, $values) {
global $USER; global $USER;
$data = new StdClass; $data = new StdClass;
$data->name = $values['pagename']; $data->name = $values['pagename'];
...@@ -106,9 +106,10 @@ function requestPageText(removeMessage) { ...@@ -106,9 +106,10 @@ function requestPageText(removeMessage) {
} }
processingStart(); processingStart();
if (removeMessage) { // @todo something might need to be done here
editsitepage_remove_message(); //if (removeMessage) {
} // removeElement('messages');
//}
editsitepage_remove_all_errors(); editsitepage_remove_all_errors();
logDebug(get_string('loadingpagecontent', 'admin')); logDebug(get_string('loadingpagecontent', 'admin'));
var d = loadJSONDoc('editchangepage.json.php',{'pagename':$('editsitepage_pagename').value}); var d = loadJSONDoc('editchangepage.json.php',{'pagename':$('editsitepage_pagename').value});
...@@ -129,9 +130,11 @@ function requestPageText(removeMessage) { ...@@ -129,9 +130,11 @@ function requestPageText(removeMessage) {
} }
// Called from submitForm on successful page save. // Called from submitForm on successful page save.
function contentSaved () { function contentSaved (form, data) {
formSuccess(form, data);
originalcontent = getEditorContent(); originalcontent = getEditorContent();
callLater(2, editsitepage_remove_message); // @todo something might need to be done here
//callLater(2, function() { removeElement('messages'); });
requestPageText(false); requestPageText(false);
} }
......
...@@ -40,8 +40,6 @@ $adminusers = get_column('usr', 'id', 'admin', 1); ...@@ -40,8 +40,6 @@ $adminusers = get_column('usr', 'id', 'admin', 1);
$form = array( $form = array(
'name' => 'adminusers', 'name' => 'adminusers',
'method' => 'post',
'action' => '',
'elements' => array( 'elements' => array(
'users' => array( 'users' => array(
'type' => 'userlist', 'type' => 'userlist',
...@@ -59,7 +57,7 @@ $form = array( ...@@ -59,7 +57,7 @@ $form = array(
) )
); );
function adminusers_submit($values) { function adminusers_submit(Pieform $form, $values) {
global $SESSION; global $SESSION;
$table = get_config('dbprefix') . 'usr'; $table = get_config('dbprefix') . 'usr';
......
...@@ -50,7 +50,7 @@ if ($institution || $add) { ...@@ -50,7 +50,7 @@ if ($institution || $add) {
redirect(get_config('wwwroot') . 'admin/users/institutions.php'); redirect(get_config('wwwroot') . 'admin/users/institutions.php');
} }
function delete_submit($values) { function delete_submit(Pieform $form, $values) {
global $SESSION; global $SESSION;
db_begin(); db_begin();
...@@ -59,7 +59,7 @@ if ($institution || $add) { ...@@ -59,7 +59,7 @@ if ($institution || $add) {
db_commit(); db_commit();
$SESSION->add_ok_msg(get_string('institutiondeletedsuccessfully', 'admin')); $SESSION->add_ok_msg(get_string('institutiondeletedsuccessfully', 'admin'));
redirect(get_config('wwwroot') . 'admin/users/institutions.php'); redirect('admin/users/institutions.php');
} }
$form = array( $form = array(
'name' => 'delete', 'name' => 'delete',
...@@ -193,7 +193,7 @@ else { ...@@ -193,7 +193,7 @@ else {
$smarty->assign('institutions', $institutions); $smarty->assign('institutions', $institutions);
} }
function institution_submit($values) { function institution_submit(Pieform $form, $values) {
global $SESSION, $institution, $add; global $SESSION, $institution, $add;
log_debug($values); log_debug($values);
...@@ -238,7 +238,7 @@ function institution_submit($values) { ...@@ -238,7 +238,7 @@ function institution_submit($values) {
} }
function institution_cancel_submit() { function institution_cancel_submit() {
redirect(get_config('wwwroot') . 'admin/users/institutions.php'); redirect('admin/users/institutions.php');
} }
$smarty->display('admin/users/institutions.tpl'); $smarty->display('admin/users/institutions.tpl');
......
...@@ -59,8 +59,7 @@ foreach ($methods as $m) { ...@@ -59,8 +59,7 @@ foreach ($methods as $m) {
$form = array( $form = array(
'name' => 'adminnotifications', 'name' => 'adminnotifications',
'method' => 'post', 'jsform' => true,
'ajaxpost' => true,
'plugintype' => 'core', 'plugintype' => 'core',
'pluginname' => 'admin', 'pluginname' => 'admin',
'renderer' => 'multicolumntable', 'renderer' => 'multicolumntable',
...@@ -100,7 +99,7 @@ $smarty = smarty(); ...@@ -100,7 +99,7 @@ $smarty = smarty();
$smarty->assign('form', pieform($form)); $smarty->assign('form', pieform($form));
$smarty->display('admin/users/notifications.tpl'); $smarty->display('admin/users/notifications.tpl');
function adminnotifications_submit($values, Pieform $form) { function adminnotifications_submit(Pieform $form, $values) {
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
if (!preg_match('/^admin\-(\d+)\-([a-z]+)$/', $key, $m)) { if (!preg_match('/^admin\-(\d+)\-([a-z]+)$/', $key, $m)) {
continue; continue;
......
...@@ -39,8 +39,6 @@ $staffusers = get_column('usr', 'id', 'staff', 1); ...@@ -39,8 +39,6 @@ $staffusers = get_column('usr', 'id', 'staff', 1);
$form = array( $form = array(
'name' => 'staffusers', 'name' => 'staffusers',
'method' => 'post',
'action' => '',
'elements' => array( 'elements' => array(
'users' => array( 'users' => array(
'type' => 'userlist', 'type' => 'userlist',
...@@ -55,7 +53,7 @@ $form = array( ...@@ -55,7 +53,7 @@ $form = array(
) )
); );
function staffusers_submit($values) { function staffusers_submit(Pieform $form, $values) {
global $SESSION; global $SESSION;
$table = get_config('dbprefix') . 'usr'; $table = get_config('dbprefix') . 'usr';
......
...@@ -77,7 +77,7 @@ $smarty->assign('buttonform', $form->build(false)); ...@@ -77,7 +77,7 @@ $smarty->assign('buttonform', $form->build(false));
$smarty->display('admin/users/suspended.tpl'); $smarty->display('admin/users/suspended.tpl');
function buttons_submit_unsuspend($values) { function buttons_submit_unsuspend(Pieform $form, $values) {
global $SESSION; global $SESSION;
$ids = get_user_ids_from_post(); $ids = get_user_ids_from_post();
...@@ -86,17 +86,17 @@ function buttons_submit_unsuspend($values) { ...@@ -86,17 +86,17 @@ function buttons_submit_unsuspend($values) {
} }
$SESSION->add_ok_msg(get_string('usersunsuspendedsuccessfully')); $SESSION->add_ok_msg(get_string('usersunsuspendedsuccessfully'));
redirect(get_config('wwwroot') . 'admin/users/suspended.php'); redirect('admin/users/suspended.php');
} }
function buttons_submit_export($values) { function buttons_submit_export(Pieform $form, $values) {
global $SESSION; global $SESSION;
$ids = get_user_ids_from_post(); $ids = get_user_ids_from_post();
$SESSION->add_info_msg(get_string('exportingnotsupportedyet')); $SESSION->add_info_msg(get_string('exportingnotsupportedyet'));
redirect(get_config('wwwroot') . 'admin/users/suspended.php'); redirect('admin/users/suspended.php');
} }
function buttons_submit_delete($values) { function buttons_submit_delete(Pieform $form, $values) {
global $SESSION; global $SESSION;
$ids = get_user_ids_from_post(); $ids = get_user_ids_from_post();
...@@ -105,7 +105,7 @@ function buttons_submit_delete($values) { ...@@ -105,7 +105,7 @@ function buttons_submit_delete($values) {
} }
$SESSION->add_ok_msg(get_string('usersdeletedsuccessfully')); $SESSION->add_ok_msg(get_string('usersdeletedsuccessfully'));
redirect(get_config('wwwroot') . 'admin/users/suspended.php'); redirect('admin/users/suspended.php');
} }
function get_user_ids_from_post() { function get_user_ids_from_post() {
...@@ -119,7 +119,7 @@ function get_user_ids_from_post() { ...@@ -119,7 +119,7 @@ function get_user_ids_from_post() {
if (!$ids) { if (!$ids) {
global $SESSION; global $SESSION;
$SESSION->add_info_msg(get_string('nousersselected')); $SESSION->add_info_msg(get_string('nousersselected'));
redirect(get_config('wwwroot') . 'admin/users/suspended.php'); redirect('admin/users/suspended.php');
} }
return $ids; return $ids;
......
...@@ -58,8 +58,6 @@ else { ...@@ -58,8 +58,6 @@ else {
$form = array( $form = array(
'name' => 'uploadcsv', 'name' => 'uploadcsv',
'method' => 'post',
'action' => '',
'elements' => array( 'elements' => array(
'institution' => $institutionelement, 'institution' => $institutionelement,
'file' => array( 'file' => array(
...@@ -158,7 +156,7 @@ function uploadcsv_validate(Pieform $form, $values) { ...@@ -158,7 +156,7 @@ function uploadcsv_validate(Pieform $form, $values) {
* Add the users to the system. Make sure that they have to change their * Add the users to the system. Make sure that they have to change their
* password on next login also. * password on next login also.
*/ */
function uploadcsv_submit($values) { function uploadcsv_submit(Pieform $form, $values) {
global $SESSION, $CSVDATA; global $SESSION, $CSVDATA;
log_info('Inserting users from the CSV file'); log_info('Inserting users from the CSV file');
foreach ($CSVDATA as $record) { foreach ($CSVDATA as $record) {
...@@ -181,8 +179,7 @@ function uploadcsv_submit($values) { ...@@ -181,8 +179,7 @@ function uploadcsv_submit($values) {
log_info('Inserted ' . count($CSVDATA) . ' records'); log_info('Inserted ' . count($CSVDATA) . ' records');
$SESSION->add_ok_msg(get_string('uploadcsvusersaddedsuccessfully', 'admin')); $SESSION->add_ok_msg(get_string('uploadcsvusersaddedsuccessfully', 'admin'));
// @todo support relative URLs here redirect('admin/users/uploadcsv.php');
redirect(get_config('wwwroot') . 'admin/users/uploadcsv.php');
} }
$smarty = smarty(); $smarty = smarty();
......
...@@ -101,7 +101,7 @@ $form = pieform(array( ...@@ -101,7 +101,7 @@ $form = pieform(array(
'description' => array( 'description' => array(
'type' => 'wysiwyg', 'type' => 'wysiwyg',
'rows' => 10, 'rows' => 10,
'cols' => 80, 'cols' => 70,
'title' => get_string('postbody', 'artefact.blog'), 'title' => get_string('postbody', 'artefact.blog'),
'description' => get_string('postbodydesc', 'artefact.blog'), 'description' => get_string('postbodydesc', 'artefact.blog'),
'rules' => array( 'rules' => array(
...@@ -113,7 +113,7 @@ $form = pieform(array( ...@@ -113,7 +113,7 @@ $form = pieform(array(
'type' => 'checkbox', 'type' => 'checkbox',
'title' => get_string('thisisdraft', 'artefact.blog'), 'title' => get_string('thisisdraft', 'artefact.blog'),
'description' => get_string('thisisdraftdesc', 'artefact.blog'), 'description' => get_string('thisisdraftdesc', 'artefact.blog'),
'checked' => $checked 'defaultvalue' => $checked
), ),
) )
)); ));
...@@ -150,7 +150,7 @@ $wwwroot = get_config('wwwroot'); ...@@ -150,7 +150,7 @@ $wwwroot = get_config('wwwroot');
* Javascript specific to this page. Creates the list of files * Javascript specific to this page. Creates the list of files
* attached to the blog post. * attached to the blog post.
*/ */
$javascript = <<< EOF $javascript = <<<EOF
...@@ -274,7 +274,7 @@ $smarty->display('artefact:blog:editpost.tpl'); ...@@ -274,7 +274,7 @@ $smarty->display('artefact:blog:editpost.tpl');
* *
* @param array * @param array
*/ */
function editpost_submit(array $values) { function editpost_submit(Pieform $form, array $values) {
global $USER; global $USER;
$values['published'] = !$values['thisisdraft']; $values['published'] = !$values['thisisdraft'];
......
...@@ -34,7 +34,7 @@ safe_require('artefact', 'blog'); ...@@ -34,7 +34,7 @@ safe_require('artefact', 'blog');
$wwwroot = get_config('wwwroot'); $wwwroot = get_config('wwwroot');
// This JavaScript creates a table to display the blog entries. // This JavaScript creates a table to display the blog entries.
$js = <<<EOJAVASCRIPT $js = <<<EOF
var bloglist = new TableRenderer( var bloglist = new TableRenderer(
'bloglist', 'bloglist',
...@@ -56,7 +56,7 @@ var bloglist = new TableRenderer( ...@@ -56,7 +56,7 @@ var bloglist = new TableRenderer(
bloglist.updateOnLoad(); bloglist.updateOnLoad();
EOJAVASCRIPT; EOF;
$smarty = smarty(array('tablerenderer')); $smarty = smarty(array('tablerenderer'));
$smarty->assign_by_ref('INLINEJAVASCRIPT', $js); $smarty->assign_by_ref('INLINEJAVASCRIPT', $js);
......
...@@ -47,7 +47,7 @@ $form = pieform(array( ...@@ -47,7 +47,7 @@ $form = pieform(array(
'description' => array( 'description' => array(
'type' => 'wysiwyg', 'type' => 'wysiwyg',
'rows' => 10, 'rows' => 10,
'cols' => 80, 'cols' => 70,
'title' => get_string('blogdesc', 'artefact.blog'), 'title' => get_string('blogdesc', 'artefact.blog'),
'description' => get_string('blogdescdesc', 'artefact.blog'), 'description' => get_string('blogdescdesc', 'artefact.blog'),
'rules' => array( 'rules' => array(
...@@ -92,7 +92,7 @@ exit; ...@@ -92,7 +92,7 @@ exit;
* *
* @param array * @param array
*/ */
function newblog_submit($values) { function newblog_submit(Pieform $form, $values) {