Ext.define('saas.view.help.DocProjectListController', { extend: 'Ext.app.ViewController', alias: 'controller.help-docproject-list', /** * 新增 */ handleAdd: function () { var me = this, vm = me.getViewModel(), store = vm.getStore('list'); Ext.create({ xtype: 'help-docproject-win', modal: true, autoShow: true, onConfirm: function (data, panel) { me.save(data).then(res => { panel.close(); store.reload(); }); } }); }, /** * 行编辑按钮 * @param {*} view * @param {*} rowIndex */ handleEdit: function (view, rowIndex) { var me = this, vm = me.getViewModel(), store = vm.getStore('list'), record = store.getAt(rowIndex); var panel = Ext.create({ xtype: 'help-docproject-win', modal: true, autoShow: true, onConfirm: function (data) { me.save(data).then(res => { panel.close(); store.reload(); }); } }); panel.loadData(record.data); }, save: function (data) { return Ext.Ajax.payload({ url: '/api/help/project/save', jsonData: data }).then(function (res) { if (res.success) { saas.util.BaseUtil.showSuccessToast('保存成功'); return res; } }).catch(function (e) { saas.util.BaseUtil.showErrorToast('保存失败: ' + e.message); }); }, /** * 行删除按钮 * @param {*} view * @param {*} rowIndex */ handleDelete: function (view, rowIndex) { var me = this; saas.util.BaseUtil.showConfirm('提示', '删除的项目将不能恢复,请确认是否删除?') .then(function (y) { if (y == 'yes') { var store = view.getStore(), record = store.getAt(rowIndex); me.delete(record.get('id')).then(res => { store.remove(record); }); } }); }, delete: function (id) { return Ext.Ajax.payload({ url: '/api/help/project/delete/' + id }).then(function (res) { if (res.success) { saas.util.BaseUtil.showSuccessToast('删除成功'); return res; } }).catch(function (e) { saas.util.BaseUtil.showErrorToast('删除失败: ' + e.message); }); }, onItemDblClick: function (gridview, record) { var addXtype = 'help-docitem-panel', id = record.get('id'), name = record.get('name'); saas.util.BaseUtil.openTab(addXtype, name, addXtype + '-' + id, { initId: id }); } });