Fix sshkey form

This commit is contained in:
Piotr Sarnacki 2015-02-10 11:53:14 +01:00
parent 4a401dc8cb
commit 767e49d95a
4 changed files with 33 additions and 16 deletions

View File

@ -4,11 +4,21 @@
Adapter = ApplicationAdapter.extend
namespace: 'settings'
find: (store, type, id, record) ->
@ajax(this.urlPrefix() + '/ssh_key/' + id, 'GET')
deleteRecord: (store, type, record) ->
id = Ember.get(record, 'id')
@ajax(this.urlPrefix() + '/ssh_key/' + id, "DELETE");
createRecord: (store, type, record) ->
data = {};
serializer = store.serializerFor(type.typeKey);
serializer.serializeIntoHash(data, type, record, { includeId: true });
this.ajax(this.buildURL(type.typeKey, null, record), "POST", { data: data })
id = Ember.get(record, 'id')
this.ajax(this.urlPrefix() + '/ssh_key/' + id, "PATCH", { data: data })
`export default Adapter`

View File

@ -18,7 +18,12 @@ Controller = Ember.ObjectController.extend Validations,
actions:
add: ->
model = Travis.SshKey.create(id: @get('repo.id'))
id = @get('repo.id')
model = @store.recordForId('sshKey', id)
if model.get('currentState.stateName') == 'root.empty'
@store.dematerializeRecord(model)
model = @store.createRecord('sshKey', id: id)
@set('model', model)
@set('isEditing', true)
@ -30,10 +35,10 @@ Controller = Ember.ObjectController.extend Validations,
@get('model').save().then =>
@set('isEditing', false)
@set('isSaving', false)
, (xhr) =>
, (error) =>
@set('isSaving', false)
if xhr.status == 422
@addErrorsFromResponse(JSON.parse(xhr.response)['errors'])
if error.errors
@addErrorsFromResponse(error.errors)
else
@set('isSaving', false)
@ -43,18 +48,19 @@ Controller = Ember.ObjectController.extend Validations,
deletingDone = => @set('isDeleting', false)
# because of the bug in ember model reference is not cleared after
# deleting the record, so I'm doing it manually here
delete @get('model').constructor._referenceCache[parseInt(@get('model.id'))]
@get('model').deleteRecord().then(deletingDone, deletingDone).then =>
@get('model').deleteRecord()
@get('model').save().then(deletingDone, deletingDone).then =>
@set('model', null)
cancel: ->
if model = @get('model')
if model.get('isNew')
@set('model', null)
@set('isEditing', false)
model = @get('model')
console.log model.get('currentState.stateName')
if model.get('currentState.stateName') == 'root.empty' ||
model.get('currentState.stateName') == 'root.loaded.created.uncommitted'
@store.dematerializeRecord(model)
@set('model', null)
@set('isEditing', false)
edit: ->
@set('isEditing', true)

View File

@ -7,11 +7,12 @@ ErrorsView = Ember.View.extend
classNameBindings: ['codes', 'show']
codes: (->
@get('errors').mapBy('code')
).property('@errors')
).property('@errors', 'errors.length')
show: Ember.computed.notEmpty('errors.[]')
fn = (name, options) ->
errors = @get('errors').for(name)
window[name + 'Errors'] = errors
view = ErrorsView.create(
controller: this
errors: errors

View File

@ -1 +1 @@
{{#each erorr in view.errors}}{{error.message}}{{/each}}
{{#each error in view.errors}}{{error.message}}{{/each}}