Skip to content

Commit

Permalink
Updated to user forms 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Mellisa Hankins committed Oct 5, 2015
1 parent b137695 commit de40bc5
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 54 deletions.
2 changes: 1 addition & 1 deletion js/mwm.zen-forms.js

Large diffs are not rendered by default.

40 changes: 1 addition & 39 deletions src/FormBootstrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,6 @@ class FormBootstrapper extends AbstractFormDecorator
'RequestHandler',
];

public $template = 'Form_bootstrapped';

public static function reset_template_for(Decorator $item, $templateName)
{
$originalTemplates = $item->up()->getTemplate();
$originalItemClass = get_class($item->original());

if (is_array($originalTemplates)) {
$template = array_pop($originalTemplates);
} else {
$template = $originalTemplates;
$originalTemplates = [];
}

$templates = [];

if ($template && !in_array($template, [$originalItemClass, 'Form'])) {
$templates[] = $template;
}

if (is_string($templateName)) {
$templates[] = $templateName;
} else {
$templates = array_merge($templates, $templateName);
}

$templates = array_merge($templates, $originalTemplates);

$parentClass = $originalItemClass;

while ($parentClass && !in_array($parentClass, static::$disallowed_template_classes)) {
$templates[] = $parentClass;
$parentClass = get_parent_class($parentClass);
}

return array_filter(array_unique($templates));
}

public static function get_attributes_from_tag($tag)
{
$attributes = [];
Expand Down Expand Up @@ -97,7 +59,7 @@ public static function requirements()

public function getTemplate()
{
return static::reset_template_for($this, $this->template);
return $this->suffixTemplates(array_merge((array)$this->up()->getTemplate(), ['Form']));
}

public function ajaxify()
Expand Down
14 changes: 1 addition & 13 deletions src/FormFieldBootstrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

class FormFieldBootstrapper extends AbstractFormFieldDecorator
{
public $templateSuffix = '_bootstrapped';

protected $holderAttributes = [];
protected $holderClasses = [
'form-group',
Expand Down Expand Up @@ -64,6 +62,7 @@ public function addExtraClassesAndAttributes()

if ($this->isButton($field)) {
$this->addExtraClass('btn');
$this->UseButtonTag = true;

if (!$this->getAttribute('data-loading-text')) {
$this->setAttribute('data-loading-text', _t('LOADING...', 'Loading...'));
Expand Down Expand Up @@ -238,17 +237,6 @@ public function OptionAttributesHTML()
['disabled', 'checked', 'selected', 'value', 'type', 'name', 'id', 'class']);
}

protected function suffixTemplates(array $templates)
{
$new = [];

foreach ($templates as $template) {
$new[] = str_replace('\\', '_', $template) . $this->templateSuffix;
}

return array_unique(array_merge($new, $templates));
}

public function collateDataFields(&$list, $saveableOnly = false)
{
return $this->original()->collateDataFields($list, $saveableOnly);
Expand Down
1 change: 0 additions & 1 deletion src/Model/AbstractFormDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function forTemplate()
['Form']
));


// Now that we're rendered, clear message
$this->clearMessage();

Expand Down
13 changes: 13 additions & 0 deletions src/Traits/ViewableDataDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use ViewableData;

trait ViewableDataDecorator {
public $templateSuffix = '_bootstrapped';

public function obj($fieldName, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null) {
$value = parent::obj($fieldName, $arguments, $forceReturnedObject, $cache, $cacheName);

Expand All @@ -36,4 +38,15 @@ public function __call($method, $arguments) {

return $return;
}

protected function suffixTemplates(array $templates)
{
$new = [];

foreach ($templates as $template) {
$new[] = str_replace('\\', '_', $template) . $this->templateSuffix;
}

return array_unique(array_merge($new, $templates));
}
}
39 changes: 39 additions & 0 deletions templates/UserForm_bootstrapped.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<% if $IncludeFormTag %>
<form $AttributesHTML>
<% end_if %>

<% include UserFormProgress %>
<% include UserFormStepErrors %>

<% include FormMessage_bootstrapped %>

<fieldset>
<% if $Legend %><legend>$Legend</legend><% end_if %>
<% loop $Fields %>
$FieldHolder
<% end_loop %>
</fieldset>

<% include UserFormStepNav %>

<% if $IncludeFormTag %>

<div id="<% if $FormModalID %>$FormModalID<% else %>{$FormName}-Modal<% end_if %>" class="<% if $FormModalClasses %>$FormModalClasses<% else %>modal fade<% end_if %>" data-modal="modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 id="{$FormModal}-Title" role="title"><% if $FormModalTitle %>$FormModalTitle<% else %>&nbsp;<% end_if %></h4>
</div>
<div class="modal-body" id="{$FormModal}-Content" role="content">
<p>$OnCompleteMessage</p>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-link" data-dismiss="modal">Close</a>
</div>
</div>
</div>
</div>

</form>
<% end_if %>
5 changes: 5 additions & 0 deletions templates/UserFormsDropdownField_bootstrapped.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<select $AttributesHTML <% if $RightTitle %>aria-describedby="{$Name}_right_title"<% end_if %>>
<% loop $Options %>
<option value="$Value.XML"<% if $Selected %> selected="selected"<% end_if %><% if $Disabled %> disabled="disabled"<% end_if %>>$Title.XML</option>
<% end_loop %>
</select>
1 change: 1 addition & 0 deletions templates/UserFormsField_bootstrapped.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input $AttributesHTML<% if $RightTitle %>aria-describedby="{$Name}_right_title" <% end_if %>/>
1 change: 1 addition & 0 deletions templates/UserFormsField_holder_bootstrapped.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<% include FormField_holder_bootstrapped %>
1 change: 1 addition & 0 deletions templates/UserFormsTextareaField_bootstrapped.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<textarea $AttributesHTML<% if $RightTitle %>aria-describedby="{$Name}_right_title" <% end_if %>>$Value</textarea>
2 changes: 2 additions & 0 deletions templates/UserformsCheckboxField_bootstrapped.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<input $AttributesHTML<% if $RightTitle %>aria-describedby="{$Name}_right_title" <% end_if %>/>
<% if $Title %><label class="left" for="$ID">$Title</label><% end_if %>
7 changes: 7 additions & 0 deletions templates/UserformsCheckboxField_holder_bootstrapped.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div id="$Name" class="field<% if $extraClass %> $extraClass<% end_if %>">
<div class="middleColumn">
$Field
</div>
<% if $RightTitle %><span id="{$Name}_right_title" class="right-title">$RightTitle</span><% end_if %>
<% if $Message %><span class="message $MessageType">$Message</span><% end_if %>
</div>

0 comments on commit de40bc5

Please sign in to comment.