Commit df4a7c33 authored by Nigel McNie's avatar Nigel McNie
Browse files

Merged in the configurable column width support. Reasonably basic right now

parent 3ffb8160
...@@ -81,6 +81,7 @@ function ViewManager() { ...@@ -81,6 +81,7 @@ function ViewManager() {
// Here we are doing two things: // Here we are doing two things:
// 1) The existing columns that are higher than the one being inserted need to be renumbered // 1) The existing columns that are higher than the one being inserted need to be renumbered
// 2) All columns need their 'columnsN' class renumbered one higher // 2) All columns need their 'columnsN' class renumbered one higher
// 3) All columns need their 'width' style attribute removed, if they have one
for (var oldID = numColumns; oldID >= 1; oldID--) { for (var oldID = numColumns; oldID >= 1; oldID--) {
var column = $('column_' + oldID); var column = $('column_' + oldID);
var newID = oldID + 1; var newID = oldID + 1;
...@@ -93,6 +94,7 @@ function ViewManager() { ...@@ -93,6 +94,7 @@ function ViewManager() {
} }
removeElementClass(column, 'columns' + numColumns); removeElementClass(column, 'columns' + numColumns);
addElementClass(column, 'columns' + (numColumns + 1)); addElementClass(column, 'columns' + (numColumns + 1));
removeNodeAttribute(column, 'style');
} }
// If the column being added is the very first one, the 'left' add column button needs to be removed // If the column being added is the very first one, the 'left' add column button needs to be removed
...@@ -120,6 +122,13 @@ function ViewManager() { ...@@ -120,6 +122,13 @@ function ViewManager() {
insertSiblingNodesAfter('column_' + (id - 1), tempDiv.firstChild); insertSiblingNodesAfter('column_' + (id - 1), tempDiv.firstChild);
} }
if (numColumns == 1) {
showElement('layout-link');
}
else if (numColumns == 4) {
hideElement('layout-link');
}
// Wire up the new column buttons to be AJAX // Wire up the new column buttons to be AJAX
self.rewriteAddColumnButtons('column_' + id); self.rewriteAddColumnButtons('column_' + id);
self.rewriteRemoveColumnButtons('column_' + id); self.rewriteRemoveColumnButtons('column_' + id);
...@@ -144,9 +153,12 @@ function ViewManager() { ...@@ -144,9 +153,12 @@ function ViewManager() {
// Get the existing number of columns // Get the existing number of columns
var numColumns = parseInt(getNodeAttribute(getFirstElementByTagAndClassName('div', 'column', self.bottomPane), 'class').match(/columns([0-9]+)/)[1]); var numColumns = parseInt(getNodeAttribute(getFirstElementByTagAndClassName('div', 'column', self.bottomPane), 'class').match(/columns([0-9]+)/)[1]);
// Renumber the columnsN classes of the remaining columns, and remove any set widths
forEach(getElementsByTagAndClassName('div', 'columns' + numColumns, self.bottomPane), function(i) { forEach(getElementsByTagAndClassName('div', 'columns' + numColumns, self.bottomPane), function(i) {
removeElementClass(i, 'columns' + numColumns); removeElementClass(i, 'columns' + numColumns);
addElementClass(i, 'columns' + (numColumns - 1)); addElementClass(i, 'columns' + (numColumns - 1));
removeNodeAttribute(i, 'style');
}); });
...@@ -163,6 +175,13 @@ function ViewManager() { ...@@ -163,6 +175,13 @@ function ViewManager() {
} }
} }
if (numColumns == 2) {
hideElement('layout-link');
}
else if (numColumns == 5) {
showElement('layout-link');
}
// The last column needs the class of the header changed, the first column possibly too // The last column needs the class of the header changed, the first column possibly too
if (addColumnLeftButtonContainer) { if (addColumnLeftButtonContainer) {
insertSiblingNodesBefore( insertSiblingNodesBefore(
......
...@@ -86,4 +86,11 @@ $string['removecolumn'] = 'Remove column'; ...@@ -86,4 +86,11 @@ $string['removecolumn'] = 'Remove column';
$string['titleformatted'] = '%s by %s'; $string['titleformatted'] = '%s by %s';
$string['50,50'] = $string['33,33,33'] = $string['25,25,25,25'] = 'Equal widths';
$string['67,33'] = 'Larger left column';
$string['33,67'] = 'Larger right column';
$string['25,50,25'] = 'Larger centre column';
$string['15,70,15'] = 'Much larger centre column';
$string['20,30,30,20'] = 'Larger centre columns';
?> ?>
...@@ -378,11 +378,13 @@ ...@@ -378,11 +378,13 @@
<FIELD NAME="atime" TYPE="datetime" NOTNULL="true" /> <FIELD NAME="atime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="submittedto" TYPE="int" LENGTH="10" NOTNULL="false" /> <FIELD NAME="submittedto" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="numcolumns" TYPE="int" LENGTH="2" NOTNULL="true" /> <FIELD NAME="numcolumns" TYPE="int" LENGTH="2" NOTNULL="true" />
<FIELD NAME="layout" TYPE="int" LENGTH="10"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" /> <KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="ownerfk" TYPE="foreign" FIELDS="owner" REFTABLE="usr" REFFIELDS="id" /> <KEY NAME="ownerfk" TYPE="foreign" FIELDS="owner" REFTABLE="usr" REFFIELDS="id" />
<KEY NAME="submittedtofk" TYPE="foreign" FIELDS="submittedto" REFTABLE="group" REFFIELDS="id" /> <KEY NAME="submittedtofk" TYPE="foreign" FIELDS="submittedto" REFTABLE="group" REFFIELDS="id" />
<KEY NAME="layoutfk" TYPE="foreign" FIELDS="layout" REFTABLE="view_layout" REFFIELDS="id"/>
</KEYS> </KEYS>
</TABLE> </TABLE>
<TABLE NAME="view_tag"> <TABLE NAME="view_tag">
...@@ -412,6 +414,17 @@ ...@@ -412,6 +414,17 @@
<KEY NAME="viewcolumnorderuk" TYPE="unique" FIELDS="view,column,order" /> <KEY NAME="viewcolumnorderuk" TYPE="unique" FIELDS="view,column,order" />
</KEYS> </KEYS>
</TABLE> </TABLE>
<TABLE NAME="view_layout">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="columns" TYPE="int" LENGTH="1" NOTNULL="true"/>
<FIELD NAME="widths" TYPE="char" LENGTH="255" NOTNULL="true"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="columnwidthuk" UNIQUE="true" FIELDS="columns,widths"/>
</KEYS>
</TABLE>
<TABLE NAME="view_artefact"> <TABLE NAME="view_artefact">
<FIELDS> <FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" /> <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
......
...@@ -48,6 +48,7 @@ class View { ...@@ -48,6 +48,7 @@ class View {
private $artefact_hierarchy; private $artefact_hierarchy;
private $ownerobj; private $ownerobj;
private $numcolumns; private $numcolumns;
private $layout;
private $columns; private $columns;
private $dirtycolumns; // for when we change stuff private $dirtycolumns; // for when we change stuff
private $tags; private $tags;
...@@ -595,7 +596,7 @@ class View { ...@@ -595,7 +596,7 @@ class View {
// set stuff in the session and redirect // set stuff in the session and redirect
$fun = 'add_ok_msg'; $fun = 'add_ok_msg';
if (!$success) { if (!$success) {
$fun = 'add_err_msg'; $fun = 'add_error_msg';
} }
$SESSION->{$fun}($message); $SESSION->{$fun}($message);
redirect('/view/blocks.php?id=' . $this->get('id') . 'c=' . $category . '&new=' . $new); redirect('/view/blocks.php?id=' . $this->get('id') . 'c=' . $category . '&new=' . $new);
...@@ -653,6 +654,19 @@ class View { ...@@ -653,6 +654,19 @@ class View {
$this->columns[$i] = array('blockinstances' => array()); $this->columns[$i] = array('blockinstances' => array());
} }
// Set column widths
if ($this->get('numcolumns') > 1) {
$layout = $this->get('layout');
if ($layout) {
$i = 0;
// The get_field also verifies the layout is correct for the
// number of columns in the view
foreach (explode(',', get_field('view_layout', 'widths', 'id', $layout, 'columns', $this->get('numcolumns'))) as $width) {
$this->columns[++$i]['width'] = $width;
}
}
}
foreach ($data as $block) { foreach ($data as $block) {
require_once(get_config('docroot') . 'blocktype/lib.php'); require_once(get_config('docroot') . 'blocktype/lib.php');
$b = new BlockInstance($block->id, (array)$block); $b = new BlockInstance($block->id, (array)$block);
...@@ -742,12 +756,24 @@ class View { ...@@ -742,12 +756,24 @@ class View {
$blockcontent .= $blockinstance->$renderfunction($blockinstance->get('id') == $this->blockinstance_currently_being_configured); $blockcontent .= $blockinstance->$renderfunction($blockinstance->get('id') == $this->blockinstance_currently_being_configured);
} }
// Widths don't appear to apply to divs unless they have at least
// _some_ content - at least in gecko (make a view with a particular
// layout like 25/50/25 and make the middle column empty and you'll see
// what I mean)
if ($blockcontent == '') {
$blockcontent = '&nbsp;';
}
$smarty = smarty_core(); $smarty = smarty_core();
$smarty->assign('javascript', defined('JSON')); $smarty->assign('javascript', defined('JSON'));
$smarty->assign('column', $column); $smarty->assign('column', $column);
$smarty->assign('numcolumns', $this->get('numcolumns')); $smarty->assign('numcolumns', $this->get('numcolumns'));
$smarty->assign('blockcontent', $blockcontent); $smarty->assign('blockcontent', $blockcontent);
if (isset($data['width'])) {
$smarty->assign('width', intval($data['width']));
}
if ($editing) { if ($editing) {
return $smarty->fetch('view/columnediting.tpl'); return $smarty->fetch('view/columnediting.tpl');
} }
...@@ -957,6 +983,7 @@ EOF; ...@@ -957,6 +983,7 @@ EOF;
if ($values['before'] != ($this->get('numcolumns') + 1)) { if ($values['before'] != ($this->get('numcolumns') + 1)) {
$this->shuffle_helper('column', 'up', '>=', $values['before']); $this->shuffle_helper('column', 'up', '>=', $values['before']);
} }
$this->set('layout', null);
$this->commit(); $this->commit();
// @TODO this could be optimised by actually moving the keys around, // @TODO this could be optimised by actually moving the keys around,
// but I don't think there's much point as the objects aren't persistent // but I don't think there's much point as the objects aren't persistent
...@@ -1008,6 +1035,7 @@ EOF; ...@@ -1008,6 +1035,7 @@ EOF;
} }
} }
$this->set('layout', null);
$this->set('numcolumns', $this->get('numcolumns') - 1); $this->set('numcolumns', $this->get('numcolumns') - 1);
// now shift all blocks one left and we're done // now shift all blocks one left and we're done
$this->shuffle_helper('column', 'down', '>', $values['column']); $this->shuffle_helper('column', 'down', '>', $values['column']);
......
<div id="column_{$column}" class="column columns{$numcolumns}"> <div id="column_{$column}" class="column columns{$numcolumns}"{if $width} style="width: {$width-2}%;"{/if}>
<div class="column-header"> <div class="column-header">
{if $column == 1} {if $column == 1}
<div class="add-column-left"> <div class="add-column-left">
......
<div id="column_{$column}" class="column columns{$numcolumns}"> <div id="column_{$column}" class="column columns{$numcolumns}"{if $width} style="width: {$width-2}%;"{/if}>
<div class="column-content"> <div class="column-content">
{$blockcontent} {$blockcontent}
</div> </div>
......
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