From 56da824e98654edb4881d4ea75e5fbf1140c1d63 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 27 Jan 2016 19:23:22 -0800 Subject: [PATCH] AutoComplete and file browser will show files when appropriate Fixed: File browser for Custom Script shows files Closes #1084 --- .../Annotations/FieldDefinitionAttribute.cs | 1 + .../CustomScript/CustomScriptSettings.cs | 2 +- src/UI/.idea/misc.xml | 1 - src/UI/Form/FormBuilder.js | 3 +-- src/UI/Form/PathTemplate.hbs | 2 +- src/UI/Mixins/AutoComplete.js | 2 +- src/UI/Mixins/DirectoryAutoComplete.js | 11 +++++++++-- src/UI/Mixins/FileBrowser.js | 5 +++-- 8 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/NzbDrone.Core/Annotations/FieldDefinitionAttribute.cs b/src/NzbDrone.Core/Annotations/FieldDefinitionAttribute.cs index 4e897ce68..5181ee68d 100644 --- a/src/NzbDrone.Core/Annotations/FieldDefinitionAttribute.cs +++ b/src/NzbDrone.Core/Annotations/FieldDefinitionAttribute.cs @@ -26,6 +26,7 @@ namespace NzbDrone.Core.Annotations Checkbox, Select, Path, + FilePath, Hidden, Tag, Action, diff --git a/src/NzbDrone.Core/Notifications/CustomScript/CustomScriptSettings.cs b/src/NzbDrone.Core/Notifications/CustomScript/CustomScriptSettings.cs index 4227a10fb..998fcd187 100644 --- a/src/NzbDrone.Core/Notifications/CustomScript/CustomScriptSettings.cs +++ b/src/NzbDrone.Core/Notifications/CustomScript/CustomScriptSettings.cs @@ -19,7 +19,7 @@ namespace NzbDrone.Core.Notifications.CustomScript { private static readonly CustomScriptSettingsValidator Validator = new CustomScriptSettingsValidator(); - [FieldDefinition(0, Label = "Path", Type = FieldType.Path)] + [FieldDefinition(0, Label = "Path", Type = FieldType.FilePath)] public string Path { get; set; } [FieldDefinition(1, Label = "Arguments", HelpText = "Arguments to pass to the script")] diff --git a/src/UI/.idea/misc.xml b/src/UI/.idea/misc.xml index 3e64709c0..e9e9ba1c3 100644 --- a/src/UI/.idea/misc.xml +++ b/src/UI/.idea/misc.xml @@ -3,5 +3,4 @@ - \ No newline at end of file diff --git a/src/UI/Form/FormBuilder.js b/src/UI/Form/FormBuilder.js index 53700b614..0a47a26b6 100644 --- a/src/UI/Form/FormBuilder.js +++ b/src/UI/Form/FormBuilder.js @@ -37,7 +37,7 @@ var _fieldBuilder = function(field) { return _templateRenderer.call(field, 'Form/HiddenTemplate'); } - if (field.type === 'path') { + if (field.type === 'path' || field.type === 'filepath') { return _templateRenderer.call(field, 'Form/PathTemplate'); } @@ -49,7 +49,6 @@ var _fieldBuilder = function(field) { return _templateRenderer.call(field, 'Form/ActionTemplate'); } - return _templateRenderer.call(field, 'Form/TextboxTemplate'); }; diff --git a/src/UI/Form/PathTemplate.hbs b/src/UI/Form/PathTemplate.hbs index 1bdeba6d4..5a95305e1 100644 --- a/src/UI/Form/PathTemplate.hbs +++ b/src/UI/Form/PathTemplate.hbs @@ -2,7 +2,7 @@
- +
{{> FormHelpPartial}} diff --git a/src/UI/Mixins/AutoComplete.js b/src/UI/Mixins/AutoComplete.js index 4d1a5ad3b..f0499d373 100644 --- a/src/UI/Mixins/AutoComplete.js +++ b/src/UI/Mixins/AutoComplete.js @@ -23,7 +23,7 @@ $.fn.autoComplete = function(options) { name : options.resource.replace('/'), displayKey : '', source : function(filter, callback) { - var data = {}; + var data = options.data || {}; data[options.query] = filter; $.ajax({ url : window.NzbDrone.ApiRoot + options.resource, diff --git a/src/UI/Mixins/DirectoryAutoComplete.js b/src/UI/Mixins/DirectoryAutoComplete.js index 9e9d606e7..f18ed35de 100644 --- a/src/UI/Mixins/DirectoryAutoComplete.js +++ b/src/UI/Mixins/DirectoryAutoComplete.js @@ -1,16 +1,23 @@ var $ = require('jquery'); require('./AutoComplete'); -$.fn.directoryAutoComplete = function() { +$.fn.directoryAutoComplete = function(options) { + options = options || {}; + var query = 'path'; + var data = { + includeFiles: options.includeFiles || false + }; $(this).autoComplete({ resource : '/filesystem', query : query, + data : data, filter : function(filter, response, callback) { var matches = []; + var results = response.directories.concat(response.files); - $.each(response.directories, function(i, d) { + $.each(results, function(i, d) { if (d[query] && d[query].startsWith(filter)) { matches.push({ value : d[query] }); } diff --git a/src/UI/Mixins/FileBrowser.js b/src/UI/Mixins/FileBrowser.js index d194038f9..ddcbefabf 100644 --- a/src/UI/Mixins/FileBrowser.js +++ b/src/UI/Mixins/FileBrowser.js @@ -8,7 +8,7 @@ $.fn.fileBrowser = function(options) { inputs.each(function() { var input = $(this); - var inputOptions = $.extend({ input : input }, options); + var inputOptions = $.extend({ input : input, showFiles: input.hasClass('x-filepath') }, options); var inputGroup = $('
'); var inputGroupButton = $(''); @@ -25,7 +25,8 @@ $.fn.fileBrowser = function(options) { button.on('click', function() { vent.trigger(vent.Commands.ShowFileBrowser, inputOptions); }); + + input.directoryAutoComplete({ includeFiles: inputOptions.showFiles }); }); - inputs.directoryAutoComplete(); };