MainConfig.js 2.42 KB
Ext.define('App.controller.MainConfig', {
    extend : 'Ext.app.Controller',
    
    init : function() {
 
    	
    	this.control({
            'mvvm-MainConfigView > button#SaveRecord' : {
                click : this.onSaveButtonClick
            }
        });
    	
    	
    	 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', 'Обновление конфигурации не выполнено!');
           }
    }
});