Skip to content

Commit

Permalink
Dev: implemented oneclick/dblclick functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Nov 30, 2016
1 parent 31cf998 commit f357c1c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 52 deletions.
10 changes: 5 additions & 5 deletions application/controllers/admin/questiongroups.php
Expand Up @@ -539,23 +539,23 @@ public function getGroupExplorerDatas($surveyid, $language)
$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(
"add" => array(
'title' => gT('Add a question to this group'),
'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(
"delete" => array(
'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(
"edit" => array(
'title' => gT('Edit this group'),
'url' => Yii::app()->createUrl('admin/questiongroups/sa/edit/', array('surveyid' => $iSurveyID, 'gid' => $aGroup->gid)),
'icon' => 'fa fa-edit',
Expand All @@ -575,15 +575,15 @@ public function getGroupExplorerDatas($surveyid, $language)
$aDatasQuestions['placement'] = 'bottom';
$aDatasQuestions['extraClasses'] = 'lsi-tree-question-item';
$aDatasQuestions['buttonlinks'] = array(
array(
"delete" => 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(
"edit" => array(
'title' => gT('Edit this group'),
'url' => Yii::app()->createUrl('admin/questions/sa/editquestion/', array('surveyid' => $iSurveyID, 'qid' => $oQuestion->qid)),
'icon' => 'fa fa-edit',
Expand Down
1 change: 1 addition & 0 deletions application/views/admin/super/_question_explorer.php
Expand Up @@ -38,6 +38,7 @@
<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 dblClickTitle = "<?php eT('Double-click to edit.');?>";
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);
Expand Down
61 changes: 15 additions & 46 deletions scripts/admin/fancytree.surveyview.js
Expand Up @@ -7,6 +7,7 @@
* @param sourceUrl [string] => The URI from where to get the questiontree-data
* @param questionDetailUrl [string] => The URI from where to get the
*/
var clickTimer;
var CreateFancytree = function (jQTreeItem, searchInput, sourceUrl, questionDetailUrl) {

jQTreeItem = $(jQTreeItem);
Expand Down Expand Up @@ -38,7 +39,7 @@ var CreateFancytree = function (jQTreeItem, searchInput, sourceUrl, questionDeta
try{
topOfNode = $(activeNode.span).offset().top;
} catch(e){}

if(topOfNode !== 0) {
// console.log('topOfNode',topOfNode);
var scrollLength = 0;
Expand All @@ -54,6 +55,10 @@ var CreateFancytree = function (jQTreeItem, searchInput, sourceUrl, questionDeta
}
}
},
alreadyClicked = {
click : false,
clickNodeId: false
},
createTree = function (nodeKey) {
var fancytree = jQTreeItem.fancytree({

Expand All @@ -73,59 +78,23 @@ var CreateFancytree = function (jQTreeItem, searchInput, sourceUrl, questionDeta
}
},
dblclick: function (event, data) {
if ($(event.toElement).closest('a').hasClass('deleteNode') || $(event.toElement).hasClass('deleteNode')) {
event.preventDefault();
return false;
}
var node = data.node;
var editLink = node.data.buttonlinks.edit.url;
clearTimeout(clickTimer);
// Use <a> href and target attributes to load the content:
if (node.data.href) {
// Open target
window.location.href = node.data.href;
window.location.href = editLink;
}
},
click: function (event, data) {
if ($(event.toElement).closest('a').hasClass('deleteNode') || $(event.toElement).hasClass('deleteNode')) {
var element = (
($(event.toElement).closest('a').length > 0)
? $(event.toElement).closest('a')
: $(event.toElement)
);
return;
}
var node = data.node;
if (node.data.gid == node.key) {
var data = { gid: node.key };
} else {
var data = { gid: node.data.gid, qid: node.key };
}

if ($(event.toElement).closest('a').hasClass('fancytree-info-button') || $(event.toElement).hasClass('fancytree-info-button')) {
event.preventDefault();
$.ajax({
url: questionDetailUrl,
data: data,
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: $('body')
}).popover('show');
$('body').on('click.singlePopover', function () {
$(node.span).find('.fancytree-title').popover('destroy');
$('body').off('click.singlePopover');
});
},
function (error) {
console.log(error);
}
);
console.log(event);
if(((node.hasChildren() && node.isExpanded()) || !node.hasChildren()) && !$(event.toElement).hasClass('fancytree-expander')){
if (node.data.href) {
// Open target
clickTimer = setTimeout(function(){window.location.href = node.data.href},1000);
}
}
},
wide: {
Expand Down
6 changes: 5 additions & 1 deletion scripts/admin/jquery.fancytree.bsbuttonbar.js
Expand Up @@ -123,7 +123,11 @@
};
this._superApply(arguments);
var newHtml = _customwrapper($(node.span));
$(node.span).html(newHtml);

$(node.span).html(newHtml).tooltip({
title: dblClickTitle
});

// renderButtons(node);
}
});
Expand Down

0 comments on commit f357c1c

Please sign in to comment.