Skip to content

Instantly share code, notes, and snippets.

@zo0m
Created April 12, 2018 17:12
Show Gist options
  • Save zo0m/43da5c2b82b381cd247eb9c1c2f38bbd to your computer and use it in GitHub Desktop.
Save zo0m/43da5c2b82b381cd247eb9c1c2f38bbd to your computer and use it in GitHub Desktop.
// thanks https://stackoverflow.com/questions/17965151/override-get-method-in-alloy-model
exports.definition = {
con-fig: {
adapter: {
type: "properties",
collection_name: "careCenter",
idAttribute : "CareCenterID"
}
},
extendModel: function(Model) {
_.extend(Model.prototype, {
idAttribute : "CareCenterID"
// extended functions and properties go here
});
return Model;
},
extendCollection: function(Collection) {
_.extend(Collection.prototype, {
add : function(attrs, opts){
var isDuplicated = false;
if(attrs && attrs.get){
isDuplicated = this.any(function(model){
return model.get("CareCenterID") === attrs.get("CareCenterID");
});
}
if(isDuplicated){
return false;
} else {
Backbone.Collection.prototype.add.call(this, attrs, opts);
}
},
comparator : function(model){
return -model.get("state");
}
});
return Collection;
}
}
extendModel: function(Model) {
_.extend(Model.prototype, {
idAttribute : "RecipientID",
set : function(attrs, opts){
if(attrs.Age != null){
var age = attrs.Age;
var result = "";
if(age <= Alloy.CFG.INFANT){
result = "infant";
} else if(age <= Alloy.CFG.CHILD){
result = "child";
} else if(age <= Alloy.CFG.TEENAGER){
result = "teenager";
} else {
result = "adult";
}
attrs.Group = result;
}
return Backbone.Model.prototype.set.call(this, attrs, opts);
}
});
return Model;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment