1. #1
    Sencha User TopKatz's Avatar
    Join Date
    Mar 2007
    Posts
    337
    Vote Rating
    2
    TopKatz is on a distinguished road

      0  

    Default removeAll(true) calling destroy api

    removeAll(true) calling destroy api


    I have a a direct store setup:

    Code:
    Ihc.app.DirectProxy = new Ext.data.HttpProxy({
        api:{
            read:Ihc.app.DirectRequestURL+'/readOrderItems',
            create:Ihc.app.DirectRequestURL+'/newOrderItem',
            update:Ihc.app.DirectRequestURL+'/updateOrderItem',
            destroy:Ihc.app.DirectRequestURL+'/deleteOrderItem'
        }
    });
    
    Ihc.app.DirectWriter = new Ext.data.JsonWriter({
        encode:true,
        writeAllFields:true,
        listful:true
    });
    
    Ihc.app.reader = new Ext.data.JsonReader({
        totalProperty: 'total',
        successProperty: 'success',
        idProperty: 'orderItemID',
        root: 'data',
        messageProperty: 'message'
    }, [
        {name: 'orderItemID'},
        {name: 'item'},
        {name: 'itemID'},
        {name: 'size'},
        {name: 'quantity'},
        {name: 'categoryID'},
        {name: 'comment'},
        {name:'orderID'},
        {name:'unlistedItem'}
    ]);
    
    Ihc.app.dsOrder = new Ext.data.Store({
        proxy:Ihc.app.DirectProxy,
        writer:Ihc.app.DirectWriter,
        autoSave:true,
        reader:Ihc.app.reader,
        baseParams:{orderID:null},
        listeners:{
            exception : function(){
                //Ihc.app.dsOrder.baseParams.orderID = null;
                Ihc.app.dsOrder.removeAll(true);
            }
        }
    });
    When I call Ihc.app.dsOrder.removeAll(true) my destroy api call is getting fired. Other then taking of autoSave true is there another way around this? I thought the true flag was supposed to suppress the destroy call?

  2. #2
    Sencha User TopKatz's Avatar
    Join Date
    Mar 2007
    Posts
    337
    Vote Rating
    2
    TopKatz is on a distinguished road

      0  

    Default


    As a work around I have set autoSave:false, and I am calling the save() method when I want to update the backend.

  3. #3
    Sencha User TopKatz's Avatar
    Join Date
    Mar 2007
    Posts
    337
    Vote Rating
    2
    TopKatz is on a distinguished road

      0  

    Default


    After continuing to play with this particular setup I started finding some other odd things.

    1. When I would start a new order, and clear out the items in the store using removeAll, I would some times get an exception when trying to add a new item to the empty store. I would see a destroy call go out(even though I did not call it!!!) with the old record ids that were removed( I could see they were not in data.items) go out in the call.

    2. I would also at times see the wrong item values get inserted. I could see the new items info go out in the create call, and see them come back in the response, but then the value would revert to that which was in the store before my removeAll call.

    All of these issues really had me thinking I was not going to be able to use the direct writer for this control. Then I got a suggestion from Lloyd in the ext IRC chat to destroy the store, and start over, instead of removing the old records.

    This suggestion fixed my problem, and allowed me to utilize the writer, and direct store with my grid. I'm not sure if this is the intent of the store, that it should be destroyed, but it is what I needed to do in my use case.

    I hope this helps some one.

  4. #4
    Ext JS Premium Member westy's Avatar
    Join Date
    Feb 2009
    Location
    Bath, UK
    Posts
    845
    Vote Rating
    39
    westy is a jewel in the rough westy is a jewel in the rough westy is a jewel in the rough

      0  

    Default


    I can't stop it at all with 4.1.0-rc1, well, at least can't find a reference to autoSave anywhere in the Ext codebase.

    Going to override the destroy method I think, since I only have to support reading.
    Product Architect
    Altus Ltd.

  5. #5
    Ext JS Premium Member westy's Avatar
    Join Date
    Feb 2009
    Location
    Bath, UK
    Posts
    845
    Vote Rating
    39
    westy is a jewel in the rough westy is a jewel in the rough westy is a jewel in the rough

      0  

    Default


    Sorted it, with some code that feels very filthy.

    In my TreeNode model class:
    Code:
        proxy: {
            type: 'ajax',
            /**
             * This gets called when we call removeChild with destroy set to true, and by default it tries to
             * sync with the server, which is not what we want.
             * This version simply removes the record from the store and calls the callback.
             * @param  {[type]}   operation The operation being performed.
             * @param  {Function} callback  The callbakc function.
             * @param  {[type]}   scope     The scope in which to call the callback
             */
            destroy: function(operation, callback, scope) {
                if (operation) {
                    Ext.Array.each(operation.records, function(record) {
                        if (record) {
                            Ext.Array.each(record.stores, function(store) {
                                store.remove(record);
                            });
                        }
                    });
                }
    
    
                Ext.callback(callback, scope, [operation]);
    
    
            }
        }
    Can't help but think buildRequest should not throw an exception if you have no url for destroy though... feel like I'm being forced to dodge something that I should be able to tell the framework I do not support.

    Cheers,
    Westy
    Product Architect
    Altus Ltd.

  6. #6
    Ext JS Premium Member westy's Avatar
    Join Date
    Feb 2009
    Location
    Bath, UK
    Posts
    845
    Vote Rating
    39
    westy is a jewel in the rough westy is a jewel in the rough westy is a jewel in the rough

      0  

    Default


    This spam is getting more cryptic
    Product Architect
    Altus Ltd.

Thread Participants: 1