Skip to content
Code-Schnipsel Gruppen Projekte
Commit a91de11b erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

Merge branch 'next' into 'main'

Next

See merge request !10
Übergeordnete 8e67e139 981d464c
No related branches found
No related tags found
3 Merge Requests!31Update 'next-3.x' with latest changes from 'main',!26fix: use script text/plain method to insert snippets,!10Next
Pipeline #5462 bestanden mit Phase
in 34 Sekunden
werden angezeigt mit 504 Ergänzungen und 17 Löschungen
<?php
use QUI\HtmlSnippets\Snippets;
QUI::$Ajax->registerFunction(
'package_quiqqer_html-snippets_ajax_backend_activateSnippet',
function ($projectName, $snippetName) {
$Project = QUI::getProject($projectName);
$Snippet = Snippets::get($Project, $snippetName);
$Snippet->activate();
},
['projectName', 'snippetName'],
'Permission::checkAdminUser'
);
<?php
use QUI\HtmlSnippets\Snippets;
QUI::$Ajax->registerFunction(
'package_quiqqer_html-snippets_ajax_backend_deactivateSnippet',
function ($projectName, $snippetName) {
$Project = QUI::getProject($projectName);
$Snippet = Snippets::get($Project, $snippetName);
$Snippet->deactivate();
},
['projectName', 'snippetName'],
'Permission::checkAdminUser'
);
......@@ -11,11 +11,12 @@ define('package/quiqqer/html-snippets/bin/backend/Snippets', [
'qui/controls/Control',
'qui/controls/loader/Loader',
'package/quiqqer/html-snippets/bin/backend/Utils',
'qui/controls/buttons/Switch',
'controls/grid/Grid',
'Ajax',
'Locale'
], function(QUI, QUIControl, QUILoader, SnippetUtils, Grid, QUIAjax, QUILocale) {
], function(QUI, QUIControl, QUILoader, SnippetUtils, QUISwitch, Grid, QUIAjax, QUILocale) {
'use strict';
const lg = 'quiqqer/html-snippets';
......@@ -30,7 +31,8 @@ define('package/quiqqer/html-snippets/bin/backend/Snippets', [
'edit',
'remove',
'refresh',
'$onImport'
'$onImport',
'$onStatusChange'
],
initialize: function(options) {
......@@ -70,6 +72,11 @@ define('package/quiqqer/html-snippets/bin/backend/Snippets', [
const columnModel = [
{
header: QUILocale.get(lg, 'grid.status'),
dataIndex: 'status',
dataType: 'QUI',
width: 80
}, {
header: QUILocale.get(lg, 'grid.name'),
dataIndex: 'name',
dataType: 'string',
......@@ -93,7 +100,7 @@ define('package/quiqqer/html-snippets/bin/backend/Snippets', [
this.$Grid = new Grid(Container, {
height: Label.getParent('.qui-panel-content').getSize().y - 100,
multiple: true,
multipleSelection: true,
columnModel: columnModel,
buttons: [
{
......@@ -146,6 +153,15 @@ define('package/quiqqer/html-snippets/bin/backend/Snippets', [
this.Loader.show();
QUIAjax.get('package_quiqqer_html-snippets_ajax_backend_getSnippets', (result) => {
for (let i = 0, len = result.length; i < len; i++) {
result[i].status = new QUISwitch({
status: result[i].active,
events: {
change: this.$onStatusChange
}
});
}
this.$Grid.setData({
data: result
});
......@@ -246,6 +262,30 @@ define('package/quiqqer/html-snippets/bin/backend/Snippets', [
}
}).open();
});
},
$onStatusChange: function(Switch) {
const status = Switch.getStatus();
const Row = Switch.getElm().getParent('.tr');
const rowData = this.$Grid.getDataByRow(Row.get('data-row'));
const snippetName = rowData.name;
const project = rowData.project;
this.Loader.show();
if (status) {
SnippetUtils.activateSnippet(snippetName, project).then(() => {
this.refresh();
}).catch(() => {
this.refresh();
});
} else {
SnippetUtils.deactivateSnippet(snippetName, project).then(() => {
this.refresh();
}).catch(() => {
this.refresh();
});
}
}
});
});
......@@ -15,9 +15,30 @@ define('package/quiqqer/html-snippets/bin/backend/Utils', function() {
});
},
getGDPRList: function() {
}
activateSnippet: function(snippetName, project) {
return new Promise(function(resolve, reject) {
require(['Ajax'], function(QUIAjax) {
QUIAjax.post('package_quiqqer_html-snippets_ajax_backend_activateSnippet', resolve, {
'package': 'quiqqer/html-snippets',
projectName: project,
snippetName: snippetName,
onError: reject
});
});
});
},
deactivateSnippet: function(snippetName, project) {
return new Promise(function(resolve, reject) {
require(['Ajax'], function(QUIAjax) {
QUIAjax.post('package_quiqqer_html-snippets_ajax_backend_deactivateSnippet', resolve, {
'package': 'quiqqer/html-snippets',
projectName: project,
snippetName: snippetName,
onError: reject
});
});
});
}
};
});
.html-snippet-eventSelect {
position: relative;
}
.html-snippet-eventSelect input {
width: calc(100% - 50px);
}
.html-snippet-eventSelect-drop {
border-radius: 3px;
cursor: pointer;
line-height: 36px;
height: 36px;
position: absolute;
right: 2px;
text-align: center;
top: 2px;
width: 40px;
}
.html-snippet-eventSelect-drop:hover {
background: #2f8fc6;
color: #fff;
}
define('package/quiqqer/html-snippets/bin/backend/controls/EventSelect', [
'qui/QUI',
'qui/controls/Control',
'qui/controls/contextmenu/Menu',
'qui/controls/contextmenu/Item',
'Locale',
'css!package/quiqqer/html-snippets/bin/backend/controls/EventSelect.css'
], function(QUI, QUIControl, QUIMenu, QUIMenuItem, QUILocale) {
'use strict';
const lg = 'quiqqer/html-snippets';
return new Class({
Extends: QUIControl,
Type: 'package/quiqqer/html-snippets/bin/backend/controls/EventSelect',
Binds: [
'$openMenu',
'$menuItemMouseDown',
'$keyup'
],
initialize: function(options) {
this.parent(options);
this.$Menu = null;
this.addEvents({
onImport: this.$onImport
});
},
$onImport: function() {
this.$Input = this.$Elm;
this.$Input.autocomplete = 'off';
this.$Input.addEvents({
keyup: this.$keyup,
blur: () => {
if (this.$Menu) {
this.$Menu.hide();
}
}
});
this.$Elm = new Element('div', {
'class': 'field-container-field html-snippet-eventSelect'
}).wraps(this.$Input);
new Element('span', {
'class': 'html-snippet-eventSelect-drop fa fa-chevron-down',
events: {
click: this.$openMenu
}
}).inject(this.getElm());
this.$Menu = new QUIMenu({
showIcons: false,
styles: {
width: this.$Elm.getSize().x
},
events: {
onMouseDown: function() {
}
}
}).inject(this.$Elm);
this.$Menu.appendChild(
new QUIMenuItem({
text: QUILocale.get(lg, 'html.snippet.select.template.event.headerBegin'),
value: 'onQuiqqer::template::header::begin',
events: {
onMouseDown: this.$menuItemMouseDown
}
})
);
this.$Menu.appendChild(
new QUIMenuItem({
text: QUILocale.get(lg, 'html.snippet.select.template.event.headerEnd'),
value: 'onQuiqqer::template::header::end',
events: {
onMouseDown: this.$menuItemMouseDown
}
})
);
this.$Menu.appendChild(
new QUIMenuItem({
text: QUILocale.get(lg, 'html.snippet.select.template.event.bodyBegin'),
value: 'onQuiqqer::template::body::begin',
events: {
onMouseDown: this.$menuItemMouseDown
}
})
);
this.$Menu.appendChild(
new QUIMenuItem({
text: QUILocale.get(lg, 'html.snippet.select.template.event.bodyEnd'),
value: 'onQuiqqer::template::body::end',
events: {
onMouseDown: this.$menuItemMouseDown
}
})
);
},
$openMenu: function() {
this.$Menu.setPosition(-10, 50);
this.$Menu.show();
},
$keyup: function(e) {
if (e.key === 'down' && this.$Menu.isHidden()) {
this.$openMenu();
return;
}
if (e.key === 'down') {
this.$Menu.down();
return;
}
if (e.key === 'up' && !this.$Menu.isHidden()) {
this.$Menu.up();
return;
}
if (e.key === 'enter' && !this.$Menu.isHidden()) {
this.$Input.value = this.$Menu.getActive().getAttribute('value');
this.$Menu.hide();
}
},
$menuItemMouseDown: function(Instance) {
this.$Input.value = Instance.getAttribute('value');
}
});
});
\ No newline at end of file
.quiqqer-html-snippet-input {
background: #f6f8fb;
padding: 10px;
}
.quiqqer-html-snippet-input textarea {
border: 1px solid #DEDEDE !important;
min-height: 200px;
position: relative;
width: 100%;
}
.quiqqer-html-snippet-input select {
margin-bottom: 10px;
.quiqqer-html-snippet-input > label {
float: left;
margin: 10px 0 5px;
width: 100% !important;
}
.quiqqer-html-snippet-input > label > span:first-child {
display: inline-block;
font-weight: bold;
padding-bottom: 5px;
padding-left: 3px;
width: 100%;
}
.quiqqer-html-snippet-input [name="gdpr"] {
background: #fff;
width: 100%;
}
\ No newline at end of file
}
.quiqqer-html-snippet-input-title {
border-bottom: 1px solid #0420451a;
width: 100%;
display: inline-block;
line-height: 2rem;
padding-bottom: 1rem;
position: relative;
}
.quiqqer-html-snippet-input-title > span {
font-size: 1.5rem;
}
.quiqqer-html-snippet-input-status {
position: absolute;
right: 3px;
top: 3px;
}
.quiqqer-html-snippet-input-status > span {
font-size: 12px;
margin-right: 10px;
}
......@@ -7,15 +7,18 @@ define('package/quiqqer/html-snippets/bin/backend/controls/SnippetInput', [
'qui/QUI',
'qui/controls/Control',
'qui/controls/loader/Loader',
'qui/controls/buttons/Switch',
'package/quiqqer/html-snippets/bin/backend/Utils',
'Ajax',
'Locale',
'css!package/quiqqer/html-snippets/bin/backend/controls/SnippetInput.css'
], function(QUI, QUIControl, QUILoader, SnippetUtils, QUIAjax, QUILocale) {
], function(QUI, QUIControl, QUILoader, QUISwitch, SnippetUtils, QUIAjax, QUILocale) {
'use strict';
const lg = 'quiqqer/html-snippets';
return new Class({
Extends: QUIControl,
......@@ -24,6 +27,7 @@ define('package/quiqqer/html-snippets/bin/backend/controls/SnippetInput', [
Binds: [
'$onImport',
'$onChange',
'$onStatusChange',
'$load'
],
......@@ -35,6 +39,8 @@ define('package/quiqqer/html-snippets/bin/backend/controls/SnippetInput', [
this.$loaded = false;
this.$data = null;
this.$Status = null;
this.$StatusText = null;
this.$Project = null;
this.$GDPR = null;
......@@ -50,19 +56,31 @@ define('package/quiqqer/html-snippets/bin/backend/controls/SnippetInput', [
$onImport: function() {
this.$Textarea = this.getElm();
this.$Textarea.placeholder = '<html-snippet-code>code</html-snippet-code>';
this.setAttribute('snippetName', this.$Textarea.get('data-qui-options-snippet'));
this.setAttribute('snippetEvent', this.$Textarea.get('data-qui-options-event'));
const TextAreaLabel = new Element('label').wraps(this.$Textarea);
new Element('span', {
html: 'Code'
}).inject(TextAreaLabel, 'top');
this.$Elm = new Element('div', {
'class': 'field-container-field quiqqer-html-snippet-input'
}).wraps(this.$Textarea);
}).wraps(TextAreaLabel);
this.Loader.inject(this.$Elm);
this.Loader.show();
SnippetUtils.isGDPRInstalled().then((isInstalled) => {
if (isInstalled) {
const GDPRLabel = new Element('label', {
html: '<span>' + QUILocale.get(lg, 'html.snippet.gdpr.title') + '</span>'
}).inject(this.$Elm, 'top');
this.$GDPR = new Element('select', {
name: 'gdpr',
html: '' +
......@@ -82,19 +100,52 @@ define('package/quiqqer/html-snippets/bin/backend/controls/SnippetInput', [
events: {
change: this.$onChange
}
}).inject(this.$Elm, 'top');
}).inject(GDPRLabel);
if (this.$data) {
this.$GDPR.value = this.$data.gdpr;
}
}
const Title = new Element('div', {
'class': 'quiqqer-html-snippet-input-title',
html: '<span>' + QUILocale.get(lg, 'html.snippet.title') + '</span>'
}).inject(this.$Elm, 'top');
this.$StatusContainer = new Element('div', {
'class': 'quiqqer-html-snippet-input-status'
}).inject(Title);
this.$StatusText = new Element('span', {
styles: {
'float': 'left'
}
}).inject(this.$StatusContainer);
this.$Status = new QUISwitch({
events: {
onChange: this.$onStatusChange
}
}).inject(this.$StatusContainer);
return this.$load();
}).then(() => {
this.$Textarea.addEvents({
change: this.$onChange,
blur: this.$onChange
});
if (this.$data && this.$data.active) {
this.$Status.setSilentOn();
this.$StatusText.set('html', QUILocale.get(lg, 'html.snippet.active'));
}
if (this.$data && !this.$data.active) {
this.$Status.setSilentOff();
this.$StatusText.set('html', QUILocale.get(lg, 'html.snippet.deactive'));
}
});
},
......@@ -140,6 +191,16 @@ define('package/quiqqer/html-snippets/bin/backend/controls/SnippetInput', [
this.$GDPR.value = snippetData.gdpr;
}
if (this.$Status) {
if (this.$data.active) {
this.$Status.setSilentOn();
this.$StatusText.set('html', QUILocale.get(lg, 'html.snippet.active'));
} else {
this.$Status.setSilentOff();
this.$StatusText.set('html', QUILocale.get(lg, 'html.snippet.deactive'));
}
}
this.Loader.hide();
resolve();
}, {
......@@ -170,6 +231,34 @@ define('package/quiqqer/html-snippets/bin/backend/controls/SnippetInput', [
}
});
});
},
$onStatusChange: function() {
const status = this.$Status.getStatus();
const project = this.$Project.getName();
const snippetName = this.getAttribute('snippetName');
this.Loader.show();
if (status) {
SnippetUtils.activateSnippet(snippetName, project).then(() => {
this.Loader.hide();
this.$StatusText.set('html', QUILocale.get(lg, 'html.snippet.active'));
}).catch((err) => {
QUI.getMessageHandler().then((MH) => {
MH.addError(err.getMessage());
});
});
} else {
SnippetUtils.deactivateSnippet(snippetName, project).then(() => {
this.Loader.hide();
this.$StatusText.set('html', QUILocale.get(lg, 'html.snippet.deactive'));
}).catch((err) => {
QUI.getMessageHandler().then((MH) => {
MH.addError(err.getMessage());
});
});
}
}
});
});
......@@ -27,7 +27,13 @@
<td>
<label class="field-container">
<span class="field-container-item">{{textEvent}}</span>
<input class="field-container-field" type="text" name="eventName" required/>
<input
data-qui="package/quiqqer/html-snippets/bin/backend/controls/EventSelect"
class="field-container-field"
type="text"
name="eventName"
required
/>
</label>
</td>
</tr>
......
......@@ -46,6 +46,7 @@ define('package/quiqqer/html-snippets/bin/backend/controls/windows/AddSnippet',
},
$onOpen: function() {
this.Loader.show();
this.getContent().addClass('html-snippets-add');
this.getContent().set('html', Mustache.render(template, {
......@@ -70,6 +71,10 @@ define('package/quiqqer/html-snippets/bin/backend/controls/windows/AddSnippet',
});
this.getContent().getElement('form').elements.name.focus();
QUI.parse(this.getContent()).then(() => {
this.Loader.hide();
});
},
submit: function() {
......
......@@ -27,7 +27,12 @@
<td>
<label class="field-container">
<span class="field-container-item">{{textEvent}}</span>
<input class="field-container-field" type="text" name="eventName" required/>
<input data-qui="package/quiqqer/html-snippets/bin/backend/controls/EventSelect"
class="field-container-field"
type="text"
name="eventName"
required
/>
</label>
</td>
</tr>
......
......@@ -80,7 +80,10 @@ define('package/quiqqer/html-snippets/bin/backend/controls/windows/EditSnippet',
Form.elements.eventName.value = result.event;
Form.elements.snippet.value = result.snippet;
Form.elements.gdpr.value = result.gdpr;
this.Loader.hide();
QUI.parse(this.getContent()).then(() => {
this.Loader.hide();
});
}, {
'package': 'quiqqer/html-snippets',
projectName: this.getAttribute('Project').getName(),
......
......@@ -2,6 +2,7 @@
<database>
<global>
<table name="html_snippets">
<field type="INT(1) DEFAULT 0">active</field>
<field type="VARCHAR(255)">name</field>
<field type="VARCHAR(64)">project</field>
<field type="VARCHAR(255)">event</field>
......@@ -10,6 +11,7 @@
<primary>name,project</primary>
<index>event</index>
<index>active</index>
<comment>This table contains the html snippets for the different projects.</comment>
</table>
</global>
......
......@@ -34,6 +34,10 @@
<de><![CDATA[GDPR Kategorie]]></de>
<en><![CDATA[GDPR Category]]></en>
</locale>
<locale name="grid.status">
<de><![CDATA[Status]]></de>
<en><![CDATA[Status]]></en>
</locale>
</groups>
<groups name="quiqqer/html-snippets" datatype="js">
......@@ -62,6 +66,42 @@
<en><![CDATA[GDPR Category]]></en>
</locale>
<locale name="html.snippet.title">
<de><![CDATA[HTML-Snippet]]></de>
<en><![CDATA[HTML-Snippet]]></en>
</locale>
<locale name="html.snippet.gdpr.title">
<de><![CDATA[GDPR Kategorie]]></de>
<en><![CDATA[GDPR category]]></en>
</locale>
<locale name="html.snippet.active">
<de><![CDATA[HTML-Snippet ist aktiviert]]></de>
<en><![CDATA[HTML snippet is activated]]></en>
</locale>
<locale name="html.snippet.deactive">
<de><![CDATA[HTML-Snippet ist deaktiviert]]></de>
<en><![CDATA[HTML snippet is edactivated]]></en>
</locale>
<locale name="html.snippet.select.template.event.headerBegin">
<de><![CDATA[<b>Header ganz oben</b> (onQuiqqer::template::header::begin)]]></de>
<en><![CDATA[<b>Header ganz oben</b> (onQuiqqer::template::header::begin)]]></en>
</locale>
<locale name="html.snippet.select.template.event.headerEnd">
<de><![CDATA[<b>Header ganz unten</b> (onQuiqqer::template::header::end)]]></de>
<en><![CDATA[<b>Header ganz unten</b> (onQuiqqer::template::header::end)]]></en>
</locale>
<locale name="html.snippet.select.template.event.bodyBegin">
<de><![CDATA[<b>Body ganz oben</b> (onQuiqqer::template::body::begin)]]></de>
<en><![CDATA[<b>Body ganz oben</b> (onQuiqqer::template::body::begin)]]></en>
</locale>
<locale name="html.snippet.select.template.event.bodyEnd">
<de><![CDATA[<b>Body ganz unten</b> (onQuiqqer::template::body::end)]]></de>
<en><![CDATA[<b>Body ganz unten</b> (onQuiqqer::template::body::end)]]></en>
</locale>
<locale name="window.remove.title">
<de><![CDATA[Snippet löschen]]></de>
<en><![CDATA[Delete snippet]]></en>
......
......@@ -9,7 +9,7 @@
<locale group="quiqqer/html-snippets" var="package.description"/>
</description>
<image src="URL_OPT_DIR/quiqqer/html-snippets/bin/images/Logo.jpg"/>
<image src="URL_OPT_DIR/quiqqer/html-snippets/bin/images/Logo.png"/>
<preview>
<image src="URL_OPT_DIR/quiqqer/html-snippets/bin/images/preview/preview-01.png"/>
......
......@@ -4,6 +4,7 @@ namespace QUI\HtmlSnippets;
use QUI;
use QUI\Interfaces\Users\User;
use QUI\Permissions\Exception;
use QUI\Projects\Project;
class Snippet
......@@ -12,6 +13,7 @@ class Snippet
protected Project $Project;
protected string $snippet;
protected string $event;
protected bool $active = false;
protected string $gdprCategory = '';
/**
......@@ -27,6 +29,7 @@ class Snippet
$this->snippet = $data['snippet'];
$this->event = $data['event'];
$this->gdprCategory = !empty($data['gdpr']) ? $data['gdpr'] : '';
$this->active = !empty($data['active']);
}
//region get
......@@ -75,10 +78,16 @@ class Snippet
'event' => $this->event,
'Project' => $this->Project->getName(),
'snippet' => $this->getSnippet(),
'gdpr' => $this->gdprCategory
'gdpr' => $this->gdprCategory,
'active' => $this->active ? 1 : 0
];
}
public function isActive(): bool
{
return $this->active;
}
//endregion
//region set
......@@ -110,6 +119,26 @@ class Snippet
$this->gdprCategory = $gdprCategory;
}
/**
* @throws Exception
* @throws QUI\Database\Exception
*/
public function activate(User $User = null): void
{
$this->active = true;
$this->save($User);
}
/**
* @throws Exception
* @throws QUI\Database\Exception
*/
public function deactivate(User $User = null): void
{
$this->active = false;
$this->save($User);
}
/**
* Saves the snippet to the database.
*
......@@ -129,6 +158,7 @@ class Snippet
QUI::getDatabase()->update(
Snippets::table(),
[
'active' => $this->active ? 1 : 0,
'event' => $this->event,
'snippet' => $this->snippet,
'gdpr' => $this->gdprCategory
......
......@@ -56,6 +56,10 @@ class SnippetTemplateEvent
}
foreach ($this->snippets as $snippet) {
if (empty($snippet['active'])) {
continue;
}
$gdprIsInstalled = QUI::getPackageManager()->isInstalled('quiqqer/gdpr');
if (empty($snippet['gdpr']) || !$gdprIsInstalled) {
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren