Commit 0c99c4b7c197b54979b50519dcb3aa50b3996cbf
1 parent
a8c008f1
Exists in
master
and in
103 other branches
Implements plot tab rename
Showing
5 changed files
with
68 additions
and
8 deletions
Show diff stats
js/app/models/PlotTabNode.js
@@ -73,7 +73,7 @@ Ext.define('amdaModel.PlotTabNode', { | @@ -73,7 +73,7 @@ Ext.define('amdaModel.PlotTabNode', { | ||
73 | break; | 73 | break; |
74 | 74 | ||
75 | case 'renameTab': | 75 | case 'renameTab': |
76 | - console.log('renameTab'); | 76 | + this.renameTab(); |
77 | break; | 77 | break; |
78 | default: | 78 | default: |
79 | break; | 79 | break; |
@@ -137,6 +137,17 @@ Ext.define('amdaModel.PlotTabNode', { | @@ -137,6 +137,17 @@ Ext.define('amdaModel.PlotTabNode', { | ||
137 | } | 137 | } |
138 | }); | 138 | }); |
139 | }); | 139 | }); |
140 | - } | ||
141 | - | 140 | + }, |
141 | + | ||
142 | + renameTab: function() { | ||
143 | + if (this.myGetOwnerTree()) { | ||
144 | + var item = this.myGetOwnerTree().getSelectionModel().selected.items[0]; | ||
145 | + this.myGetOwnerTree().fireEvent('edition', this.myGetOwnerTree().view, item); | ||
146 | + } | ||
147 | + }, | ||
148 | + | ||
149 | + rename: function(value,callBackFn) { | ||
150 | + var dataToSend = {id : this.get('tabid'), old_name: this.modified.text, name: value, parent : this.data.parentId, leaf: this.isLeaf(), nodeType: this.get('nodeType')}; | ||
151 | + AmdaAction.renameObject(dataToSend, callBackFn); | ||
152 | + }, | ||
142 | }); | 153 | }); |
js/app/views/ExplorerUI.js
@@ -1028,7 +1028,7 @@ Ext.define( 'MyTreeEditor', { | @@ -1028,7 +1028,7 @@ Ext.define( 'MyTreeEditor', { | ||
1028 | event.record.commit(); | 1028 | event.record.commit(); |
1029 | var rec = event.record.data; | 1029 | var rec = event.record.data; |
1030 | // in case of directory | 1030 | // in case of directory |
1031 | - if (!rec.leaf){ | 1031 | + if (!rec.leaf && (rec.nodeType != 'plottab')){ |
1032 | // set folder's ID returned by server | 1032 | // set folder's ID returned by server |
1033 | rec.id = result.id; | 1033 | rec.id = result.id; |
1034 | } | 1034 | } |
js/app/views/PlotComponents/PlotTabPanel.js
@@ -54,7 +54,7 @@ Ext.define('amdaPlotComp.PlotTabPanel', { | @@ -54,7 +54,7 @@ Ext.define('amdaPlotComp.PlotTabPanel', { | ||
54 | var tabContent = new amdaPlotComp.PlotTabContent({plotElementPanel: this.plotElementPanel, plotTabPanel : this, tabId : tabObject.get('id')}); | 54 | var tabContent = new amdaPlotComp.PlotTabContent({plotElementPanel: this.plotElementPanel, plotTabPanel : this, tabId : tabObject.get('id')}); |
55 | tabContent.setTabObject(tabObject); | 55 | tabContent.setTabObject(tabObject); |
56 | var tabComp = this.add({ | 56 | var tabComp = this.add({ |
57 | - title: 'Plot '+tabNumber, | 57 | + title: (tabObject.get('tab-name') != '') ? tabObject.get('tab-name') : 'Plot '+tabNumber, |
58 | closable: true, | 58 | closable: true, |
59 | layout: 'fit', | 59 | layout: 'fit', |
60 | bodyStyle: 'background: none', | 60 | bodyStyle: 'background: none', |
@@ -96,7 +96,8 @@ Ext.define('amdaPlotComp.PlotTabPanel', { | @@ -96,7 +96,8 @@ Ext.define('amdaPlotComp.PlotTabPanel', { | ||
96 | for (i = 0; i < this.items.getCount(); ++i) | 96 | for (i = 0; i < this.items.getCount(); ++i) |
97 | { | 97 | { |
98 | var tabNumber = i+1; | 98 | var tabNumber = i+1; |
99 | - this.items.getAt(i).setTitle('Plot '+tabNumber); | 99 | + var tabObj = this.object.tabs().getAt(i); |
100 | + this.items.getAt(i).setTitle((tabObj.get('tab-name') != '') ? tabObj.get('tab-name') : 'Plot '+tabNumber); | ||
100 | this.items.getAt(i).items.getAt(0).setTabObject(this.object.tabs().getAt(i)); | 101 | this.items.getAt(i).items.getAt(0).setTabObject(this.object.tabs().getAt(i)); |
101 | } | 102 | } |
102 | }, | 103 | }, |
php/classes/AmdaAction.php
@@ -191,7 +191,7 @@ class AmdaAction | @@ -191,7 +191,7 @@ class AmdaAction | ||
191 | $plotTabs = array(); | 191 | $plotTabs = array(); |
192 | foreach ($objplot->tabs as $index => $tab) { | 192 | foreach ($objplot->tabs as $index => $tab) { |
193 | $plotTabs[$index] = array( | 193 | $plotTabs[$index] = array( |
194 | - "name" => "Plot ".($index+1), | 194 | + "name" => (!empty($tab->{'tab-name'})) ? $tab->{'tab-name'} : "Plot ".($index+1), |
195 | "id" => $tab->id, | 195 | "id" => $tab->id, |
196 | ); | 196 | ); |
197 | } | 197 | } |
@@ -772,6 +772,7 @@ class AmdaAction | @@ -772,6 +772,7 @@ class AmdaAction | ||
772 | break; | 772 | break; |
773 | case 'condition' : | 773 | case 'condition' : |
774 | case 'request' : | 774 | case 'request' : |
775 | + case 'plottab' : | ||
775 | $objectMgr = new RequestMgr($obj->nodeType); | 776 | $objectMgr = new RequestMgr($obj->nodeType); |
776 | break; | 777 | break; |
777 | case 'alias' : | 778 | case 'alias' : |
@@ -861,6 +862,7 @@ class AmdaAction | @@ -861,6 +862,7 @@ class AmdaAction | ||
861 | break; | 862 | break; |
862 | case 'condition' : | 863 | case 'condition' : |
863 | case 'request' : | 864 | case 'request' : |
865 | + case 'plottab' : | ||
864 | $objectMgr = new RequestMgr($obj->nodeType); | 866 | $objectMgr = new RequestMgr($obj->nodeType); |
865 | break; | 867 | break; |
866 | default: | 868 | default: |
php/classes/RequestMgr.php
@@ -30,7 +30,7 @@ class RequestMgr extends AmdaObjectMgr | @@ -30,7 +30,7 @@ class RequestMgr extends AmdaObjectMgr | ||
30 | $this->attributes = array('name' => ''); | 30 | $this->attributes = array('name' => ''); |
31 | $this->optionalAttributes = array(); | 31 | $this->optionalAttributes = array(); |
32 | 32 | ||
33 | - if ($type == 'request') | 33 | + if ($type == 'request' || $type == 'plottab') |
34 | { | 34 | { |
35 | $this->id_prefix = 'req_'; | 35 | $this->id_prefix = 'req_'; |
36 | } | 36 | } |
@@ -70,6 +70,52 @@ class RequestMgr extends AmdaObjectMgr | @@ -70,6 +70,52 @@ class RequestMgr extends AmdaObjectMgr | ||
70 | { | 70 | { |
71 | return false; | 71 | return false; |
72 | } | 72 | } |
73 | + | ||
74 | + public function validNameObject($p) | ||
75 | + { | ||
76 | + if ($this->type == 'plottab') { | ||
77 | + if (empty($p->name)) { | ||
78 | + return array('valid' => false, 'error' => 'Name is required'); | ||
79 | + } | ||
80 | + return array('valid' => true); | ||
81 | + } | ||
82 | + return parent::validNameObject($p); | ||
83 | + } | ||
84 | + | ||
85 | + public function renameObject($p) | ||
86 | + { | ||
87 | + if ($this->type == 'plottab') { | ||
88 | + //Rename a plot tab | ||
89 | + if (!isset($p->parent) || empty($p->parent)) { | ||
90 | + return array('error' => 'Missing parent definition'); | ||
91 | + } | ||
92 | + $plotObj = $this->getObject($p->parent); | ||
93 | + if (is_array($plotObj) && isset($plotObj['error'])) { | ||
94 | + return array('error' => $plotObj['error']); | ||
95 | + } | ||
96 | + if (!isset($plotObj->tabs)) { | ||
97 | + return array('error' => 'Cannot retrieve tab in plot request'); | ||
98 | + } | ||
99 | + $renameOK = FALSE; | ||
100 | + foreach ($plotObj->tabs as &$tab) { | ||
101 | + if ($tab->id == $p->id) { | ||
102 | + $tab->{'tab-name'} = $p->name; | ||
103 | + $renameOK = TRUE; | ||
104 | + break; | ||
105 | + } | ||
106 | + } | ||
107 | + if (!$renameOK) { | ||
108 | + return array('error' => 'Cannot retrieve tab in plot request 2'); | ||
109 | + } | ||
110 | + //Save modification | ||
111 | + $file = fopen(USERREQDIR.$p->parent, 'w'); | ||
112 | + fwrite($file, json_encode($plotObj)); | ||
113 | + fclose($file); | ||
114 | + | ||
115 | + return array('id' => $p->id); | ||
116 | + } | ||
117 | + return parent::renameObject($p); | ||
118 | + } | ||
73 | 119 | ||
74 | /* Stop Time from StartTime and Interval*/ | 120 | /* Stop Time from StartTime and Interval*/ |
75 | public function convertTime($obj) | 121 | public function convertTime($obj) |