Commit 1274f7c3 authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan
Browse files

changing view layout to be a two step process for users with editing columns...

changing view layout to be a two step process for users with editing columns on view/blocks turned off
parent 445c8b5d
...@@ -196,9 +196,10 @@ $string['viewlayoutdescription'] = 'You can change the widths of the columns in ...@@ -196,9 +196,10 @@ $string['viewlayoutdescription'] = 'You can change the widths of the columns in
$string['changeviewlayout'] = 'Change my view layout'; $string['changeviewlayout'] = 'Change my view layout';
$string['backtoyourview'] = 'Back to my view'; $string['backtoyourview'] = 'Back to my view';
$string['viewlayoutchanged'] = 'View layout changed'; $string['viewlayoutchanged'] = 'View layout changed';
$string['selectnumberofcolumns'] = 'You can change the number of columns in your view'; $string['selectnumberofcolumns'] = 'Select the number of columns in your view';
$string['changeviewcolumns'] = 'Change my view columns'; $string['changeviewcolumns'] = 'Change my view columns';
$string['by'] = 'by'; $string['by'] = 'by';
$string['in'] = 'in'; $string['in'] = 'in';
$string['noblocks'] = 'Sorry, no blocks in this category :('; $string['noblocks'] = 'Sorry, no blocks in this category :(';
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<strong><a href="view.php?id={$view}&amp;new={$new}">{str tag=displaymyview section=view} &raquo;</a></strong> <strong><a href="view.php?id={$view}&amp;new={$new}">{str tag=displaymyview section=view} &raquo;</a></strong>
</div> </div>
<strong><a id="layout-link" href="layout.php?id={$view}&amp;c={$category}&amp;new={$new}">{str tag='changeviewlayout' section='view'}</a></strong> <strong><a id="layout-link" href="columns.php?id={$view}&amp;c={$category}&amp;new={$new}"{if !$can_change_layout} class="disabled"{/if}>{str tag='changeviewlayout' section='view'}</a></strong>
<div id="bottom-pane"> <div id="bottom-pane">
<div id="column-container"> <div id="column-container">
......
{include file="header.tpl"}
{include file="columnfullstart.tpl"}
<h2>{$heading}</h2>
{$form}
{include file="columnfullend.tpl"}
{include file="footer.tpl"}
...@@ -4,11 +4,6 @@ ...@@ -4,11 +4,6 @@
<h2>{str tag='viewlayout' section='view'}</h2> <h2>{str tag='viewlayout' section='view'}</h2>
<p>{str tag='selectnumberofcolumns' section='view'}</p>
{$columnsform}
{if $options}
<p>{str tag='viewlayoutdescription' section='view'}</p> <p>{str tag='viewlayoutdescription' section='view'}</p>
{$form_start_tag} {$form_start_tag}
...@@ -26,14 +21,12 @@ ...@@ -26,14 +21,12 @@
{/foreach} {/foreach}
<div class="cb"> <div class="cb">
<input type="hidden" name="pieform_viewlayout" value=""> <input type="hidden" name="pieform_viewlayout" value="">
{if $back}
<input type="submit" class="submit" name="cancel_submit" value="{str tag='back'}">
{/if}
<input type="submit" class="submit" name="submit" value="{str tag='changeviewlayout' section='view'}"> <input type="submit" class="submit" name="submit" value="{str tag='changeviewlayout' section='view'}">
</div> </div>
</form> </form>
{else}
<p>{$nolayouts}</p>
{/if}
<p><a href="{$WWWROOT}view/blocks.php?id={$view}&amp;new={$new}">&laquo; {str tag='backtoyourview' section='view'}</a></p>
{include file="columnfullend.tpl"} {include file="columnfullend.tpl"}
......
...@@ -99,6 +99,7 @@ $smarty->assign('formurl', get_config('wwwroot') . 'view/blocks.php'); ...@@ -99,6 +99,7 @@ $smarty->assign('formurl', get_config('wwwroot') . 'view/blocks.php');
$smarty->assign('category', $category); $smarty->assign('category', $category);
$smarty->assign('new', $new); $smarty->assign('new', $new);
$smarty->assign('view', $view->get('id')); $smarty->assign('view', $view->get('id'));
$smarty->assign('can_change_layout', (!$USER->get_account_preference('addremovecolumns') || ($view->get('numcolumns') > 1 && $view->get('numcolumns') < 5)));
$smarty->display('view/blocks.tpl'); $smarty->display('view/blocks.tpl');
?> ?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2007 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Clare Lenihan <clare@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'viewlayout');
require_once(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('view.php');
define('TITLE', get_string('changeviewcolumns', 'view'));
$id = param_integer('id');
$new = param_boolean('new');
$category = param_alpha('c', '');
$view = new View($id);
$numcolumns = $view->get('numcolumns');
if ($view->get('owner') != $USER->get('id')) {
throw new AccessDeniedException(get_string('canteditdontown', 'view'));
}
if ($USER->get_account_preference('addremovecolumns')) {
redirect('/view/layout.php?id=' . $id . '&c=' . $category . '&new=' . $new);
}
$columnsform = pieform(array(
'name' => 'viewcolumns',
'elements' => array(
'numcolumns' => array(
'type' => 'select',
'title' => get_string('selectnumberofcolumns', 'view'),
'options' => array( 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5'),
'defaultvalue' => $numcolumns,
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('next'), get_string('cancel')),
'goto' => get_config('wwwroot') . 'view/blocks.php?id=' . $view->get('id') . '&c=' . $category . '&new=' . $new
)
)
));
$smarty = smarty();
$smarty->assign('heading', TITLE);
$smarty->assign('form', $columnsform);
$smarty->display('view/columns.tpl');
function viewcolumns_submit(Pieform $form, $values) {
global $view, $SESSION, $category, $new;
$oldcolumns = $view->get('numcolumns');
$newcolumns = $values['numcolumns'];
if ($oldcolumns > $newcolumns) {
for ($i = $oldcolumns; $i > $newcolumns; $i--) {
$view->removecolumn(array('column' => $i));
}
}
else if ($oldcolumns < $newcolumns) {
for ($i = $oldcolumns; $i < $newcolumns; $i++) {
$view->addcolumn(array('before' => $i + 1, 'returndata' => false));
}
}
if ($newcolumns > 1 && $newcolumns < 5) {
redirect(get_config('wwwroot') . 'view/layout.php?id=' . $view->get('id') . '&c=' . $category . '&new=' . $new);
}
else {
$SESSION->add_ok_msg(get_string('viewlayoutchanged', 'view'));
redirect(get_config('wwwroot') . 'view/blocks.php?id=' . $view->get('id') . '&c=' . $category . '&new=' . $new);
}
}
?>
...@@ -31,7 +31,7 @@ define('MENUITEM', 'viewlayout'); ...@@ -31,7 +31,7 @@ define('MENUITEM', 'viewlayout');
require_once(dirname(dirname(__FILE__)) . '/init.php'); require_once(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php'); require_once('pieforms/pieform.php');
require_once('view.php'); require_once('view.php');
define('TITLE', 'Views Layout [DANGER construction site]'); define('TITLE', get_string('viewlayout', 'view'));
$id = param_integer('id'); $id = param_integer('id');
$new = param_boolean('new'); $new = param_boolean('new');
...@@ -39,6 +39,15 @@ $category = param_alpha('c', ''); ...@@ -39,6 +39,15 @@ $category = param_alpha('c', '');
$view = new View($id); $view = new View($id);
$numcolumns = $view->get('numcolumns'); $numcolumns = $view->get('numcolumns');
$currentlayout = $view->get('layout'); $currentlayout = $view->get('layout');
$back = !$USER->get_account_preference('addremovecolumns');
if ($view->get('owner') != $USER->get('id')) {
throw new AccessDeniedException(get_string('canteditdontown', 'view'));
}
// if not set, use equal width layout for that number of columns
if (!$currentlayout) {
$currentlayout = ($numcolumns == 2 ? 1 : ($numcolumns == 3 ? 4 : 7));
}
if ($numcolumns > 1 && $numcolumns < 5) { if ($numcolumns > 1 && $numcolumns < 5) {
$layouts = get_records_array('view_layout', 'columns', $numcolumns); $layouts = get_records_array('view_layout', 'columns', $numcolumns);
...@@ -52,47 +61,27 @@ if ($numcolumns > 1 && $numcolumns < 5) { ...@@ -52,47 +61,27 @@ if ($numcolumns > 1 && $numcolumns < 5) {
'layout' => array( 'layout' => array(
'type' => 'radio', 'type' => 'radio',
'options' => $options, 'options' => $options,
'defaultvalue' => $view->get('layout'), 'defaultvalue' => $currentlayout,
), ),
'submit' => array( 'submit' => array(
'type' => 'submit', 'type' => 'submitcancel',
'value' => get_string('submit'), 'value' => array(get_string('submit'), get_string('cancel')),
'goto' => get_config('wwwroot') . 'view/columns.php?id=' . $view->get('id') . '&c=' . $category . '&new=' . $new
), ),
), ),
)); ));
} }
else { else {
$nolayoutsmessage = get_string('noviewlayouts', 'view', $numcolumns); $SESSION->add_error_msg(get_string('noviewlayouts', 'view', $numcolumns));
redirect('/view/blocks.php?id=' . $id . '&c=' . $category . '&new=' . $new);
} }
$columnsform = pieform(array(
'name' => 'viewcolumns',
'renderer' => 'oneline',
'elements' => array(
'numcolumns' => array(
'type' => 'select',
'options' => array( 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5'),
'defaultvalue' => $numcolumns,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('changeviewcolumns', 'view')
)
)
));
$smarty = smarty(); $smarty = smarty();
$smarty->assign('columnsform', $columnsform);
$smarty->assign('currentlayout', $currentlayout); $smarty->assign('currentlayout', $currentlayout);
$smarty->assign('view', $id); $smarty->assign('form', $layoutform);
$smarty->assign('new', $new); $smarty->assign('form_start_tag', $layoutform->get_form_tag());
if (isset($layoutform)) { $smarty->assign('options', $options);
$smarty->assign('form_start_tag', $layoutform->get_form_tag()); $smarty->assign('back', $back);
$smarty->assign('options', $options);
}
else {
$smarty->assign('nolayouts', $nolayoutsmessage);
}
$smarty->display('view/layout.tpl'); $smarty->display('view/layout.tpl');
function viewlayout_submit(Pieform $form, $values) { function viewlayout_submit(Pieform $form, $values) {
...@@ -100,33 +89,7 @@ function viewlayout_submit(Pieform $form, $values) { ...@@ -100,33 +89,7 @@ function viewlayout_submit(Pieform $form, $values) {
$view->set('layout', $values['layout']); $view->set('layout', $values['layout']);
$view->commit(); $view->commit();
$SESSION->add_ok_msg(get_string('viewlayoutchanged', 'view')); $SESSION->add_ok_msg(get_string('viewlayoutchanged', 'view'));
redirect(get_config('wwwroot') . 'view/blocks.php?id=' . $view->get('id') . '&new=' . $new); redirect(get_config('wwwroot') . 'view/blocks.php?id=' . $view->get('id') . '&c=' . $category . '&new=' . $new);
}
function viewcolumns_submit(Pieform $form, $values) {
global $view, $SESSION, $category, $new;
$oldcolumns = $view->get('numcolumns');
$newcolumns = $values['numcolumns'];
if ($oldcolumns > $newcolumns) {
for ($i = $oldcolumns; $i > $newcolumns; $i--) {
$view->removecolumn(array('column' => $i));
}
}
else if ($oldcolumns < $newcolumns) {
for ($i = $oldcolumns; $i < $newcolumns; $i++) {
$view->addcolumn(array('before' => $i + 1, 'returndata' => false));
}
}
$SESSION->add_ok_msg(get_string('viewlayoutchanged', 'view'));
if ($newcolumns > 1 && $newcolumns < 5) {
redirect(get_config('wwwroot') . 'view/layout.php?id=' . $view->get('id') . '&c=' . $category . '&new=' . $new);
}
else {
redirect(get_config('wwwroot') . 'view/blocks.php?id=' . $view->get('id') . '&new=' . $new);
}
} }
?> ?>
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