MainConfig.js 2.34 KB
Ext.define('App.controller.MainConfig', {
    extend : 'Ext.app.Controller',
    
    init : function() {
 
    	
    	this.control({
            'toolbar  button[action=saveMainConfig]' : {
                click : this.onSaveButtonClick
            },
            
            'toolbar  button[action=loadMainConfig]' : {
                click : this.onLoadButtonClick
            }
        });
    	
    	this.onLoadButtonClick();
    	 
    },

    
    onLoadButtonClick:function() { 
    	
    	
            Ext.Ajax.request({
             	  method: "GET",
                   url: 'api/devinfo/',
                   headers: {
                       'Accept': 'application/json',
                       'Content-Type': 'application/json'
                   },
              
                   success: function(response, opts) {
                  	 
                  	var result = Ext.JSON.decode(response.responseText);
                  	 
                  	Ext.getCmp('guid').setValue(result.guid);
                  	Ext.getCmp('title').setValue(result.description);
                  			
                   }, failure: function(response, opts) {
                   }
              });
    },

    onSaveButtonClick : function(btn) {
    	
    	Ext.getCmp('formmainconfig').mask('Загрузка...');
       
        var mainconfigView = btn.up('mvvm-MainConfigView');
      
        var record = mainconfigView.getViewModel().getData();
        
        if (record) {
            
            var data=Ext.util.JSON.encode(record);
           
            Ext.Ajax.request({
          	  method: "POST",
                url: 'api/devinfo/update',
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json'
                },
                params: data,
                success: function(response, opts) {
               	 
             	 var result = Ext.JSON.decode(response.responseText);
          
               //	 Ext.Msg.alert(result.type+" "+"Код-"+result.code,result.message);
               	 
                }, failure: function(response, opts) {
               	  Ext.Msg.alert('Ошибка', 'Сервер недоступен');
                }
           });
    
           }
        
        Ext.getCmp('formmainconfig').unmask();
         
    }
});