Permalink
Browse files

issue #19735: Fixes to workspace and lists to properly handle backbon…

…e relational api changes.
  • Loading branch information...
John Rogelstad
John Rogelstad committed Mar 10, 2013
1 parent 0c13e1b commit 1aae1cbdd3397d2418bf4acef5b586fa01e71313
@@ -151,7 +151,7 @@ trailing:true white:true*/
if (imodel instanceof XM.Info) {
Klass = XT.getObjectByName(model.editableModel);
- model = new Klass({id: imodel.id});
+ model = Klass.findOrCreate({id: imodel.id});
}
fetchOptions.success = function (result) {
@@ -114,10 +114,10 @@ trailing:true white:true, bitwise:false*/
// to an info model, which is not the type of model we want
// to use in the list
var Klass = XT.getObjectByName(selectedModel.editableModel),
- model = new Klass({id: selectedModel.id}),
+ model = Klass.findOrCreate({id: selectedModel.id}),
InfoKlass = model.getRelation(key).relatedModel,
- infoModel = new InfoKlass({id: parent.get(attr)}),
- listModel = new ListModel({id : selectedModel.id}),
+ infoModel = InfoKlass.findOrCreate({id: parent.get(attr)}),
+ listModel = ListModel.findOrCreate({id : selectedModel.id}),
setAndSave = function () {
var K = XM.Model,
options = {};
@@ -131,9 +131,10 @@ trailing:true white:true, bitwise:false*/
// Callback to update our list with changes when save complete
options.success = function () {
list.getValue().add(listModel);
+ model.releaseLock();
};
- // Set and save our contact with the new account relation
+ // Set and save our record with the new relation
model.set(key, infoModel);
model.save(null, options);
}
@@ -178,7 +179,7 @@ trailing:true white:true, bitwise:false*/
index = list.getFirstSelected(),
infoModel = list.getModel(index),
Klass = XT.getObjectByName(infoModel.editableModel),
- model = new Klass({id: infoModel.id}),
+ model = Klass.findOrCreate({id: infoModel.id}),
setAndSave = function () {
var K = XM.Model,
options = {};
@@ -190,6 +191,7 @@ trailing:true white:true, bitwise:false*/
list.getValue().remove(infoModel);
list.setCount(list.getValue().length);
list.refresh();
+ model.releaseLock();
};
// Set and save our contact without account relation
@@ -216,7 +218,7 @@ trailing:true white:true, bitwise:false*/
callback = function (model) {
if (!model) { return; }
var Model = list.getValue().model,
- value = new Model({id: model.id}),
+ value = Model.findOrCreate({id: model.id}),
options = {};
options.success = function () {
list.getValue().add(value);
@@ -396,7 +396,7 @@ trailing:true white:true*/
}
that._busy = false;
};
- model = new Klass({id: id});
+ model = Klass.findOrCreate({id: id});
model.fetch(options);
} else {
that.showError("_noDocumentFound".loc());
@@ -495,7 +495,7 @@ trailing:true white:true*/
callback = function (model) {
if (!model) { return; }
var Model = list.getValue().model,
- value = new Model({id: model.id}),
+ value = Model.findOrCreate({id: model.id}),
options = {silent: true};
options.success = function () {
list.getValue().add(value);
@@ -273,7 +273,12 @@ trailing:true white:true*/
// Clean up
if (this.value) {
- this.value.off();
+ this.value.off("change", this.attributesChanged, this);
+ this.value.off("change:lock", this.lockChanged, this);
+ this.value.off("readOnlyChange", this.attributesChanged, this);
+ this.value.off("statusChange", this.statusChanged, this);
+ this.value.off("error", this.error, this);
+ this.value.off("notify", this.notify, this);
if (this.value.isNew() && !this.modelAmnesty) {
this.value.destroy();
}
@@ -361,7 +366,6 @@ trailing:true white:true*/
that.fetch(that.value.id);
},
error: function () {
- console.log("Error releasing lock.");
// fetch anyway. Why not!?
that.fetch(that.value.id);
}

0 comments on commit 1aae1cb

Please sign in to comment.