Skip to content

Commit

Permalink
Widgets um Add und View Button ergänzt (#1481)
Browse files Browse the repository at this point in the history
* Widgets um Add und View Button ergänzt

* CS
  • Loading branch information
tbaddade committed May 20, 2024
1 parent 26c759c commit 0a076c2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
30 changes: 30 additions & 0 deletions plugins/manager/assets/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ $(document).on('rex:ready',function() {
let link = this.dataset.link;
let widget_type = this.dataset.widget_type;
let field_name = this.dataset.field_name;
let _csrf_token = this.dataset.csrf_token;
let value = this.dataset.value;

$(this).find("a").each(function () {

Expand All @@ -21,6 +23,34 @@ $(document).on('rex:ready',function() {
};
}

// add
if (this.classList.contains('yform-dataset-widget-add')) {
this.onclick = function () {
let newWindowLink = link + '&_csrf_token='+ _csrf_token +'&func=add&rex_yform_manager_opener[id]='+id+'&rex_yform_manager_opener[field]='+field_name+'&rex_yform_manager_opener[multiple]='+multiple;
return newWindow( id, newWindowLink, 1200,800,',status=yes,resizable=yes');
};
}

// view
if (value !== '' && this.classList.contains('yform-dataset-widget-view')) {
this.onclick = function () {
let dataId = value;
if (multiple === 1) {
let viewObject = document.querySelector('#yform-dataset-view-'+id);
for (let position = 0; position < viewObject.options.length; position++) {
if (viewObject.options[position].selected) {
dataId = viewObject.options[position].value;
break;
}
}

}

let newWindowLink = link + '&_csrf_token='+ _csrf_token +'&func=edit&data_id=' + dataId + '&rex_yform_manager_opener[id]='+id+'&rex_yform_manager_opener[field]='+field_name+'&rex_yform_manager_opener[multiple]='+multiple;
return newWindow( id, newWindowLink, 1200,800,',status=yes,resizable=yes');
};
}

// open
if (this.classList.contains('yform-dataset-widget-open')) {
this.onclick = function () {
Expand Down
3 changes: 3 additions & 0 deletions plugins/manager/lang/de_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ yform_relation_move_first_data = Ausgewählten Datensatz an den Anfang verschieb
yform_relation_move_up_data = Ausgewählten Datensatz nach oben verschieben
yform_relation_move_down_data = Ausgewählten Datensatz nach unten verschieben
yform_relation_move_last_data = Ausgewählten Datensatz an das Ende verschieben
yform_relation_add_entry = Datensatz hinzufügen
yform_relation_choose_entry = Datensatz auswählen
yform_relation_delete_entry = Ausgewählten Datensatz löschen
yform_relation_no_entry = Kein Datensatz zugewiesen
yform_relation_view_entry = Datensatz ansehen
yform_relation_first_create_data = Bitte zunächst diesen Datensatz erstellen
yform_relation_edit_relations = Verknüpfungen verwalten

Expand Down
3 changes: 3 additions & 0 deletions plugins/manager/lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ yform_relation_move_first_data = Move selected entry to the top
yform_relation_move_up_data = Move selected entry up
yform_relation_move_down_data = Move selected entry down
yform_relation_move_last_data = Move selected entry to the bottom
yform_relation_add_entry = Add record
yform_relation_choose_entry = Select record
yform_relation_delete_entry = Delete selected record
yform_relation_no_entry = No record selected
yform_relation_view_entry = View record
yform_relation_first_create_data = Please first create this record
yform_relation_edit_relations = Edit relations

Expand Down
23 changes: 19 additions & 4 deletions plugins/manager/lib/var_yform_dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public static function getMultipleWidget($id, $name, $value, array $args = [])
$select->addOption($option['name'], $option['id']);
}

$viewButton = '<a class="btn btn-popup yform-dataset-widget-view" title="' . rex_i18n::msg('yform_relation_view_entry') . '"><i class="rex-icon rex-icon-view"></i></a>';
if ('' === $value) {
$viewButton = '<span class="btn btn-popup" title="' . rex_i18n::msg('yform_relation_no_entry') . '"><i class="rex-icon rex-icon-hide"></i></span>';
}

$e = [];
$e['field'] = $select->get() . '
<input type="hidden" class="yform-dataset-real" name="' . $name . '" id="' . $dataset_real_id . '" value="' . rex_escape($value) . '" />';
Expand All @@ -125,13 +130,15 @@ public static function getMultipleWidget($id, $name, $value, array $args = [])
<a class="btn btn-popup yform-dataset-widget-move yform-dataset-widget-move-down" title="' . rex_i18n::msg('yform_relation_down_first_data') . '"><i class="rex-icon rex-icon-down"></i></a>
<a class="btn btn-popup yform-dataset-widget-move yform-dataset-widget-move-bottom" title="' . rex_i18n::msg('yform_relation_move_last_data') . '"><i class="rex-icon rex-icon-bottom"></i></a>';
$e['functionButtons'] = '
<a class="btn btn-popup yform-dataset-widget-open" title="' . rex_i18n::msg('yform_relation_choose_entry') . '"><i class="rex-icon rex-icon-add"></i></a>
<a class="btn btn-popup yform-dataset-widget-open" title="' . rex_i18n::msg('yform_relation_choose_entry') . '"><i class="rex-icon rex-icon-view-list"></i></a>
<a class="btn btn-popup yform-dataset-widget-add" title="' . rex_i18n::msg('yform_relation_add_entry') . '"><i class="rex-icon rex-icon-add"></i></a>
<a class="btn btn-popup yform-dataset-widget-delete" title="' . rex_i18n::msg('yform_relation_delete_entry') . '"><i class="rex-icon rex-icon-remove"></i></a>
';
' . $viewButton;
$e['before'] = '<div class="yform-dataset-widget"
data-widget_type="multiple"
data-id="' . $id . '"
data-link="' . $link . '"
data-csrf_token="' . urlencode($args['_csrf_token']) . '"
data-field_name="' . urlencode($args['fieldName']) . '">';
$e['after'] = '</div>';

Expand All @@ -150,18 +157,26 @@ public static function getSingleWidget($id, $name, $value, array $args = [])
$dataset_view_id = 'yform-dataset-view-' . $id . '';
$dataset_real_id = 'yform-dataset-real-' . $id . '';

$viewButton = '<a class="btn btn-popup yform-dataset-widget-view" title="' . rex_i18n::msg('yform_relation_view_entry') . '"><i class="rex-icon rex-icon-view"></i></a>';
if ('' === $value) {
$viewButton = '<span class="btn btn-popup" title="' . rex_i18n::msg('yform_relation_no_entry') . '"><i class="rex-icon rex-icon-hide"></i></span>';
}

$e['field'] = '
<input class="form-control yform-dataset-view" type="text" value="' . $valueName . '" id="' . $dataset_view_id . '" readonly="readonly" />
<input type="hidden" class="yform-dataset-real" name="' . $name . '" id="' . $dataset_real_id . '" value="' . $value . '" />';
$e['functionButtons'] = '
<a class="btn btn-popup yform-dataset-widget-open" title="' . rex_i18n::msg('yform_relation_choose_entry') . '"><i class="rex-icon rex-icon-add"></i></a>
<a class="btn btn-popup yform-dataset-widget-delete" title="' . rex_i18n::msg('yform_relation_delete_entry') . '"><i class="rex-icon rex-icon-remove"></i></a>';
<a class="btn btn-popup yform-dataset-widget-open" title="' . rex_i18n::msg('yform_relation_choose_entry') . '"><i class="rex-icon rex-icon-view-list"></i></a>
<a class="btn btn-popup yform-dataset-widget-add" title="' . rex_i18n::msg('yform_relation_add_entry') . '"><i class="rex-icon rex-icon-add"></i></a>
<a class="btn btn-popup yform-dataset-widget-delete" title="' . rex_i18n::msg('yform_relation_delete_entry') . '"><i class="rex-icon rex-icon-remove"></i></a>
' . $viewButton;
$e['before'] = '<div class="yform-dataset-widget"
data-widget_type="single"
data-id="' . $id . '"
data-value_name="' . $valueName . '"
data-value="' . $value . '"
data-link="' . $link . '"
data-csrf_token="' . urlencode($args['_csrf_token']) . '"
data-field_name="' . urlencode($args['fieldName']) . '">';
$e['after'] = '</div>';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
$args['link'] = $link;
$args['fieldName'] = $this->getRelationSourceTableName() . '.' . $this->getName();
$args['valueName'] = $valueName;
$_csrf_key = rex_yform_manager_table::get($this->relation['target_table'])->getCSRFKey();
$args += rex_csrf_token::factory($_csrf_key)->getUrlParams();
$value = implode(',', $this->getValue());
echo \rex_var_yform_table_data::getSingleWidget($id, $name, $value, $args);
} else {
Expand All @@ -81,6 +83,8 @@
$args['fieldName'] = $this->getRelationSourceTableName() . '.' . $this->getName();
$args['size'] = $this->getRelationSize();
$args['attributes'] = $this->getAttributeArray([], ['required', 'readonly']);
$_csrf_key = rex_yform_manager_table::get($this->relation['target_table'])->getCSRFKey();
$args += rex_csrf_token::factory($_csrf_key)->getUrlParams();
$value = implode(',', $this->getValue());
echo \rex_var_yform_table_data::getMultipleWidget($id, $name, $value, $args);
}
Expand Down

0 comments on commit 0a076c2

Please sign in to comment.