Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom_url-Feld #60

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 214 additions & 0 deletions assets/customlink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
let mform_custom_url = '.rex-js-widget-customurl';

$(document).on('rex:ready', function (e, container) {
if (container.find(mform_custom_url).length) {
container.find(mform_custom_url).each(function () {
customurl_init_widget($(this).find('.input-group.custom-url'));
});
}
});

function customurl_init_widget(element) {
let id = 'cl' + randId(),
clang = element.data('clang'),
media_types = element.data('types'),
media_Category = element.data('media_category'),
extern_url_prefix = (element.data('extern-url-prefix') === undefined) ? 'https://' : element.data('extern-url-prefix'),
url_category = element.data('category'),
hidden_input = element.find('input[type=hidden]'),
showed_input = element.find('input[type=text]'),
value, text, args, timer;

element.data('id', id)
element.find('ul.dropdown-menu').attr('id', 'mform_yurl_' + id);

// yurl
element.find('.input-group-btn a.yurl').unbind().bind('click', function() {
let id = element.data('id'),
table = $(this).data('table'),
column = $(this).data('column'),
pool = newPoolWindow('index.php?page=yform/manager/data_edit&table_name=' + table + '&rex_yform_manager_opener[id]=1&rex_yform_manager_opener[field]=' + column + '&rex_yform_manager_opener[multiple]=0');

clearInterval(timer);
closeDropDown(id);

$(pool).on('rex:YForm_selectData', function (event, id, label) {
event.preventDefault();
pool.close();

value = hidden_input.val();
text = showed_input.val();

let urlUrl = table.split('_').join('-') + '://' + id;

hidden_input.val(urlUrl);
showed_input.val(label);
});

return false;
});

// media element
element.find('a.media_url').unbind().bind('click', function () {
let id = element.data('id'),
value = hidden_input.val(),
args = '';

clearInterval(timer);
closeDropDown(id);

if (media_types !== undefined) {
args = '&args[types]=' + media_types;
}
if (media_Category !== undefined) {
args = args + '&rex_file_category=' + media_Category;
}

hidden_input.attr('id', 'REX_MEDIA_' + id);

openREXMedia(id, args); // &args[preview]=1&args[types]=jpg%2Cpng

timer = setInterval(function () {
if (!$('#REX_MEDIA_' + id).length) {
clearInterval(timer);
} else {
if (value != hidden_input.val()) {
clearInterval(timer);
showed_input.val(hidden_input.val());
}
}
}, 10);

return false;
});

// url element
element.find('a.intern_url').unbind().bind('click', function () {
let id = element.data('id'),
url_id = randInt(),
args = '&clang=' + clang;

clearInterval(timer);
closeDropDown(id);

if (url_category !== undefined) {
args = args + '&category_id=' + url_category;
}

showed_input.attr('id', 'REX_URL_' + url_id + '_NAME');
hidden_input.attr('id', 'REX_URL_' + url_id);

openUrlMap('REX_URL_' + url_id, args);

return false;
});

// extern url
element.find('a.external_url').unbind().bind('click', function () {
let id = element.data('id'),
value = hidden_input.val(),
text = showed_input.val();

clearInterval(timer);
closeDropDown(id);

if (value == '' || value.indexOf(extern_url_prefix) < 0) {
value = extern_url_prefix;
}

let extern_url = prompt('Url', value);

hidden_input.attr('id', 'REX_URL_' + id).addClass('form-control').attr('readonly', true);

if (extern_url !== 'https://' && extern_url !== "" && extern_url !== undefined && extern_url != null) {
hidden_input.val(extern_url);
showed_input.val(extern_url);
}
if (extern_url == null) {
hidden_input.val(value);
showed_input.val(text);
}
return false;
});

// mail to url
element.find('a.email_url').unbind().bind('click', function () {
let id = element.data('id'),
value = hidden_input.val(),
text = showed_input.val();

clearInterval(timer);
closeDropDown(id);

if (value == '' || value.indexOf("mailto:") < 0) {
value = 'mailto:';
}

hidden_input.attr('id', 'REX_URL_' + id).addClass('form-control').attr('readonly', true);

let mailto_url = prompt('Mail', value);

if (mailto_url !== 'mailto:' && mailto_url !== "" && mailto_url !== undefined && mailto_url != null) {
showed_input.val(mailto_url);
hidden_input.val(mailto_url);
}
if (mailto_url == null) {
hidden_input.val(value);
showed_input.val(text);
}
return false;
});

// phone url
element.find('a.phone_url').unbind().bind('click', function () {
let id = element.data('id'),
value = hidden_input.val(),
text = showed_input.val();

clearInterval(timer);
closeDropDown(id);

if (value == '' || value.indexOf("tel:") < 0) {
value = 'tel:';
}

hidden_input.attr('id', 'REX_URL_' + id).addClass('form-control').attr('readonly', true);

let tel_url = prompt('Telephone', value);

if (tel_url !== 'tel:' && tel_url !== "" && tel_url !== undefined && tel_url != null) {
showed_input.val(tel_url);
hidden_input.val(tel_url);
}
if (tel_url == null) {
hidden_input.val(value);
showed_input.val(text);
}
return false;
});

// delete url
element.find('a.delete_url').unbind().bind('click', function () {
let id = element.data('id');
clearInterval(timer);
closeDropDown(id);
showed_input.val('');
hidden_input.val('');
return false;
});
}

