When cloning an agent, focus on the name field

As a bonus, the number suffix part is pre-selected for easy removal.

Akinori MUSHA 10 anni fa
parent
commit
a434315be3
1 ha cambiato i file con 8 aggiunte e 0 eliminazioni
  1. 8 0
      app/assets/javascripts/pages/agent-edit-page.js.coffee

+ 8 - 0
app/assets/javascripts/pages/agent-edit-page.js.coffee

@@ -3,6 +3,14 @@ class @AgentEditPage
3 3
     $("#agent_source_ids").on "change", @showEventDescriptions
4 4
     @showCorrectRegionsOnStartup()
5 5
 
6
+    $("#agent_name").each ->
7
+      # Select the number suffix if this is a cloned agent.
8
+      if matches = this.value.match(/ \(\d+\)$/)
9
+        this.focus()
10
+        if this.selectionStart?
11
+          this.selectionStart = matches.index
12
+          this.selectionEnd = this.value.length
13
+
6 14
     # The type selector is only available on the new agent form.
7 15
     if $("#agent_type").length
8 16
       $("#agent_type").on "change", => @handleTypeChange(false)