From d5c2450d7a43fda33e31a6427904b8049ef15bee Mon Sep 17 00:00:00 2001 From: markusfluer Date: Fri, 21 Oct 2016 17:53:35 +0200 Subject: [PATCH] Dev: Imported fancy-tree and expanded event handling --- .../controllers/admin/questiongroups.php | 74 +++++++++++++------ application/controllers/admin/questions.php | 1 + application/models/Question.php | 34 --------- .../views/admin/survey/surveySummary_view.php | 46 +++++++----- scripts/admin/jquery.fancytree.bstooltip.js | 29 +++----- 5 files changed, 93 insertions(+), 91 deletions(-) diff --git a/application/controllers/admin/questiongroups.php b/application/controllers/admin/questiongroups.php index 3d910c8a5b5..9542a3f0453 100644 --- a/application/controllers/admin/questiongroups.php +++ b/application/controllers/admin/questiongroups.php @@ -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', @@ -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 '

INDEXED:

';echo json_encode($aDatas); echo '
';echo '

NOT INDEXED:

'; - echo json_encode($jDatas); } + function getQuestionDetailData($surveyid, $langage, $gid, $qid){ + $iSurveyID = (int) $surveyid; + $oQuestion = Question::model()->findByPk(array('qid' => $qid, 'language' => $langage)); + + $jDetailContent = "
+
+
".gT('Code')."
+
 ".$oQuestion->title."
+ +
".gT('Question type')."
+
 ".$oQuestion->typedesc."
+ +
".gT('Mandatory')."
+
 ".$oQuestion->mandatoryIcon."
+ +
".gT('Other')."
+
 ".$oQuestion->otherIcon."
+ +
".gT('Relevance equation')."
+
 ".LimeExpressionManager::UnitTestConvertConditionsToRelevance($iSurveyID,$oQuestion->qid)."
+
"; + + $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 * diff --git a/application/controllers/admin/questions.php b/application/controllers/admin/questions.php index f0d349cfffc..a1e44e06401 100644 --- a/application/controllers/admin/questions.php +++ b/application/controllers/admin/questions.php @@ -2171,4 +2171,5 @@ protected function abortIfSurveyIsActive(array $surveyInfo) $this->getController()->redirect(Yii::app()->request->urlReferrer); } } + } diff --git a/application/models/Question.php b/application/models/Question.php index 949e40cbb6f..ad21c6311be 100644 --- a/application/models/Question.php +++ b/application/models/Question.php @@ -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']); diff --git a/application/views/admin/survey/surveySummary_view.php b/application/views/admin/survey/surveySummary_view.php index df6262135bf..82a37b10a1c 100644 --- a/application/views/admin/survey/surveySummary_view.php +++ b/application/views/admin/survey/surveySummary_view.php @@ -111,7 +111,6 @@ class="folder" selectMode: 2, clickFolderMode: 3, dblclick: function(event, data) { - var node = data.node; // Use href and target attributes to load the content: if( node.data.href ){ @@ -119,31 +118,42 @@ class="folder" window.open(node.data.href, node.data.target); } }, + click: function(event, data){ + var node = data.node; + console.log(node); + if(node.isActive()){ + $.ajax({ + url : "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) - });;*/ + });
diff --git a/scripts/admin/jquery.fancytree.bstooltip.js b/scripts/admin/jquery.fancytree.bstooltip.js index d9ac80448ac..f8c7a0ffb6b 100644 --- a/scripts/admin/jquery.fancytree.bstooltip.js +++ b/scripts/admin/jquery.fancytree.bstooltip.js @@ -45,58 +45,53 @@ $.each( node.data.buttonlinks, function( key, button ){ //console.log(button); - var buttonHtml = ')'); + 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 += ''; + jQbutton.append(''); } if (button.buttontext) { - buttonHtml += button.buttontext; + jQbutton.append(button.buttontext); } - buttonHtml += ''; - - 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(); } } );