Skip to content
Snippets Groups Projects
Commit 4a0ea8dd authored by Jerome Chauveau's avatar Jerome Chauveau
Browse files

first elements of settings form

parent 584b9af6
Branches
No related tags found
No related merge requests found
......@@ -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/';
}
......
<?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);
}
}
<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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment