From b4dd0efc740b5dc53b3c3e70619387206cad139b Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Mon, 15 Jul 2013 13:25:47 -0400 Subject: [PATCH] Move describe() from narrow.js to search.js. (This function is only used in the search code.) (imported from commit 44d53fbd73be56d9d416ebcafdc517c686e7adf8) --- zephyr/static/js/narrow.js | 37 ---------------------------------- zephyr/static/js/search.js | 41 +++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/zephyr/static/js/narrow.js b/zephyr/static/js/narrow.js index fd3d89eecf..ec0f7ebbf9 100644 --- a/zephyr/static/js/narrow.js +++ b/zephyr/static/js/narrow.js @@ -248,43 +248,6 @@ function unparse(operators) { return parts.join(' '); } -// Convert a list of operators to a human-readable description. -exports.describe = function (operators) { - return $.map(operators, function (elem) { - var operand = elem[1]; - switch (elem[0]) { - case 'is': - if (operand === 'private') { - return 'Narrow to all private messages'; - } else if (operand === 'starred') { - return 'Narrow to starred messages'; - } else if (operand === 'mentioned') { - return 'Narrow to mentioned messages'; - } - break; - - case 'stream': - return 'Narrow to stream ' + operand; - - case 'subject': - return 'Narrow to subject ' + operand; - - case 'sender': - return 'Narrow to sender ' + operand; - - case 'pm-with': - return 'Narrow to private messages with ' + operand; - - case 'search': - return 'Search for ' + operand; - - case 'in': - return 'Narrow to messages in ' + operand; - } - return 'Narrow to (unknown operator)'; - }).join(', '); -}; - // Collect operators which appear only once into an object, // and discard those which appear more than once. function collect_single(operators) { diff --git a/zephyr/static/js/search.js b/zephyr/static/js/search.js index 6e5dfc2e24..07c07468ab 100644 --- a/zephyr/static/js/search.js +++ b/zephyr/static/js/search.js @@ -42,6 +42,44 @@ function stream_matches_query(stream_name, q) { return phrase_match(stream_name, q); } + +// Convert a list of operators to a human-readable description. +function describe(operators) { + return $.map(operators, function (elem) { + var operand = elem[1]; + switch (elem[0]) { + case 'is': + if (operand === 'private') { + return 'Narrow to all private messages'; + } else if (operand === 'starred') { + return 'Narrow to starred messages'; + } else if (operand === 'mentioned') { + return 'Narrow to mentioned messages'; + } + break; + + case 'stream': + return 'Narrow to stream ' + operand; + + case 'subject': + return 'Narrow to subject ' + operand; + + case 'sender': + return 'Narrow to sender ' + operand; + + case 'pm-with': + return 'Narrow to private messages with ' + operand; + + case 'search': + return 'Search for ' + operand; + + case 'in': + return 'Narrow to messages in ' + operand; + } + return 'Narrow to (unknown operator)'; + }).join(', '); +} + function render_object_in_parts(obj) { // N.B. action is *not* escaped by the caller switch (obj.action) { @@ -50,6 +88,7 @@ function render_object_in_parts(obj) { case 'private_message': return {prefix: 'Narrow to private messages with', + query: get_person(obj), suffix: ''}; @@ -64,7 +103,7 @@ function render_object_in_parts(obj) { // after 'Narrow to' ensures this, and is invisible with standard HTML // whitespace handling. return {prefix: '', - query: narrow.describe(obj.operators), + query: describe(obj.operators), suffix: ''}; } return {prefix: 'Error', query: 'Error', suffix: 'Error'};