MoveAction.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2011
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. function MoveAction()
  13. {
  14. this.m_sAction = "Reorder";
  15. }
  16. MoveAction.prototype = new DragDropAction();
  17. MoveAction.prototype.setRequestParms = function(payload)
  18. {
  19. this.m_order = payload.order;
  20. };
  21. MoveAction.prototype.canMoveLeftRight = function(sDirection)
  22. {
  23. var selectionController = this.m_oCV.getSelectionController();
  24. if (selectionController && selectionController.getAllSelectedObjects().length == 1)
  25. {
  26. var cellRef = selectionController.getAllSelectedObjects()[0].getCellRef();
  27. if (sDirection == "right" && cellRef.nextSibling)
  28. {
  29. return true;
  30. }
  31. else if (sDirection == "left" && cellRef.previousSibling)
  32. {
  33. return true;
  34. }
  35. }
  36. return false;
  37. };
  38. MoveAction.prototype.updateMenu = function(jsonSpec)
  39. {
  40. if (!this.canMove())
  41. {
  42. jsonSpec = "";
  43. }
  44. else
  45. {
  46. var selectionController = this.m_oCV.getSelectionController();
  47. if (selectionController && selectionController.getAllSelectedObjects().length > 1)
  48. {
  49. jsonSpec.disabled = true;
  50. jsonSpec.items = null;
  51. }
  52. else
  53. {
  54. jsonSpec.disabled = false;
  55. jsonSpec.items = [];
  56. jsonSpec.items.push({ disabled: !this.canMoveLeftRight("left"), name: "Move", label: RV_RES.IDS_JS_LEFT, iconClass: "moveLeft", action: { name: "Move", payload: {order:"left"} }, items: null });
  57. jsonSpec.items.push({ disabled: !this.canMoveLeftRight("right"), name: "Move", label: RV_RES.IDS_JS_RIGHT, iconClass: "moveRight", action: { name: "Move", payload: {order:"right"} }, items: null });
  58. }
  59. }
  60. return jsonSpec;
  61. };
  62. MoveAction.prototype.addActionContextAdditionalParms = function()
  63. {
  64. var selectionController = this.getCognosViewer().getSelectionController();
  65. var targetRef = null;
  66. if (this.m_order == "right")
  67. {
  68. targetRef = selectionController.getAllSelectedObjects()[0].getCellRef().nextSibling;
  69. }
  70. else
  71. {
  72. targetRef = selectionController.getAllSelectedObjects()[0].getCellRef().previousSibling;
  73. }
  74. var target = selectionController.buildSelectionObject(targetRef, null);
  75. var tag = this.m_order == "right" ? "after" : "before";
  76. //always use layout tag when it is available.
  77. var tagValue = this.getRAPLayoutTag(targetRef);
  78. tagValue = (tagValue != null ) ? tagValue : target.getColumnName();
  79. return this.getSelectedCellTags() + "<" + tag + ">" + xml_encode(tagValue) + "</" + tag + ">";
  80. };