Skip to content

Commit

Permalink
Merge pull request #213 from deanblackborough/preset-tools
Browse files Browse the repository at this point in the history
Preset tools
  • Loading branch information
deanblackborough authored Feb 10, 2017
2 parents 124f45d + 8530061 commit 4a1500e
Show file tree
Hide file tree
Showing 27 changed files with 866 additions and 32 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ Changelog

Full changelog for Dlayer since the v1.00 release.

v1.11: In progress
v1.11: 10th February 2017
--------
- Added layout tools to the Form Builder, forms can now use stacked, inline or horizontal layouts. [Feature]
- I have moved the code for the delete element sub tool into the shared section for Form Builder tools.
- Added the delete sub tool to the Password, Email and Textarea elements. [Feature]
- Added titles tool to the Form Builder, the title and subtitle can now be set. [Feature]
- Added button tool to the Form Builder, allows the labels for the submit and reset buttons to be defined. [Feature]
- Added controls to preview form at full width, three quarter width, half width and quarter width. [Feature]
- Added controls to preview form at full width, three-quarter width, half width and quarter width. [Feature]
- Added four preset element tools to Form Builder, name, email, comment and address. They are standard elements with the values prefilled to assist with creating a new form. [Feature]
- Additional tests added to the test suite. [Tests]
- Minor fixes and improvements.

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg)](https://php.net/)
[![Build Status](https://travis-ci.org/Dlayer/dlayer.svg?branch=master)](https://travis-ci.org/Dlayer/dlayer)

![Dlayer_Logo](public/images/favicon-192x192.png)

Dlayer
======

Expand All @@ -11,7 +13,7 @@ Over the next few weeks, I am going to continue to polish the core of the Conten

Latest stable release
--------
v1.09 - Released 30th January 2017
v1.11 - Released 10th February 2017

Overview
--------
Expand Down
2 changes: 1 addition & 1 deletion application/configs/environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
// Version number for current release
$version_no = 'v1.11';
// Release date for current release
$version_release_date = 'In progress';
$version_release_date = '10th February 2017';
11 changes: 3 additions & 8 deletions application/modules/dlayer/views/scripts/index/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@
</div>

<div class="col-md-6 col-sm-6 col-xs-12">
<h3><span class="label label-success">v1.11</span> Form Builder part 5 <small class="text-muted">(In progress)</small></h3>
<h3><span class="label label-success">v1.11</span> Form Builder part 5 <small class="text-muted">(10th February 2017)</small></h3>

<ul>
<li>Added layout tools to the Form Builder, forms can now use stacked, inline or horizontal layouts. [Feature]</li>
<li>I have moved the code for the delete element sub tool into the shared section for Form Builder tools.</li>
<li>Added the delete sub tool to the Password, Email and Textarea elements. [Feature]</li>
<li>Added titles tool to the Form Builder, the title and subtitle can now be set. [Feature]</li>
<li>Added button tool to the Form Builder, allows the labels for the submit and reset buttons to be defined. [Feature]</li>
<li>Added controls to preview form at full width, three quarter width, half width and quarter width. [Feature]</li>
<li>Added controls to preview form at full width, three-quarter width, half width and quarter width. [Feature]</li>
<li>Added four preset element tools to Form Builder, name, email, comment and address. They are standard elements with the values prefilled to assist with creating a new form. [Feature]</li>
<li>Additional tests added to the test suite. [Tests]</li>
<li>Minor fixes and improvements.</li>
</ul>
Expand All @@ -50,12 +51,6 @@

<h3><span class="label label-default">v1.08</span> Form Builder part 2 <small class="text-muted">(26th January 2017)</small></h3>

<h3><span class="label label-default">v1.07</span> Form Builder part 1 <small class="text-muted">(25th January 2017)</small></h3>

<h3><span class="label label-default">v1.06</span> Responsive columns <small class="text-muted">(23rd January 2017)</small></h3>

<h3><span class="label label-default">v1.05</span> Database setup <small class="text-muted">(17th January 2017)</small></h3>

<p>The full <a href="http://www.dlayer.com/releases.html">release history</a> is available at Dlayer.com and
on <a href="https://github.com/Dlayer/dlayer/releases">GitHub</a>.</p>
</div>
Expand Down
5 changes: 5 additions & 0 deletions application/modules/form/controllers/DesignController.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ private function controlBarTools($field_id)
$group = 'standard';
break;

case 3:
$show = true;
$group = 'preset';
break;

default:
$show = false; // Don't include cancel tool
$group = null;
Expand Down
12 changes: 7 additions & 5 deletions application/modules/form/controllers/ProcessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ private function validateRequest($session, $session_designer)
$session->fieldId() === null
) &&
$session_designer->tool('form') !== false &&
$session_designer->tool('form')['tool'] === Dlayer_Helper::getParamAsString('tool')
(
$session_designer->tool('form')['tool'] === Dlayer_Helper::getParamAsString('tool') ||
Dlayer_Helper::getParamAsInteger('preset') === 1
)
) {
return true;
} else {
Expand All @@ -75,6 +78,7 @@ private function validateRequest($session, $session_designer)
Dlayer_Helper::getParamAsInteger('field_id'));
Dlayer_Helper::sendToErrorLog('- Session tool: ' . $session_designer->tool('form')['tool'] .
' POSTed tool: ' . Dlayer_Helper::getParamAsString('tool'));
Dlayer_Helper::sendToErrorLog('- Preset: ' . Dlayer_Helper::getParamAsInteger('preset'));

return false;
}
Expand Down Expand Up @@ -116,13 +120,11 @@ private function validateAutoRequest($session, $session_designer)
*/
private function toolClass($sub_tool_model = null)
{
$session_designer = new Dlayer_Session_Designer();

if ($sub_tool_model !== null) {
$class_name = 'Dlayer_DesignerTool_FormBuilder_' . $session_designer->tool('form')['tool'] .
$class_name = 'Dlayer_DesignerTool_FormBuilder_' . Dlayer_Helper::getParamAsString('tool') .
'_SubTool_' . $sub_tool_model . '_Tool';
} else {
$class_name = 'Dlayer_DesignerTool_FormBuilder_' . $session_designer->tool('form')['tool'] .
$class_name = 'Dlayer_DesignerTool_FormBuilder_' . Dlayer_Helper::getParamAsString('tool') .
'_Tool';
}

Expand Down
2 changes: 1 addition & 1 deletion application/views/layouts/form-builder.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</ul>
</div>
<?php } ?>
<?php $labels = array('layout' => 'Layout', 'standard' => 'Standard Elements', 'preset' => 'Preset fields'); ?>
<?php $labels = array('layout' => 'Layout', 'standard' => 'Standard Elements', 'preset' => 'Preset elements'); ?>
<?php foreach(array('layout', 'preset', 'standard') as $group) { ?>
<?php if (count($this->layout()->control_bar_tools[$group]) > 0) { ?>
<div class="btn-group dropup">
Expand Down
100 changes: 100 additions & 0 deletions library/Dlayer/DesignerTool/FormBuilder/PresetAddress/Form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

/**
* Form for the preset address tool
*
* @author Dean Blackborough
* @copyright G3D Development Limited
* @license https://github.com/Dlayer/dlayer/blob/master/LICENSE
*/
class Dlayer_DesignerTool_FormBuilder_PresetAddress_Form extends Dlayer_Form_Tool_Form
{
/**
* Set the properties for the form
*
* @param array $tool Tool and environment data array
* @param array $data Current data for content item
* @param array $element_data
* @param array|NULL $options Zend form options
*/
public function __construct(array $tool, array $data, array $element_data, $options=NULL)
{
$tool['name'] = 'Textarea'; // Override the tool
$this->field_type = 'Textarea';
$this->preset = 1;

parent::__construct($tool, $data, $element_data, $options);
}

/**
* Initialise the form, sets the action and method and then calls the elements to build the form
*
* @return void
*/
public function init()
{
$this->setAction('/form/process/tool');

$this->setMethod('post');

$this->generateFormElements();

$this->addElementsToForm('address', 'Address element', $this->elements);

$this->addDefaultElementDecorators();

$this->addCustomElementDecorators();
}

protected function generateUserElements()
{
$label = new Zend_Form_Element_Hidden('label');
$label->setBelongsTo('params');
$label->setDescription('Click <mark>save</mark> to quickly add an address element to your form, all
the options and values have been preset for you, if necessary, you can alter them by editing the element.');
if (array_key_exists('label', $this->data) && $this->data['label'] !== false) {
$label->setValue($this->data['label']);
}

$this->elements['label'] = $label;

$description = new Zend_Form_Element_Hidden('description');
$description->setBelongsTo('params');
if (array_key_exists('description', $this->data) && $this->data['description'] !== false) {
$description->setValue($this->data['description']);
}

$this->elements['description'] = $description;

$placeHolder = new Zend_Form_Element_Hidden('placeholder');
$placeHolder->setBelongsTo('params');
if (array_key_exists('placeholder', $this->data) && $this->data['placeholder'] !== false) {
$placeHolder->setValue($this->data['placeholder']);
}

$this->elements['placeholder'] = $placeHolder;

$rows = new Zend_Form_Element_Hidden('rows');
$rows->setBelongsTo('params');
if (array_key_exists('rows', $this->data) && $this->data['rows'] !== false) {
$rows->setValue($this->data['rows']);
}

$this->elements['rows'] = $rows;

$cols = new Zend_Form_Element_Hidden('cols');
$cols->setBelongsTo('params');
if (array_key_exists('cols', $this->data) && $this->data['cols'] !== false) {
$cols->setValue($this->data['cols']);
}

$this->elements['cols'] = $cols;
}

protected function addCustomElementDecorators()
{
parent::addCustomElementDecorators();

$this->elements['label']->getDecorator('Description')->setOption('escape', false);
}
}
53 changes: 53 additions & 0 deletions library/Dlayer/DesignerTool/FormBuilder/PresetAddress/Ribbon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* Preset address element tool ribbon class
*
* @author Dean Blackborough <[email protected]>
* @copyright G3D Development Limited
* @license https://github.com/Dlayer/dlayer/blob/master/LICENSE
*/
class Dlayer_DesignerTool_FormBuilder_PresetAddress_Ribbon extends Dlayer_Ribbon_Form
{
/**
* Fetch the view data for the tool tab, contains an index with the form (pre filled if necessary) and another
* with the data required by the live preview functions
*
* @param array $tool Tool and environment data array
* @return array Data array for view
*/
public function viewData(array $tool)
{
$this->tool = $tool;

$this->fieldData();

return array(
'form' => new Dlayer_DesignerTool_FormBuilder_PresetAddress_Form(
$tool,
$this->field_data,
array()
)
);
}

/**
* Fetch any existing field data, always return an array, values are false if noting exists
*
* @return void
*/
protected function fieldData()
{
if ($this->field_data_fetched === false) {
$this->field_data = array(
'label' => 'Your address',
'description' => 'Please enter your address',
'placeholder' => 'e.g., 1, The Street, The Town, AA1 BB2',
'rows' => 4,
'cols' => 40
);

$this->field_data_fetched = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php /** @var $this Dlayer_View_Codehinting */?>

<div class="col-md-12 col-sm-12">
<h3>Help <small>TODO</small></h3>

<p>@TODO - Add help page content.</p>
</div>

<div class="col-md-12 col-sm-12 further-reading">
<?php echo $this->furtherReading(null, true); ?>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php /** @var $this Dlayer_View_Codehinting */?>

<div class="col-md-12 col-sm-12">
<?php
if($this->data !== false) {
echo $this->data['form'];
}
?>
</div>
Loading

0 comments on commit 4a1500e

Please sign in to comment.