2016-10-31 10:53:37 +00:00
|
|
|
/* global OC, result, _ */
|
2016-04-20 10:19:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-10-31 10:53:37 +00:00
|
|
|
(function(_, $, OC) {
|
2016-04-20 10:19:39 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var FederationSettingsView = OC.Backbone.View.extend({
|
|
|
|
_inputFields: undefined,
|
|
|
|
|
|
|
|
/** @var Backbone.Model */
|
|
|
|
_config: undefined,
|
|
|
|
|
|
|
|
initialize: function(options) {
|
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
if (options.config) {
|
|
|
|
this._config = options.config;
|
|
|
|
} else {
|
2016-04-20 15:03:50 +00:00
|
|
|
this._config = new OC.Settings.UserSettings();
|
2016-04-20 10:19:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this._inputFields = [
|
|
|
|
'displayname',
|
|
|
|
'phone',
|
|
|
|
'email',
|
|
|
|
'website',
|
2016-11-11 13:36:17 +00:00
|
|
|
'twitter',
|
2016-04-21 08:33:03 +00:00
|
|
|
'address',
|
|
|
|
'avatar'
|
2016-04-20 10:19:39 +00:00
|
|
|
];
|
|
|
|
|
2016-04-20 15:03:50 +00:00
|
|
|
var self = this;
|
|
|
|
_.each(this._inputFields, function(field) {
|
2016-04-21 08:33:03 +00:00
|
|
|
var scopeOnly = field === 'avatar';
|
|
|
|
|
2016-04-20 15:03:50 +00:00
|
|
|
// Initialize config model
|
2016-04-21 08:33:03 +00:00
|
|
|
if (!scopeOnly) {
|
|
|
|
self._config.set(field, $('#' + field).val());
|
|
|
|
}
|
2016-04-20 15:03:50 +00:00
|
|
|
self._config.set(field + 'Scope', $('#' + field + 'scope').val());
|
|
|
|
|
|
|
|
// Set inputs whenever model values change
|
2016-04-21 08:33:03 +00:00
|
|
|
if (!scopeOnly) {
|
2016-10-31 10:53:37 +00:00
|
|
|
self.listenTo(self._config, 'change:' + field, function() {
|
2016-04-21 08:33:03 +00:00
|
|
|
self.$('#' + field).val(self._config.get(field));
|
|
|
|
});
|
|
|
|
}
|
2016-10-31 10:53:37 +00:00
|
|
|
self.listenTo(self._config, 'change:' + field + 'Scope', function() {
|
2016-04-21 09:19:10 +00:00
|
|
|
self._setFieldScopeIcon(field, self._config.get(field + 'Scope'));
|
2016-04-20 15:03:50 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-04-20 10:19:39 +00:00
|
|
|
this._registerEvents();
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var self = this;
|
|
|
|
_.each(this._inputFields, function(field) {
|
2016-04-21 08:33:03 +00:00
|
|
|
var $heading = self.$('#' + field + 'form h2');
|
|
|
|
var $icon = self.$('#' + field + 'form h2 > span');
|
2016-11-16 11:35:07 +00:00
|
|
|
var scopeMenu = new OC.Settings.FederationScopeMenu({field: field});
|
2016-04-20 10:19:39 +00:00
|
|
|
|
|
|
|
self.listenTo(scopeMenu, 'select:scope', function(scope) {
|
|
|
|
self._onScopeChanged(field, scope);
|
|
|
|
});
|
|
|
|
$heading.append(scopeMenu.$el);
|
|
|
|
$icon.on('click', _.bind(scopeMenu.show, scopeMenu));
|
|
|
|
|
2016-04-21 09:19:10 +00:00
|
|
|
// Restore initial state
|
|
|
|
self._setFieldScopeIcon(field, self._config.get(field + 'Scope'));
|
2016-04-20 10:19:39 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_registerEvents: function() {
|
|
|
|
var self = this;
|
|
|
|
_.each(this._inputFields, function(field) {
|
2016-04-21 08:33:03 +00:00
|
|
|
if (field === 'avatar') {
|
|
|
|
return;
|
|
|
|
}
|
2016-12-05 09:47:00 +00:00
|
|
|
self.$('#' + field).keyUpDelayedOrEnter(_.bind(self._onInputChanged, self), true);
|
2016-04-20 10:19:39 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_onInputChanged: function(e) {
|
2016-04-20 15:03:50 +00:00
|
|
|
var self = this;
|
|
|
|
|
2016-11-18 17:34:01 +00:00
|
|
|
var $dialog = $('.oc-dialog:visible');
|
|
|
|
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
|
|
|
|
if($dialog.length === 0) {
|
|
|
|
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this._onInputChanged, this, e));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2016-04-20 10:19:39 +00:00
|
|
|
var $target = $(e.target);
|
|
|
|
var value = $target.val();
|
|
|
|
var field = $target.attr('id');
|
|
|
|
this._config.set(field, value);
|
2016-11-18 17:34:01 +00:00
|
|
|
|
2016-04-20 15:03:50 +00:00
|
|
|
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);
|
|
|
|
});
|
2016-04-20 10:19:39 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onScopeChanged: function(field, scope) {
|
2016-11-18 19:03:02 +00:00
|
|
|
var $dialog = $('.oc-dialog:visible');
|
|
|
|
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
|
|
|
|
if($dialog.length === 0) {
|
|
|
|
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this._onScopeChanged, this, field, scope));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-20 15:03:50 +00:00
|
|
|
this._config.set(field + 'Scope', scope);
|
2016-11-18 18:44:21 +00:00
|
|
|
|
2016-11-21 20:50:57 +00:00
|
|
|
$('#' + field + 'scope').val(scope);
|
2016-11-18 18:44:21 +00:00
|
|
|
|
2016-04-20 15:03:50 +00:00
|
|
|
// TODO: user loading/success feedback
|
|
|
|
this._config.save();
|
2016-04-20 10:19:39 +00:00
|
|
|
this._setFieldScopeIcon(field, scope);
|
2017-04-26 18:23:56 +00:00
|
|
|
this._updateVerifyButton(field, scope);
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateVerifyButton: function(field, scope) {
|
|
|
|
// show verification button if the value is set and the scope is 'public'
|
|
|
|
if (field === 'twitter' || field === 'website'|| field === 'email') {
|
|
|
|
var verify = this.$('#' + field + 'form > .verify');
|
|
|
|
var scope = this.$('#' + field + 'scope').val();
|
|
|
|
var value = this.$('#' + field).val();
|
|
|
|
|
|
|
|
if (scope === 'public' && value !== '') {
|
|
|
|
verify.removeClass('hidden');
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
verify.addClass('hidden');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2016-04-20 10:19:39 +00:00
|
|
|
},
|
|
|
|
|
2016-04-20 15:03:50 +00:00
|
|
|
_showInputChangeSuccess: function(field) {
|
2017-04-26 09:19:09 +00:00
|
|
|
var $icon = this.$('#' + field + 'form > .icon-checkmark');
|
2016-04-20 15:03:50 +00:00
|
|
|
$icon.fadeIn(200);
|
|
|
|
setTimeout(function() {
|
|
|
|
$icon.fadeOut(300);
|
|
|
|
}, 2000);
|
2017-04-26 09:19:09 +00:00
|
|
|
|
2017-04-26 18:23:56 +00:00
|
|
|
var scope = this.$('#' + field + 'scope').val();
|
|
|
|
var verifyAvailable = this._updateVerifyButton(field, scope);
|
|
|
|
|
|
|
|
// change verification buttons from 'verify' to 'verifying...' on value change
|
|
|
|
if (verifyAvailable) {
|
2017-04-26 19:32:11 +00:00
|
|
|
if (field === 'twitter' || field === 'website') {
|
2017-04-26 18:23:56 +00:00
|
|
|
var verifyStatus = this.$('#' + field + 'form > .verify > #verify-' + field);
|
2017-04-27 12:03:59 +00:00
|
|
|
verifyStatus.attr('data-origin-title', t('core', 'Verify'));
|
2017-04-26 18:23:56 +00:00
|
|
|
verifyStatus.attr('src', OC.imagePath('core', 'actions/verify.svg'));
|
2017-04-27 10:27:36 +00:00
|
|
|
verifyStatus.data('status', '0');
|
2017-04-26 18:23:56 +00:00
|
|
|
verifyStatus.addClass('verify-action');
|
|
|
|
} else if (field === 'email') {
|
|
|
|
var verifyStatus = this.$('#' + field + 'form > .verify > #verify-' + field);
|
2017-04-27 12:03:59 +00:00
|
|
|
verifyStatus.attr('data-origin-title', t('core', 'Verifying …'));
|
2017-04-27 10:27:36 +00:00
|
|
|
verifyStatus.data('status', '1');
|
2017-04-26 18:23:56 +00:00
|
|
|
verifyStatus.attr('src', OC.imagePath('core', 'actions/verifying.svg'));
|
|
|
|
}
|
2017-04-26 09:19:09 +00:00
|
|
|
}
|
2016-04-20 15:03:50 +00:00
|
|
|
},
|
|
|
|
|
2016-04-20 10:19:39 +00:00
|
|
|
_setFieldScopeIcon: function(field, scope) {
|
|
|
|
var $icon = this.$('#' + field + 'form > h2 > span');
|
|
|
|
$icon.removeClass('icon-password');
|
|
|
|
$icon.removeClass('icon-contacts-dark');
|
|
|
|
$icon.removeClass('icon-link');
|
|
|
|
switch (scope) {
|
|
|
|
case 'private':
|
|
|
|
$icon.addClass('icon-password');
|
|
|
|
break;
|
|
|
|
case 'contacts':
|
|
|
|
$icon.addClass('icon-contacts-dark');
|
|
|
|
break;
|
|
|
|
case 'public':
|
|
|
|
$icon.addClass('icon-link');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
OC.Settings = OC.Settings || {};
|
|
|
|
OC.Settings.FederationSettingsView = FederationSettingsView;
|
2016-11-11 13:36:17 +00:00
|
|
|
})(_, $, OC);
|