From dca32e9e0fc1f9d172e4c9c3bea1d269d8785dac Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 30 May 2013 22:56:00 -0700 Subject: [PATCH] new quality profile edit view. --- .../Qualities/QualityProfileResource.cs | 2 +- .../Qualities/QualityProfilesModule.cs | 5 +- UI/Quality/qualityProfileModel.js | 1 - .../Profile/EditQualityProfileTemplate.html | 52 ++++++++----------- .../Quality/Profile/EditQualityProfileView.js | 42 ++++++++++++++- 5 files changed, 66 insertions(+), 36 deletions(-) diff --git a/NzbDrone.Api/Qualities/QualityProfileResource.cs b/NzbDrone.Api/Qualities/QualityProfileResource.cs index 8bb65bfaf..25e6a9108 100644 --- a/NzbDrone.Api/Qualities/QualityProfileResource.cs +++ b/NzbDrone.Api/Qualities/QualityProfileResource.cs @@ -8,7 +8,7 @@ namespace NzbDrone.Api.Qualities { public String Name { get; set; } public QualityResource Cutoff { get; set; } - public List Qualities { get; set; } + public List Available { get; set; } public List Allowed { get; set; } } diff --git a/NzbDrone.Api/Qualities/QualityProfilesModule.cs b/NzbDrone.Api/Qualities/QualityProfilesModule.cs index 30fe10c02..bf41ab48c 100644 --- a/NzbDrone.Api/Qualities/QualityProfilesModule.cs +++ b/NzbDrone.Api/Qualities/QualityProfilesModule.cs @@ -75,7 +75,10 @@ namespace NzbDrone.Api.Qualities return new QualityProfileResource { Cutoff = profile.Cutoff.InjectTo(), - Qualities = Quality.All().InjectTo>(), + Available = Quality.All() + .Where(c => !profile.Allowed.Any(q => c.Id == q.Id)) + .InjectTo>(), + Allowed = profile.Allowed.InjectTo>(), Name = profile.Name, Id = profile.Id diff --git a/UI/Quality/qualityProfileModel.js b/UI/Quality/qualityProfileModel.js index 82ffd40c3..50cf01cf1 100644 --- a/UI/Quality/qualityProfileModel.js +++ b/UI/Quality/qualityProfileModel.js @@ -5,7 +5,6 @@ define(['app'], function () { defaults: { id : null, name : '', - //'qualities.allowed': false, cutoff: null } }); diff --git a/UI/Settings/Quality/Profile/EditQualityProfileTemplate.html b/UI/Settings/Quality/Profile/EditQualityProfileTemplate.html index acd0d9368..e393b4624 100644 --- a/UI/Settings/Quality/Profile/EditQualityProfileTemplate.html +++ b/UI/Settings/Quality/Profile/EditQualityProfileTemplate.html @@ -1,13 +1,11 @@  \ No newline at end of file + diff --git a/UI/Settings/Quality/Profile/EditQualityProfileView.js b/UI/Settings/Quality/Profile/EditQualityProfileView.js index 34f3f3aa6..90b4ff5af 100644 --- a/UI/Settings/Quality/Profile/EditQualityProfileView.js +++ b/UI/Settings/Quality/Profile/EditQualityProfileView.js @@ -2,10 +2,48 @@ define(['app', 'Quality/QualityProfileModel'], function () { NzbDrone.Settings.Quality.Profile.EditQualityProfileView = Backbone.Marionette.ItemView.extend({ - template : 'Settings/Quality/Profile/EditQualityProfileTemplate', + template: 'Settings/Quality/Profile/EditQualityProfileTemplate', events: { - 'click .x-save': 'saveQualityProfile' + 'click .x-save' : 'saveQualityProfile', + 'dblclick .x-available-list': '_moveQuality', + 'dblclick .x-allowed-list' : '_moveQuality' + }, + + _moveQuality: function (event) { + + var quality; + var qualityId = event.target.value; + var availableCollection = new Backbone.Collection(this.model.get('available')); + availableCollection.comparator = function (model) { + return model.get('weight'); + }; + + var allowedCollection = new Backbone.Collection(this.model.get('allowed')); + allowedCollection.comparator = function (model) { + return model.get('weight'); + }; + + if (availableCollection.get(qualityId)) { + quality = availableCollection.get(qualityId); + availableCollection.remove(quality); + allowedCollection.add(quality); + } + else if (allowedCollection.get(qualityId)) { + quality = allowedCollection.get(qualityId); + + allowedCollection.remove(quality); + availableCollection.add(quality); + } + else { + throw 'couldnt find quality id ' + qualityId; + } + + + this.model.set('available', availableCollection.toJSON()); + this.model.set('allowed', allowedCollection.toJSON()); + + this.render(); }, saveQualityProfile: function () {