travis-web/assets/scripts/app/controllers/env_var.coffee
Piotr Sarnacki 6aa9771170 Reset value in env_var controller also based on public attr
When we switch from private to public env var, we don't want to set
"***********" as a new value of a var.
2014-08-19 19:42:08 +02:00

53 lines
1.2 KiB
CoffeeScript

require 'travis/validations'
Travis.EnvVarController = Ember.ObjectController.extend Travis.Validations,
isEditing: false
isDeleting: false
validates:
name: ['presence']
actionType: 'Save'
showValueField: Ember.computed.alias('public')
value: ( (key, value) ->
if arguments.length == 2
@get('model').set('value', value)
value
else if @get('public')
@get('model.value')
else
'••••••••••••••••'
).property('model.value', 'public')
actions:
delete: ->
return if @get('isDeleting')
@set('isDeleting', true)
deletingDone = => @set('isDeleting', false)
@get('model').deleteRecord().then deletingDone, deletingDone
edit: ->
@set('isEditing', true)
cancel: ->
@set('isEditing', false)
@get('model').revert()
save: ->
return if @get('isSaving')
@set('isSaving', true)
if @isValid()
env_var = @get('model')
# TODO: handle errors
env_var.save().then =>
@set('isEditing', false)
@set('isSaving', false)
, =>
@set('isSaving', false)
else
@set('isSaving', false)