Skip to content

Commit

Permalink
Include search warnings about named searches.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Jul 29, 2023
1 parent 4a26241 commit 2c07d35
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
18 changes: 8 additions & 10 deletions scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -11641,29 +11641,27 @@ handle_ui.on("js-edit-namedsearches", function () {
$.post(hoturl("=api/namedsearch"),
$d.find("form").serialize(),
function (data) {
if (data.ok)
location.reload(true);
else
$d.show_errors(data);
data.ok ? location.reload(true) : $d.show_errors(data);
});
}
function create(searches) {
function create(data) {
var hc = popup_skeleton({className: "modal-dialog-w40 need-diff-check"}), i;
hc.push('<h2>Saved searches</h2>');
hc.push('<p>Invoke a saved search with “ss:NAME”. Saved searches are shared with the PC.</p>');
hc.push('<h2>Named searches</h2>');
hc.push('<p>Invoke a named search with “ss:NAME”. Named searches are shared with the PC.</p>');
hc.push('<div class="editsearches">', '</div>');
for (i in searches || []) {
push1(hc, searches[i]);
for (i in data.searches || []) {
push1(hc, data.searches[i]);
}
hc.pop_push('<button type="button" name="add">Add named search</button>');
hc.push_actions(['<button type="submit" name="savesearches" value="1" class="btn-primary">Save</button>', '<button type="button" name="cancel">Cancel</button>']);
$d = hc.show();
$d.on("click", "button", click);
$d.on("submit", "form", submit);
$d.show_errors(data);
}
$.get(hoturl("=api/namedsearch"), function (data) {
if (data.ok)
create(data.searches);
create(data);
});
});

Expand Down
11 changes: 10 additions & 1 deletion src/api/api_searchconfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ static function can_edit_search(Contact $user, $v) {

static function namedsearch(Contact $user, Qrequest $qreq) {
$fjs = [];
$ms = new MessageSet;
foreach ($user->conf->named_searches() as $sj) {
if (($sj->qt ?? "n") === "n" && ($sj->t ?? "s") === "s") {
$q = $sj->q;
Expand All @@ -219,11 +220,19 @@ static function namedsearch(Contact $user, Qrequest $qreq) {
$nsj["editable"] = true;
}
$fjs[] = $nsj;
$ps = new PaperSearch($user, $q);
foreach ($ps->message_list() as $mi) {
$ms->append_item_at("named_search/" . count($fjs) . "/q", $mi);
}
}
usort($fjs, function ($a, $b) {
return strnatcasecmp($a["name"], $b["name"]);
});
return new JsonResult(["ok" => true, "searches" => $fjs]);
$j = ["ok" => true, "searches" => $fjs];
if ($ms->has_message()) {
$j["message_list"] = $ms->message_list();
}
return new JsonResult($j);
}

static function save_namedsearch(Contact $user, Qrequest $qreq) {
Expand Down

0 comments on commit 2c07d35

Please sign in to comment.