PrefFeedTree.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. dojo.place(param, tnode.rowNode, 'first');
  28. }
  29. var id = args.item.id[0];
  30. var bare_id = parseInt(id.substr(id.indexOf(':')+1));
  31. if (id.match("CAT:") && bare_id > 0) {
  32. var menu = new dijit.Menu();
  33. menu.row_id = bare_id;
  34. menu.item = args.item;
  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. menu.addChild(new dijit.MenuItem({
  41. label: __("Remove category"),
  42. onClick: function() {
  43. removeCategory(this.getParent().row_id, this.getParent().item);
  44. }}));
  45. menu.bindDomNode(tnode.domNode);
  46. tnode._menu = menu;
  47. } else if (id.match("FEED:")) {
  48. var menu = new dijit.Menu();
  49. menu.row_id = bare_id;
  50. menu.item = args.item;
  51. menu.addChild(new dijit.MenuItem({
  52. label: __("Edit feed"),
  53. onClick: function() {
  54. editFeed(this.getParent().row_id);
  55. }}));
  56. menu.addChild(new dijit.MenuItem({
  57. label: __("Unsubscribe"),
  58. onClick: function() {
  59. unsubscribeFeed(this.getParent().row_id, this.getParent().item.name);
  60. }}));
  61. menu.bindDomNode(tnode.domNode);
  62. tnode._menu = menu;
  63. }
  64. return tnode;
  65. },
  66. onDndDrop: function() {
  67. this.inherited(arguments);
  68. this.tree.model.store.save();
  69. },
  70. getRowClass: function (item, opened) {
  71. return (!item.error || item.error == '') ? "dijitTreeRow" :
  72. "dijitTreeRow Error";
  73. },
  74. getIconClass: function (item, opened) {
  75. return (!item || this.model.store.getValue(item, 'type') == 'category') ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feedIcon";
  76. },
  77. checkItemAcceptance: function(target, source, position) {
  78. var item = dijit.getEnclosingWidget(target).item;
  79. // disable copying items
  80. source.copyState = function() { return false; };
  81. var source_item = false;
  82. source.forInSelectedItems(function(node) {
  83. source_item = node.data.item;
  84. });
  85. if (!source_item || !item) return false;
  86. var id = this.tree.model.store.getValue(item, 'id');
  87. var source_id = source.tree.model.store.getValue(source_item, 'id');
  88. //console.log(id + " " + position + " " + source_id);
  89. if (source_id.match("FEED:")) {
  90. return ((id.match("CAT:") && position == "over") ||
  91. (id.match("FEED:") && position != "over"));
  92. } else if (source_id.match("CAT:")) {
  93. return ((id.match("CAT:") && !id.match("CAT:0")) ||
  94. (id.match("root") && position == "over"));
  95. }
  96. },
  97. });