Skip to content

Commit 53a4285

Browse files
committed
feat(formaccesstype): massive action
1 parent 11c86b7 commit 53a4285

File tree

4 files changed

+91
-23
lines changed

4 files changed

+91
-23
lines changed

hook.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,12 @@ function plugin_formcreator_MassiveActions($itemtype) {
375375
switch ($itemtype) {
376376
case PluginFormcreatorForm::class:
377377
return [
378-
'PluginFormcreatorForm' . MassiveAction::CLASS_ACTION_SEPARATOR . 'Duplicate' => _x('button', 'Duplicate'),
379-
'PluginFormcreatorForm' . MassiveAction::CLASS_ACTION_SEPARATOR . 'Transfert' => __('Transfer'),
380-
'PluginFormcreatorForm' . MassiveAction::CLASS_ACTION_SEPARATOR . 'Export' => _sx('button', 'Export'),
378+
PluginFormcreatorForm::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'Duplicate' => _x('button', 'Duplicate'),
379+
PluginFormcreatorForm::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'Transfert' => __('Transfer'),
380+
PluginFormcreatorForm::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'Export' => _sx('button', 'Export'),
381+
PluginFormcreatorForm::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'AccessRights' => _sx('button', 'Access rights'),
381382
];
382-
}
383+
}
383384
return [];
384385
}
385386

@@ -803,4 +804,4 @@ function plugin_formcreator_transfer(array $options) {
803804
'tickets_id' => $options['newID'],
804805
]);
805806
}
806-
}
807+
}

inc/form.class.php

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public function rawSearchOptions() {
220220
'0' => 'equals',
221221
'1' => 'notequals'
222222
],
223-
'massiveaction' => true
223+
'massiveaction' => false
224224
];
225225

226226
$tab[] = [
@@ -1195,16 +1195,16 @@ public function prepareInputForUpdate($input) {
11951195
return false;
11961196
}
11971197

1198-
if (!$this->checkConditionSettings($input)) {
1199-
$input['show_rule'] = PluginFormcreatorCondition::SHOW_RULE_ALWAYS;
1200-
}
1198+
// if (!$this->checkConditionSettings($input)) {
1199+
// $input['show_rule'] = PluginFormcreatorCondition::SHOW_RULE_ALWAYS;
1200+
// }
12011201

1202-
if (!$this->checkValidators($input)) {
1203-
$input['validation_required'] = self::VALIDATION_NONE;
1204-
}
1202+
// if (!$this->checkValidators($input)) {
1203+
// $input['validation_required'] = self::VALIDATION_NONE;
1204+
// }
12051205
}
12061206

1207-
return $input;
1207+
// return $input;
12081208
}
12091209

12101210
// Control fields values :
@@ -1239,6 +1239,13 @@ public function prepareInputForUpdate($input) {
12391239
}
12401240
}
12411241

1242+
if (isset($input['restrictions'])) {
1243+
$input['users'] = AbstractRightsDropdown::getPostedIds($input['restrictions'], User::class);
1244+
$input['groups'] = AbstractRightsDropdown::getPostedIds($input['restrictions'], Group::class);
1245+
$input['profiles'] = AbstractRightsDropdown::getPostedIds($input['restrictions'], Profile::class);
1246+
unset($input['restrictions']);
1247+
}
1248+
12421249
return $input;
12431250
}
12441251

@@ -1458,6 +1465,35 @@ public static function showMassiveActionsSubForm(MassiveAction $ma) {
14581465
]);
14591466
echo '<br /><br />' . Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']);
14601467
return true;
1468+
1469+
case 'AccessRights':
1470+
echo '<p></p>';
1471+
Dropdown::showFromArray(
1472+
'access_rights',
1473+
PluginFormcreatorForm::getEnumAccessType(),
1474+
[
1475+
'value' => PluginFormcreatorForm::ACCESS_PRIVATE,
1476+
'on_change' => 'plugin_formcreator.showMassiveRestrictions(this)',
1477+
]
1478+
);
1479+
echo '<p></p>';
1480+
echo '<div id="plugin_formcreator_restrictions_head" style="display: none">';
1481+
echo PluginFormcreatorFormAccessType::getTypeName(2);
1482+
echo '</div>';
1483+
echo '<div id="plugin_formcreator_restrictions" style="display: none">';
1484+
echo PluginFormcreatorRestrictedFormDropdown::show('restrictions', [
1485+
'users_id' => [],
1486+
'groups_id' => [],
1487+
'profiles_id' => [],
1488+
]);
1489+
echo '</div>';
1490+
echo '<div id="plugin_formcreator_captcha" style="display: none">';
1491+
echo __('Enable captcha', 'formcreator') . '&nbsp;';
1492+
Dropdown::showYesNo('is_captcha_enabled');
1493+
echo '</div>';
1494+
echo '<br /><br />' . Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']);
1495+
return true;
1496+
14611497
}
14621498
return parent::showMassiveActionsSubForm($ma);
14631499
}
@@ -1511,6 +1547,18 @@ public static function processMassiveActionsForOneItemtype(MassiveAction $ma, Co
15111547
Html::redirect(FORMCREATOR_ROOTDOC."/front/export.php?".Toolbox::append_params($listOfId));
15121548
header("Content-disposition:attachment filename=\"test\"");
15131549
return;
1550+
1551+
case 'AccessRights':
1552+
foreach ($ids as $id) {
1553+
if ($item->getFromDB($id) && $item->update($ma->POST + ['id' => $id])) {
1554+
Session::addMessageAfterRedirect(sprintf(__('Form updated: %s', 'formcreator'), $item->getName()));
1555+
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
1556+
} else {
1557+
// Example of ko count
1558+
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
1559+
}
1560+
}
1561+
return;
15141562
}
15151563
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
15161564
}