function randId() {
return Math.random().toString(16).slice(2);
}

function randInt() {
return parseInt((Math.random() * 1000000000000) + (Math.random()*1000000000000/Math.random()));
}

function closeDropDown(id) {
let dropdown = $('ul#mform_yurl_' + id);
if (dropdown.is(':visible')) {
dropdown.dropdown('toggle');
}
}
12 changes: 12 additions & 0 deletions lang/de_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ yform_values_tabs_active_notice = 'Aktiv' hat Vorrang vor 'Dynamisch'. Bei mehre
yform_values_tabs_active_options = Der erste Tab der Gruppe wid aktiviert=1,Dieser Tab wird aktiviert=2
yform_values_tabs_setup_prio_error = {0}: Überscheidung mit Tab-Gruppe «{1}» bei Feld «{2} [{3}]»!


yform_values_custom_url_description = Stellt ein Link-Widget für mehrere Link-Typen bereit. Medien-, externe, interne und E-Mail-Links
yform_values_custom_url_media = Schaltfläche für Medienpool-Datei
yform_values_custom_url_media_types = Medien-Typen (komma-getrennt)
yform_values_custom_url_media_category = Medien-Kategorie (ID)
yform_values_custom_url_external = Schaltfläche für externen Link
yform_values_custom_url_mailto = Schaltfläche für E-Mail-Link
yform_values_custom_url_intern = Schaltfläche für internen Link
yform_values_custom_url_link_category = Link-Kategorie
yform_values_custom_url_phone = Schaltfläche für Telefon-Link
yform_values_custom_url_ylink = YForm-Link-Widget (label_text::yform_tabelle::anzeige_column,label_text2::yform_tabelle_2::anzeige_column_2)

# YForm E-Mail-Templates Test
yform_email_list_send_preview = Vorschau an Test-Adresse senden
yform_email_list_send_preview_success = Die Vorschau des E-Mail-Templates "%s" wurde an <b>%s</b> verschickt.
Expand Down
55 changes: 55 additions & 0 deletions lib/yform/value/custom_link.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Author: Joachim Doerr
* Date: 2019-02-26
* Time: 10:27.
*/

