Created
March 23, 2012 09:46
-
-
Save jackey/2169088 to your computer and use it in GitHub Desktop.
Bones Attachment Model And Document Model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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