### Eclipse Workspace Patch 1.0 #P timer Index: timer.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/timer/timer.module,v retrieving revision 1.1 diff -u -r1.1 timer.module --- timer.module 9 Oct 2007 08:27:25 -0000 1.1 +++ timer.module 10 Oct 2007 04:09:30 -0000 @@ -125,6 +126,7 @@ */ function timer_field_formatter($field, $item, $formatter, $node) { $path = drupal_get_path('module', 'timer'); + drupal_add_js($path .'/timer.jquery.js'); drupal_add_css($path . '/timer.css', 'module', 'screen', FALSE); $enable_button_controls = $field['timer_enable_controls'] && user_access('use timer controls'); @@ -514,3 +516,37 @@ watchdog('content', t('@type: reset timer field %timer_field on %title.', array('@type' => t($node->type), '%timer_field' => $timer_field, '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid)); return true; } + +/* jQuery Callbacks */ + +function timer_menu($may_cache) { + $items = array(); + if (!$may_cache) { + $items[] = array( + 'path' => 'timer/callback', + 'title' => t('Eighth Gear Management'), + 'callback' => 'timer_jquery_callback', + 'access' => TRUE, // need to check for access to node/arg(3) + 'weight' => -10, + ); + } + return $items; +} + +function timer_jquery_callback() { + if (is_numeric(arg(3))) { + // need to extend for all field names + $timer_field = 'field_timer'; + $node = node_load(array('nid' => arg(3))); + switch (arg(2)) { + case 'start': + _timer_start($node, $timer_field); + print drupal_get_form('timer_form', 'stop', $node, $timer_field); + break; + case 'stop': + _timer_stop($node, $timer_field); + print drupal_get_form('timer_form', 'reset', $node, $timer_field); + break; + } + } +} \ No newline at end of file Index: timer.jquery.js =================================================================== RCS file: timer.jquery.js diff -N timer.jquery.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ timer.jquery.js 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,20 @@ +$(document).ready(function() { + timer_jquery_init(); +}); + +function timer_jquery_init() { + $('#timer-form #edit-start').click(function() { + $.get('/timer/start/'+$('#edit-nid').val(), null, function (data) { + $('form#timer-form').html(data); + timer_jquery_init(); + }); + return false; + }) + $('.stop#edit-submit').click(function() { + $.get('/timer/stop/'+$('#edit-nid').val(), null, function (data) { + $('form#timer-form').html(data); + timer_jquery_init(); + }); + return false; + }) +}