MainConfig.js 2.77 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) {
       
        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);
               	 
               	 /*
               	 	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', 'Обновление конфигурации не выполнено!');
           }
    }
});