Skip to content

Commit 4ebbac6

Browse files
committed
feat(form): enable / disable form with single click
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 514905d commit 4ebbac6

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

ajax/form_toggle.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* ---------------------------------------------------------------------
4+
* Formcreator is a plugin which allows creation of custom forms of
5+
* easy access.
6+
* ---------------------------------------------------------------------
7+
* LICENSE
8+
*
9+
* This file is part of Formcreator.
10+
*
11+
* Formcreator is free software; you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation; either version 2 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* Formcreator is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
23+
* ---------------------------------------------------------------------
24+
* @copyright Copyright © 2011 - 2021 Teclib'
25+
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+
26+
* @link https://github.com/pluginsGLPI/formcreator/
27+
* @link https://pluginsglpi.github.io/formcreator/
28+
* @link http://plugins.glpi-project.org/#/plugin/formcreator
29+
* ---------------------------------------------------------------------
30+
*/
31+
32+
include ('../../../inc/includes.php');
33+
Session::checkRight('entity', UPDATE);
34+
35+
$form = new PluginFormcreatorForm();
36+
37+
$success = $form->update([
38+
'id' => $_POST['id'],
39+
'toggle' => 'toggle',
40+
]);
41+
42+
if (!$success) {
43+
http_response_code(500);
44+
}

css/styles.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,10 +1655,12 @@ span.fc_list_icon {
16551655

16561656
/* Active / inactive light for forms */
16571657
.plugin-forcreator-active {
1658+
cursor: pointer;
16581659
color: #009933;
16591660
}
16601661

16611662
.plugin-forcreator-inactive {
1663+
cursor: pointer;
16621664
color: #a0a0a0;
16631665
}
16641666

inc/form.class.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options
351351
$output = '<i class="fa fa-circle '
352352
. $class
353353
. '" aria-hidden="true" title="' . $title . '"></i>';
354-
$output = '<div style="text-align: center">' . $output . '</div>';
354+
$output = '<div style="text-align: center" onclick="plugin_formcreator.toggleForm(' . $options['raw_data']['id']. ')">' . $output . '</div>';
355355
return $output;
356356
break;
357357

@@ -1446,6 +1446,14 @@ public function post_updateItem($history = 1) {
14461446
* @return array the modified $input array
14471447
*/
14481448
public function prepareInputForUpdate($input) {
1449+
if (isset($input['toggle'])) {
1450+
// Enable / disable form
1451+
return [
1452+
'id' => $input['id'],
1453+
'is_active' => $this->fields['is_active'] == '0' ? '1' : '0',
1454+
];
1455+
}
1456+
14491457
if (isset($input['access_rights'])
14501458
|| isset($_POST['massiveaction'])
14511459
|| isset($input['usage_count'])) {

js/scripts.js.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,19 @@ function buildTiles(list) {
12051205
tr_inverse.hide();
12061206
}, 200);
12071207
});
1208+
1209+
this.toggleForm = function (id) {
1210+
$.ajax({
1211+
url: formcreatorRootDoc + '/ajax/form_toggle.php',
1212+
type: 'POST',
1213+
data: {
1214+
toggle: 'toggle',
1215+
id: id
1216+
}
1217+
}).success(function () {
1218+
location.reload();
1219+
});
1220+
}
12081221
}
12091222

12101223
// === TARGETS ===

0 commit comments

Comments
 (0)