| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- Ext.define('saas.view.sys.baseconfig.FormPanelController', {
- extend: 'Ext.app.ViewController',
- alias: 'controller.sys-baseconfig-formpanel',
- BaseUtil: Ext.create('saas.util.BaseUtil'),
- FormUtil: Ext.create('saas.util.FormUtil'),
- init: function (form) {
- var me = this;
- this.control({
- 'button[name=save]':{
- click:function(){
- me.onSave();
- }
- }
- });
- },
- onSave: function() {
- var me = this,
- form = this.getView();
- var valid = form.isValid();
- if(!valid) {
- saas.util.BaseUtil.showErrorToast('表单校验有误,请检查');
- return false;
- }
- if(form.getForm().wasDirty==false){
- saas.util.BaseUtil.showErrorToast('未修改数据,请修改后保存');
- return false;
- }
- viewModel = me.getViewModel();
- var formData = [];
- var items = me.view.getForm().getFields().items;
- Ext.each(items, function(item, index){
- formData.push({
- code:item.name,
- data:item.value
- })
- });
- saas.util.BaseUtil.request({
- url: form._saveUrl,
- params: JSON.stringify(formData),
- method: 'POST',
- })
- .then(function(localJson) {
- if(localJson.success){
- saas.util.BaseUtil.showSuccessToast('保存成功');
- viewModel = form.getViewModel();
- var url = form._readUrl;
- saas.util.BaseUtil.request({url })
- .then(function(res) {
- if(res.success) {
- var list = res.data.list;
- if(list.length>0){
- var d = {};
- Ext.each(list, function(item, index){
- d[item.code] = item.data;
- });
- viewModel.setData(d);
- }
- }
- })
- .catch(function(response) {
- console.error(response);
- });
- }
- })
- .catch(function(res) {
- console.error(res);
- saas.util.BaseUtil.showErrorToast('保存失败: ' + res.message);
- });
- }
- });
|