/[drupal]/contributions/modules/nodereference_asmselect/nodereference_asmselect.js
ViewVC logotype

Contents of /contributions/modules/nodereference_asmselect/nodereference_asmselect.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Sun Nov 23 07:52:15 2008 UTC (12 months ago) by electricmonk
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
File MIME type: text/javascript
*** empty log message ***
1 var NodeReferenceAsmSelect =
2 {
3 settings:
4 {
5 filterPath : null
6 },
7 fn: {}
8 };
9
10 NodeReferenceAsmSelect.fn.termIdFiltersChange = function(id, fieldName)
11 {
12 var selector = '#' + id + '-filters select.asmselect-filter';
13 $(selector).change(function()
14 {
15 var filters = [];
16
17 $(selector).each(function(index, element)
18 {
19 var val = $(this).attr('value');
20 if (val)
21 {
22 filters.push('tid=' + val);
23 }
24 });
25
26 $.post( NodeReferenceAsmSelect.settings.filterPath,
27 {'filters': filters.join(','), 'field_name' : fieldName},
28 function(data)
29 {
30 NodeReferenceAsmSelect.fn.optionsChanged(id, data);
31 });
32 });
33 }
34
35 NodeReferenceAsmSelect.fn.optionsChanged = function(fieldName, options)
36 {
37 var select = $('#edit-' + fieldName + '-nids');
38
39 // save all selected options
40 var selectedOptions = select.find("option[selected]");
41
42 select.html(options).change();
43
44 // add / reselect previously selected options
45 for (var i = 0; i < selectedOptions.length; i++)
46 {
47 var option = select.find("option[value='" + selectedOptions[i].value + "']");
48
49 if (option.length)
50 {
51 // option exists, make sure it's selected
52 option.attr('selected', 'selected');
53 }
54 else
55 {
56 select.append(selectedOptions[i]);
57 }
58 }
59
60 // reset all option ids
61 select.find("option").removeAttr('id');
62
63 // trigger the change event to cause asmSelect to reprocess the options
64 select.change();
65 }
66

  ViewVC Help
Powered by ViewVC 1.1.2