]>
git.wh0rd.org - tt-rss.git/blob - lib/CheckBoxTree.js
1 define(["dojo/_base/declare", "dijit/Tree", "lib/_CheckBoxTreeNode" ], function (declare
) {
3 return declare( "lib.CheckBoxTree", dijit
.Tree
,
6 onNodeChecked: function(/*dojo.data.Item*/ storeItem
, /*treeNode*/ treeNode
) {
8 // Callback when a checkbox tree node is checked
13 onNodeUnchecked: function(/*dojo.data.Item*/ storeItem
, /* treeNode */ treeNode
) {
15 // Callback when a checkbox tree node is unchecked
20 _onClick: function(/*TreeNode*/ nodeWidget
, /*Event*/ e
) {
22 // Translates click events into commands for the controller to process
24 // the _onClick function is called whenever a 'click' is detected. This
25 // instance of _onClick only handles the click events associated with
26 // the checkbox whos DOM name is INPUT.
28 var domElement
= e
.target
;
30 // Only handle checkbox clicks here
31 if(domElement
.type
!= 'checkbox') {
32 return this.inherited( arguments
);
35 this._publish("execute", { item
: nodeWidget
.item
, node
: nodeWidget
} );
36 // Go tell the model to update the checkbox state
38 this.model
.updateCheckbox( nodeWidget
.item
, nodeWidget
._checkbox
.checked
);
39 // Generate some additional events
40 //this.onClick( nodeWidget.item, nodeWidget, e );
41 if(nodeWidget
._checkbox
.checked
) {
42 this.onNodeChecked( nodeWidget
.item
, nodeWidget
);
44 this.onNodeUnchecked( nodeWidget
.item
, nodeWidget
);
46 this.focusNode(nodeWidget
);
49 _onCheckboxChange: function(/*dojo.data.Item*/ storeItem
) {
51 // Processes notification of a change to a checkbox state (triggered by the model).
53 // Whenever the model changes the state of a checkbox in the dojo.data.store it will
54 // trigger the 'onCheckboxChange' event allowing the Tree to make the same changes
55 // on the tree Node. There are several conditions why a tree node or checkbox does not
57 // a) The node has not been created yet (the user has not expanded the tree node yet).
58 // b) The checkbox may be null if condition (a) exists or no 'checkbox' attribute was
59 // specified for the associated dojo.data.item and the attribute 'checkboxAll' is
63 var model
= this.model
,
64 identity
= model
.getIdentity(storeItem
),
65 nodes
= this._itemNodesMap
[identity
];
67 // As of dijit.Tree 1.4 multiple references (parents) are supported, therefore we may have
68 // to update multiple nodes which are all associated with the same dojo.data.item.
70 dojo
.forEach( nodes
, function(node
) {
71 if( node
._checkbox
!= null ) {
72 node
._checkbox
.attr('checked', this.model
.getCheckboxState( storeItem
));
78 postCreate: function() {
80 // Handle any specifics related to the tree and model after the instanciation of the Tree.
82 // Validate if we have a 'write' store first. Subscribe to the 'onCheckboxChange' event
83 // (triggered by the model) and kickoff the initial checkbox data validation.
85 var store
= this.model
.store
;
86 if(!store
.getFeatures()['dojo.data.api.Write']){
87 throw new Error("lib.CheckboxTree: store must support dojo.data.Write");
89 this.connect(this.model
, "onCheckboxChange", "_onCheckboxChange");
90 this.model
.validateData( this.model
.root
, this.model
);
91 this.inherited(arguments
);
94 _createTreeNode: function( args
) {
96 // Create a new CheckboxTreeNode instance.
98 // Create a new CheckboxTreeNode instance.
99 return new lib
._CheckBoxTreeNode(args
);