]> git.wh0rd.org - tt-rss.git/blame - js/PrefFeedTree.js
pngcrush.sh
[tt-rss.git] / js / PrefFeedTree.js
CommitLineData
02672124 1/* global lib,dijit */
a3e2f1a9 2define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], function (declare, domConstruct) {
d39a2f80
AD
3
4 return declare("fox.PrefFeedTree", lib.CheckBoxTree, {
5 _createTreeNode: function(args) {
02672124 6 const tnode = this.inherited(arguments);
d39a2f80 7
02672124 8 const icon = dojo.doc.createElement('img');
b3e3cb06 9 if (args.item.icon && args.item.icon[0]) {
6887a0f5 10 icon.src = args.item.icon[0];
b3e3cb06 11 } else {
12 icon.src = 'images/blank_icon.gif';
6887a0f5 13 }
b3e3cb06 14 icon.className = 'tinyFeedIcon';
15 domConstruct.place(icon, tnode.iconNode, 'only');
d39a2f80 16
02672124 17 let param = this.model.store.getValue(args.item, 'param');
d39a2f80
AD
18
19 if (param) {
20 param = dojo.doc.createElement('span');
21 param.className = 'feedParam';
22 param.innerHTML = args.item.param[0];
9f539be3
AK
23 //domConstruct.place(param, tnode.labelNode, 'after');
24 domConstruct.place(param, tnode.rowNode, 'first');
d39a2f80
AD
25 }
26
02672124
AD
27 const id = args.item.id[0];
28 const bare_id = parseInt(id.substr(id.indexOf(':')+1));
d39a2f80
AD
29
30 if (id.match("CAT:") && bare_id > 0) {
31 var menu = new dijit.Menu();
32 menu.row_id = bare_id;
33 menu.item = args.item;
34
35 menu.addChild(new dijit.MenuItem({
36 label: __("Edit category"),
37 onClick: function() {
38 editCat(this.getParent().row_id, this.getParent().item, null);
39 }}));
40
41
42 menu.addChild(new dijit.MenuItem({
43 label: __("Remove category"),
44 onClick: function() {
45 removeCategory(this.getParent().row_id, this.getParent().item);
46 }}));
47
48 menu.bindDomNode(tnode.domNode);
49 tnode._menu = menu;
50 } else if (id.match("FEED:")) {
51 var menu = new dijit.Menu();
52 menu.row_id = bare_id;
53 menu.item = args.item;
54
55 menu.addChild(new dijit.MenuItem({
56 label: __("Edit feed"),
57 onClick: function() {
58 editFeed(this.getParent().row_id);
59 }}));
60
61 menu.addChild(new dijit.MenuItem({
62 label: __("Unsubscribe"),
63 onClick: function() {
64 unsubscribeFeed(this.getParent().row_id, this.getParent().item.name);
65 }}));
66
67 menu.bindDomNode(tnode.domNode);
68 tnode._menu = menu;
69
70 }
71
72 return tnode;
73 },
74 onDndDrop: function() {
75 this.inherited(arguments);
76 this.tree.model.store.save();
77 },
78 getRowClass: function (item, opened) {
79 return (!item.error || item.error == '') ? "dijitTreeRow" :
80 "dijitTreeRow Error";
81 },
82 getIconClass: function (item, opened) {
83 return (!item || this.model.store.getValue(item, 'type') == 'category') ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feedIcon";
84 },
85 checkItemAcceptance: function(target, source, position) {
02672124 86 const item = dijit.getEnclosingWidget(target).item;
d39a2f80
AD
87
88 // disable copying items
89 source.copyState = function() { return false; };
90
02672124 91 let source_item = false;
d39a2f80
AD
92
93 source.forInSelectedItems(function(node) {
94 source_item = node.data.item;
95 });
96
97 if (!source_item || !item) return false;
98
02672124
AD
99 const id = this.tree.model.store.getValue(item, 'id');
100 const source_id = source.tree.model.store.getValue(source_item, 'id');
d39a2f80
AD
101
102 //console.log(id + " " + position + " " + source_id);
103
104 if (source_id.match("FEED:")) {
105 return ((id.match("CAT:") && position == "over") ||
49c6c279 106 (id.match("FEED:") && position != "over"));
d39a2f80
AD
107 } else if (source_id.match("CAT:")) {
108 return ((id.match("CAT:") && !id.match("CAT:0")) ||
49c6c279 109 (id.match("root") && position == "over"));
d39a2f80
AD
110 }
111 },
112 });
2148e0d5
AD
113});
114