Révision e4d0188e
Ajouté par Jérôme Schneider il y a environ 10 ans
calebasse/static/js/calebasse.dialog.js | ||
---|---|---|
55 | 55 |
modal: true, |
56 | 56 |
width: width, |
57 | 57 |
buttons: [ { text: "Annuler", |
58 |
id: "close-btn",
|
|
59 |
click: function() { $(this).dialog("close"); } },
|
|
58 |
id: "close-btn", |
|
59 |
click: function() { $(this).dialog("close"); } }, |
|
60 | 60 |
{ text: btn_submit_name, |
61 |
id: "submit-btn",
|
|
62 |
click: function() {
|
|
63 |
disable_button($('#submit-btn'));
|
|
64 |
$(id + " form").submit();
|
|
65 |
} }]});
|
|
61 |
id: "submit-btn", |
|
62 |
click: function() { |
|
63 |
disable_button($('#submit-btn')); |
|
64 |
$(id + " form").submit(); |
|
65 |
} }]}); |
|
66 | 66 |
if (on_load_callback) { |
67 |
on_load_callback($(this));
|
|
67 |
on_load_callback($(this)); |
|
68 | 68 |
} |
69 | 69 |
}); |
70 | 70 |
} |
71 | 71 |
|
72 | 72 |
function add_dialog(on, url, title, width, btn_text) { |
73 |
// function used to add patient schedules, events and acts |
|
74 |
$(on).load(url, |
|
75 |
function () { |
|
76 |
$('#rdv .datepicker-date').datepicker({dateFormat: 'd/m/yy', showOn: 'button'}); |
|
77 |
$('#id_description').attr('rows', '3'); |
|
78 |
$('#id_description').attr('cols', '30'); |
|
79 |
var deck = $('#id_participants_on_deck'); |
|
80 |
$(deck).bind('added', function() { |
|
81 |
var added = $(deck).find('div:last'); |
|
82 |
var t = added.attr('id').indexOf('_group:'); |
|
83 |
if ( t == -1) return; |
|
84 |
var query = added.attr('id').substr(t+1); |
|
73 |
// function used to add patient schedules, events and acts |
|
85 | 74 |
|
86 |
/* remove group element and fake id */ |
|
87 |
added.remove(); |
|
88 |
var val = $('#id_participants').val(); |
|
89 |
$('#id_participants').val(val.substr(0, val.substr(0, val.length-1).lastIndexOf('|')+1)); |
|
75 |
function init_dialog() { |
|
76 |
$('#rdv .datepicker-date').datepicker({dateFormat: 'd/m/yy', showOn: 'button'}); |
|
77 |
$('#id_description').attr('rows', '3'); |
|
78 |
$('#id_description').attr('cols', '30'); |
|
79 |
var deck = $('#id_participants_on_deck'); |
|
80 |
$(deck).bind('added', function() { |
|
81 |
var added = $(deck).find('div:last'); |
|
82 |
var t = added.attr('id').indexOf('_group:'); |
|
83 |
if ( t == -1) return; |
|
90 | 84 |
|
91 |
/* add all workers */ |
|
92 |
var receive_result = $('#id_participants_text').autocomplete('option', 'select'); |
|
93 |
$.getJSON($('#id_participants_text').autocomplete('option', 'source') + '?term=' + query, |
|
94 |
function(data) { |
|
95 |
$.each(data, function(key, val) { |
|
96 |
if (key==0) return; /* ignore first element as it's the group itself */ |
|
97 |
var ui = Object(); |
|
98 |
ui.item = val; |
|
99 |
receive_result(null, ui); |
|
100 |
}); |
|
101 |
}); |
|
102 |
}); |
|
103 |
var old_background_image, old_background_repeat, $button; |
|
104 |
var in_submit = false; |
|
105 |
$(on).unbind('submit'); |
|
106 |
$(on).submit(function(event) { |
|
107 |
/* stop form from submitting normally */ |
|
108 |
event.preventDefault(); |
|
85 |
/* remove group element and fake id */ |
|
86 |
added.remove(); |
|
87 |
var val = $('#id_participants').val(); |
|
88 |
$('#id_participants').val(val.substr(0, val.substr(0, val.length-1).lastIndexOf('|')+1)); |
|
109 | 89 |
|
110 |
var $form = $('form', this); |
|
111 |
$.post($form.attr('action'), $form.serialize(), |
|
112 |
function (data) { |
|
113 |
var parse = $(data); |
|
114 |
$button.css('background-image', old_background_image); |
|
115 |
$button.css('background-repeat', old_background_repeat); |
|
116 |
$button.removeAttr('disabled'); |
|
117 |
if ($('.errorlist', parse).length != 0) { |
|
118 |
$(on).html(data); |
|
119 |
$(on +' .datepicker-date').datepicker({dateFormat: 'd/m/yy', showOn: 'button'}); |
|
120 |
} else { |
|
121 |
$('body').html(data); |
|
122 |
} |
|
123 |
in_submit = false; |
|
124 |
}, |
|
125 |
"html"); |
|
126 |
}); |
|
127 |
var submit = function (ev) { |
|
128 |
if (in_submit) { |
|
129 |
return; |
|
130 |
} |
|
131 |
in_submit = true; |
|
132 |
$button = $(ev.target).parent(); |
|
133 |
old_background_image = $button.css('background-image'); |
|
134 |
old_background_repeat = $button.css('background-repeat'); |
|
135 |
$button.attr('disabled', 'disabled'); |
|
136 |
$button.css('background-image', 'url(/static/images/throbber.gif), ' + old_background_image); |
|
137 |
$button.css('background-repeat', 'no-repeat, ' + old_background_repeat); |
|
138 |
$(on + " form").submit(); |
|
139 |
}; |
|
140 |
$(this).dialog({title: title, |
|
141 |
modal: true, |
|
142 |
width: width, |
|
143 |
buttons: [ |
|
144 |
{ text: btn_text, |
|
145 |
click: submit } |
|
146 |
], |
|
147 |
close: function() {}, |
|
148 |
}); |
|
149 |
}); |
|
90 |
/* add all workers */ |
|
91 |
var query = added.attr('id').substr(t+1); |
|
92 |
var receive_result = $('#id_participants_text').autocomplete('option', 'select'); |
|
93 |
$.getJSON($('#id_participants_text').autocomplete('option', 'source') + '?term=' + query, |
|
94 |
function(data) { |
|
95 |
$.each(data, function(key, val) { |
|
96 |
if (key==0) return; /* ignore first element as it's the group itself */ |
|
97 |
var ui = Object(); |
|
98 |
ui.item = val; |
|
99 |
receive_result(null, ui); |
|
100 |
}); |
|
101 |
}); |
|
102 |
|
|
103 |
}); |
|
104 |
} |
|
105 |
|
|
106 |
$(on).load(url, |
|
107 |
function () { |
|
108 |
init_dialog(); |
|
109 |
var old_background_image, old_background_repeat, $button; |
|
110 |
var in_submit = false; |
|
111 |
$(on).unbind('submit'); |
|
112 |
$(on).submit(function(event) { |
|
113 |
/* stop form from submitting normally */ |
|
114 |
event.preventDefault(); |
|
115 |
|
|
116 |
var $form = $('form', this); |
|
117 |
$.post($form.attr('action'), $form.serialize(), |
|
118 |
function (data) { |
|
119 |
var parse = $(data); |
|
120 |
$button.css('background-image', old_background_image); |
|
121 |
$button.css('background-repeat', old_background_repeat); |
|
122 |
$button.removeAttr('disabled'); |
|
123 |
if ($('.errorlist', parse).length != 0) { |
|
124 |
$(on).html(data); |
|
125 |
init_dialog(); |
|
126 |
} else { |
|
127 |
$('body').html(data); |
|
128 |
} |
|
129 |
in_submit = false; |
|
130 |
}, |
|
131 |
"html"); |
|
132 |
}); |
|
133 |
var submit = function (ev) { |
|
134 |
if (in_submit) { |
|
135 |
return; |
|
136 |
} |
|
137 |
in_submit = true; |
|
138 |
$button = $(ev.target).parent(); |
|
139 |
old_background_image = $button.css('background-image'); |
|
140 |
old_background_repeat = $button.css('background-repeat'); |
|
141 |
$button.attr('disabled', 'disabled'); |
|
142 |
$button.css('background-image', 'url(/static/images/throbber.gif), ' + old_background_image); |
|
143 |
$button.css('background-repeat', 'no-repeat, ' + old_background_repeat); |
|
144 |
$(on + " form").submit(); |
|
145 |
}; |
|
146 |
$(this).dialog({title: title, |
|
147 |
modal: true, |
|
148 |
width: width, |
|
149 |
buttons: [ |
|
150 |
{ text: btn_text, |
|
151 |
click: submit } |
|
152 |
], |
|
153 |
close: function() {}, |
|
154 |
}); |
|
155 |
}); |
|
150 | 156 |
} |
151 | 157 |
|
152 | 158 |
function select_add_dialog(opts, $form, form_action) |
... | ... | |
176 | 182 |
var id = $(this).attr('id'); |
177 | 183 |
this.on('click', function () { |
178 | 184 |
var $dialog = $('<div id="dialog-' + (opts.name || id) + |
179 |
'" title="' + opts.title + '"><form class="inline-form" method="post"></form></div>');
|
|
180 |
var default_button = opts.default_button == undefined ? 'Envoyer' : opts.default_button;
|
|
181 |
var form_action = opts.url.split(' ')[0];
|
|
182 |
var $form = $('form', $dialog);
|
|
183 |
$dialog.appendTo('#dialogs');
|
|
184 |
if (opts.next_url) {
|
|
185 |
$form.attr('action', form_action + '?next_url=' + opts.next_url);
|
|
186 |
} else {
|
|
187 |
$form.attr('action', form_action);
|
|
188 |
}
|
|
185 |
'" title="' + opts.title + '"><form class="inline-form" method="post"></form></div>'); |
|
186 |
var default_button = opts.default_button == undefined ? 'Envoyer' : opts.default_button; |
|
187 |
var form_action = opts.url.split(' ')[0]; |
|
188 |
var $form = $('form', $dialog); |
|
189 |
$dialog.appendTo('#dialogs'); |
|
190 |
if (opts.next_url) { |
|
191 |
$form.attr('action', form_action + '?next_url=' + opts.next_url); |
|
192 |
} else { |
|
193 |
$form.attr('action', form_action); |
|
194 |
} |
|
189 | 195 |
|
190 |
if (opts.add_select) {
|
|
191 |
select_add_dialog(opts, $form, form_action);
|
|
192 |
}
|
|
196 |
if (opts.add_select) { |
|
197 |
select_add_dialog(opts, $form, form_action); |
|
198 |
} |
|
193 | 199 |
|
194 |
var buttons = [ |
|
195 |
{ |
|
196 |
text: 'Annuler', |
|
197 |
click: function () { |
|
198 |
$(this).dialog('close'); |
|
199 |
} |
|
200 |
}, |
|
201 |
{ |
|
202 |
text: default_button, |
|
203 |
click: function () { |
|
204 |
$form.submit(); |
|
205 |
} |
|
206 |
}, |
|
207 |
]; |
|
208 |
$dialog.css('max-height', $(window).height() - 200); |
|
209 |
$form.load(opts.url, function () { |
|
210 |
$dialog.dialog({ |
|
211 |
modal: opts.modal == undefined ? true : opts.modal, |
|
212 |
width: 900, |
|
213 |
maxHeight: $(window).height() - 100, |
|
214 |
buttons: buttons, |
|
215 |
close: function () { |
|
216 |
$(this).remove(); |
|
217 |
} |
|
218 |
}); |
|
200 |
var buttons = [ |
|
201 |
{ |
|
202 |
text: 'Annuler', |
|
203 |
click: function () { |
|
204 |
$(this).dialog('close'); |
|
205 |
} |
|
206 |
}, |
|
207 |
{ |
|
208 |
text: default_button, |
|
209 |
click: function () { |
|
210 |
$form.submit(); |
|
211 |
} |
|
212 |
}, |
|
213 |
]; |
|
214 |
$dialog.css('max-height', $(window).height() - 200); |
|
215 |
$form.load(opts.url, function () { |
|
216 |
$dialog.dialog({ |
|
217 |
modal: opts.modal == undefined ? true : opts.modal, |
|
218 |
width: 900, |
|
219 |
maxHeight: $(window).height() - 100, |
|
220 |
buttons: buttons, |
|
221 |
close: function () { |
|
222 |
$(this).remove(); |
|
223 |
} |
|
219 | 224 |
}); |
225 |
}); |
|
220 | 226 |
}) |
221 | 227 |
}; |
222 | 228 |
$(function () { |
... | ... | |
246 | 252 |
$('button.enable-on-change, form input[type="submit"]', form).enable(); |
247 | 253 |
}) |
248 | 254 |
$('form.form-with-confirmation', base).on('submit', function () { |
249 |
var mesg = $(this).data('confirmation-msg') || "Êtes-vous sûr ?";
|
|
250 |
return window.confirm(mesg);
|
|
255 |
var mesg = $(this).data('confirmation-msg') || "Êtes-vous sûr ?"; |
|
256 |
return window.confirm(mesg); |
|
251 | 257 |
}); |
252 | 258 |
$('form .datepicker', base).each(function (i, span) { |
253 | 259 |
var $span = $(span); |
Formats disponibles : Unified diff
calebasse.dialog.js: reindent and init dialog if there is an error
Closes #4277