Skip to content

Commit

Permalink
fix(field): default value for most fields
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Sep 9, 2019
1 parent 58f0f18 commit f05f2de
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 17 deletions.
20 changes: 14 additions & 6 deletions ajax/dropdown_values.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,21 @@
if (!isset($_REQUEST['dropdown_itemtype'])
|| $_REQUEST['dropdown_itemtype'] == '0'
|| !class_exists($_REQUEST['dropdown_itemtype'])) {
Dropdown::showFromArray('dropdown_default_value', [], ['display_emptychoice' => true]);
Dropdown::showFromArray(
'dropdown_default_value',
[], [
'display_emptychoice' => true
]
);
} else {
$question = new PluginFormcreatorQuestion();
$question->getFromDB((int) $_REQUEST['id']);
$defaultValue = isset($question->fields['default_values'])
? $question->fields['default_values']
: 0;
Dropdown::show($_REQUEST['dropdown_itemtype'], [
'name' => 'dropdown_default_value',
'rand' => mt_rand(),
'name' => 'dropdown_default_value',
'rand' => mt_rand(),
'value' => $defaultValue,
]);
$showTicketCategorySpecific = ($_REQUEST['dropdown_itemtype'] == ITILCategory::class)
? 'true'
: 'false';
}
2 changes: 1 addition & 1 deletion inc/fields/actorfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getDesignSpecializationField() {
$additions .= '<td>';
$additions .= '<textarea name="default_values" id="default_values" rows="4" cols="40"'
.'style="width: 90%">'
.$this->getValueForDesign()
.$this->question->fields['default_values']
.'</textarea>';
$additions .= '</td>';
$additions .= '<td>';
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/checkboxesfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getDesignSpecializationField() {
$additions .= '<td>';
$additions .= '<textarea name="default_values" id="default_values" rows="4" cols="40"'
.'style="width: 90%">'
.$this->getValueForDesign()
.$this->question->fields['default_values']
.'</textarea>';
$additions .= '</td>';
$additions .= '<td>';
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/floatfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getDesignSpecializationField() {
$additions .= '</label>';
$additions .= '</td>';
$additions .= '<td id="dropdown_default_value_field">';
$value = Html::entities_deep($this->getValueForDesign());
$value = Html::entities_deep($this->question->fields['default_values']);
$additions .= '<input type="text" name="default_values" id="default_values" rows="4" cols="40"'
.'style="width: 90%" value="'.$value.'">';
$additions .= '</td>';
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/glpiselectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function getDesignSpecializationField() {
$additions .= '<td></td>';
$additions .= '<td></td>';
$additions .= '</tr>';

$additions .= Html::scriptBlock("plugin_formcreator_changeGlpiObjectItemType($rand);");
return [
'label' => $label,
'field' => $field,
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/hiddenfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getDesignSpecializationField() {
$additions .= '</label>';
$additions .= '</td>';
$additions .= '<td id="dropdown_default_value_field">';
$value = Html::entities_deep($this->getValueForDesign());
$value = Html::entities_deep($this->question->fields['default_values']);
$additions .= '<input type="text" name="default_values" id="default_values" rows="4" cols="40"'
.'style="width: 90%" value="'.$value.'">';
$additions .= '</td>';
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/integerfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getDesignSpecializationField() {
$additions .= '</label>';
$additions .= '</td>';
$additions .= '<td id="dropdown_default_value_field">';
$value = Html::entities_deep($this->getValueForDesign());
$value = Html::entities_deep($this->question->fields['default_values']);
$additions .= '<input type="text" name="default_values" id="default_values" rows="4" cols="40"'
.'style="width: 90%" value="'.$value.'">';
$additions .= '</td>';
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/multiselectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getDesignSpecializationField() {
$additions .= '<td>';
$additions .= '<textarea name="default_values" id="default_values" rows="4" cols="40"'
.'style="width: 90%">'
.$this->getValueForDesign()
.$this->question->fields['default_values']
.'</textarea>';
$additions .= '</td>';
$additions .= '<td>';
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/radiosfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getDesignSpecializationField() {
$additions .= '<td>';
$additions .= '<textarea name="default_values" id="default_values" rows="4" cols="40"'
.'style="width: 90%">'
.$this->getValueForDesign()
.$this->question->fields['default_values']
.'</textarea>';
$additions .= '</td>';
$additions .= '<td>';
Expand Down
17 changes: 17 additions & 0 deletions inc/fields/tagfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ public function isPrerequisites() {
return class_exists(PluginTagTag::class);
}

public function getDesignSpecializationField() {
$rand = mt_rand();

$label = '';
$field = '';

$additions = '';

return [
'label' => $label,
'field' => $field,
'additions' => $additions,
'may_be_empty' => false,
'may_be_required' => true,
];
}

public function displayField($canEdit = true) {
global $DB;

Expand Down
2 changes: 1 addition & 1 deletion inc/fields/textfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getDesignSpecializationField() {
$additions .= '</label>';
$additions .= '</td>';
$additions .= '<td>';
$value = Html::entities_deep($this->getValueForDesign());
$value = Html::entities_deep($this->question->fields['default_values']);
$additions .= '<input type="text" name="default_values" id="default_values" rows="4" cols="40"'
.'style="width: 90%" value="'.$value.'">';
$additions .= '</td>';
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/urgencyfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getDesignSpecializationField() {
$additions .= '<td>';
$additions .= Ticket::dropdownUrgency([
'name' => 'default_values',
'value' => $this->questoin->fields['default_values'],
'value' => $this->question->fields['default_values'],
'comments' => false,
'rand' => $rand,
'display' => false,
Expand Down
6 changes: 5 additions & 1 deletion js/scripts.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -776,12 +776,14 @@ function plugin_formcreator_removeNextCondition(target) {

function plugin_formcreator_changeDropdownItemtype(rand) {
dropdown_type = $('[name="form_question"] [name="dropdown_values"]').val();
dropdown_id = $('[name="form_question"] [name="id"]').val();

$.ajax({
url: rootDoc + '/plugins/formcreator/ajax/dropdown_values.php',
type: 'GET',
data: {
dropdown_itemtype: dropdown_type,
'id': dropdown_id
},
}).done(function(response) {
showTicketCategorySpecific = false;
Expand All @@ -794,13 +796,15 @@ function plugin_formcreator_changeDropdownItemtype(rand) {
}

function plugin_formcreator_changeGlpiObjectItemType() {
glpi_object = $('[name="form_question"] [name="glpi_objects"]').val();
glpi_object = $('[name="form_question"] [name="glpi_objects"]').val();
glpi_object_id = $('[name="form_question"] [name="id"]').val();

$.ajax({
url: rootDoc + '/plugins/formcreator/ajax/dropdown_values.php',
type: 'GET',
data: {
dropdown_itemtype: glpi_object,
id: glpi_object_id
},
}).done(function(response) {
$('#dropdown_default_value_field').html(response);
Expand Down

0 comments on commit f05f2de

Please sign in to comment.