Commit 01e988c2 authored by Maria Sorica's avatar Maria Sorica Committed by Robert Lyon
Browse files

Bug 1723961: Add edit links for each plan in a block instance

Each plan in a block instance will have a set of
edit, delete and add task links to make the
plan editing easier.

behatnotneeded

Change-Id: If4c9362906d894f4e4e6e0e9a2d59c640ede0506
parent bc40a45f
......@@ -76,7 +76,7 @@ class PluginBlocktypePlans extends MaharaCoreBlocktype {
}
else {
$baseurl = $instance->get_view()->get_url();
$baseurl .= ((false === strpos($baseurl, '?')) ? '?' : '&') . 'block=' . $blockid . '&planid=' . $planid;
$baseurl .= ((false === strpos($baseurl, '?')) ? '?' : '&') . 'block=' . $blockid . '&planid=' . $planid . '&editing=' . $editing;
$pagination = array(
'baseurl' => $baseurl,
'id' => 'block' . $blockid . '_plan' . $planid . '_pagination',
......@@ -86,7 +86,7 @@ class PluginBlocktypePlans extends MaharaCoreBlocktype {
}
$configdata['view'] = $instance->get('view');
$configdata['block'] = $blockid;
ArtefactTypeTask::render_tasks($tasks, $template, $configdata, $pagination);
ArtefactTypeTask::render_tasks($tasks, $template, $configdata, $pagination, $editing);
if ($exporter && $tasks['count'] > $tasks['limit']) {
$artefacturl = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $planid
......@@ -107,6 +107,7 @@ class PluginBlocktypePlans extends MaharaCoreBlocktype {
$tasks['planid'] = $planid;
array_push($alltasks, $tasks);
}
$smarty->assign('editing', $editing);
$smarty->assign('plans', $plans);
$smarty->assign('alltasks', $alltasks);
}
......
......@@ -22,6 +22,21 @@ $todelete = new ArtefactTypePlan($id);
if (!$USER->can_edit_artefact($todelete)) {
throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
$viewid = param_integer('view', 0);
if ($viewid) {
require_once('view.php');
$view = new View($viewid);
}
else {
$view = null;
}
if ($view && $USER->can_edit_view($view)) {
$returnurl = get_config('wwwroot') . 'view/blocks.php?id=' . $view->get('id');
}
else {
$returnurl = get_config('wwwroot') . '/artefact/plans/index.php';
}
$deleteform = array(
'name' => 'deleteplanform',
......@@ -34,7 +49,7 @@ $deleteform = array(
'type' => 'submitcancel',
'class' => 'btn-default',
'value' => array(get_string('deleteplan','artefact.plans'), get_string('cancel')),
'goto' => get_config('wwwroot') . '/artefact/plans/index.php',
'goto' => $returnurl,
),
)
);
......@@ -49,10 +64,18 @@ $smarty->display('artefact:plans:delete.tpl');
// calls this function first so that we can get the artefact and call delete on it
function deleteplanform_submit(Pieform $form, $values) {
global $SESSION, $todelete;
global $SESSION, $todelete, $view;
$todelete->delete();
$SESSION->add_ok_msg(get_string('plandeletedsuccessfully', 'artefact.plans'));
redirect('/artefact/plans/index.php');
// Redirect to view edit screen if plan was deleted from a block.
if ($view && $USER->can_edit_view($view)) {
$returnurl = get_config('wwwroot') . 'view/blocks.php?id=' . $view->get('id');
}
else {
$returnurl = get_config('wwwroot') . 'artefact/plans/index.php';
}
redirect($returnurl);
}
......@@ -23,12 +23,18 @@ if (!PluginArtefactPlans::is_active()) {
define('TITLE', get_string('editplan','artefact.plans'));
$id = param_integer('id');
$viewid = param_integer('view', 0);
if ($viewid) {
require_once('view.php');
$view = new View($viewid);
}
else {
$view = null;
}
$artefact = new ArtefactTypePlan($id);
if (!$USER->can_edit_artefact($artefact)) {
throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
$editform = ArtefactTypePlan::get_form($artefact);
$smarty = smarty();
......
......@@ -45,6 +45,8 @@ $string['youhavenplan'] = array(
);
/* Tasks */
$string['addtask'] = 'Add task';
$string['addtaskspecific'] = 'Add task to "%s"';
$string['alltasks'] = 'All tasks';
$string['canteditdontowntask'] = 'You cannot edit this task because you do not own it.';
$string['completed'] = 'Completed';
......
......@@ -159,7 +159,7 @@ class ArtefactTypePlan extends ArtefactType {
}
public static function submit(Pieform $form, $values) {
global $USER, $SESSION;
global $USER, $SESSION, $view;
$new = false;
......@@ -185,12 +185,17 @@ class ArtefactTypePlan extends ArtefactType {
$SESSION->add_ok_msg(get_string('plansavedsuccessfully', 'artefact.plans'));
if ($new) {
redirect('/artefact/plans/plan.php?id='.$artefact->get('id'));
if ($view && $USER->can_edit_view($view)) {
$returnurl = get_config('wwwroot') . 'view/blocks.php?id=' . $view->get('id');
}
else if ($new) {
$returnurl = get_config('wwwroot') . 'artefact/plans/plan.php?id=' . $artefact->get('id');
}
else {
redirect('/artefact/plans/index.php');
$returnurl = get_config('wwwroot') . 'artefact/plans/index.php';
}
redirect($returnurl);
}
/**
......@@ -198,13 +203,22 @@ class ArtefactTypePlan extends ArtefactType {
*
*/
public static function get_form($plan=null) {
global $USER, $view;
if ($view && $USER->can_edit_view($view)) {
$returnurl = get_config('wwwroot') . 'view/blocks.php?id=' . $view->get('id');
}
else {
$returnurl = get_config('wwwroot') . 'artefact/plans/index.php';
}
require_once('license.php');
$elements = call_static_method(generate_artefact_class_name('plan'), 'get_planform_elements', $plan);
$elements['submit'] = array(
'type' => 'submitcancel',
'class' => 'btn-primary',
'value' => array(get_string('saveplan','artefact.plans'), get_string('cancel')),
'goto' => get_config('wwwroot') . 'artefact/plans/index.php',
'goto' => $returnurl,
);
$planform = array(
'name' => empty($plan) ? 'addplan' : 'editplan',
......@@ -440,13 +454,22 @@ class ArtefactTypeTask extends ArtefactType {
*
*/
public static function get_form($parent, $task=null) {
global $USER, $view;
if ($view && $USER->can_edit_view($view)) {
$returnurl = get_config('wwwroot') . 'view/blocks.php?id=' . $view->get('id');
}
else {
$returnurl = get_config('wwwroot') . 'artefact/plans/plan.php?id=' . $parent;
}
require_once('license.php');
$elements = call_static_method(generate_artefact_class_name('task'), 'get_taskform_elements', $parent, $task);
$elements['submit'] = array(
'type' => 'submitcancel',
'class' => 'btn-primary',
'value' => array(get_string('savetask','artefact.plans'), get_string('cancel')),
'goto' => get_config('wwwroot') . 'artefact/plans/plan.php?id=' . $parent,
'goto' => $returnurl,
);
$taskform = array(
'name' => empty($task) ? 'addtasks' : 'edittask',
......@@ -545,7 +568,7 @@ class ArtefactTypeTask extends ArtefactType {
}
public static function submit(Pieform $form, $values) {
global $USER, $SESSION;
global $USER, $SESSION, $view;
if (!empty($values['task'])) {
$id = (int) $values['task'];
......@@ -571,7 +594,14 @@ class ArtefactTypeTask extends ArtefactType {
$SESSION->add_ok_msg(get_string('plansavedsuccessfully', 'artefact.plans'));
redirect('/artefact/plans/plan.php?id='.$values['parent']);
if ($view && $USER->can_edit_view($view)) {
$returnurl = get_config('wwwroot') . 'view/blocks.php?id=' . $view->get('id');
}
else {
$returnurl = get_config('wwwroot') . 'artefact/plans/plan.php?id=' . $values['parent'];
}
redirect($returnurl);
}
/**
......
......@@ -20,7 +20,15 @@ if (!PluginArtefactPlans::is_active()) {
throw new AccessDeniedException(get_string('plugindisableduser', 'mahara', get_string('plans','artefact.plans')));
}
$id = param_integer('id',0);
$id = param_integer('id', 0);
$viewid = param_integer('view', 0);
if ($viewid) {
require_once('view.php');
$view = new View($viewid);
}
else {
$view = null;
}
if ($id) {
define('SECTION_PAGE', 'newtask');
$plan = new ArtefactTypePlan($id);
......
{foreach from=$plans item=plan}
<div class="panel-body flush">
{if $editing}
<div class="pull-right btn-group">
<a class="btn btn-default btn-sm" href="{$WWWROOT}artefact/plans/edit/index.php?id={$plan.id}{if $plan.view}&view={$plan.view}{/if}" title="{str(tag=editspecific arg1=$plan.title)|escape:html|safe}">
<span class="icon icon-pencil"></span>
<span class="sr-only">{str tag='edit'}</span>
</a>
<a class="btn btn-default btn-sm" href="{$WWWROOT}artefact/plans/new.php?id={$plan.id}{if $plan.view}&view={$plan.view}{/if}" title="{str(tag=addtaskspecific section='artefact.plans' arg1=$plan.title)|escape:html|safe}">
<span class="icon icon-plus"></span>
<span class="sr-only">{str tag='addtask' section='artefact.plans'}</span>
</a>
<a class="btn btn-default btn-sm" href="{$WWWROOT}artefact/plans/delete/index.php?id={$plan.id}{if $plan.view}&view={$plan.view}{/if}" title="{str(tag=deletespecific arg1=$plan.title)|escape:html|safe}">
<span class="icon icon-trash text-danger"></span>
<span class="sr-only">{str tag='Delete'}</span>
</a>
</div>
{/if}
<strong>{$plan.title}</strong>
<p>{$plan.description}</p>
......
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