Commit 7cf5fd1694355b5e57e40b00cc00498ed4d47c3c
1 parent
7ef7ea02
Exists in
master
and in
111 other branches
Move param in plot tree
Showing
1 changed file
with
127 additions
and
3 deletions
Show diff stats
js/app/views/PlotComponents/PlotTree.js
... | ... | @@ -329,6 +329,104 @@ Ext.define('amdaPlotComp.PlotTree', { |
329 | 329 | |
330 | 330 | moveParam : function(record,targetNode,position) |
331 | 331 | { |
332 | + if (record.$className != 'amdaPlotObj.PlotParamTreeNode') | |
333 | + return false; | |
334 | + | |
335 | + var fromIndex = record.parentNode.indexOf(record); | |
336 | + var toIndex = targetNode.parentNode.indexOf(targetNode); | |
337 | + | |
338 | + var fromPanelObject = null; | |
339 | + if (!this.tabObject.get('tree-simplified-view')) | |
340 | + { | |
341 | + fromPanelObject = record.parentNode.parentNode.object; | |
342 | + } | |
343 | + else | |
344 | + fromPanelObject = record.parentNode.object; | |
345 | + if (fromPanelObject == null) | |
346 | + return false; | |
347 | + | |
348 | + switch (targetNode.$className) | |
349 | + { | |
350 | + case 'amdaPlotObj.PlotPanelTreeNode' : | |
351 | + case 'amdaPlotObj.PlotParamsTreeNode' : | |
352 | + var toPanelObject = targetNode.object; | |
353 | + if (toPanelObject.get('panel-plot-type') != fromPanelObject.get('panel-plot-type')) | |
354 | + return false; | |
355 | + if (toPanelObject == fromPanelObject) | |
356 | + { | |
357 | + //Move param on the same panel | |
358 | + fromPanelObject.params().data.removeAt(fromIndex); | |
359 | + toPanelObject.params().data.add(record.object); | |
360 | + this.buildPanelParamsNode(toPanelObject, record.object.get('id')); | |
361 | + } | |
362 | + else | |
363 | + { | |
364 | + //Move param on another panel | |
365 | + var clonedObject = record.object.copy(); | |
366 | + fromPanelObject.params().remove(record.object); | |
367 | + toPanelObject.set('last-param-id', toPanelObject.get('last-param-id')+1); | |
368 | + clonedObject.set('id', toPanelObject.get('last-param-id')); | |
369 | + toPanelObject.params().add(clonedObject); | |
370 | + this.buildPanelParamsNode(fromPanelObject); | |
371 | + this.buildPanelParamsNode(toPanelObject, clonedObject.get('id')); | |
372 | + } | |
373 | + return true; | |
374 | + case 'amdaPlotObj.PlotParamTreeNode' : | |
375 | + var toPanelObject = null; | |
376 | + if (!this.tabObject.get('tree-simplified-view')) | |
377 | + { | |
378 | + toPanelObject = targetNode.parentNode.parentNode.object; | |
379 | + } | |
380 | + else | |
381 | + toPanelObject = targetNode.parentNode.object; | |
382 | + targetNode.object; | |
383 | + if (toPanelObject.get('panel-plot-type') != fromPanelObject.get('panel-plot-type')) | |
384 | + return false; | |
385 | + | |
386 | + if (toPanelObject == fromPanelObject) | |
387 | + { | |
388 | + //Move param on the same panel | |
389 | + var insertIndex = -1; | |
390 | + switch (position) | |
391 | + { | |
392 | + case 'before' : | |
393 | + insertIndex = (fromIndex > toIndex) ? toIndex : toIndex - 1; | |
394 | + break; | |
395 | + case 'after' : | |
396 | + default : | |
397 | + insertIndex = (fromIndex > toIndex) ? toIndex + 1 : toIndex; | |
398 | + break; | |
399 | + } | |
400 | + fromPanelObject.params().data.removeAt(fromIndex); | |
401 | + toPanelObject.params().data.insert(insertIndex, record.object); | |
402 | + this.buildPanelParamsNode(toPanelObject, record.object.get('id')); | |
403 | + } | |
404 | + else | |
405 | + { | |
406 | + //move param on another panel | |
407 | + var insertIndex = -1; | |
408 | + switch (position) | |
409 | + { | |
410 | + case 'before' : | |
411 | + insertIndex = (toIndex == 0) ? 0: toIndex - 1; | |
412 | + break; | |
413 | + case 'after' : | |
414 | + default : | |
415 | + insertIndex = toIndex + 1; | |
416 | + break; | |
417 | + } | |
418 | + var clonedObject = record.object.copy(); | |
419 | + fromPanelObject.params().remove(record.object); | |
420 | + toPanelObject.set('last-param-id', toPanelObject.get('last-param-id')+1); | |
421 | + clonedObject.set('id', toPanelObject.get('last-param-id')); | |
422 | + toPanelObject.params().insert(insertIndex, clonedObject); | |
423 | + this.buildPanelParamsNode(fromPanelObject); | |
424 | + this.buildPanelParamsNode(toPanelObject, clonedObject.get('id')); | |
425 | + } | |
426 | + return true; | |
427 | + } | |
428 | + return false; | |
429 | + | |
332 | 430 | /*var fromIndex = targetNode.parentNode.indexOf(record); |
333 | 431 | var toIndex = targetNode.parentNode.indexOf(targetNode); |
334 | 432 | |
... | ... | @@ -357,8 +455,6 @@ Ext.define('amdaPlotComp.PlotTree', { |
357 | 455 | return false; |
358 | 456 | }*/ |
359 | 457 | |
360 | - console.log('ToDo move param'); | |
361 | - | |
362 | 458 | return true; |
363 | 459 | }, |
364 | 460 | |
... | ... | @@ -484,7 +580,35 @@ Ext.define('amdaPlotComp.PlotTree', { |
484 | 580 | case 'amdaModel.MyDataParamNode' : |
485 | 581 | return record.isLeaf(); |
486 | 582 | case 'amdaPlotObj.PlotParamTreeNode' : |
487 | - return true; | |
583 | + var fromPanelObject = null; | |
584 | + if (!this.tabObject.get('tree-simplified-view')) | |
585 | + { | |
586 | + fromPanelObject = record.parentNode.parentNode.object; | |
587 | + } | |
588 | + else | |
589 | + fromPanelObject = record.parentNode.object; | |
590 | + if (fromPanelObject == null) | |
591 | + return false; | |
592 | + | |
593 | + var toPanelObject = null; | |
594 | + switch (targetNode.$className) | |
595 | + { | |
596 | + case 'amdaPlotObj.PlotPanelTreeNode' : | |
597 | + case 'amdaPlotObj.PlotParamsTreeNode' : | |
598 | + toPanelObject = targetNode.object; | |
599 | + break; | |
600 | + case 'amdaPlotObj.PlotParamTreeNode' : | |
601 | + if (!this.tabObject.get('tree-simplified-view')) | |
602 | + { | |
603 | + toPanelObject = targetNode.parentNode.parentNode.object; | |
604 | + } | |
605 | + else | |
606 | + toPanelObject = targetNode.parentNode.object; | |
607 | + break; | |
608 | + } | |
609 | + if (toPanelObject == null) | |
610 | + return false; | |
611 | + return (fromPanelObject.get('panel-plot-type') == toPanelObject.get('panel-plot-type')); | |
488 | 612 | case 'amdaPlotObj.PlotPanelTreeNode' : |
489 | 613 | switch (position) |
490 | 614 | { | ... | ... |