Fix sshkey form
This commit is contained in:
parent
4a401dc8cb
commit
767e49d95a
|
@ -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`
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1 +1 @@
|
|||
{{#each erorr in view.errors}}{{error.message}}{{/each}}
|
||||
{{#each error in view.errors}}{{error.message}}{{/each}}
|
||||
|
|
Loading…
Reference in New Issue
Block a user