Commit 53959d72 authored by Francois Marier's avatar Francois Marier Committed by Gerrit Code Review
Browse files

Merge ""Display mode" on goals, skills, & interests pages (bug #869658)"

parents 410b3fd9 3282ebbf
......@@ -34,77 +34,25 @@ define('RESUME_SUBPAGE', 'goals');
require_once(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');
safe_require('artefact', 'resume');
define('TITLE', get_string('resume', 'artefact.resume'));
require_once(get_config('docroot') . 'artefact/lib.php');
try {
$personal = artefact_instance_from_type('personalgoal');
$personal = $personal->get('description');
}
catch (Exception $e) {
$personal = get_string('defaultpersonalgoal', 'artefact.resume');
}
try {
$academic = artefact_instance_from_type('academicgoal');
$academic = $academic->get('description');
}
catch (Exception $e) {
$academic = get_string('defaultacademicgoal', 'artefact.resume');
}
try {
$career = artefact_instance_from_type('careergoal');
$career = $career->get('description');
}
catch (Exception $e) {
$career = get_string('defaultcareergoal', 'artefact.resume');
}
$gform = array(
'name' => 'goalform',
'jsform' => true,
'plugintype' => 'artefact',
'pluginname' => 'resume',
'successcallback' => 'goalandskillform_submit',
'elements' => array(
'mygoals' => array(
'type' => 'fieldset',
'legend' => get_string('mygoals', 'artefact.resume'),
'help' => true,
'elements' => array(
'personalgoal' => array(
'type' => 'wysiwyg',
'rows' => 20,
'cols' => 80,
'defaultvalue' => $personal,
'title' => get_string('personalgoal', 'artefact.resume'),
'rules' => array('maxlength' => 65536),
),
'academicgoal' => array(
'type' => 'wysiwyg',
'rows' => 20,
'cols' => 80,
'defaultvalue' => $academic,
'title' => get_string('academicgoal', 'artefact.resume'),
'rules' => array('maxlength' => 65536),
),
'careergoal' => array(
'type' => 'wysiwyg',
'rows' => 20,
'cols' => 80,
'defaultvalue' => $career,
'title' => get_string('careergoal', 'artefact.resume'),
'rules' => array('maxlength' => 65536),
),
'submit' => array(
'type' => 'submit',
'value' => get_string('save'),
),
),
),
$defaults = array(
'personalgoal' => array(
'default' => get_string('defaultpersonalgoal', 'artefact.resume'),
),
'academicgoal' => array(
'default' => get_string('defaultacademicgoal', 'artefact.resume'),
),
'careergoal' => array(
'default' => get_string('defaultcareergoal', 'artefact.resume'),
),
);
$goalform = pieform($gform);
$smarty = smarty();
$smarty->assign('goalform', $goalform);
$form = pieform(simple_resumefield_form($defaults, 'artefact/resume/goals.php'));
$smarty = smarty(array('jquery', 'artefact/resume/js/simpleresumefield.js'));
$smarty->assign('goalform', $form);
$smarty->assign('INLINEJAVASCRIPT', '$j(simple_resumefield_init);');
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('SUBPAGENAV', PluginArtefactResume::submenu_items());
$smarty->display('artefact:resume:goals.tpl');
......@@ -37,47 +37,21 @@ define('TITLE', get_string('resume', 'artefact.resume'));
require_once('pieforms/pieform.php');
safe_require('artefact', 'resume');
$defaults = array(
'coverletter' => array(
'default' => '',
'fshelp' => true,
),
);
$coverletterform = pieform(simple_resumefield_form($defaults, 'artefact/resume/index.php'));
// load up all the artefacts this user already has....
$coverletter = null;
try {
$coverletter = artefact_instance_from_type('coverletter');
}
catch (Exception $e) { }
$personalinformation = null;
try {
$personalinformation = artefact_instance_from_type('personalinformation');
}
catch (Exception $e) { }
$coverletterform = pieform(array(
'name' => 'coverletter',
'jsform' => true,
'plugintype' => 'artefact',
'pluginname' => 'resume',
'jsform' => true,
'method' => 'post',
'elements' => array(
'coverletterfs' => array(
'type' => 'fieldset',
'legend' => get_string('coverletter', 'artefact.resume'),
'elements' => array(
'coverletter' => array(
'type' => 'wysiwyg',
'cols' => 100,
'rows' => 30,
'rules' => array('maxlength' => 65536),
'defaultvalue' => ((!empty($coverletter)) ? $coverletter->get('description') : null),
),
'save' => array(
'type' => 'submit',
'value' => get_string('save'),
),
),
'help' => true,
)
)
));
$personalinformationform = pieform(array(
'name' => 'personalinformation',
'jsform' => true,
......@@ -149,50 +123,14 @@ $personalinformationform = pieform(array(
),
));
$smarty = smarty();
$smarty = smarty(array('jquery', 'artefact/resume/js/simpleresumefield.js'));
$smarty->assign('coverletterform', $coverletterform);
$smarty->assign('personalinformationform',$personalinformationform);
$smarty->assign('INLINEJAVASCRIPT', '$j(simple_resumefield_init);');
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('SUBPAGENAV', PluginArtefactResume::submenu_items());
$smarty->display('artefact:resume:index.tpl');
function coverletter_submit(Pieform $form, $values) {
global $coverletter, $personalinformation, $interest, $USER;
$userid = $USER->get('id');
$errors = array();
try {
if (empty($coverletter) && !empty($values['coverletter'])) {
$coverletter = new ArtefactTypeCoverletter(0, array(
'owner' => $userid,
'description' => $values['coverletter']
));
$coverletter->commit();
}
else if (!empty($coverletter) && !empty($values['coverletter'])) {
$coverletter->set('description', $values['coverletter']);
$coverletter->commit();
}
else if (!empty($coverletter) && empty($values['coverletter'])) {
$coverletter->delete();
}
}
catch (Exception $e) {
$errors['coverletter'] = true;
}
if (empty($errors)) {
$form->json_reply(PIEFORM_OK, get_string('resumesaved','artefact.resume'));
}
else {
$message = '';
foreach (array_keys($errors) as $key) {
$message .= get_string('resumesavefailed', 'artefact.resume')."\n";
}
$form->json_reply(PIEFORM_ERR, $message);
}
}
function personalinformation_submit(Pieform $form, $values) {
global $personalinformation, $USER;
$userid = $USER->get('id');
......
......@@ -37,81 +37,17 @@ define('TITLE', get_string('resume', 'artefact.resume'));
require_once('pieforms/pieform.php');
safe_require('artefact', 'resume');
$interest = null;
try {
$interest = artefact_instance_from_type('interest');
}
catch (Exception $e) { }
$interestsform = pieform(array(
'name' => 'interests',
'jsform' => true,
'plugintype' => 'artefact',
'pluginname' => 'resume',
'jsform' => true,
'method' => 'post',
'elements' => array(
'interestsfs' => array(
'type' => 'fieldset',
'legend' => get_string('interest', 'artefact.resume'),
'elements' => array(
'interest' => array(
'type' => 'wysiwyg',
'defaultvalue' => ((!empty($interest)) ? $interest->get('description') : null),
'cols' => 100,
'rows' => 30,
'rules' => array('maxlength' => 65536),
),
'save' => array(
'type' => 'submit',
'value' => get_string('save'),
),
),
'help' => true,
)
)
));
$smarty = smarty();
$smarty->assign('interestsform', $interestsform);
$defaults = array(
'interest' => array(
'default' => '',
'fshelp' => true,
),
);
$form = pieform(simple_resumefield_form($defaults, 'artefact/resume/skills.php'));
$smarty = smarty(array('jquery', 'artefact/resume/js/simpleresumefield.js'));
$smarty->assign('interestsform', $form);
$smarty->assign('INLINEJAVASCRIPT', '$j(simple_resumefield_init);');
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('SUBPAGENAV', PluginArtefactResume::submenu_items());
$smarty->display('artefact:resume:interests.tpl');
function interests_submit(Pieform $form, $values) {
global $coverletter, $personalinformation, $interest, $USER;
$userid = $USER->get('id');
$errors = array();
try {
if (empty($interest) && !empty($values['interest'])) {
$interest = new ArtefactTypeInterest(0, array(
'owner' => $userid,
'description' => $values['interest']
));
$interest->commit();
}
else if (!empty($interest) && !empty($values['interest'])) {
$interest->set('description', $values['interest']);
$interest->commit();
}
else if (!empty($interest) && empty($values['interest'])) {
$interest->delete();
}
}
catch (Exception $e) {
$errors['interest'] = true;
}
if (empty($errors)) {
$form->json_reply(PIEFORM_OK, get_string('resumesaved','artefact.resume'));
}
else {
$message = '';
foreach (array_keys($errors) as $key) {
$message .= get_string('resumesavefailed', 'artefact.resume')."\n";
}
$form->json_reply(PIEFORM_ERR, $message);
}
}
function simple_resumefield_success(form, data) {
var displaynode = $j("#resumefieldform_" + data.update + "display_container td");
displaynode.html(data.content);
simple_resumefield_init();
formSuccess(form, data);
}
function simple_resumefield_error(form, data) {
simple_resumefield_init();
var errornodeid = $j("#resumefieldform textarea.error.wysiwyg").attr("id");
if (errornodeid) {
var editbutton = $j("input#" + errornodeid + "edit");
if (editbutton) {
editbutton.click();
}
}
}
function connect_editbuttons() {
$j("#resumefieldform input.openedit").click(function() {
var t = this.id.substr(0, this.id.length - 4);
$j("#" + t + "_container").removeClass("js-hidden");
$j("#" + t + "submit_container").removeClass("js-hidden");
$j("#" + t + "submit").removeClass("js-hidden");
$j("#cancel_" + t + "submit").removeClass("js-hidden");
$j("#" + t + "display_container").addClass("hidden");
$j("#" + t + "display_container").removeClass("nojs-hidden-block");
$j("#" + t + "edit_container").addClass("hidden");
$j("#" + t + "edit_container").removeClass("nojs-hidden-block");
tinyMCE.get(t).show();
});
}
function connect_cancelbuttons() {
$j("#resumefieldform input.submitcancel.cancel").click(function(e) {
e.preventDefault();
var t = this.id.substr(7, this.id.length - 7 - 6);
$j("#" + t + "_container").addClass("js-hidden");
$j("#" + t + "submit_container").addClass("js-hidden");
$j("#" + t + "submit").addClass("js-hidden");
$j("#cancel_" + t + "submit").addClass("js-hidden");
$j("#" + t + "display_container").removeClass("hidden");
$j("#" + t + "edit_container").removeClass("hidden");
tinyMCE.get(t).hide();
});
}
function simple_resumefield_init() {
connect_editbuttons();
connect_cancelbuttons();
}
......@@ -1200,12 +1200,6 @@ class ArtefactTypeResumeGoalAndSkill extends ArtefactTypeResume {
public static function is_singular() {
return true;
}
public static function get_goalandskill_artefact_types() {
return array('personalgoal', 'academicgoal', 'careergoal',
'personalskill', 'academicskill', 'workskill');
}
}
class ArtefactTypePersonalgoal extends ArtefactTypeResumeGoalAndSkill { }
......@@ -1247,25 +1241,97 @@ function compositeformedit_submit(Pieform $form, $values) {
redirect($goto);
}
function goalandskillform_submit(Pieform $form, $values) {
foreach ($values as $key => $value) {
if (!in_array($key, ArtefactTypeResumeGoalAndSkill::get_goalandskill_artefact_types())) {
continue;
}
function simple_resumefield_form($defaults, $goto) {
global $simple_resume_artefacts, $simple_resume_types;
$simple_resume_artefacts = array();
$simple_resume_types = array_keys($defaults);
$form = array(
'name' => 'resumefieldform',
'plugintype' => 'artefact',
'pluginname' => 'resume',
'jsform' => true,
'successcallback' => 'simple_resumefield_submit',
'jssuccesscallback' => 'simple_resumefield_success',
'jserrorcallback' => 'simple_resumefield_error',
'elements' => array(),
);
foreach ($simple_resume_types as $t) {
try {
$a = artefact_instance_from_type($key);
$a->set('description', $value);
$simple_resume_artefacts[$t] = artefact_instance_from_type($t);
$content = $simple_resume_artefacts[$t]->get('description');
}
catch (Exception $e) {
global $USER;
$classname = generate_artefact_class_name($key);
$a = new $classname(0, array(
'owner' => $USER->get('id'),
'title' => get_string($key),
'description' => $value,
));
$content = $defaults[$t]['default'];
}
$fieldset = $t . 'fs';
$form['elements'][$fieldset] = array(
'type' => 'fieldset',
'legend' => get_string($t, 'artefact.resume'),
'elements' => array(
$t => array(
'type' => 'wysiwyg',
'class' => 'js-hidden',
'rows' => 20,
'cols' => 80,
'defaultvalue' => $content,
'rules' => array('maxlength' => 65536),
),
$t . 'submit' => array(
'type' => 'submitcancel',
'class' => 'js-hidden',
'value' => array(get_string('save'), get_string('cancel')),
'goto' => get_config('wwwroot') . $goto,
),
$t . 'display' => array(
'type' => 'html',
'class' => 'nojs-hidden-block',
'value' => $content,
),
$t . 'edit' => array(
'type' => 'button',
'class' => 'nojs-hidden-block openedit',
'value' => get_string('edit'),
),
),
);
if (!empty($defaults[$t]['fshelp'])) {
$form['elements'][$fieldset]['help'] = true;
}
$a->commit();
}
$form->json_reply(PIEFORM_OK, get_string('goalandskillsaved', 'artefact.resume'));
}
$form['elements']['goto'] = array(
'type' => 'hidden',
'value' => $goto,
);
return $form;
}
function simple_resumefield_submit(Pieform $form, $values) {
global $simple_resume_types, $simple_resume_artefacts, $USER;
foreach ($simple_resume_types as $t) {
if (isset($values[$t . 'submit']) && isset($values[$t])) {
if (!isset($simple_resume_artefacts[$t])) {
$classname = generate_artefact_class_name($t);
$simple_resume_artefacts[$t] = new $classname(0, array(
'owner' => $USER->get('id'),
'title' => get_string($t),
));
}
$simple_resume_artefacts[$t]->set('description', $values[$t]);
$simple_resume_artefacts[$t]->commit();
$data = array(
'message' => get_string('goalandskillsaved', 'artefact.resume'),
'update' => $t,
'content' => clean_html($values[$t]),
'goto' => get_config('wwwroot') . $values['goto'],
);
$form->reply(PIEFORM_OK, $data);
}
}
$form->reply(PIEFORM_OK, array('goto' => get_config('wwwroot') . $values['goto']));
}
......@@ -34,72 +34,25 @@ define('RESUME_SUBPAGE', 'skills');
require_once(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');
safe_require('artefact', 'resume');
define('TITLE', get_string('resume', 'artefact.resume'));
require_once(get_config('docroot') . 'artefact/lib.php');
$personal = null;
$academic = null;
$work = null;
try {
$personal = artefact_instance_from_type('personalskill');
}
catch (Exception $e) {}
try {
$academic = artefact_instance_from_type('academicskill');
}
catch (Exception $e) {}
try {
$work = artefact_instance_from_type('workskill');
}
catch (Exception $e) {}
$sform = array(
'name' => 'skillform',
'jsform' => true,
'plugintype' => 'artefact',
'pluginname' => 'resume',
'successcallback' => 'goalandskillform_submit',
'elements' => array(
'myskills' => array(
'type' => 'fieldset',
'legend' => get_string('myskills', 'artefact.resume'),
'help' => true,
'elements' => array(
'personalskill' => array(
'type' => 'wysiwyg',
'rows' => 20,
'cols' => 80,
'defaultvalue' => ((!empty($personal)) ? $personal->get('description') : null),
'title' => get_string('personalskill', 'artefact.resume'),
'rules' => array('maxlength' => 65536),
),
'academicskill' => array(
'type' => 'wysiwyg',
'rows' => 20,
'cols' => 80,
'defaultvalue' => ((!empty($academic)) ? $academic->get('description') : null),
'title' => get_string('academicskill', 'artefact.resume'),
'rules' => array('maxlength' => 65536),
),
'workskill' => array(
'type' => 'wysiwyg',
'rows' => 20,
'cols' => 80,
'defaultvalue' => ((!empty($work)) ? $work->get('description') : null),
'title' => get_string('workskill', 'artefact.resume'),
'rules' => array('maxlength' => 65536),
),
'submit' => array(
'type' => 'submit',
'value' => get_string('save'),
),
),
),
$defaults = array(
'personalskill' => array(
'default' => '',
),
'academicskill' => array(
'default' => '',
),
'workskill' => array(
'default' => '',
),
);
$skillform = pieform($sform);
$smarty = smarty();
$smarty->assign('skillform', $skillform);
$form = pieform(simple_resumefield_form($defaults, 'artefact/resume/skills.php'));
$smarty = smarty(array('jquery', 'artefact/resume/js/simpleresumefield.js'));
$smarty->assign('skillform', $form);
$smarty->assign('INLINEJAVASCRIPT', '$j(simple_resumefield_init);');
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('SUBPAGENAV', PluginArtefactResume::submenu_items());
$smarty->display('artefact:resume:skills.tpl');
{include file="header.tpl"}
<div id="resumewrap">
<h3>{str tag=mygoals section=artefact.resume} {contextualhelp plugintype='artefact' pluginname='resume' section='mygoals'}</h3>
{$goalform|safe}
</div>
{include file="footer.tpl"}
{include file="header.tpl"}
<div id="resumewrap">
<h3>{str tag=myskills section=artefact.resume} {contextualhelp plugintype='artefact' pluginname='resume' section='myskills'}</h3>
{$skillform|safe}
</div>
{include file="footer.tpl"}
Supports Markdown
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