#context-blockform td.blocks div.label { background:#eee; }
#context-blockform td.blocks div.label a { float:right; }
-#context-blockform td.blocks div.form-item,
-#context-blockform td.blocks input.block-weight { display:none; }
-
#context-ui-items #context-blockform {
font-size:11px;
line-height:15px;
display:block;
border:0px;
}
+
+#context-blockform .tabledrag-toggle-weight-wrapper {
+ margin-bottom:0;
+ }
'#weight' => $block->weight,
'#type' => 'markup',
'#tree' => TRUE,
- 'weight' => array('#type' => 'weight', '#delta' => $weight_delta, '#default_value' => 0),
+ 'weight' => array('#type' => 'weight', '#delta' => $weight_delta, '#default_value' => $block->weight),
);
}
}
$edited = array();
}
- foreach ($edited as $region => $bids) {
- foreach ($bids as $position => $bid) {
- if (isset($block_info[$bid])) {
- $blocks[$bid] = array(
- 'module' => $block_info[$bid]->module,
- 'delta' => $block_info[$bid]->delta,
+ foreach ($edited as $region => $block_data) {
+ foreach ($block_data as $position => $data) {
+ if (isset($block_info[$data->bid])) {
+ $blocks[$data->bid] = array(
+ 'module' => $block_info[$data->bid]->module,
+ 'delta' => $block_info[$data->bid]->delta,
'region' => $region,
- 'weight' => $position,
+ 'weight' => $data->weight,
);
}
}
var blocks = [];
$('tr', $(this)).each(function() {
var bid = $(this).attr('id');
- blocks.push(bid);
+ var weight = $(this).find('select').val();
+ blocks.push({'bid' : bid, 'weight' : weight});
});
Drupal.contextBlockForm.state[region] = blocks;
});
});
};
+ // make sure we update the state right before submits, this takes care of an
+ // apparent race condition between saving the state and the weights getting set
+ // by tabledrag
+ $('#ctools-export-ui-edit-item-form').submit(function() { Drupal.contextBlockForm.setState(); });
+
// Tabledrag
// Add additional handlers to update our blocks.
$.each(Drupal.settings.tableDrag, function(base) {
// create new block markup
var block = document.createElement('tr');
var text = $(this).parents('div.form-item').eq(0).hide().children('label').text();
+ var select = '<div class="form-item form-type-select"><select class="tabledrag-hide form-select">';
+ var i;
+ for (i = -10; i < 10; ++i) {
+ select += '<option>' + i + '</option>';
+ }
+ select += '</select></div>';
$(block).attr('id', $(this).attr('value')).addClass('draggable');
- $(block).html("<td>"+ text + "<input class='block-weight' /></td><td><a href='' class='remove'>X</a></td>");
+ $(block).html("<td>"+ text + "</td><td>" + select + "</td><td><a href='' class='remove'>X</a></td>");
// add block item to region
var base = "context-blockform-region-"+ region;
Drupal.tableDrag[base].makeDraggable(block);
$('table#'+base).append(block);
+ if ($.cookie('Drupal.tableDrag.showWeight') == 1) {
+ $('table#'+base).find('.tabledrag-hide').css('display', '');
+ $('table#'+base).find('.tabledrag-handle').css('display', 'none');
+ }
+ else {
+ $('table#'+base).find('.tabledrag-hide').css('display', 'none');
+ $('table#'+base).find('.tabledrag-handle').css('display', '');
+ }
Drupal.attachBehaviors($('table#'+base));
Drupal.contextBlockForm.setState();
'id' => "context-blockform-region-{$region}",
'class' => array("context-blockform-region"),
);
- drupal_add_tabledrag($attr['id'], 'order', 'sibling', 'block-weight', NULL, NULL, FALSE);
+ drupal_add_tabledrag($attr['id'], 'order', 'sibling', 'tabledrag-hide', NULL, NULL, FALSE);
$rows = array();
foreach (element_children($form[$region]) as $id) {
- $form[$region][$id]['weight']['#attributes'] = array('class' => array('block-weight'));
+ $form[$region][$id]['weight']['#attributes'] = array('class' => array('tabledrag-hide'));
$label = $form[$region][$id]['#value'];
$remove = l('X', $_GET['q'], array('fragment' => 'remove', 'attributes' => array('class' => array('remove'))));
$rows[] = array(
- 'data' => array($label . drupal_render($form[$region][$id]['weight']), $remove),
+ 'data' => array($label, drupal_render($form[$region][$id]['weight']), $remove),
'class' => array('draggable'),
'id' => $id,
);