Implémentation fonctionnalité 'Explanation of the choice'

This commit is contained in:
Meteor-Furet 2018-05-26 18:40:00 +02:00 committed by Thomas Citharel
parent c2672f1ca2
commit 7a26f330d8
6 changed files with 122 additions and 5 deletions

View file

@ -91,7 +91,7 @@ if ($messagePollCreated) {
if (isset($_POST['update_poll_info'])) {
$updated = false;
$field = $inputService->filterAllowedValues($_POST['update_poll_info'], ['title', 'admin_mail', 'description',
'rules', 'expiration_date', 'name', 'hidden', 'removePassword', 'password']);
'rules', 'expiration_date', 'name', 'hidden', 'removePassword', 'password', 'explanation']);
// Update the right poll field
if ($field === 'title') {
@ -111,7 +111,13 @@ if (isset($_POST['update_poll_info'])) {
if ($description) {
$poll->description = $description;
$updated = true;
}
}
} elseif ($field === 'explanation') {
$explanation = $inputService->filterDescription($_POST['explanation']);
if ($explanation) {
$poll->admin_choice_exp = $explanation;
$updated = true;
}
} elseif ($field === 'rules') {
$rules = strip_tags($_POST['rules']);
switch ($rules) {
@ -531,8 +537,6 @@ $votes = $pollService->allVotesByPollId($poll_id);
$comments = $pollService->allCommentsByPollId($poll_id);
// Assign data to template
var_dump($poll);
var_dump($pollService->splitSlots($slots));
$smarty->assign('poll_id', $poll_id);
$smarty->assign('admin_poll_id', $admin_poll_id);
$smarty->assign('poll', $poll);

View file

@ -0,0 +1,70 @@
<?php
/**
* This software is governed by the CeCILL-B license. If a copy of this license
* is not distributed with this file, you can obtain one at
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
*
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
* Authors of Framadate/OpenSondage: Framasoft (https://github.com/framasoft)
*
* =============================
*
* Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
* ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
*
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/
namespace Framadate\Migration;
use Framadate\Utils;
/**
* This migration adds the field Value_Max on the poll table.
*
* @package Framadate\Migration
* @version 0.9
*/
class AddColumn_admin_choice_exp_In_poll implements Migration {
function __construct() {
}
/**
* This method should describe in english what is the purpose of the migration class.
*
* @return string The description of the migration class
*/
function description() {
return 'Add column "Admin choice explanation" in table "poll" ';
}
/**
* This method could check if the execute method should be called.
* It is called before the execute method.
*
* @param \PDO $pdo The connection to database
* @return bool true is the Migration should be executed.
*/
function preCondition(\PDO $pdo) {
return true;
}
/**
* This method is called only one time in the migration page.
*
* @param \PDO $pdo The connection to database
* @return bool true is the execution succeeded
*/
function execute(\PDO $pdo) {
$this->alterPollTable($pdo);
return true;
}
private function alterPollTable(\PDO $pdo) {
$pdo->exec('
ALTER TABLE `' . Utils::table('poll') . '`
ADD `admin_choice_exp` VARCHAR(250) DEFAULT "";');
}
}

View file

@ -106,6 +106,7 @@ class PollRepository extends AbstractRepository {
'results_publicly_visible' => $poll->results_publicly_visible ? 1 : 0,
'closed' => $poll->closed ? 1 : 0,
'admin_choice' => $poll->admin_choice ? $poll->admin_choice : NULL,
'admin_choice_exp' => $poll->admin_choice_exp ? $poll->admin_choice_exp : "",
], [
'id' => $poll->id
]) > 0;

View file

@ -189,6 +189,28 @@ $(document).ready(function() {
return false;
});
$('#explanation-form .btn-edit').on('click', function() {
$('#explanation-form .well').hide();
$('#explanation-form .control-label .btn-edit').hide();
$('#explanation-form .js-exp').removeClass('hidden');
$('.js-exp textarea').focus();
if (firstOpening) {
firstOpening = false;
if ($('#rich-editor-button').hasClass('active')) {
wrapper.enable();
}
}
return false;
});
$('#explanation-form .btn-cancel').on('click', function() {
$('#explanation-form .well').show();
$('#explanation-form .control-label .btn-edit').show();
$('#explanation-form .js-exp').addClass('hidden');
$('.js-exp .btn-edit').focus();
return false;
});
$('#poll-rules-form .btn-edit').on('click', function() {
$('#poll-rules-form p').hide();
$('#poll-rules-form .js-poll-rules').removeClass('hidden');

View file

@ -223,7 +223,8 @@
"seconds": "seconds",
"vote": "vote",
"votes": "votes",
"with": "with"
"with": "with",
"Explanation of the choice" : "Explanation of the choice",
},
"Homepage": {
"Make a standard poll": "Make a standard poll",
@ -352,6 +353,9 @@
"The poll is still opened": "The poll is still opened",
"The poll is closed": "The poll is closed",
"Close the poll": "Close the poll",
"Edit the explanation": "Edit the explanation",
"Save the explanation": "Save the explanation",
"Cancel the explanation edit": "Cancel the explanation edit",
},
"Step 1": {
"All voters can modify any vote": "All voters can modify any vote",

View file

@ -280,7 +280,9 @@
{/if}
<p class="">{$closed_icon} {$closed_txt|html} </p>
</div>
</div>
</div>
<div class="row">
{if $poll->closed}
<div class="col-md-4 ">
<div id="admin-choice">
@ -301,6 +303,20 @@
{/if}
</div>
</div>
{if strcmp($poll->admin_choice,"")!=0}
<div class="form-group col-md-8" id="explanation-form">
<label class="control-label">{__('Generic', 'Explanation of the choice')}{if $admin && !$expired} <button class="btn btn-link btn-sm btn-edit" title="{__('PollInfo', 'Edit the explanation')}"><span class="glyphicon glyphicon-pencil"></span><span class="sr-only">{__('Generic', 'Edit')}</span></button>{/if}</label>
<div class="form-control-static well poll-explanation">{$poll->admin_choice_exp|markdown:false:false}</div>
{if $admin && !$expired}
<div class="hidden js-exp">
<label class="sr-only" for="newexplanation">{__('Generic', 'Explanation of the choice')}</label>
<textarea class="form-control" id="newexplanation" name="explanation" rows="2" cols="40">{$poll->admin_choice_exp|html}</textarea>
<button type="submit" id="btn-new-exp" name="update_poll_info" value="explanation" class="btn btn-sm btn-success" title="{__('PollInfo', 'Save the explanation')}"><span class="glyphicon glyphicon-ok"></span><span class="sr-only">{__('Generic', 'Save')}</span></button>
<button class="btn btn-default btn-sm btn-cancel" title="{__('PollInfo', 'Cancel the explanation edit')}"><span class="glyphicon glyphicon-remove"></span><span class="sr-only">{__('Generic', 'Cancel')}</span></button>
</div>
{/if}
</div>
{/if}
{/if}
</div>
{if $admin && !$poll->closed}