45 lines
1.6 KiB
CoffeeScript
45 lines
1.6 KiB
CoffeeScript
window.Qwaiter=
|
||
alert: (msg) ->
|
||
$('.modal').modal('hide')
|
||
template = @mustache('#alert-template', {title: 'Alert', message: msg, close: 'OK'})
|
||
$(template).modal()
|
||
false
|
||
confirm: (options) ->
|
||
options ||= {}
|
||
content = options.content || 'Are you sure?'
|
||
title = options.title || 'Confirm'
|
||
wrapper = $('<div class="modal"></div>')
|
||
if typeof(options.ok) == 'function'
|
||
callback_wrapper = ->
|
||
wrapper.modal('hide')
|
||
options.ok()
|
||
callback_cancel_wrapper = ->
|
||
wrapper.modal('hide')
|
||
options.cancel() if options.cancel
|
||
header = $('<div class="modal-header"></div>')
|
||
.append('<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>')
|
||
.append('<h3>'+title+'</h3>').appendTo(wrapper)
|
||
body = $('<div class="modal-body"></div>').append('<p>'+content+'</p>').appendTo(wrapper)
|
||
ok_button = $('<a href="#" class="btn btn-primary">Yes</a>')
|
||
if typeof(options.ok) == 'function'
|
||
ok_button.click(callback_wrapper)
|
||
else
|
||
ok_button.click ->
|
||
eval(options.ok)
|
||
wrapper.modal('hide')
|
||
footer = $('<div class="modal-footer"></div>')
|
||
.append($('<a href="#" class="btn">Close</a>').click(callback_cancel_wrapper))
|
||
.append(ok_button)
|
||
.appendTo(wrapper)
|
||
wrapper.modal()
|
||
currency: (num) ->
|
||
num = 0.0 if isNaN(num) || num == '' || num == null
|
||
'€ ' + parseFloat(num).toFixed(2)
|
||
mustache: (selector, locals)->
|
||
locs = $.extend(locals,
|
||
currency: ->
|
||
(val)->
|
||
currency(Mustache.render(val, this))
|
||
)
|
||
Mustache.to_html($(selector).html(), locs)
|