PHRAS-1766 Add orderable checkbox for each subdef - Remove order option on groups

This commit is contained in:
Xavier Rousset
2017-12-18 18:02:48 +01:00
parent 3a6f2eb365
commit c7f6b325d8
3 changed files with 11 additions and 70 deletions

View File

@@ -149,12 +149,11 @@ class SubdefsController extends Controller
break; break;
} }
$subdefs->set_subdef($group, $name, $class, false, $options, [], $preset); $subdefs->set_subdef($group, $name, $class, false, $options, [], true, $preset);
} }
} else { } else {
$subdefs = $databox->get_subdef_structure(); $subdefs = $databox->get_subdef_structure();
$this->updateSubdefGroups($subdefs, $request);
foreach ($Parmsubdefs as $post_sub) { foreach ($Parmsubdefs as $post_sub) {
$options = []; $options = [];
@@ -193,7 +192,7 @@ class SubdefsController extends Controller
} }
$labels = $request->request->get($post_sub . '_label', []); $labels = $request->request->get($post_sub . '_label', []);
$subdefs->set_subdef($group, $name, $class, $downloadable, $options, $labels, $preset, $orderable); $subdefs->set_subdef($group, $name, $class, $downloadable, $options, $labels, $orderable, $preset);
} }
} }
@@ -218,35 +217,6 @@ class SubdefsController extends Controller
return $mapping; return $mapping;
} }
/**
* Update Databox subdefsStructure DOM according to defined groups.
*
* @param \databox_subdefsStructure $subdefs
* @param Request $request
*/
protected function updateSubdefGroups(\databox_subdefsStructure $subdefs, Request $request)
{
$subdefsGroups = $request->request->get('subdefsgroups', []);
$changedGroups = [];
/** @var SubdefGroup $subdefsGroup */
foreach ($subdefs as $groupName => $subdefsGroup) {
$documentOrderable = isset($subdefsGroups[$groupName]['document_orderable'])
? \p4field::isyes($subdefsGroups[$groupName]['document_orderable'])
: false;
if ($subdefsGroup->isDocumentOrderable() !== $documentOrderable) {
if ($documentOrderable) {
$subdefsGroup->allowDocumentOrdering();
} else {
$subdefsGroup->disallowDocumentOrdering();
}
$changedGroups[] = $subdefsGroup;
}
}
if ($changedGroups) {
$subdefs->updateSubdefGroups($changedGroups);
}
}
/** /**
* @return array * @return array
*/ */

View File

@@ -220,36 +220,19 @@ class databox_subdefsStructure implements IteratorAggregate, Countable
return $this; return $this;
} }
/**
* @param SubdefGroup[] $groups
*/
public function updateSubdefGroups($groups)
{
Assertion::allIsInstanceOf($groups, SubdefGroup::class);
$dom_xp = $this->databox->get_xpath_structure();
foreach ($groups as $group) {
$nodes = $dom_xp->query('//record/subdefs/subdefgroup[@name="' . $group->getName() . '"]');
/** @var DOMElement $node */
foreach ($nodes as $node) {
$node->setAttribute('document_orderable', ($group->isDocumentOrderable() ? 'true' : 'false'));
}
}
}
/** /**
* @param string $group * @param string $group
* @param string $name * @param string $name
* @param string $class * @param string $class
* @param string $preset
* @param boolean $downloadable * @param boolean $downloadable
* @param array $options * @param array $options
* @param array $labels * @param array $labels
* @param boolean $orderable
* @param string $preset
* @return databox_subdefsStructure * @return databox_subdefsStructure
* @throws Exception * @throws Exception
*/ */
public function set_subdef($group, $name, $class, $downloadable, $options, $labels, $preset = "Custom") public function set_subdef($group, $name, $class, $downloadable, $options, $labels, $orderable = true, $preset = "Custom")
{ {
$dom_struct = $this->databox->get_dom_structure(); $dom_struct = $this->databox->get_dom_structure();
@@ -257,6 +240,7 @@ class databox_subdefsStructure implements IteratorAggregate, Countable
$subdef->setAttribute('class', $class); $subdef->setAttribute('class', $class);
$subdef->setAttribute('name', mb_strtolower($name)); $subdef->setAttribute('name', mb_strtolower($name));
$subdef->setAttribute('downloadable', ($downloadable ? 'true' : 'false')); $subdef->setAttribute('downloadable', ($downloadable ? 'true' : 'false'));
$subdef->setAttribute('orderable', ($orderable ? 'true' : 'false'));
$subdef->setAttribute('presets', $preset); $subdef->setAttribute('presets', $preset);
foreach ($labels as $code => $label) { foreach ($labels as $code => $label) {

View File

@@ -373,24 +373,6 @@
<button type="submit" disabled="disabled" class="btn btn-primary subviews-submit">{{ 'boutton::valider' | trans }}</button> <button type="submit" disabled="disabled" class="btn btn-primary subviews-submit">{{ 'boutton::valider' | trans }}</button>
{% for subdefgroup, subdeflist in subdefs %} {% for subdefgroup, subdeflist in subdefs %}
<div id="{{subdefgroup}}"> <div id="{{subdefgroup}}">
<div>
<table cellspacing="0" cellpadding="0" border="0" style="width:500px;">
<tbody>
<tr>
<td style="width:120px;">
<h2>{{ 'subdef.document' | trans }}</h2>
</td>
<td style="width:250px;"></td>
<td></td>
</tr>
<tr>
<td>{{ 'subdef.orderable' | trans }}</td>
<td><input type="checkbox" name="subdefsgroups[{{ subdefgroup }}][document_orderable]" {% if subdeflist.isDocumentOrderable() %}checked="checked" {% endif %}value="1"/></td>
<td></td>
</tr>
</tbody>
</table>
</div>
{% for subdefname , subdef in subdeflist %} {% for subdefname , subdef in subdeflist %}
<div> <div>
<input type="hidden" name="subdefs[]" value="{{subdefgroup}}_{{subdefname}}"/> <input type="hidden" name="subdefs[]" value="{{subdefgroup}}_{{subdefname}}"/>
@@ -403,6 +385,11 @@
<td style="width:100px;line-height: 0.9rem;">{{ 'Telechargeable' | trans }}</td> <td style="width:100px;line-height: 0.9rem;">{{ 'Telechargeable' | trans }}</td>
<td style="width:300px;"><input type="checkbox" name="{{subdefgroup}}_{{subdefname}}_downloadable" {% if subdef.isDownloadable() %}checked="checked"{% endif %} value="1" /></td> <td style="width:300px;"><input type="checkbox" name="{{subdefgroup}}_{{subdefname}}_downloadable" {% if subdef.isDownloadable() %}checked="checked"{% endif %} value="1" /></td>
<td></td> <td></td>
</tr>
<tr>
<td>{{ 'subdef.orderable' | trans }}</td>
<td><input type="checkbox" name="{{subdefgroup}}_{{subdefname}}_orderable" {% if subdef.isOrderable() %}checked="checked"{% endif %} value="1" /></td>
<td></td>
</tr> </tr>
<tr> <tr>
<td> <td>