mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-15 01:23:53 -07:00
Notifications wired up
This commit is contained in:
parent
e4410d8cb7
commit
1d007be8fd
11 changed files with 174 additions and 64 deletions
|
@ -7,27 +7,6 @@ define([
|
|||
], function () {
|
||||
|
||||
NzbDrone.Settings.Indexers.ItemView = Backbone.Marionette.ItemView.extend({
|
||||
template : 'Settings/Indexers/ItemTemplate',
|
||||
initialize: function () {
|
||||
NzbDrone.vent.on(NzbDrone.Commands.SaveSettings, this.saveSettings, this);
|
||||
},
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
}
|
||||
template : 'Settings/Indexers/ItemTemplate'
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,10 +14,14 @@ define([
|
|||
'click': 'addNotification'
|
||||
},
|
||||
|
||||
initialize: function (options) {
|
||||
this.notificationCollection = options.notificationCollection;
|
||||
},
|
||||
|
||||
addNotification: function () {
|
||||
this.model.set('id', undefined);
|
||||
this.model.set('name', '');
|
||||
var view = new NzbDrone.Settings.Notifications.EditView({ model: this.model});
|
||||
var view = new NzbDrone.Settings.Notifications.EditView({ model: this.model, notificationCollection: this.notificationCollection });
|
||||
NzbDrone.modalRegion.show(view);
|
||||
}
|
||||
});
|
||||
|
@ -25,6 +29,16 @@ define([
|
|||
NzbDrone.Settings.Notifications.AddView = Backbone.Marionette.CompositeView.extend({
|
||||
itemView : NzbDrone.Settings.Notifications.AddItemView,
|
||||
itemViewContainer : '.notifications .items',
|
||||
template : 'Settings/Notifications/AddTemplate'
|
||||
template : 'Settings/Notifications/AddTemplate',
|
||||
|
||||
itemViewOptions: function () {
|
||||
return {
|
||||
notificationCollection: this.notificationCollection
|
||||
};
|
||||
},
|
||||
|
||||
initialize: function (options) {
|
||||
this.notificationCollection = options.notificationCollection;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,8 +13,9 @@ define(['app', 'Settings/Notifications/ItemView', 'Settings/Notifications/AddVie
|
|||
var schemaCollection = new NzbDrone.Settings.Notifications.Collection();
|
||||
schemaCollection.url = '/api/notification/schema';
|
||||
schemaCollection.fetch();
|
||||
schemaCollection.url = '/api/notification';
|
||||
|
||||
var view = new NzbDrone.Settings.Notifications.AddView({ collection: schemaCollection});
|
||||
var view = new NzbDrone.Settings.Notifications.AddView({ collection: schemaCollection, notificationCollection: this.collection});
|
||||
NzbDrone.modalRegion.show(view);
|
||||
}
|
||||
});
|
||||
|
|
11
UI/Settings/Notifications/DeleteTemplate.html
Normal file
11
UI/Settings/Notifications/DeleteTemplate.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3>Remove: {{name}}</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>Are you sure you want to remove '{{name}}'?</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn" data-dismiss="modal">cancel</button>
|
||||
<button class="btn btn-danger x-confirm-delete">delete</button>
|
||||
</div>
|
24
UI/Settings/Notifications/DeleteView.js
Normal file
24
UI/Settings/Notifications/DeleteView.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
'use strict';
|
||||
define(['app', 'Settings/Notifications/Model'], function () {
|
||||
|
||||
NzbDrone.Settings.Notifications.DeleteView = Backbone.Marionette.ItemView.extend({
|
||||
template: 'Settings/Notifications/DeleteTemplate',
|
||||
|
||||
events: {
|
||||
'click .x-confirm-delete': 'removeNotification'
|
||||
},
|
||||
|
||||
removeNotification: function () {
|
||||
var self = this;
|
||||
|
||||
//Success is not getting triggered: http://stackoverflow.com/questions/6988873/backbone-model-destroy-not-triggering-success-function-on-success
|
||||
this.model.destroy({
|
||||
wait : true,
|
||||
success: function (model) {
|
||||
model.collection.remove(model);
|
||||
self.$el.parent().modal('hide');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
|
@ -13,18 +13,27 @@ define([
|
|||
'click .x-save': 'save'
|
||||
},
|
||||
|
||||
save: function () {
|
||||
this.model.save();
|
||||
|
||||
// window.alert('saving');
|
||||
// this.model.save(undefined, this.syncNotification("Notification Settings Saved", "Couldn't Save Notification Settings"));
|
||||
initialize: function (options) {
|
||||
this.notificationCollection = options.notificationCollection;
|
||||
},
|
||||
|
||||
save: function () {
|
||||
var name = this.model.get('name');
|
||||
var success = 'Notification Saved: ' + name;
|
||||
var fail = 'Failed to save notification: ' + name;
|
||||
|
||||
syncNotification: function (success, error) {
|
||||
this.model.save(undefined, this.syncNotification(success, fail, this));
|
||||
},
|
||||
|
||||
syncNotification: function (success, error, context) {
|
||||
return {
|
||||
success: function () {
|
||||
window.alert(success);
|
||||
NzbDrone.Shared.Messenger.show({
|
||||
message: success
|
||||
});
|
||||
|
||||
context.notificationCollection.add(context.model, { merge: true });
|
||||
context.$el.parent().modal('hide');
|
||||
},
|
||||
|
||||
error: function () {
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
<td name="cutoffName"></td>
|
||||
<td>
|
||||
<i class="icon-cog x-edit" title="Edit"></i>
|
||||
| Delete
|
||||
<i class="icon-remove x-delete" title="Delete"></i>
|
||||
</td>
|
|
@ -3,7 +3,8 @@
|
|||
define([
|
||||
'app',
|
||||
'Settings/Notifications/Collection',
|
||||
'Settings/Notifications/EditView'
|
||||
'Settings/Notifications/EditView',
|
||||
'Settings/Notifications/DeleteView'
|
||||
|
||||
], function () {
|
||||
|
||||
|
@ -13,15 +14,15 @@ define([
|
|||
|
||||
events: {
|
||||
'click .x-edit' : 'edit',
|
||||
'click .x-remove': 'removeNotification'
|
||||
'click .x-delete': 'deleteNotification'
|
||||
},
|
||||
|
||||
edit: function () {
|
||||
var view = new NzbDrone.Settings.Notifications.EditView({ model: this.model});
|
||||
var view = new NzbDrone.Settings.Notifications.EditView({ model: this.model, notificationCollection: this.model.collection});
|
||||
NzbDrone.modalRegion.show(view);
|
||||
},
|
||||
|
||||
removeNotification: function () {
|
||||
deleteNotification: function () {
|
||||
var view = new NzbDrone.Settings.Notifications.DeleteView({ model: this.model});
|
||||
NzbDrone.modalRegion.show(view);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue