You are here

function panels_ajax_flexible_edit_settings in Panels 6.3

Same name and namespace in other branches
  1. 7.3 plugins/layouts/flexible/flexible.inc \panels_ajax_flexible_edit_settings()

AJAX responder to edit flexible settings for an item.

$handler object The display renderer handler object.

1 string reference to 'panels_ajax_flexible_edit_settings'
flexible.inc in plugins/layouts/flexible/flexible.inc

File

plugins/layouts/flexible/flexible.inc, line 935

Code

function panels_ajax_flexible_edit_settings($handler, $id) {
  $settings =& $handler->display->layout_settings;
  panels_flexible_convert_settings($settings, $handler->plugins['layout']);
  if (empty($settings['items'][$id])) {
    ctools_modal_render(t('Error'), t('Invalid item id.'));
  }
  $item =& $settings['items'][$id];
  $siblings = array();
  if ($id != 'canvas') {
    $siblings = $settings['items'][$item['parent']]['children'];
  }
  switch ($item['type']) {
    case 'column':
      $title = t('Configure column');
      break;
    case 'row':
      if ($id == 'canvas') {
        $title = t('Configure canvas');
      }
      else {
        $title = t('Configure row');
      }
      break;
    case 'region':
      $title = t('Configure region');
      break;
  }
  $form_state = array(
    'display' => &$handler->display,
    'item' => &$item,
    'id' => $id,
    'siblings' => $siblings,
    'settings' => &$settings,
    'ajax' => TRUE,
    'title' => $title,
    'op' => 'edit',
  );
  $output = ctools_modal_form_wrapper('panels_flexible_config_item_form', $form_state);
  if (empty($output)) {

    // If the width type changed then other nearby items will have
    // to have their widths adjusted.
    panels_edit_cache_set($handler->cache);
    $css_id = isset($handler->display->css_id) ? $handler->display->css_id : '';
    $renderer = panels_flexible_create_renderer(TRUE, $css_id, array(), $settings, $handler->display, $handler->plugins['layout'], $handler);
    $output = array();

    // If the item is a region, replace the title.
    $class = $renderer->base[$item['type']] . '-' . $id;
    if ($item['type'] == 'region') {
      $output[] = ctools_ajax_command_replace(".{$class} h2.label", '<h2 class="label">' . check_plain($item['title']) . '</h2>');
    }

    // Rerender our links in case something changed.
    $output[] = ctools_ajax_command_replace('.flexible-links-' . $id, panels_flexible_render_item_links($renderer, $id, $item));

    // If editing the canvas, reset the CSS width
    if ($id == 'canvas') {

      // update canvas CSS.
      $css = array(
        '.' . $renderer->item_class['column'] . '-inside' => array(
          'padding-left' => $renderer->column_separation,
          'padding-right' => $renderer->column_separation,
        ),
        '.' . $renderer->item_class['region'] . '-inside' => array(
          'padding-left' => $renderer->region_separation,
          'padding-right' => $renderer->region_separation,
        ),
        '.' . $renderer->item_class['row'] => array(
          'padding-bottom' => $renderer->row_separation,
        ),
      );
      if (!empty($item['fixed_width']) && intval($item['fixed_width'])) {
        $css['.' . $renderer->base['canvas']] = array(
          'width' => intval($item['fixed_width']) . 'px',
        );
      }
      else {
        $css['.' . $renderer->base['canvas']] = array(
          'width' => 'auto',
        );
      }
      foreach ($css as $selector => $data) {
        $output[] = ctools_ajax_command_css($selector, $data);
      }
    }
    $output[] = ctools_modal_command_dismiss();
  }
  $handler->commands = $output;
}