mirror of
https://git.tt-rss.org/fox/tt-rss.git
synced 2025-08-07 06:37:44 +02:00
switch modules to new dojo definition format
This commit is contained in:
parent
546b419f52
commit
d39a2f8005
962
js/FeedTree.js
962
js/FeedTree.js
File diff suppressed because it is too large
Load Diff
@ -1,125 +1,126 @@
|
|||||||
dojo.provide("fox.PrefFeedTree");
|
require(["dojo/_base/declare", "dojo/data/ItemFileWriteStore"], function (declare) {
|
||||||
dojo.provide("fox.PrefFeedStore");
|
|
||||||
|
|
||||||
dojo.require("lib.CheckBoxTree");
|
return declare("fox.PrefFeedStore", dojo.data.ItemFileWriteStore, {
|
||||||
dojo.require("dojo.data.ItemFileWriteStore");
|
|
||||||
|
|
||||||
dojo.declare("fox.PrefFeedStore", dojo.data.ItemFileWriteStore, {
|
_saveEverything: function(saveCompleteCallback, saveFailedCallback,
|
||||||
|
newFileContentString) {
|
||||||
|
|
||||||
_saveEverything: function(saveCompleteCallback, saveFailedCallback,
|
dojo.xhrPost({
|
||||||
newFileContentString) {
|
url: "backend.php",
|
||||||
|
content: {op: "pref-feeds", method: "savefeedorder",
|
||||||
|
payload: newFileContentString},
|
||||||
|
error: saveFailedCallback,
|
||||||
|
load: saveCompleteCallback});
|
||||||
|
},
|
||||||
|
|
||||||
dojo.xhrPost({
|
});
|
||||||
url: "backend.php",
|
|
||||||
content: {op: "pref-feeds", method: "savefeedorder",
|
|
||||||
payload: newFileContentString},
|
|
||||||
error: saveFailedCallback,
|
|
||||||
load: saveCompleteCallback});
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
dojo.declare("fox.PrefFeedTree", lib.CheckBoxTree, {
|
require(["dojo/_base/declare", "lib/CheckBoxTree"], function (declare) {
|
||||||
_createTreeNode: function(args) {
|
|
||||||
var tnode = this.inherited(arguments);
|
|
||||||
|
|
||||||
if (args.item.icon)
|
return declare("fox.PrefFeedTree", lib.CheckBoxTree, {
|
||||||
tnode.iconNode.src = args.item.icon[0];
|
_createTreeNode: function(args) {
|
||||||
|
var tnode = this.inherited(arguments);
|
||||||
|
|
||||||
var param = this.model.store.getValue(args.item, 'param');
|
if (args.item.icon)
|
||||||
|
tnode.iconNode.src = args.item.icon[0];
|
||||||
|
|
||||||
if (param) {
|
var param = this.model.store.getValue(args.item, 'param');
|
||||||
param = dojo.doc.createElement('span');
|
|
||||||
param.className = 'feedParam';
|
|
||||||
param.innerHTML = args.item.param[0];
|
|
||||||
//dojo.place(param, tnode.labelNode, 'after');
|
|
||||||
dojo.place(param, tnode.rowNode, 'first');
|
|
||||||
}
|
|
||||||
|
|
||||||
var id = args.item.id[0];
|
if (param) {
|
||||||
var bare_id = parseInt(id.substr(id.indexOf(':')+1));
|
param = dojo.doc.createElement('span');
|
||||||
|
param.className = 'feedParam';
|
||||||
|
param.innerHTML = args.item.param[0];
|
||||||
|
//dojo.place(param, tnode.labelNode, 'after');
|
||||||
|
dojo.place(param, tnode.rowNode, 'first');
|
||||||
|
}
|
||||||
|
|
||||||
if (id.match("CAT:") && bare_id > 0) {
|
var id = args.item.id[0];
|
||||||
var menu = new dijit.Menu();
|
var bare_id = parseInt(id.substr(id.indexOf(':')+1));
|
||||||
menu.row_id = bare_id;
|
|
||||||
menu.item = args.item;
|
|
||||||
|
|
||||||
menu.addChild(new dijit.MenuItem({
|
if (id.match("CAT:") && bare_id > 0) {
|
||||||
label: __("Edit category"),
|
var menu = new dijit.Menu();
|
||||||
onClick: function() {
|
menu.row_id = bare_id;
|
||||||
editCat(this.getParent().row_id, this.getParent().item, null);
|
menu.item = args.item;
|
||||||
}}));
|
|
||||||
|
menu.addChild(new dijit.MenuItem({
|
||||||
|
label: __("Edit category"),
|
||||||
|
onClick: function() {
|
||||||
|
editCat(this.getParent().row_id, this.getParent().item, null);
|
||||||
|
}}));
|
||||||
|
|
||||||
|
|
||||||
menu.addChild(new dijit.MenuItem({
|
menu.addChild(new dijit.MenuItem({
|
||||||
label: __("Remove category"),
|
label: __("Remove category"),
|
||||||
onClick: function() {
|
onClick: function() {
|
||||||
removeCategory(this.getParent().row_id, this.getParent().item);
|
removeCategory(this.getParent().row_id, this.getParent().item);
|
||||||
}}));
|
}}));
|
||||||
|
|
||||||
menu.bindDomNode(tnode.domNode);
|
menu.bindDomNode(tnode.domNode);
|
||||||
tnode._menu = menu;
|
tnode._menu = menu;
|
||||||
} else if (id.match("FEED:")) {
|
} else if (id.match("FEED:")) {
|
||||||
var menu = new dijit.Menu();
|
var menu = new dijit.Menu();
|
||||||
menu.row_id = bare_id;
|
menu.row_id = bare_id;
|
||||||
menu.item = args.item;
|
menu.item = args.item;
|
||||||
|
|
||||||
menu.addChild(new dijit.MenuItem({
|
menu.addChild(new dijit.MenuItem({
|
||||||
label: __("Edit feed"),
|
label: __("Edit feed"),
|
||||||
onClick: function() {
|
onClick: function() {
|
||||||
editFeed(this.getParent().row_id);
|
editFeed(this.getParent().row_id);
|
||||||
}}));
|
}}));
|
||||||
|
|
||||||
menu.addChild(new dijit.MenuItem({
|
menu.addChild(new dijit.MenuItem({
|
||||||
label: __("Unsubscribe"),
|
label: __("Unsubscribe"),
|
||||||
onClick: function() {
|
onClick: function() {
|
||||||
unsubscribeFeed(this.getParent().row_id, this.getParent().item.name);
|
unsubscribeFeed(this.getParent().row_id, this.getParent().item.name);
|
||||||
}}));
|
}}));
|
||||||
|
|
||||||
menu.bindDomNode(tnode.domNode);
|
menu.bindDomNode(tnode.domNode);
|
||||||
tnode._menu = menu;
|
tnode._menu = menu;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return tnode;
|
return tnode;
|
||||||
},
|
},
|
||||||
onDndDrop: function() {
|
onDndDrop: function() {
|
||||||
this.inherited(arguments);
|
this.inherited(arguments);
|
||||||
this.tree.model.store.save();
|
this.tree.model.store.save();
|
||||||
},
|
},
|
||||||
getRowClass: function (item, opened) {
|
getRowClass: function (item, opened) {
|
||||||
return (!item.error || item.error == '') ? "dijitTreeRow" :
|
return (!item.error || item.error == '') ? "dijitTreeRow" :
|
||||||
"dijitTreeRow Error";
|
"dijitTreeRow Error";
|
||||||
},
|
},
|
||||||
getIconClass: function (item, opened) {
|
getIconClass: function (item, opened) {
|
||||||
return (!item || this.model.store.getValue(item, 'type') == 'category') ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feedIcon";
|
return (!item || this.model.store.getValue(item, 'type') == 'category') ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feedIcon";
|
||||||
},
|
},
|
||||||
checkItemAcceptance: function(target, source, position) {
|
checkItemAcceptance: function(target, source, position) {
|
||||||
var item = dijit.getEnclosingWidget(target).item;
|
var item = dijit.getEnclosingWidget(target).item;
|
||||||
|
|
||||||
// disable copying items
|
// disable copying items
|
||||||
source.copyState = function() { return false; };
|
source.copyState = function() { return false; };
|
||||||
|
|
||||||
var source_item = false;
|
var source_item = false;
|
||||||
|
|
||||||
source.forInSelectedItems(function(node) {
|
source.forInSelectedItems(function(node) {
|
||||||
source_item = node.data.item;
|
source_item = node.data.item;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!source_item || !item) return false;
|
if (!source_item || !item) return false;
|
||||||
|
|
||||||
var id = this.tree.model.store.getValue(item, 'id');
|
var id = this.tree.model.store.getValue(item, 'id');
|
||||||
var source_id = source.tree.model.store.getValue(source_item, 'id');
|
var source_id = source.tree.model.store.getValue(source_item, 'id');
|
||||||
|
|
||||||
//console.log(id + " " + position + " " + source_id);
|
//console.log(id + " " + position + " " + source_id);
|
||||||
|
|
||||||
if (source_id.match("FEED:")) {
|
if (source_id.match("FEED:")) {
|
||||||
return ((id.match("CAT:") && position == "over") ||
|
return ((id.match("CAT:") && position == "over") ||
|
||||||
(id.match("FEED:") && position != "over"));
|
(id.match("FEED:") && position != "over"));
|
||||||
} else if (source_id.match("CAT:")) {
|
} else if (source_id.match("CAT:")) {
|
||||||
return ((id.match("CAT:") && !id.match("CAT:0")) ||
|
return ((id.match("CAT:") && !id.match("CAT:0")) ||
|
||||||
(id.match("root") && position == "over"));
|
(id.match("root") && position == "over"));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,96 +1,102 @@
|
|||||||
dojo.provide("fox.PrefFilterTree");
|
require(["dojo/_base/declare", "dojo/data/ItemFileWriteStore"], function (declare) {
|
||||||
|
|
||||||
dojo.require("lib.CheckBoxTree");
|
return declare("fox.PrefFilterStore", dojo.data.ItemFileWriteStore, {
|
||||||
dojo.require("dojo.data.ItemFileWriteStore");
|
|
||||||
|
|
||||||
dojo.declare("fox.PrefFilterStore", dojo.data.ItemFileWriteStore, {
|
_saveEverything: function (saveCompleteCallback, saveFailedCallback,
|
||||||
|
newFileContentString) {
|
||||||
|
|
||||||
_saveEverything: function(saveCompleteCallback, saveFailedCallback,
|
dojo.xhrPost({
|
||||||
newFileContentString) {
|
url: "backend.php",
|
||||||
|
content: {
|
||||||
|
op: "pref-filters", method: "savefilterorder",
|
||||||
|
payload: newFileContentString
|
||||||
|
},
|
||||||
|
error: saveFailedCallback,
|
||||||
|
load: saveCompleteCallback
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
dojo.xhrPost({
|
});
|
||||||
url: "backend.php",
|
});
|
||||||
content: {op: "pref-filters", method: "savefilterorder",
|
|
||||||
payload: newFileContentString},
|
require(["dojo/_base/declare", "lib/CheckBoxTree"], function (declare) {
|
||||||
error: saveFailedCallback,
|
|
||||||
load: saveCompleteCallback});
|
return declare("fox.PrefFilterTree", lib.CheckBoxTree, {
|
||||||
},
|
_createTreeNode: function(args) {
|
||||||
|
var tnode = this.inherited(arguments);
|
||||||
|
|
||||||
|
var enabled = this.model.store.getValue(args.item, 'enabled');
|
||||||
|
var param = this.model.store.getValue(args.item, 'param');
|
||||||
|
var rules = this.model.store.getValue(args.item, 'rules');
|
||||||
|
|
||||||
|
if (param) {
|
||||||
|
param = dojo.doc.createElement('span');
|
||||||
|
param.className = (enabled != false) ? 'labelParam' : 'labelParam filterDisabled';
|
||||||
|
param.innerHTML = args.item.param[0];
|
||||||
|
dojo.place(param, tnode.rowNode, 'first');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rules) {
|
||||||
|
param = dojo.doc.createElement('span');
|
||||||
|
param.className = 'filterRules';
|
||||||
|
param.innerHTML = rules;
|
||||||
|
dojo.place(param, tnode.rowNode, 'next');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.model.store.getValue(args.item, 'id') != 'root') {
|
||||||
|
var img = dojo.doc.createElement('img');
|
||||||
|
img.src ='images/filter.png';
|
||||||
|
img.className = 'markedPic';
|
||||||
|
tnode._filterIconNode = img;
|
||||||
|
dojo.place(tnode._filterIconNode, tnode.labelNode, 'before');
|
||||||
|
}
|
||||||
|
|
||||||
|
return tnode;
|
||||||
|
},
|
||||||
|
|
||||||
|
getLabel: function(item) {
|
||||||
|
var label = item.name;
|
||||||
|
|
||||||
|
var feed = this.model.store.getValue(item, 'feed');
|
||||||
|
var inverse = this.model.store.getValue(item, 'inverse');
|
||||||
|
|
||||||
|
if (feed)
|
||||||
|
label += " (" + __("in") + " " + feed + ")";
|
||||||
|
|
||||||
|
if (inverse)
|
||||||
|
label += " (" + __("Inverse") + ")";
|
||||||
|
|
||||||
|
/* if (item.param)
|
||||||
|
label = "<span class=\"labelFixedLength\">" + label +
|
||||||
|
"</span>" + item.param[0]; */
|
||||||
|
|
||||||
|
return label;
|
||||||
|
},
|
||||||
|
getIconClass: function (item, opened) {
|
||||||
|
return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "invisible";
|
||||||
|
},
|
||||||
|
getLabelClass: function (item, opened) {
|
||||||
|
var enabled = this.model.store.getValue(item, 'enabled');
|
||||||
|
return (enabled != false) ? "dijitTreeLabel labelFixedLength" : "dijitTreeLabel labelFixedLength filterDisabled";
|
||||||
|
},
|
||||||
|
getRowClass: function (item, opened) {
|
||||||
|
return (!item.error || item.error == '') ? "dijitTreeRow" :
|
||||||
|
"dijitTreeRow Error";
|
||||||
|
},
|
||||||
|
checkItemAcceptance: function(target, source, position) {
|
||||||
|
var item = dijit.getEnclosingWidget(target).item;
|
||||||
|
|
||||||
|
// disable copying items
|
||||||
|
source.copyState = function() { return false; };
|
||||||
|
|
||||||
|
return position != 'over';
|
||||||
|
},
|
||||||
|
onDndDrop: function() {
|
||||||
|
this.inherited(arguments);
|
||||||
|
this.tree.model.store.save();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
dojo.declare("fox.PrefFilterTree", lib.CheckBoxTree, {
|
|
||||||
_createTreeNode: function(args) {
|
|
||||||
var tnode = this.inherited(arguments);
|
|
||||||
|
|
||||||
var enabled = this.model.store.getValue(args.item, 'enabled');
|
|
||||||
var param = this.model.store.getValue(args.item, 'param');
|
|
||||||
var rules = this.model.store.getValue(args.item, 'rules');
|
|
||||||
|
|
||||||
if (param) {
|
|
||||||
param = dojo.doc.createElement('span');
|
|
||||||
param.className = (enabled != false) ? 'labelParam' : 'labelParam filterDisabled';
|
|
||||||
param.innerHTML = args.item.param[0];
|
|
||||||
dojo.place(param, tnode.rowNode, 'first');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rules) {
|
|
||||||
param = dojo.doc.createElement('span');
|
|
||||||
param.className = 'filterRules';
|
|
||||||
param.innerHTML = rules;
|
|
||||||
dojo.place(param, tnode.rowNode, 'next');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.model.store.getValue(args.item, 'id') != 'root') {
|
|
||||||
var img = dojo.doc.createElement('img');
|
|
||||||
img.src ='images/filter.png';
|
|
||||||
img.className = 'markedPic';
|
|
||||||
tnode._filterIconNode = img;
|
|
||||||
dojo.place(tnode._filterIconNode, tnode.labelNode, 'before');
|
|
||||||
}
|
|
||||||
|
|
||||||
return tnode;
|
|
||||||
},
|
|
||||||
|
|
||||||
getLabel: function(item) {
|
|
||||||
var label = item.name;
|
|
||||||
|
|
||||||
var feed = this.model.store.getValue(item, 'feed');
|
|
||||||
var inverse = this.model.store.getValue(item, 'inverse');
|
|
||||||
|
|
||||||
if (feed)
|
|
||||||
label += " (" + __("in") + " " + feed + ")";
|
|
||||||
|
|
||||||
if (inverse)
|
|
||||||
label += " (" + __("Inverse") + ")";
|
|
||||||
|
|
||||||
/* if (item.param)
|
|
||||||
label = "<span class=\"labelFixedLength\">" + label +
|
|
||||||
"</span>" + item.param[0]; */
|
|
||||||
|
|
||||||
return label;
|
|
||||||
},
|
|
||||||
getIconClass: function (item, opened) {
|
|
||||||
return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "invisible";
|
|
||||||
},
|
|
||||||
getLabelClass: function (item, opened) {
|
|
||||||
var enabled = this.model.store.getValue(item, 'enabled');
|
|
||||||
return (enabled != false) ? "dijitTreeLabel labelFixedLength" : "dijitTreeLabel labelFixedLength filterDisabled";
|
|
||||||
},
|
|
||||||
getRowClass: function (item, opened) {
|
|
||||||
return (!item.error || item.error == '') ? "dijitTreeRow" :
|
|
||||||
"dijitTreeRow Error";
|
|
||||||
},
|
|
||||||
checkItemAcceptance: function(target, source, position) {
|
|
||||||
var item = dijit.getEnclosingWidget(target).item;
|
|
||||||
|
|
||||||
// disable copying items
|
|
||||||
source.copyState = function() { return false; };
|
|
||||||
|
|
||||||
return position != 'over';
|
|
||||||
},
|
|
||||||
onDndDrop: function() {
|
|
||||||
this.inherited(arguments);
|
|
||||||
this.tree.model.store.save();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
|
@ -1,43 +1,43 @@
|
|||||||
dojo.provide("fox.PrefLabelTree");
|
require(["dojo/_base/declare", "lib/CheckBoxTree", "dijit/form/DropDownButton"], function (declare) {
|
||||||
|
|
||||||
dojo.require("lib.CheckBoxTree");
|
return declare("fox.PrefLabelTree", lib.CheckBoxTree, {
|
||||||
dojo.require("dijit.form.DropDownButton");
|
setNameById: function (id, name) {
|
||||||
|
var item = this.model.store._itemsByIdentity['LABEL:' + id];
|
||||||
|
|
||||||
dojo.declare("fox.PrefLabelTree", lib.CheckBoxTree, {
|
if (item)
|
||||||
setNameById: function (id, name) {
|
this.model.store.setValue(item, 'name', name);
|
||||||
var item = this.model.store._itemsByIdentity['LABEL:' + id];
|
|
||||||
|
|
||||||
if (item)
|
},
|
||||||
this.model.store.setValue(item, 'name', name);
|
_createTreeNode: function(args) {
|
||||||
|
var tnode = this.inherited(arguments);
|
||||||
|
|
||||||
},
|
var fg_color = this.model.store.getValue(args.item, 'fg_color');
|
||||||
_createTreeNode: function(args) {
|
var bg_color = this.model.store.getValue(args.item, 'bg_color');
|
||||||
var tnode = this.inherited(arguments);
|
var type = this.model.store.getValue(args.item, 'type');
|
||||||
|
var bare_id = this.model.store.getValue(args.item, 'bare_id');
|
||||||
|
|
||||||
var fg_color = this.model.store.getValue(args.item, 'fg_color');
|
if (type == 'label') {
|
||||||
var bg_color = this.model.store.getValue(args.item, 'bg_color');
|
var span = dojo.doc.createElement('span');
|
||||||
var type = this.model.store.getValue(args.item, 'type');
|
span.innerHTML = 'α';
|
||||||
var bare_id = this.model.store.getValue(args.item, 'bare_id');
|
span.className = 'labelColorIndicator';
|
||||||
|
span.id = 'LICID-' + bare_id;
|
||||||
|
|
||||||
if (type == 'label') {
|
span.setStyle({
|
||||||
var span = dojo.doc.createElement('span');
|
color: fg_color,
|
||||||
span.innerHTML = 'α';
|
backgroundColor: bg_color});
|
||||||
span.className = 'labelColorIndicator';
|
|
||||||
span.id = 'LICID-' + bare_id;
|
|
||||||
|
|
||||||
span.setStyle({
|
tnode._labelIconNode = span;
|
||||||
color: fg_color,
|
|
||||||
backgroundColor: bg_color});
|
|
||||||
|
|
||||||
tnode._labelIconNode = span;
|
dojo.place(tnode._labelIconNode, tnode.labelNode, 'before');
|
||||||
|
}
|
||||||
|
|
||||||
dojo.place(tnode._labelIconNode, tnode.labelNode, 'before');
|
return tnode;
|
||||||
}
|
},
|
||||||
|
getIconClass: function (item, opened) {
|
||||||
|
return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "invisible";
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return tnode;
|
|
||||||
},
|
|
||||||
getIconClass: function (item, opened) {
|
|
||||||
return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "invisible";
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
11
js/prefs.js
11
js/prefs.js
@ -943,15 +943,12 @@ function init() {
|
|||||||
"dijit/Toolbar",
|
"dijit/Toolbar",
|
||||||
"dijit/Tree",
|
"dijit/Tree",
|
||||||
"dijit/tree/dndSource",
|
"dijit/tree/dndSource",
|
||||||
"dojo/data/ItemFileWriteStore"], function (dojo, ready, parser) {
|
"dojo/data/ItemFileWriteStore",
|
||||||
|
"fox/PrefFeedTree",
|
||||||
|
"fox/PrefFilterTree",
|
||||||
|
"fox/PrefLabelTree" ], function (dojo, ready, parser) {
|
||||||
|
|
||||||
ready(function() {
|
ready(function() {
|
||||||
|
|
||||||
dojo.require("lib.CheckBoxTree");
|
|
||||||
dojo.require("fox.PrefFeedTree");
|
|
||||||
dojo.require("fox.PrefFilterTree");
|
|
||||||
dojo.require("fox.PrefLabelTree");
|
|
||||||
|
|
||||||
parser.parse();
|
parser.parse();
|
||||||
|
|
||||||
loading_set_progress(50);
|
loading_set_progress(50);
|
||||||
|
@ -248,12 +248,11 @@ function init() {
|
|||||||
"dijit/Tree",
|
"dijit/Tree",
|
||||||
"dijit/tree/dndSource",
|
"dijit/tree/dndSource",
|
||||||
"dijit/tree/ForestStoreModel",
|
"dijit/tree/ForestStoreModel",
|
||||||
"dojo/data/ItemFileWriteStore" ], function (dojo, ready, parser) {
|
"dojo/data/ItemFileWriteStore",
|
||||||
|
"fox/FeedTree" ], function (dojo, ready, parser) {
|
||||||
|
|
||||||
ready(function() {
|
ready(function() {
|
||||||
|
|
||||||
dojo.require("fox.FeedTree");
|
|
||||||
|
|
||||||
parser.parse();
|
parser.parse();
|
||||||
|
|
||||||
if (!genericSanityCheck())
|
if (!genericSanityCheck())
|
||||||
|
@ -1,474 +1,486 @@
|
|||||||
dojo.provide("lib.CheckBoxTree");
|
//dojo.provide("lib.CheckBoxTree");
|
||||||
dojo.provide("lib.CheckBoxStoreModel");
|
//dojo.provide("lib.CheckBoxStoreModel");
|
||||||
|
|
||||||
// THIS WIDGET IS BASED ON DOJO/DIJIT 1.4.0 AND WILL NOT WORK WITH PREVIOUS VERSIONS
|
// THIS WIDGET IS BASED ON DOJO/DIJIT 1.4.0 AND WILL NOT WORK WITH PREVIOUS VERSIONS
|
||||||
//
|
//
|
||||||
// Release date: 02/05/2010
|
// Release date: 02/05/2010
|
||||||
//
|
//
|
||||||
|
|
||||||
dojo.require("dijit.Tree");
|
//dojo.require("dijit.Tree");
|
||||||
dojo.require("dijit.form.CheckBox");
|
//dojo.require("dijit.form.CheckBox");
|
||||||
|
|
||||||
dojo.declare( "lib.CheckBoxStoreModel", dijit.tree.TreeStoreModel,
|
require(["dojo/_base/declare", "dijit/tree/TreeStoreModel"], function (declare) {
|
||||||
{
|
|
||||||
// checkboxAll: Boolean
|
|
||||||
// If true, every node in the tree will receive a checkbox regardless if the 'checkbox' attribute
|
|
||||||
// is specified in the dojo.data.
|
|
||||||
checkboxAll: true,
|
|
||||||
|
|
||||||
// checkboxState: Boolean
|
return declare( "lib.CheckBoxStoreModel", dijit.tree.TreeStoreModel,
|
||||||
// The default state applied to every checkbox unless otherwise specified in the dojo.data.
|
{
|
||||||
// (see also: checkboxIdent)
|
// checkboxAll: Boolean
|
||||||
checkboxState: false,
|
// If true, every node in the tree will receive a checkbox regardless if the 'checkbox' attribute
|
||||||
|
// is specified in the dojo.data.
|
||||||
|
checkboxAll: true,
|
||||||
|
|
||||||
// checkboxRoot: Boolean
|
// checkboxState: Boolean
|
||||||
// If true, the root node will receive a checkbox eventhough it's not a true entry in the store.
|
// The default state applied to every checkbox unless otherwise specified in the dojo.data.
|
||||||
// This attribute is independent of the showRoot attribute of the tree itself. If the tree
|
// (see also: checkboxIdent)
|
||||||
// attribute 'showRoot' is set to false to checkbox for the root will not show either.
|
checkboxState: false,
|
||||||
checkboxRoot: false,
|
|
||||||
|
|
||||||
// checkboxStrict: Boolean
|
// checkboxRoot: Boolean
|
||||||
// If true, a strict parent-child checkbox relation is maintained. For example, if all children
|
// If true, the root node will receive a checkbox eventhough it's not a true entry in the store.
|
||||||
// are checked the parent will automatically be checked or if any of the children are unchecked
|
// This attribute is independent of the showRoot attribute of the tree itself. If the tree
|
||||||
// the parent will be unchecked.
|
// attribute 'showRoot' is set to false to checkbox for the root will not show either.
|
||||||
checkboxStrict: true,
|
checkboxRoot: false,
|
||||||
|
|
||||||
// checkboxIdent: String
|
// checkboxStrict: Boolean
|
||||||
// The attribute name (attribute of the dojo.data.item) that specifies that items checkbox initial
|
// If true, a strict parent-child checkbox relation is maintained. For example, if all children
|
||||||
// state. Example: { name:'Egypt', type:'country', checkbox: true }
|
// are checked the parent will automatically be checked or if any of the children are unchecked
|
||||||
// If a dojo.data.item has no 'checkbox' attribute specified it will depend on the attribute
|
// the parent will be unchecked.
|
||||||
// 'checkboxAll' if one will be created automatically and if so what the initial state will be as
|
checkboxStrict: true,
|
||||||
// specified by 'checkboxState'.
|
|
||||||
checkboxIdent: "checkbox",
|
|
||||||
|
|
||||||
updateCheckbox: function(/*dojo.data.Item*/ storeItem, /*Boolean*/ newState ) {
|
// checkboxIdent: String
|
||||||
// summary:
|
// The attribute name (attribute of the dojo.data.item) that specifies that items checkbox initial
|
||||||
// Update the checkbox state (true/false) for the item and the associated parent and
|
// state. Example: { name:'Egypt', type:'country', checkbox: true }
|
||||||
// child checkboxes if any.
|
// If a dojo.data.item has no 'checkbox' attribute specified it will depend on the attribute
|
||||||
// description:
|
// 'checkboxAll' if one will be created automatically and if so what the initial state will be as
|
||||||
// Update a single checkbox state (true/false) for the item and the associated parent
|
// specified by 'checkboxState'.
|
||||||
// and child checkboxes if any. This function is called from the tree if a user checked
|
checkboxIdent: "checkbox",
|
||||||
// or unchecked a checkbox on the tree. The parent and child tree nodes are updated to
|
|
||||||
// maintain consistency if 'checkboxStrict' is set to true.
|
|
||||||
// storeItem:
|
|
||||||
// The item in the dojo.data.store whos checkbox state needs updating.
|
|
||||||
// newState:
|
|
||||||
// The new state of the checkbox: true or false
|
|
||||||
// example:
|
|
||||||
// | model.updateCheckboxState(item, true);
|
|
||||||
//
|
|
||||||
|
|
||||||
this._setCheckboxState( storeItem, newState );
|
updateCheckbox: function(/*dojo.data.Item*/ storeItem, /*Boolean*/ newState ) {
|
||||||
//if( this.checkboxStrict ) { I don't need all this 1-1 stuff, only parent -> child (fox)
|
// summary:
|
||||||
this._updateChildCheckbox( storeItem, newState );
|
// Update the checkbox state (true/false) for the item and the associated parent and
|
||||||
//this._updateParentCheckbox( storeItem, newState );
|
// child checkboxes if any.
|
||||||
//}
|
// description:
|
||||||
},
|
// Update a single checkbox state (true/false) for the item and the associated parent
|
||||||
setAllChecked: function(checked) {
|
// and child checkboxes if any. This function is called from the tree if a user checked
|
||||||
var items = this.store._arrayOfAllItems;
|
// or unchecked a checkbox on the tree. The parent and child tree nodes are updated to
|
||||||
this.setCheckboxState(items, checked);
|
// maintain consistency if 'checkboxStrict' is set to true.
|
||||||
},
|
// storeItem:
|
||||||
setCheckboxState: function(items, checked) {
|
// The item in the dojo.data.store whos checkbox state needs updating.
|
||||||
for (var i = 0; i < items.length; i++) {
|
// newState:
|
||||||
this._setCheckboxState(items[i], checked);
|
// The new state of the checkbox: true or false
|
||||||
}
|
// example:
|
||||||
},
|
// | model.updateCheckboxState(item, true);
|
||||||
getCheckedItems: function() {
|
//
|
||||||
var items = this.store._arrayOfAllItems;
|
|
||||||
var result = [];
|
|
||||||
|
|
||||||
for (var i = 0; i < items.length; i++) {
|
this._setCheckboxState( storeItem, newState );
|
||||||
if (this.store.getValue(items[i], 'checkbox'))
|
//if( this.checkboxStrict ) { I don't need all this 1-1 stuff, only parent -> child (fox)
|
||||||
result.push(items[i]);
|
this._updateChildCheckbox( storeItem, newState );
|
||||||
}
|
//this._updateParentCheckbox( storeItem, newState );
|
||||||
|
//}
|
||||||
return result;
|
},
|
||||||
},
|
setAllChecked: function(checked) {
|
||||||
|
var items = this.store._arrayOfAllItems;
|
||||||
getCheckboxState: function(/*dojo.data.Item*/ storeItem) {
|
this.setCheckboxState(items, checked);
|
||||||
// summary:
|
},
|
||||||
// Get the current checkbox state from the dojo.data.store.
|
setCheckboxState: function(items, checked) {
|
||||||
// description:
|
for (var i = 0; i < items.length; i++) {
|
||||||
// Get the current checkbox state from the dojo.data store. A checkbox can have three
|
this._setCheckboxState(items[i], checked);
|
||||||
// different states: true, false or undefined. Undefined in this context means no
|
|
||||||
// checkbox identifier (checkboxIdent) was found in the dojo.data store. Depending on
|
|
||||||
// the checkbox attributes as specified above the following will take place:
|
|
||||||
// a) If the current checkbox state is undefined and the checkbox attribute 'checkboxAll' or
|
|
||||||
// 'checkboxRoot' is true one will be created and the default state 'checkboxState' will
|
|
||||||
// be applied.
|
|
||||||
// b) If the current state is undefined and 'checkboxAll' is false the state undefined remains
|
|
||||||
// unchanged and is returned. This will prevent any tree node from creating a checkbox.
|
|
||||||
//
|
|
||||||
// storeItem:
|
|
||||||
// The item in the dojo.data.store whos checkbox state is returned.
|
|
||||||
// example:
|
|
||||||
// | var currState = model.getCheckboxState(item);
|
|
||||||
//
|
|
||||||
var currState = undefined;
|
|
||||||
|
|
||||||
// Special handling required for the 'fake' root entry (the root is NOT a dojo.data.item).
|
|
||||||
// this stuff is only relevant for Forest store -fox
|
|
||||||
/* if ( storeItem == this.root ) {
|
|
||||||
if( typeof(storeItem.checkbox) == "undefined" ) {
|
|
||||||
this.root.checkbox = undefined; // create a new checbox reference as undefined.
|
|
||||||
if( this.checkboxRoot ) {
|
|
||||||
currState = this.root.checkbox = this.checkboxState;
|
|
||||||
}
|
}
|
||||||
} else {
|
},
|
||||||
currState = this.root.checkbox;
|
getCheckedItems: function() {
|
||||||
}
|
var items = this.store._arrayOfAllItems;
|
||||||
} else { // a valid dojo.store.item
|
var result = [];
|
||||||
currState = this.store.getValue(storeItem, this.checkboxIdent);
|
|
||||||
if( currState == undefined && this.checkboxAll) {
|
|
||||||
this._setCheckboxState( storeItem, this.checkboxState );
|
|
||||||
currState = this.checkboxState;
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
|
|
||||||
currState = this.store.getValue(storeItem, this.checkboxIdent);
|
for (var i = 0; i < items.length; i++) {
|
||||||
if( currState == undefined && this.checkboxAll) {
|
if (this.store.getValue(items[i], 'checkbox'))
|
||||||
this._setCheckboxState( storeItem, this.checkboxState );
|
result.push(items[i]);
|
||||||
currState = this.checkboxState;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return currState; // the current state of the checkbox (true/false or undefined)
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
_setCheckboxState: function(/*dojo.data.Item*/ storeItem, /*Boolean*/ newState ) {
|
getCheckboxState: function(/*dojo.data.Item*/ storeItem) {
|
||||||
// summary:
|
// summary:
|
||||||
// Set/update the checkbox state on the dojo.data store.
|
// Get the current checkbox state from the dojo.data.store.
|
||||||
// description:
|
// description:
|
||||||
// Set/update the checkbox state on the dojo.data.store. Retreive the current
|
// Get the current checkbox state from the dojo.data store. A checkbox can have three
|
||||||
// state of the checkbox and validate if an update is required, this will keep
|
// different states: true, false or undefined. Undefined in this context means no
|
||||||
// update events to a minimum. On completion a 'onCheckboxChange' event is
|
// checkbox identifier (checkboxIdent) was found in the dojo.data store. Depending on
|
||||||
// triggered.
|
// the checkbox attributes as specified above the following will take place:
|
||||||
// If the current state is undefined (ie: no checkbox attribute specified for
|
// a) If the current checkbox state is undefined and the checkbox attribute 'checkboxAll' or
|
||||||
// this dojo.data.item) the 'checkboxAll' attribute is checked to see if one
|
// 'checkboxRoot' is true one will be created and the default state 'checkboxState' will
|
||||||
// needs to be created. In case of the root the 'checkboxRoot' attribute is checked.
|
// be applied.
|
||||||
// NOTE: the store.setValue function will create the 'checkbox' attribute for the
|
// b) If the current state is undefined and 'checkboxAll' is false the state undefined remains
|
||||||
// item if none exists.
|
// unchanged and is returned. This will prevent any tree node from creating a checkbox.
|
||||||
// storeItem:
|
//
|
||||||
// The item in the dojo.data.store whos checkbox state is updated.
|
// storeItem:
|
||||||
// newState:
|
// The item in the dojo.data.store whos checkbox state is returned.
|
||||||
// The new state of the checkbox: true or false
|
// example:
|
||||||
// example:
|
// | var currState = model.getCheckboxState(item);
|
||||||
// | model.setCheckboxState(item, true);
|
//
|
||||||
//
|
var currState = undefined;
|
||||||
var stateChanged = true;
|
|
||||||
|
|
||||||
if( storeItem != this.root ) {
|
// Special handling required for the 'fake' root entry (the root is NOT a dojo.data.item).
|
||||||
var currState = this.store.getValue(storeItem, this.checkboxIdent);
|
// this stuff is only relevant for Forest store -fox
|
||||||
if( currState != newState && ( currState !== undefined || this.checkboxAll ) ) {
|
/* if ( storeItem == this.root ) {
|
||||||
this.store.setValue(storeItem, this.checkboxIdent, newState);
|
if( typeof(storeItem.checkbox) == "undefined" ) {
|
||||||
} else {
|
this.root.checkbox = undefined; // create a new checbox reference as undefined.
|
||||||
stateChanged = false; // No changes to the checkbox
|
if( this.checkboxRoot ) {
|
||||||
}
|
currState = this.root.checkbox = this.checkboxState;
|
||||||
} else { // Tree root instance
|
}
|
||||||
if( this.root.checkbox != newState && ( this.root.checkbox !== undefined || this.checkboxRoot ) ) {
|
} else {
|
||||||
this.root.checkbox = newState;
|
currState = this.root.checkbox;
|
||||||
} else {
|
}
|
||||||
stateChanged = false;
|
} else { // a valid dojo.store.item
|
||||||
}
|
currState = this.store.getValue(storeItem, this.checkboxIdent);
|
||||||
}
|
if( currState == undefined && this.checkboxAll) {
|
||||||
if( stateChanged ) { // In case of any changes trigger the update event.
|
this._setCheckboxState( storeItem, this.checkboxState );
|
||||||
this.onCheckboxChange(storeItem);
|
currState = this.checkboxState;
|
||||||
}
|
}
|
||||||
return stateChanged;
|
} */
|
||||||
},
|
|
||||||
|
|
||||||
_updateChildCheckbox: function(/*dojo.data.Item*/ parentItem, /*Boolean*/ newState ) {
|
currState = this.store.getValue(storeItem, this.checkboxIdent);
|
||||||
// summary:
|
if( currState == undefined && this.checkboxAll) {
|
||||||
// Set all child checkboxes to true/false depending on the parent checkbox state.
|
this._setCheckboxState( storeItem, this.checkboxState );
|
||||||
// description:
|
currState = this.checkboxState;
|
||||||
// If a parent checkbox changes state, all child and grandchild checkboxes will be
|
}
|
||||||
// updated to reflect the change. For example, if the parent state is set to true,
|
|
||||||
// all child and grandchild checkboxes will receive that same 'true' state.
|
|
||||||
// If a child checkbox changes state and has multiple parent, all of its parents
|
|
||||||
// need to be re-evaluated.
|
|
||||||
// parentItem:
|
|
||||||
// The parent dojo.data.item whos child/grandchild checkboxes require updating.
|
|
||||||
// newState:
|
|
||||||
// The new state of the checkbox: true or false
|
|
||||||
//
|
|
||||||
|
|
||||||
if( this.mayHaveChildren( parentItem )) {
|
return currState; // the current state of the checkbox (true/false or undefined)
|
||||||
this.getChildren( parentItem, dojo.hitch( this,
|
},
|
||||||
function( children ) {
|
|
||||||
dojo.forEach( children, function(child) {
|
_setCheckboxState: function(/*dojo.data.Item*/ storeItem, /*Boolean*/ newState ) {
|
||||||
if( this._setCheckboxState(child, newState) ) {
|
// summary:
|
||||||
var parents = this._getParentsItem(child);
|
// Set/update the checkbox state on the dojo.data store.
|
||||||
if( parents.length > 1 ) {
|
// description:
|
||||||
this._updateParentCheckbox( child, newState );
|
// Set/update the checkbox state on the dojo.data.store. Retreive the current
|
||||||
|
// state of the checkbox and validate if an update is required, this will keep
|
||||||
|
// update events to a minimum. On completion a 'onCheckboxChange' event is
|
||||||
|
// triggered.
|
||||||
|
// If the current state is undefined (ie: no checkbox attribute specified for
|
||||||
|
// this dojo.data.item) the 'checkboxAll' attribute is checked to see if one
|
||||||
|
// needs to be created. In case of the root the 'checkboxRoot' attribute is checked.
|
||||||
|
// NOTE: the store.setValue function will create the 'checkbox' attribute for the
|
||||||
|
// item if none exists.
|
||||||
|
// storeItem:
|
||||||
|
// The item in the dojo.data.store whos checkbox state is updated.
|
||||||
|
// newState:
|
||||||
|
// The new state of the checkbox: true or false
|
||||||
|
// example:
|
||||||
|
// | model.setCheckboxState(item, true);
|
||||||
|
//
|
||||||
|
var stateChanged = true;
|
||||||
|
|
||||||
|
if( storeItem != this.root ) {
|
||||||
|
var currState = this.store.getValue(storeItem, this.checkboxIdent);
|
||||||
|
if( currState != newState && ( currState !== undefined || this.checkboxAll ) ) {
|
||||||
|
this.store.setValue(storeItem, this.checkboxIdent, newState);
|
||||||
|
} else {
|
||||||
|
stateChanged = false; // No changes to the checkbox
|
||||||
|
}
|
||||||
|
} else { // Tree root instance
|
||||||
|
if( this.root.checkbox != newState && ( this.root.checkbox !== undefined || this.checkboxRoot ) ) {
|
||||||
|
this.root.checkbox = newState;
|
||||||
|
} else {
|
||||||
|
stateChanged = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( stateChanged ) { // In case of any changes trigger the update event.
|
||||||
|
this.onCheckboxChange(storeItem);
|
||||||
|
}
|
||||||
|
return stateChanged;
|
||||||
|
},
|
||||||
|
|
||||||
|
_updateChildCheckbox: function(/*dojo.data.Item*/ parentItem, /*Boolean*/ newState ) {
|
||||||
|
// summary:
|
||||||
|
// Set all child checkboxes to true/false depending on the parent checkbox state.
|
||||||
|
// description:
|
||||||
|
// If a parent checkbox changes state, all child and grandchild checkboxes will be
|
||||||
|
// updated to reflect the change. For example, if the parent state is set to true,
|
||||||
|
// all child and grandchild checkboxes will receive that same 'true' state.
|
||||||
|
// If a child checkbox changes state and has multiple parent, all of its parents
|
||||||
|
// need to be re-evaluated.
|
||||||
|
// parentItem:
|
||||||
|
// The parent dojo.data.item whos child/grandchild checkboxes require updating.
|
||||||
|
// newState:
|
||||||
|
// The new state of the checkbox: true or false
|
||||||
|
//
|
||||||
|
|
||||||
|
if( this.mayHaveChildren( parentItem )) {
|
||||||
|
this.getChildren( parentItem, dojo.hitch( this,
|
||||||
|
function( children ) {
|
||||||
|
dojo.forEach( children, function(child) {
|
||||||
|
if( this._setCheckboxState(child, newState) ) {
|
||||||
|
var parents = this._getParentsItem(child);
|
||||||
|
if( parents.length > 1 ) {
|
||||||
|
this._updateParentCheckbox( child, newState );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( this.mayHaveChildren( child )) {
|
||||||
|
this._updateChildCheckbox( child, newState );
|
||||||
|
}
|
||||||
|
}, this );
|
||||||
|
}),
|
||||||
|
function(err) {
|
||||||
|
console.error(this, ": updating child checkboxes: ", err);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_updateParentCheckbox: function(/*dojo.data.Item*/ storeItem, /*Boolean*/ newState ) {
|
||||||
|
// summary:
|
||||||
|
// Update the parent checkbox state depending on the state of all child checkboxes.
|
||||||
|
// description:
|
||||||
|
// Update the parent checkbox state depending on the state of all child checkboxes.
|
||||||
|
// The parent checkbox automatically changes state if ALL child checkboxes are true
|
||||||
|
// or false. If, as a result, the parent checkbox changes state, we will check if
|
||||||
|
// its parent needs to be updated as well all the way upto the root.
|
||||||
|
// storeItem:
|
||||||
|
// The dojo.data.item whos parent checkboxes require updating.
|
||||||
|
// newState:
|
||||||
|
// The new state of the checkbox: true or false
|
||||||
|
//
|
||||||
|
var parents = this._getParentsItem(storeItem);
|
||||||
|
dojo.forEach( parents, function( parentItem ) {
|
||||||
|
if( newState ) { // new state = true (checked)
|
||||||
|
this.getChildren( parentItem, dojo.hitch( this,
|
||||||
|
function(siblings) {
|
||||||
|
var allChecked = true;
|
||||||
|
dojo.some( siblings, function(sibling) {
|
||||||
|
siblState = this.getCheckboxState(sibling);
|
||||||
|
if( siblState !== undefined && allChecked )
|
||||||
|
allChecked = siblState;
|
||||||
|
return !(allChecked);
|
||||||
|
}, this );
|
||||||
|
if( allChecked ) {
|
||||||
|
this._setCheckboxState( parentItem, true );
|
||||||
|
this._updateParentCheckbox( parentItem, true );
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
function(err) {
|
||||||
|
console.error(this, ": updating parent checkboxes: ", err);
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
} else { // new state = false (unchecked)
|
||||||
|
if( this._setCheckboxState( parentItem, false ) ) {
|
||||||
|
this._updateParentCheckbox( parentItem, false );
|
||||||
}
|
}
|
||||||
if( this.mayHaveChildren( child )) {
|
}
|
||||||
this._updateChildCheckbox( child, newState );
|
}, this );
|
||||||
}
|
},
|
||||||
}, this );
|
|
||||||
}),
|
|
||||||
function(err) {
|
|
||||||
console.error(this, ": updating child checkboxes: ", err);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_updateParentCheckbox: function(/*dojo.data.Item*/ storeItem, /*Boolean*/ newState ) {
|
_getParentsItem: function(/*dojo.data.Item*/ storeItem ) {
|
||||||
// summary:
|
// summary:
|
||||||
// Update the parent checkbox state depending on the state of all child checkboxes.
|
// Get the parent(s) of a dojo.data item.
|
||||||
// description:
|
// description:
|
||||||
// Update the parent checkbox state depending on the state of all child checkboxes.
|
// Get the parent(s) of a dojo.data item. The '_reverseRefMap' entry of the item is
|
||||||
// The parent checkbox automatically changes state if ALL child checkboxes are true
|
// used to identify the parent(s). A child will have a parent reference if the parent
|
||||||
// or false. If, as a result, the parent checkbox changes state, we will check if
|
// specified the '_reference' attribute.
|
||||||
// its parent needs to be updated as well all the way upto the root.
|
// For example: children:[{_reference:'Mexico'}, {_reference:'Canada'}, ...
|
||||||
// storeItem:
|
// storeItem:
|
||||||
// The dojo.data.item whos parent checkboxes require updating.
|
// The dojo.data.item whos parent(s) will be returned.
|
||||||
// newState:
|
//
|
||||||
// The new state of the checkbox: true or false
|
var parents = [];
|
||||||
//
|
|
||||||
var parents = this._getParentsItem(storeItem);
|
if( storeItem != this.root ) {
|
||||||
dojo.forEach( parents, function( parentItem ) {
|
var references = storeItem[this.store._reverseRefMap];
|
||||||
if( newState ) { // new state = true (checked)
|
for(itemId in references ) {
|
||||||
this.getChildren( parentItem, dojo.hitch( this,
|
parents.push(this.store._itemsByIdentity[itemId]);
|
||||||
function(siblings) {
|
}
|
||||||
|
if (!parents.length) {
|
||||||
|
parents.push(this.root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parents; // parent(s) of a dojo.data.item (Array of dojo.data.items)
|
||||||
|
},
|
||||||
|
|
||||||
|
validateData: function(/*dojo.data.Item*/ storeItem, /*thisObject*/ scope ) {
|
||||||
|
// summary:
|
||||||
|
// Validate/normalize the parent(s) checkbox data in the dojo.data store.
|
||||||
|
// description:
|
||||||
|
// Validate/normalize the parent-child checkbox relationship if the attribute
|
||||||
|
// 'checkboxStrict' is set to true. This function is called as part of the post
|
||||||
|
// creation of the Tree instance. All parent checkboxes are set to the appropriate
|
||||||
|
// state according to the actual state(s) of their children.
|
||||||
|
// This will potentionally overwrite whatever was specified for the parent in the
|
||||||
|
// dojo.data store. This will garantee the tree is in a consistent state after startup.
|
||||||
|
// storeItem:
|
||||||
|
// The element to start traversing the dojo.data.store, typically model.root
|
||||||
|
// scope:
|
||||||
|
// The scope to use when this method executes.
|
||||||
|
// example:
|
||||||
|
// | this.model.validateData(this.model.root, this.model);
|
||||||
|
//
|
||||||
|
if( !scope.checkboxStrict ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
scope.getChildren( storeItem, dojo.hitch( scope,
|
||||||
|
function(children) {
|
||||||
var allChecked = true;
|
var allChecked = true;
|
||||||
dojo.some( siblings, function(sibling) {
|
var childState;
|
||||||
siblState = this.getCheckboxState(sibling);
|
dojo.forEach( children, function( child ) {
|
||||||
if( siblState !== undefined && allChecked )
|
if( this.mayHaveChildren( child )) {
|
||||||
allChecked = siblState;
|
this.validateData( child, this );
|
||||||
return !(allChecked);
|
}
|
||||||
}, this );
|
childState = this.getCheckboxState( child );
|
||||||
if( allChecked ) {
|
if( childState !== undefined && allChecked )
|
||||||
this._setCheckboxState( parentItem, true );
|
allChecked = childState;
|
||||||
this._updateParentCheckbox( parentItem, true );
|
}, this);
|
||||||
|
|
||||||
|
if ( this._setCheckboxState( storeItem, allChecked) ) {
|
||||||
|
this._updateParentCheckbox( storeItem, allChecked);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
function(err) {
|
function(err) {
|
||||||
console.error(this, ": updating parent checkboxes: ", err);
|
console.error(this, ": validating checkbox data: ", err);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else { // new state = false (unchecked)
|
},
|
||||||
if( this._setCheckboxState( parentItem, false ) ) {
|
|
||||||
this._updateParentCheckbox( parentItem, false );
|
onCheckboxChange: function(/*dojo.data.Item*/ storeItem ) {
|
||||||
}
|
// summary:
|
||||||
|
// Callback whenever a checkbox state has changed state, so that
|
||||||
|
// the Tree can update the checkbox. This callback is generally
|
||||||
|
// triggered by the '_setCheckboxState' function.
|
||||||
|
// tags:
|
||||||
|
// callback
|
||||||
}
|
}
|
||||||
}, this );
|
|
||||||
},
|
|
||||||
|
|
||||||
_getParentsItem: function(/*dojo.data.Item*/ storeItem ) {
|
});
|
||||||
// summary:
|
|
||||||
// Get the parent(s) of a dojo.data item.
|
|
||||||
// description:
|
|
||||||
// Get the parent(s) of a dojo.data item. The '_reverseRefMap' entry of the item is
|
|
||||||
// used to identify the parent(s). A child will have a parent reference if the parent
|
|
||||||
// specified the '_reference' attribute.
|
|
||||||
// For example: children:[{_reference:'Mexico'}, {_reference:'Canada'}, ...
|
|
||||||
// storeItem:
|
|
||||||
// The dojo.data.item whos parent(s) will be returned.
|
|
||||||
//
|
|
||||||
var parents = [];
|
|
||||||
|
|
||||||
if( storeItem != this.root ) {
|
|
||||||
var references = storeItem[this.store._reverseRefMap];
|
|
||||||
for(itemId in references ) {
|
|
||||||
parents.push(this.store._itemsByIdentity[itemId]);
|
|
||||||
}
|
|
||||||
if (!parents.length) {
|
|
||||||
parents.push(this.root);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return parents; // parent(s) of a dojo.data.item (Array of dojo.data.items)
|
|
||||||
},
|
|
||||||
|
|
||||||
validateData: function(/*dojo.data.Item*/ storeItem, /*thisObject*/ scope ) {
|
|
||||||
// summary:
|
|
||||||
// Validate/normalize the parent(s) checkbox data in the dojo.data store.
|
|
||||||
// description:
|
|
||||||
// Validate/normalize the parent-child checkbox relationship if the attribute
|
|
||||||
// 'checkboxStrict' is set to true. This function is called as part of the post
|
|
||||||
// creation of the Tree instance. All parent checkboxes are set to the appropriate
|
|
||||||
// state according to the actual state(s) of their children.
|
|
||||||
// This will potentionally overwrite whatever was specified for the parent in the
|
|
||||||
// dojo.data store. This will garantee the tree is in a consistent state after startup.
|
|
||||||
// storeItem:
|
|
||||||
// The element to start traversing the dojo.data.store, typically model.root
|
|
||||||
// scope:
|
|
||||||
// The scope to use when this method executes.
|
|
||||||
// example:
|
|
||||||
// | this.model.validateData(this.model.root, this.model);
|
|
||||||
//
|
|
||||||
if( !scope.checkboxStrict ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
scope.getChildren( storeItem, dojo.hitch( scope,
|
|
||||||
function(children) {
|
|
||||||
var allChecked = true;
|
|
||||||
var childState;
|
|
||||||
dojo.forEach( children, function( child ) {
|
|
||||||
if( this.mayHaveChildren( child )) {
|
|
||||||
this.validateData( child, this );
|
|
||||||
}
|
|
||||||
childState = this.getCheckboxState( child );
|
|
||||||
if( childState !== undefined && allChecked )
|
|
||||||
allChecked = childState;
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
if ( this._setCheckboxState( storeItem, allChecked) ) {
|
|
||||||
this._updateParentCheckbox( storeItem, allChecked);
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
function(err) {
|
|
||||||
console.error(this, ": validating checkbox data: ", err);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
onCheckboxChange: function(/*dojo.data.Item*/ storeItem ) {
|
|
||||||
// summary:
|
|
||||||
// Callback whenever a checkbox state has changed state, so that
|
|
||||||
// the Tree can update the checkbox. This callback is generally
|
|
||||||
// triggered by the '_setCheckboxState' function.
|
|
||||||
// tags:
|
|
||||||
// callback
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
dojo.declare( "lib._CheckBoxTreeNode", dijit._TreeNode,
|
require(["dojo/_base/declare", "dijit/Tree"], function (declare) {
|
||||||
{
|
|
||||||
// _checkbox: [protected] dojo.doc.element
|
|
||||||
// Local reference to the dojo.doc.element of type 'checkbox'
|
|
||||||
_checkbox: null,
|
|
||||||
|
|
||||||
_createCheckbox: function() {
|
return declare("lib._CheckBoxTreeNode", dijit._TreeNode,
|
||||||
// summary:
|
{
|
||||||
// Create a checkbox on the CheckBoxTreeNode
|
// _checkbox: [protected] dojo.doc.element
|
||||||
// description:
|
// Local reference to the dojo.doc.element of type 'checkbox'
|
||||||
// Create a checkbox on the CheckBoxTreeNode. The checkbox is ONLY created if a
|
_checkbox: null,
|
||||||
// valid reference was found in the dojo.data store or the attribute 'checkboxAll'
|
|
||||||
// is set to true. If the current state is 'undefined' no reference was found and
|
|
||||||
// 'checkboxAll' is set to false.
|
|
||||||
// Note: the attribute 'checkboxAll' is validated by the getCheckboxState function
|
|
||||||
// therefore no need to do that here. (see getCheckboxState for details).
|
|
||||||
//
|
|
||||||
var currState = this.tree.model.getCheckboxState( this.item );
|
|
||||||
if( currState !== undefined ) {
|
|
||||||
this._checkbox = new dijit.form.CheckBox();
|
|
||||||
//this._checkbox = dojo.doc.createElement('input');
|
|
||||||
this._checkbox.type = 'checkbox';
|
|
||||||
this._checkbox.attr('checked', currState);
|
|
||||||
dojo.place(this._checkbox.domNode, this.expandoNode, 'after');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
postCreate: function() {
|
_createCheckbox: function () {
|
||||||
// summary:
|
// summary:
|
||||||
// Handle the creation of the checkbox after the CheckBoxTreeNode has been instanciated.
|
// Create a checkbox on the CheckBoxTreeNode
|
||||||
// description:
|
// description:
|
||||||
// Handle the creation of the checkbox after the CheckBoxTreeNode has been instanciated.
|
// Create a checkbox on the CheckBoxTreeNode. The checkbox is ONLY created if a
|
||||||
this._createCheckbox();
|
// valid reference was found in the dojo.data store or the attribute 'checkboxAll'
|
||||||
this.inherited( arguments );
|
// is set to true. If the current state is 'undefined' no reference was found and
|
||||||
}
|
// 'checkboxAll' is set to false.
|
||||||
|
// Note: the attribute 'checkboxAll' is validated by the getCheckboxState function
|
||||||
});
|
// therefore no need to do that here. (see getCheckboxState for details).
|
||||||
|
//
|
||||||
dojo.declare( "lib.CheckBoxTree", dijit.Tree,
|
var currState = this.tree.model.getCheckboxState(this.item);
|
||||||
{
|
if (currState !== undefined) {
|
||||||
|
this._checkbox = new dijit.form.CheckBox();
|
||||||
onNodeChecked: function(/*dojo.data.Item*/ storeItem, /*treeNode*/ treeNode) {
|
//this._checkbox = dojo.doc.createElement('input');
|
||||||
// summary:
|
this._checkbox.type = 'checkbox';
|
||||||
// Callback when a checkbox tree node is checked
|
this._checkbox.attr('checked', currState);
|
||||||
// tags:
|
dojo.place(this._checkbox.domNode, this.expandoNode, 'after');
|
||||||
// callback
|
|
||||||
},
|
|
||||||
|
|
||||||
onNodeUnchecked: function(/*dojo.data.Item*/ storeItem, /* treeNode */ treeNode) {
|
|
||||||
// summary:
|
|
||||||
// Callback when a checkbox tree node is unchecked
|
|
||||||
// tags:
|
|
||||||
// callback
|
|
||||||
},
|
|
||||||
|
|
||||||
_onClick: function(/*TreeNode*/ nodeWidget, /*Event*/ e) {
|
|
||||||
// summary:
|
|
||||||
// Translates click events into commands for the controller to process
|
|
||||||
// description:
|
|
||||||
// the _onClick function is called whenever a 'click' is detected. This
|
|
||||||
// instance of _onClick only handles the click events associated with
|
|
||||||
// the checkbox whos DOM name is INPUT.
|
|
||||||
//
|
|
||||||
var domElement = e.target;
|
|
||||||
|
|
||||||
// Only handle checkbox clicks here
|
|
||||||
if(domElement.type != 'checkbox') {
|
|
||||||
return this.inherited( arguments );
|
|
||||||
}
|
|
||||||
|
|
||||||
this._publish("execute", { item: nodeWidget.item, node: nodeWidget} );
|
|
||||||
// Go tell the model to update the checkbox state
|
|
||||||
|
|
||||||
this.model.updateCheckbox( nodeWidget.item, nodeWidget._checkbox.checked );
|
|
||||||
// Generate some additional events
|
|
||||||
//this.onClick( nodeWidget.item, nodeWidget, e );
|
|
||||||
if(nodeWidget._checkbox.checked) {
|
|
||||||
this.onNodeChecked( nodeWidget.item, nodeWidget);
|
|
||||||
} else {
|
|
||||||
this.onNodeUnchecked( nodeWidget.item, nodeWidget);
|
|
||||||
}
|
|
||||||
this.focusNode(nodeWidget);
|
|
||||||
},
|
|
||||||
|
|
||||||
_onCheckboxChange: function(/*dojo.data.Item*/ storeItem ) {
|
|
||||||
// summary:
|
|
||||||
// Processes notification of a change to a checkbox state (triggered by the model).
|
|
||||||
// description:
|
|
||||||
// Whenever the model changes the state of a checkbox in the dojo.data.store it will
|
|
||||||
// trigger the 'onCheckboxChange' event allowing the Tree to make the same changes
|
|
||||||
// on the tree Node. There are several conditions why a tree node or checkbox does not
|
|
||||||
// exists:
|
|
||||||
// a) The node has not been created yet (the user has not expanded the tree node yet).
|
|
||||||
// b) The checkbox may be null if condition (a) exists or no 'checkbox' attribute was
|
|
||||||
// specified for the associated dojo.data.item and the attribute 'checkboxAll' is
|
|
||||||
// set to false.
|
|
||||||
// tags:
|
|
||||||
// callback
|
|
||||||
var model = this.model,
|
|
||||||
identity = model.getIdentity(storeItem),
|
|
||||||
nodes = this._itemNodesMap[identity];
|
|
||||||
|
|
||||||
// As of dijit.Tree 1.4 multiple references (parents) are supported, therefore we may have
|
|
||||||
// to update multiple nodes which are all associated with the same dojo.data.item.
|
|
||||||
if( nodes ) {
|
|
||||||
dojo.forEach( nodes, function(node) {
|
|
||||||
if( node._checkbox != null ) {
|
|
||||||
node._checkbox.attr('checked', this.model.getCheckboxState( storeItem ));
|
|
||||||
}
|
}
|
||||||
}, this );
|
},
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
postCreate: function() {
|
postCreate: function () {
|
||||||
// summary:
|
// summary:
|
||||||
// Handle any specifics related to the tree and model after the instanciation of the Tree.
|
// Handle the creation of the checkbox after the CheckBoxTreeNode has been instanciated.
|
||||||
// description:
|
// description:
|
||||||
// Validate if we have a 'write' store first. Subscribe to the 'onCheckboxChange' event
|
// Handle the creation of the checkbox after the CheckBoxTreeNode has been instanciated.
|
||||||
// (triggered by the model) and kickoff the initial checkbox data validation.
|
this._createCheckbox();
|
||||||
//
|
this.inherited(arguments);
|
||||||
var store = this.model.store;
|
}
|
||||||
if(!store.getFeatures()['dojo.data.api.Write']){
|
|
||||||
throw new Error("lib.CheckboxTree: store must support dojo.data.Write");
|
|
||||||
}
|
|
||||||
this.connect(this.model, "onCheckboxChange", "_onCheckboxChange");
|
|
||||||
this.model.validateData( this.model.root, this.model );
|
|
||||||
this.inherited(arguments);
|
|
||||||
},
|
|
||||||
|
|
||||||
_createTreeNode: function( args ) {
|
});
|
||||||
// summary:
|
});
|
||||||
// Create a new CheckboxTreeNode instance.
|
|
||||||
// description:
|
require(["dojo/_base/declare", "dijit/Tree"], function (declare) {
|
||||||
// Create a new CheckboxTreeNode instance.
|
|
||||||
return new lib._CheckBoxTreeNode(args);
|
return declare( "lib.CheckBoxTree", dijit.Tree,
|
||||||
}
|
{
|
||||||
|
|
||||||
|
onNodeChecked: function(/*dojo.data.Item*/ storeItem, /*treeNode*/ treeNode) {
|
||||||
|
// summary:
|
||||||
|
// Callback when a checkbox tree node is checked
|
||||||
|
// tags:
|
||||||
|
// callback
|
||||||
|
},
|
||||||
|
|
||||||
|
onNodeUnchecked: function(/*dojo.data.Item*/ storeItem, /* treeNode */ treeNode) {
|
||||||
|
// summary:
|
||||||
|
// Callback when a checkbox tree node is unchecked
|
||||||
|
// tags:
|
||||||
|
// callback
|
||||||
|
},
|
||||||
|
|
||||||
|
_onClick: function(/*TreeNode*/ nodeWidget, /*Event*/ e) {
|
||||||
|
// summary:
|
||||||
|
// Translates click events into commands for the controller to process
|
||||||
|
// description:
|
||||||
|
// the _onClick function is called whenever a 'click' is detected. This
|
||||||
|
// instance of _onClick only handles the click events associated with
|
||||||
|
// the checkbox whos DOM name is INPUT.
|
||||||
|
//
|
||||||
|
var domElement = e.target;
|
||||||
|
|
||||||
|
// Only handle checkbox clicks here
|
||||||
|
if(domElement.type != 'checkbox') {
|
||||||
|
return this.inherited( arguments );
|
||||||
|
}
|
||||||
|
|
||||||
|
this._publish("execute", { item: nodeWidget.item, node: nodeWidget} );
|
||||||
|
// Go tell the model to update the checkbox state
|
||||||
|
|
||||||
|
this.model.updateCheckbox( nodeWidget.item, nodeWidget._checkbox.checked );
|
||||||
|
// Generate some additional events
|
||||||
|
//this.onClick( nodeWidget.item, nodeWidget, e );
|
||||||
|
if(nodeWidget._checkbox.checked) {
|
||||||
|
this.onNodeChecked( nodeWidget.item, nodeWidget);
|
||||||
|
} else {
|
||||||
|
this.onNodeUnchecked( nodeWidget.item, nodeWidget);
|
||||||
|
}
|
||||||
|
this.focusNode(nodeWidget);
|
||||||
|
},
|
||||||
|
|
||||||
|
_onCheckboxChange: function(/*dojo.data.Item*/ storeItem ) {
|
||||||
|
// summary:
|
||||||
|
// Processes notification of a change to a checkbox state (triggered by the model).
|
||||||
|
// description:
|
||||||
|
// Whenever the model changes the state of a checkbox in the dojo.data.store it will
|
||||||
|
// trigger the 'onCheckboxChange' event allowing the Tree to make the same changes
|
||||||
|
// on the tree Node. There are several conditions why a tree node or checkbox does not
|
||||||
|
// exists:
|
||||||
|
// a) The node has not been created yet (the user has not expanded the tree node yet).
|
||||||
|
// b) The checkbox may be null if condition (a) exists or no 'checkbox' attribute was
|
||||||
|
// specified for the associated dojo.data.item and the attribute 'checkboxAll' is
|
||||||
|
// set to false.
|
||||||
|
// tags:
|
||||||
|
// callback
|
||||||
|
var model = this.model,
|
||||||
|
identity = model.getIdentity(storeItem),
|
||||||
|
nodes = this._itemNodesMap[identity];
|
||||||
|
|
||||||
|
// As of dijit.Tree 1.4 multiple references (parents) are supported, therefore we may have
|
||||||
|
// to update multiple nodes which are all associated with the same dojo.data.item.
|
||||||
|
if( nodes ) {
|
||||||
|
dojo.forEach( nodes, function(node) {
|
||||||
|
if( node._checkbox != null ) {
|
||||||
|
node._checkbox.attr('checked', this.model.getCheckboxState( storeItem ));
|
||||||
|
}
|
||||||
|
}, this );
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
postCreate: function() {
|
||||||
|
// summary:
|
||||||
|
// Handle any specifics related to the tree and model after the instanciation of the Tree.
|
||||||
|
// description:
|
||||||
|
// Validate if we have a 'write' store first. Subscribe to the 'onCheckboxChange' event
|
||||||
|
// (triggered by the model) and kickoff the initial checkbox data validation.
|
||||||
|
//
|
||||||
|
var store = this.model.store;
|
||||||
|
if(!store.getFeatures()['dojo.data.api.Write']){
|
||||||
|
throw new Error("lib.CheckboxTree: store must support dojo.data.Write");
|
||||||
|
}
|
||||||
|
this.connect(this.model, "onCheckboxChange", "_onCheckboxChange");
|
||||||
|
this.model.validateData( this.model.root, this.model );
|
||||||
|
this.inherited(arguments);
|
||||||
|
},
|
||||||
|
|
||||||
|
_createTreeNode: function( args ) {
|
||||||
|
// summary:
|
||||||
|
// Create a new CheckboxTreeNode instance.
|
||||||
|
// description:
|
||||||
|
// Create a new CheckboxTreeNode instance.
|
||||||
|
return new lib._CheckBoxTreeNode(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user