settings is fully moved to required.

This commit is contained in:
Keivan Beigi 2013-06-18 18:02:23 -07:00
commit 6f8c73771d
54 changed files with 533 additions and 439 deletions

View file

@ -1,7 +1,7 @@
"use strict";
define(['app', 'Settings/Indexers/Model'], function () {
NzbDrone.Settings.Indexers.Collection = Backbone.Collection.extend({
url : NzbDrone.Constants.ApiRoot + '/indexer',
model: NzbDrone.Settings.Indexers.Model
define(['app', 'Settings/Indexers/Model'], function (App, IndexerModel) {
return Backbone.Collection.extend({
url : App.Constants.ApiRoot + '/indexer',
model: IndexerModel
});
});

View file

@ -1,60 +1,63 @@
'use strict';
define(['app',
'Settings/Indexers/ItemView',
'Settings/Indexers/EditView',
'Settings/SyncNotification'],
function () {
NzbDrone.Settings.Indexers.CollectionView = Backbone.Marionette.CompositeView.extend({
itemView : NzbDrone.Settings.Indexers.ItemView,
itemViewContainer : '#x-indexers',
template : 'Settings/Indexers/CollectionTemplate',
'marionette',
'Shared/Messenger',
'Settings/Indexers/ItemView',
'Settings/Indexers/EditView',
'Settings/Indexers/Collection'],
function (App, Marionette, Messenger, IndexerItemView, IndexerEditView, IndexerCollection) {
return Marionette.CompositeView.extend({
itemView : IndexerItemView,
itemViewContainer: '#x-indexers',
template : 'Settings/Indexers/CollectionTemplate',
events: {
'click .x-add': 'openSchemaModal'
},
events: {
'click .x-add': 'openSchemaModal'
},
initialize: function () {
NzbDrone.vent.on(NzbDrone.Commands.SaveSettings, this._saveSettings, this);
this.savedCount = 0;
},
initialize: function () {
this.listenTo(App.vent, App.Commands.SaveSettings, this._saveSettings);
this.savedCount = 0;
},
openSchemaModal: function () {
var self = this;
//TODO: Is there a better way to deal with changing URLs?
var schemaCollection = new NzbDrone.Settings.Indexers.Collection();
schemaCollection.url = '/api/indexer/schema';
schemaCollection.fetch({
success: function (collection) {
collection.url = '/api/indexer';
var model = _.first(collection.models);
model.set('id', undefined);
model.set('name', '');
openSchemaModal: function () {
var self = this;
//TODO: Is there a better way to deal with changing URLs?
var schemaCollection = new IndexerCollection();
schemaCollection.url = '/api/indexer/schema';
schemaCollection.fetch({
success: function (collection) {
collection.url = '/api/indexer';
var model = _.first(collection.models);
model.set('id', undefined);
model.set('name', '');
var view = new NzbDrone.Settings.Indexers.EditView({ model: model, indexerCollection: self.collection});
NzbDrone.modalRegion.show(view);
var view = new IndexerEditView({ model: model, indexerCollection: self.collection});
App.modalRegion.show(view);
}
});
},
_saveSettings: function () {
var self = this;
_.each(this.collection.models, function (model, index, list) {
model.saveIfChanged(NzbDrone.Settings.SyncNotificaiton.callback({
errorMessage : 'Failed to save indexer: ' + model.get('name'),
successCallback: self._saveSuccessful,
context : self
}));
});
if (self.savedCount > 0) {
Messenger.show({message: 'Indexer settings saved'});
}
});
},
_saveSettings: function () {
var self = this;
this.savedCount = 0;
},
_.each(this.collection.models, function (model, index, list) {
model.saveIfChanged(NzbDrone.Settings.SyncNotificaiton.callback({
errorMessage: 'Failed to save indexer: ' + model.get('name'),
successCallback: self._saveSuccessful,
context: self
}));
});
if (self.savedCount > 0) {
NzbDrone.Shared.Messenger.show({message: 'Indexer settings saved'});
_saveSuccessful: function () {
this.savedCount++;
}
this.savedCount = 0;
},
_saveSuccessful: function () {
this.savedCount++;
}
});
});
});

View file

@ -2,12 +2,14 @@
define([
'app',
'Settings/Indexers/Model'
'marionette',
'Shared/Messenger',
'Mixins/AsModelBoundView'
], function () {
], function (App, Marionette, Messenger, AsModelBoundView) {
NzbDrone.Settings.Indexers.EditView = Backbone.Marionette.ItemView.extend({
template : 'Settings/Indexers/EditTemplate',
var view = Marionette.ItemView.extend({
template: 'Settings/Indexers/EditTemplate',
events: {
'click .x-save': 'save'
@ -24,12 +26,12 @@ define([
syncNotification: function (success, error, context) {
return {
success: function () {
NzbDrone.Shared.Messenger.show({
Messenger.show({
message: success
});
context.indexerCollection.add(context.model);
NzbDrone.modalRegion.closeModal();
App.modalRegion.closeModal();
},
error: function () {
@ -38,4 +40,7 @@ define([
};
}
});
return AsModelBoundView.call(view);
});

View file

@ -1,13 +1,10 @@
"use strict";
define([
'app',
'Settings/Indexers/Collection'
define(['marionette'], function () {
], function () {
NzbDrone.Settings.Indexers.ItemView = Backbone.Marionette.ItemView.extend({
template : 'Settings/Indexers/ItemTemplate',
tagName : 'li'
return Marionette.ItemView.extend({
template: 'Settings/Indexers/ItemTemplate',
tagName : 'li'
});
});

View file

@ -1,9 +1,9 @@
"use strict";
define(['app',
'Mixins/SaveIfChangedModel',
'backbone.deepmodel'], function (App, SaveIfChangedModel, DeepModel) {
NzbDrone.Settings.Indexers.Model = DeepModel.DeepModel.extend({
define([
'backbone.deepmodel', 'Mixins/AsChangeTrackingModel'], function (DeepModel, AsChangeTrackingModel) {
var model = DeepModel.DeepModel.extend({
});
_.extend(NzbDrone.Settings.Indexers.Model.prototype, NzbDrone.Mixins.SaveIfChangedModel);
return AsChangeTrackingModel.call(model);
});