MainConfig.js 1.86 KB
Ext.define('App.controller.MainConfig', {
    extend : 'Ext.app.Controller',
    
    init : function() {
 
    	
    	this.control({
            'mvvm-MainConfigView > button#SaveRecord' : {
                click : this.onSaveButtonClick
            }
        });
    },

    onSaveButtonClick : function(btn) {
        //get reference to the form
        var mainconfigView = btn.up('mvvm-MainConfigView');
      
		//get the bound record
        var record = mainconfigView.getViewModel().getData().rec;

        if (record) {
            
            var data=Ext.util.JSON.encode(record);
           
           
            
            Ext.Ajax.request({
          	  method: "POST",
                url: 'api/mainconfig/update',
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json'
                },
                params: data,
                success: function(response, opts) {
               	 
               	 var result = Ext.JSON.decode(response.responseText);
               	 
               	 	if(result) {
               	 			Ext.Msg.alert('Success', 'Обновление конфигурации выполнено!');
               	   		//record.commit(); 
               	 	}
               	 	else
               	 		{
               	 		 Ext.Msg.alert('Failure', 'Обновление конфигурации не выполнено!');
               	 		}
               	 
               	 
                }, failure: function(response, opts) {
               	  Ext.Msg.alert('Failure', 'Обновление конфигурации не выполнено!');
                }
           });
    
           }
           else {
           	 Ext.Msg.alert('Failure', 'Обновление конфигурации не выполнено!');
           }
    }
});