diff --git a/XML2HTMLPlugin.php b/XML2HTMLPlugin.php index eb09f4288de1392078b822d36afefe5405d9293f..70324520a7056efee7b8b5a32604be9301e59bdc 100644 --- a/XML2HTMLPlugin.php +++ b/XML2HTMLPlugin.php @@ -119,6 +119,54 @@ class XML2HTMLPlugin extends GenericPlugin return 'This plugin transform XML articles to HTML'; } + /** + * @param $request + * @param $verb + * @return mixed + */ + public function getActions($request, $verb) { + $router = $request->getRouter(); + import('lib.pkp.classes.linkAction.request.AjaxModal'); + return array_merge( + $this->getEnabled()?array( + new LinkAction( + 'settings', + new AjaxModal( + $router->url($request, null, null, 'manage', null, array('verb' => 'settings', 'plugin' => $this->getName(), 'category' => 'generic')), + $this->getDisplayName() + ), + __('manager.plugins.settings'), + null + ), + ):array(), + parent::getActions($request, $verb) + ); + } + + + public function manage($args, $request) { + switch ($request->getUserVar('verb')) { + case 'settings': + AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON, LOCALE_COMPONENT_PKP_MANAGER); + $this->import('XML2HTMLSettingsForm'); + $form = new XML2HTMLSettingsForm($this, $request->getContext()->getId()); + + if ($request->getUserVar('save')) { + $form->readInputData(); + if ($form->validate()) { + $form->execute(); + $notificationManager = new NotificationManager(); + $notificationManager->createTrivialNotification($request->getUser()->getId()); + return new JSONMessage(true); + } + } else { + $form->initData(); + } + return new JSONMessage(true, $form->fetch($request)); + } + return parent::manage($args, $request); + } + function getPluginAssetsPath($request) { return $request->getBaseUrl() . '/' . $this->getPluginPath() . '/resources/'; } diff --git a/XML2HTMLSettingsForm.inc.php b/XML2HTMLSettingsForm.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..de1f5101e8894de141a15921edc7e51460aabd43 --- /dev/null +++ b/XML2HTMLSettingsForm.inc.php @@ -0,0 +1,73 @@ +<?php + + +import('lib.pkp.classes.form.Form'); + +class XML2HTMLSettingsForm extends Form { + + private static $FORMAT_SETTING = "format"; + private $_contextId; + + private $_plugin; + + /** + * Constructor + * @param $plugin xml2html plugin + * @param $contextId int Context ID + */ + function __construct($plugin, $contextId) { + $this->_contextId = $contextId; + $this->_plugin = $plugin; + + parent::__construct($plugin->getTemplateResource('settingsForm.tpl')); + $this->addCheck(new FormValidatorPost($this)); + $this->addCheck(new FormValidatorCSRF($this)); + } + + /** + * Initialize form data. + */ + function initData() { + $contextId = $this->_contextId; + $plugin = $this->_plugin; + $this->setData('format', $plugin->getSetting($contextId, XML2HTMLSettingsForm::$FORMAT)); + + } + + /** + * Assign form data to user-submitted data. + */ + function readInputData() { + $this->readUserVars(array(XML2HTMLSettingsForm::$FORMAT)); + +// +// // if recent items is selected, check that we have a value +// if ($this->getData('displayItems') == 'recent') { +// $this->addCheck(new FormValidator($this, 'recentItems', 'required', 'plugins.generic.webfeed.settings.recentItemsRequired')); +// } + + } + + /** + * Fetch the form. + * @copydoc Form::fetch() + */ + function fetch($request, $template = null, $display = false) { + $templateMgr = TemplateManager::getManager($request); + $templateMgr->assign('pluginName', $this->_plugin->getName()); + return parent::fetch($request); + } + + /** + * @copydoc Form::execute() + */ + function execute(...$functionArgs) { + $plugin = $this->_plugin; + $contextId = $this->_contextId; + + $plugin->updateSetting($contextId, XML2HTMLSettingsForm::$FORMAT, $this->getData(XML2HTMLSettingsForm::$FORMAT)); + + + parent::execute(...$functionArgs); + } +} diff --git a/templates/settingsForm.tpl b/templates/settingsForm.tpl new file mode 100644 index 0000000000000000000000000000000000000000..875ae0d4a3beab686ad0c93574990fd26254e721 --- /dev/null +++ b/templates/settingsForm.tpl @@ -0,0 +1,13 @@ + +<script> + $(function() {ldelim} + // Attach the form handler. + $('#xml2htmlSettingsForm').pkpHandler('$.pkp.controllers.form.AjaxFormHandler'); + {rdelim}); +</script> + +<form class="pkp_form" id="xml2htmlSettingsForm" method="post" action="{url router=$smarty.const.ROUTE_COMPONENT op="manage" category="generic" plugin=$pluginName verb="settings" save=true}"> + <div id="xml2htmlSettings"> + TEST + </div> +</form>