|
2 | 2 | Vue.component('apijson-table', { |
3 | 3 | delimiters: ['{', '}'], |
4 | 4 | props: [ |
5 | | - "table_name", |
| 5 | + "model_name", //apijson model name |
| 6 | + "request_tag", //apijson request tag, default will be same with model name |
6 | 7 | "config", |
7 | 8 | "custom_tcolumns_render_generator", |
8 | 9 | "hook_init", |
|
44 | 45 | </div> |
45 | 46 | </modal> |
46 | 47 | <modal v-model="modal_delete" title="Confirm to delete" @on-ok="real_remove"> |
47 | | - <p>Confirm to delete #{delete_params.row&&delete_params.row.id} in table '{table_name}'?</p> |
| 48 | + <p>Confirm to delete #{delete_params.row&&delete_params.row.id} in table '{model_name}'?</p> |
48 | 49 | </modal> |
49 | 50 | </div>`, |
50 | 51 | data: function(){ |
51 | 52 | var thisp = this |
52 | 53 | return { |
| 54 | + l_request_tag: null, |
| 55 | + |
53 | 56 | loading: false, |
54 | 57 | modal_view: false, |
55 | 58 | viewedit_items: [], |
|
172 | 175 | "@page":thisp.current_page-1, |
173 | 176 | "@query":2 |
174 | 177 | } |
175 | | - arr_params[this.table_name] = { |
| 178 | + arr_params[this.model_name] = { |
176 | 179 | "@order":thisp.sort_key+thisp.sort_order, |
177 | 180 | "@role":"{{=role}}" |
178 | 181 | } |
|
225 | 228 | } |
226 | 229 | else { |
227 | 230 | thisp.$Notice.error({ |
228 | | - title: 'error when get table '+thisp.table_name, |
| 231 | + title: 'error when get table '+thisp.model_name, |
229 | 232 | desc: data.msg |
230 | 233 | }) |
231 | 234 | } |
|
276 | 279 | save: function(){ |
277 | 280 | var thisp = this |
278 | 281 | var params = { |
279 | | - "@tag": thisp.table_name |
| 282 | + "@tag": thisp.l_request_tag |
280 | 283 | } |
281 | 284 | var record_params = {} |
282 | 285 | var row = thisp.edit_params.row |
283 | 286 |
|
| 287 | + //only save modified fields |
284 | 288 | for (var k in thisp.viewedit_items) { |
285 | 289 | var d = thisp.viewedit_items[k] |
286 | 290 | if (d.key=="id"|| d.value!=row[d.key]) { |
287 | 291 | record_params[d.key] = d.value |
288 | 292 | } |
289 | 293 | } |
290 | | - params[thisp.table_name] = record_params |
| 294 | + params[thisp.l_request_tag] = record_params |
291 | 295 | params = thisp.ajax_hook("apijson_put","update",params) |
292 | 296 | $.ajax({ |
293 | 297 | type: "POST", |
|
297 | 301 | success: function (data) { |
298 | 302 | if (data.code==200){ |
299 | 303 | thisp.$Notice.success({ |
300 | | - title: 'success update #'+row.id+' in table '+thisp.table_name, |
| 304 | + title: 'success update #'+row.id+' in table '+thisp.model_name, |
301 | 305 | desc: data.msg |
302 | 306 | }) |
303 | 307 | thisp.modal_view = false |
304 | 308 | thisp.update_list() |
305 | 309 | } |
306 | 310 | else { |
307 | 311 | thisp.$Notice.error({ |
308 | | - title: 'error when update #'+row.id+' in table '+thisp.table_name, |
| 312 | + title: 'error when update #'+row.id+' in table '+thisp.model_name, |
309 | 313 | desc: data.msg |
310 | 314 | }) |
311 | 315 | } |
|
323 | 327 | real_remove_set_deleted: function(){ |
324 | 328 | var thisp = this |
325 | 329 | var params = { |
326 | | - "@tag": thisp.table_name |
| 330 | + "@tag": thisp.l_request_tag |
327 | 331 | } |
328 | 332 | var params_table = { |
329 | 333 | "id": thisp.delete_params.row.id, |
330 | 334 | } |
331 | 335 | params_table[this.config_deleted_field_name] = true |
332 | | - params[thisp.table_name] = params_table |
| 336 | + params[thisp.l_request_tag] = params_table |
333 | 337 |
|
334 | 338 | params = thisp.ajax_hook("apijson_put","delete",params) |
335 | 339 |
|
|
341 | 345 | success: function (data) { |
342 | 346 | if (data.code!=200){ |
343 | 347 | thisp.$Notice.error({ |
344 | | - title: 'error when remove #'+thisp.delete_params.row.id+' in table '+thisp.table_name, |
| 348 | + title: 'error when remove #'+thisp.delete_params.row.id+' in table '+thisp.model_name, |
345 | 349 | desc: data.msg |
346 | 350 | }) |
347 | 351 | return |
348 | 352 | } |
349 | | - var result = data[thisp.table_name] |
| 353 | + var result = data[thisp.l_request_tag] |
350 | 354 | if (result.code!=200){ |
351 | 355 | thisp.$Notice.error({ |
352 | | - title: 'error when remove #'+thisp.delete_params.row.id+' in table '+thisp.table_name, |
| 356 | + title: 'error when remove #'+thisp.delete_params.row.id+' in table '+thisp.model_name, |
353 | 357 | desc: result.msg |
354 | 358 | }) |
355 | 359 | return |
356 | 360 | } |
357 | 361 | thisp.$Notice.success({ |
358 | | - title: 'success remove #'+thisp.delete_params.row.id+' in table '+thisp.table_name, |
| 362 | + title: 'success remove #'+thisp.delete_params.row.id+' in table '+thisp.model_name, |
359 | 363 | desc: result.msg |
360 | 364 | }) |
361 | 365 | thisp.update_list() |
|
365 | 369 | real_remove_delete: function(){ |
366 | 370 | var thisp = this |
367 | 371 | var params = { |
368 | | - "@tag": thisp.table_name |
| 372 | + "@tag": thisp.l_request_tag |
369 | 373 | } |
370 | | - params[thisp.table_name] = { |
| 374 | + params[thisp.l_request_tag] = { |
371 | 375 | "id": thisp.delete_params.row.id |
372 | 376 | } |
373 | 377 | params = thisp.ajax_hook("apijson_delete","delete",params) |
|
379 | 383 | success: function (data) { |
380 | 384 | if (data.code!=200){ |
381 | 385 | thisp.$Notice.error({ |
382 | | - title: 'error when remove #'+thisp.delete_params.row.id+' in table '+thisp.table_name, |
| 386 | + title: 'error when remove #'+thisp.delete_params.row.id+' in table '+thisp.model_name, |
383 | 387 | desc: data.msg |
384 | 388 | }) |
385 | 389 | return |
386 | 390 | } |
387 | | - var result = data[thisp.table_name] |
| 391 | + var result = data[thisp.l_request_tag] |
388 | 392 | if (result.code!=200){ |
389 | 393 | thisp.$Notice.error({ |
390 | | - title: 'error when remove #'+thisp.delete_params.row.id+' in table '+thisp.table_name, |
| 394 | + title: 'error when remove #'+thisp.delete_params.row.id+' in table '+thisp.model_name, |
391 | 395 | desc: result.msg |
392 | 396 | }) |
393 | 397 | return |
394 | 398 | } |
395 | 399 | thisp.$Notice.success({ |
396 | | - title: 'success remove #'+thisp.delete_params.row.id+' in table '+thisp.table_name, |
| 400 | + title: 'success remove #'+thisp.delete_params.row.id+' in table '+thisp.model_name, |
397 | 401 | desc: result.msg |
398 | 402 | }) |
399 | 403 | thisp.update_list() |
|
411 | 415 | real_add: function(){ |
412 | 416 | thisp = this |
413 | 417 | var params = { |
414 | | - "@tag": thisp.table_name |
| 418 | + "@tag": thisp.l_request_tag |
415 | 419 | } |
416 | 420 | var post_params = {} |
417 | 421 | for (var k in thisp.add_items) { |
418 | 422 | var d = thisp.add_items[k] |
419 | 423 | post_params[d.key] = d.value |
420 | 424 | } |
421 | | - params[this.table_name] = post_params |
| 425 | + params[this.l_request_tag] = post_params |
422 | 426 | params = thisp.ajax_hook("apijson_post","add",params) |
423 | 427 | $.ajax({ |
424 | 428 | type: "POST", |
|
428 | 432 | success: function (data) { |
429 | 433 | if (data.code!=200){ |
430 | 434 | thisp.$Notice.error({ |
431 | | - title: 'error when add new record in table '+thisp.table_name, |
| 435 | + title: 'error when add new record in table '+thisp.model_name, |
432 | 436 | desc: data.msg |
433 | 437 | }) |
434 | 438 | return |
435 | 439 | } |
436 | | - var result = data[thisp.table_name] |
| 440 | + var result = data[thisp.l_request_tag] |
437 | 441 | thisp.$Notice.success({ |
438 | | - title: 'success add #'+result.id+' in table '+thisp.table_name, |
| 442 | + title: 'success add #'+result.id+' in table '+thisp.model_name, |
439 | 443 | desc: result.msg |
440 | 444 | }) |
441 | 445 | thisp.update_list() |
|
456 | 460 | } |
457 | 461 | }, |
458 | 462 | mounted: function(){ |
| 463 | + if (this.request_tag==null) { |
| 464 | + this.l_request_tag = this.model_name |
| 465 | + } |
| 466 | + else { |
| 467 | + this.l_request_tag = this.request_tag |
| 468 | + } |
| 469 | + |
459 | 470 | if (this.config!=null){ |
460 | 471 | this.config_editable = this.config.editable || false |
461 | 472 | this.config_table_fields = this.config.table_fields || null |
|
0 commit comments