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