source: sipes/modules_contrib/cck/js/content.admin.js @ a8b1f3f

stableversion-3.0
Last change on this file since a8b1f3f was 830017c, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se actualizo el modulo

  • Propiedad mode establecida a 100644
File size: 3.3 KB
Línea 
1
2Drupal.behaviors.cckManageFields = function(context) {
3  attachUpdateSelects(context);
4};
5
6function attachUpdateSelects(context) {
7  var widgetTypes = Drupal.settings.contentWidgetTypes;
8  var fields = Drupal.settings.contentFields;
9
10  // Store the default text of widget selects.
11  $('#content-field-overview .content-widget-type-select', context).each(function() {
12    this.initialValue = this.options[0].text;
13  });
14
15  // 'Field type' select updates its 'Widget' select.
16  $('#content-field-overview .content-field-type-select', context).each(function() {
17    this.targetSelect = $('.content-widget-type-select', $(this).parents('tr').eq(0));
18
19    $(this).change(function() {
20      var selectedFieldType = this.options[this.selectedIndex].value;
21      var options = (selectedFieldType in widgetTypes) ? widgetTypes[selectedFieldType] : [ ];
22      this.targetSelect.contentPopulateOptions(options);
23    });
24
25    // Trigger change on initial pageload to get the right widget options
26    // when field type comes pre-selected (on failed validation).
27    $(this).trigger('change');
28  });
29
30  // 'Existing field' select updates its 'Widget' select and 'Label' textfield.
31  $('#content-field-overview .content-field-select', context).each(function() {
32    this.targetSelect = $('.content-widget-type-select', $(this).parents('tr').eq(0));
33    this.targetTextfield = $('.content-label-textfield', $(this).parents('tr').eq(0));
34
35    $(this).change(function(e, updateText) {
36      var updateText = (typeof(updateText) == 'undefined') ? true : updateText;
37      var selectedField = this.options[this.selectedIndex].value;
38      var selectedFieldType = (selectedField in fields) ? fields[selectedField].type : null;
39      var selectedFieldWidget = (selectedField in fields) ? fields[selectedField].widget : null
40      var options = (selectedFieldType && (selectedFieldType in widgetTypes)) ? widgetTypes[selectedFieldType] : [ ];
41      this.targetSelect.contentPopulateOptions(options, selectedFieldWidget);
42
43      if (updateText) {
44        $(this.targetTextfield).attr('value', (selectedField in fields) ? fields[selectedField].label : '');
45      }
46    });
47
48    // Trigger change on initial pageload to get the right widget options
49    // and label when field type comes pre-selected (on failed validation).
50    $(this).trigger('change', false);
51  });
52}
53
54jQuery.fn.contentPopulateOptions = function(options, selected) {
55  return this.each(function() {
56    var disabled = false;
57    if (options.length == 0) {
58      options = [this.initialValue];
59      disabled = true;
60    }
61
62    // If possible, keep the same widget selected when changing field type.
63    // This is based on textual value, since the internal value might be
64    // different (optionwidgets_buttons vs. nodereference_buttons).
65    var previousSelectedText = this.options[this.selectedIndex].text;
66
67    var html = '';
68    jQuery.each(options, function(value, text) {
69      // Figure out which value should be selected. The 'selected' param
70      // takes precedence.
71      var is_selected = ((typeof(selected) !== 'undefined' && value == selected) || (typeof(selected) == 'undefined' && text == previousSelectedText));
72      html += '<option value="' + value + '"' + (is_selected ? ' selected="selected"' : '') +'>' + text + '</option>';
73    });
74
75    $(this)
76      .html(html)
77      .attr('disabled', disabled ? 'disabled' : '');
78  });
79}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.