Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rules and transfer form #265

Merged
merged 6 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 40 additions & 22 deletions ajax/ruleaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,53 @@
}

echo "<table width='100%'><tr><td width='30%'>";

$rule = getItemForItemtype($_POST["sub_type"]);
$actions_options = $rule->getAllActions();
$action_type = '';
if (isset($_POST["action_type"])) {
$action_type = $_POST["action_type"];
}

$randaction = RuleAction::dropdownActions(['subtype' => $_POST["sub_type"],
'name' => "action_type",
'field' => $_POST["field"],
'value' => $action_type,
'alreadyused' => $already_used]);

echo "</td><td>";
echo "<span id='action_type_span$randaction'>\n";
echo "</span>\n";
$actions = ["assign"];
$field = $_POST["field"];
if ($already_used) {
if (!isset($actions_options[$field]['permitseveral'])) {
return false;
}
$actions = $actions_options[$field]['permitseveral'];

$paramsaction = ['action_type' => '__VALUE__',
'field' => $_POST["field"],
'sub_type' => $_POST["sub_type"],
$item->getForeignKeyField() => $_POST[$item->getForeignKeyField()]];

Ajax::updateItemOnSelectEvent("dropdown_action_type$randaction", "action_type_span$randaction",
$CFG_GLPI["root_doc"]."/ajax/ruleactionvalue.php", $paramsaction);
} else {
if (isset($actions_options[$field]['force_actions'])) {
$actions = $actions_options[$field]['force_actions'];
}
}

if (isset($_POST['value'])) {
$paramsaction['value'] = stripslashes($_POST['value']);
$elements = [];
foreach ($actions as $action) {
$elements[$action] = RuleAction::getActionByID($action);
}
$updateScript = <<<JS
var condition = $('#DropdownForConditionAction').val();
var condition_span = $('#action_type_span');
var url = "{$CFG_GLPI['root_doc']}/ajax/ruleactionvalue.php";

Ajax::updateItem("action_type_span$randaction", $CFG_GLPI["root_doc"]."/ajax/ruleactionvalue.php",
$paramsaction, "dropdown_action_type$randaction");
echo "</td></tr></table>";
condition_span.load(url, {
action_type: condition,
field: "{$_POST['field']}",
sub_type: "{$_POST['sub_type']}",
{$item->getForeignKeyField()}: "{$_POST[$item->getForeignKeyField()]}"
});
JS;
renderTwigTemplate('macros/input.twig', [
'type' => 'select',
'id' => 'DropdownForConditionAction',
'name' => 'action_type',
'value' => $action_type,
'values' => $elements,
'hooks' => [
'change' => $updateScript
],
'init' => $updateScript
]);
echo "<span id='action_type_span'></span>\n";
}
46 changes: 28 additions & 18 deletions ajax/rulecriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,37 @@
if (isset($_POST['condition'])) {
$condparam['value'] = $_POST['condition'];
}
echo "<table width='100%'><tr><td width='30%'>";
$randcrit = RuleCriteria::dropdownConditions($_POST["sub_type"], $condparam);
echo "</td><td>";
echo "<span id='condition_span$randcrit'>\n";
echo "</span>\n";

$paramscriteria = ['condition' => '__VALUE__',
'criteria' => $_POST["criteria"],
'sub_type' => $_POST["sub_type"]];
$elements = [];
foreach (RuleCriteria::getConditions($_POST['sub_type'], '') as $pattern => $label) {
if (empty($p['allow_conditions'])
|| (!empty($p['allow_conditions']) && in_array($pattern, $p['allow_conditions']))) {
$elements[$pattern] = $label;
}
}

Ajax::updateItemOnSelectEvent("dropdown_condition$randcrit", "condition_span$randcrit",
$CFG_GLPI["root_doc"]."/ajax/rulecriteriavalue.php",
$paramscriteria);
$updateScript = <<<JS
var condition = $('#DropdownForConditionCriterias').val();
var condition_span = $('#condition_span');
var url = "{$CFG_GLPI['root_doc']}/ajax/rulecriteriavalue.php";

if (isset($_POST['pattern'])) {
$paramscriteria['value'] = stripslashes($_POST['pattern']);
}
condition_span.load(url, {
condition: condition,
criteria: "{$_POST['criteria']}",
sub_type: "{$_POST['sub_type']}"
});
JS;

Ajax::updateItem("condition_span$randcrit",
$CFG_GLPI["root_doc"]."/ajax/rulecriteriavalue.php", $paramscriteria,
"dropdown_condition$randcrit");
echo "</td></tr></table>";
renderTwigTemplate('macros/input.twig', [
'name' => 'condition',
'id' => 'DropdownForConditionCriterias',
'type' => 'select',
'values' => $elements,
'hooks' => [
'change' => $updateScript
],
'init' => $updateScript
]);
echo "<span id='condition_span'></span>\n";
}
}
Loading
Loading