tao-test/app/tao/views/js/lib/jsTree/plugins/jquery.tree.checkbox.js

97 lines
3.0 KiB
JavaScript
Raw Normal View History

2022-08-29 20:14:13 +02:00
define(['jquery', 'jquery.tree'], function ($) {
$.extend($.tree.plugins, {
"checkbox" : {
defaults : {
three_state : true
},
get_checked : function (t) {
if(!t) t = $.tree.focused();
return t.container.find("a.checked").parent();
},
get_undeterminded : function (t) {
if(!t) t = $.tree.focused();
return t.container.find("a.undetermined").parent();
},
get_unchecked : function (t) {
if(!t) t = $.tree.focused();
return t.container.find("a:not(.checked, .undetermined)").parent();
},
check : function (n) {
if(!n) return false;
var t = $.tree.reference(n);
//-TAO EDIT-
if (t.callback("beforecheck", [n, t]) === false) return false;
//--
n = t.get_node(n);
//-TAO EDIT-
if (n.hasClass('node-class') && n.hasClass('closed')) {
t.open_branch(n);
return false;
}
//--
if(n.children("a").hasClass("checked")) return true;
var opts = $.extend(true, {}, $.tree.plugins.checkbox.defaults, t.settings.plugins.checkbox);
if(opts.three_state) {
n.find("li").addBack().children("a").removeClass("unchecked undetermined").addClass("checked");
n.parents("li").each(function () {
if($(this).children("ul").find("a:not(.checked):eq(0)").size() > 0) {
$(this).parents("li").addBack().children("a").removeClass("unchecked checked").addClass("undetermined");
return false;
}
else $(this).children("a").removeClass("unchecked undetermined").addClass("checked");
});
}
//-TAO EDIT-
//else n.children("a").removeClass("unchecked").addClass("checked");
else if (!n.hasClass('node-class')) {
n.children("a").removeClass("unchecked").addClass("checked");
}
//--
return true;
},
uncheck : function (n) {
if(!n) return false;
var t = $.tree.reference(n);
//-TAO EDIT-
if (t.callback("beforeuncheck", [n, t]) === false) return false;
//--
n = t.get_node(n);
if(n.children("a").hasClass("unchecked")) return true;
var opts = $.extend(true, {}, $.tree.plugins.checkbox.defaults, t.settings.plugins.checkbox);
if(opts.three_state) {
n.find("li").addBack().children("a").removeClass("checked undetermined").addClass("unchecked");
n.parents("li").each(function () {
if($(this).find("a.checked, a.undetermined").size() - 1 > 0) {
$(this).parents("li").addBack().children("a").removeClass("unchecked checked").addClass("undetermined");
return false;
}
else $(this).children("a").removeClass("checked undetermined").addClass("unchecked");
});
}
else n.children("a").removeClass("checked").addClass("unchecked");
return true;
},
toggle : function (n) {
if(!n) return false;
var t = $.tree.reference(n);
n = t.get_node(n);
if(n.children("a").hasClass("checked")) $.tree.plugins.checkbox.uncheck(n);
else $.tree.plugins.checkbox.check(n);
},
callbacks : {
onchange : function(n, t) {
$.tree.plugins.checkbox.toggle(n);
}
}
}
});
});