Commit a9a54979150f02690784cbea5d9b697b95249f7c

Authored by Cyril
1 parent c177593e

refactor flash

* make unobtrusive js
* convert js to coffee
app/assets/javascripts/main.js.coffee
@@ -33,6 +33,11 @@ $ -> @@ -33,6 +33,11 @@ $ ->
33 # Bottom tooltip 33 # Bottom tooltip
34 $('.has_bottom_tooltip').tooltip(placement: 'bottom') 34 $('.has_bottom_tooltip').tooltip(placement: 'bottom')
35 35
  36 + # Flash
  37 + if (flash = $("#flash-container")).length > 0
  38 + flash.click -> $(@).slideUp("slow")
  39 + flash.slideDown "slow"
  40 + setTimeout (-> flash.slideUp("slow")), 3000
36 41
37 # Disable form buttons while a form is submitting 42 # Disable form buttons while a form is submitting
38 $('body').on 'ajax:complete, ajax:beforeSend, submit', 'form', (e) -> 43 $('body').on 'ajax:complete, ajax:beforeSend, submit', 'form', (e) ->
app/assets/stylesheets/common.scss
@@ -68,7 +68,7 @@ table a code { @@ -68,7 +68,7 @@ table a code {
68 } 68 }
69 69
70 /** FLASH message **/ 70 /** FLASH message **/
71 -#flash_container { 71 +#flash-container {
72 height: 50px; 72 height: 50px;
73 position: fixed; 73 position: fixed;
74 z-index: 10001; 74 z-index: 10001;
@@ -79,6 +79,8 @@ table a code { @@ -79,6 +79,8 @@ table a code {
79 background: white; 79 background: white;
80 cursor: pointer; 80 cursor: pointer;
81 border-bottom: 1px solid #ccc; 81 border-bottom: 1px solid #ccc;
  82 + text-align: center;
  83 + display: none;
82 84
83 h4 { 85 h4 {
84 color: #666; 86 color: #666;
app/views/layouts/_flash.html.haml
1 -- if alert || notice  
2 - - text = alert || notice  
3 - %div{style: "display:none", id: "flash_container"}  
4 - %center  
5 - %h4= text  
6 - :javascript  
7 - $(function(){  
8 - $("#flash_container").slideDown("slow");  
9 - $("#flash_container").click(function(){  
10 - $(this).slideUp("slow");  
11 - });  
12 - setTimeout("hideFlash()",3000);  
13 - });  
14 -  
15 - function hideFlash(){  
16 - $("#flash_container").slideUp("slow");  
17 - } 1 +- if text = alert || notice
  2 + #flash-container
  3 + %h4= text
app/views/layouts/devise.html.haml
@@ -2,5 +2,5 @@ @@ -2,5 +2,5 @@
2 %html{ lang: "en"} 2 %html{ lang: "en"}
3 = render "layouts/head" 3 = render "layouts/head"
4 %body.ui_basic.login-page 4 %body.ui_basic.login-page
5 - = render partial: "layouts/flash" 5 + = render "layouts/flash"
6 .container= yield 6 .container= yield