From a39f816422ee396278b11783d9c7e2086cf14703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Wed, 15 Apr 2020 18:20:28 +0200 Subject: [PATCH] Added an CKEditor plugin for easy placeholder selection. --- config/packages/fos_ckeditor.yaml | 5 + .../partdb_label/icons/hidpi/placeholder.png | Bin 0 -> 2041 bytes .../partdb_label/icons/placeholder.png | Bin 0 -> 1781 bytes .../ckeditor/plugins/partdb_label/lang/de.js | 50 ++++++++ .../ckeditor/plugins/partdb_label/lang/en.js | 50 ++++++++ .../ckeditor/plugins/partdb_label/plugin.js | 115 ++++++++++++++++++ src/Form/LabelOptionsType.php | 1 + 7 files changed, 221 insertions(+) create mode 100644 public/ckeditor/plugins/partdb_label/icons/hidpi/placeholder.png create mode 100644 public/ckeditor/plugins/partdb_label/icons/placeholder.png create mode 100644 public/ckeditor/plugins/partdb_label/lang/de.js create mode 100644 public/ckeditor/plugins/partdb_label/lang/en.js create mode 100644 public/ckeditor/plugins/partdb_label/plugin.js 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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 z>Hak?*LFm@cyC#+&BD_mVTi4nIXl>1^u z4Xa7(@_odMb1*Jxw4>BCWlgwTW+xBg4*9LIXmn$EX|>Ea>_yrpX0dEk-a)_WH$O0Qt1hxRC@afj+0KTu`q!PzwcqLMR30~yn-|r3 z*+1QX`Y!FtJpb4crWI#;mYi5aQqDzZZus`#=Juem6vsM#dA6Z%_B2!AMEfT(iF>Vk ztk-1ia4wueikr8-L7(HAW4dVQ6}9zPRf;D@&mcRRcx^qI#sadfaL3a6K~?}yKU!v3VE$wCdEwkcA@S+|0y4h^9{>OV literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..5641ad1d4f9ffe37a74d028068103f5e93cdfd82 GIT binary patch literal 1781 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4(FKV3ElTi71Ki^|4CM&(%vz$xlkv ztH>-n*TA>HIW;5GqpB!1xXLdi zxhgx^GDXSWj?1RP3TQxXYDuC(MQ%=Bu~mhw64+cTAR8pCucQE0Qj%?}6yY17;GAES zs$i;Ts%M~N$E9FXl#*r@k>g7FXt#Bv$C=6)S^`fSBQuTAW;zSx}OhpQivaGchT@w8U0P2`H}sH9WN<6JdH@ zG1U9OfY1lY=o{)8=p!pH$xOqc93+FG92g34r=u8NkywCDv9B+F<+-^it|=~YEd%-o z8a7xhC=RJCNYxKYEzU13N=|hxOU)}$273tPJ*$AsiqxD4m(1MMykcM=*(w>Dp-Dz! zN`ic9<(Zq9o*JH+Qj!7Jgb?>h%}Ym@068J26ciPqd6_^*8-XnX>xn?f*(#YE0TTfz zg1}OdSfzl$YUP`sl9^WNl30=oG|RxqK-a)T*U&V?(Adhr*vimY+rY@m0AdhWH89bo zB$gx+QV&Wx3N}C;zP?r-nZ+gfMU`M7NO}rRErjqO+?-5sLQ+rw$AeX3GRSwfN(Dvv zDW%D&DPUg!jf2P*=ckpFCl;kTrURqER>?6fEfW|Hl?nl+NjaIt8L34IhI;0DhNzm# zGg5&D;`W|C)N%Tt)D3f;jXs9^ZNLhUvI9^bL=2eCfcaG)o?(F;c$QDi1LpH0V1^cv zUgXTcz}S@O>>N-WFR7|XlZ7qYouq$z@Ra)bmD$*r$CY8_OlX~BnC7)H@BFE zPHDVyX~7rnRgS#Bw!Szm-)JxQUQ=|bzgfh9+mQpd8kXN#tFU9Z&A znE1Tt{NFq8ZJ!ss-JK`c^gOd96oP`~R{^>&ZkExQoWl<@I;T$e90K zNWJWK{t$*umd z`s7Kj`q^t-og6o8&{?-ZtTW+x$t1HL{Y&&KsK89!%XfZN7EOME;B3re~`e*7;iOUzNEr zcE=5-?~A3bE=pbLxy*E8!}j2e=$1a|jM#Nw)>NH4$?RhGWc9kleEBNXds{zob4*F! zZS-~D6JXKIS>O>_%)r1c48n{Iv*t(u1wVSaIEGmCF1@r{uO(1~^}+e24$F%&S4`F8 zR}|`X$~YoDp^`<{c5C~Ez6u7e!kIIAI$RbmaWq;yBlpwuKkfH7OqyGKF7Ef5z28nQ z>?z$+(ALQl->GILXdQaAdFGws#QLA&>|0;_`{3K`#oin7Iz#-^;t1bv_JXEpnVA#xcfsk7G7%6`cOu=+5-raz*_+q+f@%N&5>sM|Aw1 r@h<<)an^eqMT*Un=j?j7`^yJTWyYu^g_QFrLA8~qtDnm{r-UW|z)Xla literal 0 HcmV?d00001 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, ],