factor out onclick javascript

This commit is contained in:
Joey Hess 2012-08-08 17:07:38 -04:00
parent 94fcd0cf59
commit 09449792fa
6 changed files with 16 additions and 11 deletions

View file

@ -165,3 +165,11 @@ webAppFormAuthToken :: Widget
webAppFormAuthToken = do webAppFormAuthToken = do
webapp <- lift getYesod webapp <- lift getYesod
[whamlet|<input type="hidden" name="auth" value="#{secretToken webapp}">|] [whamlet|<input type="hidden" name="auth" value="#{secretToken webapp}">|]
{- A button with an icon, and maybe label, that can be clicked to perform
- some action.
- With javascript, clicking it POSTs the Route, and remains on the same
- page.
- With noscript, clicking it GETs the Route. -}
actionButton :: Route WebApp -> (Maybe String) -> String -> String -> Widget
actionButton route label buttonclass iconclass = $(widgetFile "actionbutton")

View file

@ -53,7 +53,6 @@ sideBarDisplay = do
addalert :: AlertId -> Bool -> Bool -> Text -> Maybe Text -> Text -> Maybe String -> Widget addalert :: AlertId -> Bool -> Bool -> Text -> Maybe Text -> Text -> Maybe String -> Widget
addalert i closable block divclass heading message icon = do addalert i closable block divclass heading message icon = do
let alertid = show i let alertid = show i
let closealert = CloseAlert i
$(widgetFile "sidebar/alert") $(widgetFile "sidebar/alert")
{- Called by client to get a sidebar display. {- Called by client to get a sidebar display.

View file

@ -0,0 +1,2 @@
<a class="#{buttonclass}" href="@{route}" onclick="(function( $ ) { $.post('@{route}'); })( jQuery ); return false;">
<i class="#{iconclass}"></i> #{fromMaybe "" label}

View file

@ -28,10 +28,7 @@
<div .bar style="width: #{percent};"> <div .bar style="width: #{percent};">
<div .btn-group .span2> <div .btn-group .span2>
$if isNothing (startedTime info) $if isNothing (startedTime info)
<a .btn href="@{StartTransferR transfer}" onclick="(function( $ ) { $.post('@{StartTransferR transfer}'); })( jQuery ); return false;"> ^{actionButton (StartTransferR transfer) Nothing "btn" "icon-play"}
<i .icon-play title="start"></i>
$else $else
<a .btn href="@{PauseTransferR transfer}" onclick="(function( $ ) { $.post('@{PauseTransferR transfer}'); })( jQuery ); return false;"> ^{actionButton (PauseTransferR transfer) Nothing "btn" "icon-pause"}
<i .icon-pause title="pause"></i> ^{actionButton (CancelTransferR transfer) Nothing "btn" "icon-remove"}
<a .btn href="@{CancelTransferR transfer}" onclick="(function( $ ) { $.post('@{CancelTransferR transfer}'); })( jQuery ); return false;">
<i .icon-remove title="cancel"></i>

View file

@ -10,8 +10,7 @@
$maybe reldir <- relDir webapp $maybe reldir <- relDir webapp
<ul .nav .pull-right> <ul .nav .pull-right>
<li> <li>
<a href="@{FileBrowserR}" onclick="(function( $ ) { $.post('@{FileBrowserR}'); })( jQuery ); return false;"> ^{actionButton FileBrowserR (Just "Files") "" "icon-folder-open icon-white"}
<i .icon-folder-open .icon-white></i> Files
<li .dropdown #menu1> <li .dropdown #menu1>
<a .dropdown-toggle data-toggle="dropdown" href="#menu1"> <a .dropdown-toggle data-toggle="dropdown" href="#menu1">
Current Repository: #{reldir} Current Repository: #{reldir}

View file

@ -1,6 +1,6 @@
<div .alert .fade .in .#{divclass} :block:.alert-block ##{alertid} :closable:onclick="(function( $ ) { $.get('@{closealert}') })( jQuery );"> <div .alert .fade .in .#{divclass} :block:.alert-block ##{alertid} :closable:onclick="(function( $ ) { $.get('@{CloseAlert i}') })( jQuery );">
$if closable $if closable
<a .close data-dismiss="alert">&times;</a> <a .close>&times;</a>
$maybe h <- heading $maybe h <- heading
$if block $if block
<h4 .alert-heading> <h4 .alert-heading>