mirror of https://github.com/Radarr/Radarr
Better message handling on save
This commit is contained in:
parent
03c085030e
commit
ef58acb4b5
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using NzbDrone.Common;
|
||||||
using NzbDrone.Common.Reflection;
|
using NzbDrone.Common.Reflection;
|
||||||
using NzbDrone.Core.Annotations;
|
using NzbDrone.Core.Annotations;
|
||||||
|
|
||||||
|
@ -25,6 +26,12 @@ namespace NzbDrone.Api.ClientSchema
|
||||||
propertyInfo.SetValue(model, intValue, null);
|
propertyInfo.SetValue(model, intValue, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (propertyInfo.PropertyType == typeof(Nullable<Int32>))
|
||||||
|
{
|
||||||
|
var intValue = field.Value.ToString().ParseInt32();
|
||||||
|
propertyInfo.SetValue(model, intValue, null);
|
||||||
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
propertyInfo.SetValue(model, field.Value, null);
|
propertyInfo.SetValue(model, field.Value, null);
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
<component name="ProjectDictionaryState">
|
||||||
|
<dictionary name="Mark" />
|
||||||
|
</component>
|
|
@ -10,19 +10,11 @@ define(['app', 'Settings/SettingsModel', 'Shared/Messenger'], function () {
|
||||||
|
|
||||||
saveSettings: function () {
|
saveSettings: function () {
|
||||||
if (!this.model.isSaved) {
|
if (!this.model.isSaved) {
|
||||||
this.model.save(undefined, this.syncNotification("General Settings Saved", "Couldn't Save General Settings"));
|
this.model.save(undefined, NzbDrone.Settings.SyncNotificaiton.callback({
|
||||||
|
successMessage: 'General Settings saved',
|
||||||
|
errorMessage: "Failed to save General Settings"
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
syncNotification: function (success, error) {
|
|
||||||
return {
|
|
||||||
success: function () {
|
|
||||||
NzbDrone.Shared.Messenger.show({message: success});
|
|
||||||
},
|
|
||||||
error : function () {
|
|
||||||
NzbDrone.Shared.Messenger.show({message: error, type: 'error'});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
define(['app',
|
define(['app',
|
||||||
'Settings/Indexers/ItemView',
|
'Settings/Indexers/ItemView',
|
||||||
'Settings/Indexers/EditView'],
|
'Settings/Indexers/EditView',
|
||||||
|
'Settings/SyncNotification'],
|
||||||
function () {
|
function () {
|
||||||
NzbDrone.Settings.Indexers.CollectionView = Backbone.Marionette.CompositeView.extend({
|
NzbDrone.Settings.Indexers.CollectionView = Backbone.Marionette.CompositeView.extend({
|
||||||
itemView : NzbDrone.Settings.Indexers.ItemView,
|
itemView : NzbDrone.Settings.Indexers.ItemView,
|
||||||
|
@ -35,29 +36,11 @@ define(['app',
|
||||||
},
|
},
|
||||||
|
|
||||||
saveSettings: function () {
|
saveSettings: function () {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
_.each(this.collection.models, function (model, index, list) {
|
_.each(this.collection.models, function (model, index, list) {
|
||||||
var name = model.get('name');
|
model.saveIfChanged(NzbDrone.Settings.SyncNotificaiton.callback({
|
||||||
var error = 'Failed to save indexer: ' + name;
|
errorMessage: 'Failed to save indexer: ' + model.get('name')
|
||||||
|
}));
|
||||||
model.saveIfChanged(self.syncNotification(undefined, error));
|
|
||||||
});
|
});
|
||||||
},
|
|
||||||
|
|
||||||
syncNotification: function (success, error) {
|
|
||||||
return {
|
|
||||||
success: function () {
|
|
||||||
if (success) {
|
|
||||||
NzbDrone.Shared.Messenger.show({message: success});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error : function () {
|
|
||||||
if (error) {
|
|
||||||
NzbDrone.Shared.Messenger.show({message: error, type: 'error'});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,20 +21,10 @@ define(['app', 'Settings/Naming/NamingModel'], function () {
|
||||||
},
|
},
|
||||||
|
|
||||||
saveSettings: function () {
|
saveSettings: function () {
|
||||||
this.model.save(undefined, this.syncNotification("Naming Settings Saved", "Couldn't Save Naming Settings"));
|
this.model.save(undefined, NzbDrone.Settings.SyncNotificaiton.callback({
|
||||||
},
|
successMessage: 'Naming Settings saved',
|
||||||
|
errorMessage: "Failed to save Naming Settings"
|
||||||
|
}));
|
||||||
syncNotification: function (success, error) {
|
|
||||||
return {
|
|
||||||
success: function () {
|
|
||||||
window.alert(success);
|
|
||||||
},
|
|
||||||
|
|
||||||
error: function () {
|
|
||||||
window.alert(error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
@ -24,7 +24,12 @@ define([
|
||||||
var success = 'Notification Saved: ' + name;
|
var success = 'Notification Saved: ' + name;
|
||||||
var fail = 'Failed to save notification: ' + name;
|
var fail = 'Failed to save notification: ' + name;
|
||||||
|
|
||||||
this.model.save(undefined, this.syncNotification(success, fail, this));
|
this.model.save(undefined, NzbDrone.Settings.SyncNotificaiton.callback({
|
||||||
|
successMessage: success,
|
||||||
|
errorMessage: fail,
|
||||||
|
successCallback: this._saveSuccess,
|
||||||
|
context: this
|
||||||
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
_deleteNotification: function () {
|
_deleteNotification: function () {
|
||||||
|
@ -32,21 +37,9 @@ define([
|
||||||
NzbDrone.modalRegion.show(view);
|
NzbDrone.modalRegion.show(view);
|
||||||
},
|
},
|
||||||
|
|
||||||
syncNotification: function (success, error, context) {
|
_saveSuccess: function () {
|
||||||
return {
|
this.notificationCollection.add(this.model, { merge: true });
|
||||||
success: function () {
|
NzbDrone.modalRegion.closeModal();
|
||||||
NzbDrone.Shared.Messenger.show({
|
|
||||||
message: success
|
|
||||||
});
|
|
||||||
|
|
||||||
context.notificationCollection.add(context.model, { merge: true });
|
|
||||||
NzbDrone.modalRegion.closeModal();
|
|
||||||
},
|
|
||||||
|
|
||||||
error: function () {
|
|
||||||
window.alert(error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
"use strict";
|
||||||
|
define([
|
||||||
|
'app'
|
||||||
|
],
|
||||||
|
function () {
|
||||||
|
NzbDrone.Settings.SyncNotificaiton = {
|
||||||
|
callback: function (options) {
|
||||||
|
return {
|
||||||
|
success: function () {
|
||||||
|
if (options.successMessage) {
|
||||||
|
NzbDrone.Shared.Messenger.show({message: options.successMessage});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.successCallback) {
|
||||||
|
options.successCallback.call(options.context);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error : function () {
|
||||||
|
if (options.errorMessage) {
|
||||||
|
NzbDrone.Shared.Messenger.show({message: options.errorMessage, type: 'error'});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.errorCallback) {
|
||||||
|
options.errorCallback.call(options.context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue