$(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);
+ }
+ });
}
}
});
.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) {
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);
_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();
));
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];
$tr.find('select#selectBackend');
addSelect2($tr.find('.applicableUsers'), this._userListLimit);
- $tr.data('constructing', true);
-
if (storageConfig.id) {
$tr.data('id', storageConfig.id);
}
});
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() {
}));
}
- $tr.removeData('constructing');
return $tr;
},
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();
$tr.find('.mountOptionsToggle, .remove').empty();
$tr.find('input, select, button').attr('disabled', 'disabled');
});
+ onCompletion.resolve();
}
});
}
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();
}
});
},