Skip to content

Commit a2f7d09

Browse files
committed
Merge remote-tracking branch 'origin/support/2.13.0' into support/2.14.0
2 parents 0ff9359 + 8c04048 commit a2f7d09

7 files changed

Lines changed: 64 additions & 22 deletions

File tree

ajax/section_update.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@
5050
Session::addMessageAfterRedirect(__('Could not update the section', 'formcreator'), false, ERROR);
5151
exit;
5252
}
53-
echo json_encode(['id' => $section->getID(), 'name' => $section->fields['name']], JSON_UNESCAPED_UNICODE);
53+
echo json_encode(['id' => $section->getID(), 'name' => $section->getDesignLabel()], JSON_UNESCAPED_UNICODE);

inc/abstractitiltarget.class.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,6 +2379,11 @@ public function getDefaultData(PluginFormcreatorFormAnswer $formanswer): array {
23792379
}
23802380

23812381
$data = array_merge($data, $predefined_fields);
2382+
2383+
if (($data['requesttypes_id'] ?? 0) == 0) {
2384+
unset($data['requesttypes_id']);
2385+
}
2386+
23822387
return $data;
23832388
}
23842389

inc/field/filefield.class.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,14 @@ private function saveDocument($file, $prefix) {
224224
return;
225225
}
226226

227-
$doc = new Document();
228-
$file_data = [];
229-
$file_data["name"] = Toolbox::addslashes_deep($form->getField('name') . ' - ' . $this->question->fields['name']);
230-
$file_data["entities_id"] = isset($_SESSION['glpiactive_entity'])
231-
? $_SESSION['glpiactive_entity']
232-
: $form->getField('entities_id');
233-
$file_data["is_recursive"] = $form->getField('is_recursive');
234-
$file_data['_filename'] = [$file];
235-
$file_data['_prefix_filename'] = [$prefix];
227+
$file_data = [
228+
'name' => Toolbox::addslashes_deep($form->fields['name'] . ' - ' . $this->question->fields['name']),
229+
'entities_id' => $_SESSION['glpiactive_entity'] ?? $form->getField('entities_id'),
230+
'is_recursive' => $form->getField('is_recursive'),
231+
'_filename' => [$file],
232+
'_prefix_filename' => [$prefix],
233+
];
234+
$doc = new Document();
236235
if ($docID = $doc->add($file_data)) {
237236
return $docID;
238237
}

inc/section.class.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,4 +538,22 @@ public function getTranslatableStrings(array $options = []) : array {
538538

539539
return $strings;
540540
}
541+
542+
public function getDesignLabel(): string {
543+
$sectionId = $this->getID();
544+
$nb = (new DBUtils())->countElementsInTable(PluginFormcreatorCondition::getTable(), [
545+
'itemtype' => self::getType(),
546+
'items_id' => $sectionId,
547+
]);
548+
$formId = $this->fields[PluginFormcreatorForm::getForeignKeyField()];
549+
$onclick = 'plugin_formcreator.showSectionForm(' . $formId . ', ' . $sectionId . ');';
550+
$html = '<a href="#" onclick=' . $onclick . '" data-field="name">';
551+
$html .= "<sup class='plugin_formcreator_conditions_count' title='" . __('Count of conditions', 'formcreator') ."'>$nb</sup>";
552+
$html .= '<span>';
553+
$html .= empty($this->fields['name']) ? '(' . $sectionId . ')' : $this->fields['name'];
554+
$html .= '</span>';
555+
$html .= '</a>';
556+
557+
return $html;
558+
}
541559
}

