Mercurial > hg > rr-repo
comparison sites/all/modules/webform/js/select-admin.js @ 0:ff03f76ab3fe
initial version
author | danieleb <danielebarchiesi@me.com> |
---|---|
date | Wed, 21 Aug 2013 18:51:11 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ff03f76ab3fe |
---|---|
1 | |
2 /** | |
3 * @file | |
4 * Enhancements for select list configuration options. | |
5 */ | |
6 | |
7 (function ($) { | |
8 | |
9 Drupal.behaviors.webformSelectLoadOptions = {}; | |
10 Drupal.behaviors.webformSelectLoadOptions.attach = function(context) { | |
11 settings = Drupal.settings; | |
12 | |
13 $('#edit-extra-options-source', context).change(function() { | |
14 var url = settings.webform.selectOptionsUrl + '/' + this.value; | |
15 $.ajax({ | |
16 url: url, | |
17 success: Drupal.webform.selectOptionsLoad, | |
18 dataType: 'json' | |
19 }); | |
20 }); | |
21 } | |
22 | |
23 Drupal.webform = Drupal.webform || {}; | |
24 | |
25 Drupal.webform.selectOptionsOriginal = false; | |
26 Drupal.webform.selectOptionsLoad = function(result) { | |
27 if (Drupal.optionsElement) { | |
28 if (result.options) { | |
29 // Save the current select options the first time a new list is chosen. | |
30 if (Drupal.webform.selectOptionsOriginal === false) { | |
31 Drupal.webform.selectOptionsOriginal = $(Drupal.optionElements[result.elementId].manualOptionsElement).val(); | |
32 } | |
33 $(Drupal.optionElements[result.elementId].manualOptionsElement).val(result.options); | |
34 Drupal.optionElements[result.elementId].disable(); | |
35 Drupal.optionElements[result.elementId].updateWidgetElements(); | |
36 } | |
37 else { | |
38 Drupal.optionElements[result.elementId].enable(); | |
39 if (Drupal.webform.selectOptionsOriginal) { | |
40 $(Drupal.optionElements[result.elementId].manualOptionsElement).val(Drupal.webform.selectOptionsOriginal); | |
41 Drupal.optionElements[result.elementId].updateWidgetElements(); | |
42 Drupal.webform.selectOptionsOriginal = false; | |
43 } | |
44 } | |
45 } | |
46 else { | |
47 if (result.options) { | |
48 $('#' + result.elementId).val(result.options).attr('readonly', 'readonly'); | |
49 } | |
50 else { | |
51 $('#' + result.elementId).attr('readonly', ''); | |
52 } | |
53 } | |
54 } | |
55 | |
56 })(jQuery); |