1 |
1 |
function displayPopup(event)
|
2 |
2 |
{
|
3 |
|
var url = $(this).attr('href');
|
|
3 |
var $anchor = $(this);
|
|
4 |
var url = $anchor.attr('href');
|
|
5 |
var selector = $anchor.data('selector') || 'form';
|
|
6 |
var title_selector = $anchor.data('title-selector') || '#appbar h2';
|
|
7 |
|
|
8 |
function ajaxform_submit (data, status, xhr, form) {
|
|
9 |
if ('location' in data) {
|
|
10 |
var e = $.Event('gadjo:dialog-done');
|
|
11 |
$anchor.trigger(e, form);
|
|
12 |
|
|
13 |
if (! e.isDefaultPrevented()) {
|
|
14 |
if (data.location.split('#')[0] == window.location.href.split('#')[0]) {
|
|
15 |
window.location.reload(true);
|
|
16 |
}
|
|
17 |
window.location = data.location;
|
|
18 |
}
|
|
19 |
} else {
|
|
20 |
var $form = $(form);
|
|
21 |
|
|
22 |
$form.empty().append($(data.content).find(selector).children());
|
|
23 |
$form.find('.buttons').hide();
|
|
24 |
}
|
|
25 |
}
|
|
26 |
|
4 |
27 |
$.ajax({
|
5 |
28 |
url: url,
|
6 |
29 |
success: function(html) {
|
7 |
|
var form = $(html).find('#content form');
|
8 |
|
var title = $(html).find('#appbar h2').text();
|
9 |
|
var dialog = $(form).dialog({modal: true, title: title, width: 'auto'});
|
|
30 |
var is_json = typeof html != 'string';
|
|
31 |
if (is_json) {
|
|
32 |
var html = html.content;
|
|
33 |
} else {
|
|
34 |
var html = html;
|
|
35 |
}
|
|
36 |
var $html = $(html);
|
|
37 |
var $content = $html.find(selector)
|
|
38 |
if ($content.is('form') {
|
|
39 |
var $form = $content;
|
|
40 |
} else {
|
|
41 |
var $form = $content.find('form');
|
|
42 |
}
|
|
43 |
var title = $html.find(title_selector).text();
|
10 |
44 |
var buttons = Array();
|
11 |
|
if (! form.prop('action')) {
|
12 |
|
form.prop('action', url);
|
|
45 |
|
|
46 |
$form.dialog({modal: true, 'title': title, width: 'auto'});
|
|
47 |
|
|
48 |
if (! $form.prop('action')) {
|
|
49 |
$form.prop('action', url);
|
13 |
50 |
}
|
14 |
|
$(dialog).find('.buttons').hide();
|
15 |
|
$(html).find('.buttons button, .buttons a').each(function(idx, elem) {
|
|
51 |
|
|
52 |
$form.find('.buttons').hide();
|
|
53 |
|
|
54 |
$form.find('.buttons button, .buttons a').each(function(idx, elem) {
|
|
55 |
var $elem = $(elem);
|
16 |
56 |
var button = Object();
|
17 |
|
button.text = $(elem).text();
|
18 |
|
if ($(elem).hasClass('cancel')) {
|
19 |
|
button.click = function() { $(this).dialog('destroy'); return false; };
|
|
57 |
|
|
58 |
button.text = $elem.text();
|
|
59 |
if ($elem.hasClass('cancel')) {
|
|
60 |
button.click = function() { $form.dialog('destroy'); return false; };
|
20 |
61 |
} else {
|
21 |
|
button.click = function() { (form).find('button').click(); return false; };
|
|
62 |
button.click = function() { $form.find('button').click(); return false; };
|
22 |
63 |
}
|
23 |
|
if ($(elem).hasClass('submit-button')) {
|
|
64 |
if ($elem.hasClass('submit-button')) {
|
24 |
65 |
button.class = 'submit-button';
|
25 |
|
} else if ($(elem).hasClass('delete-button')) {
|
|
66 |
} else if ($elem.hasClass('delete-button')) {
|
26 |
67 |
button.class = 'delete-button';
|
27 |
68 |
}
|
28 |
69 |
buttons.push(button);
|
29 |
70 |
});
|
|
71 |
|
30 |
72 |
buttons.reverse();
|
31 |
|
$(dialog).dialog('option', 'buttons', buttons);
|
32 |
|
if ($(dialog).find('input:visible').length) {
|
33 |
|
$(dialog).find('input:visible')[0].focus();
|
|
73 |
$form.dialog('option', 'buttons', buttons);
|
|
74 |
if ($form.find('input:visible').length) {
|
|
75 |
$form.find('input:visible')[0].focus();
|
|
76 |
}
|
|
77 |
if (is_json && $.fn.ajaxForm != undefined) {
|
|
78 |
$form.ajaxForm({success: ajaxform_submit});
|
34 |
79 |
}
|
35 |
80 |
return false;
|
36 |
81 |
}
|
... | ... | |
39 |
84 |
}
|
40 |
85 |
|
41 |
86 |
$(function() {
|
42 |
|
$('a[rel=popup]').click(displayPopup);
|
|
87 |
$(document).on('click.gadjo', 'a[rel=popup]', displayPopup);
|
43 |
88 |
});
|
44 |
|
-
|