Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#3525 Give the possibility to choose language of template … #3579

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -651,24 +651,48 @@ function reviewHistory($args, $request) {
* @param $request PKPRequest
* @return JSONMessage JSON object
*/
/**
* @copydoc PKPReviewerGridHandler::fetchTemplateBody()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good to replace duplicated code self-documentation with @copydoc, but this PR leaves the old header in as well. I'd suggest removing the old one.

*/
function fetchTemplateBody($args, $request) {
import('lib.pkp.classes.mail.SubmissionMailTemplate');
$template = new SubmissionMailTemplate($this->getSubmission(), $request->getUserVar('template'));
if (!$template) return;

$user = $request->getUser();
$dispatcher = $request->getDispatcher();
$context = $request->getContext();

$template->assignParams(array(
'editorialContactSignature' => $user->getContactSignature(),
'signatureFullName' => $user->getFullname(),
));

return new JSONMessage(true, $template->getBody());
$templateLocale = $request->getUserVar('templateLocale');
$templateId = $request->getUserVar('template_'.$templateLocale);
if (strlen($templateLocale) < 2 ) {
$templateLocale = NULL;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Extra indent)

import('lib.pkp.classes.mail.SubmissionMailTemplate');
$template = new SubmissionMailTemplate($this->getSubmission(), $templateId, $templateLocale);
if ($template) {
$user = $request->getUser();
$dispatcher = $request->getDispatcher();
$context = $request->getContext();
$template->assignParams(array(
'contextUrl' => $dispatcher->url($request, ROUTE_PAGE, $context->getPath()),
'editorialContactSignature' => $user->getContactSignature(),
'signatureFullName' => $user->getFullname(),
'passwordResetUrl' => $dispatcher->url($request, ROUTE_PAGE, $context->getPath(), 'login', 'lostPassword'),
'messageToReviewer' => __('reviewer.step1.requestBoilerplate'),
'abstractTermIfEnabled' => ($this->getSubmission()->getLocalizedAbstract() == '' ? '' : __('common.abstract')), // Deprecated; for OJS 2.x templates
// submissionReviewUrl -> we can't prepopulate, it depends if oneclick is enabled
));
$template->replaceParams();

return new JSONMessage(
true,
array(
'body' => $template->getBody(),
'variables' => array(
'reviewerName' => __('user.name'),
'responseDueDate' => __('reviewer.submission.responseDueDate'),
'reviewDueDate' => __('reviewer.submission.reviewDueDate'),
'submissionReviewUrl' => __('common.url'),
'reviewerUserName' => __('user.username'),
)
)
);
}
}



//
// Private helper methods
//
Expand Down
16 changes: 16 additions & 0 deletions classes/mail/EmailTemplateDAO.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ function getLocaleEmailTemplate($emailKey, $contextId) {
function getEmailTemplate($emailKey, $locale, $contextId) {
$primaryLocale = AppLocale::getPrimaryLocale();

// $context = $request->getContext();
//
// propose tous les templates si mail settings language est ok
// AIE, visiblement on ne peut retourner un seul mail settings
//
// $permittedSettings = array('supportedFormLocales', 'supportedSubmissionLocales', 'supportedLocales','supportedMailLocales');
// if (in_array($settingName, $permittedSettings) && $locale) {
// $currentSettingValue = (array) $context->getSetting($settingName);
// if (AppLocale::isLocaleValid($locale) && array_key_exists($locale, $availableLocales)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Dead code should be removed)

// if ($settingValue) {
// array_push($currentSettingValue, $locale);
// if ($settingName == 'supportedFormLocales') {
// // reload localized default context settings
//
//

$result = $this->retrieve(
'SELECT COALESCE(edl.subject, ddl.subject, edpl.subject, ddpl.subject) AS subject,
COALESCE(edl.body, ddl.body, edpl.body, ddpl.body) AS body,
Expand Down
9 changes: 9 additions & 0 deletions controllers/grid/languages/LanguageGridCellProvider.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ function getTemplateVarsFromRowColumn($row, $column) {
case 'formLocale';
return array('selected' => $element['supportedFormLocales'],
'disabled' => !$element['supported']);
case 'mailLocale';
return array('selected' => $element['supportedMailLocales'],
'disabled' => !$element['supported']);
default:
assert(false);
break;
Expand Down Expand Up @@ -119,6 +122,12 @@ function getCellActions($request, $row, $column) {
$actionArgs['value'] = !$element['supportedFormLocales'];
$actionRequest = new AjaxAction($router->url($request, null, null, 'saveLanguageSetting', null, $actionArgs));
break;
case 'mailLocale':
$action = 'setMailLocale-' . $row->getId();
$actionArgs['setting'] = 'supportedMailLocales';
$actionArgs['value'] = !$element['supportedMailLocales'];
$actionRequest = new AjaxAction($router->url($request, null, null, 'saveLanguageSetting', null, $actionArgs));
break;
}

if ($action && $actionRequest) {
Expand Down
14 changes: 12 additions & 2 deletions controllers/grid/languages/LanguageGridHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function saveLanguageSetting($args, $request) {
$availableLocales = $this->getGridDataElements($request);
$context = $request->getContext();

$permittedSettings = array('supportedFormLocales', 'supportedSubmissionLocales', 'supportedLocales');
$permittedSettings = array('supportedFormLocales', 'supportedSubmissionLocales', 'supportedLocales','supportedMailLocales');
if (in_array($settingName, $permittedSettings) && $locale) {
$currentSettingValue = (array) $context->getSetting($settingName);
if (AppLocale::isLocaleValid($locale) && array_key_exists($locale, $availableLocales)) {
Expand Down Expand Up @@ -209,6 +209,16 @@ function addManagementColumns() {
$cellProvider
)
);

$this->addColumn(
new GridColumn(
'mailLocale',
'manager.language.mails',
null,
'controllers/grid/common/cell/selectStatusCell.tpl',
$cellProvider
)
);
}

/**
Expand All @@ -223,7 +233,7 @@ function addManagementData($request, $data) {

if (is_array($data)) {
foreach ($data as $locale => $localeData) {
foreach (array('supportedFormLocales', 'supportedSubmissionLocales', 'supportedLocales') as $name) {
foreach (array('supportedFormLocales', 'supportedSubmissionLocales', 'supportedLocales','supportedMailLocales') as $name) {
$data[$locale][$name] = in_array($locale, (array) $context->getSetting($name));
}
}
Expand Down
19 changes: 15 additions & 4 deletions controllers/grid/users/reviewer/form/ReviewerForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,21 @@ function fetch($request) {
}
}

foreach ($templateKeys as $templateKey) {
$template = new SubmissionMailTemplate($submission, $templateKey, null, null, null, false);
$template->assignParams(array());
$templates[$templateKey] = $template->getSubject();

$supportedMailLocales = $context->getSetting('supportedMailLocales');
if (empty($supportedMailLocales)) $supportedMailLocales = array($context->getPrimaryLocale());
$supportedMailLocaleNames = array_flip(array_intersect(
array_flip(AppLocale::getAllLocales()),
$supportedMailLocales ));
$templateMgr->assign('supportedMailLocaleNames',$supportedMailLocaleNames);


foreach (array_keys($supportedMailLocaleNames) as $localeKey) {
foreach ($templateKeys as $templateKey) {
$template = new SubmissionMailTemplate($submission, $templateKey, $localeKey, null, null, false);
$template->assignParams(array());
$templates[$localeKey][$templateKey] = $template->getSubject();
}
}

$templateMgr->assign('templates', $templates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@
// Hide the grid now
$('#searchGridAndButton').hide();
$('#regularReviewerForm').show();

// Change the NAME placeholder in the mail editor
$('[name^="personalMessage"]').val()
.replace('<span class="" data-symbolic="reviewerName" contenteditable="false" data-mce-selected="1">{$reviewerName}</span>', reviewerName);
$("iframe[id^='personalMessage']")
.contents()
.find('[data-symbolic="reviewerName"]')
.each(function() {
$(this).html(reviewerName);
$(this).attr('class', '');
$(this).removeAttr('contenteditable');
});
}
};

Expand Down
66 changes: 57 additions & 9 deletions js/controllers/grid/users/reviewer/form/AddReviewerFormHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,18 @@
this.templateUrl_ = options.templateUrl;
}

// Attach locale select events
$form.find('#templateLocale').change(
this.callbackWrapper(this.selectLocaleHandler_));
// Attach form elements events.
$form.find('#template').change(
$form.find('.template').change(
this.callbackWrapper(this.selectTemplateHandler_));

// Change the NAME placeholder in the mail editor
$('[name="firstName"]').keyup(
this.callbackWrapper(this.addReviewerNameToMailEditor));
$('[name="lastName"]').keyup(
this.callbackWrapper(this.addReviewerNameToMailEditor));
};
$.pkp.classes.Helper.inherits(
$.pkp.controllers.grid.users.reviewer.form.
Expand Down Expand Up @@ -89,10 +98,30 @@
function(sourceElement, event) {

var $form = this.getHtmlElement();
$.post(this.templateUrl_, $form.find('#template').serialize(),
var localeSelected = $('#templateLocale').val();
var templateID = '#template_'+localeSelected;
var data = $form.find(templateID+', #templateLocale').serialize();
$.post(this.templateUrl_, data,
this.callbackWrapper(this.updateTemplate), 'json');
};

/**
* Respond to an "locale change" call by triggering a published event.
*
* @param {HTMLElement} sourceElement The element that
* issued the event.
* @param {Event} event The triggering event.
* @private
*/
$.pkp.controllers.grid.users.reviewer.form.
AddReviewerFormHandler.prototype.selectLocaleHandler_ =
function(sourceElement, event) {
var localeSelected = sourceElement.value;
$('.template').hide();
$('#template_'+localeSelected).removeClass("pkp_helpers_display_none").show();
this.selectTemplateHandler_(sourceElement, event);
};


/**
* Internal callback to replace the textarea with the contents of the
Expand All @@ -108,17 +137,36 @@

var $form = this.getHtmlElement(),
processedJsonData = this.handleJson(jsonData),
jsonDataContent = (jsonData.content),
$textarea = $form.find('textarea[name="personalMessage"]'),
editor =
tinyMCE.EditorManager.get(/** @type {string} */ ($textarea.attr('id')));
editor = tinyMCE.EditorManager.get($textarea.attr('id'));

if (processedJsonData !== false) {
if (processedJsonData.content !== '') {
editor.setContent(processedJsonData.content);
}
}
$textarea.attr('data-variables', JSON.stringify(jsonDataContent.variables));
editor.setContent(jsonDataContent.body);
this.addReviewerNameToMailEditor();
return processedJsonData.status;
};


/**
* Add reviewerName to Email template editor
* @protected
*/
$.pkp.controllers.grid.users.reviewer.form.AddReviewerFormHandler.
prototype.addReviewerNameToMailEditor = function() {
var reviewerName = $('[id^="selectedReviewerName"]').html();
$('[name^="personalMessage"]').val()
.replace('<span class="" data-symbolic="reviewerName" contenteditable="false" data-mce-selected="1">{$reviewerName}</span>', reviewerName);

$("iframe[id^='personalMessage']")
.contents()
.find('[data-symbolic="reviewerName"]')
.each(function() {
$(this).html(reviewerName);
$(this).attr('class', '');
$(this).removeAttr('contenteditable');
});
};

/** @param {jQuery} $ jQuery closure. */
}(jQuery));
1 change: 1 addition & 0 deletions locale/en_US/common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@

<!-- Stage Participants -->
<message key="stageParticipants.history.messageSent">Notification sent to users.</message>
<message key="stageParticipants.notify.chooseLocale">Select language for predefined message.</message>
<message key="stageParticipants.notify.chooseMessage">Choose a predefined message to use, or fill out the form below.</message>
<message key="stageParticipants.notify.message">Message</message>
<message key="stageParticipants.notify.warning">Please ensure that you have filled out the message field and selected at least one recipient.</message>
Expand Down
1 change: 1 addition & 0 deletions locale/en_US/manager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<message key="manager.language.ui">UI</message>
<message key="manager.language.submissions">Submissions</message>
<message key="manager.language.forms">Forms</message>
<message key="manager.language.mails">Mails</message>
<message key="manager.language.reloadLocalizedDefaultSettings">Reload defaults</message>
<message key="manager.languages.alternateLocaleInstructions">This system optionally allows certain critical information to be entered in several additional languages. To use this feature, select alternate locales and choose from the options listed below.</message>
<message key="manager.languages.supportedLocalesInstructions">Select all locales to support on the site via a language select menu to appear on each page. The menu will only appear if more than one locale is selected.</message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,40 @@
*
*}
<div id="reviewerFormFooter" class="reviewerFormFooterContainer">
<!-- message template choice -->
{if $templates|@count == 1}
{foreach from=$templates item=template key=templateKey}
<input type="hidden" name="template" value="{$templateKey|escape}"/>
<!-- message locale template choice -->

{if $supportedMailLocaleNames|@count == 1}
{foreach from=$supportedMailLocaleNames item=localeName key=localeKey}
<input type="hidden" name="templateLocale" value="{$localeKey|escape}" id="templateLocale" />
{/foreach}
{else}
{fbvFormSection title="stageParticipants.notify.chooseMessage" for="template" size=$fbvStyles.size.medium}
{fbvElement type="select" from=$templates translate=false id="template"}
{fbvFormSection title="stageParticipants.notify.chooseLocale" for="templatelocale" size=$fbvStyles.size.medium}
{fbvElement type="select" from=$supportedMailLocaleNames translate=false id="templateLocale"}
{/fbvFormSection}
{/if}

<!-- message template choice -->


{*{if $localizedTemplates|@count == 1}
{foreach from=$localizedTemplates item=template key=templateKey}
<input type="hidden" name="template" value="{$templateKey|escape}"/>
{/foreach}
{else}*}

{fbvFormSection title="stageParticipants.notify.chooseMessage" for="template" size=$fbvStyles.size.medium}
{foreach from=$templates item=localizedTemplates key=localeKey name=foo}
{if $smarty.foreach.foo.first}
{fbvElement type="select" from=$localizedTemplates translate=false id="template_$localeKey" class="template"}
{else}
{fbvElement type="select" from=$localizedTemplates translate=false id="template_$localeKey" class="template pkp_helpers_display_none"}
{/if}
{/foreach}
{/fbvFormSection}

{*{/if}*}



<!-- Message to reviewer textarea -->
{fbvFormSection title="editor.review.personalMessageToReviewer" for="personalMessage"}
Expand Down