PrefFeedTree.js 3.6 KB

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