-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from alexplusde/choice_status
Neues Feld: choice_status (Select-Feld in Übersicht wechseln können)
- Loading branch information
Showing
7 changed files
with
209 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
$(document).on('rex:ready', function (event, container) { | ||
initStatusToggle(container); | ||
}); | ||
|
||
|
||
function initStatusToggle(container) { | ||
// status select | ||
if (container.find('[data-status="choice_status_select"]').length) { | ||
|
||
var statusChangeSelect = function () { | ||
var $this = $(this); | ||
|
||
updateDatasetStatus($this, $this.val(), function (resp) { | ||
}); | ||
}; | ||
container.find('select[data-status="choice_status_select"]').change(statusChangeSelect); | ||
|
||
/* | ||
var statusChangeButtons = function () { | ||
var $this = $(this); | ||
updateDatasetStatus($this, $this.val(), function (resp) { | ||
var $parent = $this.parent(); | ||
$parent.html(resp.message.element); | ||
$parent.children('select:first').change(statusChange); | ||
}); | ||
}; | ||
container.find('div[data-status="choice_status"] button').click(statusChangeButtons); | ||
*/ | ||
} | ||
} | ||
|
||
function updateDatasetStatus($this, status, callback) { | ||
|
||
$('#rex-js-ajax-loader').addClass('rex-visible'); | ||
if (confirm('Ändern?')) { | ||
url = window.location.origin; | ||
$.get(url + '/redaxo/index.php?page=content&rex-api-call=choice_status', { | ||
data_id: $this.data('id'), | ||
table: $this.data('table'), | ||
field: $this.data('field'), | ||
token: $this.data('token'), | ||
value: status | ||
}, function (resp) { | ||
callback(resp); | ||
$('#rex-js-ajax-loader').removeClass('rex-visible'); | ||
}); | ||
|
||
} else { | ||
window.location.reload(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
$data_id = $this->getVar("data_id"); | ||
$table = $this->getVar("table"); | ||
$field = $this->getVar('field'); | ||
$options = $this->getVar("options"); | ||
$selected = $this->getVar("selected"); | ||
$token = $this->getVar("token"); | ||
?> | ||
<select data-table="<?= $table ?>" | ||
data-token="<?= $token ?>" | ||
data-field="<?= $field ?>" | ||
data-id="<?= $data_id ?>" class="form-control" | ||
data-status="choice_status_select" style="width: auto;"> | ||
<?php foreach ($options as $value => $option) { | ||
?> | ||
<option value="<?= $value ?>" <?php if ($value == $selected) { | ||
echo "selected"; | ||
} ?>><?= $option ?></option> | ||
<?php | ||
} // foreach $options | ||
?> | ||
</select> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
class rex_yform_value_choice_status extends rex_yform_value_choice | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'choice_status|name|label|choices|[expanded type: boolean; default: 0, 0,1]|[multiple type: boolean; default: 0, 0,1]|[default]|[group_by]|[preferred_choices]|[placeholder]|[group_attributes]|[attributes]|[choice_attributes]|[notice]|[no_db]'; | ||
} | ||
|
||
public function getDefinitions(): array | ||
{ | ||
return [ | ||
'type' => 'value', | ||
'name' => 'choice_status', | ||
'values' => [ | ||
'name' => ['type' => 'name', 'label' => rex_i18n::msg('yform_values_defaults_name')], | ||
'label' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_defaults_label')], | ||
'choices' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_choice_choices'), 'notice' => rex_i18n::msg('yform_values_choice_choices_notice').rex_i18n::rawMsg('yform_values_choice_choices_table')], | ||
'expanded' => ['type' => 'boolean', 'label' => rex_i18n::msg('yform_values_choice_expanded'), 'notice' => rex_i18n::msg('yform_values_choice_expanded_notice')], | ||
'multiple' => ['type' => 'boolean', 'label' => rex_i18n::msg('yform_values_choice_multiple'), 'notice' => rex_i18n::msg('yform_values_choice_multiple_notice').rex_i18n::rawMsg('yform_values_choice_expanded_multiple_table')], | ||
'default' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_choice_default'), 'notice' => rex_i18n::msg('yform_values_choice_default_notice')], | ||
'group_by' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_choice_group_by'), 'notice' => rex_i18n::msg('yform_values_choice_group_by_notice')], | ||
'preferred_choices' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_choice_preferred_choices'), 'notice' => rex_i18n::msg('yform_values_choice_preferred_choices_notice')], | ||
'placeholder' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_choice_placeholder'), 'notice' => rex_i18n::msg('yform_values_choice_placeholder_notice')], | ||
'group_attributes' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_choice_group_attributes'), 'notice' => rex_i18n::msg('yform_values_choice_group_attributes_notice')], | ||
'attributes' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_choice_attributes'), 'notice' => rex_i18n::msg('yform_values_choice_attributes_notice')], | ||
'choice_attributes' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_choice_choice_attributes'), 'notice' => rex_i18n::msg('yform_values_choice_choice_attributes_notice')], | ||
'notice' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_defaults_notice')], | ||
'no_db' => ['type' => 'no_db', 'label' => rex_i18n::msg('yform_values_defaults_table'), 'default' => 0], | ||
'choice_label' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_choice_choice_label'), 'notice' => rex_i18n::msg('yform_values_choice_choice_label_notice')], | ||
], | ||
'description' => rex_i18n::msg('yform_values_choice_description'), | ||
'db_type' => ['text', 'int', 'tinyint(1)', 'varchar(191)'], | ||
]; | ||
} | ||
|
||
public static function select($a) | ||
{ | ||
$field = $a['field']; | ||
$status_field = $a['params']['table']->getValueField($field); | ||
$status_options = \rex_yform_value_choice::getListValues([ | ||
'field' => $field, | ||
'params' => ['field' => $status_field], | ||
]); | ||
|
||
$table_name = $a['params']['table']->getTableName(); | ||
$data_id = $a['list']->getValue('id'); | ||
$token = self::getToken($data_id, $table_name); | ||
$selected_status = $a['value']; | ||
|
||
$fragment = new rex_fragment(); | ||
$fragment->setVar("options", $status_options); | ||
$fragment->setVar("selected", $selected_status); | ||
$fragment->setVar("table", $table_name); | ||
$fragment->setVar("field", $field); | ||
$fragment->setVar("data_id", $data_id); | ||
$fragment->setVar("token", $token); | ||
|
||
// if ($selected_status == 0) { | ||
return $fragment->parse('choice_status_select.php'); | ||
// } | ||
return $status_options[$selected_status]; | ||
} | ||
|
||
public static function getToken($data_id, $table_name) | ||
{ | ||
$secret = rex_config::get('yform_field', 'choice_status_secret'); | ||
|
||
return password_hash($secret . $data_id . $table_name, PASSWORD_DEFAULT); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
class rex_api_choice_status extends rex_api_function | ||
{ | ||
protected $published = true; | ||
|
||
public function execute() | ||
{ | ||
if (!rex::isBackend() || !rex_backend_login::hasSession()) { | ||
exit(); | ||
} | ||
|
||
$token = rex_request('token', 'string', ""); | ||
$table = rex_request('table', 'string', ""); | ||
$data_id = rex_request('data_id', 'int', 0); | ||
$field = rex_request('field', 'string', ''); | ||
$value = rex_request('value', 'string', ''); | ||
$secret = rex_config::get('yform_field', 'choice_status_secret'); | ||
|
||
$check = password_verify($secret . $data_id . $table, $token); | ||
|
||
rex_response::cleanOutputBuffers(); | ||
|
||
if ($data_id && $table && $token && $field && $value && $check) { | ||
$dataset = rex_yform_manager_dataset::get($data_id, $table); | ||
|
||
if ($dataset) { | ||
$dataset->setValue($field, $value); | ||
if (!$dataset->save()) { | ||
rex_logger::factory()->log('Error', 'error: API Call: Status not saved'); | ||
rex_response::setStatus(rex_response::HTTP_BAD_REQUEST); | ||
} else { | ||
rex_response::setStatus(rex_response::HTTP_OK); | ||
} | ||
} | ||
} else { | ||
rex_logger::factory()->log('Error', 'error: API Parameter not correct: token:'.$token); | ||
rex_response::setStatus(rex_response::HTTP_BAD_REQUEST); | ||
} | ||
exit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters