View source
<?php
class panels_renderer_ipe extends panels_renderer_editor {
var $admin = FALSE;
function render() {
$output = parent::render();
return "<div id='panels-ipe-display-{$this->clean_key}' class='panels-ipe-display-container'>{$output}</div>";
}
function add_meta() {
ctools_include('display-edit', 'panels');
ctools_include('content');
if (empty($this->display->cache_key)) {
$this->cache = panels_edit_cache_get_default($this->display);
}
ctools_include('cleanstring');
$this->clean_key = ctools_cleanstring($this->display->cache_key);
panels_ipe_get_cache_key($this->clean_key);
ctools_include('ajax');
ctools_include('modal');
ctools_modal_add_js();
ctools_add_css('panels_dnd', 'panels');
ctools_add_css('panels_admin', 'panels');
ctools_add_js('panels_ipe', 'panels_ipe');
ctools_add_css('panels_ipe', 'panels_ipe');
$settings = array(
'formPath' => url($this
->get_url('save-form')),
);
drupal_add_js(array(
'PanelsIPECacheKeys' => array(
$this->clean_key,
),
), 'setting');
drupal_add_js(array(
'PanelsIPESettings' => array(
$this->clean_key => $settings,
),
), 'setting');
jquery_ui_add(array(
'ui.draggable',
'ui.droppable',
'ui.sortable',
));
parent::add_meta();
}
function render_pane(&$pane) {
$output = parent::render_pane($pane);
if (empty($output)) {
return;
}
if (empty($pane->IPE_empty)) {
$output = "<div class=\"panels-ipe-portlet-content\">{$output}</div>";
}
else {
$output = "<div class=\"panels-ipe-portlet-content panels-ipe-empty-pane\">{$output}</div>";
}
$output = theme('panels_ipe_pane_wrapper', $output, $pane, $this->display, $this);
return "<div id=\"panels-ipe-paneid-{$pane->pid}\" class=\"panels-ipe-portlet-wrapper panels-ipe-portlet-marker\">" . $output . "</div>";
}
function render_pane_content(&$pane) {
$content = parent::render_pane_content($pane);
if (!is_object($content)) {
$content = new StdClass();
}
if (empty($content->content)) {
$content_type = ctools_get_content_type($pane->type);
$title = ctools_content_admin_title($content_type, $pane->subtype, $pane->configuration, $this->display->context);
$content->content = t('Placeholder for empty "@title"', array(
'@title' => $title,
));
$pane->IPE_empty = TRUE;
}
return $content;
}
function render_region($region_id, $panes) {
$empty_ph = theme('panels_ipe_placeholder_pane', $region_id, $this->plugins['layout']['panels'][$region_id]);
$panes['empty_placeholder'] = '<div class="panels-ipe-placeholder panels-ipe-on panels-ipe-portlet-marker panels-ipe-portlet-static">' . $empty_ph . "</div>";
$panes['add_button'] = theme('panels_ipe_add_pane_button', $region_id, $this->display, $this);
$output = parent::render_region($region_id, $panes);
$output = theme('panels_ipe_region_wrapper', $output, $region_id, $this->display);
$classes = 'panels-ipe-region';
return "<div id='panels-ipe-regionid-{$region_id}' class='panels-ipe-region'>{$output}</div>";
}
function ajax_save_form($break = NULL) {
ctools_include('form');
if (!empty($this->cache->locked)) {
if ($break != 'break') {
$account = user_load($this->cache->locked->uid);
$name = theme('username', $account);
$lock_age = format_interval(time() - $this->cache->locked->updated);
$message = t("This panel is being edited by user !user, and is therefore locked from editing by others. This lock is !age old.\n\nClick OK to break this lock and discard any changes made by !user.", array(
'!user' => $name,
'!age' => $lock_age,
));
$this->commands[] = array(
'command' => 'unlockIPE',
'message' => $message,
'break_path' => url($this
->get_url('save-form', 'break')),
);
return;
}
panels_edit_cache_break_lock($this->cache);
}
$form_state = array(
'display' => &$this->display,
'content_types' => $this->cache->content_types,
'rerender' => FALSE,
'no_redirect' => TRUE,
'layout' => $this->plugins['layout'],
);
$output = ctools_build_form('panels_ipe_edit_control_form', $form_state);
if ($output) {
panels_edit_cache_set($this->cache);
$this->commands[] = array(
'command' => 'initIPE',
'key' => $this->clean_key,
'data' => $output,
);
return;
}
if (!empty($form_state['clicked_button']['#save-display'])) {
panels_edit_cache_save($this->cache);
}
else {
panels_edit_cache_clear($this->cache);
}
$this->commands[] = array(
'command' => 'endIPE',
'key' => $this->clean_key,
'data' => $output,
);
}
function command_update_pane($pid) {
if (is_object($pid)) {
$pane = $pid;
}
else {
$pane = $this->display->content[$pid];
}
$this->commands[] = ctools_ajax_command_replace("#panels-ipe-paneid-{$pane->pid}", $this
->render_pane($pane));
$this->commands[] = ctools_ajax_command_changed("#panels-ipe-display-{$this->clean_key}");
}
function command_add_pane($pid) {
if (is_object($pid)) {
$pane = $pid;
}
else {
$pane = $this->display->content[$pid];
}
$this->commands[] = ctools_ajax_command_append("#panels-ipe-regionid-{$pane->panel} div.panels-ipe-sort-container", $this
->render_pane($pane));
$this->commands[] = ctools_ajax_command_changed("#panels-ipe-display-{$this->clean_key}");
}
}
function panels_ipe_edit_control_form(&$form_state) {
$display =& $form_state['display'];
$form['#display'] = $display;
$layout = panels_get_layout($display->layout);
$layout_panels = panels_get_regions($layout, $display);
$form['panel'] = array(
'#tree' => TRUE,
);
$form['panel']['pane'] = array(
'#tree' => TRUE,
);
foreach ($layout_panels as $panel_id => $title) {
if (!isset($display->panels[$panel_id])) {
$display->panels[$panel_id] = array();
}
$form['panel']['pane'][$panel_id] = array(
'#type' => 'hidden',
'#default_value' => implode(',', (array) $display->panels[$panel_id]),
);
}
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#id' => 'panels-ipe-save',
'#submit' => array(
'panels_edit_display_form_submit',
),
'#save-display' => TRUE,
);
$form['buttons']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#id' => 'panels-ipe-cancel',
);
return $form;
}