Newer
Older
<?php
/**
* Copyright (c) 2012-2019, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Intonation_View_RenderReviewForm extends ZendAfi_View_Helper_BaseHelper {
public function renderReviewForm($review, $ajax = false) {
if (!$record = $review->getFirstNotice())
return '';
$params =
['controller' => 'abonne',
'action' => $ajax ? 'ajax-review' : 'review',
'record_id' => $record->getId(),
'record_key' => $record->getClefOeuvre(),
'id' => $review->getId()];
$form = ZendAfi_Form_Review::newWith($review->toArray());
$form->setAction($this->view->url($params, null, true));
$form = $ajax
? $this->_ajaxMode($form)
: $this->_standardMode($form);
return $this->view->renderForm($form);
}
protected function _ajaxMode($form) {
$form->addElement('submit',
'submit' . $form->getAttrib('id'),
['label' => $this->_('Valider'),
'onclick' => 'return confirm(\'Confirmer votre avis ?\');']);
Class_ScriptLoader::getInstance()
->addJQueryReady(
sprintf('
$("#%s").submit(function(e) {
e.preventDefault();
e.stopPropagation();
var form = $(this);
var url = form.attr("action");
$.ajax(
{type: "POST",
url: url,
data: form.serialize(),
success: function(data) {
var li = form.closest(".list-group-item");
li.find(".card").addClass("bg-success");
li.slideUp(1000);
}});
});', $form->getAttrib('id')));
return $form;
}
protected function _standardMode($form) {
$form
->addElement('submit',
'review_submit',
['label' => $this->_('Valider'),
'title' => $this->_('Valider mon avis.'),
'onclick' => sprintf("if (confirm('%s')) { %s }; return false;",
$this->_escapeJsAttrib($this->_('Confirmer votre avis ?')),
'$(this).parents(\'form\').submit()')]);
$form->addToDisplayGroup(['review_submit'], 'review');
return $form;