Settings saving now supports callbacks, SWU plugin utilizes those
This commit is contained in:
parent
8294082652
commit
a79e38a350
2 changed files with 35 additions and 21 deletions
|
|
@ -26,8 +26,6 @@ $(function() {
|
|||
self.config_checkoutFolder = ko.observable();
|
||||
self.config_checkType = ko.observable();
|
||||
|
||||
self.savingSettings = false;
|
||||
|
||||
self.configurationDialog = $("#settings_plugin_softwareupdate_configurationdialog");
|
||||
|
||||
self.config_availableCheckTypes = [
|
||||
|
|
@ -90,8 +88,10 @@ $(function() {
|
|||
self.configurationDialog.modal();
|
||||
};
|
||||
|
||||
self.savePluginSettings = function() {
|
||||
self.savingSettings = true;
|
||||
self.savePluginSettings = function(viewModel, event) {
|
||||
var target = $(event.target);
|
||||
target.prepend('<i class="icon-spinner icon-spin"></i> ');
|
||||
|
||||
var data = {
|
||||
plugins: {
|
||||
softwareupdate: {
|
||||
|
|
@ -101,11 +101,16 @@ $(function() {
|
|||
}
|
||||
}
|
||||
};
|
||||
self.settings.saveData(data, function() {
|
||||
self.configurationDialog.modal("hide");
|
||||
self._copyConfig();
|
||||
self.performCheck();
|
||||
self.savingSettings = false;
|
||||
self.settings.saveData(data, {
|
||||
success: function() {
|
||||
self.configurationDialog.modal("hide");
|
||||
self._copyConfig();
|
||||
self.performCheck();
|
||||
},
|
||||
complete: function() {
|
||||
$("i.icon-spinner", target).remove();
|
||||
},
|
||||
sending: true
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -375,10 +380,6 @@ $(function() {
|
|||
return true;
|
||||
};
|
||||
|
||||
self.onSettingsPreventRefresh = function() {
|
||||
return self.savingSettings;
|
||||
};
|
||||
|
||||
self.onDataUpdaterReconnect = function() {
|
||||
if (self.waitingForRestart) {
|
||||
self.waitingForRestart = false;
|
||||
|
|
|
|||
|
|
@ -669,13 +669,22 @@ $(function() {
|
|||
mapToObservables(serverChangedData, specialMappings, clientChangedData);
|
||||
};
|
||||
|
||||
self.saveData = function (data, successCallback) {
|
||||
self.saveData = function (data, successCallback, setAsSending) {
|
||||
var options;
|
||||
if (_.isPlainObject(successCallback)) {
|
||||
options = successCallback;
|
||||
} else {
|
||||
options = {
|
||||
success: successCallback,
|
||||
sending: (setAsSending == true)
|
||||
}
|
||||
}
|
||||
|
||||
self.settingsDialog.trigger("beforeSave");
|
||||
|
||||
if (data == undefined) {
|
||||
// we only set sending to true when we didn't include data
|
||||
self.sending(true);
|
||||
self.sending(data == undefined || options.sending || false);
|
||||
|
||||
if (data == undefined) {
|
||||
// we also only send data that actually changed when no data is specified
|
||||
data = getOnlyChangedData(self.getLocalData(), self.lastReceivedSettings);
|
||||
}
|
||||
|
|
@ -686,18 +695,22 @@ $(function() {
|
|||
dataType: "json",
|
||||
contentType: "application/json; charset=UTF-8",
|
||||
data: JSON.stringify(data),
|
||||
success: function(response) {
|
||||
success: function(data, status, xhr) {
|
||||
self.receiving(true);
|
||||
self.sending(false);
|
||||
try {
|
||||
self.fromResponse(response);
|
||||
if (successCallback) successCallback(response);
|
||||
self.fromResponse(data);
|
||||
if (options.success) options.success(data, status, xhr);
|
||||
} finally {
|
||||
self.receiving(false);
|
||||
}
|
||||
},
|
||||
error: function(xhr) {
|
||||
error: function(xhr, status, error) {
|
||||
self.sending(false);
|
||||
if (options.error) options.error(xhr, status, error);
|
||||
},
|
||||
complete: function(xhr, status) {
|
||||
if (options.complete) options.complete(xhr, status);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue