1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Better message handling on save

This commit is contained in:
Mark McDowall 2013-05-31 17:22:47 -07:00
parent 03c085030e
commit ef58acb4b5
7 changed files with 63 additions and 64 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using NzbDrone.Common;
using NzbDrone.Common.Reflection;
using NzbDrone.Core.Annotations;
@ -25,6 +26,12 @@ public static T DeserializeSchema<T>(T model, List<Field> fields)
propertyInfo.SetValue(model, intValue, null);
}
else if (propertyInfo.PropertyType == typeof(Nullable<Int32>))
{
var intValue = field.Value.ToString().ParseInt32();
propertyInfo.SetValue(model, intValue, null);
}
else
{
propertyInfo.SetValue(model, field.Value, null);

View File

@ -0,0 +1,3 @@
<component name="ProjectDictionaryState">
<dictionary name="Mark" />
</component>

View File

@ -10,19 +10,11 @@ define(['app', 'Settings/SettingsModel', 'Shared/Messenger'], function () {
saveSettings: function () {
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'});
}
};
}
}
);

View File

@ -1,7 +1,8 @@
'use strict';
define(['app',
'Settings/Indexers/ItemView',
'Settings/Indexers/EditView'],
'Settings/Indexers/EditView',
'Settings/SyncNotification'],
function () {
NzbDrone.Settings.Indexers.CollectionView = Backbone.Marionette.CompositeView.extend({
itemView : NzbDrone.Settings.Indexers.ItemView,
@ -35,29 +36,11 @@ define(['app',
},
saveSettings: function () {
var self = this;
_.each(this.collection.models, function (model, index, list) {
var name = model.get('name');
var error = 'Failed to save indexer: ' + name;
model.saveIfChanged(self.syncNotification(undefined, error));
model.saveIfChanged(NzbDrone.Settings.SyncNotificaiton.callback({
errorMessage: 'Failed to save indexer: ' + model.get('name')
}));
});
},
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'});
}
}
};
}
});
});

View File

@ -21,20 +21,10 @@ define(['app', 'Settings/Naming/NamingModel'], function () {
},
saveSettings: function () {
this.model.save(undefined, this.syncNotification("Naming Settings Saved", "Couldn't Save Naming Settings"));
},
syncNotification: function (success, error) {
return {
success: function () {
window.alert(success);
},
error: function () {
window.alert(error);
}
};
this.model.save(undefined, NzbDrone.Settings.SyncNotificaiton.callback({
successMessage: 'Naming Settings saved',
errorMessage: "Failed to save Naming Settings"
}));
}
});
})

View File

@ -24,7 +24,12 @@ define([
var success = 'Notification Saved: ' + 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 () {
@ -32,21 +37,9 @@ define([
NzbDrone.modalRegion.show(view);
},
syncNotification: function (success, error, context) {
return {
success: function () {
NzbDrone.Shared.Messenger.show({
message: success
});
context.notificationCollection.add(context.model, { merge: true });
_saveSuccess: function () {
this.notificationCollection.add(this.model, { merge: true });
NzbDrone.modalRegion.closeModal();
},
error: function () {
window.alert(error);
}
};
}
});
});

View File

@ -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);
}
}
};
}
};
});