inc/formaccesstype.class.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public static function showForForm(CommonDBTM $item, $withtemplate = '') {
7171
'access_rights',
7272
PluginFormcreatorForm::getEnumAccessType(),
7373
[
74-
'value' => (isset($item->fields['access_rights'])) ? $item->fields['access_rights'] : '1',
74+
'value' => $item->fields['access_rights'] ?? PluginFormcreatorForm::ACCESS_PRIVATE,
75+
'on_change' => 'plugin_formcreator.showMassiveRestrictions(this)',
7576
]
7677
);
7778
echo '</td>';
@@ -94,26 +95,32 @@ public static function showForForm(CommonDBTM $item, $withtemplate = '') {
9495
echo '</tr>';
9596

9697
// Captcha
97-
if ($item->fields["access_rights"] == PluginFormcreatorForm::ACCESS_PUBLIC) {
98-
echo '<tr>';
98+
$is_visible = $item->fields["access_rights"] == PluginFormcreatorForm::ACCESS_PUBLIC;
99+
// if ($item->fields["access_rights"] == PluginFormcreatorForm::ACCESS_PUBLIC) {
100+
echo '<tr id="plugin_formcreator_captcha" style="display: ' . ($is_visible ? 'block' : 'none') . '">';
99101
echo '<td>' . __('Enable captcha', 'formcreator') . '</td>';
100102
echo '<td>';
101103
Dropdown::showYesNo('is_captcha_enabled', $item->fields['is_captcha_enabled']);
102104
echo '</td>';
103105
echo '</tr>';
104-
}
106+
// }
105107

106-
if ($item->fields["access_rights"] == PluginFormcreatorForm::ACCESS_RESTRICTED) {
107-
echo '<tr><th colspan="2">'.self::getTypeName(2).'</th></tr>';
108-
echo '<tr>';
108+
$is_visible = $item->fields["access_rights"] == PluginFormcreatorForm::ACCESS_RESTRICTED;
109+
// if ($item->fields["access_rights"] == PluginFormcreatorForm::ACCESS_RESTRICTED) {
110+
echo '<tr id="plugin_formcreator_restrictions_head" style="display: ' . ($is_visible ? 'block' : 'none') . '">';
111+
echo '<th colspan="2">' . self::getTypeName(2) . '</th>';
112+
echo '</tr>';
113+
echo '<tr id="plugin_formcreator_restrictions" style="display: ' . ($is_visible ? 'block' : 'none') . '">';
109114
echo '<td><label>' . __('Restricted to') . '</label></td>';
110-
echo '<td class="restricted-form">' . PluginFormcreatorRestrictedFormDropdown::show('restrictions', [
115+
echo '<td class="restricted-form">';
116+
echo PluginFormcreatorRestrictedFormDropdown::show('restrictions', [
111117
'users_id' => $item->fields['users'] ?? [],
112118
'groups_id' => $item->fields['groups'] ?? [],
113119
'profiles_id' => $item->fields['profiles'] ?? [],
114-
]) . '</td>';
120+
]); // Does not supports display parameter to return the output instead of printing it
121+
echo '</td>';
115122
echo '</tr>';
116-
}
123+
// }
117124

118125
$formFk = PluginFormcreatorForm::getForeignKeyField();
119126
echo '<tr>';

js/scripts.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,18 @@ var plugin_formcreator = new function() {
14161416
return item.name != '_glpi_csrf_token';
14171417
});
14181418
}
1419+
1420+
this.showMassiveRestrictions = function (item) {
1421+
document.querySelector('#plugin_formcreator_restrictions_head').style.display = 'none';
1422+
document.querySelector('#plugin_formcreator_restrictions').style.display = 'none';
1423+
document.querySelector('#plugin_formcreator_captcha').style.display = 'none';
1424+
if (item.value == 2 /* PluginFormcreatorForm::ACCESS_RESTRICTED */) {
1425+
document.querySelector('#plugin_formcreator_restrictions').style.display = 'block';
1426+
document.querySelector('#plugin_formcreator_restrictions_head').style.display = 'block';
1427+
} else if (item.value == 0 /* PluginFormcreatorForm::ACCESS_PUBLIC */) {
1428+
document.querySelector('#plugin_formcreator_captcha').style.display = 'block';
1429+
}
1430+
}
14191431
}
14201432

14211433
// === TARGETS ===

0 commit comments

Comments
 (0)