DocProjectListController.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. Ext.define('saas.view.help.DocProjectListController', {
  2. extend: 'Ext.app.ViewController',
  3. alias: 'controller.help-docproject-list',
  4. /**
  5. * 新增
  6. */
  7. handleAdd: function () {
  8. var me = this, vm = me.getViewModel(), store = vm.getStore('list');
  9. Ext.create({
  10. xtype: 'help-docproject-win',
  11. modal: true,
  12. autoShow: true,
  13. onConfirm: function (data, panel) {
  14. me.save(data).then(res => {
  15. panel.close();
  16. store.reload();
  17. });
  18. }
  19. });
  20. },
  21. /**
  22. * 行编辑按钮
  23. * @param {*} view
  24. * @param {*} rowIndex
  25. */
  26. handleEdit: function (view, rowIndex) {
  27. var me = this, vm = me.getViewModel(),
  28. store = vm.getStore('list'),
  29. record = store.getAt(rowIndex);
  30. var panel = Ext.create({
  31. xtype: 'help-docproject-win',
  32. modal: true,
  33. autoShow: true,
  34. onConfirm: function (data) {
  35. me.save(data).then(res => {
  36. panel.close();
  37. store.reload();
  38. });
  39. }
  40. });
  41. panel.loadData(record.data);
  42. },
  43. save: function (data) {
  44. return Ext.Ajax.payload({
  45. url: '/api/help/project/save',
  46. jsonData: data
  47. }).then(function (res) {
  48. if (res.success) {
  49. saas.util.BaseUtil.showSuccessToast('保存成功');
  50. return res;
  51. }
  52. }).catch(function (e) {
  53. saas.util.BaseUtil.showErrorToast('保存失败: ' + e.message);
  54. });
  55. },
  56. /**
  57. * 行删除按钮
  58. * @param {*} view
  59. * @param {*} rowIndex
  60. */
  61. handleDelete: function (view, rowIndex) {
  62. var me = this;
  63. saas.util.BaseUtil.showConfirm('提示', '删除的项目将不能恢复,请确认是否删除?')
  64. .then(function (y) {
  65. if (y == 'yes') {
  66. var store = view.getStore(), record = store.getAt(rowIndex);
  67. me.delete(record.get('id')).then(res => {
  68. store.remove(record);
  69. });
  70. }
  71. });
  72. },
  73. delete: function (id) {
  74. return Ext.Ajax.payload({
  75. url: '/api/help/project/delete/' + id
  76. }).then(function (res) {
  77. if (res.success) {
  78. saas.util.BaseUtil.showSuccessToast('删除成功');
  79. return res;
  80. }
  81. }).catch(function (e) {
  82. saas.util.BaseUtil.showErrorToast('删除失败: ' + e.message);
  83. });
  84. },
  85. onItemDblClick: function (gridview, record) {
  86. var addXtype = 'help-docitem-panel', id = record.get('id'), name = record.get('name');
  87. saas.util.BaseUtil.openTab(addXtype, name, addXtype + '-' + id, {
  88. initId: id
  89. });
  90. }
  91. });