Skip to content

Commit

Permalink
solved issue with multiple messages from Alert
Browse files Browse the repository at this point in the history
  • Loading branch information
grych committed Mar 16, 2017
1 parent 09be292 commit e9a2790
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
## 0.3.1

### New features:

* debugging Drab functions directly from `IEx` console
* display information when handler die, different for prod and dev


## 0.3.0

### API Changes and Depreciations:

* Drab.Query.select API changed: now `select(:val)` returns first value instead of the list, but all jQuery methods
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ end

```elixir
def deps do
[{:drab, "~> 0.3"}]
[{:drab, "~> 0.3.1"}]
end
```

Expand Down
8 changes: 0 additions & 8 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
## 0.3.1
Changes:
* display information when handler die (like error 500 page), different for prod and dev (Drab.Core)
* Drab.socket() returns current socket, so you can test Drab from iex console

## 0.4.0
Changes:

## Bugs:
* Drab.Modal returns some sizzle on the second run, and do not wait, when debugging - all wrong while debugging
* all debugging function return stuff ater drab.modal, check flush after launching any modal
* Ignoring unmatched topic "drab:/drab" in DrabPoc.UserSocket

## Future
Changes:
* *** use GenServer, Luke!
* rewrite Drab.Query - use meta, Luke!
* tests, tests, tests
* benchmarks
Expand Down
14 changes: 5 additions & 9 deletions lib/drab.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,12 @@ defmodule Drab do
When started with iex (`iex -S mix phoenix.server`) Drab shows the helpful message on how to debug its functions:
Started Drab for /drab, handling events in DrabPoc.PageCommander
You may debug Drab functions in IEx by copy/paste the following:
import Drab.Core
import Drab.Query
import Drab.Modal
import Drab.Waiter
Started Drab for /drab/docs, handling events in DrabPoc.DocsCommander
You may debug Drab functions in IEx by copy/paste the following:
import Drab.Core; import Drab.Query; import Drab.Modal; import Drab.Waiter
socket = GenServer.call(pid("0.413.0"), :get_socket)
socket = GenServer.call(pid("0.634.0"), :get_socket)
Examples:
Examples:
socket |> select(:htmls, from: "h4")
socket |> execjs("alert('hello from IEx!')")
socket |> alert("Title", "Sure?", buttons: [ok: "Azaliż", cancel: "Poniechaj"])
Expand Down
8 changes: 4 additions & 4 deletions lib/drab/channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ defmodule Drab.Channel do
pid_string = Regex.named_captures(~r/#PID<(?<pid>.*)>/, p) |> Map.get("pid")
Logger.debug """
Started Drab for #{socket.assigns.__url_path}, handling events in #{inspect(commander)}
You may debug Drab functions in IEx by copy/paste the following:
#{Enum.map(modules, fn module -> "import #{inspect(module)}" end) |> Enum.join("\n")}
Started Drab for #{socket.assigns.__url_path}, handling events in #{inspect(commander)}
You may debug Drab functions in IEx by copy/paste the following:
#{Enum.map(modules, fn module -> "import #{inspect(module)}" end) |> Enum.join("; ")}
socket = GenServer.call(pid("#{pid_string}"), :get_socket)
Examples:
Examples:
socket |> select(:htmls, from: "h4")
socket |> execjs("alert('hello from IEx!')")
socket |> alert("Title", "Sure?", buttons: [ok: "Azaliż", cancel: "Poniechaj"])
Expand Down
10 changes: 7 additions & 3 deletions priv/templates/drab/drab.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ Drab.on_connect(function(resp, drab) {
drab.channel.on("modal", function(message) {
$modal = $(MODAL)
$(MODAL_FORM).on("submit", function() {
$(MODAL).data("clicked", true) // prevents double send
modal_button_clicked(message, "ok")
return false // prevent submit
})
$(MODAL_BUTTONS).on("click", function() {
$(this).data("clicked", true)
$(MODAL).data("clicked", true)
modal_button_clicked(message, $(this).attr("name"))
})
$modal.on("hidden.bs.modal", function() {
if (!$(MODAL_BUTTON_OK).data("clicked")) {
clearTimeout(drab.modal_timeout_function)
if (!$(MODAL).data("clicked")) {
// if it is not an OK button (prevent double send)
modal_button_clicked(message, "cancel")
}
Expand All @@ -46,10 +48,12 @@ Drab.on_connect(function(resp, drab) {
clearTimeout(drab.modal_timeout_function)
}
drab.modal_timeout_function = setTimeout(function() {
$(MODAL).data("clicked", true) // prevents double send
modal_button_clicked(message, "cancel")
}, message.timeout)
}
// set focus on form

// set focus on the form
$modal.on("shown.bs.modal", function() {
$(MODAL_FORM + " :input").first().focus()
})
Expand Down

0 comments on commit e9a2790

Please sign in to comment.