Skip to content

Instantly share code, notes, and snippets.

@jackey
Created March 23, 2012 09:46
Show Gist options
  • Save jackey/2169088 to your computer and use it in GitHub Desktop.
Save jackey/2169088 to your computer and use it in GitHub Desktop.
Bones Attachment Model And Document Model
var _ = Bones._;
var sync = Document.prototype.sync;
Document.prototype.sync = function (method, model, options) {
var self = this;
var properties = this.getSchema().getProperty('properties');
var names = properties.getPropertyNames();
_.each(names, function(name, index) {
var property = properties.getProperty(name);
// Maybe I should use function instead of directly access value;
if (property.getProperty('type')._value == 'file') {
// We trigger the event with property name type;
self.trigger('type:file', self, method, model, options);
}
});
}
var UserProfile = Document.extend({
schema: {
'properties': {
'gravatar':{'type': 'file'},
'name': {'type': 'string'},
}
}
});
// Test code.
var d = new Document();
d.set({
'gravatar': {filename: ''},
'name': 'jackey'
});
d.bind('type:file', function (method, model, options) {
// Save file here.
});
d.save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment