diff --git a/action.php b/action.php
index ae1a2e1..2d7f5cb 100644
--- a/action.php
+++ b/action.php
@@ -24,6 +24,28 @@
*/
class action_plugin_dw2pdf extends ActionPlugin
{
+ /**
+ * action_plugin_dw2pdf constructor.
+ */
+ public function __construct()
+ {
+ global $JSINFO;
+
+ $this->loadConfig();
+
+ $JSINFO['plugins']['dw2pdf']['showexporttemplate'] = $this->getConf('showexporttemplate');
+
+ if ($this->getConf('showexporttemplate')) {
+ $templates = [$this->getConf('template')];
+ $dir = scandir(DOKU_PLUGIN . 'dw2pdf' . DIRECTORY_SEPARATOR . 'tpl');
+ foreach ($dir as $value) {
+ if (is_dir(DOKU_PLUGIN . 'dw2pdf' . DIRECTORY_SEPARATOR . 'tpl' . DIRECTORY_SEPARATOR . $value) && !in_array($value, array(".", "..", $this->getConf('template')))) {
+ $templates[] = $value;
+ }
+ }
+ $JSINFO['plugins']['dw2pdf']['templates'] = json_encode($templates);
+ }
+ }
/**
* Register the events
*
diff --git a/conf/default.php b/conf/default.php
index df4ff74..7c0c183 100644
--- a/conf/default.php
+++ b/conf/default.php
@@ -15,3 +15,4 @@
$conf['usestyles'] = 'wrap,';
$conf['qrcodescale'] = '1';
$conf['showexportbutton'] = 1;
+$conf['showexporttemplate'] = 0;
diff --git a/conf/metadata.php b/conf/metadata.php
index ec08ae1..97a43cc 100644
--- a/conf/metadata.php
+++ b/conf/metadata.php
@@ -15,3 +15,4 @@
$meta['usestyles'] = array('string');
$meta['qrcodescale'] = array('string', '_pattern' => '/^(|\d+(\.\d+)?)$/');
$meta['showexportbutton'] = array('onoff');
+$meta['showexporttemplate'] = array('onoff');
diff --git a/lang/en/lang.php b/lang/en/lang.php
index 1e15541..a288745 100644
--- a/lang/en/lang.php
+++ b/lang/en/lang.php
@@ -10,3 +10,7 @@
$lang['forbidden'] = "You have no read access to the selected pages.";
$lang['exportfailed'] = "The PDF could not be created.";
$lang['missingbookcreator'] = 'The Bookcreator Plugin is not installed or is disabled';
+$lang['js']['export_pdf_modal'] = "Export to PDF";
+$lang['js']['template'] = 'Which template should be used for formatting the PDFs?';
+$lang['js']['cancel'] = 'Cancel';
+$lang['js']['export'] = 'Export';
diff --git a/lang/en/settings.php b/lang/en/settings.php
index 56538f6..e4007e9 100644
--- a/lang/en/settings.php
+++ b/lang/en/settings.php
@@ -25,3 +25,4 @@
$lang['usestyles'] = 'You can give a comma separated list of plugins of which the style.css or screen.css should be used for PDF generation. By default only print.css and pdf.css are used.';
$lang['qrcodescale'] = 'Size scaling of the embedded QR code. Empty or 0 to disable.';
$lang['showexportbutton'] = 'Show PDF export button (only when supported by your template)';
+$lang['showexporttemplate'] = 'Show PDF export template selection';
diff --git a/lang/pt-br/lang.php b/lang/pt-br/lang.php
index e33af05..04892e5 100644
--- a/lang/pt-br/lang.php
+++ b/lang/pt-br/lang.php
@@ -14,3 +14,7 @@
$lang['tocheader'] = 'Índice';
$lang['export_ns'] = 'Exportar domínio "%s:" para o arquivo %s.pdf';
$lang['missingbookcreator'] = 'O plugin Bookcreator não está instalado ou está desativado';
+$lang['js']['export_pdf_modal'] = 'Exportar para PDF';
+$lang['js']['template'] = 'Qual modelo deve ser usado para formatar os PDFs?';
+$lang['js']['cancel'] = 'Cancelar';
+$lang['js']['export'] = 'Exportar';
diff --git a/lang/pt-br/settings.php b/lang/pt-br/settings.php
index 204f63e..d444c8c 100644
--- a/lang/pt-br/settings.php
+++ b/lang/pt-br/settings.php
@@ -25,3 +25,4 @@
$lang['usestyles'] = 'Você pode gerar uma lista de plugins separadas por vírgula nos quais style.css ou screen.css devem ser usadas para a gerar um PDF.';
$lang['qrcodescale'] = 'Escala de tamanho do código QR incorporado. Vazio ou 0 para desativar.';
$lang['showexportbutton'] = 'Mostrar botão de exportação de PDF (se suportado pelo modelo)';
+$lang['showexporttemplate'] = 'Mostrar seleção de template de exportação de PDF';
diff --git a/script.js b/script.js
new file mode 100644
index 0000000..ba793b4
--- /dev/null
+++ b/script.js
@@ -0,0 +1,9 @@
+/**
+ * includes all needed JavaScript for the dw2pdf plugin
+ *
+ * be sure to touch this file when one of the scripts has been updated to refresh caching
+ */
+
+jQuery(function() {
+ /* DOKUWIKI:include script/template.js */
+});
diff --git a/script/template.js b/script/template.js
new file mode 100644
index 0000000..40bdcd2
--- /dev/null
+++ b/script/template.js
@@ -0,0 +1,107 @@
+/**
+ * Template dialog for end users
+ *
+ * @author Eduardo Mozart de Oliveira
+ */
+(function () {
+ if (!JSINFO || !JSINFO.plugins.dw2pdf.showexporttemplate) return;
+
+
+ // basic dialog template
+ let $dialogSelect = '';
+
+ const $dialog = jQuery(
+ '
' +
+ '' +
+ '
'
+ );
+
+ /**
+ * Executes the renaming based on the form contents
+ * @return {boolean}
+ */
+ const templateFN = function () {
+ window.location.href = jQuery('#dokuwiki__pagetools .action.export_pdf a').attr("href") + "&tpl=" + $dialog.find('select').find(':selected').text();
+
+ return true;
+ };
+
+ /**
+ * Create the actual dialog modal and show it
+ */
+ const showDialog = function () {
+ $dialog.dialog({
+ title: LANG.plugins.dw2pdf.export_pdf_modal + ' ' + JSINFO.id,
+ width: 800,
+ height: 200,
+ dialogClass: 'plugin_dw2pdf_dialog',
+ modal: true,
+ buttons: [
+ {
+ text: LANG.plugins.dw2pdf.cancel,
+ click: function () {
+ $dialog.dialog("close");
+ }
+ },
+ {
+ text: LANG.plugins.dw2pdf.export,
+ click: templateFN
+ }
+ ],
+ // remove HTML from DOM again
+ close: function () {
+ jQuery(this).remove();
+ }
+ });
+ };
+
+ /**
+ * Bind an event handler as the first handler
+ *
+ * @param {jQuery} $owner
+ * @param {string} event
+ * @param {function} handler
+ * @link https://stackoverflow.com/a/4700103
+ */
+ const bindFirst = function ($owner, event, handler) {
+ $owner.unbind(event, handler);
+ $owner.bind(event, handler);
+
+ const events = jQuery._data($owner[0])['events'][event];
+ events.unshift(events.pop());
+
+ jQuery._data($owner[0])['events'][event] = events;
+ };
+
+
+ // attach handler to menu item
+ jQuery('#dokuwiki__pagetools .action.export_pdf a')
+ .show()
+ .click(function (e) {
+ e.preventDefault();
+ showDialog();
+ });
+
+ // attach handler to mobile menu entry
+ const $mobileMenuOption = jQuery('form select[name=do] option[value=export_pdf]');
+ if ($mobileMenuOption.length === 1) {
+ bindFirst($mobileMenuOption.closest('select[name=do]'), 'change', function (e) {
+ const $select = jQuery(this);
+ if ($select.val() !== 'export_pdf') return;
+ e.preventDefault();
+ e.stopPropagation();
+ e.stopImmediatePropagation();
+ $select.val('');
+ showDialog();
+ });
+ }
+
+})();