Skip to content

Commit

Permalink
Dev: Updated the Question tree with the new version of fancytree.
Browse files Browse the repository at this point in the history
Styling is not final, events are working
  • Loading branch information
lacrioque committed Nov 2, 2016
1 parent a735a58 commit ec20a0f
Show file tree
Hide file tree
Showing 10 changed files with 582 additions and 337 deletions.
103 changes: 84 additions & 19 deletions application/controllers/admin/questiongroups.php
Expand Up @@ -533,13 +533,13 @@ public function update($gid)
* @see: https://github.com/mar10/fancytree/wiki/TutorialLoadData#pass-a-javascript-array
*
* @param int $surveyid
* @param string $langage
* @param string $language
* @return string (json array)
*/
public function getGroupExplorerDatas($surveyid, $langage)
public function getGroupExplorerDatas($surveyid, $language)
{
$iSurveyID = (int) $surveyid;
$aGroups = QuestionGroup::model()->getGroupExplorerDatas($iSurveyID, $langage); // Get an array of Groups and questions
$aGroups = QuestionGroup::model()->getGroupExplorerDatas($iSurveyID, $language); // Get an array of Groups and questions
$aDatas = array(); // The indexed array

// Two task :
Expand All @@ -549,21 +549,37 @@ public function getGroupExplorerDatas($surveyid, $langage)
$aGroupArray = array();

$aGroupArray["key"] = $aGroup->gid; // The key is used by fancy tree to build the node id.
$aGroupArray["title"] = $aGroup->sanitized_group_name; // The title will be shown as text
$aGroupArray["gid"] = $aGroup->gid;
$aGroupArray["title"] = ( // The title will be shown as text, but be truncated to max 28 letters
(mb_strlen($aGroup->sanitized_group_name, Yii::app()->charset) > 28)
? mb_substr($string, 0, 26, Yii::app()->charset).""
: $aGroup->sanitized_group_name);
$aGroupArray["folder"] = true; // Means it's a node with children
$aGroupArray["href"] = Yii::app()->createUrl('admin/questiongroups/sa/view/', array('surveyid' => $iSurveyID, 'gid' => $aGroup->gid)); // Means it's a node with children
$aGroupArray['extraClasses'] = 'lsi-tree-group-item';
$aGroupArray['buttonlinks'] = array(
array(
'title' => gT('Add a question to this group'),
'url' => 'someurl',
'icon' => 'glyphicon glyphicon-plus-sign',
'url' => Yii::app()->createUrl('admin/questions/sa/newquestion/', array('surveyid' => $iSurveyID, 'gid' => $aGroup->gid)),
'icon' => 'fa fa-plus-circle',
'toggle' => 'tooltip',
'cssclasses' => 'btn btn-xs btn-success',

),
array(
'title' => 'test',
'url' => 'someurlTEST',
'icon' => 'glyphicon glyphicon-trash',
'cssclasses' => 'btn btn-xs btn-danger',
'title' => gT('Delete this Group'),
'url' => Yii::app()->createUrl('admin/questiongroups/sa/delete/', array('surveyid' => $iSurveyID, 'gid' => $aGroup->gid)),
'icon' => 'fa fa-trash-o',
'toggle' => 'modal',
'target' => '#confirmation-modal',
'cssclasses' => 'btn btn-xs btn-danger deleteNode'
),
array(
'title' => gT('Edit this group'),
'url' => Yii::app()->createUrl('admin/questiongroups/sa/edit/', array('surveyid' => $iSurveyID, 'gid' => $aGroup->gid)),
'icon' => 'fa fa-edit',
'toggle' => 'tooltip',
'cssclasses' => 'btn btn-xs btn-default',
),
);

Expand All @@ -576,9 +592,24 @@ public function getGroupExplorerDatas($surveyid, $langage)
$aDatasQuestions['tooltip'] = $oQuestion->getSanitized_question();
$aDatasQuestions['href'] = Yii::app()->createUrl('admin/questions/sa/view/', array('surveyid' => $surveyid, 'gid' => $aGroup->gid, 'qid' => $oQuestion->qid));
$aDatasQuestions['toggle'] = 'tooltip';
$aDatasQuestions['placement'] = 'left';
$aDatasQuestions['placement'] = 'bottom';
$aDatasQuestions['extraClasses'] = 'lsi-tree-question-item';
$aDatasQuestions['buttonlinks'] = array(

array(
'title' => gT('Delete this Question'),
'url' => Yii::app()->createUrl('admin/questions/sa/delete/', array('surveyid' => $iSurveyID, 'qid' => $oQuestion->qid)),
'icon' => 'fa fa-trash-o',
'toggle' => 'modal',
'target' => '#confirmation-modal',
'cssclasses' => 'btn btn-xs btn-danger deleteNode',
),
array(
'title' => gT('Edit this group'),
'url' => Yii::app()->createUrl('admin/questions/sa/editquestion/', array('surveyid' => $iSurveyID, 'qid' => $oQuestion->qid)),
'icon' => 'fa fa-edit',
'toggle' => 'tooltip',
'cssclasses' => 'btn btn-xs btn-default',
),
);

$aGroupArray["children"][] = $aDatasQuestions; // Doing that, we push the questions in the children array, as an unindexed array (no count)
Expand All @@ -590,10 +621,47 @@ public function getGroupExplorerDatas($surveyid, $langage)
echo json_encode($jDatas);
}

