diff --git a/config/packages/fos_ckeditor.yaml b/config/packages/fos_ckeditor.yaml index 1d2bef5b..048dbf83 100644 --- a/config/packages/fos_ckeditor.yaml +++ b/config/packages/fos_ckeditor.yaml @@ -21,6 +21,7 @@ fos_ck_editor: height: 100 enterMode: 2 toolbar: label_toolbar + extraPlugins: "partdb_label" plugins: bbcode: @@ -32,6 +33,9 @@ fos_ck_editor: specialchar: path: "ckeditor/plugins/specialchar" filename: "plugin.js" + partdb_label: + path: "ckeditor/plugins/partdb_label/" + filename: "plugin.js" toolbars: @@ -44,6 +48,7 @@ fos_ck_editor: - "/" - ['Format', 'FontSize'] - ['Table', 'HorizontalRule'] + - ['Placeholders'] description_toolbar: - [ 'Bold', 'Italic', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] - ["SpecialChar"] diff --git a/public/ckeditor/plugins/partdb_label/icons/hidpi/placeholder.png b/public/ckeditor/plugins/partdb_label/icons/hidpi/placeholder.png new file mode 100644 index 00000000..5289e6da Binary files /dev/null and b/public/ckeditor/plugins/partdb_label/icons/hidpi/placeholder.png differ diff --git a/public/ckeditor/plugins/partdb_label/icons/placeholder.png b/public/ckeditor/plugins/partdb_label/icons/placeholder.png new file mode 100644 index 00000000..5641ad1d Binary files /dev/null and b/public/ckeditor/plugins/partdb_label/icons/placeholder.png differ diff --git a/public/ckeditor/plugins/partdb_label/lang/de.js b/public/ckeditor/plugins/partdb_label/lang/de.js new file mode 100644 index 00000000..27d22bf5 --- /dev/null +++ b/public/ckeditor/plugins/partdb_label/lang/de.js @@ -0,0 +1,50 @@ +/* + * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). + * + * Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +CKEDITOR.plugins.setLang( 'partdb_label', 'de', { + title: 'Platzhalter einfügen', + label: 'Platzhalter', + 'section.global': 'Global', + 'section.part': 'Bauteil', + 'part.id': 'Datenbank ID', + 'part.name': 'Bauteilename', + 'part.category': 'Kategorie', + 'part.category_full': 'Kategorie (Ganzer Pfad)', + 'part.manufacturer': 'Hersteller', + 'part.manufacturer_full': 'Hersteller (Ganzer Pfad)', + 'part.footprint': 'Footprint', + 'part.footprint_full': 'Footprint (Ganzer Pfad)', + 'part.mass': 'Gewicht', + 'part.tags': 'Tags', + 'part.mpn': 'Herstellernummer (MPN)', + 'part.status': 'Herstellungsstatus', + 'part.description': 'Beschreibung', + 'part.description_t': 'Beschreibung (Text)', + 'part.comment': 'Kommentar', + 'part.comment_t': 'Kommentar (Text)', + 'part.last_modified': 'Änderungsdatum', + 'part.creation_date': 'Erstellungsdatum', + 'global.username': 'Benutzername', + 'global.username_full': 'Benutzername (inklusive Name)', + 'global.datetime': 'Datum & Uhrzeit', + 'global.date': 'Datum', + 'global.time': 'Uhrzeit', + 'global.install_name': 'Installationsname', + 'global.type': 'Zieltyp', +} ); \ No newline at end of file diff --git a/public/ckeditor/plugins/partdb_label/lang/en.js b/public/ckeditor/plugins/partdb_label/lang/en.js new file mode 100644 index 00000000..c50bbae9 --- /dev/null +++ b/public/ckeditor/plugins/partdb_label/lang/en.js @@ -0,0 +1,50 @@ +/* + * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). + * + * Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +CKEDITOR.plugins.setLang( 'partdb_label', 'en', { + title: 'Insert Placeholders', + label: 'Placeholders', + 'section.global': 'Globals', + 'section.part': 'Part', + 'part.id': 'Database ID', + 'part.name': 'Part name', + 'part.category': 'Category', + 'part.category_full': 'Category (Full path)', + 'part.manufacturer': 'Manufacturer', + 'part.manufacturer_full': 'Manufacturer (Full path)', + 'part.footprint': 'Footprint', + 'part.footprint_full': 'Footprint (Full path)', + 'part.mass': 'Mass', + 'part.tags': 'Tags', + 'part.mpn': 'Manufacturer Product Number (MPN)', + 'part.status': 'Manufacturing status', + 'part.description': 'Description', + 'part.description_t': 'Description (Text)', + 'part.comment': 'Comment', + 'part.comment_t': 'Comment (Text)', + 'part.last_modified': 'Last modified datetime', + 'part.creation_date': 'Creation datetime', + 'global.username': 'Username', + 'global.username_full': 'Username (including name)', + 'global.datetime': 'Current datetime', + 'global.date': 'Current date', + 'global.time': 'Current time', + 'global.install_name': 'Instance name', + 'global.type': 'Target type', +} ); \ No newline at end of file diff --git a/public/ckeditor/plugins/partdb_label/plugin.js b/public/ckeditor/plugins/partdb_label/plugin.js new file mode 100644 index 00000000..b01b91b2 --- /dev/null +++ b/public/ckeditor/plugins/partdb_label/plugin.js @@ -0,0 +1,115 @@ +/* + * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). + * + * Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +const PLACEHOLDERS = { + part: { + label: 'section.part', + entries: [ + ['%%ID%%', 'part.id'], + ['%%NAME%%', 'part.name'], + ['%%CATEGORY%%', 'part.category'], + ['%%CATEGORY_FULL', 'part.category_full'], + ['%%MANUFACTURER', 'part.manufacturer'], + ['%%MANUFACTURER_FULL', 'part.manufacturer_full'], + ['%%FOOTPRINT%%', 'part.footprint'], + ['%%FOOTPRINT_FULL%%', 'part.footprint'], + ['%%MASS%%', 'part.mass'], + ['%%MPN%%', 'part.mpn'], + ['%%TAGS%%', 'part.tags'], + ['%%M_STATUS%%', 'part.status'], + ['%%DESCRIPTION%%', 'part.description'], + ['%%DESCRIPTION_T%%', 'part.description_t'], + ['%%COMMENT%%', 'part.comment'], + ['%%COMMENT_T%%', 'part.comment_t'], + ['%%LAST_MODIFIED%%', 'part.last_modified'], + ['%%CREATION_DATE%%', 'part.creation_date'], + ] + }, + global: { + label: 'section.global', + entries: [ + ['%%USERNAME%%', 'global.username'], + ['%%USERNAME_FULL%%', 'global.username_full'], + ['%%DATETIME%%', 'global.datetime'], + ['%%DATE%%', 'global.date'], + ['%%TIME%%', 'global.time'], + ['%%INSTALL_NAME%%', 'global.install_name'], + ['%%TYPE%%', 'global.type'] + ], + }, +}; + +function findLabelForPlaceholder(search) +{ + for (var group in PLACEHOLDERS) { + var entries = PLACEHOLDERS[group].entries; + for (var placeholder in entries) { + if (entries[placeholder][0] == search) { + return entries[placeholder][1]; + } + } + } +} + +CKEDITOR.plugins.add('partdb_label', { + hidpi: true, + icons: 'placeholder', + lang: ['en', 'de'], + init: function (editor) { + var config = editor.config, + lang = editor.lang.partdb_label; + + editor.ui.addRichCombo('Placeholders', { + label: lang.label, + title: lang.title, + allowedContent: 'abbr[title]', + panel: { + css: [ CKEDITOR.skin.getPath( 'editor' ) ].concat( config.contentsCss ), + multiSelect: false, + attributes: { 'aria-label': lang.title } + }, + init: function () { + for (var group in PLACEHOLDERS) { + var localized_group = PLACEHOLDERS[group].label; + if (lang[localized_group]) { + localized_group = lang[localized_group]; + } + this.startGroup(localized_group); + var entries = PLACEHOLDERS[group].entries; + for (var placeholder in entries) { + var localized_placeholder = entries[placeholder][1]; + if (lang[localized_placeholder]) { + localized_placeholder = lang[localized_placeholder]; + } + this.add(entries[placeholder][0], localized_placeholder, entries[placeholder][0]) + } + } + }, + onClick: function(value) { + editor.focus(); + editor.fire('saveSnapshot'); + var title = findLabelForPlaceholder(value); + if (lang[title]) { + title = lang[title]; + } + editor.insertHtml('' + value + '' + ' ', 'text'); + } + }); + } +}); \ No newline at end of file diff --git a/src/Form/LabelOptionsType.php b/src/Form/LabelOptionsType.php index dd7a2dc2..d3a052eb 100644 --- a/src/Form/LabelOptionsType.php +++ b/src/Form/LabelOptionsType.php @@ -64,6 +64,7 @@ class LabelOptionsType extends AbstractType $builder->add('lines', CKEditorType::class, [ 'label' => 'label_profile.lines.label', + 'empty_data' => '', 'attr' => [ 'rows' => 4, ],