Commit 893445acd3aec8543c9d94a612d4fea9e80935c0
1 parent
35438055
Ajax
Showing
3 changed files
with
25 additions
and
4 deletions
Show diff stats
src/app/pages/statements/components/busStop2/busStop2.component.ts
... | ... | @@ -110,7 +110,7 @@ export class BusStop2 { |
110 | 110 | }, |
111 | 111 | { |
112 | 112 | headerName: 'ID', |
113 | - field: 'id', | |
113 | + field: 'busStopId', | |
114 | 114 | width: 150 |
115 | 115 | }, |
116 | 116 | { |
... | ... | @@ -167,14 +167,22 @@ export class BusStop2 { |
167 | 167 | ]; |
168 | 168 | } |
169 | 169 | |
170 | - | |
171 | 170 | private onCellClicked($event) { |
172 | 171 | console.log('onCellClicked: ' + $event.rowIndex + ' ' + $event.colDef.field); |
173 | 172 | } |
174 | 173 | |
175 | 174 | private onCellValueChanged($event) { |
176 | - console.log($event.data); | |
177 | - console.log('onCellValueChanged: ' + $event.oldValue + ' to ' + $event.newValue); | |
175 | + if ($event.oldValue !== $event.newValue) { | |
176 | + let data = JSON.stringify($event.data); | |
177 | + let id = $event.data.busStopId; | |
178 | + let result = null; | |
179 | + if (id) { | |
180 | + result = this.service.update(id, data); | |
181 | + } else { | |
182 | + result = this.service.create(data); | |
183 | + } | |
184 | + console.log(result); | |
185 | + } | |
178 | 186 | } |
179 | 187 | |
180 | 188 | private onCellDoubleClicked($event) { | ... | ... |
src/app/pages/statements/components/busStop2/busStop2.service.ts
... | ... | @@ -32,6 +32,18 @@ export class BusStop2Service { |
32 | 32 | .then(response => response.json().busStopEditDsM as busStop2[]) |
33 | 33 | .catch(this.handleError); |
34 | 34 | } |
35 | + update(id: number, data: string): Promise<any> { | |
36 | + return this.http.post(this.url + '/update?id=' + id + '&data=' + data, {}, this.headers) | |
37 | + .toPromise() | |
38 | + .then(response => response.json()) | |
39 | + .catch(this.handleError); | |
40 | + } | |
41 | + create(data: string): Promise<any> { | |
42 | + return this.http.post(this.url + '/create?data=' + data, {}) | |
43 | + .toPromise() | |
44 | + .then(response => response.json()) | |
45 | + .catch(this.handleError); | |
46 | + } | |
35 | 47 | private handleError(error: any): Promise<any> { |
36 | 48 | console.error('An error occured', error); |
37 | 49 | return Promise.reject(error.message || error); | ... | ... |