Skip to content

Commit

Permalink
Dev: Imported fancy-tree and expanded event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Nov 11, 2016
1 parent ef932a8 commit d5c2450
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 91 deletions.
74 changes: 52 additions & 22 deletions application/controllers/admin/questiongroups.php
Expand Up @@ -524,19 +524,18 @@ public function getGroupExplorerDatas($surveyid, $langage)
{
$iSurveyID = (int) $surveyid;
$aGroups = QuestionGroup::model()->getGroupExplorerDatas($iSurveyID, $langage); // Get an array of Groups and questions
$count = 1; // @see : http://www.explainxkcd.com/wiki/index.php/163
$aDatas = array(); // The indexed array

// Two task :
// Clean the datas (ellipsize etc)
// Build the unindexed array that will be converted to jSon
foreach($aGroups as $aGroup)
{
$aGroupArray = array();

$aDatas[$count]["key"] = $aGroup->gid; // The key is used by fancy tree to build the node id.
$aDatas[$count]["title"] = $aGroup->sanitized_group_name; // The title will be shown as text
$aDatas[$count]["folder"] = true; // Means it's a node with children
$aDatas[$count]['buttonlinks'] = 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["folder"] = true; // Means it's a node with children
$aGroupArray['buttonlinks'] = array(
array(
'title' => gT('Add a question to this group'),
'url' => 'someurl',
Expand All @@ -552,30 +551,61 @@ public function getGroupExplorerDatas($surveyid, $langage)
),
);

$countQ = 1;
$aDatasQ = array(); // The indexed array that will contain questions

foreach ($aGroup['aQuestions'] as $oQuestion)
{
$aDatasQ[$countQ]["key"] = $oQuestion->qid;
$aDatasQ[$countQ]["title"] = $oQuestion->sanitized_title . ' : ' . $oQuestion->getEllipsized_question();
$aDatasQ[$countQ]['tooltip'] = $oQuestion->getSanitized_question();
$aDatasQ[$countQ]['toggle'] = 'tooltip';
$aDatas[$count]["children"][] = $aDatasQ[$countQ]; // Doing that, we push the questions in the children array, as an unindexed array (no count)
$countQ++;
$aDatasQuestions = array(); // The indexed array that will contain questions
$aDatasQuestions["key"] = $oQuestion->qid;
$aDatasQuestions["gid"] = $aGroup->gid;
$aDatasQuestions["title"] = $oQuestion->sanitized_title . ' : ' . $oQuestion->getEllipsized_question();
$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['buttonlinks'] = array(

);

$aGroupArray["children"][] = $aDatasQuestions; // Doing that, we push the questions in the children array, as an unindexed array (no count)
}

$jDatas[] = $aDatas[$count]; // Doing that, we push the Group as an unindexed array to jDatas
$count++;
// Doing that, we push the Group as an unindexed array to jDatas, !IMPORTANT! don't index the jDatas array
$jDatas[] = $aGroupArray;
}

// If you need to understand the difference between indexed/non indexed result,
// Uncoment the folowing line and go to : {YOUR_URL}/admin/questiongroups/sa/getGroupExplorerDatas/surveyid/{YOUR_SURVEY_ID}/langage/{YOUR_BASE_LANGUAGE}
// echo '<h1>INDEXED:</h1>';echo json_encode($aDatas); echo '<hr/>';echo '<h1>NOT INDEXED:</h1>';

echo json_encode($jDatas);
}

