PrefFeedTree.js 3.7 KB

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