PrefFeedTree.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. tnode.iconNode.src = args.item.icon[0];
  20. var param = this.model.store.getValue(args.item, 'param');
  21. if (param) {
  22. param = dojo.doc.createElement('span');
  23. param.className = 'feedParam';
  24. param.innerHTML = args.item.param[0];
  25. //domConstruct.place(param, tnode.labelNode, 'after');
  26. domConstruct.place(param, tnode.rowNode, 'first');
  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. });
  97. });