Skip to content

Commit

Permalink
fix(targetticket,targetchange): editing actors
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Aug 22, 2019
1 parent 5ab2460 commit 87d7bc5
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 107 deletions.
2 changes: 1 addition & 1 deletion front/targetticket.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
$targetticket = new PluginFormcreatorTargetTicket();

// Edit an existing target ticket
if (isset($_POST["update"])) {
if (isset($_POST['update'])) {
$targetticket->update($_POST);
Html::back();

Expand Down
124 changes: 48 additions & 76 deletions inc/targetbase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ protected function showDueDateSettings(PluginFormcreatorForm $form, $rand) {
Dropdown::showFromArray('due_date_rule', self::getEnumDueDateRule(),
[
'value' => $this->fields['due_date_rule'],
'on_change' => 'formcreatorChangeDueDate(this.value)',
'on_change' => 'plugin_formcreator_formcreatorChangeDueDate(this.value)',
'display_emptychoice' => true
]
);
Expand Down Expand Up @@ -1102,27 +1102,27 @@ protected function showActorsSettings() {
// Requester header
echo '<th width="33%">';
echo _n('Requester', 'Requesters', 1) . ' &nbsp;';
echo '<img title="Ajouter" alt="Ajouter" onclick="displayRequesterForm()" class="pointer"
echo '<img title="Ajouter" alt="Ajouter" onclick="plugin_formcreator_displayRequesterForm()" class="pointer"
id="btn_add_requester" src="../../../pics/add_dropdown.png">';
echo '<img title="Annuler" alt="Annuler" onclick="hideRequesterForm()" class="pointer"
echo '<img title="Annuler" alt="Annuler" onclick="plugin_formcreator_hideRequesterForm()" class="pointer"
id="btn_cancel_requester" src="../../../pics/delete.png" style="display:none">';
echo '</th>';

// Watcher header
echo '<th width="34%">';
echo _n('Watcher', 'Watchers', 1) . ' &nbsp;';
echo '<img title="Ajouter" alt="Ajouter" onclick="displayWatcherForm()" class="pointer"
echo '<img title="Ajouter" alt="Ajouter" onclick="plugin_formcreator_displayWatcherForm()" class="pointer"
id="btn_add_watcher" src="../../../pics/add_dropdown.png">';
echo '<img title="Annuler" alt="Annuler" onclick="hideWatcherForm()" class="pointer"
echo '<img title="Annuler" alt="Annuler" onclick="plugin_formcreator_hideWatcherForm()" class="pointer"
id="btn_cancel_watcher" src="../../../pics/delete.png" style="display:none">';
echo '</th>';

// Assigned header
echo '<th width="33%">';
echo __('Assigned to') . ' &nbsp;';
echo '<img title="Ajouter" alt="Ajouter" onclick="displayAssignedForm()" class="pointer"
echo '<img title="Ajouter" alt="Ajouter" onclick="plugin_formcreator_displayAssignedForm()" class="pointer"
id="btn_add_assigned" src="../../../pics/add_dropdown.png">';
echo '<img title="Annuler" alt="Annuler" onclick="hideAssignedForm()" class="pointer"
echo '<img title="Annuler" alt="Annuler" onclick="plugin_formcreator_hideAssignedForm()" class="pointer"
id="btn_cancel_assigned" src="../../../pics/delete.png" style="display:none">';
echo '</th>';

Expand All @@ -1143,45 +1143,39 @@ protected function showActorsSettings() {
Dropdown::showFromArray(
'actor_type',
$dropdownItems, [
'on_change' => 'formcreatorChangeActorRequester(this.value)'
'on_change' => 'plugin_formcreator_ChangeActorRequester(this.value)'
]
);

echo '<div id="block_requester_user" style="display:none">';
User::dropdown([
'name' => 'actor_value_person',
'name' => 'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_PERSON,
'right' => 'all',
'all' => 0,
]);
echo '</div>';

echo '<div id="block_requester_group" style="display:none">';
Group::dropdown([
'name' => 'actor_value_group',
'name' => 'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP,
]);
echo '</div>';

echo '<div id="block_requester_question_user" style="display:none">';
// Dropdown::showFromArray('actor_value_question_person', $questions_user_list, [
// 'value' => $this->fields['due_date_question'],
// ]);
PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['glpiselect'],
'values' => User::class,
],
'actor_value_question_person',
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_PERSON,
[
'value' => 0
]
);
echo '</div>';

echo '<div id="block_requester_question_group" style="display:none">';
// Dropdown::showFromArray('actor_value_question_group', $questions_group_list, [
// 'value' => $this->fields['due_date_question'],
// ]);
PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
Expand All @@ -1196,15 +1190,12 @@ protected function showActorsSettings() {
echo '</div>';

echo '<div id="block_requester_question_actors" style="display:none">';
// Dropdown::showFromArray('actor_value_question_actors', $questions_actors_list, [
// 'value' => $this->fields['due_date_question'],
// ]);
PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['actor'],
],
'actor_value_question_person',
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS,
[
'value' => 0
]
Expand All @@ -1218,7 +1209,7 @@ protected function showActorsSettings() {

echo '<p align="center">';
echo '<input type="hidden" name="id" value="' . $this->getID() . '" />';
echo '<input type="hidden" name="actor_role" value="requester" />';
echo '<input type="hidden" name="actor_role" value="' . PluginFormcreatorTarget_Actor::ACTOR_ROLE_REQUESTER . '" />';
echo '<input type="submit" value="' . __('Add') . '" class="submit_button" />';
echo '</p>';

Expand Down Expand Up @@ -1283,67 +1274,58 @@ protected function showActorsSettings() {
unset($dropdownItems['supplier']);
unset($dropdownItems['question_supplier']);
Dropdown::showFromArray('actor_type',
$dropdownItems, ['on_change' => 'formcreatorChangeActorWatcher(this.value)']
$dropdownItems, ['on_change' => 'plugin_formcreator_ChangeActorWatcher(this.value)']
);

echo '<div id="block_watcher_user" style="display:none">';
User::dropdown([
'name' => 'actor_value_person',
'name' => 'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_PERSON,
'right' => 'all',
'all' => 0,
]);
echo '</div>';

echo '<div id="block_watcher_group" style="display:none">';
Group::dropdown([
'name' => 'actor_value_group',
'name' => 'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP,
]);
echo '</div>';

echo '<div id="block_watcher_question_user" style="display:none">';
// Dropdown::showFromArray('actor_value_question_person', $questions_user_list, [
// 'value' => $this->fields['due_date_question'],
// ]);
PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['glpiselect'],
'values' => User::class,
],
'actor_value_question_person',
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_PERSON,
[
'value' => 0
]
);
echo '</div>';

echo '<div id="block_watcher_question_group" style="display:none">';
// Dropdown::showFromArray('actor_value_question_group', $questions_group_list, [
// 'value' => $this->fields['due_date_question'],
// ]);
PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['glpiselect'],
'values' => Group::class,
],
'actor_value_question_person',
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_GROUP,
[
'value' => 0
]
);
echo '</div>';

echo '<div id="block_watcher_question_actors" style="display:none">';
// Dropdown::showFromArray('actor_value_question_actors', $questions_actors_list, [
// 'value' => $this->fields['due_date_question'],
// ]);
PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['actor'],
],
'actor_value_question_person',
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS,
[
'value' => 0
]
Expand All @@ -1357,7 +1339,7 @@ protected function showActorsSettings() {

echo '<p align="center">';
echo '<input type="hidden" name="id" value="' . $this->getID() . '" />';
echo '<input type="hidden" name="actor_role" value="observer" />';
echo '<input type="hidden" name="actor_role" value="' . PluginFormcreatorTarget_Actor::ACTOR_ROLE_OBSERVER . '" />';
echo '<input type="submit" value="' . __('Add') . '" class="submit_button" />';
echo '</p>';

Expand Down Expand Up @@ -1422,91 +1404,79 @@ protected function showActorsSettings() {
Dropdown::showFromArray(
'actor_type',
$dropdownItems, [
'on_change' => 'formcreatorChangeActorAssigned(this.value)'
'on_change' => 'plugin_formcreator_ChangeActorAssigned(this.value)'
]
);

echo '<div id="block_assigned_user" style="display:none">';
User::dropdown([
'name' => 'actor_value_person',
'name' => 'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_PERSON,
'right' => 'all',
'all' => 0,
]);
echo '</div>';

echo '<div id="block_assigned_group" style="display:none">';
Group::dropdown([
'name' => 'actor_value_group',
'name' => 'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP,
]);
echo '</div>';

echo '<div id="block_assigned_supplier" style="display:none">';
Supplier::dropdown([
'name' => 'actor_value_supplier',
'name' => 'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_SUPPLIER,
]);
echo '</div>';

echo '<div id="block_assigned_question_user" style="display:none">';
// Dropdown::showFromArray('actor_value_question_person', $questions_user_list, [
// 'value' => $this->fields['due_date_question'],
// ]);
PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['glpiselect'],
'values' => User::class,
],
'actor_value_question_person',
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_PERSON,
[
'value' => 0
]
);
echo '</div>';

