Merge the Smartlinks plugin (SmartlinksBundle 0.6.0) into the bundle as the Smart Links domain (0.18.0)
Two domains, one MT3S bundle: Marketing Programs (unchanged) and the
imported Smart Links (smart links + UTM taxonomies), each keeping its
own menu, tables, routes and translations.
- Code moved from MauticPlugin\SmartlinksBundle\ to
MauticPlugin\MT3SMarketingProgramBundle\; template namespace
@Smartlinks/ -> @MT3SMarketingProgram/; smartlinks.js ->
Assets/js/mt3s-mp-smartlinks.js; icon -> Assets/img/smartlinks-icon.svg.
- Incoming migrations renamed Version_0_X_0_SmartLinks.php to avoid
the class-name collision; schema untouched, data intact.
- Permissions folded into MT3SMarketingProgramPermissions:
smart_links + taxonomies under the mt3smarketingprogram: base
(roles that had the old smartlinks: grants must be re-granted).
- config.php: Smart Links routes + menu group, public /l/{slug},
SmartlinksIntegration services, smartlinks_* parameters (legacy
utm_manager_* keys still readable), version 0.18.0. The 0.17.0
placeholder /s/marketing-program-utm-taxonomies is replaced by the
real /s/utm-taxonomies.
- Translations merged (en_US) and added (fr_FR); Tests/ + phpunit moved
in; readme documents both domains and the 0.18.0 merge history.
Verified live: menus, both config tabs, both lists + forms, program
pages, public redirect with taxonomy UTM values, host + unknown-slug
404s, 90/90 unit tests, full php -l, all ini catalogs parse.
This commit is contained in:
1 parent
debce4ba4a
commit
dce849610c
69 files changed
+8225
-43
No files matched your search
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="12" fill="#4e5e9e"/><text x="32" y="41" font-family="Arial,sans-serif" font-size="22" font-weight="bold" fill="#fff" text-anchor="middle">UTM</text></svg>
|
||||
|
After Width: | Height: | Size: 248 B |
@@ -0,0 +1,240 @@
|
||||
/**
|
||||
* UTM Manager
|
||||
*
|
||||
* - Settings > Configuration > UTM Manager tab: delegated handlers only (the configuration
|
||||
* page is loaded through Ajax). Showing / hiding the value editor by mode is done by
|
||||
* Mautic's own data-show-on switcher.
|
||||
* - Smart Link form: short link preview, "Generate" a random slug, destination URL shown
|
||||
* only for external redirects. Started by Mautic.smartlinksSmartLinkOnLoad(), which Mautic
|
||||
* calls after it loads any page whose mauticContent is "smartlinksSmartLink".
|
||||
*/
|
||||
(function ($) {
|
||||
'use strict';
|
||||
|
||||
if (typeof $ === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
var NS = '.smartlinks';
|
||||
|
||||
/**
|
||||
* Rows are renumbered 0..n-1 in DOM order after every change, so the submitted order is the
|
||||
* displayed order (Symfony collections keep the order of their keys).
|
||||
*/
|
||||
var reindexValues = function ($list) {
|
||||
$list.children('.utm-value-row').each(function (index) {
|
||||
$(this).find('input, select, textarea').each(function () {
|
||||
var $input = $(this);
|
||||
var name = $input.attr('name');
|
||||
var id = $input.attr('id');
|
||||
if (name) {
|
||||
$input.attr('name', name.replace(/^(.*\[values\]\[)[^\]]+(\].*)$/, '$1' + index + '$2'));
|
||||
}
|
||||
if (id) {
|
||||
$input.attr('id', id.replace(/^(.*_values_)[^_]+(_.*)$/, '$1' + index + '$2'));
|
||||
}
|
||||
});
|
||||
});
|
||||
refreshEditor($list.closest('.utm-values-editor'));
|
||||
};
|
||||
|
||||
var refreshEditor = function ($editor) {
|
||||
var count = $editor.find('.utm-value-row').length;
|
||||
$editor.find('.utm-values-empty').toggleClass('hide', count > 0);
|
||||
$editor.find('[data-utm-load-suggestions]').toggleClass('hide', count > 0);
|
||||
};
|
||||
|
||||
var getList = function ($editor) {
|
||||
return $editor.find('.utm-values-list').first();
|
||||
};
|
||||
|
||||
var existingValues = function ($editor) {
|
||||
var values = {};
|
||||
$editor.find('.utm-value-input').each(function () {
|
||||
values[$.trim($(this).val())] = true;
|
||||
});
|
||||
|
||||
return values;
|
||||
};
|
||||
|
||||
var addValueRow = function ($editor, value, label) {
|
||||
var $list = getList($editor);
|
||||
var index = $list.children('.utm-value-row').length;
|
||||
var $row = $($list.attr('data-prototype').replace(/__value__/g, index));
|
||||
|
||||
$list.append($row);
|
||||
if (typeof value !== 'undefined') {
|
||||
$row.find('.utm-value-input').val(value);
|
||||
$row.find('.utm-label-input').val(label || value);
|
||||
}
|
||||
reindexValues($list);
|
||||
|
||||
return $row;
|
||||
};
|
||||
|
||||
/**
|
||||
* Appends rows for the given {value, label} items, skipping values already in the list.
|
||||
*/
|
||||
var appendValues = function ($editor, items) {
|
||||
var existing = existingValues($editor);
|
||||
$.each(items, function (i, item) {
|
||||
if (item.value === '' || existing[item.value]) {
|
||||
return;
|
||||
}
|
||||
existing[item.value] = true;
|
||||
addValueRow($editor, item.value, item.label);
|
||||
});
|
||||
};
|
||||
|
||||
var refreshFieldStates = function ($element) {
|
||||
// Re-runs Mautic's data-show-on switcher (bound to the form's change event).
|
||||
$element.closest('form').trigger('change');
|
||||
};
|
||||
|
||||
$(document)
|
||||
.on('click' + NS, '.smartlinks-utm-config [data-utm-add-value]', function () {
|
||||
var $row = addValueRow($(this).closest('.utm-values-editor'));
|
||||
$row.find('.utm-value-input').trigger('focus');
|
||||
})
|
||||
.on('click' + NS, '.smartlinks-utm-config [data-utm-remove-value]', function () {
|
||||
var $list = $(this).closest('.utm-values-list');
|
||||
$(this).closest('.utm-value-row').remove();
|
||||
reindexValues($list);
|
||||
})
|
||||
.on('change' + NS, '.smartlinks-utm-config .utm-value-default', function () {
|
||||
// Only one default value per parameter.
|
||||
if ($(this).is(':checked')) {
|
||||
$(this).closest('.utm-values-list').find('.utm-value-default').not(this).prop('checked', false);
|
||||
}
|
||||
})
|
||||
.on('mouseenter' + NS, '.smartlinks-utm-config .utm-values-list', function () {
|
||||
var $list = $(this);
|
||||
if ($list.data('utmSortable') || typeof $list.sortable !== 'function') {
|
||||
return;
|
||||
}
|
||||
$list.data('utmSortable', true).sortable({
|
||||
items: '> .utm-value-row',
|
||||
handle: '.utm-value-handle',
|
||||
axis: 'y',
|
||||
stop: function () {
|
||||
reindexValues($list);
|
||||
}
|
||||
});
|
||||
})
|
||||
.on('click' + NS, '.smartlinks-utm-config [data-utm-import]', function () {
|
||||
var $editor = $(this).closest('.utm-values-editor');
|
||||
var $text = $editor.find('.utm-import-text');
|
||||
var items = [];
|
||||
|
||||
$.each(($text.val() || '').split(/\r?\n/), function (i, line) {
|
||||
var parts = line.split(';');
|
||||
var value = $.trim(parts.shift());
|
||||
if (value !== '') {
|
||||
items.push({value: value, label: $.trim(parts.join(';')) || value});
|
||||
}
|
||||
});
|
||||
|
||||
appendValues($editor, items);
|
||||
$text.val('');
|
||||
})
|
||||
.on('click' + NS, '.smartlinks-utm-config [data-utm-load-suggestions]', function () {
|
||||
appendValues($(this).closest('.utm-values-editor'), JSON.parse($(this).attr('data-utm-suggestions') || '[]'));
|
||||
})
|
||||
.on('click' + NS, '.smartlinks-utm-config [data-utm-add-parameter]', function () {
|
||||
var $config = $(this).closest('.smartlinks-utm-config');
|
||||
var $container = $config.find('.utm-custom-parameters');
|
||||
var index = parseInt($container.attr('data-index'), 10) || 0;
|
||||
var $panel = $($container.attr('data-prototype').replace(/__param__/g, index));
|
||||
|
||||
$container.attr('data-index', index + 1).append($panel);
|
||||
$config.find('.utm-custom-empty').addClass('hide');
|
||||
refreshFieldStates($container);
|
||||
$panel.find('.utm-custom-key').trigger('focus');
|
||||
})
|
||||
.on('click' + NS, '.smartlinks-utm-config [data-utm-remove-parameter]', function () {
|
||||
var $config = $(this).closest('.smartlinks-utm-config');
|
||||
$(this).closest('[data-utm-parameter]').remove();
|
||||
$config.find('.utm-custom-empty').toggleClass('hide', $config.find('.utm-custom-parameters [data-utm-parameter]').length > 0);
|
||||
})
|
||||
.on('input' + NS, '.smartlinks-utm-config .utm-custom-key', function () {
|
||||
var key = $.trim($(this).val());
|
||||
var $code = $(this).closest('[data-utm-parameter]').find('.utm-parameter-key').first();
|
||||
$code.text(key !== '' ? key : $code.text());
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Smart Link form (menu: Smart Links)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The short link the user is building: https://{short link domain}/l/{slug}. Spaces are
|
||||
* replaced by the configured character, uppercase turned to lowercase, exactly like the
|
||||
* server does on save (SmartLinkModel::applySlugRules).
|
||||
*/
|
||||
Mautic.smartLinkPreview = function ($wrapper) {
|
||||
var $slugInput = $wrapper.find('.smart-link-slug');
|
||||
var domain = $.trim($('#smartLinkDomainReminder').attr('data-domain') || '');
|
||||
var slug = $.trim($slugInput.val() || '');
|
||||
var replacement = $.trim($('#smartLinkDomainReminder').attr('data-separator') || '-');
|
||||
|
||||
slug = slug.replace(/\s+/g, replacement);
|
||||
if (parseInt($('#smartLinkDomainReminder').attr('data-lowercase') || '1', 10)) {
|
||||
slug = slug.toLowerCase();
|
||||
}
|
||||
|
||||
$('#smartLinkPreview').text(domain !== '' && slug !== '' ? domain + '/l/' + slug : '');
|
||||
};
|
||||
|
||||
/**
|
||||
* The destination depends on the redirect type: the URL for external redirects, the
|
||||
* landing page or the standalone form for Mautic ones.
|
||||
*/
|
||||
Mautic.smartLinkToggleDestination = function ($wrapper) {
|
||||
var type = $wrapper.find('.smart-link-redirect-type').val();
|
||||
$('#smartLinkDestinationUrlWrapper').toggleClass('hide', type === 'mautic');
|
||||
$('#smartLinkMauticDestinationWrapper').toggleClass('hide', type !== 'mautic');
|
||||
};
|
||||
|
||||
Mautic.smartlinksSmartLinkOnLoad = function (container) {
|
||||
var $wrapper = $(container).find('.smart-link-slug-group').first();
|
||||
|
||||
if ($wrapper.length) {
|
||||
Mautic.smartLinkPreview($wrapper);
|
||||
// The redirect type lives outside the slug group: scope the toggle to the form.
|
||||
Mautic.smartLinkToggleDestination($wrapper.closest('form'));
|
||||
}
|
||||
};
|
||||
|
||||
$(document)
|
||||
.on('input', '.smart-link-slug', function () {
|
||||
Mautic.smartLinkPreview($(this).closest('.smart-link-slug-group'));
|
||||
})
|
||||
.on('change', '.smart-link-redirect-type', function () {
|
||||
Mautic.smartLinkToggleDestination($(this).closest('form'));
|
||||
})
|
||||
.on('click', '#smartLinkGenerateSlug', function () {
|
||||
var $button = $(this);
|
||||
var generated = $.trim($button.attr('data-generated') || '');
|
||||
var $slugInput = $button.closest('.smart-link-slug-group').find('.smart-link-slug');
|
||||
|
||||
if (generated !== '') {
|
||||
$slugInput.val(generated).trigger('input');
|
||||
// The next click proposes a different slug; the page isn't reloaded between clicks.
|
||||
$button.attr('data-generated', Mautic.smartLinkRandomSlug());
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Random slug of 4 letters and digits for the "Generate" button (client-side fallback; the
|
||||
* server proposes one on each page load and the validator checks uniqueness on submit).
|
||||
*/
|
||||
Mautic.smartLinkRandomSlug = function () {
|
||||
var alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||
var slug = '';
|
||||
for (var i = 0; i < 4; i++) {
|
||||
slug += alphabet.charAt(Math.floor(Math.random() * alphabet.length));
|
||||
}
|
||||
|
||||
return slug;
|
||||
};
|
||||
})(window.mQuery);
|
||||
Reference in new issue
Block a user