mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 15:56:07 -07:00
Add select/remove all for newsletter libraries
This commit is contained in:
parent
49a6cf8809
commit
0e5bb7b188
2 changed files with 109 additions and 21 deletions
|
@ -1,14 +1,11 @@
|
||||||
% if newsletter:
|
% if newsletter:
|
||||||
<%!
|
<%!
|
||||||
import json
|
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']
|
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']))
|
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
|
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'])
|
|
||||||
%>
|
%>
|
||||||
<div class="modal-dialog" role="document">
|
<div class="modal-dialog" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
|
@ -112,6 +109,33 @@
|
||||||
</div>
|
</div>
|
||||||
<p class="help-block">${item['description'] | n}</p>
|
<p class="help-block">${item['description'] | n}</p>
|
||||||
</div>
|
</div>
|
||||||
|
% elif item['input_type'] == 'selectize':
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="${item['name']}">${item['label']}</label>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<select class="form-control" id="${item['name']}" name="${item['name']}">
|
||||||
|
<option value="select-all">Select All</option>
|
||||||
|
<option value="remove-all">Remove All</option>
|
||||||
|
% if isinstance(item['select_options'], dict):
|
||||||
|
% for section, options in item['select_options'].iteritems():
|
||||||
|
<optgroup label="${section}">
|
||||||
|
% for option in options:
|
||||||
|
<option value="${option['value']}">${option['text']}</option>
|
||||||
|
% endfor
|
||||||
|
</optgroup>
|
||||||
|
% endfor
|
||||||
|
% else:
|
||||||
|
<option value="border-all"></option>
|
||||||
|
% for option in item['select_options']:
|
||||||
|
<option value="${option['value']}">${option['text']}</option>
|
||||||
|
% endfor
|
||||||
|
% endif
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="help-block">${item['description'] | n}</p>
|
||||||
|
</div>
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
</div>
|
</div>
|
||||||
|
@ -228,6 +252,33 @@
|
||||||
</div>
|
</div>
|
||||||
<p class="help-block">${item['description'] | n}</p>
|
<p class="help-block">${item['description'] | n}</p>
|
||||||
</div>
|
</div>
|
||||||
|
% elif item['input_type'] == 'selectize':
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="${item['name']}">${item['label']}</label>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<select class="form-control" id="${item['name']}" name="${item['name']}">
|
||||||
|
<option value="select-all">Select All</option>
|
||||||
|
<option value="remove-all">Remove All</option>
|
||||||
|
% if isinstance(item['select_options'], dict):
|
||||||
|
% for section, options in item['select_options'].iteritems():
|
||||||
|
<optgroup label="${section}">
|
||||||
|
% for option in options:
|
||||||
|
<option value="${option['value']}">${option['text']}</option>
|
||||||
|
% endfor
|
||||||
|
</optgroup>
|
||||||
|
% endfor
|
||||||
|
% else:
|
||||||
|
<option value="border-all"></option>
|
||||||
|
% for option in item['select_options']:
|
||||||
|
<option value="${option['value']}">${option['text']}</option>
|
||||||
|
% endfor
|
||||||
|
% endif
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="help-block">${item['description'] | n}</p>
|
||||||
|
</div>
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
<input type="hidden" id="email_html_support" name="email_html_support" value="1">
|
<input type="hidden" id="email_html_support" name="email_html_support" value="1">
|
||||||
|
@ -285,7 +336,27 @@
|
||||||
|
|
||||||
var $incl_libraries = $('#recently_added_incl_libraries').selectize({
|
var $incl_libraries = $('#recently_added_incl_libraries').selectize({
|
||||||
plugins: ['remove_button'],
|
plugins: ['remove_button'],
|
||||||
maxItems: null
|
maxItems: null,
|
||||||
|
render: {
|
||||||
|
option: function(item) {
|
||||||
|
if (item.value.endsWith('-all')) {
|
||||||
|
return '<div class="' + item.value + '">' + item.text + '</div>'
|
||||||
|
}
|
||||||
|
return '<div>' + item.text + '</div>';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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;
|
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});
|
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'],
|
plugins: ['remove_button'],
|
||||||
persist: false,
|
persist: false,
|
||||||
maxItems: null,
|
maxItems: null,
|
||||||
valueField: 'email',
|
|
||||||
labelField: 'user',
|
|
||||||
searchField: ['user', 'email'],
|
|
||||||
options: ${json.dumps(user_emails) | n},
|
|
||||||
render: {
|
render: {
|
||||||
item: function(item, escape) {
|
item: function(item, escape) {
|
||||||
return '<div>' +
|
return '<div>' +
|
||||||
(item.user ? '<span class="user">' + escape(item.user) + '</span>' : '') +
|
(item.text ? '<span class="item-text">' + escape(item.text) + '</span>' : '') +
|
||||||
(item.email ? '<span class="email">' + escape(item.email) + '</span>' : '') +
|
(item.value ? '<span class="item-value">' + escape(item.value) + '</span>' : '') +
|
||||||
'</div>';
|
'</div>';
|
||||||
},
|
},
|
||||||
option: function(item, escape) {
|
option: function(item, escape) {
|
||||||
var label = item.user || item.email;
|
var label = item.text || item.value;
|
||||||
var caption = item.user ? item.email : null;
|
var caption = item.text ? item.value : null;
|
||||||
|
if (item.value.endsWith('-all')) {
|
||||||
|
return '<div class="' + item.value + '">' + escape(label) + '</div>'
|
||||||
|
}
|
||||||
return '<div>' +
|
return '<div>' +
|
||||||
escape(label) +
|
escape(label) +
|
||||||
(caption ? '<span class="caption">' + escape(caption) + '</span>' : '') +
|
(caption ? '<span class="caption">' + escape(caption) + '</span>' : '') +
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
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) {
|
createFilter: function(input) {
|
||||||
var match, regex;
|
var match, regex;
|
||||||
|
|
||||||
|
@ -341,16 +423,15 @@
|
||||||
},
|
},
|
||||||
create: function(input) {
|
create: function(input) {
|
||||||
if ((new RegExp('^' + REGEX_EMAIL + '$', 'i')).test(input)) {
|
if ((new RegExp('^' + REGEX_EMAIL + '$', 'i')).test(input)) {
|
||||||
return {email: input};
|
return {value: input};
|
||||||
}
|
}
|
||||||
var match = input.match(new RegExp('^([^<]*)\<' + REGEX_EMAIL + '\>$', 'i'));
|
var match = input.match(new RegExp('^([^<]*)\<' + REGEX_EMAIL + '\>$', 'i'));
|
||||||
if (match) {
|
if (match) {
|
||||||
return {
|
return {
|
||||||
email : match[2],
|
value : match[2],
|
||||||
user : $.trim(match[1])
|
text : $.trim(match[1])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
alert('Invalid email address.');
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -556,10 +556,17 @@ class RecentlyAdded(Newsletter):
|
||||||
return libraries.Libraries().get_sections()
|
return libraries.Libraries().get_sections()
|
||||||
|
|
||||||
def _get_sections_options(self):
|
def _get_sections_options(self):
|
||||||
sections = {'': ''}
|
library_types = {'movie': 'Movie Libraries',
|
||||||
for s in self._get_sections():
|
'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':
|
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
|
return sections
|
||||||
|
|
||||||
def return_config_options(self):
|
def return_config_options(self):
|
||||||
|
@ -573,7 +580,7 @@ class RecentlyAdded(Newsletter):
|
||||||
'value': self.config['incl_libraries'],
|
'value': self.config['incl_libraries'],
|
||||||
'description': 'Select the libraries to include in the newsletter.',
|
'description': 'Select the libraries to include in the newsletter.',
|
||||||
'name': 'recently_added_incl_libraries',
|
'name': 'recently_added_incl_libraries',
|
||||||
'input_type': 'select',
|
'input_type': 'selectize',
|
||||||
'select_options': self._get_sections_options()
|
'select_options': self._get_sections_options()
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue