PDA

View Full Version : Can UpdateManager be used as an EventQueue/RequestQueue ?



cchiriac
13 Mar 2007, 3:04 AM
I'm trying to build an ordered list (based on View.js) with internal drag&drop support for reordering.
When an item is moved inside the list, i remove it from the current position and insert it in the new location. I perform the oprations directly on the view's Store.

Basically for an internal move i have one "remove" and one "insert" in this order.

To synchronize the changes with the database I plug two listeners to the store and use an UpdateManager of some status element to perfom the requests (by changing the url). The problem is that sometimes the order of the requests is not respected so i find myself trying to insert before having removed. Of course it throws an exception as i'm trying to duplicate the primary key.

So the idea would be to set the UpdateManager in a "syncronous" mode, using some sort of event queue which would force my requests to come in the correct order. Is this possible/already implemented/not way too stupid ? Has anybody had some a similar problem ?

cchiriac
13 Mar 2007, 3:55 AM
Ok so here is my 2cents workaround that i could find.



persistAdded: function(list, records, index){
var updater = list.getPersistUpdateManager();
updater.indicatorText = '<div class="loading-indicator">Enregistrement...</div>';
updater.setDefaultUrl(DefaultConfig.getBaseUri() + 'script.php&cmd=ADD&index=' + index);

if (updater.isUpdating()){
var updaterRefresh = function(){
updater.un("update", updaterRefresh); // first be sure the listener called more than once
updater.refresh();
}
updater.on('update', updaterRefresh);
} else {
updater.refresh();
}
},

persistRemoved: function(list, record, index){
var updater = list.getPersistUpdateManager();
updater.indicatorText = '<div class="loading-indicator">Enregistrement...</div>';
updater.setDefaultUrl(DefaultConfig.getBaseUri() + 'script.php&cmd=REMOVE&index=' + index);
updater.refresh();
},


I think the code kinda self-explains ( and shows the solution isn't at all elegant ) but for me it solves the problem.
I'm just forcing the "insert" to come up after an eventual active request is processed. For me that request, if it exists, it's surely an "remove" from the d&d order changing.

As we are not multi-threaded it shouldn't fall in some twisted cases.

For the second method i could have done the same thing, but for now i don't have "insert", "remove" couples of requests.