class rex_yform_value_custom_url extends rex_yform_value_abstract
{
public function enterObject()
{
static $counter = 0;
++$counter;

if ($this->needsOutput()) {
$this->params['form_output'][$this->getId()] = $this->parse('value.custom_url.tpl.php', compact('counter'));
}

$this->params['value_pool']['email'][$this->getName()] = $this->getValue();
$this->params['value_pool']['sql'][$this->getName()] = $this->getValue();
}

public function getDefinitions(): array
{
return [
'type' => 'value',
'name' => 'custom_url',
'values' => [
'name' => ['type' => 'name', 'label' => rex_i18n::msg('yform_values_defaults_name')],
'label' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_defaults_label')],
'media' => ['type' => 'checkbox', 'label' => rex_i18n::msg('yform_values_custom_url_media')],
'external' => ['type' => 'checkbox', 'label' => rex_i18n::msg('yform_values_custom_url_external')],
'mailto' => ['type' => 'checkbox', 'label' => rex_i18n::msg('yform_values_custom_url_mailto')],
'intern' => ['type' => 'checkbox', 'label' => rex_i18n::msg('yform_values_custom_url_intern')],
'phone' => ['type' => 'checkbox', 'label' => rex_i18n::msg('yform_values_custom_url_phone')],
'types' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_custom_url_media_types')],
'media_category' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_custom_url_media_category')],
'category' => ['type' => 'be_url', 'label' => rex_i18n::msg('yform_values_custom_url_url_category')],
'yurl' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_custom_url_yurl')],
'notice' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_defaults_notice')],
],
'description' => rex_i18n::msg('yform_values_custom_url_description'),
'formbuilder' => false,
'db_type' => ['text'],
];
}

public static function getListValue($params)
{
if ('' == $params['value']) {
return '-';
}
return rex_var_custom_url::getCustomUrlText($params['value']);
}
}
2 changes: 1 addition & 1 deletion pages/yform_field.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<?php
$anchor = '<a target="_blank" href="https://donate.alexplus.de/?addon=yform_field"><img src="' . rex_url::addonAssets('yform_field', 'jetzt-beauftragen.svg') . '" style="width: 100% max-width: 400px;"></a>';

$fragment = new rex_fragment();
$fragment = new rex_fragment();
$fragment->setVar('class', 'info', false);
$fragment->setVar('title', $this->i18n('yform_field_donate'), false);
$fragment->setVar('body', '<p>' . $this->i18n('yform_field_info_donate') . '</p>' . $anchor, false);
Expand Down
43 changes: 43 additions & 0 deletions ytemplates/bootstrap/value.custom_link.tpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

$buttonId = $counter;
$categoryId = 0;
$name = $this->getFieldName();
$value = htmlspecialchars($this->getValue());
$parameters = [
'media' => (1 == $this->getElement('media')),
'mailto' => (1 == $this->getElement('mailto')),
'external' => (1 == $this->getElement('external')),
'intern' => (1 == $this->getElement('intern')),
'phone' => (1 == $this->getElement('phone')),
'types' => $this->getElement('types'),
'category' => $this->getElement('category'),
'media_category' => $this->getElement('media_category'),
'yurl' => $this->getElement('yurl'),
];

$widget = rex_var_custom_url::getWidget($buttonId, $name, $value, $parameters);

$class_group = trim('form-group ' . $this->getHTMLClass() . ' ' . $this->getWarningClass());

$notice = [];
if ('' != $this->getElement('notice')) {
$notice[] = rex_i18n::translate($this->getElement('notice'), false);
}
if (isset($this->params['warning_messages'][$this->getId()]) && !$this->params['hide_field_warning_messages']) {
$notice[] = '<span class="text-warning">' . rex_i18n::translate($this->params['warning_messages'][$this->getId()], false) . '</span>'; // var_dump();
}
if (count($notice) > 0) {
$notice = '<p class="help-block">' . implode('<br />', $notice) . '</p>';
} else {
$notice = '';
}

?>
<div class="<?= $class_group ?>"
id="<?= $this->getHTMLId() ?>">
<label class="control-label"
for="<?= $this->getFieldId() ?>"><?= $this->getLabel() ?></label>
<?= $widget ?>
<?= $notice ?>
</div>
Loading