Commit aba4dd0e authored by Chenu Denis's avatar Chenu Denis
Browse files

[feature] Add a button to launch on browse responses

parent 7745407b
......@@ -68,9 +68,8 @@ class StartUrl
if (!$this->surveyId) {
return false;
}
$oSurvey = \Survey::model()->findByPk($this->surveyId);
if ($oSurvey->active != "Y") {
return false;
if (!Utilities::SurveyIsValid($this->surveyId)) {
return;
}
if ($this->token && $this->getSetting('allowTokenUser')) {
$this->available = true;
......@@ -80,7 +79,6 @@ class StartUrl
$this->available = true;
return $this->available;
}
if (Permission::model()->hasSurveyPermission($this->surveyId, 'responses', 'update') && $this->getSetting('allowAdminUser')) {
$this->available = true;
return $this->available;
......
......@@ -66,6 +66,9 @@ class Utilities
*/
public static function loadReponse($surveyid, $srid, $token = null, $accesscode = null)
{
if (!self::SurveyIsValid($surveyid)) {
return;
}
if (self::getCurrentSrid($surveyid) == $srid && self::getCurrentToken($surveyid) == $token) {
$oStarurl = new StartUrl($surveyid, $token);
if ($oStarurl->isAvailable()) {
......@@ -386,6 +389,23 @@ class Utilities
return false;
}
/**
* Check minimal possibility to allow reload
* Without set the osUsrvey (allow to update after
* @param integer $surveyId
* @return boolean
*/
public static function SurveyIsValid($surveyId)
{
$now = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", Yii::app()->getConfig("timeadjust"));
return Survey::model()->count(
array(
'condition' => "sid = :sid AND COALESCE(expires, '$now') >= '$now' AND COALESCE(startdate, '$now') <= '$now' AND active ='Y'",
'params'=>array(':sid' => $surveyId)
)
);
}
/**
* Check if need to throw exception,
* return if not
......
$(document).ajaxComplete(function() {
if($('#responses-grid table').data('reloadAnyResponse') == 'done') {
return;
}
$('#responses-grid table tbody').find('tr').each(function( index, element) {
var pencil = $(element).find('.button-column').find('a .fa-pencil');
if($(pencil).length) {
var srid = $(element).find('input').eq(0).val();
var newLink = $('<a/>', {
'class': 'btn btn-default btn-xs',
'href': LS.reloadAnyResponse.baseUrl + srid,
'target': '_blank',
'title': LS.reloadAnyResponse.lang.launch,
'data-toggle': 'tooltip'
}).html('<i class="fa fa-pencil-square-o text-success" aria-hidden="true"></i>');
$(pencil).closest("a").after(newLink);
}
});
$('#responses-grid table').data('reloadAnyResponse','done');
});
......@@ -64,9 +64,19 @@ class reloadAnyResponse extends PluginBase
'uncheckValue' => 0,
),
'label' => "Replace edit response in browse response interface.",
'help' => "When an admin user want to edit an existing response : he was redirected to editing the public survey.",
'help' => "When an admin user want to edit an existing response directly redirect to editing the public survey.",
'default' => 0,
),
'addEditResponseOnBrowse' => array(
'type' => 'checkbox',
'htmlOptions' => array(
'value' => 1,
'uncheckValue' => 0,
),
'label' => "Add an edit button on browser.",
'help' => "Add a button on browse reponse if user is allowed to edit (only if replace edit response is not activated).",
'default' => 1,
),
'allowTokenUser' => array(
'type' => 'select',
'options' => array(
......@@ -663,21 +673,41 @@ class reloadAnyResponse extends PluginBase
$this->fixSurveyAttributes();
return;
}
if (!$this->get('replaceEditResponse') || !$this->get('allowAdminUser')) {
if ($this->getEvent()->get("controller") != "admin") {
return;
}
if ($this->getEvent()->get("controller") != "admin") {
if ($this->getEvent()->get("action") != "responses" && $this->getEvent()->get("action") != "dataentry") {
return;
}
if ($this->getEvent()->get("action") != "dataentry") {
$surveyid = App()->getRequest()->getParam('surveyid');
if (!Permission::model()->hasSurveyPermission($surveyid, 'response', 'update')) {
return;
}
if ($this->getEvent()->get("subaction") != "editdata") {
if (!\reloadAnyResponse\Utilities::SurveyIsValid($surveyid)) {
return;
}
$surveyid = App()->getRequest()->getParam('surveyid');
$srid = App()->getRequest()->getParam('id');
if (!Permission::model()->hasSurveyPermission($surveyid, 'response', 'update')) {
if($this->get('addEditResponseOnBrowse',null, null, 1) && !$this->get('replaceEditResponse',null,null,0)) {
$reloadAnyResponseOptions = array(
'baseUrl' => Yii::app()->createUrl("survey/index", array('sid' => $surveyid,'newtest'=>'Y','srid'=>"")),
'lang' => array(
'launch' => gT("Execute Survey"),
),
);
App()->clientScript->registerScript(
'reloadAnyResponseAdminScript',
'LS.reloadAnyResponse = ' . json_encode($reloadAnyResponseOptions),
CClientScript::POS_BEGIN
);
App()->clientScript->registerScriptFile(
App()->assetManager->publish(dirname(__FILE__) . '/assets/browseResponse/browse_response.js'),
CClientScript::POS_END
);
return;
}
if(!$this->get('replaceEditResponse',null,null,0)) {
return;
}
if ($this->getEvent()->get("action") != "dataentry") {
return;
}
$criteria = \reloadAnyResponse\Utilities::getResponseCriteria($surveyid, $srid);
......@@ -686,7 +716,6 @@ class reloadAnyResponse extends PluginBase
return;
}
$surveyLink = Yii::app()->createUrl("survey/index", array('sid' => $surveyid,'srid' => $srid,'newtest' => 'Y'));
$this->getEvent()->set('run', false);
App()->getController()->redirect($surveyLink);
}
......@@ -707,11 +736,19 @@ class reloadAnyResponse extends PluginBase
if (empty($srid)) {
return;
}
if(Permission::model()->hasSurveyPermission($sid, 'responses', 'update')) {
$startUrl = new \reloadAnyResponse\StartUrl($sid);
if ($startUrl->isAvailable()) {
$this->enablealloweditaftercompletion = true;
$this->subscribe('afterFindSurvey', 'setSurveyAttributes');
return;
}
}
$token = App()->getRequest()->getParam('token');
if (empty($token)) {
$token = \reloadAnyResponse\Utilities::getCurrentReloadedToken($sid);
}
if(!empty($token)) {
if ($srid == "new") {
/* @todo : allow create system and checker */
......@@ -986,6 +1023,7 @@ class reloadAnyResponse extends PluginBase
$this->endWithEditionMessage($since);
}
$token = \reloadAnyResponse\Utilities::getCurrentReloadedToken($surveyid);
tracevar($this->getCurrentSetting('reloadResetSubmitted', $surveyid));
\reloadAnyResponse\Utilities::resetLoadedReponse($surveyid, $currentSrid, $token, $this->getCurrentSetting('reloadResetSubmitted', $surveyid));
$this->surveyId = $surveyid;
$this->reloadedSrid = $currentSrid;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment