Commit bc18da3c authored by Doris Tam's avatar Doris Tam Committed by Lisa Seeto
Browse files

Bug 1269724: Return to the editing page after adding journal entry from the page

Added another query parameter in the url 'shortcutnewentryviewid' to know which view
the request for new entry came from and  to know where to return to once new entry is made.

Change-Id: I5c6a7e2fd214f6fb8dc61acead56f746992976eb
parent 6fb84258
function addNewPostShortcut(blockid) {
function addNewPostShortcut(blockid, viewid) {
var addentry = jQuery('#blockinstance_' + blockid + ' .blockinstance-content');
addentry.find('a').first().on("click", function(e) {
e.preventDefault();
......@@ -6,6 +6,6 @@ function addNewPostShortcut(blockid) {
if (!blogselect) {
blogselect = jQuery(this).find('span').first().attr('id').match( /\d+/);
}
window.open(config.wwwroot + 'artefact/blog/post.php?blog=' + blogselect, '_self');
window.open(config.wwwroot + 'artefact/blog/post.php?blog=' + blogselect + '&shortcutnewentryviewid=' + viewid, '_self');
});
}
}
\ No newline at end of file
......@@ -28,10 +28,11 @@ class PluginBlocktypeRecentposts extends MaharaCoreBlocktype {
public static function get_instance_javascript(BlockInstance $bi) {
$blockid = $bi->get('id');
$viewid = $bi->get('view');
return array(
array(
'file' => 'js/recentposts.js',
'initjs' => "addNewPostShortcut($blockid);",
'initjs' => "addNewPostShortcut($blockid, $viewid);",
)
);
}
......
var addNewTaggedPostShortcut = (function($) {
return function (blockid) {
return function (blockid, viewid) {
$('#blockinstance_' + blockid + ' a.btnshortcut').each(function() {
$(this).off();
$(this).on('click', function(e) {
......@@ -9,7 +9,7 @@ var addNewTaggedPostShortcut = (function($) {
var currentTag = p.find('input.select').first();
var BlogIDInput = $('<input>', {'name': 'blog', 'type': 'text', 'value': selectedBlog[0].value});
var TagInput = $('<input>', {'name': 'tagselect', 'type': 'text', 'value': currentTag[0].value});
var myForm = $('<form>', {'action': config.wwwroot + 'artefact/blog/post.php', 'method': 'POST'});
var myForm = $('<form>', {'action': config.wwwroot + 'artefact/blog/post.php?shortcutnewentryviewid='+ viewid, 'method': 'POST'});
myForm.append(BlogIDInput[0], TagInput);
document.body.appendChild(myForm[0]);
myForm.trigger('submit');
......
......@@ -30,10 +30,11 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
public static function get_instance_javascript(BlockInstance $bi) {
$blockid = $bi->get('id');
$viewid = $bi->get('view');
return array(
array(
'file' => 'js/taggedposts.js',
'initjs' => "addNewTaggedPostShortcut($blockid);",
'initjs' => "addNewTaggedPostShortcut($blockid, $viewid);",
)
);
}
......
......@@ -96,6 +96,11 @@ if ($file = param_integer('file', 0)) {
$highlight = array($file);
}
$goto = get_config('wwwroot') . 'artefact/blog/view/index.php?id=' . $blog;
// check if we came from new entry shortcut of a blog block
if (param_exists('shortcutnewentryviewid')) {
$goto = get_config('wwwroot') . 'view/blocks.php?id=' . param_integer('shortcutnewentryviewid');
}
$form = pieform(array(
'name' => 'editpost',
......@@ -188,7 +193,7 @@ $form = pieform(array(
'type' => 'submitcancel',
'subclass' => array('btn-primary'),
'value' => array(get_string('savepost', 'artefact.blog'), get_string('cancel')),
'goto' => get_config('wwwroot') . 'artefact/blog/view/index.php?id=' . $blog,
'goto' => $goto,
)
)
));
......@@ -222,7 +227,7 @@ $smarty->display('artefact:blog:editpost.tpl');
* blog list.
*/
function editpost_cancel_submit() {
global $blog;
global $blog, $goto;
$blogobj = new ArtefactTypeBlog($blog);
if ($blogobj->get('institution')) {
redirect(get_config('wwwroot') . 'artefact/blog/view/index.php?id=' . $blog . '&institution=' . $blogobj->get('institution'));
......@@ -231,12 +236,12 @@ function editpost_cancel_submit() {
redirect(get_config('wwwroot') . 'artefact/blog/view/index.php?id=' . $blog . '&group=' . $blogobj->get('group'));
}
else {
redirect(get_config('wwwroot') . 'artefact/blog/view/index.php?id=' . $blog);
redirect($goto);
}
}
function editpost_submit(Pieform $form, $values) {
global $USER, $SESSION, $blogpost, $blog;
global $USER, $SESSION, $blogpost, $blog, $goto;
require_once('embeddedimage.php');
db_begin();
......@@ -279,7 +284,8 @@ function editpost_submit(Pieform $form, $values) {
$result = array(
'error' => false,
'message' => get_string('blogpostsaved', 'artefact.blog'),
'goto' => get_config('wwwroot') . 'artefact/blog/view/index.php?id=' . $blog,
'goto' => $goto
);
if ($form->submitted_by_js()) {
// Redirect back to the blog page from within the iframe
......
......@@ -3,7 +3,7 @@
{str tag='alldraftposts' section='artefact.blog'}
{/if}
{if ($editing && $canaddpost)}
<a class="card-footer" href="{$WWWROOT}artefact/blog/post.php?blog={$blogid}">
<a class="card-footer" href="{$WWWROOT}artefact/blog/post.php?blog={$blogid}&shortcutnewentryviewid={$view}">
<span class="icon icon-plus left" role="presentation" aria-hidden="true"></span>
{str tag='shortcutnewentry' section='artefact.blog'}
</a>
......
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