Allow prev action on TelSelections search results

Stephen Paul Weber created

Change summary

lib/tel_selections.rb | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)

Detailed changes

lib/tel_selections.rb 🔗

@@ -49,14 +49,16 @@ class TelSelections
 		end
 
 		def choose_from_list(tns)
-			if tns.empty?
-				choose_tel(error: "No numbers found, try another search.")
-			else
-				Command.reply { |reply|
-					reply.allowed_actions = [:next]
-					reply.command << FormTemplate.render("tn_list", tns: tns)
-				}.then { |iq| iq.form.field("tel").value.to_s.strip }
-			end
+			raise "No numbers found, try another search." if tns.empty?
+
+			Command.reply { |reply|
+				reply.allowed_actions = [:next, :prev]
+				reply.command << FormTemplate.render("tn_list", tns: tns)
+			}.then { |iq|
+				next choose_tel if iq.prev?
+
+				iq.form.field("tel").value.to_s.strip
+			}
 		end
 
 		class AvailableNumber