From 6d15b5e6315e9371560149c4aba4d86c0475ac4e Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Wed, 11 Jun 2014 13:16:17 -0700 Subject: [PATCH] Working on User patching. --- app/models/CocoModel.coffee | 6 +++++- app/views/contribute/contribute_class_view.coffee | 2 +- app/views/kinds/RootView.coffee | 2 +- app/views/modal/diplomat_suggestion_modal.coffee | 2 +- app/views/modal/wizard_settings_modal.coffee | 2 +- test/app/models/CocoModel.spec.coffee | 9 ++++++++- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/models/CocoModel.coffee b/app/models/CocoModel.coffee index 1472d6b04..feb574353 100644 --- a/app/models/CocoModel.coffee +++ b/app/models/CocoModel.coffee @@ -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: -> diff --git a/app/views/contribute/contribute_class_view.coffee b/app/views/contribute/contribute_class_view.coffee index d9110c3fd..ae6fd59af 100644 --- a/app/views/contribute/contribute_class_view.coffee +++ b/app/views/contribute/contribute_class_view.coffee @@ -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) diff --git a/app/views/kinds/RootView.coffee b/app/views/kinds/RootView.coffee index fd036784b..5cd547c8a 100644 --- a/app/views/kinds/RootView.coffee +++ b/app/views/kinds/RootView.coffee @@ -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) diff --git a/app/views/modal/diplomat_suggestion_modal.coffee b/app/views/modal/diplomat_suggestion_modal.coffee index 511fe369a..bd735f995 100644 --- a/app/views/modal/diplomat_suggestion_modal.coffee +++ b/app/views/modal/diplomat_suggestion_modal.coffee @@ -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 diff --git a/app/views/modal/wizard_settings_modal.coffee b/app/views/modal/wizard_settings_modal.coffee index 5715a4c1f..c099a4fba 100644 --- a/app/views/modal/wizard_settings_modal.coffee +++ b/app/views/modal/wizard_settings_modal.coffee @@ -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') diff --git a/test/app/models/CocoModel.spec.coffee b/test/app/models/CocoModel.spec.coffee index 275ffa65e..f7703b851 100644 --- a/test/app/models/CocoModel.spec.coffee +++ b/test/app/models/CocoModel.spec.coffee @@ -74,4 +74,11 @@ describe 'CocoModel', -> request = jasmine.Ajax.requests.mostRecent() params = JSON.parse request.params expect(params.object).toBeUndefined() - \ No newline at end of file + + 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()