function getQuestionDetailData($surveyid, $langage, $gid, $qid){
function getQuestionDetailData($surveyid, $language, $gid=null, $qid=null){
$iSurveyID = (int) $surveyid;
$oQuestion = Question::model()->findByPk(array('qid' => $qid, 'language' => $langage));
if($qid === null){
$jDetailsArray = $this->collectQuestionGroupDetail($surveyid, $language, $gid);
} else {
$jDetailsArray = $this->collectQuestionDetail($surveyid, $language, $qid);
}

echo json_encode($jDetailsArray);
Yii::app()->end();
}
private function collectQuestionGroupDetail($surveyid, $language, $gid){

$oQuestionGroup = QuestionGroup::model()->findByPk(array('gid' => $gid, 'language' => $language));
$jDetailsArray = array(print_r($oQuestionGroup,true));
$jDetailContent = "<div class='container-center'>
<dl>
<dt>".gT('Description')."</dt>
<dd class='text-right'>&nbsp;".$oQuestionGroup->getGroupDescription($gid,$language)."</dd>
<dt>".gT('Questions')."</dt>
<dd class='text-right'>&nbsp;".$oQuestionGroup->questionsInGroup."</dd>
<dt>".gT('Randomization Group')."</dt>
<dd class='text-right'>&nbsp;".$oQuestionGroup->randomization_group."</dd>
<dt>".gT('Relevance')."</dt>
<dd class='text-right'>&nbsp;".LimeExpressionManager::UnitTestConvertConditionsToRelevance($surveyid,$oQuestionGroup->gid)."</dd>
</dl>";

$jDetailsArray = array(
'success' => true,
'title' => $oQuestionGroup->sanitized_group_name,
'content' => $jDetailContent
);
return $jDetailsArray;
}
private function collectQuestionDetail($surveyid, $language, $qid){

$oQuestion = Question::model()->findByPk(array('qid' => $qid, 'language' => $language));
$jDetailContent = "<div class='container-center'>
<dl>
<dt>".gT('Code')."</dt>
Expand All @@ -609,19 +677,16 @@ function getQuestionDetailData($surveyid, $langage, $gid, $qid){
<dd class='text-right'>&nbsp;".$oQuestion->otherIcon."</dd>
<dt>".gT('Relevance equation')."</dt>
<dd class='text-right'>&nbsp;".LimeExpressionManager::UnitTestConvertConditionsToRelevance($iSurveyID,$oQuestion->qid)."</dd>
<dd class='text-right'>&nbsp;".LimeExpressionManager::UnitTestConvertConditionsToRelevance($surveyid,$oQuestion->qid)."</dd>
</dl>";

$jDetailsArray = array(
'success' => true,
'title' => $oQuestion->sanitized_title,
'content' => $jDetailContent
);

echo json_encode($jDetailsArray);
Yii::app()->end();
return $jDetailsArray;
}

/**
* Renders template(s) wrapped in header and footer
*
Expand Down
7 changes: 7 additions & 0 deletions application/models/QuestionGroup.php
Expand Up @@ -245,6 +245,13 @@ function getAllGroups($condition, $order=false)
return $command->query();
}

public function getQuestionsInGroup(){
$iGroupId = $this->gid;
$aQuestionIds = $this->getQuestionIdsInGroup($iGroupId);

return count($aQuestionIds);
}

public function getbuttons()
{
// Find out if the survey is active to disable add-button
Expand Down
165 changes: 35 additions & 130 deletions application/views/admin/super/_question_explorer.php
Expand Up @@ -5,150 +5,55 @@
* @var $sidemenu
* @var $aGroups
* @var $iSurveyId
* @var $language
* @var $iQuestionId
* @var $iQuestionGroupId
*/
?>
<?php
App()->getClientScript()->registerPackage('fancytree');
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('adminscripts') . "jquery.fancytree.bstooltip.js");
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('adminscripts') . "jquery.fancytree.bsbuttonbar.js");
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('adminscripts') . "fancytree.surveyview.js");

