PrefFeedTree.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. dojo.provide("fox.PrefFeedTree");
  2. dojo.provide("fox.PrefFeedStore");
  3. dojo.require("lib.CheckBoxTree");
  4. dojo.require("dojo.data.ItemFileWriteStore");
  5. dojo.declare("fox.PrefFeedStore", dojo.data.ItemFileWriteStore, {
  6. _saveEverything: function(saveCompleteCallback, saveFailedCallback,
  7. newFileContentString) {
  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. dojo.declare("fox.PrefFeedTree", lib.CheckBoxTree, {
  17. _createTreeNode: function(args) {
  18. var tnode = this.inherited(arguments);
  19. if (args.item.icon)
  20. tnode.iconNode.src = args.item.icon[0];
  21. var param = this.model.store.getValue(args.item, 'param');
  22. if (param) {
  23. param = dojo.doc.createElement('span');
  24. param.className = 'feedParam';
  25. param.innerHTML = args.item.param[0];
  26. dojo.place(param, tnode.labelNode, 'after');
  27. }
  28. var id = args.item.id[0];
  29. var bare_id = parseInt(id.substr(id.indexOf(':')+1));
  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. menu.addChild(new dijit.MenuItem({
  35. label: __("Edit category"),
  36. onClick: function() {
  37. editCat(this.getParent().row_id, this.getParent().item, null);
  38. }}));
  39. menu.addChild(new dijit.MenuItem({
  40. label: __("Remove category"),
  41. onClick: function() {
  42. removeCategory(this.getParent().row_id, this.getParent().item);
  43. }}));
  44. menu.bindDomNode(tnode.domNode);
  45. tnode._menu = menu;
  46. } else if (id.match("FEED:")) {
  47. var menu = new dijit.Menu();
  48. menu.row_id = bare_id;
  49. menu.item = args.item;
  50. menu.addChild(new dijit.MenuItem({
  51. label: __("Edit feed"),
  52. onClick: function() {
  53. editFeed(this.getParent().row_id);
  54. }}));
  55. menu.addChild(new dijit.MenuItem({
  56. label: __("Unsubscribe"),
  57. onClick: function() {
  58. unsubscribeFeed(this.getParent().row_id, this.getParent().item.name);
  59. }}));
  60. menu.bindDomNode(tnode.domNode);
  61. tnode._menu = menu;
  62. }
  63. return tnode;
  64. },
  65. onDndDrop: function() {
  66. this.inherited(arguments);
  67. this.tree.model.store.save();
  68. },
  69. getRowClass: function (item, opened) {
  70. return (!item.error || item.error == '') ? "dijitTreeRow" :
  71. "dijitTreeRow Error";
  72. },
  73. getIconClass: function (item, opened) {
  74. return (!item || this.model.store.getValue(item, 'type') == 'category') ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feedIcon";
  75. },
  76. checkItemAcceptance: function(target, source, position) {
  77. var item = dijit.getEnclosingWidget(target).item;
  78. // disable copying items
  79. source.copyState = function() { return false; };
  80. var source_item = false;
  81. source.forInSelectedItems(function(node) {
  82. source_item = node.data.item;
  83. });
  84. if (!source_item || !item) return false;
  85. var id = this.tree.model.store.getValue(item, 'id');
  86. var source_id = source.tree.model.store.getValue(source_item, 'id');
  87. //console.log(id + " " + position + " " + source_id);
  88. if (source_id.match("FEED:")) {
  89. return ((id.match("CAT:") && position == "over") ||
  90. (id.match("FEED:") && position != "over"));
  91. } else if (source_id.match("CAT:")) {
  92. return ((id.match("CAT:") && !id.match("CAT:0")) ||
  93. (id.match("root") && position == "over"));
  94. }
  95. },
  96. });