Last active
September 9, 2015 13:38
-
-
Save ultimatemonty/cb9e9c1cb9793e594628 to your computer and use it in GitHub Desktop.
SPIKE: Object Factory
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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName:'SPIKE: Object Factory' | |
}); |
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
var Action = { | |
nodeType: 'action', | |
name: 'Action', | |
shape: 'rectangle' | |
}; | |
export default Action; |
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
import Ember from 'ember'; | |
const AssignProspectList = { | |
type: 'assign_prospect_list', | |
name: 'Assign to List', | |
validate: function() { | |
return Object.keys({}).length > 0; | |
}, | |
description: Ember.computed(function() { | |
let name = this.get('name'), | |
nodeType = this.get('nodeType'); | |
return `${nodeType} ${name}`; | |
}) | |
} | |
export default AssignProspectList; |
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
// app/objects/form-definition.js | |
import Ember from 'ember'; | |
const FormDefinition = Ember.Object.extend({ | |
type: null, | |
name: null, | |
icon: null, | |
label: null, | |
form: null, | |
description: Ember.computed(function() { | |
throw new Error('You must implement the `description` method for this form!'); | |
}), | |
validate: function() { | |
throw new Error('You must implement the `validate` method for this form!'); | |
}, | |
_validateRequiredProps: Ember.on('init', function() { | |
if (Ember.isEmpty(this.get('type'))) { | |
throw new Error('`type` is a required field for this form and must be filled in') | |
} | |
}) | |
}); | |
export default FormDefinition; |
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
const RemoveProspectList = { | |
type: 'remove_prospect_list', | |
name: 'Remove from List' | |
} | |
export default RemoveProspectList; |
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
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
definition: Ember.inject.service(), | |
model: function() { | |
let defService = this.get('definition'); | |
return defService.findDefinition('assign_prospect_list'); | |
} | |
}); |
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
import Ember from 'ember'; | |
import FormDefinition from '../objects/form-definition'; | |
import Action from '../objects/action'; | |
import AssignProspectList from '../objects/assign-prospect-list'; | |
import RemoveProspectList from '../objects/remove-prospect-list'; | |
const DefinitionsService = Ember.Service.extend({ | |
actions: [ | |
AssignProspectList, | |
RemoveProspectList | |
], | |
findActionBy: function(key, value) { | |
return this.actions.findBy(key, value); | |
}, | |
findDefinition: function(type) { | |
let definitionHash = Ember.$().extend({}, Action, this.findActionBy('type', type)); | |
let definitionObj = FormDefinition.extend(Ember.Copyable, definitionHash); | |
return definitionObj.create(); | |
} | |
}); | |
export default DefinitionsService; |
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
{ | |
"version": "0.4.10", | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.11/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember-template-compiler.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment