Commit 5f57b602 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon

Bug 1813987: Remove 'addcolumn' functionality when editing a view

behatnotneeded

Change-Id: I99b248e03ffe5b23e622c46ce14765bdf1e47195
parent d45aed8d
......@@ -269,7 +269,6 @@
attachAccordion();
attachToolbarToggle();
// Rewrite the configure buttons to be ajax
rewriteConfigureButtons();
......@@ -279,15 +278,6 @@
// Show the keyboard-accessible ajax move buttons
rewriteMoveButtons();
// Rewrite the 'add column' buttons to be ajax
rewriteAddColumnButtons();
// Rewrite the 'remove column' buttons to be ajax
rewriteRemoveColumnButtons();
// Ensure the enabled/disabled state of the add/remove buttons is correct
checkColumnButtonDisabledState();
// Setup the 'add block' dialog
setupPositionBlockDialog();
......@@ -296,7 +286,6 @@
makeNewBlocksDraggable();
makeExistingBlocksSortable();
$(workspace).show();
$(window).on('resize colresize', function(){
......@@ -404,8 +393,6 @@
});
}
function loadCookieContentEditorCollapsed() {
if (document.cookie) {
var index = document.cookie.indexOf(cookieName),
......@@ -955,124 +942,6 @@
});
}
/**
* Rewrites the add column buttons to be AJAX
*
*/
function rewriteAddColumnButtons() {
$('[data-action="addcolumn"]').each(function() {
$(this).off('click'); // prevent double binding
$(this).on('click', function(e) {
e.stopPropagation();
e.preventDefault();
// Work around for a konqueror bug - konqueror passes onclick
// events to disabled buttons
if (!$(this).disabled) {
$(this).prop('disabled', true);
var name = $(this).attr('name'),
match = name.match(/action_addcolumn_row_(\d+)_before_(\d+)/),
rowid = parseInt(match[1], 10),
colid = parseInt(match[2], 10),
pd = {'id': $('#viewid').val(), 'change': 1};
pd['action_addcolumn_row_' + rowid + '_before_' + colid] = 1;
sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST', function(data) {
addColumn(rowid, colid, data);
checkColumnButtonDisabledState();
}, function() {
checkColumnButtonDisabledState();
});
}
});
});
}
/**
* Rewrite the remove column buttons to be AJAX
*
* If the first parameter is a string/element, only the buttons below that
* element will be rewritten
*/
function rewriteRemoveColumnButtons() {
workspace.find('.removecolumn').off('click'); // prevent double binding
workspace.find('.removecolumn').on('click', function(e) {
e.stopPropagation();
e.preventDefault();;
// Work around for a konqueror bug - konqueror passes onclick
// events to disabled buttons
if (!this.disabled) {
$(this).attr('disabled', 'disabled');
var name = $(this).attr('name'),
match = name.match(/action_removecolumn_row_(\d+)_column_(\d+)/),
rowid = parseInt(match[1], 10),
colid = parseInt(match[2], 10),
pd = {'id': $('#viewid').val(), 'change': 1};
pd['action_removecolumn_row_' + rowid + '_column_' + colid] = 1;
sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST', function(data) {
removeColumn(rowid, colid);
checkColumnButtonDisabledState();
}, function() {
checkColumnButtonDisabledState();
});
}
});
}
/**
* Disables the 'add column' buttons
*/
function checkColumnButtonDisabledState() {
// For each row
workspace.find('.js-col-row').each(function() {
// Get the existing number of columns
var match = $(this).find('.column'),
numColumns = match.length,
state = (numColumns === 5);
$('.addcolumn', $(this)).each(function() {
if (state) {
$(this).prop('disabled', true);
}
else {
$(this).prop('disabled', false);
}
});
state = (numColumns === 1);
$('.removecolumn', $(this)).each(function() {
if (state) {
$(this).prop('disabled', true);
}
else {
$(this).prop('disabled', false);
}
});
});
}
/**
* return true if the mousedown is <LEFT BUTTON> or the keydown is <Space> or <Enter>
*/
......@@ -1336,118 +1205,6 @@
return {'row': row, 'column': column, 'order': order};
}
function renumberColumns(rowid) {
var columns = $('#row_'+rowid).find('.column'),
numColumns = columns.length,
addrightbutton,
i;
// Renumber all columns
for (i = 1; i <= numColumns; i = i + 1) {
$(columns[i - 1]).attr('id', 'row_' + rowid + '_column_' + i);
$('.addcolumn', $('#row_' + rowid + '_column_' + i)).attr('name', 'action_addcolumn_row_' + rowid + '_before_' + i);
$('.removecolumn', $('#row_' + rowid + '_column_' + i)).attr('name', 'action_removecolumn_row_' + rowid + '_column_' + i);
}
// If the column being added is the very first one, the 'left' add column button needs to be removed
$('#row_' + rowid + '_column_2 .js-add-column-left').remove();
$('#row_' + rowid + '_column_2 .btn-three').removeClass('btn-three').addClass('btn-two');
// Renumber the columns classes of the remaining columns, and remove any set widths
$(columns).removeClass('columns1 columns2 columns3 columns4 columns5');
$(columns).addClass('columns' + numColumns);
$(columns).attr('style', '');
//Update last
$('.lastcolumn').removeClass('lastcolumn');
$('.js-col-row .column:last-child').addClass('lastcolumn');
// Move the add button between the columns
columns.find('.js-add-column-right').removeClass('js-add-column-right').addClass('js-add-column-center');
$('.js-col-row .column:last-child').find('.addcolumn').addClass('js-add-column-right').removeClass('js-add-column-center');
}
/**
* Adds a column to the view
*/
function addColumn(rowid, colid, data) {
// Get the existing number of columns
var tempDiv = $('<div>');
/// Now we insert the new column into the DOM. Inserting the HTML into a
// new element and then into the DOM means we can add the new column
// without changing any of the existing DOM tree (and thus destroying
// events)
tempDiv.html(data.data);
if (colid === 1) {
$(':first', tempDiv).insertBefore('#row_' + rowid + '_column_1');
}
else {
$(':first', tempDiv).insertAfter('#row_' + rowid + '_column_' + (colid - 1));
}
renumberColumns(rowid);
// Wire up the new column buttons to be AJAX
rewriteAddColumnButtons();
rewriteRemoveColumnButtons();
makeExistingBlocksSortable();
}
/**
* Removes a column from the view, sizes the others to take its place and
* moves the blockinstances in it to the other columns
*/
function removeColumn(rowid, colid) {
var addColumnLeftButtonContainer,
blockInstances = $('#row_' + rowid + '_column_' + colid + ' .blockinstance'),
columns = $('#row_'+rowid).find('.column'),
numColumns = columns.length,
i = 1,
currentTallest;
if (colid === 1) {
// We are removing the first column, which has the button for adding a column to the left of itself. We want to keep this
addColumnLeftButtonContainer = $('#row_' + rowid).find('.js-add-column-left').first();
}
// Remove the column itself
$('#row_' + rowid + '_column_' + colid).remove();
renumberColumns(rowid);
if (addColumnLeftButtonContainer) {
$('#row_' + rowid + '_column_1 .js-remove-column').before(addColumnLeftButtonContainer);
$('#row_' + rowid + '_column_1 .btn-two').removeClass('btn-two').addClass('btn-three');
}
// Put the block instances that were in the removed column into the other columns
$(blockInstances).each(function() {
$('#row_' + rowid + '_column_' + i + ' .column-content').append($(this));
if (i < (numColumns - 1)) {
i++;
}
$(this).find('.column-content').each(function(i) {
if ($(this).height() > currentTallest) {
currentTallest = $(this).height();
}
});
$(this).find('.column-content').css({'min-height': currentTallest});
});
rewriteAddColumnButtons();
rewriteRemoveColumnButtons();
}
/**
* Initialise
*
......
......@@ -47,8 +47,6 @@ $string['messagesallow'] = 'Allow anyone to send me messages';
$string['language'] = 'Language';
$string['showviewcolumns'] = 'Show controls to add and remove columns when editing a page';
$string['tagssideblockmaxtags'] = 'Maximum tags in cloud';
$string['tagssideblockmaxtagsdescription'] = 'Maximum number of tags to display in your tag cloud';
......
......@@ -229,7 +229,6 @@ function expected_account_preferences() {
'licensedefault' => '',
'messages' => 'allow',
'lang' => 'default',
'addremovecolumns' => 0,
'maildisabled' => 0,
'tagssideblockmaxtags' => get_config('tagssideblockmaxtags'),
'groupsideblockmaxgroups' => '',
......@@ -374,12 +373,6 @@ function general_account_prefs_form_elements($prefs) {
'help' => true,
);
$elements['addremovecolumns'] = array(
'type' => 'switchbox',
'defaultvalue' => $prefs->addremovecolumns,
'title' => get_string('showviewcolumns', 'account'),
'help' => 'true'
);
// TODO: add a way for plugins (like blog!) to have account preferences
$elements['multipleblogs'] = array(
'type' => 'switchbox',
......
......@@ -2261,7 +2261,6 @@ class View {
$smarty->assign('row', $row);
$smarty->assign('numcolumns', $currentrownumcols);
$smarty->assign('rowcontent', $result);
$smarty->assign('addremovecolumns', $USER->get_account_preference('addremovecolumns'));
if ($editing) {
// TODO look into this - necessary?
......@@ -2344,8 +2343,6 @@ class View {
$smarty->assign('width', $data['width']);
}
$smarty->assign('addremovecolumns', $USER->get_account_preference('addremovecolumns'));
if ($editing) {
return $smarty->fetch('view/columnediting.tpl');
}
......
<div id="row_{$row}_column_{$column}" class="column column-layout columns{$numcolumns}{if $column == 1} firstcolumn{/if}{if $column == $numcolumns} lastcolumn{/if} {if $width}col-width-{$width}{/if}" {if $width}style="width:{if $width == 100}{$width }%;{else}{$width - 2}%;{/if}"{/if}>
{if $addremovecolumns}
<div class="btn-header btn-group {if $column == 1}btn-three{else}btn-two{/if}">
{if $column == 1}
<button name="action_addcolumn_row_{$row}_before_1" alt="{str tag='add' section='view'}" title="{str tag='addcolumn' section='view'}" data-action="addcolumn" class="js-add-column-left addcolumn btn btn-secondary btn-sm text-left">
<span class="icon-long-arrow-alt-left icon-rotate-45 icon" role="presentation"></span>
<span class="icon-plus icon" role="presentation"></span>
</button>
{/if}
<button name="action_removecolumn_row_{$row}_column_{$column}" alt="{str tag='remove' section='view'}" title="{str tag='removecolumn' section='view'}" class="js-remove-column removecolumn text-center btn btn-secondary btn-sm">
<span class="icon-times-circle icon-lg icon" role="presentation"></span>
</button>
{if $column == $numcolumns}
<button name="action_addcolumn_row_{$row}_before_{$column+1}" alt="{str tag='add' section='view'}" title="{str tag='addcolumn' section='view'}" data-action="addcolumn" class="js-add-column-right addcolumn btn btn-secondary btn-sm text-right">
<span class="icon-plus icon" role="presentation"></span>
<span class="icon-long-arrow-alt-right icon-rotate-45 icon" role="presentation"></span>
</button>
{else}
<button name="action_addcolumn_row_{$row}_before_{$column+1}" alt="{str tag='add' section='view'}" title="{str tag='addcolumn' section='view'}" data-action="addcolumn" class="js-add-column-center addcolumn btn btn-secondary btn-sm text-right">
<span class="icon-plus icon" role="presentation"></span>
<span class="icon-long-arrow-alt-right icon-rotate-45 icon" role="presentation"></span>
</button>
{/if}
</div>
{else}
<div class="column-header-empty"></div>
{/if}
<div class="column-content">
{$blockcontent|safe}
</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