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

Commit

Permalink
fix(task): show the current value when editing a task
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry authored and DIOHz0r committed Feb 8, 2018
1 parent 3aba4b9 commit 2b59152
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 25 deletions.
17 changes: 13 additions & 4 deletions inc/policybase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ public function unapply(PluginFlyvemdmFleet $fleet, $value, $itemtype, $itemId)
/**
* @return string
*/
public function showValueInput() {
$html = '<input name="value" value="" >';
public function showValueInput($value = '', $itemtype = '', $itemId = 0) {
$html = '<input name="value" value="' . $value . '" >';

return $html;
}
Expand Down Expand Up @@ -220,7 +220,6 @@ public function getPolicyData() {
/**
* Generate the form for add or edit a policy
*
* @param PluginFlyvemdmPolicyBase $policy to be edited
* @param string $mode add or update
* @param array $_input values for update
* @return string html
Expand All @@ -229,8 +228,18 @@ public function formGenerator(
$mode = 'add',
array $_input = []
) {
$task = new PluginFlyvemdmTask();
$value = '';
$itemtype = '';
$itemId = 0;
if (!$task->isNewID($_input['task'])) {
$task->getFromDB($_input['task']);
$value = $task->getField('value');
$itemtype = $task->getField('itemtype');
$itemId = $task->getField('items_id');
}
$form['mode'] = $mode;
$form['input'] = $this->showValueInput();
$form['input'] = $this->showValueInput($value, $itemtype, $itemId);
if ($mode == "update") {
$form['url'] = Toolbox::getItemTypeFormURL(PluginFlyvemdmTask::class);
$form['rand'] = mt_rand();
Expand Down
7 changes: 2 additions & 5 deletions inc/policyboolean.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ public function getMqttMessage($value, $itemtype, $itemId) {
return $array;
}

/**
* @return int|string
*/
public function showValueInput() {
return Dropdown::showYesNo('value', '0', -1, ['display' => false]);
public function showValueInput($value = '', $itemtype = '', $itemId = 0) {
return Dropdown::showYesNo('value', $value, -1, ['display' => false]);
}

/**
Expand Down
19 changes: 10 additions & 9 deletions inc/policydeployapplication.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,18 @@ public function unapply(PluginFlyvemdmFleet $fleet, $value, $itemtype, $itemId)
return true;
}

/**
* @return string
*/
public function showValueInput() {
public function showValueInput($value = '', $itemtype = '', $itemId = 0) {
$value = json_decode($value, JSON_OBJECT_AS_ARRAY);
$out = PluginFlyvemdmPackage::dropdown([
'display' => false,
'displaywith' => ['alias'],
'name' => 'items_id',
'display' => false,
'displaywith' => ['alias'],
'name' => 'items_id',
'value' => $itemId,
]);
$out .= '<input type="hidden" name="itemtype" value="PluginFlyvemdmPackage" />';
$out .= '<input type="hidden" name="value[remove_on_delete]" value="1" />';
$itemtype = PluginFlyvemdmPackage::class;
$removeOnDelete = $value['remove_on_delete'];
$out .= '<input type="hidden" name="itemtype" value="' . $itemtype . '" />';
$out .= '<input type="hidden" name="value[remove_on_delete]" value="' . $removeOnDelete . '" />';

return $out;
}
Expand Down
9 changes: 5 additions & 4 deletions inc/policydeployfile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,19 @@ public function unapply(PluginFlyvemdmFleet $fleet, $value, $itemtype, $itemId)
/**
* @return string|void
*/
public function showValueInput() {
public function showValueInput($value = '') {
$out = PluginFlyvemdmFile::dropdown([
'display' => false,
'name' => 'items_id',
]);
$out .= '<input type="hidden" name="itemtype" value="PluginFlyvemdmFile" />';
$out .= '<input type="hidden" name="itemtype" value="' . PluginFlyvemdmFile::class . '" />';
$out .= '<br>';
$out .= __('copy to', 'flyvemdm');
$out .= '<br>';
$out .= PluginFlyvemdmWellknownpath::dropdown([
'display' => false,
'name' => 'destination_base',
'display' => false,
'name' => 'destination_base',
'value' => $value,
]);
$out .= '<input type="text" name="value[destination]" value="" />';
$out .= '<input type="hidden" name="value[remove_on_delete]" value="1" />';
Expand Down
4 changes: 2 additions & 2 deletions inc/policydropdown.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public function translateData() {
/**
* @return int|string
*/
public function showValueInput() {
return Dropdown::showFromArray('value', $this->valueList, ['display' => false]);
public function showValueInput($value = '', $itemtype = '', $itemId = 0) {
return Dropdown::showFromArray('value', $this->valueList, ['display' => false, 'value' => $value]);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion inc/policyinterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ public function unapply(PluginFlyvemdmFleet $fleet, $value, $itemtype, $itemId);

/**
* return HTML input to set policy value
* @param string $value value of the task
* @param string $itemtype type of the item linked to the task
* @param integer $itemId ID of the item
* @return string
*/
public function showValueInput();
public function showValueInput($value = '', $itemtype = '', $itemId = 0);


/**
Expand Down

0 comments on commit 2b59152

Please sign in to comment.