Better message handling on save

pull/24/head
Mark McDowall 11 years ago
parent 03c085030e
commit ef58acb4b5

@ -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 @@ namespace NzbDrone.Api.ClientSchema
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);

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

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

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

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

@ -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 });
NzbDrone.modalRegion.closeModal();
},
error: function () {
window.alert(error);
}
};
_saveSuccess: function () {
this.notificationCollection.add(this.model, { merge: true });
NzbDrone.modalRegion.closeModal();
}
});
});

@ -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…
Cancel
Save