Mercurial > defr > drupal > noderef_view
comparison noderef_view.js @ 4:b4c1e3d5d5ce
Warn if value omitted due to lack of space
author | Franck Deroche <franck@defr.org> |
---|---|
date | Mon, 26 Jan 2009 12:29:17 +0100 |
parents | 25a0c2fcbcfb |
children | e3f85c9247b7 |
comparison
equal
deleted
inserted
replaced
3:9372c6448311 | 4:b4c1e3d5d5ce |
---|---|
1 // vim: set ts=2 sw=2 expandtab syntax=php: | 1 // vim: set ts=2 sw=2 expandtab: |
2 /** | 2 /** |
3 * Attach the noderef_view behavior. | 3 * Attach the noderef_view behavior. |
4 */ | 4 */ |
5 Drupal.behaviors.noderef_view = function(context) { | 5 Drupal.behaviors.noderef_view = function(context) { |
6 $('.noderef_view_link', context).each(function(i, obj) { | 6 $('.noderef_view_link', context).each(function(i, obj) { |
9 var wrapper = $(this).prev(); | 9 var wrapper = $(this).prev(); |
10 while (!wrapper.is('div')) { | 10 while (!wrapper.is('div')) { |
11 wrapper = wrapper.prev(); | 11 wrapper = wrapper.prev(); |
12 } | 12 } |
13 | 13 |
14 // Hide existing "No space left" message | |
15 $('div.noderef_nospace', wrapper).fadeOut(); | |
16 | |
14 // Suppress behavior if it was previsously attached | 17 // Suppress behavior if it was previsously attached |
15 $(document).unbind('popups_form_success.noderef_view'); | 18 $(document).unbind('popups_form_success.noderef_view'); |
16 | 19 |
17 // And now bind it. This code will be executed after successful | 20 // And now bind it. This code will be executed after successful |
18 // completion of the popup select form | 21 // completion of the popup select form |
19 $(document).bind('popups_form_success.noderef_view', function() { | 22 $(document).bind('popups_form_success.noderef_view', function() { |
20 selection = noderef_view_get_selection(); | 23 var selection = noderef_view_get_selection(), left = []; |
21 for(nid in selection) { | 24 for(nid in selection) { |
25 count = 0; | |
22 // Autocomplete field | 26 // Autocomplete field |
23 $('input.form-autocomplete:not([value])', wrapper) | 27 count += $('input.form-autocomplete:not([value])', wrapper) |
24 .filter(':first') | 28 .filter(':first') |
25 .val(selection[nid]); | 29 .val(selection[nid]) |
26 // Select field | 30 .length; |
27 $('select', wrapper).val(nid); | 31 // Select field (exclude the weight of autocomplete fields) |
32 count += $('select:not([id$="--weight"])', wrapper).val(nid).length; | |
28 // Radio field | 33 // Radio field |
29 $('input:radio[value='+ nid + '], input:checkbox[value='+ nid +']', wrapper).attr('checked', 'checked'); | 34 count += $('input:radio[value='+ nid + '], input:checkbox[value='+ nid +']', wrapper) |
35 .attr('checked', 'checked') | |
36 .length; | |
37 if (count == 0) { | |
38 left.push(selection[nid]); | |
39 } | |
40 } | |
41 if (left.length) { | |
42 message = Drupal.t('No space left for value(s): @titles', | |
43 { '@titles': left.join(', ')}); | |
44 wrapper.append('<div class="warning noderef_nospace">'+ message +'</div>'); | |
30 } | 45 } |
31 }); | 46 }); |
32 }); | 47 }); |
33 }); | 48 }); |
34 } | 49 } |