Skip to content
Snippets Groups Projects
Commit 5a49056a authored by Earl Miles's avatar Earl Miles
Browse files

Add callbacks to the collapsible so that it can be trivially transformed into...

Add callbacks to the collapsible so that it can be trivially transformed into other things like an accordion. Add accordion functionality to the task admin UI.
parent 71c6dfc1
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
background-image: url(../images/collapsible-expanded.png); background-image: url(../images/collapsible-expanded.png);
} }
.ctools-collapsible-container .ctools-collapsible-handle {
cursor: pointer;
}
.ctools-collapsible-container .ctools-toggle-collapsed { .ctools-collapsible-container .ctools-toggle-collapsed {
background-image: url(../images/collapsible-collapsed.png); background-image: url(../images/collapsible-collapsed.png);
} }
...@@ -46,3 +46,20 @@ ...@@ -46,3 +46,20 @@
padding-right: .75em; padding-right: .75em;
} }
#delegator-task-list-arrange td {
vertical-align: top;
}
#delegator-task-list-arrange tr.delegator-collapsible td {
padding-left: 4em;
}
#delegator-task-list-arrange tr.draggable .ctools-collapsible-content {
display: none;
}
/*
#delegator-task-list-arrange tr.delegator-collapsible div.ctools-collapsible-content {
display: block;
}
*/
...@@ -266,6 +266,10 @@ function delegator_admin_list_form(&$form_state) { ...@@ -266,6 +266,10 @@ function delegator_admin_list_form(&$form_state) {
'#value' => $title, '#value' => $title,
); );
$form['handlers'][$id]['summary'] = array(
'#value' => delegator_get_handler_summary($plugin, $handler, $task, $form_state['subtask_id']),
);
$form['handlers'][$id]['weight'] = array( $form['handlers'][$id]['weight'] = array(
'#type' => 'weight', '#type' => 'weight',
'#default_value' => $info['weight'], '#default_value' => $info['weight'],
...@@ -441,7 +445,12 @@ function theme_delegator_admin_list_form($form) { ...@@ -441,7 +445,12 @@ function theme_delegator_admin_list_form($form) {
'class' => 'delegator-changed-col', 'class' => 'delegator-changed-col',
); );
$title = theme('ctools_collapsible', drupal_render($element['title']), 'Imagine content here, please', TRUE); if ($summary = drupal_render($element['summary'])) {
$title = theme('ctools_collapsible', drupal_render($element['title']), $summary, TRUE);
}
else {
$title = drupal_render($element['title']);
}
$row[] = array( $row[] = array(
'data' => $title, 'data' => $title,
......
...@@ -394,6 +394,15 @@ function delegator_get_handler_title($plugin, $handler, $task, $subtask_id) { ...@@ -394,6 +394,15 @@ function delegator_get_handler_title($plugin, $handler, $task, $subtask_id) {
} }
} }
/**
* Get the admin summary (additional info) for a given handler.
*/
function delegator_get_handler_summary($plugin, $handler, $task, $subtask_id) {
if ($function = ctools_plugin_get_function($plugin, 'admin summary')) {
return $function($handler, $task, $subtask_id);
}
}
/** /**
* Implementation of hook_ctools_plugin_dierctory() to let the system know * Implementation of hook_ctools_plugin_dierctory() to let the system know
* we implement task and task_handler plugins. * we implement task and task_handler plugins.
......
...@@ -4,7 +4,9 @@ task handler definition: ...@@ -4,7 +4,9 @@ task handler definition:
description -- description of the task handler. description -- description of the task handler.
task type -- The type of the task this handler can service. task type -- The type of the task this handler can service.
render -- callback of the function to render the handler. The arguments to this callback are specific to the task type. render -- callback of the function to render the handler. The arguments to this callback are specific to the task type.
title callback -- callback to render the admin title as this handler is listed. admin title -- callback to render the admin title as this handler is listed.
params: $handler, $task, $subtask_id
admin summary -- callback to render what's in the collapsible info as the handler is listed. Optional.
params: $handler, $task, $subtask_id params: $handler, $task, $subtask_id
default conf -- either an array() of default conf data or a callback that returns an array. default conf -- either an array() of default conf data or a callback that returns an array.
params: $handler, $task, $subtask_id params: $handler, $task, $subtask_id
...@@ -36,5 +38,7 @@ task handler definition: ...@@ -36,5 +38,7 @@ task handler definition:
'id2' => t('tab name'), 'id2' => t('tab name'),
), ),
If a form name is blank it is a 'hidden' form -- it has no tab but can still be reached.
Notes: Because #required validation cannot be skipped when clicking cancel, please don't use it. Notes: Because #required validation cannot be skipped when clicking cancel, please don't use it.
\ No newline at end of file
...@@ -38,4 +38,41 @@ Drupal.behaviors.zzGoLastDelegatorTaskList = function(context) { ...@@ -38,4 +38,41 @@ Drupal.behaviors.zzGoLastDelegatorTaskList = function(context) {
$next.trigger('click'); $next.trigger('click');
}); });
}); });
} }
\ No newline at end of file
Drupal.Delegator = {};
Drupal.Delegator.CollapsibleCallback = function($container, handle, content, toggle) {
var $parent = $container.parents('tr.draggable');
var id = $parent.attr('id') + '-collapse';
if (toggle.hasClass('ctools-toggle-collapsed')) {
// Force any other item to close, like an accordion:
$('#delegator-task-list-arrange .ctools-toggle:not(.ctools-toggle-collapsed)').trigger('click');
// Closed, about to be opened.
var tr = '<tr class="delegator-collapsible" id="' + id + '"><td colspan=4></td></tr>';
$parent.after(tr);
$('#' + id + ' td').append(content);
$('#' + id).addClass($parent.attr('class'));
}
};
Drupal.Delegator.CollapsibleCallbackAfterToggle = function($container, handle, content, toggle) {
var $parent = $container.parents('tr.draggable');
var id = $parent.attr('id') + '-collapse';
if (toggle.hasClass('ctools-toggle-collapsed')) {
// Was just closed.
content.hide();
handle.after(content);
$('#' + id).remove();
}
};
$(document).ready(function() {
Drupal.CTools.CollapsibleCallbacks.push(Drupal.Delegator.CollapsibleCallback);
Drupal.CTools.CollapsibleCallbacksAfterToggle.push(Drupal.Delegator.CollapsibleCallbackAfterToggle);
// Force all our accordions to close when tabledragging to prevent ugliness:
$('#delegator-task-list-arrange .tabledrag-handle').mousedown(function() {
$('#delegator-task-list-arrange .ctools-toggle:not(.ctools-toggle-collapsed)').trigger('click');
});
});
\ No newline at end of file
...@@ -25,4 +25,15 @@ Automatically filled in data: ...@@ -25,4 +25,15 @@ Automatically filled in data:
name name
module module
path path
file file
\ No newline at end of file
General feature for callbacks:
either 'function_name' or
array(
'file' => 'filename',
'path' => 'filepath', // optional
'function' => 'function_name'
),
Using ctools_plugin_get_function() of ctools_plugin_load_function() will take advantage.
\ No newline at end of file
...@@ -257,11 +257,30 @@ function _ctools_get_plugins($module, $type, $id = NULL) { ...@@ -257,11 +257,30 @@ function _ctools_get_plugins($module, $type, $id = NULL) {
function ctools_plugin_get_function($plugin, $function_name) { function ctools_plugin_get_function($plugin, $function_name) {
// If cached the .inc file may not have been loaded. require_once is quite safe // If cached the .inc file may not have been loaded. require_once is quite safe
// and fast so it's okay to keep calling it. // and fast so it's okay to keep calling it.
if ($plugin['file']) { if (isset($plugin['file'])) {
require_once './' . $plugin['path'] . '/' . $plugin['file']; require_once './' . $plugin['path'] . '/' . $plugin['file'];
} }
if (isset($plugin[$function_name]) && function_exists($plugin[$function_name])) {
return $plugin[$function_name]; if (!isset($plugin[$function_name])) {
return;
}
if (is_array($plugin[$function_name]) && isset($plugin[$function_name]['function'])) {
$function = $plugin[$function_name]['function'];
if (isset($plugin[$function_name]['file'])) {
$file = $plugin[$function_name]['file'];
if (isset($plugin[$function_name]['path'])) {
$file = $plugin[$function_name]['path'] . '/' . $file;
}
require_once './' . $file;
}
}
else {
$function = $plugin[$function_name];
}
if (function_exists($function)) {
return $function;
} }
} }
......
...@@ -21,6 +21,10 @@ if (!Drupal.CTools) { ...@@ -21,6 +21,10 @@ if (!Drupal.CTools) {
* a class, which will cause the container to draw collapsed. * a class, which will cause the container to draw collapsed.
*/ */
// Set up an array for callbacks.
Drupal.CTools.CollapsibleCallbacks = [];
Drupal.CTools.CollapsibleCallbacksAfterToggle = [];
/** /**
* Bind collapsible behavior to a given container. * Bind collapsible behavior to a given container.
*/ */
...@@ -40,15 +44,27 @@ Drupal.CTools.bindCollapsible = function() { ...@@ -40,15 +44,27 @@ Drupal.CTools.bindCollapsible = function() {
content.hide(); content.hide();
} }
// Let both the toggle and the handle be clickable. var afterToggle = function() {
toggle.click(function() { if (Drupal.CTools.CollapsibleCallbacksAfterToggle) {
content.slideToggle(20); for (i in Drupal.CTools.CollapsibleCallbacksAfterToggle) {
toggle.toggleClass('ctools-toggle-collapsed'); Drupal.CTools.CollapsibleCallbacksAfterToggle[i]($container, handle, content, toggle);
}); }
handle.click(function() { }
content.slideToggle(20); }
var clickMe = function() {
if (Drupal.CTools.CollapsibleCallbacks) {
for (i in Drupal.CTools.CollapsibleCallbacks) {
Drupal.CTools.CollapsibleCallbacks[i]($container, handle, content, toggle);
}
}
content.slideToggle(100, afterToggle);
toggle.toggleClass('ctools-toggle-collapsed'); toggle.toggleClass('ctools-toggle-collapsed');
}); }
// Let both the toggle and the handle be clickable.
toggle.click(clickMe);
handle.click(clickMe);
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment