Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

86 lignes
2.2 KiB

  1. (function ($) {
  2. // register namespace
  3. $.extend(true, window, {
  4. "Slick": {
  5. "CellCopyManager": CellCopyManager
  6. }
  7. });
  8. function CellCopyManager() {
  9. var _grid;
  10. var _self = this;
  11. var _copiedRanges;
  12. function init(grid) {
  13. _grid = grid;
  14. _grid.onKeyDown.subscribe(handleKeyDown);
  15. }
  16. function destroy() {
  17. _grid.onKeyDown.unsubscribe(handleKeyDown);
  18. }
  19. function handleKeyDown(e, args) {
  20. var ranges;
  21. if (!_grid.getEditorLock().isActive()) {
  22. if (e.which == $.ui.keyCode.ESCAPE) {
  23. if (_copiedRanges) {
  24. e.preventDefault();
  25. clearCopySelection();
  26. _self.onCopyCancelled.notify({ranges: _copiedRanges});
  27. _copiedRanges = null;
  28. }
  29. }
  30. if (e.which == 67 && (e.ctrlKey || e.metaKey)) {
  31. ranges = _grid.getSelectionModel().getSelectedRanges();
  32. if (ranges.length != 0) {
  33. e.preventDefault();
  34. _copiedRanges = ranges;
  35. markCopySelection(ranges);
  36. _self.onCopyCells.notify({ranges: ranges});
  37. }
  38. }
  39. if (e.which == 86 && (e.ctrlKey || e.metaKey)) {
  40. if (_copiedRanges) {
  41. e.preventDefault();
  42. clearCopySelection();
  43. ranges = _grid.getSelectionModel().getSelectedRanges();
  44. _self.onPasteCells.notify({from: _copiedRanges, to: ranges});
  45. _copiedRanges = null;
  46. }
  47. }
  48. }
  49. }
  50. function markCopySelection(ranges) {
  51. var columns = _grid.getColumns();
  52. var hash = {};
  53. for (var i = 0; i < ranges.length; i++) {
  54. for (var j = ranges[i].fromRow; j <= ranges[i].toRow; j++) {
  55. hash[j] = {};
  56. for (var k = ranges[i].fromCell; k <= ranges[i].toCell; k++) {
  57. hash[j][columns[k].id] = "copied";
  58. }
  59. }
  60. }
  61. _grid.setCellCssStyles("copy-manager", hash);
  62. }
  63. function clearCopySelection() {
  64. _grid.removeCellCssStyles("copy-manager");
  65. }
  66. $.extend(this, {
  67. "init": init,
  68. "destroy": destroy,
  69. "clearCopySelection": clearCopySelection,
  70. "onCopyCells": new Slick.Event(),
  71. "onCopyCancelled": new Slick.Event(),
  72. "onPasteCells": new Slick.Event()
  73. });
  74. }
  75. })(jQuery);