Last active
August 29, 2015 14:07
-
-
Save arthuryeti/b63c3caf7d7b760ef642 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
moduleKeywords = ['extended', 'included'] | |
class NvModel | |
@_resource = {} | |
@_all = [] | |
@all: -> | |
models = _.map @_all, (model) => | |
model = new @(model) | |
$q.when models | |
@getEntityDefinition: () -> | |
@_resource.getEntityDefinition() | |
###* | |
* Extend the Class object | |
* @param {Object} obj Give an object of methods | |
* @return {Object} Return the current model | |
### | |
@extend: (obj) -> | |
for key, value of obj when key not in moduleKeywords | |
@[key] = value | |
obj.extended?.apply(@) | |
this | |
###* | |
* Extend the Instance object | |
* @param {Object} obj Give an object of methods | |
* @return {Object} Return the current model | |
### | |
@include: (obj) -> | |
for key, value of obj when key not in moduleKeywords | |
# Assign properties to the prototype | |
@::[key] = value | |
obj.included?.apply(@) | |
this | |
constructor: (entity) -> | |
angular.extend @, entity | |
@_resource.getEntityDefinition() | |
_.defaults @, @_resource.properties | |
sendToServer: -> | |
@_resource.entity = _.omit @, '_resource' | |
@_resource.create() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment