Revision 1b63706d
Added by Benjamin Dauvergne over 12 years ago
calebasse/static/js/calebasse.dialog.js | ||
---|---|---|
1 |
(function ($) { |
|
2 |
$.fn.dialogButton = function (opts) { |
|
3 |
var id = $(this).attr('id'); |
|
4 |
this.on('click', function () { |
|
5 |
var $dialog = $('<div id="dialog-' + (opts.name || id) + |
|
6 |
'" title="' + opts.title + '"><form class="inline-form" method="post"></form></div>'); |
|
7 |
var default_button = opts.default_button == undefined ? 'Envoyer' : opts.default_button; |
|
8 |
var form_action = opts.url.split(' ')[0]; |
|
9 |
var $form = $('form', $dialog); |
|
10 |
$dialog.appendTo('#dialogs'); |
|
11 |
$form.attr('action', form_action); |
|
12 |
var buttons = [{ |
|
13 |
text: default_button, |
|
14 |
click: function () { |
|
15 |
$form.submit(); |
|
16 |
} |
|
17 |
}, |
|
18 |
{ |
|
19 |
text: 'Annuler', |
|
20 |
click: function () { |
|
21 |
$(this).dialog('close'); |
|
22 |
} |
|
23 |
}]; |
|
24 |
$dialog.css('max-height', $(window).height() - 200); |
|
25 |
$form.load(opts.url, function () { |
|
26 |
$dialog.dialog({ |
|
27 |
modal: opts.modal == undefined ? true : opts.modal, |
|
28 |
width: 700, |
|
29 |
maxHeight: $(window).height() - 100, |
|
30 |
buttons: buttons, |
|
31 |
close: function () { |
|
32 |
$(this).remove(); |
|
33 |
} |
|
34 |
}); |
|
35 |
}); |
|
36 |
}) |
|
37 |
}; |
|
38 |
$(function () { |
|
39 |
$('.dialog-button').each(function (i, button) { |
|
40 |
var $button = $(button); |
|
41 |
$button.dialogButton({ |
|
42 |
url: $button.data('url') || $button.closest('a').attr('href'), |
|
43 |
default_button: $button.data('default-button') || $button.text(), |
|
44 |
title: $button.attr('title') || $button.text(), |
|
45 |
}); |
|
46 |
}); |
|
47 |
}); |
|
48 |
})(window.jQuery) |
Also available in: Unified diff
add a jQuery extension to create dialog from simple form views