]> git.wh0rd.org - tt-rss.git/blob - js/PrefFeedTree.js
Merge branch 'dojo-1.12.1'
[tt-rss.git] / js / PrefFeedTree.js
1 require(["dojo/_base/declare", "dojo/data/ItemFileWriteStore"], function (declare) {
2
3 return declare("fox.PrefFeedStore", dojo.data.ItemFileWriteStore, {
4
5 _saveEverything: function(saveCompleteCallback, saveFailedCallback,
6 newFileContentString) {
7
8 dojo.xhrPost({
9 url: "backend.php",
10 content: {op: "pref-feeds", method: "savefeedorder",
11 payload: newFileContentString},
12 error: saveFailedCallback,
13 load: saveCompleteCallback});
14 },
15
16 });
17
18 });
19
20 require(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], function (declare, domConstruct) {
21
22 return declare("fox.PrefFeedTree", lib.CheckBoxTree, {
23 _createTreeNode: function(args) {
24 var tnode = this.inherited(arguments);
25
26 if (args.item.icon) {
27 var icon = dojo.doc.createElement('img');
28 icon.src = args.item.icon[0];
29 icon.className = 'tinyFeedIcon';
30 domConstruct.place(icon, tnode.iconNode, 'only');
31 }
32
33 var param = this.model.store.getValue(args.item, 'param');
34
35 if (param) {
36 param = dojo.doc.createElement('span');
37 param.className = 'feedParam';
38 param.innerHTML = args.item.param[0];
39 //domConstruct.place(param, tnode.labelNode, 'after');
40 domConstruct.place(param, tnode.rowNode, 'first');
41 }
42
43 var id = args.item.id[0];
44 var bare_id = parseInt(id.substr(id.indexOf(':')+1));
45
46 if (id.match("CAT:") && bare_id > 0) {
47 var menu = new dijit.Menu();
48 menu.row_id = bare_id;
49 menu.item = args.item;
50
51 menu.addChild(new dijit.MenuItem({
52 label: __("Edit category"),
53 onClick: function() {
54 editCat(this.getParent().row_id, this.getParent().item, null);
55 }}));
56
57
58 menu.addChild(new dijit.MenuItem({
59 label: __("Remove category"),
60 onClick: function() {
61 removeCategory(this.getParent().row_id, this.getParent().item);
62 }}));
63
64 menu.bindDomNode(tnode.domNode);
65 tnode._menu = menu;
66 } else if (id.match("FEED:")) {
67 var menu = new dijit.Menu();
68 menu.row_id = bare_id;
69 menu.item = args.item;
70
71 menu.addChild(new dijit.MenuItem({
72 label: __("Edit feed"),
73 onClick: function() {
74 editFeed(this.getParent().row_id);
75 }}));
76
77 menu.addChild(new dijit.MenuItem({
78 label: __("Unsubscribe"),
79 onClick: function() {
80 unsubscribeFeed(this.getParent().row_id, this.getParent().item.name);
81 }}));
82
83 menu.bindDomNode(tnode.domNode);
84 tnode._menu = menu;
85
86 }
87
88 return tnode;
89 },
90 onDndDrop: function() {
91 this.inherited(arguments);
92 this.tree.model.store.save();
93 },
94 getRowClass: function (item, opened) {
95 return (!item.error || item.error == '') ? "dijitTreeRow" :
96 "dijitTreeRow Error";
97 },
98 getIconClass: function (item, opened) {
99 return (!item || this.model.store.getValue(item, 'type') == 'category') ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feedIcon";
100 },
101 checkItemAcceptance: function(target, source, position) {
102 var item = dijit.getEnclosingWidget(target).item;
103
104 // disable copying items
105 source.copyState = function() { return false; };
106
107 var source_item = false;
108
109 source.forInSelectedItems(function(node) {
110 source_item = node.data.item;
111 });
112
113 if (!source_item || !item) return false;
114
115 var id = this.tree.model.store.getValue(item, 'id');
116 var source_id = source.tree.model.store.getValue(source_item, 'id');
117
118 //console.log(id + " " + position + " " + source_id);
119
120 if (source_id.match("FEED:")) {
121 return ((id.match("CAT:") && position == "over") ||
122 (id.match("FEED:") && position != "over"));
123 } else if (source_id.match("CAT:")) {
124 return ((id.match("CAT:") && !id.match("CAT:0")) ||
125 (id.match("root") && position == "over"));
126 }
127 },
128 });
129 });
130