usersettings.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* global OC */
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. (function() {
  8. 'use strict';
  9. var errorNotification;
  10. /**
  11. * Model for storing and saving user settings
  12. *
  13. * @class UserSettings
  14. */
  15. var UserSettings = OC.Backbone.Model.extend({
  16. url: OC.generateUrl('/settings/users/{id}/settings', {id: OC.currentUser}),
  17. isNew: function() {
  18. return false; // Force PUT on .save()
  19. },
  20. parse: function(data) {
  21. if (_.isUndefined(data)) {
  22. return null;
  23. }
  24. if (errorNotification) {
  25. errorNotification.hide();
  26. }
  27. if (data.status && data.status === 'error') {
  28. errorNotification = OC.Notification.show(data.data.message, { type: 'error' });
  29. }
  30. if (_.isUndefined(data.data)) {
  31. return null;
  32. }
  33. data = data.data;
  34. var ignored = [
  35. 'userId',
  36. 'message'
  37. ];
  38. _.each(ignored, function(ign) {
  39. if (!_.isUndefined(data[ign])) {
  40. delete data[ign];
  41. }
  42. });
  43. return data;
  44. }
  45. });
  46. OC.Settings = OC.Settings || {};
  47. OC.Settings.UserSettings = UserSettings;
  48. })();