]> git.wh0rd.org - tt-rss.git/blob - lib/CheckBoxTree.js
pngcrush.sh
[tt-rss.git] / lib / CheckBoxTree.js
1 define(["dojo/_base/declare", "dijit/Tree", "lib/_CheckBoxTreeNode" ], function (declare) {
2
3 return declare( "lib.CheckBoxTree", dijit.Tree,
4 {
5
6 onNodeChecked: function(/*dojo.data.Item*/ storeItem, /*treeNode*/ treeNode) {
7 // summary:
8 // Callback when a checkbox tree node is checked
9 // tags:
10 // callback
11 },
12
13 onNodeUnchecked: function(/*dojo.data.Item*/ storeItem, /* treeNode */ treeNode) {
14 // summary:
15 // Callback when a checkbox tree node is unchecked
16 // tags:
17 // callback
18 },
19
20 _onClick: function(/*TreeNode*/ nodeWidget, /*Event*/ e) {
21 // summary:
22 // Translates click events into commands for the controller to process
23 // description:
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.
27 //
28 var domElement = e.target;
29
30 // Only handle checkbox clicks here
31 if(domElement.type != 'checkbox') {
32 return this.inherited( arguments );
33 }
34
35 this._publish("execute", { item: nodeWidget.item, node: nodeWidget} );
36 // Go tell the model to update the checkbox state
37
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);
43 } else {
44 this.onNodeUnchecked( nodeWidget.item, nodeWidget);
45 }
46 this.focusNode(nodeWidget);
47 },
48
49 _onCheckboxChange: function(/*dojo.data.Item*/ storeItem ) {
50 // summary:
51 // Processes notification of a change to a checkbox state (triggered by the model).
52 // description:
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
56 // exists:
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
60 // set to false.
61 // tags:
62 // callback
63 var model = this.model,
64 identity = model.getIdentity(storeItem),
65 nodes = this._itemNodesMap[identity];
66
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.
69 if( nodes ) {
70 dojo.forEach( nodes, function(node) {
71 if( node._checkbox != null ) {
72 node._checkbox.attr('checked', this.model.getCheckboxState( storeItem ));
73 }
74 }, this );
75 }
76 },
77
78 postCreate: function() {
79 // summary:
80 // Handle any specifics related to the tree and model after the instanciation of the Tree.
81 // description:
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.
84 //
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");
88 }
89 this.connect(this.model, "onCheckboxChange", "_onCheckboxChange");
90 this.model.validateData( this.model.root, this.model );
91 this.inherited(arguments);
92 },
93
94 _createTreeNode: function( args ) {
95 // summary:
96 // Create a new CheckboxTreeNode instance.
97 // description:
98 // Create a new CheckboxTreeNode instance.
99 return new lib._CheckBoxTreeNode(args);
100 }
101
102 });
103
104 });
105