Defer initialisation of data until after complete construction
This commit is contained in:
parent
ee7128b435
commit
08839ce77d
|
@ -1,10 +1,16 @@
|
||||||
$(document).ready(function() {
|
$(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') {
|
if (scheme === 'publickey') {
|
||||||
var config = $tr.find('.configuration');
|
var config = $tr.find('.configuration');
|
||||||
if ($(config).find('[name="public_key_generate"]').length === 0) {
|
if ($(config).find('[name="public_key_generate"]').length === 0) {
|
||||||
setupTableRow($tr, config);
|
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('value', t('files_external', 'Generate keys'))
|
||||||
.attr('name', 'public_key_generate')
|
.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) {
|
function generateKeys(tr) {
|
||||||
|
|
|
@ -703,7 +703,9 @@ MountConfigListView.prototype = _.extend({
|
||||||
storageConfig.backend = $target.val();
|
storageConfig.backend = $target.val();
|
||||||
$tr.find('.mountPoint input').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();
|
$tr.find('td.configuration').children().not('[type=hidden]').first().focus();
|
||||||
this.saveStorageConfig($tr);
|
this.saveStorageConfig($tr);
|
||||||
|
@ -712,8 +714,23 @@ MountConfigListView.prototype = _.extend({
|
||||||
_onSelectAuthMechanism: function(event) {
|
_onSelectAuthMechanism: function(event) {
|
||||||
var $target = $(event.target);
|
var $target = $(event.target);
|
||||||
var $tr = $target.closest('tr');
|
var $tr = $target.closest('tr');
|
||||||
|
|
||||||
var authMechanism = $target.val();
|
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 authMechanismConfiguration = this._allAuthMechanisms[authMechanism];
|
||||||
var $td = $tr.find('td.configuration');
|
var $td = $tr.find('td.configuration');
|
||||||
$td.find('.auth-param').remove();
|
$td.find('.auth-param').remove();
|
||||||
|
@ -723,22 +740,18 @@ MountConfigListView.prototype = _.extend({
|
||||||
));
|
));
|
||||||
|
|
||||||
this.trigger('selectAuthMechanism',
|
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
|
* Create a config row for a new storage
|
||||||
*
|
*
|
||||||
* @param {StorageConfig} storageConfig storage config to pull values from
|
* @param {StorageConfig} storageConfig storage config to pull values from
|
||||||
|
* @param {jQuery.Deferred} onCompletion
|
||||||
* @return {jQuery} created row
|
* @return {jQuery} created row
|
||||||
*/
|
*/
|
||||||
newStorage: function(storageConfig) {
|
newStorage: function(storageConfig, onCompletion) {
|
||||||
var mountPoint = storageConfig.mountPoint;
|
var mountPoint = storageConfig.mountPoint;
|
||||||
var backend = this._allBackends[storageConfig.backend];
|
var backend = this._allBackends[storageConfig.backend];
|
||||||
|
|
||||||
|
@ -753,8 +766,6 @@ MountConfigListView.prototype = _.extend({
|
||||||
$tr.find('select#selectBackend');
|
$tr.find('select#selectBackend');
|
||||||
addSelect2($tr.find('.applicableUsers'), this._userListLimit);
|
addSelect2($tr.find('.applicableUsers'), this._userListLimit);
|
||||||
|
|
||||||
$tr.data('constructing', true);
|
|
||||||
|
|
||||||
if (storageConfig.id) {
|
if (storageConfig.id) {
|
||||||
$tr.data('id', storageConfig.id);
|
$tr.data('id', storageConfig.id);
|
||||||
}
|
}
|
||||||
|
@ -777,15 +788,16 @@ MountConfigListView.prototype = _.extend({
|
||||||
});
|
});
|
||||||
if (storageConfig.authMechanism) {
|
if (storageConfig.authMechanism) {
|
||||||
selectAuthMechanism.val(storageConfig.authMechanism);
|
selectAuthMechanism.val(storageConfig.authMechanism);
|
||||||
|
} else {
|
||||||
|
storageConfig.authMechanism = selectAuthMechanism.val();
|
||||||
}
|
}
|
||||||
$tr.find('td.authentication').append(selectAuthMechanism);
|
$tr.find('td.authentication').append(selectAuthMechanism);
|
||||||
|
|
||||||
var $td = $tr.find('td.configuration');
|
var $td = $tr.find('td.configuration');
|
||||||
$.each(backend.configuration, _.partial(this.writeParameterInput, $td));
|
$.each(backend.configuration, _.partial(this.writeParameterInput, $td));
|
||||||
|
|
||||||
this.trigger('selectBackend', $tr, backend.identifier);
|
this.trigger('selectBackend', $tr, backend.identifier, onCompletion);
|
||||||
|
this.configureAuthMechanism($tr, storageConfig.authMechanism, onCompletion);
|
||||||
selectAuthMechanism.trigger('change'); // generate configuration parameters for auth mechanism
|
|
||||||
|
|
||||||
if (storageConfig.backendOptions) {
|
if (storageConfig.backendOptions) {
|
||||||
$td.children().each(function() {
|
$td.children().each(function() {
|
||||||
|
@ -825,7 +837,6 @@ MountConfigListView.prototype = _.extend({
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
$tr.removeData('constructing');
|
|
||||||
return $tr;
|
return $tr;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -842,11 +853,12 @@ MountConfigListView.prototype = _.extend({
|
||||||
url: OC.generateUrl('apps/files_external/userglobalstorages'),
|
url: OC.generateUrl('apps/files_external/userglobalstorages'),
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
success: function(result) {
|
success: function(result) {
|
||||||
|
var onCompletion = jQuery.Deferred();
|
||||||
$.each(result, function(i, storageParams) {
|
$.each(result, function(i, storageParams) {
|
||||||
storageParams.mountPoint = storageParams.mountPoint.substr(1); // trim leading slash
|
storageParams.mountPoint = storageParams.mountPoint.substr(1); // trim leading slash
|
||||||
var storageConfig = new self._storageConfigClass();
|
var storageConfig = new self._storageConfigClass();
|
||||||
_.extend(storageConfig, storageParams);
|
_.extend(storageConfig, storageParams);
|
||||||
var $tr = self.newStorage(storageConfig);
|
var $tr = self.newStorage(storageConfig, onCompletion);
|
||||||
|
|
||||||
// userglobal storages must be at the top of the list
|
// userglobal storages must be at the top of the list
|
||||||
$tr.detach();
|
$tr.detach();
|
||||||
|
@ -862,6 +874,7 @@ MountConfigListView.prototype = _.extend({
|
||||||
$tr.find('.mountOptionsToggle, .remove').empty();
|
$tr.find('.mountOptionsToggle, .remove').empty();
|
||||||
$tr.find('input, select, button').attr('disabled', 'disabled');
|
$tr.find('input, select, button').attr('disabled', 'disabled');
|
||||||
});
|
});
|
||||||
|
onCompletion.resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -873,13 +886,15 @@ MountConfigListView.prototype = _.extend({
|
||||||
url: OC.generateUrl(url),
|
url: OC.generateUrl(url),
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
success: function(result) {
|
success: function(result) {
|
||||||
|
var onCompletion = jQuery.Deferred();
|
||||||
$.each(result, function(i, storageParams) {
|
$.each(result, function(i, storageParams) {
|
||||||
storageParams.mountPoint = storageParams.mountPoint.substr(1); // trim leading slash
|
storageParams.mountPoint = storageParams.mountPoint.substr(1); // trim leading slash
|
||||||
var storageConfig = new self._storageConfigClass();
|
var storageConfig = new self._storageConfigClass();
|
||||||
_.extend(storageConfig, storageParams);
|
_.extend(storageConfig, storageParams);
|
||||||
var $tr = self.newStorage(storageConfig);
|
var $tr = self.newStorage(storageConfig, onCompletion);
|
||||||
self.recheckStorageConfig($tr);
|
self.recheckStorageConfig($tr);
|
||||||
});
|
});
|
||||||
|
onCompletion.resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue