summaryrefslogtreecommitdiffstats
path: root/apps/files_external/js
diff options
context:
space:
mode:
authorRobin McCorkell <rmccorkell@owncloud.com>2015-11-22 17:25:32 +0000
committerRobin McCorkell <rmccorkell@owncloud.com>2015-11-22 17:25:32 +0000
commit08839ce77dcf23ae12725bd47e58c1bab5ea4aaf (patch)
tree73f82ca876e48777ebf1431c1f369a0d719f743b /apps/files_external/js
parentee7128b43549ed2ce1e8a96c132503809ac87ba9 (diff)
downloadnextcloud-server-08839ce77dcf23ae12725bd47e58c1bab5ea4aaf.tar.gz
nextcloud-server-08839ce77dcf23ae12725bd47e58c1bab5ea4aaf.zip
Defer initialisation of data until after complete construction
Diffstat (limited to 'apps/files_external/js')
-rw-r--r--apps/files_external/js/public_key.js12
-rw-r--r--apps/files_external/js/settings.js49
2 files changed, 39 insertions, 22 deletions
diff --git a/apps/files_external/js/public_key.js b/apps/files_external/js/public_key.js
index e35d7ad3789..5f9658381f0 100644
--- a/apps/files_external/js/public_key.js
+++ b/apps/files_external/js/public_key.js
@@ -1,10 +1,16 @@
$(document).ready(function() {
- OCA.External.Settings.mountConfig.whenSelectAuthMechanism(function($tr, authMechanism, scheme) {
+ OCA.External.Settings.mountConfig.whenSelectAuthMechanism(function($tr, authMechanism, scheme, onCompletion) {
if (scheme === 'publickey') {
var config = $tr.find('.configuration');
if ($(config).find('[name="public_key_generate"]').length === 0) {
setupTableRow($tr, config);
+ onCompletion.then(function() {
+ // If there's no private key, build one
+ if (0 === $(config).find('[data-parameter="private_key"]').val().length) {
+ generateKeys($tr);
+ }
+ });
}
}
});
@@ -22,10 +28,6 @@ $(document).ready(function() {
.attr('value', t('files_external', 'Generate keys'))
.attr('name', 'public_key_generate')
);
- // If there's no private key, build one
- if (0 === $(config).find('[data-parameter="private_key"]').val().length) {
- generateKeys(tr);
- }
}
function generateKeys(tr) {
diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js
index e16944eaa19..f712ecf4328 100644
--- a/apps/files_external/js/settings.js
+++ b/apps/files_external/js/settings.js
@@ -703,7 +703,9 @@ MountConfigListView.prototype = _.extend({
storageConfig.backend = $target.val();
$tr.find('.mountPoint input').val('');
- $tr = this.newStorage(storageConfig);
+ var onCompletion = jQuery.Deferred();
+ $tr = this.newStorage(storageConfig, onCompletion);
+ onCompletion.resolve();
$tr.find('td.configuration').children().not('[type=hidden]').first().focus();
this.saveStorageConfig($tr);
@@ -712,8 +714,23 @@ MountConfigListView.prototype = _.extend({
_onSelectAuthMechanism: function(event) {
var $target = $(event.target);
var $tr = $target.closest('tr');
-
var authMechanism = $target.val();
+
+ var onCompletion = jQuery.Deferred();
+ this.configureAuthMechanism($tr, authMechanism, onCompletion);
+ onCompletion.resolve();
+
+ this.saveStorageConfig($tr);
+ },
+
+ /**
+ * Configure the storage config with a new authentication mechanism
+ *
+ * @param {jQuery} $tr config row
+ * @param {string} authMechanism
+ * @param {jQuery.Deferred} onCompletion
+ */
+ configureAuthMechanism: function($tr, authMechanism, onCompletion) {
var authMechanismConfiguration = this._allAuthMechanisms[authMechanism];
var $td = $tr.find('td.configuration');
$td.find('.auth-param').remove();
@@ -723,22 +740,18 @@ MountConfigListView.prototype = _.extend({
));
this.trigger('selectAuthMechanism',
- $tr, authMechanism, authMechanismConfiguration['scheme']
+ $tr, authMechanism, authMechanismConfiguration['scheme'], onCompletion
);
-
- if ($tr.data('constructing') !== true) {
- // row is ready, trigger recheck
- this.saveStorageConfig($tr);
- }
},
/**
* Create a config row for a new storage
*
* @param {StorageConfig} storageConfig storage config to pull values from
+ * @param {jQuery.Deferred} onCompletion
* @return {jQuery} created row
*/
- newStorage: function(storageConfig) {
+ newStorage: function(storageConfig, onCompletion) {
var mountPoint = storageConfig.mountPoint;
var backend = this._allBackends[storageConfig.backend];
@@ -753,8 +766,6 @@ MountConfigListView.prototype = _.extend({
$tr.find('select#selectBackend');
addSelect2($tr.find('.applicableUsers'), this._userListLimit);
- $tr.data('constructing', true);
-
if (storageConfig.id) {
$tr.data('id', storageConfig.id);
}
@@ -777,15 +788,16 @@ MountConfigListView.prototype = _.extend({
});
if (storageConfig.authMechanism) {
selectAuthMechanism.val(storageConfig.authMechanism);
+ } else {
+ storageConfig.authMechanism = selectAuthMechanism.val();
}
$tr.find('td.authentication').append(selectAuthMechanism);
var $td = $tr.find('td.configuration');
$.each(backend.configuration, _.partial(this.writeParameterInput, $td));
- this.trigger('selectBackend', $tr, backend.identifier);
-
- selectAuthMechanism.trigger('change'); // generate configuration parameters for auth mechanism
+ this.trigger('selectBackend', $tr, backend.identifier, onCompletion);
+ this.configureAuthMechanism($tr, storageConfig.authMechanism, onCompletion);
if (storageConfig.backendOptions) {
$td.children().each(function() {
@@ -825,7 +837,6 @@ MountConfigListView.prototype = _.extend({
}));
}
- $tr.removeData('constructing');
return $tr;
},
@@ -842,11 +853,12 @@ MountConfigListView.prototype = _.extend({
url: OC.generateUrl('apps/files_external/userglobalstorages'),
contentType: 'application/json',
success: function(result) {
+ var onCompletion = jQuery.Deferred();
$.each(result, function(i, storageParams) {
storageParams.mountPoint = storageParams.mountPoint.substr(1); // trim leading slash
var storageConfig = new self._storageConfigClass();
_.extend(storageConfig, storageParams);
- var $tr = self.newStorage(storageConfig);
+ var $tr = self.newStorage(storageConfig, onCompletion);
// userglobal storages must be at the top of the list
$tr.detach();
@@ -862,6 +874,7 @@ MountConfigListView.prototype = _.extend({
$tr.find('.mountOptionsToggle, .remove').empty();
$tr.find('input, select, button').attr('disabled', 'disabled');
});
+ onCompletion.resolve();
}
});
}
@@ -873,13 +886,15 @@ MountConfigListView.prototype = _.extend({
url: OC.generateUrl(url),
contentType: 'application/json',
success: function(result) {
+ var onCompletion = jQuery.Deferred();
$.each(result, function(i, storageParams) {
storageParams.mountPoint = storageParams.mountPoint.substr(1); // trim leading slash
var storageConfig = new self._storageConfigClass();
_.extend(storageConfig, storageParams);
- var $tr = self.newStorage(storageConfig);
+ var $tr = self.newStorage(storageConfig, onCompletion);
self.recheckStorageConfig($tr);
});
+ onCompletion.resolve();
}
});
},