Skip to content

Commit

Permalink
feat(form): enable / disable form with single click
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <[email protected]>
  • Loading branch information
btry committed Mar 18, 2021
1 parent ea3afe5 commit e7bd38e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
44 changes: 44 additions & 0 deletions ajax/form_toggle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* ---------------------------------------------------------------------
* Formcreator is a plugin which allows creation of custom forms of
* easy access.
* ---------------------------------------------------------------------
* LICENSE
*
* This file is part of Formcreator.
*
* Formcreator is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Formcreator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
* @copyright Copyright © 2011 - 2021 Teclib'
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+
* @link https://github.com/pluginsGLPI/formcreator/
* @link https://pluginsglpi.github.io/formcreator/
* @link http://plugins.glpi-project.org/#/plugin/formcreator
* ---------------------------------------------------------------------
*/

include ('../../../inc/includes.php');
Session::checkRight('entity', UPDATE);

$form = new PluginFormcreatorForm();

$success = $form->update([
'id' => $_POST['id'],
'toggle' => 'toggle',
]);

if (!$success) {
http_response_code(500);
}
2 changes: 2 additions & 0 deletions css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1589,10 +1589,12 @@ span.fc_list_icon {

/* Active / inactive light for forms */
.plugin-forcreator-active {
cursor: pointer;
color: #009933;
}

.plugin-forcreator-inactive {
cursor: pointer;
color: #a0a0a0;
}

Expand Down
10 changes: 9 additions & 1 deletion inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options
$output = '<i class="fa fa-circle '
. $class
. '" aria-hidden="true" title="' . $title . '"></i>';
$output = '<div style="text-align: center">' . $output . '</div>';
$output = '<div style="text-align: center" onclick="plugin_formcreator.toggleForm(' . $options['raw_data']['id']. ')">' . $output . '</div>';
return $output;
break;

Expand Down Expand Up @@ -1400,6 +1400,14 @@ public function post_updateItem($history = 1) {
* @return array the modified $input array
*/
public function prepareInputForUpdate($input) {
if (isset($input['toggle'])) {
// Enable / disable form
return [
'id' => $input['id'],
'is_active' => $this->fields['is_active'] == '0' ? '1' : '0',
];
}

if (isset($input['access_rights'])
|| isset($_POST['massiveaction'])
|| isset($input['usage_count'])) {
Expand Down
13 changes: 13 additions & 0 deletions js/scripts.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,19 @@ function buildTiles(list) {
sections.find('.moveDown').show();
sections.last().find('.moveDown').hide();
}

this.toggleForm = function (id) {
$.ajax({
url: formcreatorRootDoc + '/ajax/form_toggle.php',
type: 'POST',
data: {
toggle: 'toggle',
id: id
}
}).success(function () {
location.reload();
});
}
}

// === TARGETS ===
Expand Down

0 comments on commit e7bd38e

Please sign in to comment.