?>


<!-- State when page is loaded : for JavaScript-->
<li id="explorer" class="dropdownlvl2 dropdownstyle panel panel-default">
<?php if(isset($sidemenu['explorer']['state']) && $sidemenu['explorer']['state']==true):?>
<input type="hidden" id="open-explorer" />

<?php if(isset($sidemenu['explorer']['gid'])):?>
<input type="hidden" id="open-questiongroup" data-gid="<?php echo $sidemenu['explorer']['gid'];?>" />
<?php endif;?>
<?php endif;?>
<?php endif;?>

<li id="explorer" class="dropdownlvl2 dropdownstyle panel panel-default">
<a data-toggle="collapse" id="explorer-collapse" href="#explorer-lvl1">
<span class="glyphicon glyphicon-folder-open"></span> <?php eT('Question explorer');?>
<span class="caret" ></span>
</a>


<a data-toggle="collapse" id="explorer-collapse" href="#explorer-lvl1">
<span class="glyphicon glyphicon-folder-open"></span> <?php eT('Question explorer');?>
<span class="caret" ></span>
</a>
<!-- The actual panle-element which contains the tree, and the filter_input -->
<div id="explorer-lvl1" class="panel-collapse collapse" >
<div class="panel-body">
<ul class="nav navbar-nav dropdown-first-level" id="explorer-container">

<!-- Groups and questions-->
<?php if(count($aGroups)):?>
<li class="panel panel-default dropdownstyle" id="questionexplorer-group-container">


<?php if (!$bSurveyIsActive && Permission::model()->hasSurveyPermission($iSurveyId, 'surveycontent', 'create')): ?>
<div class="row ">
<div class="col-sm-8" >
<!-- add group -->
<a class="btn btn-link"
data-toggle="tooltip"
data-placement="bottom"
title="<?php eT('Add a group');?>"
href="<?php echo $this->createUrl("/admin/questiongroups/sa/add/surveyid/$iSurveyId"); ?>">
<span class="glyphicon glyphicon-plus-sign"></span>
<?php eT('Add group');?>
</a>
</div>
</div>
<?php endif; ?>


<?php foreach($aGroups as $aGroup):?>

<!-- Group -->
<div class="row explorer-group-title">
<div class="col-sm-8">
<a href="#" data-question-group-id="<?php echo $aGroup->gid; ?>" class="explorer-group">
<span id="caret-<?php echo $aGroup->gid; ?>" class="fa fa-caret-right caret-explorer-group"></span>&nbsp;&nbsp;
<span class="question-explorer-group-name"><?php echo $aGroup->group_name;?></span>
</a>
</div>

