Commit 0c99c4b7c197b54979b50519dcb3aa50b3996cbf
1 parent
a8c008f1
Exists in
master
and in
102 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 | 73 | break; |
74 | 74 | |
75 | 75 | case 'renameTab': |
76 | - console.log('renameTab'); | |
76 | + this.renameTab(); | |
77 | 77 | break; |
78 | 78 | default: |
79 | 79 | break; |
... | ... | @@ -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 | 1028 | event.record.commit(); |
1029 | 1029 | var rec = event.record.data; |
1030 | 1030 | // in case of directory |
1031 | - if (!rec.leaf){ | |
1031 | + if (!rec.leaf && (rec.nodeType != 'plottab')){ | |
1032 | 1032 | // set folder's ID returned by server |
1033 | 1033 | rec.id = result.id; |
1034 | 1034 | } |
... | ... |
js/app/views/PlotComponents/PlotTabPanel.js
... | ... | @@ -54,7 +54,7 @@ Ext.define('amdaPlotComp.PlotTabPanel', { |
54 | 54 | var tabContent = new amdaPlotComp.PlotTabContent({plotElementPanel: this.plotElementPanel, plotTabPanel : this, tabId : tabObject.get('id')}); |
55 | 55 | tabContent.setTabObject(tabObject); |
56 | 56 | var tabComp = this.add({ |
57 | - title: 'Plot '+tabNumber, | |
57 | + title: (tabObject.get('tab-name') != '') ? tabObject.get('tab-name') : 'Plot '+tabNumber, | |
58 | 58 | closable: true, |
59 | 59 | layout: 'fit', |
60 | 60 | bodyStyle: 'background: none', |
... | ... | @@ -96,7 +96,8 @@ Ext.define('amdaPlotComp.PlotTabPanel', { |
96 | 96 | for (i = 0; i < this.items.getCount(); ++i) |
97 | 97 | { |
98 | 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 | 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 | 191 | $plotTabs = array(); |
192 | 192 | foreach ($objplot->tabs as $index => $tab) { |
193 | 193 | $plotTabs[$index] = array( |
194 | - "name" => "Plot ".($index+1), | |
194 | + "name" => (!empty($tab->{'tab-name'})) ? $tab->{'tab-name'} : "Plot ".($index+1), | |
195 | 195 | "id" => $tab->id, |
196 | 196 | ); |
197 | 197 | } |
... | ... | @@ -772,6 +772,7 @@ class AmdaAction |
772 | 772 | break; |
773 | 773 | case 'condition' : |
774 | 774 | case 'request' : |
775 | + case 'plottab' : | |
775 | 776 | $objectMgr = new RequestMgr($obj->nodeType); |
776 | 777 | break; |
777 | 778 | case 'alias' : |
... | ... | @@ -861,6 +862,7 @@ class AmdaAction |
861 | 862 | break; |
862 | 863 | case 'condition' : |
863 | 864 | case 'request' : |
865 | + case 'plottab' : | |
864 | 866 | $objectMgr = new RequestMgr($obj->nodeType); |
865 | 867 | break; |
866 | 868 | default: |
... | ... |
php/classes/RequestMgr.php
... | ... | @@ -30,7 +30,7 @@ class RequestMgr extends AmdaObjectMgr |
30 | 30 | $this->attributes = array('name' => ''); |
31 | 31 | $this->optionalAttributes = array(); |
32 | 32 | |
33 | - if ($type == 'request') | |
33 | + if ($type == 'request' || $type == 'plottab') | |
34 | 34 | { |
35 | 35 | $this->id_prefix = 'req_'; |
36 | 36 | } |
... | ... | @@ -70,6 +70,52 @@ class RequestMgr extends AmdaObjectMgr |
70 | 70 | { |
71 | 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 | 120 | /* Stop Time from StartTime and Interval*/ |
75 | 121 | public function convertTime($obj) |
... | ... |