Commit 4d9a5645 authored by Robert Lyon's avatar Robert Lyon

Bug 1829940: Restrict the chooser to one 'add' button

Done in this patch:
- restricted the list to one shortcut button (the placeholder one)
- cleaned up old code where one could edit the block on the without
modal
- moved the button to be above content layout and next to the
instructions section
- move the block help link to within placeholder block and be an 'i'
on 'Content types' heading

behatnotneeded

Change-Id: I8a85842ffef5e50c62aca73a4b33c22579b160ca
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 882259ee
......@@ -337,14 +337,19 @@ abstract class PluginBlocktype extends Plugin implements IPluginBlocktype {
return $description;
}
public static function get_blocktypes_for_category($category, View $view) {
public static function get_blocktypes_for_category($category, View $view, $blocktype = null) {
$sql = 'SELECT bti.name, bti.artefactplugin
FROM {blocktype_installed} bti
JOIN {blocktype_installed_category} btic ON btic.blocktype = bti.name
JOIN {blocktype_installed_viewtype} btiv ON btiv.blocktype = bti.name
WHERE btic.category = ? AND bti.active = 1 AND btiv.viewtype = ?
ORDER BY btic.sortorder, bti.name';
if (!$bts = get_records_sql_array($sql, array($category, $view->get('type')))) {
WHERE btic.category = ? AND bti.active = 1 AND btiv.viewtype = ?';
$where = array($category, $view->get('type'));
if ($blocktype) {
$sql .= ' AND bti.name = ?';
$where[] = $blocktype;
}
$sql .= ' ORDER BY btic.sortorder, bti.name';
if (!$bts = get_records_sql_array($sql, $where)) {
return false;
}
......
......@@ -47,6 +47,8 @@ class PluginBlocktypePlaceholder extends MaharaCoreBlocktype {
$elements['types'] = array(
'type' => 'fieldset',
'legend' => get_string('contenttypes', 'blocktype.placeholder'),
'help' => true,
'helpcallback' => 'get_block_help',
'elements' => array(
'contenttypes' => array(
'type' => 'html',
......
......@@ -1452,7 +1452,7 @@
/**
* changes the intructions so they are for ajax
*/
$('#blocksinstruction').html(strings['blocksinstructionajaxlive']);
$('#blocksinstruction').html(strings['blocksinstructionajaxlive1']);
$('#viewinstructions-dropdown').on('hide.bs.collapse show.bs.collapse', function(event) {
var pd = {
'viewid': $('#viewid').val(),
......
<!-- @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later -->
<!-- @copyright For copyright information on Mahara, please see the README file distributed with this software. -->
<h3>Edit page</h3>
<p>This area shows a preview of what your page looks like. Changes are saved automatically. Drag blocks onto the page to add them. You can then also drag them around the page to change their position.</p>
<p>This area shows a preview of what your page looks like. Changes are saved automatically. Drag 'Add a new block' onto the page to add one. You can then choose what type of block it will be. You can then also drag blocks around the page to change their position.</p>
<p>Designing your page layout enables you to personalise the way in which your resources and information can be displayed. For example if you wish to display only one of your journal entries, click on the "Journals" tab, then drag the "Journal entry" block into your page area.</p>
<p>As you build up the content in your page, you can check on how it will look by clicking on "Display page". Click the "Edit" button to continue editing.</p>
......@@ -303,7 +303,7 @@ $string['blockinstanceconfiguredsuccessfully'] = 'Block configured successfully'
$string['blockconfigurationrenderingerror'] = 'Configuration failed because the block could not be rendered.';
$string['blocksintructionnoajax'] = 'Select a block and choose where to add it to your page. You can position a block using the arrow buttons in its titlebar.';
$string['blocksinstructionajaxlive'] = 'This area shows a preview of what your page looks like. Changes are saved automatically.<br>Drag blocks onto the page to add them. You can then also drag them around the page to change their position.';
$string['blocksinstructionajaxlive1'] = 'This area shows a preview of what your page looks like. Changes are saved automatically.<br>Drag \'Add a new block\' onto the page to add one. You can then choose what type of block it will be. You can then also drag blocks around the page to change their position.';
$string['blockchangedsuccess'] = "Changed placeholder block to a '%s' block successful";
$string['blockchangederror'] = "Changing block to a '%s' block failed";
$string['blockchangedbacksuccess'] = "Changed block back to placeholder block";
......@@ -320,7 +320,7 @@ $string['nrrows'] = array(
'%s row',
'%s rows',
);
$string['addnewblock'] = 'Add a new block';
$string['addnewblockhere'] = 'Add new block here';
$string['add'] = 'Add';
$string['addcolumn'] = 'Add column';
......
......@@ -88,7 +88,12 @@ function pieform_element_fieldset(Pieform $form, $element) {
// Help icon
if (!empty($element['help'])) {
$function = $form->get_property('helpcallback');
if (!empty($element['helpcallback'])) {
$function = $element['helpcallback'];
}
else {
$function = $form->get_property('helpcallback');
}
if (function_exists($function)) {
$fieldset .= $function($form, $element);
}
......
......@@ -2017,7 +2017,6 @@ class View {
public function build_blocktype_list($category, $javascript=false) {
require_once(get_config('docroot') . 'blocktype/lib.php');
$blocktypes = PluginBlockType::get_blocktypes_for_category($category, $this);
$smarty = smarty_core();
$smarty->assign('blocktypes', $blocktypes);
$smarty->assign('javascript', $javascript);
......
......@@ -1425,7 +1425,7 @@ function jsstrings() {
'views' => array(
'view' => array(
'confirmdeleteblockinstance',
'blocksinstructionajaxlive',
'blocksinstructionajaxlive1',
),
),
);
......@@ -2214,6 +2214,14 @@ function pieform_get_help(Pieform $form, $element) {
return get_help_icon($plugintype, $pluginname, $formname, $element['name'], '', '', (isset($element['title']) ? $element['title'] : null));
}
function get_block_help(Pieform $form, $element) {
$helplink = get_manual_help_link_array(array('blocktype', 'blocks'));
$manualhelplink = $helplink['prefix'] . '/' . $helplink['language'] . '/' . $helplink['version'] . '/' . $helplink['suffix'];
$content = get_string('helpfor', 'mahara', $element['legend']);
return ' <span class="help"><a href="' . $manualhelplink . '" title="' . get_string('Help') . '" target="_blank"><span class="icon icon-info-circle" role="presentation"></span><span class="sr-only">'. $content . '</span></a></span>';
}
/**
* Is this a page in the admin area?
*
......
......@@ -1325,11 +1325,17 @@ EOD;
/**
* generate configdata for the bloctype: peerassessment
* @param array $fields holding each chunk of data between the ; in the behat data column
* @return array redundant info as there is no data directly connected in this case
* @param array $sortedfields holding each chunk of data between the ; in the behat data column
* @return array $configdata of key and values of db table
*/
public static function generate_configdata_peerassessment($fields) {
return array();
public static function generate_configdata_peerassessment($sortedfields) {
$configdata = array();
foreach ($sortedfields as $key => $value) {
if ($key == 'instructions') {
$configdata[$key] = $value;
}
}
return $configdata;
}
/**
......
......@@ -123,7 +123,7 @@ iframe {
}
.view-container {
margin-top: 30px;
margin-top: 15px;
clear: both;
}
......@@ -135,6 +135,9 @@ iframe {
&.with-toolbar {
margin-right: 20px;
}
&.with-addblock {
margin-top: 0px;
}
}
.postlist {
......
{include file="header.tpl"}
{include file="view/editviewtabs.tpl" selected='content' issiteview=$issiteview}
{if $instructions}
<div id="viewinstructions" class="last form-group collapsible-group small-group">
<fieldset class="pieform-fieldset collapsible collapsible-small">
<legend>
<h4>
<a href="#viewinstructions-dropdown" data-toggle="collapse" aria-expanded="false" aria-controls="viewinstructions-dropdown" class="{if $instructionscollapsed}collapsed{/if}">
{str tag='instructions' section='view'}
<span class="icon icon-chevron-down collapse-indicator right text-inline"></span>
</a>
</h4>
</legend>
<div class="fieldset-body collapse viewinstructions {if !$instructionscollapsed} in {/if}" id="viewinstructions-dropdown">
{$instructions|clean_html|safe}
</div>
</fieldset>
</div>
{else}
<div id="blocksinstruction" class="lead view-description">
{str tag='blocksintructionnoajax' section='view'}
</div>
{/if}
<div class="view-instructions">
<form action="{$formurl}" method="post" class="row">
<input type="submit" name="{$action_name}" id="action-dummy" class="d-none">
<input type="hidden" id="viewid" name="id" value="{$view}">
<input type="hidden" name="change" value="1">
<input type="hidden" id="category" name="c" value="{$category}">
<input type="hidden" name="sesskey" value="{$SESSKEY}">
<div class="view-container" selected='content' data-target="col-collapse">
{if $columns}
<form action="{$formurl}" method="post" class="row">
<input type="submit" name="{$action_name}" id="action-dummy" class="d-none">
<input type="hidden" id="viewid" name="id" value="{$view}">
<input type="hidden" name="change" value="1">
<input type="hidden" id="category" name="c" value="{$category}">
<input type="hidden" name="sesskey" value="{$SESSKEY}">
<div id="editcontent-sidebar-wrapper" class="col-collapse">
<div id="editcontent-sidebar" data-spy="affix" data-offset-top="420" data-offset-top="100" class="toolbar-affix">
{include file="view/contenteditor.tpl" selected='content'}
</div>
<div id="editcontent-sidebar-wrapper">
<div id="editcontent-sidebar">
{include file="view/contenteditor.tpl" selected='content'}
</div>
<div class="col-with-collapse">
<div id="bottom-pane" data-role="workspace">
<div id="column-container" class="user-page-content">
{$columns|safe}
</div>
</div>
<div class="col-with-collapse">
{if $instructions}
<div id="viewinstructions" class="last form-group collapsible-group small-group">
<fieldset class="pieform-fieldset collapsible collapsible-small">
<legend>
<h4>
<a href="#viewinstructions-dropdown" data-toggle="collapse" aria-expanded="false" aria-controls="viewinstructions-dropdown" class="{if $instructionscollapsed}collapsed{/if}">
{str tag='instructions' section='view'}
<span class="icon icon-chevron-down collapse-indicator right text-inline"></span>
</a>
</h4>
</legend>
<div class="fieldset-body collapse viewinstructions {if !$instructionscollapsed} in {/if}" id="viewinstructions-dropdown">
{$instructions|clean_html|safe}
</div>
</fieldset>
</div>
</form>
<div id="view-return-controls" class="col-collapse-offset col-with-collapse">
{if !$issitetemplate}
<a class="btn btn-secondary" href="{$displaylink}">
{str tag=displayview section=view}
<span class="icon icon-arrow-circle-right right" role="presentation" aria-hidden="true"></span>
</a>
{/if}
{if !$groupid && !$institution}
<a class="btn btn-secondary" href="{$WWWROOT}view/index.php">
{str tag=returntoviews section=view}
<span class="icon icon-arrow-circle-right right" role="presentation" aria-hidden="true"></span>
</a>
{/if}
{if $groupid}
<a class="btn btn-secondary" href="{$WWWROOT}view/groupviews.php?group={$groupid}">
{str tag=returntogroupportfolios section=group}
<span class="icon icon-arrow-circle-right right" role="presentation" aria-hidden="true"></span>
</a>
{/if}
{if $institution}
{if $institution == 'mahara'}
<a class="btn btn-secondary" href="{$WWWROOT}admin/site/views.php">
{str tag=returntositeportfolios section=view}
{else}
<a class="btn btn-secondary" href="{$WWWROOT}view/institutionviews.php?institution={$institution}">
{str tag=returntoinstitutionportfolios section=view}
{/if}
<span class="icon icon-arrow-circle-right right" role="presentation" aria-hidden="true"></span>
</a>
{/if}
{else}
<div id="blocksinstruction" class="lead view-description with-addblock">
{str tag='blocksintructionnoajax' section='view'}
</div>
{/if}
</div>
</form>
</div>
<div class="view-container" selected='content'>
<form action="{$formurl}" method="post" class="row">
<input type="submit" name="{$action_name}" id="action-dummy" class="d-none">
<input type="hidden" id="viewid" name="id" value="{$view}">
<input type="hidden" name="change" value="1">
<input type="hidden" id="category" name="c" value="{$category}">
<input type="hidden" name="sesskey" value="{$SESSKEY}">
{elseif $block}
<form action="{$formurl}" method="post">
<input type="submit" name="{$action_name}" id="action-dummy" class="d-none">
<input type="hidden" id="viewid" name="id" value="{$view}">
<input type="hidden" name="change" value="1">
<input type="hidden" id="category" name="c" value="{$category}">
<input type="hidden" name="sesskey" value="{$SESSKEY}">
<div id="editcontent-sidebar-wrapper" class="col-collapse">
<div id="editcontent-sidebar">
{include file="view/contenteditor.tpl" selected='content'}
</div>
</div>
<div class="blockconfig-background">
<div class="blockconfig-container">
{$block.html|safe}
<div class="fullwidth">
<div id="bottom-pane" data-role="workspace">
<div id="column-container" class="user-page-content">
{$columns|safe}
</div>
</div>
{if $block.javascript}
<script>
{$block.javascript|safe}
</script>
{/if}
</form>
{/if}
</div>
</form>
<div id="view-return-controls" class="col-collapse-offset col-with-collapse">
{if !$issitetemplate}
<a class="btn btn-secondary" href="{$displaylink}">
{str tag=displayview section=view}
<span class="icon icon-arrow-circle-right right" role="presentation" aria-hidden="true"></span>
</a>
{/if}
{if !$groupid && !$institution}
<a class="btn btn-secondary" href="{$WWWROOT}view/index.php">
{str tag=returntoviews section=view}
<span class="icon icon-arrow-circle-right right" role="presentation" aria-hidden="true"></span>
</a>
{/if}
{if $groupid}
<a class="btn btn-secondary" href="{$WWWROOT}view/groupviews.php?group={$groupid}">
{str tag=returntogroupportfolios section=group}
<span class="icon icon-arrow-circle-right right" role="presentation" aria-hidden="true"></span>
</a>
{/if}
{if $institution}
{if $institution == 'mahara'}
<a class="btn btn-secondary" href="{$WWWROOT}admin/site/views.php">
{str tag=returntositeportfolios section=view}
{else}
<a class="btn btn-secondary" href="{$WWWROOT}view/institutionviews.php?institution={$institution}">
{str tag=returntoinstitutionportfolios section=view}
{/if}
<span class="icon icon-arrow-circle-right right" role="presentation" aria-hidden="true"></span>
</a>
{/if}
</div>
</div>
<div class="modal" id="addblock" role="dialog">
......
......@@ -3,10 +3,6 @@
<div>{str tag=addcontent section=view}</div>
</div>
<div id="content-editor-foldable" class="btn-group-vertical btn-accordion fullwidth">
{if $shortcut_list}
{* Blocks with the category 'shortcut' should always be showing. *}
{$shortcut_list|safe}
{/if}
{$category_list|safe}
{$placeholder_button|safe}
</div>
</div>
......@@ -195,6 +195,19 @@ $addform = pieform(array(
// Build content before initialising smarty in case pieform elements define headers.
$viewcontent = $view->build_rows(true);
// Get the placeholder block info
$placeholderblock = PluginBlockType::get_blocktypes_for_category('shortcut', $view, 'placeholder');
$placeholderbutton = '';
if ($placeholderblock) {
// it's active so make the button with different display title
$placeholderblock[0]['title'] = get_string('addnewblock', 'view');
$placeholderblock[0]['cssicon'] = '_';
$smarty = smarty_core();
$smarty->assign('blocktypes', $placeholderblock);
$smarty->assign('javascript', false);
$placeholderbutton = $smarty->fetch('view/blocktypelist.tpl');
}
$smarty = smarty($javascript, $stylesheets, array(
'view' => array(
'addblock',
......@@ -207,18 +220,11 @@ $smarty = smarty($javascript, $stylesheets, array(
$smarty->assign('addform', $addform);
// The list of categories for the tabbed interface
$smarty->assign('category_list', $view->build_category_list($category, false));
// The list of shortcut blocks
$smarty->assign('shortcut_list', $view->build_blocktype_list('shortcut'));
// The list of blocktypes for the default category
$smarty->assign('blocktype_list', $view->build_blocktype_list($category));
// Tell smarty we're editing rather than just rendering
$smarty->assign('editing', true);
$smarty->assign('placeholder_button', $placeholderbutton);
// Work out what action is being performed. This is used to put a hidden submit
// button right at the very start of the form, so that hitting enter in any
// form fields will cause the correct action to be performed
......@@ -272,16 +278,10 @@ if ($collection = $view->get('collection')) {
}
$smarty->assign('collectionid', $collectionid);
if ($blockid) {
// Configuring a single block
$bi = new BlockInstance($blockid);
$smarty->assign('block', $bi->render_editing(true));
}
else {
// The HTML for the columns in the view
$columns = $viewcontent;
$smarty->assign('columns', $columns);
}
// The HTML for the columns in the view
$columns = $viewcontent;
$smarty->assign('columns', $columns);
$smarty->assign('issiteview', isset($institution) && ($institution == 'mahara'));
$smarty->assign('issitetemplate', $view->is_site_template());
......
......@@ -55,9 +55,10 @@ Scenario: Creating institution tags
And I fill in select2 input "settings_tags" with "One tag" and select "Institution One: One tag (1)"
And I fill in select2 input "settings_tags" with "Test" and select "Test"
And I press "Save"
And I expand "Journals" node in the "blocktype sidebar" property
And I follow "Tagged journal entries"
When I follow "Add a new block" in the "blocktype sidebar" property
And I press "Add"
And I click on "Show more"
And I click on "Tagged journal entries" in the "Content types" property
And I fill in select2 input "instconf_tagselect" with "One tag" and select "Institution One: One tag"
And I press "Save"
Then I should see "Journal entries with tag \"Institution One: One tag\""
......
......@@ -17,8 +17,9 @@ Scenario: Make Text Block Retractable
Given I log in as "UserA" with password "Kupuh1pa!"
And I choose "Pages and collections" in "Create" from main menu
And I click on "Edit" in "Page UserA_01" card menu
And I follow "Text"
When I follow "Add a new block" in the "blocktype sidebar" property
And I press "Add"
And I click on "Text" in the "Content types" property
And I set the field "Block title" to "Text Block 1"
And I set the field "Block content" to "Here is a new block."
Given I select "Yes" from "Retractable"
......
......@@ -14,8 +14,11 @@ Scenario: Accessing annotation block (Bug 1443730)
# Checking if annotation block is available by default
And I follow "Page admin_01"
And I follow "Edit"
And I expand "General" node
And I should not see "Annotation"
When I follow "Add a new block" in the "blocktype sidebar" property
And I press "Add"
And I click on "Show more"
And I click on "Show more"
And I should not see "Annotation" in the "Content types" property
And I display the page
# Navigating to admin block to turn it on
And I choose "Plugin administration" in "Extensions" from administration menu
......@@ -24,9 +27,12 @@ Scenario: Accessing annotation block (Bug 1443730)
# Editing page to add annotation block
And follow "Page admin_01"
And I follow "Edit"
And I expand "General" node
And I follow "Annotation"
When I follow "Add a new block" in the "blocktype sidebar" property
And I press "Add"
And I set the field "Block title" to "Annotation"
And I click on "Show more"
And I click on "Show more"
And I click on "Annotation" in the "Content types" property
And I press "Save"
# Checking empty annotation message
And I should see "This field is required"
......
......@@ -18,15 +18,23 @@ Scenario: Add some externalfeed blocks
Given I log in as "UserA" with password "Kupuh1pa!"
And I choose "Pages and collections" in "Create" from main menu
And I click on "Edit" in "Page UserA_01" card menu
And I expand "External" node
And I follow "External feed"
When I follow "Add a new block" in the "blocktype sidebar" property
And I press "Add"
And I click on "Show more"
And I click on "Show more"
And I click on "Show more"
And I click on "External feed" in the "Content types" property
Then I should see "URL of a valid RSS or ATOM feed"
And I fill in "Feed location" with "http://www.apple.com/main/rss/hotnews/hotnews.rss"
And I press "Save"
Then I should see "provided by Apple."
And I follow "External feed"
When I follow "Add a new block" in the "blocktype sidebar" property
And I press "Add"
And I click on "Show more"
And I click on "Show more"
And I click on "Show more"
And I click on "External feed" in the "Content types" property
And I set the field "Block title" to ""
And I fill in "Feed location" with "http://php.net/feed.atom"
And I fill in "Items to show" with "2"
And I enable the switch "Show feed items in full"
......
......@@ -80,9 +80,11 @@ Scenario: Installing framework module and activating for an institution
# Add another compentency annotation block
And I follow "Edit"
And I expand "General" node
And I follow "Annotation"
When I follow "Add a new block" in the "blocktype sidebar" property
And I press "Add"
And I click on "Show more"
And I click on "Show more"
And I click on "Annotation" in the "Content types" property
And I fill in "My three cents" in editor "Annotation"
And I set the select2 value "1.1 - Sub level of the standard" for "instconf_smartevidence"
And I press "Save"
......
......@@ -17,9 +17,12 @@ Scenario:
Given I log in as "UserA" with password "Kupuh1pa!"
And I choose "Pages and collections" in "Create" from main menu
And I click on "Edit" in "Page UserA_01" card menu
And I expand "General" node
And I follow "Creative Commons license"
When I follow "Add a new block" in the "blocktype sidebar" property
And I press "Add"
And I click on "Show more"
And I click on "Show more"
And I click on "Creative Commons license" in the "Content types" property
And I set the field "Block title" to "Creative Commons license"
# Note that #freecultureseal cannot be tested for as it exists in the page even if not seen
And I enable the switch "Allow commercial uses of your work?"
And I select "Yes, as long as others share alike" from "Allow modifications of your work?"
......
......@@ -26,9 +26,11 @@ Scenario:
And I choose "Pages and collections" in "Create" from main menu
And I follow "Collection UserA_01"
And I follow "Edit"
And I expand "General" node
And I follow "Navigation"
When I follow "Add a new block" in the "blocktype sidebar" property
And I press "Add"
And I click on "Show more"
And I click on "Show more"
And I click on "Navigation" in the "Content types" property
And I select "Collection UserA_02" from "Collection"
And I click on "Set a block title"
And I set the field "Block title" to "Nav for collection B"
......
......@@ -19,10 +19,13 @@ Scenario: Open badges block
Given I log in as "UserA" with password "Kupuh1pa!"
And I choose "Pages and collections" in "Create" from main menu
And I click on "Edit" in "Page UserA_01" card menu
And I expand "External" node
And I scroll to the base of id "content-editor-foldable"
And I follow "Open Badges"
When I follow "Add a new block" in the "blocktype sidebar" property
And I press "Add"
And I click on "Show more"
And I click on "Show more"
And I click on "Show more"
And I click on "Open Badges" in the "Content types" property
And I press "Save"
# Need to add delays as Mahara needs to talk to external site.
# unreliable connection to server produces errors
......
......@@ -63,9 +63,11 @@ Scenario: Create forum and add block to group page
And I log in as "UserC" with password "Kupuh1pa!"
And I choose "Pages and collections" in "Create" from main menu
And I click on "Edit" in "Page UserC_01" card menu
And I expand "General" node
And I follow "Recent forum posts"
When I follow "Add a new block" in the "blocktype sidebar" property
And I press "Add"
And I click on "Show more"
And I click on "Show more"
And I click on "Recent forum posts" in the "Content types" property
# TODO could test other options
And I press "Save"
And I display the page
......
......@@ -64,10 +64,11 @@ Scenario: Add comments block to page
And I click on "Edit" in "Page UserA_01" card menu
And I wait "1" seconds
# Add a comments block so that comments will now be at the top of the page
And I expand "General" node
And I wait "1" seconds
And I follow "Comments" in the "blocktype sidebar" property
When I follow "Add a new block" in the "blocktype sidebar" property
And I press "Add"
And I click on "Show more"
And I click on "Show more"
And I click on "Comments" in the "Content types" property
Then I should see "Comments for this page will be displayed here rather than at the bottom of the page."
And I display the page
Then I should see "Joe Anonymous"
......
......@@ -40,9 +40,13 @@ Scenario: Creating and accessing social media buttons (Bug 1448948)
And I press "Save"
And I choose "Pages and collections" in "Create" from main menu
And I click on "Edit" in "Page UserA_01" card menu
And I expand "Personal info" node