FormPanelController.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. Ext.define('saas.view.sys.config.FormPanelController', {
  2. extend: 'Ext.app.ViewController',
  3. alias: 'controller.sys-config-formpanel',
  4. init: function (form) {
  5. var me = this;
  6. this.control({
  7. 'button[name=save]':{
  8. click:function(){
  9. me.onSave();
  10. }
  11. }
  12. });
  13. },
  14. onSave: function() {
  15. var me = this,
  16. form = this.getView();
  17. var valid = form.isValid();
  18. if(!valid) {
  19. saas.util.BaseUtil.showErrorToast('表单校验有误,请检查');
  20. return false;
  21. }
  22. if(form.getForm().wasDirty==false){
  23. saas.util.BaseUtil.showErrorToast('未修改数据,请修改后保存');
  24. return false;
  25. }
  26. viewModel = me.getViewModel();
  27. var formData = viewModel.data;
  28. formData.en_name = null;
  29. formData.updateTime = null;
  30. saas.util.BaseUtil.request({
  31. url: form._saveUrl,
  32. params: JSON.stringify(formData),
  33. method: 'POST',
  34. })
  35. .then(function(localJson) {
  36. if(localJson.success){
  37. saas.util.BaseUtil.showSuccessToast('保存成功');
  38. viewModel = form.getViewModel();
  39. var url = form._readUrl;
  40. saas.util.BaseUtil.request({url })
  41. .then(function(res) {
  42. if(res.success) {
  43. var d = res.data;
  44. viewModel.setData(d)
  45. }
  46. })
  47. .catch(function(response) {
  48. console.error(response);
  49. });
  50. }
  51. })
  52. .catch(function(res) {
  53. console.error(res);
  54. saas.util.BaseUtil.showErrorToast('保存失败: ' + res.message);
  55. });
  56. }
  57. });