diff options
author | Christoph Wurst <christoph@owncloud.com> | 2016-04-20 17:03:50 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-11-21 11:29:24 +0100 |
commit | 20739c93a680d7085d0e71c0e4f9c0bb24018fb9 (patch) | |
tree | ca8659d0fe9de7388a301fe14cee8f2cf2e88a96 /settings/js | |
parent | c42d977185648fcc34c8e0135973ebc1c4776512 (diff) | |
download | nextcloud-server-20739c93a680d7085d0e71c0e4f9c0bb24018fb9.tar.gz nextcloud-server-20739c93a680d7085d0e71c0e4f9c0bb24018fb9.zip |
Persist settings on the server
Persist personal settings federated sharing scopes
Show new settings fields in read-only mode too
Insert values on page load
Return updated values; show inline success feedback
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'settings/js')
-rw-r--r-- | settings/js/federationsettingsview.js | 58 | ||||
-rw-r--r-- | settings/js/usersettings.js | 47 |
2 files changed, 93 insertions, 12 deletions
diff --git a/settings/js/federationsettingsview.js b/settings/js/federationsettingsview.js index cf5158fa785..6a10d9f7f7e 100644 --- a/settings/js/federationsettingsview.js +++ b/settings/js/federationsettingsview.js @@ -1,4 +1,4 @@ -/* global OC */ +/* global OC, result */ /** * Copyright (c) 2016, Christoph Wurst <christoph@owncloud.com> @@ -22,7 +22,7 @@ if (options.config) { this._config = options.config; } else { - this._config = new OC.Backbone.Model() + this._config = new OC.Settings.UserSettings(); } this._inputFields = [ @@ -33,6 +33,21 @@ 'address' ]; + var self = this; + _.each(this._inputFields, function(field) { + // Initialize config model + self._config.set(field, $('#' + field).val()); + self._config.set(field + 'Scope', $('#' + field + 'scope').val()); + + // Set inputs whenever model values change + self.listenTo(self._config, 'change:' + field, function () { + self.$('#' + field).val(self._config.get(field)); + }); + self.listenTo(self._config, 'change:' + field + 'Scope', function () { + self._onScopeChanged(field, self._config.get(field + 'Scope')); + }); + }); + this._registerEvents(); }, @@ -53,6 +68,8 @@ // TODO: fix position without magic numbers var pos = ($heading.width() - $heading.find('label').width()) - 68; scopeMenu.$el.css('right', pos); + + self._onScopeChanged(field, self._config.get(field + 'Scope')); }); }, @@ -64,21 +81,30 @@ }, _onInputChanged: function(e) { - OC.msg.startSaving('#personal-settings-container .msg'); + var self = this; + var $target = $(e.target); var value = $target.val(); var field = $target.attr('id'); - console.log(field + ' changed to ' + value); this._config.set(field, value); - console.log(this._config.toJSON()); - // TODO: this._config.save(); - // TODO: OC.msg.finishedSaving('#personal-settings-container .msg', result); - // TODO: call _updateDisplayName after successful update + var savingData = this._config.save({ + error: function(jqXHR) { + OC.msg.finishedSaving('#personal-settings-container .msg', jqXHR); + } + }); + + $.when(savingData).done(function() { + //OC.msg.finishedSaving('#personal-settings-container .msg', result) + self._showInputChangeSuccess(field); + if (field === 'displayname') { + self._updateDisplayName(value); + } + }); }, _updateDisplayName: function(displayName) { // update displayName on the top right expand button - $('#expandDisplayName').text($('#displayName').val()); + $('#expandDisplayName').text(displayName); // update avatar if avatar is available if(!$('#removeavatar').hasClass('hidden')) { updateAvatar(); @@ -86,12 +112,20 @@ }, _onScopeChanged: function(field, scope) { - // TODO: save changes to the server - console.log(field + ' changed to ' + scope); - + this._config.set(field + 'Scope', scope); + // TODO: user loading/success feedback + this._config.save(); this._setFieldScopeIcon(field, scope); }, + _showInputChangeSuccess: function(field) { + var $icon = this.$('#' + field + 'form > span'); + $icon.fadeIn(200); + setTimeout(function() { + $icon.fadeOut(300); + }, 2000); + }, + _setFieldScopeIcon: function(field, scope) { var $icon = this.$('#' + field + 'form > h2 > span'); $icon.removeClass('icon-password'); diff --git a/settings/js/usersettings.js b/settings/js/usersettings.js new file mode 100644 index 00000000000..d8d089f83de --- /dev/null +++ b/settings/js/usersettings.js @@ -0,0 +1,47 @@ +/* global OC */ + +/** + * Copyright (c) 2016, Christoph Wurst <christoph@owncloud.com> + * + * This file is licensed under the Affero General Public License version 3 or later. + * See the COPYING-README file. + */ + +(function() { + 'use strict'; + + /** + * Model for storing and saving user settings + * + * @class UserSettings + */ + var UserSettings = OC.Backbone.Model.extend({ + url: OC.generateUrl('/settings/users/{id}/settings', {id: OC.currentUser}), + parse: function(data) { + if (_.isUndefined(data)) { + return null; + } + if (_.isUndefined(data.data)) { + return null; + } + data = data.data; + + var ignored = [ + 'userId', + 'message' + ]; + + _.each(ignored, function(ign) { + if (!_.isUndefined(data[ign])) { + delete data[ign]; + } + }); + + return data; + } + }); + + OC.Settings = OC.Settings || {}; + + OC.Settings.UserSettings = UserSettings; +})();
\ No newline at end of file |