Created
June 9, 2014 22:06
-
-
Save j-mcnally/f67966a6a0be6f3ece18 to your computer and use it in GitHub Desktop.
EmberJS Component
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
xtokeninput = Ember.Component.extend | |
tagName: 'input' | |
classNames: [] | |
jsonRoot: null | |
baseURL: "" | |
tokenValue: 'id' | |
tokens: [] | |
# Setting tokens externally | |
updateValue: (-> | |
this.$().tokenInput('clear') | |
tokens = this.$().val().split(",") | |
for token in tokens | |
this.$().tokenInput('add', {id: token, name: token}) if $.trim(token) != "" | |
).observes('value') | |
updateTokens: (-> | |
this.set('value', this.get('tokens').join(",")) | |
).observes('tokens') | |
changeHandler: -> | |
values = $.map this.$().tokenInput("get"), | |
(o) => | |
o[this.tokenValue] | |
this.set('tokens', values) | |
_initializeTokenInput: (-> | |
self = this | |
this.$().tokenInput( | |
this.get("baseURL") + this.get("dataSourceURL"), | |
crossDomain: false | |
jsonContainer: this.get('jsonRoot') | |
theme: 'dewey' | |
tokenValue: this.get('tokenValue') | |
onAdd: -> | |
self.changeHandler() | |
onDelete: -> | |
self.changeHandler() | |
onResult: (item) -> | |
container_root = self.get('jsonRoot') | |
container = item | |
container = container['tags'] if (container_root != null) | |
inputVal = self.$().parent().find('tester').text() | |
inputObject = {id: inputVal, name: inputVal} | |
if container.length <= 0 | |
item = [] | |
item['tags'] = [inputObject] | |
else | |
unless item['tags'][0]['name'] is inputVal | |
item['tags'].unshift inputObject | |
return item | |
) | |
).on('didInsertElement') | |
`export default xtokeninput` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment