Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #24 from jerryjj/master

Fixing race condition on model state
  • Loading branch information...
commit 52f830464b0ce7d497da71bcee7c154375d6178e 2 parents 42cd2fb + a02c11d
Henri Bergius bergie authored
1  src/jquery.Midgard.midgardToolbar.js
View
@@ -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;
40 src/jquery.Midgard.midgardWorkflows.js
View
@@ -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);
}
});
@@ -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) {
Please sign in to comment.
Something went wrong with that request. Please try again.