Working on User patching.

This commit is contained in:
Scott Erickson 2014-06-11 13:16:17 -07:00
parent 7fd87f2605
commit 6d15b5e631
6 changed files with 17 additions and 6 deletions

View file

@ -104,10 +104,14 @@ class CocoModel extends Backbone.Model
options.patch = true
attrs = {_id: @id}
anythingChanged = false
for key in _.keys @attributes
unless _.isEqual @attributes[key], @_revertAttributes[key]
attrs[key] = @attributes[key]
anythingChanged = true
return unless anythingChanged
console.debug 'Patching', @, attrs
@save(attrs, options)
fetch: ->

View file

@ -36,7 +36,7 @@ module.exports = class ContributeClassView extends View
subscription = el.attr('name')
me.setEmailSubscription subscription+'News', checked
me.save()
me.patch()
@openModalView new SignupModalView() if me.get 'anonymous'
el.parent().find('.saved-notification').finish().show('fast').delay(3000).fadeOut(2000)

View file

@ -150,7 +150,7 @@ module.exports = class RootView extends CocoView
saveLanguage: (newLang) ->
me.set('preferredLanguage', newLang)
res = me.save()
res = me.patch()
return unless res
res.error ->
errors = JSON.parse(res.responseText)

View file

@ -12,7 +12,7 @@ module.exports = class DiplomatSuggestionView extends View
subscribeAsDiplomat: ->
me.setEmailSubscription 'diplomatNews', true
me.save()
me.patch()
$("#email_translator").prop("checked", 1)
@hide()
return

View file

@ -40,7 +40,7 @@ module.exports = class WizardSettingsModal extends View
forms.applyErrorsToForm(@$el, res)
return
res = me.save()
res = me.patch()
return unless res
save = $('#save-button', @$el).text($.i18n.t('common.saving', defaultValue: 'Saving...'))
.addClass('btn-info').show().removeClass('btn-danger')

View file

@ -74,4 +74,11 @@ describe 'CocoModel', ->
request = jasmine.Ajax.requests.mostRecent()
params = JSON.parse request.params
expect(params.object).toBeUndefined()
it 'does nothing when there\'s nothing to patch', ->
b = new BlandClass({_id: 'test', number:1})
b.loaded = true
b.set('number', 1)
b.patch()
request = jasmine.Ajax.requests.mostRecent()
expect(request).toBeUndefined()