function getQuestionDetailData($surveyid, $langage, $gid, $qid){
$iSurveyID = (int) $surveyid;
$oQuestion = Question::model()->findByPk(array('qid' => $qid, 'language' => $langage));

$jDetailContent = "<div class='container-center'>
<dl>
<dt>".gT('Code')."</dt>
<dd class='text-right'>&nbsp;".$oQuestion->title."</dd>
<dt>".gT('Question type')."</dt>
<dd class='text-right'>&nbsp;".$oQuestion->typedesc."</dd>
<dt>".gT('Mandatory')."</dt>
<dd class='text-right'>&nbsp;".$oQuestion->mandatoryIcon."</dd>
<dt>".gT('Other')."</dt>
<dd class='text-right'>&nbsp;".$oQuestion->otherIcon."</dd>
<dt>".gT('Relevance equation')."</dt>
<dd class='text-right'>&nbsp;".LimeExpressionManager::UnitTestConvertConditionsToRelevance($iSurveyID,$oQuestion->qid)."</dd>
</dl>";

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

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

/**
* Renders template(s) wrapped in header and footer
*
Expand Down
1 change: 1 addition & 0 deletions application/controllers/admin/questions.php
Expand Up @@ -2171,4 +2171,5 @@ protected function abortIfSurveyIsActive(array $surveyInfo)
$this->getController()->redirect(Yii::app()->request->urlReferrer);
}
}

}
34 changes: 0 additions & 34 deletions application/models/Question.php
Expand Up @@ -862,40 +862,6 @@ public function getSanitized_title()
return $this->sanitized_title;
}

/**
* Get an new title/code for a question
* @param integer|string $index base for question code (exemple : inde of question when survey import)
* @return string|null : new title, null if impossible
*/
public function getNewTitle($index=0)
{
$sOldTitle=$this->title;
if($this->validate(array('title'))){
return $sOldTitle;
}
/* Maybe it's an old invalid title : try to fix it */
$sNewTitle=preg_replace("/[^A-Za-z0-9]/", '', $sOldTitle);
if (is_numeric(substr($sNewTitle,0,1)))
{
$sNewTitle='q' . $sNewTitle;
}
/* Maybe there are another question with same title try to fix it 10 times */
$attempts = 0;
while (!$this->validate(array('title')))
{
$rand = mt_rand(0, 1024);
$sNewTitle= 'q' . $index.'r' . $rand ;
$this->title = $sNewTitle;
$attempts++;
if ($attempts > 10)
{
$this->addError('title', 'Failed to resolve question code problems after 10 attempts.');
return null;
}
}
return $sNewTitle;
}

public function search()
{
$pageSize=Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']);
Expand Down
46 changes: 28 additions & 18 deletions application/views/admin/survey/surveySummary_view.php
Expand Up @@ -111,39 +111,49 @@ class="folder"
selectMode: 2,
clickFolderMode: 3,
dblclick: function(event, data) {

var node = data.node;
// Use <a> href and target attributes to load the content:
if( node.data.href ){
// Open target
window.open(node.data.href, node.data.target);
}
},
click: function(event, data){
var node = data.node;
console.log(node);
if(node.isActive()){
$.ajax({
url : "<?php echo Yii::app()->urlManager->createUrl("admin/questiongroups/sa/getQuestionDetailData/surveyid/$iSurveyID/langage/".$surveyinfo['language']);?>",
data : {gid: node.data.gid, qid: node.key},
method : "GET",
dataType: "json"
}).then(
function (success){
$(node.span).find('.fancytree-title').popover({
title: success.title,
content: success.content,
placement: 'right',
html: true,
delay: {show: 200, hide: 4000},
container: node.tree.$container.parent()
}).popover('show');
$('body').on('click.singlePopover', function(){$(node.span).find('.fancytree-title').popover('destroy'); $('body').off('click.singlePopover')});
},
function(error){
console.log(error);
}
)
}
},
wide: {
iconWidth: "1em", // Adjust this if @fancy-icon-width != "16px"
iconSpacing: "0.5em", // Adjust this if @fancy-icon-spacing != "3px"
levelOfs: "1.5em" // Adjust this if ul padding != "16px"
},
expand: function(event, data){
console.log("expand");


}

});/*.on("mouseover", "span.fancytree-title", function(event){
// Add a hover handler to all node titles (using event delegation)
var node = $.ui.fancytree.getNode(event);
node.info(event.type);
// Add bootstrap tooltip
if(node.data.toggle=='tooltip')
{
//$(this).addClass('hidden')
$(this).attr('data-toggle', 'tooltip');
$(this).tooltip();
}
//console.log(node.toggle)
});;*/
});
</script>
</div>
</div>
Expand Down
29 changes: 12 additions & 17 deletions scripts/admin/jquery.fancytree.bstooltip.js
Expand Up @@ -45,58 +45,53 @@
$.each( node.data.buttonlinks, function( key, button ){
//console.log(button);

var buttonHtml = '<a href="'+button.url+'" role="button"';
var jQbutton = $('<a role="button"></a>)');
jQbutton.attr("href",button.url);

if (button.cssclasses)
{
buttonHtml += ' class="'+button.cssclasses+'"';
jQbutton.addClass(button.cssclasses);
}
else
{
buttonHtml += ' class="btn btn-xs btn-default" ';
jQbutton.addClass("btn btn-xs btn-default");
}

if (button.toggle)
{
buttonHtml += ' data-toggle="'+button.toggle+'"';
jQbutton.data("toggle", button.toggle);
}

if (button.placement)
{
buttonHtml += ' data-placement="'+button.placement+'"';
jQbutton.data("placement", button.placement);
}

if (button.title)
{
buttonHtml += ' title="'+button.title+'"';
jQbutton.attr("title", button.title);
}

buttonHtml += '>';

if (button.icon)
{
buttonHtml += '<span class="'+button.icon+'"></span>';
jQbutton.append('<i class="'+button.icon+'"></i>');
}

if (button.buttontext)
{
buttonHtml += button.buttontext;
jQbutton.append(button.buttontext);
}

buttonHtml += '</a>';

var $elButton = $(buttonHtml)

$("span.fancytree-title", node.span).append(' ').append( $elButton );
$("span.fancytree-title", node.span).append(' ').append( jQbutton );

if (button.toggle=='tooltip')
{
$elButton.tooltip();
jQbutton.tooltip();
}

if (button.toggle=='popover')
{
$elButton.popover();
jQbutton.popover();
}

} );
Expand Down

0 comments on commit d5c2450

Please sign in to comment.