dhtmlXGrid_drag.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /*
  2. * Copyright Scand LLC http://www.scbr.com To use this component please contact
  3. * info@scbr.com to obtain license
  4. */
  5. /**
  6. * @desc: enable/disable drag-and-drop
  7. * @type: public
  8. * @edition: Professional
  9. * @param: mode - enabled/disabled [ can be true/false/temporary_disabled - last
  10. * value mean that tree can be D-n-D can be switched to true later ]
  11. * @topic: 0
  12. */
  13. dhtmlXGridObject.prototype.enableDragAndDrop = function(mode) {
  14. if (mode == "temporary_disabled") {
  15. this.dADTempOff = false;
  16. mode = true;
  17. } else
  18. this.dADTempOff = true;
  19. this.dragAndDropOff = convertStringToBoolean(mode);
  20. };
  21. /**
  22. * @desc: set Drag-And-Drop behavior (child - drop as chils, sibling - drop as
  23. * sibling
  24. * @type: public
  25. * @edition: Professional
  26. * @param: mode - behavior name (child,sibling,complex)
  27. * @topic: 0
  28. */
  29. dhtmlXGridObject.prototype.setDragBehavior = function(mode) {
  30. switch (mode) {
  31. case "child" :
  32. this.dadmode = 0;
  33. break;
  34. case "sibling" :
  35. this.dadmode = 1;
  36. break;
  37. }
  38. };
  39. /**
  40. * @desc: create html element for dragging
  41. * @type: private
  42. * @param: htmlObject - html node object
  43. * @topic: 1
  44. */
  45. dhtmlXGridObject.prototype._createDragNode = function(htmlObject) {
  46. htmlObject.parentObject = new Object();
  47. htmlObject.parentObject.treeNod = this;
  48. htmlObject.parentObject.parentNode = htmlObject.parentNode;
  49. if (!this.dADTempOff)
  50. return null;
  51. var dragSpan = document.createElement('div');
  52. dragSpan.innerHTML = this.rowToDragElement(htmlObject.parentNode.idd);
  53. dragSpan.style.position = "absolute";
  54. dragSpan.className = "dragSpanDiv";
  55. return dragSpan;
  56. }
  57. Array.prototype.moveOrder = function(ind1, ind2, mode) {
  58. var tmp = this[ind2]; // moved node
  59. var tmp2 = this[ind1]; // moved node
  60. // remove from old position
  61. for (var i = 0; i < this.length - 1; i++)
  62. if ((this[i] == null) || (this[i] == tmp)) {
  63. this[i] = this[i + 1];
  64. this[i + 1] = null;
  65. }
  66. this[this.length - 1] = null;
  67. // insert in new position
  68. mode = mode || false;
  69. for (var i = 0; i < this.length; i++)
  70. if (!mode) {
  71. if (this[i] == tmp2)
  72. mode = true;
  73. } else {
  74. var tmp2 = this[i];
  75. this[i] = tmp;
  76. tmp = tmp2;
  77. }
  78. }
  79. dhtmlXGridObject.prototype._trsfDr = function(ind, row) {
  80. if (ind)
  81. row = this.rowsCol[ind];
  82. else
  83. ind = this.rowsCol._dhx_find(row);
  84. if (row.parent_id != 0) {
  85. var ind2 = ind;
  86. if ((this.rowsCol[ind2]) && (this.rowsCol[ind2].expand == ""))
  87. ind2 += this.hasChildren(row.idd);
  88. var z = this.loadedKidsHash.get(row.parent_id);
  89. var kz = z._dhx_find(row) + 1;
  90. return [ind2 + 1, kz];
  91. } else
  92. return [ind + 1, ind + 1];
  93. }
  94. dhtmlXGridObject.prototype._drag = function(sourceHtmlObject, dhtmlObject,
  95. targetHtmlObject, innerFlag) {
  96. if (!innerFlag)
  97. this.dadmodex = this.dadmode;
  98. if (this._autoOpenTimer)
  99. window.clearTimeout(this._autoOpenTimer);
  100. // dirty trick for Opera
  101. this._deSelectD();
  102. var r1 = targetHtmlObject.parentNode;
  103. var rInd1 = this.rowsCol._dhx_find(r1)
  104. var r2 = sourceHtmlObject.parentObject;
  105. if (r2 && r2.childNodes) {
  106. if ((!innerFlag) && (this.dragFunc)
  107. && (!this.dragFunc(r2.id, r1.idd, r2.treeNod, this)))
  108. return;
  109. var gridRowId = (allGetServerTime()).getMilliseconds();
  110. var text = new Array(this.getColumnCount());
  111. if (this.isTreeGrid()) {
  112. if (this.dadmodex) {
  113. var z = this._trsfDr(rInd1);
  114. this._dhkPos = z[1];
  115. var rnew = this.addRow(gridRowId, text, z[0], r1.parent_id);
  116. this._dhkPos = null;
  117. this.dadmodex = null;
  118. } else
  119. var rnew = this.addRow(gridRowId, text, (rInd1 + 1), r1.idd);
  120. } else
  121. var rnew = this.addRow(gridRowId, text, (rInd1 + 1));
  122. var flToDel = this.treeToGridElement(r2.treeNod, r2.id, gridRowId);
  123. for (var j = 0; j < r2.childsCount; j++)
  124. this._drag(r2.childNodes[j].span.parentNode, 0, rnew.childNodes[0],
  125. 1)
  126. if (dhtmlObject && flToDel)
  127. r2.treeNod.deleteItem(r2.id, false);
  128. if ((!innerFlag) && (this.dropFunc))
  129. this.dropFunc(r2.id, r1.idd, gridRowId, r2.treeNod, this);
  130. return;
  131. }
  132. var r2 = sourceHtmlObject.parentNode;
  133. var rInd2 = this.rowsCol._dhx_find(r2)
  134. var sgrid = r2.grid;
  135. var tgrid = this;
  136. var id_list = sgrid.getSelectedId();
  137. var list = (id_list || "").split(sgrid.delim);
  138. if (list.length < 2)
  139. id_list = r2.idd;
  140. if ((!innerFlag) && (tgrid.dragFunc)
  141. && (!tgrid.dragFunc(id_list, r1.idd, sgrid, tgrid)))
  142. return;
  143. var id_list2 = "";
  144. if (list.length < 2)
  145. id_list2 = tgrid._dragBTWgrids(sgrid, r2, rInd2, tgrid, r1, rInd1,
  146. innerFlag);
  147. else
  148. for (var i = list.length - 1; i >= 0; i--) {
  149. var r3 = sgrid.getRowIndex(list[i]);
  150. if (r3 != -1)
  151. id_list2 += tgrid._dragBTWgrids(sgrid, sgrid.obj.rows[r3], r3,
  152. tgrid, r1, rInd1)
  153. + ",";
  154. }
  155. if (!innerFlag) {
  156. if (sgrid.setSizes)
  157. sgrid.setSizes();
  158. if (tgrid.setSizes)
  159. tgrid.setSizes();
  160. // alert(id_list+"-||-"+r1.idd+"-||-"+id_list2+"-||-"+sgrid+"-||-"+tgrid);
  161. if (this.dropFunc)
  162. tgrid.dropFunc(id_list, r1.idd, id_list2, sgrid, tgrid);
  163. }
  164. }
  165. dhtmlXGridObject.prototype._dragBTWgrids = function(sgrid, rs, rsind, tgrid,
  166. rt, rtind, innerFlag) {
  167. if (sgrid.dpcpy) { // mercy drag
  168. if (sgrid.cellType._dhx_find("tree") != -1)
  169. return (sgrid._recreateLevel(sgrid, rs, tgrid, rt, rtind + 1))[1];
  170. else {
  171. var newId = rs.idd + "_" + (allGetServerTime()).valueOf();
  172. if (tgrid.cellType._dhx_find("tree") != -1)
  173. if (tgrid.dadmodex) {
  174. var z = tgrid._trsfDr(0, rt);
  175. tgrid._dhkPos = z[1];
  176. tgrid.addRow(newId, tgrid.gridToGrid(rs.idd, sgrid, tgrid),
  177. z[0], rt.parent_id);
  178. tgrid._dhkPos = null;
  179. tgrid.dadmodex = null;
  180. } else
  181. tgrid.addRow(newId, tgrid.gridToGrid(rs.idd, sgrid, tgrid),
  182. "", rt.idd);
  183. else
  184. tgrid.addRow(newId, tgrid.gridToGrid(rs.idd, sgrid, tgrid),
  185. rtind + 1);
  186. tgrid._copyUserData(rs.idd, newId, sgrid, tgrid);
  187. return newId;
  188. }
  189. } else {
  190. if (sgrid == tgrid) {
  191. if (tgrid.isTreeGrid()) {
  192. sgrid.collapseKids(rs);
  193. sgrid.has_kids_dec(sgrid.getRowById(rs.parent_id));
  194. if (!rt.idd) {
  195. tgrid._changeParent(rs, rt);
  196. tgrid.rowsCol._dhx_removeAt(rsind);
  197. tgrid.rowsCol._dhx_insertAt(0, rs);
  198. rs.parentNode.insertBefore(rs, rs.parentNode.childNodes[0])
  199. tgrid._fixLevel(rs);
  200. this.setSizes();
  201. return rs.idd;
  202. }
  203. if (tgrid.dadmodex) {
  204. if (rt.expand == "")
  205. tgrid.collapseKids(rt);
  206. var z = tgrid._trsfDr(0, rt);
  207. tgrid._dhkPos = z[1];
  208. tgrid._changeParent(rs, tgrid.rowsAr[rt.parent_id]);
  209. if (this.rowsCol[z[0]])
  210. rt.parentNode.insertBefore(rs, this.rowsCol[z[0]]);
  211. else
  212. rs.parentNode.appendChild(rs);
  213. this.rowsCol._dhx_removeAt(this.rowsCol._dhx_find(rs));
  214. this.rowsCol._dhx_insertAt(this.rowsCol._dhx_find(rt) + 1,
  215. rs);
  216. tgrid._fixLevel(rs);
  217. tgrid._dhkPos = null;
  218. tgrid.dadmodex = null;
  219. return rs.idd;
  220. } else
  221. tgrid.expandKids(rt);
  222. tgrid._changeParent(rs, rt);
  223. tgrid._fixLevel(rs);
  224. }
  225. if (rt.tagName != "TR") {
  226. rs.parentNode.insertBefore(rs, rs.parentNode.childNodes[0]);
  227. tgrid.rowsCol.moveOrder(0, rsind, true);
  228. this.setSizes();
  229. return rs.idd;
  230. } else if (rt.nextSibling)
  231. rt.parentNode.insertBefore(rs, rt.nextSibling);
  232. else
  233. _isKHTML ? this.obj.appendChild(rs) : tgrid.obj.firstChild
  234. .appendChild(rs);
  235. if (rtind == -1)
  236. rtind = 0;
  237. tgrid.rowsCol.moveOrder(rtind, rsind);
  238. } else {
  239. // moving between grids
  240. tgrid._moveBTW(sgrid, rs, tgrid, rt);
  241. }
  242. return rs.idd;
  243. }
  244. }
  245. dhtmlXGridObject.prototype._recreateLevel = function(sgrid, rs, tgrid, rt,
  246. rtind) {
  247. var newId = rs.idd + "_" + (allGetServerTime()).valueOf();
  248. if (rt.tagName != "TR") {
  249. var r = tgrid.addRow(newId, tgrid.gridToGrid(rs.idd, sgrid, tgrid), 0,
  250. 0, sgrid._getRowImage(rs));
  251. tgrid._copyUserData(rs.idd, newId, sgrid, tgrid);
  252. } else if (tgrid.isTreeGrid()) {
  253. if (tgrid.dadmodex) {
  254. var z = tgrid._trsfDr(0, rt);
  255. tgrid._dhkPos = z[1];
  256. var r = tgrid.addRow(newId, tgrid.gridToGrid(rs.idd, sgrid, tgrid),
  257. z[0], rt.parent_id, sgrid._getRowImage(rs));
  258. tgrid._copyUserData(rs.idd, newId, sgrid, tgrid);
  259. tgrid._dhkPos = null;
  260. tgrid.dadmodex = null;
  261. } else {
  262. var r = tgrid.addRow(newId, tgrid.gridToGrid(rs.idd, sgrid, tgrid),
  263. "", rt.idd, sgrid._getRowImage(rs));
  264. tgrid._copyUserData(rs.idd, newId, sgrid, tgrid);
  265. }
  266. } else {
  267. var r = tgrid.addRow(newId, tgrid.gridToGrid(rs.idd, sgrid, tgrid),
  268. rtind);
  269. tgrid._copyUserData(rs.idd, newId, sgrid, tgrid);
  270. }
  271. rtind++;
  272. var z = sgrid.loadedKidsHash.get(rs.idd);
  273. if (z)
  274. for (var i = 0; i < z.length; i++)
  275. rtind = (sgrid._recreateLevel(sgrid, z[i], tgrid, r, rtind))[0];
  276. return [rtind, newId];
  277. }
  278. dhtmlXGridObject.prototype._moveBTW = function(sgrid, rs, tgrid, rt, fl) {
  279. if (tgrid.isTreeGrid())
  280. if (tgrid.dadmodex) {
  281. var z = tgrid._trsfDr(0, rt);
  282. tgrid._dhkPos = z[1];
  283. var z = tgrid.addRow(rs.idd,
  284. tgrid.gridToGrid(rs.idd, sgrid, tgrid), z[0], rt.parent_id);
  285. tgrid._copyUserData(rs.idd, rs.idd, sgrid, tgrid);
  286. tgrid._dhkPos = null;
  287. tgrid.dadmodex = null;
  288. } else {
  289. var z = tgrid.addRow(rs.idd,
  290. tgrid.gridToGrid(rs.idd, sgrid, tgrid), 0, rt.idd);
  291. tgrid._copyUserData(rs.idd, rs.idd, sgrid, tgrid);
  292. }
  293. else {
  294. var z = tgrid.addRow(rs.idd, tgrid.gridToGrid(rs.idd, sgrid, tgrid),
  295. this.getRowIndex(rt.idd) * 1 + 1);
  296. tgrid._copyUserData(rs.idd, rs.idd, sgrid, tgrid);
  297. }
  298. if (sgrid.isTreeGrid()) {
  299. var a = sgrid.loadedKidsHash.get(rs.idd);
  300. if (a)
  301. for (var i = 0; i < a.length; i++) {
  302. this._moveBTW(sgrid, a[i], tgrid, z, 1)
  303. }
  304. }
  305. if (!fl)
  306. sgrid.deleteRow(rs.idd);
  307. }
  308. /**
  309. * @desc: redefine this method in your code to define how grid row values should
  310. * be used in another grid
  311. * @param: rowId - id of draged row
  312. * @param: sgrid - source grid object
  313. * @param: tgrid - target grid object
  314. * @returns: array of values
  315. * @type: public
  316. * @edition: Professional
  317. * @topic: 7
  318. */
  319. dhtmlXGridObject.prototype.gridToGrid = function(rowId, sgrid, tgrid) {
  320. var z = new Array();
  321. for (var i = 0; i < sgrid.hdr.rows[0].cells.length; i++)
  322. z[i] = sgrid.cells(rowId, i).getValue();
  323. return z;
  324. }
  325. dhtmlXGridObject.prototype.checkParentLine = function(node, id) {
  326. if ((!id) || (!node))
  327. return false;
  328. if (node.idd == id)
  329. return true;
  330. else
  331. return this.checkParentLine(this.getRowById(node.parent_id), id);
  332. }
  333. dhtmlXGridObject.prototype._dragIn = function(htmlObject, shtmlObject, x, y) {
  334. if (!this.dADTempOff)
  335. return 0;
  336. var tree = this.isTreeGrid();
  337. if (htmlObject.parentNode == shtmlObject.parentNode)
  338. return 0;
  339. if ((!tree)
  340. && ((htmlObject.parentNode.nextSibling) && (htmlObject.parentNode.nextSibling == shtmlObject.parentNode)))
  341. return 0;
  342. if ((tree)
  343. && ((this.checkParentLine(htmlObject.parentNode,
  344. shtmlObject.parentNode.idd))))
  345. return 0;
  346. if ((this.dragInFunc)
  347. && (!this.dragInFunc(shtmlObject.parentNode.idd,
  348. htmlObject.parentNode.idd, shtmlObject.parentNode.grid,
  349. htmlObject.parentNode.grid)))
  350. return 0;
  351. this._selectD(htmlObject);
  352. if ((tree) && (htmlObject.parentNode.expand != "")) {
  353. this._autoOpenTimer = window.setTimeout(new callerFunction(
  354. this._autoOpenItem, this), 1000);
  355. this._autoOpenId = htmlObject.parentNode.idd;
  356. } else if (this._autoOpenTimer)
  357. window.clearTimeout(this._autoOpenTimer);
  358. return htmlObject;
  359. }
  360. dhtmlXGridObject.prototype._autoOpenItem = function(e, gridObject) {
  361. gridObject.openItem(gridObject._autoOpenId);
  362. }
  363. dhtmlXGridObject.prototype._dragOut = function(htmlObject) {
  364. this._deSelectD(htmlObject);
  365. if (this._autoOpenTimer)
  366. window.clearTimeout(this._autoOpenTimer);
  367. }
  368. dhtmlXGridObject.prototype._selectD = function(htmlObject) {
  369. this._llSelD = htmlObject;
  370. if (htmlObject.parentNode.tagName == "TR")
  371. for (var i = 0; i < htmlObject.parentNode.childNodes.length; i++) {
  372. var z = htmlObject.parentNode.childNodes[i];
  373. z._bgCol = z.style.backgroundColor;
  374. z.style.backgroundColor = "#FFCCCC";
  375. }
  376. var a1 = getAbsoluteTop(htmlObject);
  377. var a2 = getAbsoluteTop(this.objBox);
  378. // scroll down
  379. if ((a1 - a2 - parseInt(this.objBox.scrollTop)) > (parseInt(this.objBox.offsetHeight) - 50))
  380. this.objBox.scrollTop = parseInt(this.objBox.scrollTop) + 20;
  381. // scroll top
  382. if ((a1 - a2) < (parseInt(this.objBox.scrollTop) + 30))
  383. this.objBox.scrollTop = parseInt(this.objBox.scrollTop) - 20;
  384. }
  385. dhtmlXGridObject.prototype._deSelectD = function() {
  386. if ((this._llSelD) && (this._llSelD.parentNode.tagName == "TR"))
  387. for (var i = 0; i < this._llSelD.parentNode.childNodes.length; i++)
  388. this._llSelD.parentNode.childNodes[i].style.backgroundColor = this._llSelD._bgCol;
  389. this._llSelD = null;
  390. }
  391. /**
  392. * @desc: redefine this method in your code to define how grid row values should
  393. * be displaied while draging
  394. * @param: gridRowId - id of grid row
  395. * @returns: if true, then grid row will be moved to tree, else - copied
  396. * @type: public
  397. * @edition: Professional
  398. * @topic: 7
  399. */
  400. dhtmlXGridObject.prototype.rowToDragElement = function(gridRowId) {
  401. var out = this.cells(gridRowId, 0).getValue();
  402. return out;
  403. }
  404. dhtmlXGridObject.prototype._nonTrivialNode = function(tree, targetObject,
  405. beforeNode, itemObject) {
  406. if (tree.dragFunc)
  407. if (!tree.dragFunc(itemObject.parentNode.idd, targetObject.id,
  408. (beforeNode ? beforeNode.id : null), this, tree))
  409. return false;
  410. var treeNodeId = (allGetServerTime()).getMilliseconds();
  411. tree._attachChildNode(targetObject, treeNodeId, "", "", "", "", "", "", "",
  412. beforeNode);
  413. var gridRowId = itemObject.parentNode.idd;
  414. if (this.gridToTreeElement(tree, treeNodeId, gridRowId))
  415. this.deleteRow(gridRowId);
  416. if (tree.dropFunc)
  417. tree.dropFunc(treeNodeId, targetObject.id, (beforeNode
  418. ? beforeNode.id
  419. : null), this, tree);
  420. }
  421. /**
  422. * @desc: redefine this method in your code to define how grid row values should
  423. * be used in tree (using input parameters you can change id of new tree
  424. * node, set label, set userdata blocks etc.).
  425. * @param: treeObj - object of tree
  426. * @param: treeNodeId - id of node created in tree
  427. * @param: gridRowId - id of grid row
  428. * @returns: if true, then grid row will be moved to tree, else - copied
  429. * @type: public
  430. * @edition: Professional
  431. * @topic: 7
  432. */
  433. dhtmlXGridObject.prototype.gridToTreeElement = function(treeObj, treeNodeId,
  434. gridRowId) {
  435. treeObj.setItemText(treeNodeId, this.cells(gridRowId, 0).getValue());
  436. return true;
  437. }
  438. /**
  439. * @desc: redefine this method in your code to define how tree node values
  440. * should be used in grid (using input parameters you can change id of
  441. * new row, values for cells, userdata blocks etc.).
  442. * @param: treeObj - object of tree
  443. * @param: treeNodeId - id of node created in tree
  444. * @param: gridRowId - id of grid row
  445. * @returns: if true, then tree node should be moved to grid, else - copied
  446. * @type: public
  447. * @edition: Professional
  448. * @topic: 7
  449. */
  450. dhtmlXGridObject.prototype.treeToGridElement = function(treeObj, treeNodeId,
  451. gridRowId) {
  452. for (var i = 0; i < this.getColumnCount(); i++) {
  453. this.cells(gridRowId, i).setValue(treeObj.getUserData(treeNodeId, this
  454. .getColumnId(i)));
  455. }
  456. return true;
  457. }
  458. dhtmlXGridObject.prototype._copyUserData = function(sId, tId, sG, tG) {
  459. var z1 = sG.UserData[sId];
  460. var z2 = new Hashtable();
  461. if (z1) {
  462. z2.keys = z2.keys.concat(z1.keys);
  463. z2.values = z2.values.concat(z1.values);
  464. }
  465. tG.UserData[tId] = z2;
  466. }
  467. /**
  468. * @desc: move row
  469. * @type: public
  470. * @param: srowId - source row Id
  471. * @param: trowId - target row Id
  472. * @param: mode - moving mode (up,down,row_sibling)
  473. * @param: targetId - target row in row_sibling mode
  474. * @param: targetGrid - used for moving between grids (optional)
  475. * @edition: Professional
  476. * @topic: 2
  477. */
  478. dhtmlXGridObject.prototype.moveRow = function(rowId, mode, targetId, targetGrid) {
  479. switch (mode) {
  480. case "row_sibling" :
  481. var sNode = this.getRowById(rowId);
  482. if (!sNode)
  483. return (0);
  484. var a = {
  485. parentNode : sNode
  486. };
  487. var tNode = (targetGrid || this).getRowById(targetId);
  488. if (!tNode)
  489. return (0);
  490. var b = {
  491. parentNode : tNode
  492. };
  493. (targetGrid || this)._drag(a, this, b);
  494. break;
  495. case "up" :
  496. this.moveRowUp(rowId);
  497. break;
  498. case "down" :
  499. this.moveRowDown(rowId);
  500. break;
  501. }
  502. }
  503. /**
  504. * @desc: set function called when drag-and-drop event occured
  505. * @param: aFunc - event handling function
  506. * @type: public
  507. * @topic: 10
  508. * @event: onDrag
  509. * @eventdesc: Event occured after item was dragged and droped on another item,
  510. * but before item moving processed. Event also raised while
  511. * programmatic moving nodes.
  512. * @eventparam: ID of source item
  513. * @eventparam: ID of target item
  514. * @eventparam: source grid object
  515. * @eventparam: target grid object
  516. * @eventreturn: true - confirm drag-and-drop; false - deny drag-and-drop;
  517. */
  518. dhtmlXGridObject.prototype.setDragHandler = function(func) {
  519. if (typeof(func) == "function")
  520. this.dragFunc = func;
  521. else
  522. this.dragFunc = eval(func);
  523. };
  524. /**
  525. * @desc: set function called after drag-and-drap event occured
  526. * @param: func - event handling function
  527. * @type: public
  528. * @edition: Professional
  529. * @topic: 10
  530. * @event: onDrop
  531. * @eventdesc: Event raised after drag-and-drop processed.
  532. * @eventparam: ID of source item
  533. * @eventparam: ID of target item
  534. * @eventparam: ID of droped item (has sense for mercy drag-n-drop)
  535. * @eventparam: source grid object
  536. * @eventparam: target grid object
  537. */
  538. dhtmlXGridObject.prototype.setDropHandler = function(func) {
  539. if (typeof(func) == "function")
  540. this.dropFunc = func;
  541. else
  542. this.dropFunc = eval(func);
  543. };
  544. /**
  545. * @desc: set function called when drag moved over potencial landing
  546. * @param: func - event handling function
  547. * @type: public
  548. * @edition: Professional
  549. * @topic: 10
  550. * @event: onDragIn
  551. * @eventdesc: Event raised if drag moved over potencial landing
  552. * @eventparam: ID of source item
  553. * @eventparam: ID of target item
  554. * @eventparam: source grid object
  555. * @eventparam: target grid object
  556. * @eventreturn: true - allow landing; false - deny landing;
  557. */
  558. dhtmlXGridObject.prototype.setDragInHandler = function(func) {
  559. if (typeof(func) == "function")
  560. this.dragInFunc = func;
  561. else
  562. this.dragInFunc = eval(func);
  563. };
  564. /**
  565. * @desc: enable drag without removing (copy instead of move)
  566. * @beforeInit: 1
  567. * @param: mode - 1 - on, 0 - off;
  568. * @type: public
  569. * @edition:Professional
  570. * @topic: 0
  571. */
  572. dhtmlXGridObject.prototype.enableMercyDrag = function(mode) {
  573. this.dpcpy = convertStringToBoolean(mode);
  574. };