diff --git a/data/interfaces/default/newsletter_config.html b/data/interfaces/default/newsletter_config.html
index b8fb30c3..bc4da76c 100644
--- a/data/interfaces/default/newsletter_config.html
+++ b/data/interfaces/default/newsletter_config.html
@@ -1,14 +1,11 @@
% if newsletter:
<%!
import json
- from plexpy import helpers, notifiers, users
+ from plexpy import helpers, notifiers
email_notifiers = [n for n in notifiers.get_notifiers() if n['agent_name'] == 'email']
sorted(email_notifiers, key=lambda k: (k['agent_label'], k['friendly_name'], k['id']))
email_notifiers = [{'id': 0, 'agent_label': 'New Email Configuration', 'friendly_name': ''}] + email_notifiers
-
- user_emails = [{'user': u['friendly_name'] or u['username'], 'email': u['email']} for u in users.Users().get_users() if u['email']]
- sorted(user_emails, key=lambda u: u['user'])
%>
@@ -112,6 +109,33 @@
${item['description'] | n}
+ % elif item['input_type'] == 'selectize':
+
% endif
% endfor
@@ -228,6 +252,33 @@
${item['description'] | n}
+ % elif item['input_type'] == 'selectize':
+
% endif
% endfor
@@ -285,7 +336,27 @@
var $incl_libraries = $('#recently_added_incl_libraries').selectize({
plugins: ['remove_button'],
- maxItems: null
+ maxItems: null,
+ render: {
+ option: function(item) {
+ if (item.value.endsWith('-all')) {
+ return '' + item.text + '
'
+ }
+ return '' + item.text + '
';
+ }
+ },
+ onItemAdd: function(value) {
+ if (value === 'select-all') {
+ var all_keys = $.map(this.options, function(option){
+ return option.value.endsWith('-all') ? null : option.value;
+ });
+ this.setValue(all_keys);
+ } else if (value === 'remove-all') {
+ this.clear();
+ this.refreshOptions();
+ this.positionDropdown();
+ }
+ }
});
var incl_libraries = $incl_libraries[0].selectize;
incl_libraries.setValue(${json.dumps(next((c['value'] for c in newsletter['config_options'] if c['name'] == 'recently_added_incl_libraries'), [])) | n});
@@ -304,26 +375,37 @@
plugins: ['remove_button'],
persist: false,
maxItems: null,
- valueField: 'email',
- labelField: 'user',
- searchField: ['user', 'email'],
- options: ${json.dumps(user_emails) | n},
render: {
item: function(item, escape) {
return '' +
- (item.user ? '' + escape(item.user) + '' : '') +
- (item.email ? '' + escape(item.email) + '' : '') +
+ (item.text ? '' + escape(item.text) + '' : '') +
+ (item.value ? '' + escape(item.value) + '' : '') +
'
';
},
option: function(item, escape) {
- var label = item.user || item.email;
- var caption = item.user ? item.email : null;
+ var label = item.text || item.value;
+ var caption = item.text ? item.value : null;
+ if (item.value.endsWith('-all')) {
+ return '' + escape(label) + '
'
+ }
return '' +
escape(label) +
(caption ? '' + escape(caption) + '' : '') +
'
';
}
},
+ onItemAdd: function(value) {
+ if (value === 'select-all') {
+ var all_keys = $.map(this.options, function(option){
+ return option.value.endsWith('-all') ? null : option.value;
+ });
+ this.setValue(all_keys);
+ } else if (value === 'remove-all') {
+ this.clear();
+ this.refreshOptions();
+ this.positionDropdown();
+ }
+ },
createFilter: function(input) {
var match, regex;
@@ -341,16 +423,15 @@
},
create: function(input) {
if ((new RegExp('^' + REGEX_EMAIL + '$', 'i')).test(input)) {
- return {email: input};
+ return {value: input};
}
var match = input.match(new RegExp('^([^<]*)\<' + REGEX_EMAIL + '\>$', 'i'));
if (match) {
return {
- email : match[2],
- user : $.trim(match[1])
+ value : match[2],
+ text : $.trim(match[1])
};
}
- alert('Invalid email address.');
return false;
}
});
diff --git a/plexpy/newsletters.py b/plexpy/newsletters.py
index c9bb9501..5699b5a6 100644
--- a/plexpy/newsletters.py
+++ b/plexpy/newsletters.py
@@ -556,10 +556,17 @@ class RecentlyAdded(Newsletter):
return libraries.Libraries().get_sections()
def _get_sections_options(self):
- sections = {'': ''}
- for s in self._get_sections():
+ library_types = {'movie': 'Movie Libraries',
+ 'show': 'TV Show Libraries',
+ 'artist': 'Music Libraries'}
+ sections = {}
+ for s in sorted(self._get_sections(), key=lambda x: x['section_name']):
if s['section_type'] != 'photo':
- sections[s['section_id']] = s['section_name']
+ library_type = library_types[s['section_type']]
+ group = sections.get(library_type, [])
+ group.append({'value': s['section_id'],
+ 'text': s['section_name']})
+ sections[library_type] = group
return sections
def return_config_options(self):
@@ -573,7 +580,7 @@ class RecentlyAdded(Newsletter):
'value': self.config['incl_libraries'],
'description': 'Select the libraries to include in the newsletter.',
'name': 'recently_added_incl_libraries',
- 'input_type': 'select',
+ 'input_type': 'selectize',
'select_options': self._get_sections_options()
}
]