Commit 6826f6a4 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Adding the dealing with collections (Bug #745418)



Need to handle the choosing of copy the collection when user clicks the
'copy' button

Change-Id: I93b6e505c4dd84a1efc4d71149d1f16a15b1c89f
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent f0ca6b1e
......@@ -163,3 +163,41 @@ addLoadEvent(function () {
});
}
});
jQuery(function($j) {
$j(".copyview").each(function() {
$j(this).click(function(e) {
if (e.target.href.match(/collection=(.*)/)) {
e.preventDefault();
// We need to let user choose from collection or view only
var collection = e.target.href.match(/collection=(.*)/)[1];
if (!$j('#dialog-confirm').length) {
$j('body').append('<div id="dialog-confirm" title="' + get_string('confirmcopytitle') + '">' + get_string('confirmcopydesc') + '</div>');
}
$j('#dialog-confirm').dialog({
resizable: false,
height: 200,
modal: true,
buttons: [
{
text: get_string('View'),
click: function() {
// drop the collection bit from the url
var url = e.target.href.replace(/collection=(.*)/, '');
console.log('copypage');
window.location = url;
}
},
{
text: get_string('Collection'),
click: function() {
console.log('copycollection');
window.location = e.target.href;
}
}
]
});
}
});
});
});
\ No newline at end of file
......@@ -373,6 +373,8 @@ $string['copyview'] = 'Copy page';
$string['createemptyview'] = 'Create empty page';
$string['copyaview'] = 'Copy a page';
$string['copyvieworcollection'] = 'Copy a page or collection';
$string['confirmcopytitle'] = 'Confirm copy';
$string['confirmcopydesc'] = 'Please choose which you would like to copy:';
$string['Untitled'] = 'Untitled';
$string['copyfornewusers'] = 'Copy for new users';
$string['copyfornewusersdescription1'] = 'Whenever a new user is created, automatically make a personal copy of the selected pages / collections in the user\'s portfolio.';
......
......@@ -6025,11 +6025,13 @@ function createview_submit(Pieform $form, $values) {
* Copy a view via a 'copy' url
* Currently for copying a page via a 'copy' button on view/view.php
*
* @param integer $id View id
* @param bool $istemplate (optional) If you want to mark as template
* @param integer $groupid Group id (optional) The group to copy the view to
* @param integer $id View id
* @param bool $istemplate (optional) If you want to mark as template
* @param integer $groupid (optional) The group to copy the view to
* @param integer $collectionid (optional) Provide the collection id to indicate we want
* to copy collection the view belongs to
*/
function copyview($id, $istemplate = false, $groupid = null) {
function copyview($id, $istemplate = false, $groupid = null, $collectionid = null) {
global $USER, $SESSION;
// check that the user can copy view
......@@ -6046,17 +6048,35 @@ function copyview($id, $istemplate = false, $groupid = null) {
if (!empty($groupid) && is_int($groupid)) {
$values['group'] = $groupid;
}
list($view, $template, $copystatus) = View::create_from_template($values, $id);
if (isset($copystatus['quotaexceeded'])) {
$SESSION->add_error_msg(get_string('viewcopywouldexceedquota', 'view'));
redirect(get_config('wwwroot') . 'view/view.php?id=' . $id);
if (!empty($collectionid)) {
require_once(get_config('libroot') . 'collection.php');
list($collection, $template, $copystatus) = Collection::create_from_template($values, $collectionid);
if (isset($copystatus['quotaexceeded'])) {
$SESSION->add_error_msg(get_string('collectioncopywouldexceedquota', 'collection'));
redirect(get_config('wwwroot') . 'view/view.php?id=' . $id);
}
$SESSION->add_ok_msg(get_string('copiedpagesblocksandartefactsfromtemplate', 'collection',
$copystatus['pages'],
$copystatus['blocks'],
$copystatus['artefacts'],
$template->get('name'))
);
redirect(get_config('wwwroot') . 'collection/edit.php?copy=1&id=' . $collection->get('id'));
}
else {
list($view, $template, $copystatus) = View::create_from_template($values, $id);
if (isset($copystatus['quotaexceeded'])) {
$SESSION->add_error_msg(get_string('viewcopywouldexceedquota', 'view'));
redirect(get_config('wwwroot') . 'view/view.php?id=' . $id);
}
$SESSION->add_ok_msg(get_string('copiedblocksandartefactsfromtemplate', 'view',
$copystatus['blocks'],
$copystatus['artefacts'],
$template->get('title'))
);
redirect(get_config('wwwroot') . 'view/edit.php?new=1&id=' . $view->get('id'));
}
$SESSION->add_ok_msg(get_string('copiedblocksandartefactsfromtemplate', 'view',
$copystatus['blocks'],
$copystatus['artefacts'],
$template->get('title'))
);
redirect(get_config('wwwroot') . 'view/edit.php?new=1&id=' . $view->get('id'));
}
function createview_cancel_submit(Pieform $form, $values) {
......
......@@ -41,7 +41,7 @@
<div class="fr links">
{if $microheaderlinks}
{foreach from=$microheaderlinks item=item}
<a class="btn" href="{$item.url}">{$item.name}</a>
<a class="btn{if $item.class} {$item.class}{/if}" href="{$item.url}">{$item.name}</a>
{/foreach}
{/if}
<a class="btn nojs-hidden-inline" href="javascript:history.back()"><span class="btn-back">{str tag=back}</span></a>
......
......@@ -12,7 +12,7 @@
{/if}
{/strip}{/if}
{if $copyurl}{strip}
<a title="{str tag=copythisview section=view}" href="{$copyurl}" class="btn editview">{str tag=copy section=mahara}</a>
<a title="{str tag=copythisview section=view}" href="{$copyurl}" class="btn copyview">{str tag=copy section=mahara}</a>
{/strip}{/if}
{if $mnethost}<a href="{$mnethost.url}" class="btn">{str tag=backto arg1=$mnethost.name}</a>{/if}
</div>
......
......@@ -42,7 +42,7 @@
<div class="fr links">
{if $microheaderlinks}
{foreach from=$microheaderlinks item=item}
<a class="btn" href="{$item.url}">{$item.name}</a>
<a class="btn{if $item.class} {$item.class}{/if}" href="{$item.url}">{$item.name}</a>
{/foreach}
{/if}
<a class="btn nojs-hidden-inline" href="javascript:history.back()"><span class="btn-back">{str tag=back}</span></a>
......
......@@ -20,6 +20,7 @@ require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'group.php');
$viewid = param_integer('id');
$collection = param_integer('collection', null);
$groupid = param_integer('group', null);
$view = new View($viewid);
......@@ -28,4 +29,4 @@ if (!$view->is_copyable()) {
throw new AccessDeniedException(get_string('thisviewmaynotbecopied', 'view'));
}
copyview($view->get('id'), 0, $groupid);
\ No newline at end of file
copyview($view->get('id'), 0, $groupid, $collection);
......@@ -185,7 +185,7 @@ function releaseview_submit() {
redirect($view->get_url());
}
$javascript = array('paginator', 'viewmenu', 'expandable', 'author');
$javascript = array('paginator', 'viewmenu', 'expandable', 'author', 'js/jquery/jquery-ui/js/jquery-ui-1.10.2.min.js');
$blocktype_js = $view->get_all_blocktype_javascript();
$javascript = array_merge($javascript, $blocktype_js['jsfiles']);
$inlinejs = "addLoadEvent( function() {\n" . join("\n", $blocktype_js['initjs']) . "\n});";
......@@ -222,6 +222,7 @@ if ($viewtheme && $THEME->basename != $viewtheme) {
$THEME = new Theme($viewtheme);
}
$headers = array('<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'theme/views.css') . '">');
$headers[] = '<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'js/jquery/jquery-ui/css/ui-lightness/jquery-ui-1.10.2.min.css') . '">';
$headers = array_merge($headers, $view->get_all_blocktype_css());
// Set up skin, if the page has one
$viewskin = $view->get('skin');
......@@ -264,7 +265,10 @@ $viewcontent = $view->build_rows(); // Build content before initialising smarty
$smarty = smarty(
$javascript,
$headers,
array(),
array('confirmcopytitle' => 'view',
'confirmcopydesc' => 'view',
'View' => 'view',
'Collection' => 'collection'),
array(
'stylesheets' => $extrastylesheets,
'sidebars' => false,
......@@ -384,7 +388,8 @@ if (get_config('viewmicroheaders')) {
$microheaderlinks[] = array(
'name' => get_string('copy', 'mahara'),
'image' => $THEME->get_url('images/btn_edit.png'),
'url' => get_config('wwwroot') . 'view/copy.php?id=' . $viewid,
'url' => get_config('wwwroot') . 'view/copy.php?id=' . $viewid . (!empty($collection) ? '&collection=' . $collection->get('id') : ''),
'class' => 'copyview',
);
}
$smarty->assign('microheaderlinks', $microheaderlinks);
......@@ -394,7 +399,7 @@ else {
$smarty->assign('editurl', get_config('wwwroot') . 'view/blocks.php?id=' . $viewid . ($new ? '&new=1' : ''));
}
if ($can_copy) {
$smarty->assign('copyurl', get_config('wwwroot') . 'view/copy.php?id=' . $viewid);
$smarty->assign('copyurl', get_config('wwwroot') . 'view/copy.php?id=' . $viewid . (!empty($collection) ? '&collection=' . $collection->get('id') : ''));
}
}
......
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