Search code examples
extjs4renameextjs4.1treepanel

Rename and Insert erro TreeStore ExtJS 4.1.1


Good Evening guys,

When I update the method it does not save all model items like "tipoNo" and "pai". Someone know what i can do ?

Request Payload

This is the information sent in the request.

{"parentId":1,"nome":"qwfqwfqw"}

Model:

Fields in the my model.

fields : [ {
    name : 'id',
    type : 'long'
},{
    name : 'pai',
    type : 'long'
}, {
    name : 'nome',
    type : 'string'
}, {
    name : 'tipoNo',
    type : 'string'
}, {
    name : 'leaf',
    type : 'boolean',
    convert : function(value, record) {
        var no = record.get('tipoNo');
        return (no == "CLIENTE" ? true : false);
    }
} ],

Proxy

Proxy to requisite information on the server.

proxy : {
    type : 'rest',
    url : Webapp.link('node'),
    reader : {
        type : 'json',
        root : 'nodes',
        idProperty : 'id'
    },
    writer : {
        type : 'json',
        writeAllFields : false
    }
}

Controller Method

/**
 * Rename
 * 
 * @param {Ext.grid.plugin.CellEditing} editor
 * @param {Object} e                            
 */
updateList : function (editor, e) {
    var node = e.record;
    node.save({
        success: function(list, operation) {
            console.log("updated");
        },
        failure: function(list, operation) {
            var error = operation.getError(),
                msg = Ext.isObject(error) ? error.status + ' ' + error.statusText : error;

            Ext.MessageBox.show({
                title: 'Notificação',
                msg: msg,
                icon: Ext.Msg.ERROR,
                buttons: Ext.Msg.OK
            });
        }
    });
},

Solution

  • Solution in this case:

    /**
     * Executa a edição
     * 
     * @param {Ext.grid.plugin.CellEditing} editor
     * @param {Object} e                            
     */
    updateList : function (editor, e) {
        var node = e.record;
        var me = this;
        var nodeTree = me.getNodeTree();
    
        var method = (node.data.id !== undefined ? 'PUT' : 'POST');
        var post = {
                id: (node.data.id !== undefined ? null : node.data.id),
                nome: node.data.nome,
                pai: (node.data.parentId == -1 ? null : node.data.pai),
                tipoNo: node.data.tipoNo
        };
        Ext.Ajax.request({
            url: Webapp.link("node"),
            headers: { 'Content-Type': 'application/json' }, 
            jsonData: post,
            method: method,
            success: function(response){
                var text = response.responseText;
                console.log(text);
                nodeTree.refreshView();
            }
        });
    
    },