| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- Ext.define('school.view.basic.subject.ListController', {
- extend: 'school.view.core.base.BasePanelController',
- alias: 'controller.basic-subject-list',
- onAddClick: function () {
- let me = this,
- view = me.getView(),
- win = Ext.getCmp('subject-addwin');
- if (!win) {
- win = Ext.create('Ext.window.Window', {
- title: '新增学科信息',
- width: 300,
- height: 180,
- id: 'subject-addwin',
- constrain: true,
- modal: true,
- bodyPadding: 10,
- layout: 'fit',
- items: [{
- xtype: 'form',
- layout: 'column',
- defaults: {
- columnWidth: 1
- },
- items: [{
- xtype: 'textfield',
- name: 'text',
- emptyText: '学科名称',
- allowBlank: false,
- maxLength: 20
- }],
- buttonAlign: 'center',
- buttons: [{
- text: '确定',
- formBind: true,
- handler: function () {
- let form = this.up('form');
- let text = form.getValues().text;
- let url, params, headers;
-
- params = JSON.stringify({
- subject_name: text
- });
- view.setLoading(true);
- school.util.BaseUtil.request({
- url: '/api/school/subject/save',
- method: 'POST',
- params: params,
- headers: headers
- }).then(function (res) {
- view.setLoading(false);
- win.close();
- school.util.BaseUtil.showSuccessToast('添加成功');
- view.refresh();
- }).catch(function (e) {
- view.setLoading(false);
- school.util.BaseUtil.showErrorToast('添加失败: ' + e.message);
- });
- }
- }]
- }]
- });
- view.add(win);
- }
- win.show();
- },
- onActionClick: function(tableView, td, row, col, e, record, tr) {
- let me = this;
- let targetCls = event.target.classList;
- if(targetCls.contains('fa-pencil')) {
- me.modifyClick(record.data);
- }else if(targetCls.contains('fa-trash-o')) {
- me.onDeleteClick(record.data.subject_id);
- }
- },
- modifyClick: function (data) {
- let me = this,
- view = me.getView(),
- win = Ext.getCmp('subject-modifywin');
- if (!win) {
- win = Ext.create('Ext.window.Window', {
- title: '修改学科信息',
- width: 300,
- height: 180,
- id: 'subject-modifywin',
- constrain: true,
- modal: true,
- bodyPadding: 10,
- layout: 'fit',
- items: [{
- xtype: 'form',
- layout: 'column',
- defaults: {
- columnWidth: 1
- },
- items: [{
- xtype: 'textfield',
- name: 'text',
- emptyText: '学科名称',
- allowBlank: false,
- maxLength: 20
- }],
- buttonAlign: 'center',
- buttons: [{
- text: '确定',
- formBind: true,
- handler: function () {
- let form = this.up('form');
- let text = form.getValues().text;
- let url, params, headers;
-
- params = JSON.stringify({
- subject_id: data.subject_id,
- subject_name: text
- });
- view.setLoading(true);
- school.util.BaseUtil.request({
- url: '/api/school/subject/save',
- method: 'POST',
- params: params,
- headers: headers
- }).then(function (res) {
- view.setLoading(false);
- win.close();
- school.util.BaseUtil.showSuccessToast('修改成功');
- view.refresh();
- }).catch(function (e) {
- view.setLoading(false);
- school.util.BaseUtil.showErrorToast('修改失败: ' + e.message);
- });
- }
- }]
- }]
- });
- view.add(win);
- win.down('form').getForm().findField('text').setValue(data.subject_name);
- }
- win.show();
- },
- onDeleteClick: function(id) {
- let me = this,
- view = me.getView(),
- grid = view.down('grid'),
- selectedRecords = grid.getSelection(),
- data;
- data = id ? [{
- id: id
- }] : selectedRecords.map(function(r) {
- return {
- id: r.get('subject_id')
- };
- });
- if(data.length == 0) {
- school.util.BaseUtil.showErrorToast('请先勾选需要删除的记录');
- return;
- }
- grid.setLoading(true);
- school.util.BaseUtil.request({
- // url: 'http://10.1.80.47:9560/student/batchDelete',
- url: '/api/school/subject/batchDelete',
- method: 'POST',
- params: JSON.stringify({
- baseDTOs: data
- })
- }).then(function(res) {
- grid.setLoading(false);
- school.util.BaseUtil.showSuccessToast('成功删除' + data.length + '条记录');
- grid.store.loadPage(grid.store.currentPage);
- }).catch(function(e) {
- grid.setLoading(false);
- school.util.BaseUtil.showErrorToast('删除失败: ' + e.message);
- });
- }
- });
|