]> git.wh0rd.org - tt-rss.git/blob - js/PrefFeedTree.js
pngcrush.sh
[tt-rss.git] / js / PrefFeedTree.js
1 /* global lib,dijit */
2 define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], function (declare, domConstruct) {
3
4 return declare("fox.PrefFeedTree", lib.CheckBoxTree, {
5 _createTreeNode: function(args) {
6 const tnode = this.inherited(arguments);
7
8 const icon = dojo.doc.createElement('img');
9 if (args.item.icon && args.item.icon[0]) {
10 icon.src = args.item.icon[0];
11 } else {
12 icon.src = 'images/blank_icon.gif';
13 }
14 icon.className = 'tinyFeedIcon';
15 domConstruct.place(icon, tnode.iconNode, 'only');
16
17 let param = this.model.store.getValue(args.item, 'param');
18
19 if (param) {
20 param = dojo.doc.createElement('span');
21 param.className = 'feedParam';
22 param.innerHTML = args.item.param[0];
23 //domConstruct.place(param, tnode.labelNode, 'after');
24 domConstruct.place(param, tnode.rowNode, 'first');
25 }
26
27 const id = args.item.id[0];
28 const bare_id = parseInt(id.substr(id.indexOf(':')+1));
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) {
86 const item = dijit.getEnclosingWidget(target).item;
87
88 // disable copying items
89 source.copyState = function() { return false; };
90
91 let source_item = false;
92
93 source.forInSelectedItems(function(node) {
94 source_item = node.data.item;
95 });
96
97 if (!source_item || !item) return false;
98
99 const id = this.tree.model.store.getValue(item, 'id');
100 const source_id = source.tree.model.store.getValue(source_item, 'id');
101
102 //console.log(id + " " + position + " " + source_id);
103
104 if (source_id.match("FEED:")) {
105 return ((id.match("CAT:") && position == "over") ||
106 (id.match("FEED:") && position != "over"));
107 } else if (source_id.match("CAT:")) {
108 return ((id.match("CAT:") && !id.match("CAT:0")) ||
109 (id.match("root") && position == "over"));
110 }
111 },
112 });
113 });
114