Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
feat(fleet): added the option to edit created policies
Browse files Browse the repository at this point in the history
Signed-off-by: Domingo Oropeza <doropeza@teclib.com>
  • Loading branch information
DIOHz0r committed Feb 8, 2018
1 parent 70ab199 commit 0ac70e3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
14 changes: 14 additions & 0 deletions ajax/policyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,23 @@
}

$policyId = intval($_POST['value']);
$mode = (isset($_POST['mode'])) ? strval($_POST['mode']) : null;

$factory = new PluginFlyvemdmPolicyFactory();
$policy = $factory->createFromDBByID($policyId);
if ($policy !== null) {
if ($mode == "update") {
$rand = mt_rand();
echo '<form name="policy_editor_form'.$rand.'" id="policy_editor_form'.$rand.'" method="post"
action="/plugins/flyvemdm/front/task.form.php"><br>';
}
echo $policy->showValueInput();
if ($mode == "update") {
echo "<input type='hidden' name='id' value='" . $_POST['task'] . "'>
<input type='hidden' name='plugin_flyvemdm_policies_id' value='" . $policyId . "'>
<input type='hidden' name='plugin_flyvemdm_fleets_id' value='" . $_POST['fleet'] . "'>
<br><br><input type='submit' class='submit' name='update' value='" . _x('button',
'Update') . "'>";
echo Html::closeForm(false);
}
}
10 changes: 10 additions & 0 deletions front/task.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,14 @@
$task->add($_POST);
Html::back();
}

if (isset($_POST['update'])) {
//$task->check(-1, UPDATE, $_POST);
$_POST = $task->preprocessInput($_POST);
// var_dump($_POST);
// die();
$task->update($_POST);
Html::back();
}

Html::back();
41 changes: 40 additions & 1 deletion tpl/fleet_policy.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@
<tr>
<td>{% if canEdit %}{{ policy.checkbox|raw }}{% endif %}</td>
<td>{{ policy.policyName }}</td>
<td>{{ policy.value }}</td>
<td>
{% if canEdit %}
<a href="#" onclick="editPolicy('{{ policy.plugin_flyvemdm_policies_id }}', '{{ policy.id }}'); return false;">
{{ policy.value }}
</a>
{% else %}
{{ policy.value }}
{% endif %}
</td>
</tr>
{% endfor %}
<tr>
Expand All @@ -57,5 +65,36 @@
</table>
{% if canEdit %}
{{ massiveActionForm.end|raw }}
<div id='policy_editor' align="center" class='invisible'>
<div>Update policy value:</div>
<div id="policy_editor_form"></div>
</div>
<script type="text/javascript">
$( document ).ready(function() {
$('#policy_editor').dialog({
height: 'auto',
width: 'auto',
modal: true,
autoOpen: false
});
});

function editPolicy($policyId, $taskId) {
$('#policy_editor').dialog('open');
$.ajax({
url: '../ajax/policyValue.php',
method: 'POST',
data: {
mode: 'update',
fleet: '{{ fleet_policy.plugin_flyvemdm_fleets_id }}',
task: $taskId,
value: $policyId
},
success: function (response) {
$('#policy_editor_form').html(response);
}
});
}
</script>
{% endif %}
</div>

0 comments on commit 0ac70e3

Please sign in to comment.