data-view-plugins.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.DataView.LabelEditor = function(cfg, field) {
  7. Ext.DataView.LabelEditor.superclass.constructor.call(this, field
  8. || new Ext.form.TextField({
  9. allowBlank : false,
  10. growMin : 90,
  11. growMax : 240,
  12. grow : true,
  13. selectOnFocus : true
  14. }), cfg);
  15. }
  16. Ext.extend(Ext.DataView.LabelEditor, Ext.Editor, {
  17. alignment : "tl-tl",
  18. hideEl : false,
  19. cls : "x-small-editor",
  20. shim : false,
  21. completeOnEnter : true,
  22. cancelOnEsc : true,
  23. labelSelector : 'span.x-editable',
  24. init : function(view) {
  25. this.view = view;
  26. view.on('render', this.initEditor, this);
  27. this.on('complete', this.onSave, this);
  28. },
  29. initEditor : function() {
  30. this.view.getEl().on('mousedown', this.onMouseDown, this, {
  31. delegate : this.labelSelector
  32. });
  33. },
  34. onMouseDown : function(e, target) {
  35. if (!e.ctrlKey && !e.shiftKey) {
  36. var item = this.view.findItemFromChild(target);
  37. e.stopEvent();
  38. var record = this.view.store.getAt(this.view.indexOf(item));
  39. this.startEdit(target, record.data[this.dataIndex]);
  40. this.activeRecord = record;
  41. } else {
  42. e.preventDefault();
  43. }
  44. },
  45. onSave : function(ed, value) {
  46. this.activeRecord.set(this.dataIndex, value);
  47. }
  48. });
  49. Ext.DataView.DragSelector = function(cfg) {
  50. cfg = cfg || {};
  51. var view, regions, proxy, tracker;
  52. var rs, bodyRegion, dragRegion = new Ext.lib.Region(0, 0, 0, 0);
  53. var dragSafe = cfg.dragSafe === true;
  54. this.init = function(dataView) {
  55. view = dataView;
  56. view.on('render', onRender);
  57. };
  58. function fillRegions() {
  59. rs = [];
  60. view.all.each(function(el) {
  61. rs[rs.length] = el.getRegion();
  62. });
  63. bodyRegion = view.el.getRegion();
  64. }
  65. function cancelClick() {
  66. return false;
  67. }
  68. function onBeforeStart(e) {
  69. return !dragSafe || e.target == view.el.dom;
  70. }
  71. function onStart(e) {
  72. view.on('containerclick', cancelClick, view, {
  73. single : true
  74. });
  75. if (!proxy) {
  76. proxy = view.el.createChild({
  77. cls : 'x-view-selector'
  78. });
  79. } else {
  80. proxy.setDisplayed('block');
  81. }
  82. fillRegions();
  83. view.clearSelections();
  84. }
  85. function onDrag(e) {
  86. var startXY = tracker.startXY;
  87. var xy = tracker.getXY();
  88. var x = Math.min(startXY[0], xy[0]);
  89. var y = Math.min(startXY[1], xy[1]);
  90. var w = Math.abs(startXY[0] - xy[0]);
  91. var h = Math.abs(startXY[1] - xy[1]);
  92. dragRegion.left = x;
  93. dragRegion.top = y;
  94. dragRegion.right = x + w;
  95. dragRegion.bottom = y + h;
  96. dragRegion.constrainTo(bodyRegion);
  97. proxy.setRegion(dragRegion);
  98. for (var i = 0, len = rs.length; i < len; i++) {
  99. var r = rs[i], sel = dragRegion.intersect(r);
  100. if (sel && !r.selected) {
  101. r.selected = true;
  102. view.select(i, true);
  103. } else if (!sel && r.selected) {
  104. r.selected = false;
  105. view.deselect(i);
  106. }
  107. }
  108. }
  109. function onEnd(e) {
  110. if (proxy) {
  111. proxy.setDisplayed(false);
  112. }
  113. }
  114. function onRender(view) {
  115. tracker = new Ext.dd.DragTracker({
  116. onBeforeStart : onBeforeStart,
  117. onStart : onStart,
  118. onDrag : onDrag,
  119. onEnd : onEnd
  120. });
  121. tracker.initEl(view.el);
  122. }
  123. };