<?php
if (!$bSurveyIsActive && Permission::model()->hasSurveyPermission($iSurveyId, 'surveycontent', 'create')): ?>
<div class="col-sm-1" id="questions-container-<?php echo $aGroup->gid; ?>">
<!-- add question to this group -->
<a data-toggle="tooltip" data-placement="top" style="padding: 0" title="<?php eT('Add a question to this group');?>" class="question-explorer-add-question" href="<?php echo $this->createUrl("/admin/questions/sa/newquestion/surveyid/$iSurveyId/gid/$aGroup->gid"); ?>">
<span class="glyphicon glyphicon-plus-sign"></span>
</a>
</div>
<?php elseif (Permission::model()->hasSurveyPermission($iSurveyId, 'surveycontent', 'create')): ?>
<div class="col-sm-1" style="padding: 0" id="questions-container-<?php echo $aGroup->gid; ?>">
<!-- add question to this group -->
<a title="<?php eT("You can't add questions while the survey is active.");?>" class='disabled question-explorer-add-question' href="#" data-toggle="tooltip" data-placement="top">
<span class="glyphicon glyphicon-plus-sign"></span>
</a>
</div>
<?php endif;?>
<div class="col-sm-1">
<!-- add question to this group -->
<a data-toggle="tooltip" data-placement="top" title="<?php eT('Group summary');?>" class="question-explorer-add-question" href="<?php echo $this->createUrl("/admin/questiongroups/sa/view/surveyid/$iSurveyId/gid/$aGroup->gid"); ?>">
<span class="glyphicon glyphicon-list"></span>
</a>
</div>
</div>

<!-- Questions -->
<div class="row" id="questions-group-<?php echo $aGroup->gid; ?>" style="display: none;">
<div class="col-sm-12">
<?php if(count($aGroup['aQuestions'])):?>
<?php foreach($aGroup['aQuestions'] as $question):?>
<?php if($question->parent_qid == 0):?>

<?php if(isset($sidemenu['explorer']['qid']) && $question->qid == $sidemenu['explorer']['qid']): ?>
<!-- Active question -->
<div class="question-link active" >
<span class="question-collapse-title">
<span class="glyphicon glyphicon-list-alt"></span>
<strong>
<?php echo sanitize_html_string(strip_tags($question->title));?>
</strong>
<br/>
<em class="question-explorer-question">
<?php
echo $question->question;
?>
</em>
</span>
</div>
<?php else: ?>
<!-- Other questions -->
<a href="<?php echo $this->createUrl("/admin/questions/sa/view/surveyid/$iSurveyId/gid/".$aGroup->gid."/qid/".$question->qid); ?>" class="question-link" >
<span class="question-collapse-title">
<span class="glyphicon glyphicon-list"></span>
<strong>
<?php echo sanitize_html_string(strip_tags($question->title));?>
</strong>
<br/>
<em class="question-explorer-question">
<?php
echo $question->question;
?>
</em>
</span>
</a>
<?php endif; ?>
<?php endif; ?>
<?php endforeach;?>
<?php else:?>
<a href="" onclick="event.preventDefault();" style="cursor: default;">
<?php eT('There are no questions in this group.');?>
</a>
<?php endif;?>
</div>
</div>
<?php endforeach;?>
</li>

<div class="panel-body container-fluid">
<!-- The filtering input, fixed against submit, by js -->
<div class="row row-with-margin">
<div class="row">
<label class="col-xs-12 control-label" for="searchInQuestionTree"><?php eT("Search for question/questiongroup"); ?></label>
</div>
<div class="row">
<input class="col-xs-12 form-control" id="searchInQuestionTree" name="searchInQuestionTree" placeholder=" ...<?php eT('Search');?>" />
</div>
</div>
<!-- the fancytree container, here is where the magic happens -->
<div id="fancytree" class="row" data-show-expand-collapse="1" data-expand-all="<?php eT('Expand All');?>" data-collapse-all="<?php eT('Collapse All'); ?>"></div>
<!-- The necessary scripts and variables for the fancytree-library -->
<script>
var sourceUrl = "<?php echo Yii::app()->urlManager->createUrl("admin/questiongroups/sa/getGroupExplorerDatas", array("surveyid"=>$iSurveyId, "language" => $language));?>";
var questionDetailUrl = "<?php echo Yii::app()->urlManager->createUrl("admin/questiongroups/sa/getQuestionDetailData", array("surveyid" => $iSurveyId, "language" => $language));?>";
var fancytree = new CreateFancytree($("#fancytree"), $("#searchInQuestionTree"), sourceUrl, questionDetailUrl);
fancytree.run("<?php echo $iQuestionId; ?>", "<?php echo $iQuestionGroupId; ?>");
</script>

<?php else:?>
<li class="toWhite">
<a href="" onclick="event.preventDefault();" style="cursor: default;">
<?php eT('No question group in this survey');?>
</a>
</li>
<?php endif;?>
</ul>
</div>
</div>
</li>
</li>

0 comments on commit ec20a0f

Please sign in to comment.