diff --git a/NzbDrone.Api/Commands/CommandModule.cs b/NzbDrone.Api/Commands/CommandModule.cs index 18733976d..836427cca 100644 --- a/NzbDrone.Api/Commands/CommandModule.cs +++ b/NzbDrone.Api/Commands/CommandModule.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using Nancy; using NzbDrone.Api.Extensions; using NzbDrone.Common.Composition; using NzbDrone.Common.Messaging; @@ -16,10 +17,11 @@ namespace NzbDrone.Api.Commands _messageAggregator = messageAggregator; _container = container; - CreateResource = RunCommand; + Post["/"] = x => RunCommand(ReadResourceFromRequest()); + } - private CommandResource RunCommand(CommandResource resource) + private Response RunCommand(CommandResource resource) { var commandType = _container.GetImplementations(typeof(ICommand)) @@ -29,7 +31,7 @@ namespace NzbDrone.Api.Commands dynamic command = Request.Body.FromJson(commandType); _messageAggregator.PublishCommand(command); - return resource; + return resource.AsResponse(); } } } \ No newline at end of file diff --git a/NzbDrone.Api/Config/NamingModule.cs b/NzbDrone.Api/Config/NamingModule.cs index eb17a7c64..65f674b49 100644 --- a/NzbDrone.Api/Config/NamingModule.cs +++ b/NzbDrone.Api/Config/NamingModule.cs @@ -1,33 +1,93 @@ -using FluentValidation; +using System.Collections.Generic; +using FluentValidation; +using Nancy.Responses; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Organizer; +using NzbDrone.Core.Qualities; +using NzbDrone.Core.Tv; +using Nancy.ModelBinding; +using NzbDrone.Api.Mapping; +using NzbDrone.Api.Extensions; namespace NzbDrone.Api.Config { public class NamingModule : NzbDroneRestModule { private readonly INamingConfigService _namingConfigService; + private readonly IBuildFileNames _buildFileNames; - public NamingModule(INamingConfigService namingConfigService) + public NamingModule(INamingConfigService namingConfigService, IBuildFileNames buildFileNames) : base("config/naming") { _namingConfigService = namingConfigService; + _buildFileNames = buildFileNames; GetResourceSingle = GetNamingConfig; UpdateResource = UpdateNamingConfig; + + Get["/samples"] = x => GetExamples(this.Bind()); + SharedValidator.RuleFor(c => c.MultiEpisodeStyle).InclusiveBetween(0, 3); SharedValidator.RuleFor(c => c.NumberStyle).InclusiveBetween(0, 3); SharedValidator.RuleFor(c => c.Separator).Matches(@"\s|\s\-\s|\."); } - private NamingConfigResource UpdateNamingConfig(NamingConfigResource resource) + private void UpdateNamingConfig(NamingConfigResource resource) { - return ToResource(_namingConfigService.Save, resource); + GetNewId(_namingConfigService.Save, resource); } private NamingConfigResource GetNamingConfig() { - return ToResource(_namingConfigService.GetConfig); + return _namingConfigService.GetConfig().InjectTo(); + } + + private JsonResponse GetExamples(NamingConfigResource config) + { + var nameSpec = config.InjectTo(); + + var series = new Core.Tv.Series + { + SeriesType = SeriesTypes.Standard, + Title = "Series Title" + }; + + var episode1 = new Episode + { + SeasonNumber = 1, + EpisodeNumber = 1, + Title = "Episode Title (1)" + }; + + var episode2 = new Episode + { + SeasonNumber = 1, + EpisodeNumber = 2, + Title = "Episode Title (2)" + }; + + var episodeFile = new EpisodeFile + { + Quality = new QualityModel(Quality.HDTV720p), + Path = @"C:\Test\Series.Title.S01E01.720p.HDTV.x264-EVOLVE.mkv" + }; + + var sampleResource = new NamingSampleResource(); + + sampleResource.SingleEpisodeExample = _buildFileNames.BuildFilename(new List { episode1 }, + series, + episodeFile, + nameSpec); + + episodeFile.Path = @"C:\Test\Series.Title.S01E01-E02.720p.HDTV.x264-EVOLVE.mkv"; + + sampleResource.MultiEpisodeExample = _buildFileNames.BuildFilename(new List { episode1, episode2 }, + series, + episodeFile, + nameSpec); + + return sampleResource.AsResponse(); } } } \ No newline at end of file diff --git a/NzbDrone.Api/Naming/NamingResource.cs b/NzbDrone.Api/Config/NamingSampleResource.cs similarity index 52% rename from NzbDrone.Api/Naming/NamingResource.cs rename to NzbDrone.Api/Config/NamingSampleResource.cs index 4cffb1d57..60fba0b3c 100644 --- a/NzbDrone.Api/Naming/NamingResource.cs +++ b/NzbDrone.Api/Config/NamingSampleResource.cs @@ -1,8 +1,6 @@ -using NzbDrone.Api.Config; - -namespace NzbDrone.Api.Naming +namespace NzbDrone.Api.Config { - public class NamingResource : NamingConfigResource + public class NamingSampleResource { public string SingleEpisodeExample { get; set; } public string MultiEpisodeExample { get; set; } diff --git a/NzbDrone.Api/EpisodeFiles/EpisodeFileModule.cs b/NzbDrone.Api/EpisodeFiles/EpisodeFileModule.cs index cfb062866..15b4e65ed 100644 --- a/NzbDrone.Api/EpisodeFiles/EpisodeFileModule.cs +++ b/NzbDrone.Api/EpisodeFiles/EpisodeFileModule.cs @@ -1,10 +1,7 @@ using System.Collections.Generic; using NzbDrone.Api.REST; using NzbDrone.Core.MediaFiles; -using NzbDrone.Core.Tv; -using NzbDrone.Api.Extensions; -using System.Linq; -using Omu.ValueInjecter; +using NzbDrone.Api.Mapping; namespace NzbDrone.Api.EpisodeFiles { @@ -23,7 +20,7 @@ namespace NzbDrone.Api.EpisodeFiles private EpisodeFileResource GetEpisodeFile(int id) { - return ToResource(() => _mediaFileService.Get(id)); + return _mediaFileService.Get(id).InjectTo(); } private List GetEpisodeFiles() @@ -38,15 +35,11 @@ namespace NzbDrone.Api.EpisodeFiles return ToListResource(() => _mediaFileService.GetFilesBySeries(seriesId.Value)); } - private EpisodeFileResource SetQuality(EpisodeFileResource episodeFileResource) + private void SetQuality(EpisodeFileResource episodeFileResource) { var episodeFile = _mediaFileService.Get(episodeFileResource.Id); episodeFile.Quality = episodeFileResource.Quality; - _mediaFileService.Update(episodeFile); - episodeFileResource.InjectFrom(episodeFile); - - return episodeFileResource; } } } \ No newline at end of file diff --git a/NzbDrone.Api/Episodes/EpisodeModule.cs b/NzbDrone.Api/Episodes/EpisodeModule.cs index 7ead10be9..94874f57a 100644 --- a/NzbDrone.Api/Episodes/EpisodeModule.cs +++ b/NzbDrone.Api/Episodes/EpisodeModule.cs @@ -1,9 +1,6 @@ using System.Collections.Generic; using NzbDrone.Api.REST; -using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; -using NzbDrone.Api.Extensions; -using System.Linq; namespace NzbDrone.Api.Episodes { @@ -32,11 +29,9 @@ namespace NzbDrone.Api.Episodes return ToListResource(() => _episodeService.GetEpisodeBySeries(seriesId.Value)); } - private EpisodeResource SetMonitored(EpisodeResource episodeResource) + private void SetMonitored(EpisodeResource episodeResource) { _episodeService.SetEpisodeMonitored(episodeResource.Id, episodeResource.Monitored); - - return episodeResource; } } } \ No newline at end of file diff --git a/NzbDrone.Api/Frontend/StaticResourceModule.cs b/NzbDrone.Api/Frontend/StaticResourceModule.cs index a988ce3de..3c7542075 100644 --- a/NzbDrone.Api/Frontend/StaticResourceModule.cs +++ b/NzbDrone.Api/Frontend/StaticResourceModule.cs @@ -31,7 +31,7 @@ namespace NzbDrone.Api.Frontend path.StartsWith("/api", StringComparison.CurrentCultureIgnoreCase) || path.StartsWith("/signalr", StringComparison.CurrentCultureIgnoreCase)) { - return null; + return new NotFoundResponse(); } var mapper = _requestMappers.SingleOrDefault(m => m.CanHandle(path)); @@ -44,7 +44,7 @@ namespace NzbDrone.Api.Frontend _logger.Warn("Couldn't find handler for {0}", path); - return null; + return new NotFoundResponse(); } } } \ No newline at end of file diff --git a/NzbDrone.Api/Indexers/IndexerModule.cs b/NzbDrone.Api/Indexers/IndexerModule.cs index 08fc8518a..387b481b7 100644 --- a/NzbDrone.Api/Indexers/IndexerModule.cs +++ b/NzbDrone.Api/Indexers/IndexerModule.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using NzbDrone.Api.ClientSchema; -using NzbDrone.Api.Mapping; using NzbDrone.Api.REST; using NzbDrone.Core.Indexers; using Omu.ValueInjecter; @@ -47,18 +46,14 @@ namespace NzbDrone.Api.Indexers return result; } - private IndexerResource CreateIndexer(IndexerResource indexerResource) + private int CreateIndexer(IndexerResource indexerResource) { var indexer = GetIndexer(indexerResource); indexer = _indexerService.Create(indexer); - - var response = indexer.InjectTo(); - response.Fields = SchemaBuilder.GenerateSchema(indexer.Settings); - - return response; + return indexer.Id; } - private IndexerResource UpdateIndexer(IndexerResource indexerResource) + private void UpdateIndexer(IndexerResource indexerResource) { var indexer = _indexerService.Get(indexerResource.Id); indexer.InjectFrom(indexerResource); @@ -66,12 +61,7 @@ namespace NzbDrone.Api.Indexers ValidateIndexer(indexer); - indexer = _indexerService.Update(indexer); - - var response = indexer.InjectTo(); - response.Fields = SchemaBuilder.GenerateSchema(indexer.Settings); - - return response; + _indexerService.Update(indexer); } diff --git a/NzbDrone.Api/Indexers/ReleaseModule.cs b/NzbDrone.Api/Indexers/ReleaseModule.cs index a96ffe130..aaf452261 100644 --- a/NzbDrone.Api/Indexers/ReleaseModule.cs +++ b/NzbDrone.Api/Indexers/ReleaseModule.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Nancy; using NzbDrone.Api.Mapping; using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.Download; @@ -8,6 +9,8 @@ using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; using Omu.ValueInjecter; using System.Linq; +using Nancy.ModelBinding; +using NzbDrone.Api.Extensions; namespace NzbDrone.Api.Indexers { @@ -31,17 +34,17 @@ namespace NzbDrone.Api.Indexers _downloadService = downloadService; _parsingService = parsingService; GetResourceAll = GetReleases; - CreateResource = DownloadRelease; + Post["/"] = x=> DownloadRelease(this.Bind()); } - private ReleaseResource DownloadRelease(ReleaseResource release) + private Response DownloadRelease(ReleaseResource release) { var remoteEpisode = _parsingService.Map(release.InjectTo(), 0); remoteEpisode.Report = release.InjectTo(); _downloadService.DownloadReport(remoteEpisode); - return release; + return release.AsResponse(); } private List GetReleases() diff --git a/NzbDrone.Api/Naming/NamingModule.cs b/NzbDrone.Api/Naming/NamingModule.cs deleted file mode 100644 index f97f9f19b..000000000 --- a/NzbDrone.Api/Naming/NamingModule.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Collections.Generic; -using NzbDrone.Api.Commands; -using NzbDrone.Api.Extensions; -using NzbDrone.Common.Messaging; -using NzbDrone.Core.MediaFiles; -using NzbDrone.Core.Organizer; -using NzbDrone.Core.Qualities; -using NzbDrone.Core.Tv; -using Omu.ValueInjecter; - -namespace NzbDrone.Api.Naming -{ - public class NamingModule : NzbDroneRestModule - { - private readonly IBuildFileNames _buildFileNames; - - public NamingModule(IBuildFileNames buildFileNames) - :base("naming") - { - _buildFileNames = buildFileNames; - CreateResource = GetExamples; - } - - private NamingResource GetExamples(NamingResource resource) - { - var nameSpec = new NamingConfig(); - nameSpec.InjectFrom(resource); - - var series = new Core.Tv.Series - { - SeriesType = SeriesTypes.Standard, - Title = "Series Title" - }; - - var episode1 = new Episode - { - SeasonNumber = 1, - EpisodeNumber = 1, - Title = "Episode Title (1)" - }; - - var episode2 = new Episode - { - SeasonNumber = 1, - EpisodeNumber = 2, - Title = "Episode Title (2)" - }; - - var episodeFile = new EpisodeFile - { - Quality = new QualityModel(Quality.HDTV720p), - Path = @"C:\Test\Series.Title.S01E01.720p.HDTV.x264-EVOLVE.mkv" - }; - - resource.SingleEpisodeExample = _buildFileNames.BuildFilename(new List { episode1 }, - series, - episodeFile, - nameSpec); - - episodeFile.Path = @"C:\Test\Series.Title.S01E01-E02.720p.HDTV.x264-EVOLVE.mkv"; - - resource.MultiEpisodeExample = _buildFileNames.BuildFilename(new List { episode1, episode2 }, - series, - episodeFile, - nameSpec); - - return resource; - } - } -} \ No newline at end of file diff --git a/NzbDrone.Api/Notifications/NotificationModule.cs b/NzbDrone.Api/Notifications/NotificationModule.cs index 2279a8623..58ba9ed3e 100644 --- a/NzbDrone.Api/Notifications/NotificationModule.cs +++ b/NzbDrone.Api/Notifications/NotificationModule.cs @@ -42,29 +42,17 @@ namespace NzbDrone.Api.Notifications return result; } - private NotificationResource Create(NotificationResource notificationResource) + private int Create(NotificationResource notificationResource) { var notification = GetNotification(notificationResource); - - notification = _notificationService.Create(notification); - notificationResource.Id = notification.Id; - - var response = notification.InjectTo(); - response.Fields = SchemaBuilder.GenerateSchema(notification.Settings); - - return response; + return _notificationService.Create(notification).Id; } - private NotificationResource Update(NotificationResource notificationResource) + private void Update(NotificationResource notificationResource) { var notification = GetNotification(notificationResource); notification.Id = notificationResource.Id; - notification = _notificationService.Update(notification); - - var response = notification.InjectTo(); - response.Fields = SchemaBuilder.GenerateSchema(notification.Settings); - - return response; + _notificationService.Update(notification); } private void DeleteNotification(int id) diff --git a/NzbDrone.Api/NzbDrone.Api.csproj b/NzbDrone.Api/NzbDrone.Api.csproj index 23fdba9b4..5210ef0a6 100644 --- a/NzbDrone.Api/NzbDrone.Api.csproj +++ b/NzbDrone.Api/NzbDrone.Api.csproj @@ -122,8 +122,7 @@ - - + diff --git a/NzbDrone.Api/NzbDroneRestModule.cs b/NzbDrone.Api/NzbDroneRestModule.cs index b46857972..d8072c4b2 100644 --- a/NzbDrone.Api/NzbDroneRestModule.cs +++ b/NzbDrone.Api/NzbDroneRestModule.cs @@ -22,11 +22,11 @@ namespace NzbDrone.Api } - protected TResource ToResource(Func function, TResource resource) where TModel : ModelBase, new() + protected int GetNewId(Func function, TResource resource) where TModel : ModelBase, new() { var model = resource.InjectTo(); function(model); - return model.InjectTo(); + return model.Id; } protected List ToListResource(Func> function) where TModel : ModelBase, new() @@ -35,17 +35,6 @@ namespace NzbDrone.Api return modelList.InjectTo>(); } - protected TResource ToResource(Func function) where TModel : ModelBase, new() - { - var modelList = function(); - return modelList.InjectTo(); - } - - protected TResource ToResource(Func action, int id) where TModel : ModelBase, new() - { - var model = action(id); - return model.InjectTo(); - } protected PagingResource ApplyToPage(Func, PagingSpec> function, PagingSpec pagingSpec) where TModel : ModelBase, new() { diff --git a/NzbDrone.Api/Qualities/QualityProfileModule.cs b/NzbDrone.Api/Qualities/QualityProfileModule.cs index fd8c6dbd0..1ff4379a6 100644 --- a/NzbDrone.Api/Qualities/QualityProfileModule.cs +++ b/NzbDrone.Api/Qualities/QualityProfileModule.cs @@ -30,11 +30,11 @@ namespace NzbDrone.Api.Qualities DeleteResource = DeleteProfile; } - private QualityProfileResource Create(QualityProfileResource resource) + private int Create(QualityProfileResource resource) { var model = resource.InjectTo(); model = _qualityProfileService.Add(model); - return GetById(model.Id); + return model.Id; } private void DeleteProfile(int id) @@ -42,11 +42,10 @@ namespace NzbDrone.Api.Qualities _qualityProfileService.Delete(id); } - private QualityProfileResource Update(QualityProfileResource resource) + private void Update(QualityProfileResource resource) { var model = resource.InjectTo(); _qualityProfileService.Update(model); - return GetById(resource.Id); } private QualityProfileResource GetById(int id) diff --git a/NzbDrone.Api/Qualities/QualitySizeModule.cs b/NzbDrone.Api/Qualities/QualitySizeModule.cs index c5a66c5fd..27d3b329e 100644 --- a/NzbDrone.Api/Qualities/QualitySizeModule.cs +++ b/NzbDrone.Api/Qualities/QualitySizeModule.cs @@ -19,16 +19,15 @@ namespace NzbDrone.Api.Qualities UpdateResource = Update; } - private QualitySizeResource Update(QualitySizeResource resource) + private void Update(QualitySizeResource resource) { var model = resource.InjectTo(); _qualityTypeProvider.Update(model); - return GetById(resource.Id); } private QualitySizeResource GetById(int id) { - return ToResource(() => _qualityTypeProvider.Get(id)); + return _qualityTypeProvider.Get(id).InjectTo(); } private List GetAll() diff --git a/NzbDrone.Api/REST/RestModule.cs b/NzbDrone.Api/REST/RestModule.cs index 54562bfea..f232e40d6 100644 --- a/NzbDrone.Api/REST/RestModule.cs +++ b/NzbDrone.Api/REST/RestModule.cs @@ -19,8 +19,8 @@ namespace NzbDrone.Api.REST private Func> _getResourceAll; private Func, PagingResource> _getResourcePaged; private Func _getResourceSingle; - private Func _createResource; - private Func _updateResource; + private Func _createResource; + private Action _updateResource; protected ResourceValidator PostValidator { get; private set; } protected ResourceValidator PutValidator { get; private set; } @@ -132,7 +132,7 @@ namespace NzbDrone.Api.REST } } - protected Func CreateResource + protected Func CreateResource { private get { return _createResource; } set @@ -140,36 +140,37 @@ namespace NzbDrone.Api.REST _createResource = value; Post[ROOT_ROUTE] = options => { - var resource = CreateResource(ReadFromRequest()); - return resource.AsResponse(HttpStatusCode.Created); + var id = CreateResource(ReadResourceFromRequest()); + return GetResourceById(id).AsResponse(HttpStatusCode.Created); }; } } - protected Func UpdateResource + protected Action UpdateResource { private get { return _updateResource; } set { _updateResource = value; Put[ROOT_ROUTE] = options => - { - var resource = UpdateResource(ReadFromRequest()); - return resource.AsResponse(HttpStatusCode.Accepted); - }; + { + var resource = ReadResourceFromRequest(); + UpdateResource(resource); + return GetResourceById(resource.Id).AsResponse(HttpStatusCode.Accepted); + }; Put[ID_ROUTE] = options => { - var model = ReadFromRequest(); - model.Id = options.Id; - var resource = UpdateResource(model); - return resource.AsResponse(HttpStatusCode.Accepted); + var resource = ReadResourceFromRequest(); + resource.Id = options.Id; + UpdateResource(resource); + return GetResourceById(resource.Id).AsResponse(HttpStatusCode.Accepted); }; } } - private TResource ReadFromRequest() + protected TResource ReadResourceFromRequest() { //TODO: handle when request is null var resource = Request.Body.FromJson(); diff --git a/NzbDrone.Api/RootFolders/RootFolderModule.cs b/NzbDrone.Api/RootFolders/RootFolderModule.cs index f160570ff..bb68ef289 100644 --- a/NzbDrone.Api/RootFolders/RootFolderModule.cs +++ b/NzbDrone.Api/RootFolders/RootFolderModule.cs @@ -16,9 +16,9 @@ namespace NzbDrone.Api.RootFolders DeleteResource = DeleteFolder; } - private RootFolderResource CreateRootFolder(RootFolderResource rootFolderResource) + private int CreateRootFolder(RootFolderResource rootFolderResource) { - return ToResource(_rootFolderService.Add, rootFolderResource); + return GetNewId(_rootFolderService.Add, rootFolderResource); } private List GetRootFolders() diff --git a/NzbDrone.Api/Seasons/SeasonModule.cs b/NzbDrone.Api/Seasons/SeasonModule.cs index cd68b2881..8c6bf7d8b 100644 --- a/NzbDrone.Api/Seasons/SeasonModule.cs +++ b/NzbDrone.Api/Seasons/SeasonModule.cs @@ -13,7 +13,7 @@ namespace NzbDrone.Api.Seasons _seasonService = seasonService; GetResourceAll = GetSeasons; - UpdateResource = SetMonitored; + UpdateResource = Update; Post["/pass"] = x => SetSeasonPass(); } @@ -27,14 +27,12 @@ namespace NzbDrone.Api.Seasons return ToListResource(() => _seasonService.GetSeasonsBySeries(seriesId)); } - return ToListResource(() => _seasonService.GetAllSeasons()); + return ToListResource(() => _seasonService.GetAllSeasons()); } - private SeasonResource SetMonitored(SeasonResource seasonResource) + private void Update(SeasonResource seasonResource) { _seasonService.SetMonitored(seasonResource.SeriesId, seasonResource.SeasonNumber, seasonResource.Monitored); - - return seasonResource; } private List SetSeasonPass() diff --git a/NzbDrone.Api/Series/SeriesModule.cs b/NzbDrone.Api/Series/SeriesModule.cs index 4aead6dc9..57caeb7a6 100644 --- a/NzbDrone.Api/Series/SeriesModule.cs +++ b/NzbDrone.Api/Series/SeriesModule.cs @@ -66,18 +66,14 @@ namespace NzbDrone.Api.Series return seriesResources; } - private SeriesResource AddSeries(SeriesResource seriesResource) + private int AddSeries(SeriesResource seriesResource) { - return ToResource(_seriesService.AddSeries, seriesResource); + return GetNewId(_seriesService.AddSeries, seriesResource); } - private SeriesResource UpdateSeries(SeriesResource seriesResource) + private void UpdateSeries(SeriesResource seriesResource) { - var resource = ToResource(_seriesService.UpdateSeries, seriesResource); - MapCoversToLocal(resource); - FetchAndLinkSeriesStatistics(resource); - - return resource; + GetNewId(_seriesService.UpdateSeries, seriesResource); } private void DeleteSeries(int id) diff --git a/UI/Settings/MediaManagement/Naming/Model.js b/UI/Settings/MediaManagement/Naming/Model.js index 3897989d2..cb8028556 100644 --- a/UI/Settings/MediaManagement/Naming/Model.js +++ b/UI/Settings/MediaManagement/Naming/Model.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict'; define( [ 'Settings/SettingsModelBase' diff --git a/UI/Settings/MediaManagement/Naming/View.js b/UI/Settings/MediaManagement/Naming/View.js index 87f299522..d33b0bbc0 100644 --- a/UI/Settings/MediaManagement/Naming/View.js +++ b/UI/Settings/MediaManagement/Naming/View.js @@ -19,13 +19,13 @@ define( 'change .x-rename-episodes': '_setNamingOptionsVisibility' }, - onRender: function(){ - if(!this.model.get('renameEpisodes')){ + onRender: function () { + if (!this.model.get('renameEpisodes')) { this.ui.namingOptions.hide(); } - this.listenTo(this.model, 'change', this._buildExamples); - this._buildExamples(); + this.listenTo(this.model, 'change', this._updateExamples); + this._updateExamples(); }, _setNamingOptionsVisibility: function () { @@ -39,16 +39,14 @@ define( } }, - _buildExamples: function () { - var self = this; + _updateExamples: function () { - var data = this.model.toJSON(); - data.id = 0; + var self = this; var promise = $.ajax({ - type: 'POST', - url : window.ApiRoot + '/naming', - data: JSON.stringify(data) + type: 'GET', + url : window.ApiRoot + '/config/naming/samples', + data: this.model.toJSON() }); promise.done(function (result) {