Skip to content

Commit

Permalink
Merge pull request bergie#24 from jerryjj/master
Browse files Browse the repository at this point in the history
Fixing race condition on model state
  • Loading branch information
bergie committed Jan 6, 2012
2 parents 42cd2fb + a02c11d commit 52f8304
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/jquery.Midgard.midgardToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
if (options.workflows.length) {
options.workflows.each(function(workflow) {
html = jQuery('body').data().midgardWorkflows.prepareItem(model, workflow, function(err, model) {
widget._clearWorkflows();
if (err) {
//console.log('WORKFLOW ACTION FAILED',err);
return;
Expand Down
40 changes: 29 additions & 11 deletions src/jquery.Midgard.midgardWorkflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,46 @@
},
action_types: {
backbone_save: function(model, workflow, callback) {
copy_of_url = model.url;
original_model = model.clone();
original_model.url = copy_of_url;

action = workflow.get("action")
if (action.url) {
model.url = action.url
model.url = action.url
}

model.save(null, {
success: function() {
model.url = original_model.url;
original_model.save(null, {
success: function(m) {
model.url = copy_of_url;
model.change();
callback(null, model);
},
error: function(model, err) {
error: function(m, err) {
model.url = copy_of_url;
model.change();
callback(err, model);
}
});
},
backbone_destroy: function(model, workflow, callback) {
copy_of_url = model.url;
original_model = model.clone();
original_model.url = copy_of_url;

action = workflow.get("action")
if (action.url) {
model.url = action.url
}

model.destroy({
success: function() {
model.url = original_model.url;
callback(null, model);
success: function(m) {
model.url = copy_of_url;
model.change();
callback(null, m);
},
error: function(model, err) {
error: function(m, err) {
model.url = copy_of_url;
model.change();
callback(err, model);
}
});
Expand Down Expand Up @@ -161,10 +172,17 @@
},

prepareItem: function(model, workflow, final_cb) {
var widget = this;

renderer = this.getRenderer(workflow.get("type"));
action_type_cb = this.getActionType(workflow.get("action").type);

return renderer(model, workflow, action_type_cb, final_cb);
return renderer(model, workflow, action_type_cb, function(err, m) {
delete widget.workflows[model.cid];
widget._last_instance = null;

final_cb(err, m);
});
},

_generateCollectionFor: function(model) {
Expand Down

0 comments on commit 52f8304

Please sign in to comment.