echo '<div id="block_assigned_question_group" style="display:none">';
// Dropdown::showFromArray('actor_value_question_group', $questions_group_list, [
// 'value' => $this->fields['due_date_question'],
// ]);
PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['glpiselect'],
'values' => Group::class,
],
'actor_value_question_person',
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP,
[
'value' => 0
]
);
echo '</div>';

echo '<div id="block_assigned_question_actors" style="display:none">';
// Dropdown::showFromArray('actor_value_question_actors', $questions_actors_list, [
// 'value' => $this->fields['due_date_question'],
// ]);
PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['actor'],
],
'actor_value_question_person',
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS,
[
'value' => 0
]
);
echo '</div>';

echo '<div id="block_assigned_question_supplier" style="display:none">';
// Dropdown::showFromArray('actor_value_question_supplier', $questions_supplier_list, [
// 'value' => $this->fields['due_date_question'],
// ]);
PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['glpiselect'],
'values' => Supplier::class,
],
'actor_value_question_person',
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_SUPPLIER,
[
'value' => 0
]
Expand All @@ -1520,7 +1490,7 @@ protected function showActorsSettings() {

echo '<p align="center">';
echo '<input type="hidden" name="id" value="' . $this->getID() . '" />';
echo '<input type="hidden" name="actor_role" value="assigned" />';
echo '<input type="hidden" name="actor_role" value="' . PluginFormcreatorTarget_Actor::ACTOR_ROLE_ASSIGNED . '" />';
echo '<input type="submit" value="' . __('Add') . '" class="submit_button" />';
echo '</p>';

Expand Down Expand Up @@ -1816,23 +1786,25 @@ public function prepareInputForUpdate($input) {
}

public function post_addItem() {
if (!$this->skipCreateActors) {
$target_actor = $this->getItem_Actor();
$myFk = self::getForeignKeyField();
$target_actor->add([
$myFk => $this->getID(),
'actor_role' => PluginFormcreatorTarget_Actor::ACTOR_ROLE_REQUESTER,
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR,
'use_notification' => '1',
]);
$target_actor = $this->getItem_Actor();
$target_actor->add([
$myFk => $this->getID(),
'actor_role' => PluginFormcreatorTarget_Actor::ACTOR_ROLE_OBSERVER,
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_VALIDATOR,
'use_notification' => '1',
]);
}
if ($this->skipCreateActors) {
return;
}

$target_actor = $this->getItem_Actor();
$myFk = self::getForeignKeyField();
$target_actor->add([
$myFk => $this->getID(),
'actor_role' => PluginFormcreatorTarget_Actor::ACTOR_ROLE_REQUESTER,
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR,
'use_notification' => '1',
]);
$target_actor = $this->getItem_Actor();
$target_actor->add([
$myFk => $this->getID(),
'actor_role' => PluginFormcreatorTarget_Actor::ACTOR_ROLE_OBSERVER,
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_VALIDATOR,
'use_notification' => '1',
]);
}

protected static function getDeleteImage($id) {
Expand Down
Loading

0 comments on commit 87d7bc5

Please sign in to comment.