Index: modules/field_ui/field_ui.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP <+>/**\n * @file\n * Attaches the behaviors for the Field UI module.\n */\n \n(function($) {\n\nDrupal.behaviors.fieldUIFieldOverview = {\n attach: function (context, settings) {\n $('table#field-overview', context).once('field-overview', function () {\n Drupal.fieldUIFieldOverview.attachUpdateSelects(this, settings);\n });\n }\n};\n\nDrupal.fieldUIFieldOverview = {\n /**\n * Implements dependent select dropdowns on the 'Manage fields' screen.\n */\n attachUpdateSelects: function(table, settings) {\n var widgetTypes = settings.fieldWidgetTypes;\n var fields = settings.fields;\n\n // Store the default text of widget selects.\n $('.widget-type-select', table).each(function () {\n this.initialValue = this.options[0].text;\n });\n\n // 'Field type' select updates its 'Widget' select.\n $('.field-type-select', table).each(function () {\n this.targetSelect = $('.widget-type-select', $(this).closest('tr'));\n\n $(this).bind('change keyup', function () {\n var selectedFieldType = this.options[this.selectedIndex].value;\n var options = (selectedFieldType in widgetTypes ? widgetTypes[selectedFieldType] : []);\n this.targetSelect.fieldUIPopulateOptions(options);\n });\n\n // Trigger change on initial pageload to get the right widget options\n // when field type comes pre-selected (on failed validation).\n $(this).trigger('change', false);\n });\n\n // 'Existing field' select updates its 'Widget' select and 'Label' textfield.\n $('.field-select', table).each(function () {\n this.targetSelect = $('.widget-type-select', $(this).closest('tr'));\n this.targetTextfield = $('.label-textfield', $(this).closest('tr'));\n this.targetTextfield\n .data('field_ui_edited', false)\n .bind('keyup', function (e) {\n $(this).data('field_ui_edited', $(this).val() != '');\n });\n\n $(this).bind('change keyup', function (e, updateText) {\n var updateText = (typeof updateText == 'undefined' ? true : updateText);\n var selectedField = this.options[this.selectedIndex].value;\n var selectedFieldType = (selectedField in fields ? fields[selectedField].type : null);\n var selectedFieldWidget = (selectedField in fields ? fields[selectedField].widget : null);\n var options = (selectedFieldType && (selectedFieldType in widgetTypes) ? widgetTypes[selectedFieldType] : []);\n this.targetSelect.fieldUIPopulateOptions(options, selectedFieldWidget);\n\n // Only overwrite the \"Label\" input if it has not been manually\n // changed, or if it is empty.\n if (updateText && !this.targetTextfield.data('field_ui_edited')) {\n this.targetTextfield.val(selectedField in fields ? fields[selectedField].label : '');\n }\n });\n\n // Trigger change on initial pageload to get the right widget options\n // and label when field type comes pre-selected (on failed validation).\n $(this).trigger('change', false);\n });\n }\n};\n\n/**\n * Populates options in a select input.\n */\njQuery.fn.fieldUIPopulateOptions = function (options, selected) {\n return this.each(function () {\n var disabled = false;\n if (options.length == 0) {\n options = [this.initialValue];\n disabled = true;\n }\n\n // If possible, keep the same widget selected when changing field type.\n // This is based on textual value, since the internal value might be\n // different (options_buttons vs. node_reference_buttons).\n var previousSelectedText = this.options[this.selectedIndex].text;\n\n var html = '';\n jQuery.each(options, function (value, text) {\n // Figure out which value should be selected. The 'selected' param\n // takes precedence.\n var is_selected = ((typeof selected != 'undefined' && value == selected) || (typeof selected == 'undefined' && text == previousSelectedText));\n html += '';\n });\n\n $(this).html(html).attr('disabled', disabled ? 'disabled' : '');\n });\n};\n\nDrupal.behaviors.fieldUIDisplayOverview = {\n attach: function (context, settings) {\n $('table#field-display-overview', context).once('field-display-overview', function() {\n Drupal.fieldUIOverview.attach(this, settings.fieldUIRowsData, Drupal.fieldUIDisplayOverview);\n });\n }\n};\n\nDrupal.fieldUIOverview = {\n /**\n * Attaches the fieldUIOverview behavior.\n */\n attach: function (table, rowsData, rowHandlers) {\n var tableDrag = Drupal.tableDrag[table.id];\n\n // Add custom tabledrag callbacks.\n tableDrag.onDrop = this.onDrop;\n tableDrag.row.prototype.onSwap = this.onSwap;\n\n // Create row handlers.\n $('tr.draggable', table).each(function () {\n // Extract server-side data for the row.\n var row = this;\n if (row.id in rowsData) {\n var data = rowsData[row.id];\n data.tableDrag = tableDrag;\n\n // Create the row handler, make it accessible from the DOM row element.\n var rowHandler = new rowHandlers[data.rowHandler](row, data);\n $(row).data('fieldUIRowHandler', rowHandler);\n }\n });\n },\n\n /**\n * Event handler to be attached to form inputs triggering a region change.\n */\n onChange: function () {\n var $trigger = $(this);\n var row = $trigger.closest('tr').get(0);\n var rowHandler = $(row).data('fieldUIRowHandler');\n\n var refreshRows = {};\n refreshRows[rowHandler.name] = $trigger.get(0);\n\n // Handle region change.\n var region = rowHandler.getRegion();\n if (region != rowHandler.region) {\n // Remove parenting.\n $('select.field-parent', row).val('');\n // Let the row handler deal with the region change.\n $.extend(refreshRows, rowHandler.regionChange(region));\n // Update the row region.\n rowHandler.region = region;\n }\n\n // Ajax-update the rows.\n Drupal.fieldUIOverview.AJAXRefreshRows(refreshRows);\n },\n\n /**\n * Lets row handlers react when a row is dropped into a new region.\n */\n onDrop: function () {\n var dragObject = this;\n var row = dragObject.rowObject.element;\n var rowHandler = $(row).data('fieldUIRowHandler');\n if (rowHandler !== undefined) {\n var regionRow = $(row).prevAll('tr.region-message').get(0);\n var region = regionRow.className.replace(/([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/, '$2');\n\n if (region != rowHandler.region) {\n // Let the row handler deal with the region change.\n refreshRows = rowHandler.regionChange(region);\n // Update the row region.\n rowHandler.region = region;\n // Ajax-update the rows.\n Drupal.fieldUIOverview.AJAXRefreshRows(refreshRows);\n }\n }\n },\n\n /**\n * Refreshes placeholder rows in empty regions while a row is being dragged.\n *\n * Copied from block.js.\n *\n * @param table\n * The table DOM element.\n * @param rowObject\n * The tableDrag rowObject for the row being dragged.\n */\n onSwap: function (draggedRow) {\n var rowObject = this;\n $('tr.region-message', rowObject.table).each(function () {\n // If the dragged row is in this region, but above the message row, swap\n // it down one space.\n if ($(this).prev('tr').get(0) == rowObject.group[rowObject.group.length - 1]) {\n // Prevent a recursion problem when using the keyboard to move rows up.\n if ((rowObject.method != 'keyboard' || rowObject.direction == 'down')) {\n rowObject.swap('after', this);\n }\n }\n // This region has become empty.\n if ($(this).next('tr').is(':not(.draggable)') || $(this).next('tr').length == 0) {\n $(this).removeClass('region-populated').addClass('region-empty');\n }\n // This region has become populated.\n else if ($(this).is('.region-empty')) {\n $(this).removeClass('region-empty').addClass('region-populated');\n }\n });\n },\n\n /**\n * Triggers Ajax refresh of selected rows.\n *\n * The 'format type' selects can trigger a series of changes in child rows.\n * The #ajax behavior is therefore not attached directly to the selects, but\n * triggered manually through a hidden #ajax 'Refresh' button.\n *\n * @param rows\n * A hash object, whose keys are the names of the rows to refresh (they\n * will receive the 'ajax-new-content' effect on the server side), and\n * whose values are the DOM element in the row that should get an Ajax\n * throbber.\n */\n AJAXRefreshRows: function (rows) {\n // Separate keys and values.\n var rowNames = [];\n var ajaxElements = [];\n $.each(rows, function (rowName, ajaxElement) {\n rowNames.push(rowName);\n ajaxElements.push(ajaxElement);\n });\n\n if (rowNames.length) {\n // Add a throbber next each of the ajaxElements.\n var $throbber = $('
 
');\n $(ajaxElements)\n .addClass('progress-disabled')\n .after($throbber);\n\n // Fire the Ajax update.\n $('input[name=refresh_rows]').val(rowNames.join(' '));\n $('input#edit-refresh').mousedown();\n\n // Disabled elements do not appear in POST ajax data, so we mark the\n // elements disabled only after firing the request.\n $(ajaxElements).attr('disabled', true);\n }\n }\n};\n\n\n/**\n * Row handlers for the 'Manage display' screen.\n */\nDrupal.fieldUIDisplayOverview = {};\n\n/**\n * Constructor for a 'field' row handler.\n *\n * This handler is used for both fields and 'extra fields' rows.\n *\n * @param row\n * The row DOM element.\n * @param data\n * Additional data to be populated in the constructed object.\n */\nDrupal.fieldUIDisplayOverview.field = function (row, data) {\n this.row = row;\n this.name = data.name;\n this.region = data.region;\n this.tableDrag = data.tableDrag;\n\n // Attach change listener to the 'formatter type' select.\n this.$formatSelect = $('select.field-formatter-type', row);\n this.$formatSelect.change(Drupal.fieldUIOverview.onChange);\n\n return this;\n};\n\nDrupal.fieldUIDisplayOverview.field.prototype = {\n /**\n * Returns the region corresponding to the current form values of the row.\n */\n getRegion: function () {\n return (this.$formatSelect.val() == 'hidden') ? 'hidden' : 'visible';\n },\n\n /**\n * Reacts to a row being changed regions.\n *\n * This function is called when the row is moved to a different region, as a\n * result of either :\n * - a drag-and-drop action (the row's form elements then probably need to be\n * updated accordingly)\n * - user input in one of the form elements watched by the\n * Drupal.fieldUIOverview.onChange change listener.\n *\n * @param region\n * The name of the new region for the row.\n * @return\n * A hash object indicating which rows should be Ajax-updated as a result\n * of the change, in the format expected by\n * Drupal.displayOverview.AJAXRefreshRows().\n */\n regionChange: function (region) {\n\n // When triggered by a row drag, the 'format' select needs to be adjusted\n // to the new region.\n var currentValue = this.$formatSelect.val();\n switch (region) {\n case 'visible':\n if (currentValue == 'hidden') {\n // Restore the formatter back to the default formatter. Pseudo-fields do\n // not have default formatters, we just return to 'visible' for those.\n var value = (this.defaultFormatter != undefined) ? this.defaultFormatter : 'visible';\n }\n break;\n\n default:\n var value = 'hidden';\n break;\n }\n if (value != undefined) {\n this.$formatSelect.val(value);\n }\n\n var refreshRows = {};\n refreshRows[this.name] = this.$formatSelect.get(0);\n\n return refreshRows;\n }\n};\n\n})(jQuery);\n =================================================================== --- modules/field_ui/field_ui.js (date 1342468944000) +++ modules/field_ui/field_ui.js (revision ) @@ -98,6 +98,12 @@ }); $(this).html(html).attr('disabled', disabled ? 'disabled' : ''); + if(disabled) { + $(this).html(html).attr('disabled', 'disabled'); + } + else { + $(this).html(html).removeAttr('disabled'); + } }); };