js/scripts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ var plugin_formcreator = new function() {
10861086
displayAjaxMessageAfterRedirect();
10871087
}).done(function (data) {
10881088
var section = $('.plugin_formcreator_form_design[data-itemtype="PluginFormcreatorForm"] [data-itemtype="PluginFormcreatorSection"][data-id="' + sectionId + '"]');
1089-
section.find('> a [data-field="name"]').text(data['name']);
1089+
section.find('[data-field="name"]').replaceWith(data['name']);
10901090
that.resetTabs();
10911091
}).complete(function () {
10921092
var myModal = form.closest('div.modal');

templates/components/form/section_design.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232

3333
<li class="plugin_formcreator_section" data-itemtype="PluginFormcreatorSection" data-id="{{ item.fields['id'] }}">
3434
{% set conditionsCount = call('PluginFormcreatorCondition::countForItem', [item]) %}
35-
<a href="#" onclick="plugin_formcreator.showSectionForm({{ item.fields['plugin_formcreator_forms_id'] }}, {{ item.fields['id'] }})">
35+
<a href="#" onclick="plugin_formcreator.showSectionForm({{ item.fields['plugin_formcreator_forms_id'] }}, {{ item.fields['id'] }})" data-field="name">
3636
{# TODO : Show count of conditions #}
3737
<sup class="plugin_formcreator_conditions_count" title="{{ __('Count of conditions', 'formcreator') }}">{{ conditionsCount }}</sup>
3838
{% if item.fields['name'] is empty %}
3939
{% set name = '(' ~ item.fields['id'] ~ ')' %}
4040
{% else %}
4141
{% set name = call('Glpi\\Toolbox\\Sanitizer::unsanitize', [item.fields['name']]) %}
4242
{% endif %}
43-
<span data-field="name">{{ name }}</span>
43+
<span>{{ name }}</span>
4444
</a>
4545

4646
{# Delete a section #}

tests/3-unit/PluginFormcreatorTargetTicket.php

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
use PluginFormcreatorSection;
5050
use Profile;
5151
use Profile_User;
52+
use RequestType;
5253
use Session;
5354
use Supplier_Ticket;
5455
use TaskCategory;
@@ -79,6 +80,19 @@ public function beforeTestMethod($method) {
7980
}
8081
}
8182

83+
public function afterTestMethod($method) {
84+
parent::beforeTestMethod($method);
85+
switch ($method) {
86+
case 'testRequestSource':
87+
$requestType = new RequestType();
88+
$requestType->update([
89+
'id' => 1, // Helpdesk
90+
'is_helpdesk_default' => 1,
91+
]);
92+
break;
93+
}
94+
}
95+
8296
public function providerGetTypeName() {
8397
return [
8498
[
@@ -2038,7 +2052,7 @@ public function providerRequestSource() {
20382052
$testedClassName = $this->getTestedClassName();
20392053

20402054
$form = $this->getForm();
2041-
yield [
2055+
yield 'request source is Formcreator' =>[
20422056
'instance' => $this->getTargetTicket([
20432057
PluginFormcreatorForm::getForeignKeyField() => $form->getID(),
20442058
'source_rule' => $testedClassName::REQUESTSOURCE_FORMCREATOR,
@@ -2047,21 +2061,22 @@ public function providerRequestSource() {
20472061
'expected' => PluginFormcreatorCommon::getFormcreatorRequestTypeId()
20482062
];
20492063

2064+
$email_request_source = 2; // e-mail, see table glpi_requesttypes
20502065
$form = $this->getForm();
20512066
$user = $this->getGlpiCoreItem(User::class, [
20522067
'name' => 'user' . $this->getUniqueString(),
20532068
'password' => 'password',
20542069
'password2' => 'password',
2055-
'default_requesttypes_id' => 2, // e-mail, see table glpi_requesttypes
2070+
'default_requesttypes_id' => $email_request_source,
20562071
]);
20572072
$this->login($user->fields['name'], 'password');
20582073

2059-
yield [
2074+
yield 'request source is none; then set by user\'s preference' => [
20602075
'instance' => $this->getTargetTicket([
20612076
PluginFormcreatorForm::getForeignKeyField() => $form->getID(),
20622077
'source_rule' => $testedClassName::REQUESTSOURCE_NONE
20632078
]),
2064-
'expected' => 2
2079+
'expected' => $email_request_source,
20652080
];
20662081

20672082
$form = $this->getForm();
@@ -2072,13 +2087,18 @@ public function providerRequestSource() {
20722087
'default_requesttypes_id' => 0, // unset
20732088
]);
20742089
$this->login($user->fields['name'], 'password');
2090+
$requestType = new RequestType();
2091+
$requestType->update([
2092+
'id' => 3, // Phone
2093+
'is_helpdesk_default' => 1,
2094+
]);
20752095

2076-
yield [
2096+
yield 'request source is none; then set by GLPI default' => [
20772097
'instance' => $this->getTargetTicket([
20782098
PluginFormcreatorForm::getForeignKeyField() => $form->getID(),
20792099
'source_rule' => $testedClassName::REQUESTSOURCE_NONE,
20802100
]),
2081-
'expected' => 0 // Unset (see Setup > General > Default values)
2101+
'expected' => 3 // Unset (see Setup > General > Default values)
20822102
];
20832103

20842104
$form = $this->getForm();
@@ -2090,16 +2110,16 @@ public function providerRequestSource() {
20902110
$this->getGlpiCoreItem(TicketTemplatePredefinedField::getType(), [
20912111
'tickettemplates_id' => $ticketTemplate->getID(),
20922112
'num' => 9, // RequestType
2093-
'value' => 1, // Helpdesk
2113+
'value' => 4, // Direct
20942114
]);
20952115

2096-
yield [
2116+
yield 'request source is none; then set by target\'s template' => [
20972117
'instance' => $this->getTargetTicket([
20982118
PluginFormcreatorForm::getForeignKeyField() => $form->getID(),
20992119
'source_rule' => $testedClassName::REQUESTSOURCE_NONE,
21002120
'tickettemplates_id' => $ticketTemplate->getID(),
21012121
]),
2102-
'expected' => 1 // Helpdesk (see Setup > General > Default values)
2122+
'expected' => 4 // Helpdesk (see Setup > General > Default values)
21032123
];
21042124
}
21052125

0 commit comments

Comments
 (0)