Prompt for the new filter name when only copying one.
This also reworks 'Pref_Filters' a bit so it's easier to retrieve filter titles.
This commit is contained in:
@@ -258,7 +258,7 @@ class Pref_Filters extends Handler_Protected {
|
||||
];
|
||||
|
||||
foreach ($filters as $filter) {
|
||||
$name = $this->_get_name($filter->id);
|
||||
$details = $this->_get_details($filter->id);
|
||||
|
||||
if ($filter_search &&
|
||||
mb_stripos($filter->title, $filter_search) === false &&
|
||||
@@ -273,8 +273,9 @@ class Pref_Filters extends Handler_Protected {
|
||||
$item = [
|
||||
'id' => 'FILTER:' . $filter->id,
|
||||
'bare_id' => $filter->id,
|
||||
'name' => $name[0],
|
||||
'param' => $name[1],
|
||||
'bare_name' => $details['title'],
|
||||
'name' => $details['title_summary'],
|
||||
'param' => $details['actions_summary'],
|
||||
'checkbox' => false,
|
||||
'last_triggered' => $filter->last_triggered ? TimeHelper::make_local_datetime($filter->last_triggered) : null,
|
||||
'enabled' => sql_bool_to_bool($filter->enabled),
|
||||
@@ -745,9 +746,9 @@ class Pref_Filters extends Handler_Protected {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
* @return array{'title': string, 'title_summary': string, 'actions_summary': string}
|
||||
*/
|
||||
private function _get_name(int $id): array {
|
||||
private function _get_details(int $id): array {
|
||||
|
||||
$filter = ORM::for_table("ttrss_filters2")
|
||||
->table_alias('f')
|
||||
@@ -763,10 +764,11 @@ class Pref_Filters extends Handler_Protected {
|
||||
->find_one();
|
||||
|
||||
if ($filter) {
|
||||
$title = $filter->title ?: __('[No caption]');
|
||||
$title_summary = [
|
||||
sprintf(
|
||||
_ngettext("%s (%d rule)", "%s (%d rules)", (int) $filter->num_rules),
|
||||
($filter->title ? $filter->title : __("[No caption]")),
|
||||
$title,
|
||||
$filter->num_rules)];
|
||||
|
||||
if ($filter->match_any_rule) array_push($title_summary, __("matches any rule"));
|
||||
@@ -805,7 +807,11 @@ class Pref_Filters extends Handler_Protected {
|
||||
"<li class='text-muted'><em>" . sprintf(_ngettext("(+%d action)", "(+%d actions)", $actions_not_shown), $actions_not_shown)) . "</em></li>";
|
||||
}
|
||||
|
||||
return [implode(", ", $title_summary), implode("", $actions_summary)];
|
||||
return [
|
||||
'title' => $title,
|
||||
'title_summary' => implode(', ', $title_summary),
|
||||
'actions_summary' => implode('', $actions_summary),
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
|
||||
@@ -171,13 +171,23 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
|
||||
const sel_rows = this.getSelectedFilters();
|
||||
|
||||
if (sel_rows.length > 0) {
|
||||
if (confirm(__("Copy selected filters?"))) {
|
||||
Notify.progress("Copying selected filters...");
|
||||
const query = {op: "Pref_Filters", method: "copy", ids: sel_rows.toString()};
|
||||
let proceed = false;
|
||||
|
||||
const query = {
|
||||
op: "Pref_Filters", method: "copy",
|
||||
ids: sel_rows.toString()
|
||||
};
|
||||
if (sel_rows.length === 1) {
|
||||
const selected_filter = this.model.getCheckedItems()[0];
|
||||
const new_title = prompt(__("Name for copied filter:"), 'Copy - ' + this.model.store.getValue(selected_filter, "bare_name"));
|
||||
|
||||
if (new_title) {
|
||||
query.new_title = new_title;
|
||||
proceed = true;
|
||||
}
|
||||
} else if (sel_rows.length > 1) {
|
||||
proceed = confirm(__("Copy selected filters?"));
|
||||
}
|
||||
|
||||
if (proceed) {
|
||||
Notify.progress("Copying selected filters...");
|
||||
|
||||
xhr.post("backend.php", query, () => {
|
||||
this.reload();
|
||||
|
||||
Reference in New Issue
Block a user