Skip to content

Commit

Permalink
Finalized the admin interface
Browse files Browse the repository at this point in the history
  • Loading branch information
hugowetterberg committed Feb 8, 2009
1 parent 3aacf65 commit e2253a6
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 1 deletion.
17 changes: 17 additions & 0 deletions css/nodeformcols.admin.css
@@ -0,0 +1,17 @@
/* $Id$ */
#fields td.region {
font-weight: bold;
}
#fields tr.region-message {
font-weight: normal;
color: #999;
}
#fields tr.region-populated {
display: none;
}
.field-region {
background-color: #ff6;
margin-top: 4px;
margin-bottom: 4px;
padding: 3px;
}
95 changes: 95 additions & 0 deletions js/nodeformcols.js
@@ -0,0 +1,95 @@
// $Id$

/**
* Move a field in the fields table from one region to another via select list.
*
* This behavior is dependent on the tableDrag behavior, since it uses the
* objects initialized in that behavior to update the row.
*/
Drupal.behaviors.fieldDrag = function(context) {
var table = $('table#fields');
var tableDrag = Drupal.tableDrag.fields; // Get the fields tableDrag object.

// Add a handler for when a row is swapped, update empty regions.
tableDrag.row.prototype.onSwap = function(swappedRow) {
checkEmptyRegions(table, this);
};

// A custom message for the fields page specifically.
Drupal.theme.tableDragChangedWarning = function () {
return '<div class="warning">' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t("The changes to these fields will not be saved until the <em>Save fields</em> button is clicked.") + '</div>';
};

// Add a handler so when a row is dropped, update fields dropped into new regions.
tableDrag.onDrop = function() {
dragObject = this;
if ($(dragObject.rowObject.element).prev('tr').is('.region-message')) {
var regionRow = $(dragObject.rowObject.element).prev('tr').get(0);
var regionName = regionRow.className.replace(/([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/, '$2');
var regionField = $('select.field-region-select', dragObject.rowObject.element);
var weightField = $('select.field-weight', dragObject.rowObject.element);
var oldRegionName = weightField[0].className.replace(/([^ ]+[ ]+)*field-weight-([^ ]+)([ ]+[^ ]+)*/, '$2');

if (!regionField.is('.field-region-'+ regionName)) {
regionField.removeClass('field-region-' + oldRegionName).addClass('field-region-' + regionName);
weightField.removeClass('field-weight-' + oldRegionName).addClass('field-weight-' + regionName);
regionField.val(regionName);
}
}
};

// Add the behavior to each region select list.
$('select.field-region-select:not(.fieldregionselect-processed)', context).each(function() {
$(this).change(function(event) {
// Make our new row and select field.
var row = $(this).parents('tr:first');
var select = $(this);
tableDrag.rowObject = new tableDrag.row(row);

// Find the correct region and insert the row as the first in the region.
$('tr.region-message', table).each(function() {
if ($(this).is('.region-' + select[0].value + '-message')) {
// Add the new row and remove the old one.
$(this).after(row);
// Manually update weights and restripe.
tableDrag.updateFields(row.get(0));
tableDrag.rowObject.changed = true;
if (tableDrag.oldRowElement) {
$(tableDrag.oldRowElement).removeClass('drag-previous');
}
tableDrag.oldRowElement = row.get(0);
tableDrag.restripeTable();
tableDrag.rowObject.markChanged();
tableDrag.oldRowElement = row;
$(row).addClass('drag-previous');
}
});

// Modify empty regions with added or removed fields.
checkEmptyRegions(table, row);
// Remove focus from selectbox.
select.get(0).blur();
});
$(this).addClass('fieldregionselect-processed');
});

var checkEmptyRegions = function(table, rowObject) {
$('tr.region-message', table).each(function() {
// If the dragged row is in this region, but above the message row, swap it down one space.
if ($(this).prev('tr').get(0) == rowObject.element) {
// Prevent a recursion problem when using the keyboard to move rows up.
if ((rowObject.method != 'keyboard' || rowObject.direction == 'down')) {
rowObject.swap('after', this);
}
}
// This region has become empty
if ($(this).next('tr').is(':not(.draggable)') || $(this).next('tr').size() == 0) {
$(this).removeClass('region-populated').addClass('region-empty');
}
// This region has become populated.
else if ($(this).is('.region-empty')) {
$(this).removeClass('region-empty').addClass('region-populated');
}
});
};
};
4 changes: 3 additions & 1 deletion nodeformcols.admin.inc
Expand Up @@ -106,11 +106,13 @@ function nodeformcols_configuration_form($form_state, $type) {

function _nodeformcols_configuration_form_after_build($form) {
drupal_add_js('misc/tableheader.js');
drupal_add_js(drupal_get_path('module', 'nodeformcols') . '/js/nodeformcols.js');
drupal_add_css(drupal_get_path('module', 'nodeformcols') . '/css/nodeformcols.admin.css');

$regions = nodeformcols_form_regions();
foreach ($regions as $region => $title) {
uasort($form['conf'][$region], "element_sort");
drupal_add_tabledrag('fields', 'match', 'sibling', 'field-region-select', 'field-region-'. $region);
drupal_add_tabledrag('fields', 'match', 'sibling', 'field-region-select', 'field-region-'. $region, NULL, FALSE);
drupal_add_tabledrag('fields', 'order', 'sibling', 'field-weight', 'field-weight-'. $region);
}
return $form;
Expand Down

0 comments on commit e2253a6

Please sign in to comment.