Moved and renamed 'storm_quicktt' module to storm directory as 'stormquicktt'
This commit is contained in:
parent
e7e66a9245
commit
a39c010e06
8 changed files with 187 additions and 187 deletions
138
modules/storm/stormquicktt/jquery.timers.js
Normal file
138
modules/storm/stormquicktt/jquery.timers.js
Normal file
|
@ -0,0 +1,138 @@
|
|||
/**
|
||||
* jQuery.timers - Timer abstractions for jQuery
|
||||
* Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com)
|
||||
* Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
|
||||
* Date: 2009/10/16
|
||||
*
|
||||
* @author Blair Mitchelmore
|
||||
* @version 1.2
|
||||
*
|
||||
**/
|
||||
|
||||
jQuery.fn.extend({
|
||||
everyTime: function(interval, label, fn, times) {
|
||||
return this.each(function() {
|
||||
jQuery.timer.add(this, interval, label, fn, times);
|
||||
});
|
||||
},
|
||||
oneTime: function(interval, label, fn) {
|
||||
return this.each(function() {
|
||||
jQuery.timer.add(this, interval, label, fn, 1);
|
||||
});
|
||||
},
|
||||
stopTime: function(label, fn) {
|
||||
return this.each(function() {
|
||||
jQuery.timer.remove(this, label, fn);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
jQuery.extend({
|
||||
timer: {
|
||||
global: [],
|
||||
guid: 1,
|
||||
dataKey: "jQuery.timer",
|
||||
regex: /^([0-9]+(?:\.[0-9]*)?)\s*(.*s)?$/,
|
||||
powers: {
|
||||
// Yeah this is major overkill...
|
||||
'ms': 1,
|
||||
'cs': 10,
|
||||
'ds': 100,
|
||||
's': 1000,
|
||||
'das': 10000,
|
||||
'hs': 100000,
|
||||
'ks': 1000000
|
||||
},
|
||||
timeParse: function(value) {
|
||||
if (value == undefined || value == null)
|
||||
return null;
|
||||
var result = this.regex.exec(jQuery.trim(value.toString()));
|
||||
if (result[2]) {
|
||||
var num = parseFloat(result[1]);
|
||||
var mult = this.powers[result[2]] || 1;
|
||||
return num * mult;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
},
|
||||
add: function(element, interval, label, fn, times) {
|
||||
var counter = 0;
|
||||
|
||||
if (jQuery.isFunction(label)) {
|
||||
if (!times)
|
||||
times = fn;
|
||||
fn = label;
|
||||
label = interval;
|
||||
}
|
||||
|
||||
interval = jQuery.timer.timeParse(interval);
|
||||
|
||||
if (typeof interval != 'number' || isNaN(interval) || interval < 0)
|
||||
return;
|
||||
|
||||
if (typeof times != 'number' || isNaN(times) || times < 0)
|
||||
times = 0;
|
||||
|
||||
times = times || 0;
|
||||
|
||||
var timers = jQuery.data(element, this.dataKey) || jQuery.data(element, this.dataKey, {});
|
||||
|
||||
if (!timers[label])
|
||||
timers[label] = {};
|
||||
|
||||
fn.timerID = fn.timerID || this.guid++;
|
||||
|
||||
var handler = function() {
|
||||
if ((++counter > times && times !== 0) || fn.call(element, counter) === false)
|
||||
jQuery.timer.remove(element, label, fn);
|
||||
};
|
||||
|
||||
handler.timerID = fn.timerID;
|
||||
|
||||
if (!timers[label][fn.timerID])
|
||||
timers[label][fn.timerID] = window.setInterval(handler,interval);
|
||||
|
||||
this.global.push( element );
|
||||
|
||||
},
|
||||
remove: function(element, label, fn) {
|
||||
var timers = jQuery.data(element, this.dataKey), ret;
|
||||
|
||||
if ( timers ) {
|
||||
|
||||
if (!label) {
|
||||
for ( label in timers )
|
||||
this.remove(element, label, fn);
|
||||
} else if ( timers[label] ) {
|
||||
if ( fn ) {
|
||||
if ( fn.timerID ) {
|
||||
window.clearInterval(timers[label][fn.timerID]);
|
||||
delete timers[label][fn.timerID];
|
||||
}
|
||||
} else {
|
||||
for ( var fn in timers[label] ) {
|
||||
window.clearInterval(timers[label][fn]);
|
||||
delete timers[label][fn];
|
||||
}
|
||||
}
|
||||
|
||||
for ( ret in timers[label] ) break;
|
||||
if ( !ret ) {
|
||||
ret = null;
|
||||
delete timers[label];
|
||||
}
|
||||
}
|
||||
|
||||
for ( ret in timers ) break;
|
||||
if ( !ret )
|
||||
jQuery.removeData(element, this.dataKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
jQuery(window).bind("unload", function() {
|
||||
jQuery.each(jQuery.timer.global, function(index, item) {
|
||||
jQuery.timer.remove(item);
|
||||
});
|
||||
});
|
38
modules/storm/stormquicktt/stormquicktt.admin.inc
Normal file
38
modules/storm/stormquicktt/stormquicktt.admin.inc
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
function stormquicktt_settings() {
|
||||
$form = array();
|
||||
$form['stormquicktt_mintime2record'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Minimum time to be recorded (minutes)'),
|
||||
'#default_value' => variable_get('stormquicktt_mintime2record', 5),
|
||||
);
|
||||
$form['stormquicktt_default_title'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Default title'),
|
||||
'#default_value' => variable_get('stormquicktt_default_title', 'Auto-created by QuickTT'),
|
||||
);
|
||||
$status_option_prj = array('none' => '-none-');
|
||||
$project_status = storm_attributes_bydomain('Project status');
|
||||
$status_option_prj = array_merge($status_option_prj, $project_status['values']);
|
||||
|
||||
$form['stormquicktt_project_stati'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Display projects with following status'),
|
||||
'#options' => $status_option_prj,
|
||||
'#multiple' => TRUE,
|
||||
'#size' => 5,
|
||||
'#default_value' => variable_get('stormquicktt_project_stati', array('in progress')),
|
||||
'#description' => t('Select multiple values by pressing the ctrl-key while selecting with the mouse.'),
|
||||
);
|
||||
|
||||
$form['stormquicktt_pause_split'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Split timetrackings on pause.'),
|
||||
'#description' => t('If selected there are multiple timetrackings for before and after each break. '.
|
||||
'If unset there is one timetracking for the whole time, but the pause time will be subtracted from the billing duration.'),
|
||||
'#default_value' => variable_get('stormquicktt_pause_split', FALSE),
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
28
modules/storm/stormquicktt/stormquicktt.css
Normal file
28
modules/storm/stormquicktt/stormquicktt.css
Normal file
|
@ -0,0 +1,28 @@
|
|||
#stormquicktt #edit-selects-projects, .storm-quicktt-info .note input {width:90%;}
|
||||
.storm-quicktt-pause:hover, .storm-quicktt-resume:hover {cursor:pointer;}
|
||||
.storm-quicktt-timer-box .storm-quicktt-resume {font-weight:bold;}
|
||||
.storm-quicktt-timer-box .storm-quicktt-resume:before {content:' (';}
|
||||
.storm-quicktt-timer-box .storm-quicktt-resume:after {content:'!)';}
|
||||
|
||||
.sqtt-timetracking-trigger img{
|
||||
width:16px;
|
||||
height:16px;
|
||||
margin-bottom: -2px;
|
||||
}
|
||||
.sqtt-timetracking-trigger:hover{
|
||||
cursor:pointer;
|
||||
}
|
||||
.block .sqtt-timetracking-trigger {
|
||||
font-size: 0;
|
||||
}
|
||||
|
||||
.timetracking-loading span {
|
||||
text-decoration:blink;
|
||||
font-size:25px;
|
||||
}
|
||||
.timetracking-loading span:before {
|
||||
content:'(';
|
||||
}
|
||||
.timetracking-loading span:after {
|
||||
content:')';
|
||||
}
|
15
modules/storm/stormquicktt/stormquicktt.info
Normal file
15
modules/storm/stormquicktt/stormquicktt.info
Normal file
|
@ -0,0 +1,15 @@
|
|||
name = Storm Quick TimeTracker
|
||||
description = Get a block for permanent and quick timetracking for Storm projects
|
||||
package = Storm
|
||||
core = 6.x
|
||||
php = 5
|
||||
dependencies[] = storm
|
||||
dependencies[] = stormproject
|
||||
dependencies[] = stormtimetracking
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-03-25
|
||||
version = "6.x-2.x-dev"
|
||||
core = "6.x"
|
||||
project = "stormquicktt"
|
||||
datestamp = "1332637511"
|
||||
|
128
modules/storm/stormquicktt/stormquicktt.js
Normal file
128
modules/storm/stormquicktt/stormquicktt.js
Normal file
|
@ -0,0 +1,128 @@
|
|||
(function ($) {
|
||||
|
||||
Drupal.admin = Drupal.admin || {};
|
||||
|
||||
Drupal.behaviors.stormquicktt = function (context) {
|
||||
Drupal.admin.stormquickttInit();
|
||||
};
|
||||
|
||||
Drupal.admin.stormquickttInit = function () {
|
||||
$('#stormquicktt #edit-selects-projects:not(.storm-quicktt-processed)')
|
||||
.addClass('storm-quicktt-processed')
|
||||
.change(function () {
|
||||
$('.storm-quicktt-timer').stopTime();
|
||||
var id = this.value;
|
||||
var x = $('#stormquicktt #edit-selects-mode')[0];
|
||||
var mode = $('#stormquicktt #edit-selects-mode')[0].checked;
|
||||
Drupal.admin.stormquickttInteract("startstop", id, mode);
|
||||
});
|
||||
$('.storm-quicktt-pause:not(.storm-quicktt-processed)')
|
||||
.addClass('storm-quicktt-processed')
|
||||
.click(function () {
|
||||
Drupal.admin.stormquickttInteract("pause", 0, 0);
|
||||
});
|
||||
$('.storm-quicktt-resume:not(.storm-quicktt-processed)')
|
||||
.addClass('storm-quicktt-processed')
|
||||
.click(function () {
|
||||
Drupal.admin.stormquickttInteract("resume", 0, 0);
|
||||
});
|
||||
$('#edit-storm-quicktt-note:not(.storm-quicktt-processed)')
|
||||
.addClass('storm-quicktt-processed')
|
||||
.bind('blur keypress', function (event) {
|
||||
if (event.type == 'keypress' && event.keyCode != 13)
|
||||
return;
|
||||
if (this.value == '')
|
||||
return;
|
||||
Drupal.admin.stormquickttInteract("note", this.value, 0);
|
||||
this.value = '';
|
||||
$(this).focus();
|
||||
if (event.type == 'keypress' && event.keyCode == 13)
|
||||
return false;
|
||||
});
|
||||
$('.sqtt-timetracking-trigger:not(.storm-quicktt-processed)')
|
||||
.addClass('storm-quicktt-processed')
|
||||
.click(function () {
|
||||
var info = this.getAttribute('id');
|
||||
$(this).addClass('timetracking-loading');
|
||||
$('.storm-quicktt-timer').stopTime();
|
||||
Drupal.admin.stormquickttInteract("triggerTimetracking", info, 0, this);
|
||||
});
|
||||
|
||||
Drupal.admin.stormquickttInitTimer();
|
||||
};
|
||||
|
||||
Drupal.admin.stormquickttInitTimer = function () {
|
||||
$('.storm-quicktt-timer').everyTime(60000, function(i) {
|
||||
Drupal.admin.stormquickttInteract("update", 0, 0);
|
||||
});
|
||||
};
|
||||
|
||||
Drupal.admin.stormquickttInteract = function (_op, _nid, _mode, _context) {
|
||||
$.ajax({
|
||||
url: Drupal.settings.stormquicktt_url,
|
||||
async: false,
|
||||
global: false,
|
||||
type: "POST",
|
||||
data: ({
|
||||
op : _op,
|
||||
nid : _nid,
|
||||
mode: _mode
|
||||
}),
|
||||
dataType: "html",
|
||||
complete: function(XMLHttpRequest) {
|
||||
|
||||
},
|
||||
success: function (answer) {
|
||||
if (answer=='OK') {
|
||||
switch (_op) {
|
||||
case 'pause':
|
||||
$('.storm-quicktt-pause').hide();
|
||||
$('.storm-quicktt-resume').show();
|
||||
break;
|
||||
case 'resume':
|
||||
$('.storm-quicktt-pause').show();
|
||||
$('.storm-quicktt-resume').hide();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (_op) {
|
||||
case 'update':
|
||||
if (answer == '') {
|
||||
//This shouldn't happen
|
||||
}
|
||||
else {
|
||||
$('.storm-quicktt-timer').stopTime();
|
||||
$('.storm-quicktt-timer').html(answer);
|
||||
Drupal.admin.stormquickttInitTimer();
|
||||
}
|
||||
break;
|
||||
case 'triggerTimetracking':
|
||||
answer = Drupal.parseJson(answer);
|
||||
if (answer.msg) {
|
||||
$('#sdb-timetracking .content').html(answer.msg);
|
||||
$('.storm-quicktt-info').html(answer.msg);
|
||||
}
|
||||
$("#storm-quicktt-blockform #edit-selects-projects option").removeAttr('selected');
|
||||
if (answer.pid) {
|
||||
$("#storm-quicktt-blockform #edit-selects-projects option[value='"+answer.pid+"']").attr('selected',true);
|
||||
}
|
||||
if (answer.trigger) {
|
||||
$('.'+_nid).replaceWith(answer.trigger);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$('#sdb-timetracking').html(answer);
|
||||
$('.storm-quicktt-info').html(answer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Drupal.attachBehaviors($('#stormquicktt'));
|
||||
},
|
||||
error: function (XMLHttpRequest, textStatus, errorThrown) {
|
||||
alert(XMLHttpRequest.statusText);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
})(jQuery);
|
646
modules/storm/stormquicktt/stormquicktt.module
Normal file
646
modules/storm/stormquicktt/stormquicktt.module
Normal file
|
@ -0,0 +1,646 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* The main file for the stormquicktt module.
|
||||
*
|
||||
* eKomi is a web service that provides real customer feedback to e-comerce website
|
||||
* and displays a certificate on that very same website.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_help().
|
||||
*/
|
||||
function stormquicktt_help($path, $arg) {
|
||||
switch ($path) {
|
||||
case 'admin/suitedesk/quicktt':
|
||||
return '<p>'. t('Here you can set up parameters for SuiteDesk-Quick-TimeTracker.') .'</p>';
|
||||
case 'admin/help#stormquicktt':
|
||||
return filter_filter('process', 2, NULL, file_get_contents(dirname(__FILE__) ."/README.txt"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_menu().
|
||||
*/
|
||||
function stormquicktt_menu() {
|
||||
$items = array();
|
||||
$access_config = array('administer site configuration');
|
||||
$items['admin/settings/suitedesk/quicktt'] = array(
|
||||
'title' => 'SuiteDesk Quick TimeTracker',
|
||||
'description' => 'Configure SuiteDesk Quick TimeTracker',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('stormquicktt_settings'),
|
||||
'access arguments' => $access_config,
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'file' => 'stormquicktt.admin.inc',
|
||||
);
|
||||
$items['stormquicktt/interact'] = array(
|
||||
'page callback' => 'stormquicktt_interact',
|
||||
'access arguments' => array('access content'),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
function stormquicktt_add_resources() {
|
||||
static $loaded = FALSE;
|
||||
if (!$loaded) {
|
||||
drupal_add_css(drupal_get_path('module', 'stormquicktt') .'/stormquicktt.css');
|
||||
drupal_add_js(drupal_get_path('module', 'stormquicktt') .'/stormquicktt.js');
|
||||
drupal_add_js(drupal_get_path('module', 'stormquicktt') .'/jquery.timers.js');
|
||||
drupal_add_js(array('stormquicktt_url' => url('stormquicktt/interact', array('absolute' => TRUE,))), 'setting');
|
||||
$loaded = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_block().
|
||||
*/
|
||||
function stormquicktt_block($op = 'list', $delta = 0, $edit = array()) {
|
||||
switch ($op) {
|
||||
case 'list':
|
||||
$blocks[0]['info'] = t('SuiteDesk Quick TimeTracker');
|
||||
$blocks[0]['cache'] = BLOCK_NO_CACHE;
|
||||
return $blocks;
|
||||
case 'configure':
|
||||
return;
|
||||
case 'save':
|
||||
return;
|
||||
case 'view':
|
||||
if (!user_access('Storm timetracking: add')) {
|
||||
return;
|
||||
}
|
||||
stormquicktt_add_resources();
|
||||
$v = variable_get('stormquicktt_project_stati', array('in progress'));
|
||||
$sql = "SELECT n.*, spr.* FROM {node} AS n
|
||||
INNER JOIN {stormproject} AS spr
|
||||
ON n.vid=spr.vid WHERE n.status=1 AND n.type='stormproject' AND (spr.projectstatus IN ('". implode("','", $v) ."'))
|
||||
ORDER BY spr.organization_title, n.title";
|
||||
$sql = stormproject_access_sql($sql);
|
||||
$result = db_query($sql);
|
||||
$options = array('0' => t('- No billable work -'));
|
||||
while ($node = db_fetch_object($result)) {
|
||||
if (!isset($options[$node->organization_title])) {
|
||||
$options[$node->organization_title] = array();
|
||||
}
|
||||
$options[$node->organization_title][$node->nid] = $node->title;
|
||||
}
|
||||
$form = drupal_get_form('stormquicktt_blockform', $options);
|
||||
|
||||
$blocks['subject'] = t('Quick Timetracking');
|
||||
$blocks['content'] = <<<EOT
|
||||
<div id="stormquicktt">
|
||||
$form
|
||||
</div>
|
||||
EOT;
|
||||
return $blocks;
|
||||
}
|
||||
}
|
||||
|
||||
function stormquicktt_blockform($form_state, $options) {
|
||||
$nid = stormquicktt_tracking_active_nid();
|
||||
$pid = isset($_SESSION['stormquicktt_pid']) ? $_SESSION['stormquicktt_pid'] : 0;
|
||||
if (!empty($nid) && empty($pid)) {
|
||||
switch(stormquicktt_tracking_active_type()) {
|
||||
case 'prj':
|
||||
$pid = $nid;
|
||||
break;
|
||||
case 'tkt':
|
||||
case 'tsk':
|
||||
$node = node_load($nid);
|
||||
if (!empty($node) && !empty($node->project_nid)) {
|
||||
$pid = $node->project_nid;
|
||||
$_SESSION['stormquicktt_pid'] = $pid;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$mode = isset($_SESSION['stormquicktt_mode']) ? $_SESSION['stormquicktt_mode'] : TRUE;
|
||||
$form = array();
|
||||
$form['#cache'] = TRUE;
|
||||
$form['selects'] = array(
|
||||
'#tree' => TRUE,
|
||||
'#prefix' => '<div class="selects">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
$form['selects']['mode'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Auto-Start Tracking'),
|
||||
'#default_value' => $mode,
|
||||
);
|
||||
$form['selects']['projects'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Projects'),
|
||||
'#options' => $options,
|
||||
'#default_value' => $pid,
|
||||
# '#size' => 10,
|
||||
);
|
||||
if (!module_exists('storm_dashboard')) {
|
||||
$form['selects']['info'] = array(
|
||||
'#tree' => TRUE,
|
||||
'#prefix' => '<div class="storm-quicktt-info">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
$form['selects']['info']['time'] = array(
|
||||
'#type' => 'markup',
|
||||
'#value' => stormquicktt_tracking_info(),
|
||||
);
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
function stormquicktt_interact() {
|
||||
if (!isset($_POST['op'])) {
|
||||
exit;
|
||||
}
|
||||
$_GET['q'] = $_SERVER['HTTP_REFERER'];
|
||||
$op = $_POST['op'];
|
||||
$nid = $_POST['nid'];
|
||||
$_SESSION['stormquicktt_mode'] = ($_POST['mode'] == 'true');
|
||||
switch ($op) {
|
||||
case 'pause':
|
||||
stormquicktt_pause_time();
|
||||
print 'OK';
|
||||
break;
|
||||
case 'resume':
|
||||
stormquicktt_resume_time();
|
||||
print 'OK';
|
||||
break;
|
||||
case 'update':
|
||||
if (!$_SESSION['stormquicktt_update_active']) {
|
||||
$_SESSION['stormquicktt_update_active'] = TRUE;
|
||||
print stormquicktt_elapsed_time();
|
||||
$_SESSION['stormquicktt_update_active'] = FALSE;
|
||||
}
|
||||
else {
|
||||
print 'OK';
|
||||
}
|
||||
break;
|
||||
case 'note':
|
||||
stormquicktt_note_for_time($nid);
|
||||
print 'OK';
|
||||
break;
|
||||
case 'triggerTimetracking':
|
||||
$oid = 0;
|
||||
$pid = 0;
|
||||
$tid = 0;
|
||||
$kid = 0;
|
||||
$y = explode('-', $nid);
|
||||
$nid = $y[2];
|
||||
if (!stormquicktt_tracking_active() || stormquicktt_tracking_active_nid() != $nid) {
|
||||
$node = node_load($nid);
|
||||
switch ($node->type) {
|
||||
case 'stormticket':
|
||||
$kid = $nid;
|
||||
$pid = $node->project_nid;
|
||||
break;
|
||||
case 'stormtask':
|
||||
$tid = $nid;
|
||||
$pid = $node->project_nid;
|
||||
break;
|
||||
case 'stormproject':
|
||||
$pid = $nid;
|
||||
break;
|
||||
case 'stormorganization':
|
||||
$oid = $nid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$msg = stormquicktt_start($oid, $pid, $tid, $kid, FALSE);
|
||||
$trigger = stormquicktt_timetracking_trigger($nid);
|
||||
$msg .= stormquicktt_tracking_info();
|
||||
print drupal_json(array('msg' => $msg, 'pid' => $pid, 'trigger' => $trigger));
|
||||
break;
|
||||
default:
|
||||
$msg = "";
|
||||
if ($_SESSION['stormquicktt_mode']) {
|
||||
$msg = stormquicktt_start(0, $nid, 0, 0, FALSE);
|
||||
print $msg . stormquicktt_tracking_info();
|
||||
}
|
||||
elseif ($nid) {
|
||||
$pid = isset($_SESSION['stormquicktt_pid']) ? $_SESSION['stormquicktt_pid'] : 0;
|
||||
if ($pid == $nid) {
|
||||
print $msg . stormquicktt_tracking_info();
|
||||
}
|
||||
else {
|
||||
$title = t('Action');
|
||||
$link = l(t('Goto Project'), 'node/'. $nid);
|
||||
$msg .= '<div class="info"><label>'. $title .':</label> '. $link . '</div>';
|
||||
$msg .= stormquicktt_timetracking_trigger($nid);
|
||||
$active_nid = stormquicktt_tracking_active_nid();
|
||||
if ($active_nid) {
|
||||
$msg .= stormquicktt_tracking_info();
|
||||
}
|
||||
print $msg;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$active_nid = stormquicktt_tracking_active_nid();
|
||||
if ($active_nid) {
|
||||
$msg .= stormquicktt_tracking_info();
|
||||
}
|
||||
print $msg;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
function stormquicktt_start($oid = 0, $pid = 0, $tid = 0, $kid = 0, $show_msg = TRUE) {
|
||||
$start = time();
|
||||
$msg = "";
|
||||
if ($_SESSION['stormquicktt_oid']) {
|
||||
$msg = stormquicktt_store_time($start, $show_msg);
|
||||
}
|
||||
$_SESSION['stormquicktt_note_for_time'] = '';
|
||||
if ($kid) { //Ticket-ID is set and we get the other IDs from the node
|
||||
$node = node_load($kid);
|
||||
$node->ticket_nid = $node->nid;
|
||||
}
|
||||
elseif ($tid) { //Task-ID is set and we get the other IDs from the node
|
||||
$node = node_load($tid);
|
||||
$node->task_nid = $node->nid;
|
||||
}
|
||||
elseif ($pid) { //Project-ID is set and we get the other IDs from the node
|
||||
$node = node_load($pid);
|
||||
$node->project_nid = $node->nid;
|
||||
}
|
||||
elseif ($oid) { //Organization-ID is set and we get the other IDs from the node
|
||||
$node = node_load($oid);
|
||||
$node->organization_nid = $node->nid;
|
||||
}
|
||||
else { //No ID is set and we do only store time if a timetracking was active
|
||||
$node = new stdClass();
|
||||
}
|
||||
$_SESSION['stormquicktt_oid'] = (isset($node->organization_nid)) ? $node->organization_nid : 0;
|
||||
$_SESSION['stormquicktt_pid'] = (isset($node->project_nid)) ? $node->project_nid : 0;
|
||||
$_SESSION['stormquicktt_tid'] = (isset($node->task_nid)) ? $node->task_nid : 0;
|
||||
$_SESSION['stormquicktt_kid'] = (isset($node->ticket_nid)) ? $node->ticket_nid : 0;
|
||||
$_SESSION['stormquicktt_start'] = (isset($node->organization_nid)) ? $start : 0;
|
||||
$_SESSION['stormquicktt_pause_start'] = 0;
|
||||
$_SESSION['stormquicktt_pause_collect'] = 0;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
function stormquicktt_pause_time() {
|
||||
if (!stormquicktt_tracking_active()) {
|
||||
return;
|
||||
}
|
||||
if (!empty($_SESSION['stormquicktt_pause_start'])) {
|
||||
return;
|
||||
}
|
||||
if (variable_get('stormquicktt_pause_split', FALSE)) {
|
||||
$oid = $_SESSION['stormquicktt_oid'];
|
||||
$pid = $_SESSION['stormquicktt_pid'];
|
||||
$tid = $_SESSION['stormquicktt_tid'];
|
||||
$kid = $_SESSION['stormquicktt_kid'];
|
||||
$start = $_SESSION['stormquicktt_start'];
|
||||
stormquicktt_store_time(time(), FALSE);
|
||||
$_SESSION['stormquicktt_oid'] = $oid;
|
||||
$_SESSION['stormquicktt_pid'] = $pid;
|
||||
$_SESSION['stormquicktt_tid'] = $tid;
|
||||
$_SESSION['stormquicktt_kid'] = $kid;
|
||||
$_SESSION['stormquicktt_start'] = $start;
|
||||
}
|
||||
$_SESSION['stormquicktt_pause_start'] = time();
|
||||
}
|
||||
|
||||
function stormquicktt_resume_time() {
|
||||
if (empty($_SESSION['stormquicktt_pause_start'])) {
|
||||
return;
|
||||
}
|
||||
if (variable_get('stormquicktt_pause_split', FALSE)) {
|
||||
$_SESSION['stormquicktt_pause_collect'] += ($_SESSION['stormquicktt_pause_start'] - $_SESSION['stormquicktt_start']);
|
||||
$_SESSION['stormquicktt_start'] = time();
|
||||
}
|
||||
else {
|
||||
$_SESSION['stormquicktt_pause_collect'] += (time() - $_SESSION['stormquicktt_pause_start']);
|
||||
}
|
||||
$_SESSION['stormquicktt_pause_start'] = 0;
|
||||
}
|
||||
|
||||
function stormquicktt_elapsed_time() {
|
||||
if (!empty($_SESSION['stormquicktt_pause_start']) && variable_get('stormquicktt_pause_split', FALSE)) {
|
||||
if (!empty($_SESSION['stormquicktt_start'])) {
|
||||
return '<div>'. t('Elapsed time: !time min', array('!time' => floor(($_SESSION['stormquicktt_pause_start'] - $_SESSION['stormquicktt_start']) / 60))) .'</div>';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
stormquicktt_store_time();
|
||||
if (!empty($_SESSION['stormquicktt_ttid'])) {
|
||||
$now = time();
|
||||
if (variable_get('stormquicktt_pause_split', FALSE) && !empty($_SESSION['stormquicktt_pause_collect'])) {
|
||||
$now += $_SESSION['stormquicktt_pause_collect'];
|
||||
}
|
||||
return '<div>'. t('Elapsed time: !time min', array('!time' => floor(($now - $_SESSION['stormquicktt_start']) / 60))) .'</div>';
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function stormquicktt_store_time($stop = 0, $show_msg = TRUE) {
|
||||
if (!user_access('Storm timetracking: add')) {
|
||||
return t('You have no permission to add timetracking.');
|
||||
}
|
||||
global $user;
|
||||
$oid = $_SESSION['stormquicktt_oid'];
|
||||
$pid = $_SESSION['stormquicktt_pid'];
|
||||
$tid = $_SESSION['stormquicktt_tid'];
|
||||
$kid = $_SESSION['stormquicktt_kid'];
|
||||
$start = $_SESSION['stormquicktt_start'];
|
||||
$pause = 0;
|
||||
if ($stop) {
|
||||
stormquicktt_resume_time();
|
||||
$pause = $_SESSION['stormquicktt_pause_collect'];
|
||||
if (variable_get('stormquicktt_pause_split', FALSE)) {
|
||||
$pause = 0;
|
||||
}
|
||||
unset($_SESSION['stormquicktt_oid']);
|
||||
unset($_SESSION['stormquicktt_pid']);
|
||||
unset($_SESSION['stormquicktt_tid']);
|
||||
unset($_SESSION['stormquicktt_kid']);
|
||||
unset($_SESSION['stormquicktt_start']);
|
||||
}
|
||||
if ($oid) {
|
||||
$finish = ($stop) ? $stop : time();
|
||||
$minutes = ceil(($finish-$start) / 60);
|
||||
if ($minutes >= variable_get('stormquicktt_mintime2record', 5)) {
|
||||
if ($kid) {
|
||||
$type = t('Ticket');
|
||||
$node = node_load($kid);
|
||||
$name = $node->title;
|
||||
}
|
||||
elseif ($tid) {
|
||||
$type = t('Task');
|
||||
$node = node_load($tid);
|
||||
$name = $node->title;
|
||||
}
|
||||
elseif ($pid) {
|
||||
$type = t('Project');
|
||||
$node = node_load($pid);
|
||||
$name = $node->title;
|
||||
}
|
||||
elseif ($oid) {
|
||||
$type = t('Organization');
|
||||
$node = node_load($oid);
|
||||
$name = $node->title;
|
||||
}
|
||||
if (!isset($_SESSION['stormquicktt_ttid'])) {
|
||||
$node = new stdClass();
|
||||
$node->uid = $user->uid;
|
||||
$node->type = 'stormtimetracking';
|
||||
$node->title = $name .' ('. variable_get('stormquicktt_default_title', 'Auto-created by QuickTT') .')';
|
||||
$node->organization_nid = $oid;
|
||||
$node->project_nid = $pid;
|
||||
$node->task_nid = $tid;
|
||||
$node->ticket_nid = $kid;
|
||||
$node->trackingdate = $start;
|
||||
$node->timebegin = format_date($start, 'custom', 'H:i');
|
||||
$node->billable = variable_get('stormtimetracking_billable_default', FALSE);
|
||||
$node->billed = FALSE;
|
||||
}
|
||||
else {
|
||||
$node = node_load($_SESSION['stormquicktt_ttid']);
|
||||
}
|
||||
$node->revision = FALSE;
|
||||
$node->timeend = format_date($finish, 'custom', 'H:i');
|
||||
_stormtimetracking_beforesave($node);
|
||||
$old_stormtimetracking_auto_duration = variable_get('stormtimetracking_auto_duration', TRUE);
|
||||
variable_set('stormtimetracking_auto_duration', FALSE);
|
||||
$node->billing_duration = $node->duration - ($pause / 3600);
|
||||
if (empty($_SESSION['stormquicktt_note_for_time']) OR empty($node->body)) {
|
||||
$pos = FALSE;
|
||||
}
|
||||
else {
|
||||
$pos = strpos($_SESSION['stormquicktt_note_for_time'], $node->body);
|
||||
}
|
||||
if ($pos === FALSE) {
|
||||
$node->body .= $_SESSION['stormquicktt_note_for_time'];
|
||||
}
|
||||
else {
|
||||
$node->body = $_SESSION['stormquicktt_note_for_time'];
|
||||
}
|
||||
$_SESSION['stormquicktt_note_for_time'] = $node->body;
|
||||
node_save($node);
|
||||
variable_set('stormtimetracking_auto_duration', $old_stormtimetracking_auto_duration);
|
||||
if ($stop) {
|
||||
unset($_SESSION['stormquicktt_ttid']);
|
||||
}
|
||||
else {
|
||||
$_SESSION['stormquicktt_ttid'] = $node->nid;
|
||||
return '';
|
||||
}
|
||||
$destination = ($_GET['q'] == 'stormdashboard/interact') ? 'stormdashboard' : $_GET['q'];
|
||||
$link = l(t('edit'), 'node/'. $node->nid .'/edit', array('query' => array('destination' => $destination)));
|
||||
$msg = t('Time spent on %type %name: %min minutes (!edit).', array('%type' => $type, '%name' => $name, '%min' => $minutes, '!edit' => $link));
|
||||
}
|
||||
elseif (!$stop) {
|
||||
return '';
|
||||
}
|
||||
else {
|
||||
$msg = t('Time spent too short and not recorded.');
|
||||
}
|
||||
}
|
||||
drupal_get_messages(); //Clear messages to display only the following one.
|
||||
if ($show_msg) {
|
||||
drupal_set_message($msg);
|
||||
}
|
||||
$_SESSION['stormquicktt_pause_start'] = 0;
|
||||
$_SESSION['stormquicktt_pause_collect'] = 0;
|
||||
return '<div class="stormquicktt-message">'. $msg .'</div>';
|
||||
}
|
||||
|
||||
function stormquicktt_note_for_time($text) {
|
||||
$_SESSION['stormquicktt_note_for_time'] .= "<p>". $text ."</p>\n";
|
||||
}
|
||||
|
||||
function stormquicktt_tracking_active_nid() {
|
||||
if (!stormquicktt_tracking_active()) {
|
||||
return 0;
|
||||
}
|
||||
$oid = $_SESSION['stormquicktt_oid'];
|
||||
$pid = $_SESSION['stormquicktt_pid'];
|
||||
$tid = $_SESSION['stormquicktt_tid'];
|
||||
$kid = $_SESSION['stormquicktt_kid'];
|
||||
if ($kid) { //Ticket-ID is set and we get the other IDs from the node
|
||||
return $kid;
|
||||
}
|
||||
elseif ($tid) { //Task-ID is set and we get the other IDs from the node
|
||||
return $tid;
|
||||
}
|
||||
elseif ($pid) { //Project-ID is set and we get the other IDs from the node
|
||||
return $pid;
|
||||
}
|
||||
elseif ($oid) { //Organization-ID is set and we get the other IDs from the node
|
||||
return $oid;
|
||||
}
|
||||
else { //No ID is set which shouldn't be possible
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function stormquicktt_tracking_active_type() {
|
||||
if (!stormquicktt_tracking_active()) {
|
||||
return NULL;
|
||||
}
|
||||
$oid = $_SESSION['stormquicktt_oid'];
|
||||
$pid = $_SESSION['stormquicktt_pid'];
|
||||
$tid = $_SESSION['stormquicktt_tid'];
|
||||
$kid = $_SESSION['stormquicktt_kid'];
|
||||
if ($kid) { //Ticket-ID is set and we get the other IDs from the node
|
||||
return 'tkt';
|
||||
}
|
||||
elseif ($tid) { //Task-ID is set and we get the other IDs from the node
|
||||
return 'tsk';
|
||||
}
|
||||
elseif ($pid) { //Project-ID is set and we get the other IDs from the node
|
||||
return 'prj';
|
||||
}
|
||||
elseif ($oid) { //Organization-ID is set and we get the other IDs from the node
|
||||
return 'org';
|
||||
}
|
||||
else { //No ID is set which shouldn't be possible
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
function stormquicktt_tracking_active() {
|
||||
return !empty($_SESSION['stormquicktt_oid']);
|
||||
}
|
||||
|
||||
function stormquicktt_tracking_start() {
|
||||
return stormquicktt_tracking_active() ? $_SESSION['stormquicktt_start'] : 0;
|
||||
}
|
||||
|
||||
function stormquicktt_tracking_info() {
|
||||
$output = '';
|
||||
if (stormquicktt_tracking_active()) {
|
||||
$oid = $_SESSION['stormquicktt_oid'];
|
||||
$pid = $_SESSION['stormquicktt_pid'];
|
||||
$tid = $_SESSION['stormquicktt_tid'];
|
||||
$kid = $_SESSION['stormquicktt_kid'];
|
||||
$start = $_SESSION['stormquicktt_start'];
|
||||
if ($kid) { //Ticket-ID is set and we get the other IDs from the node
|
||||
$node = node_load($kid);
|
||||
$type = t('Ticket');
|
||||
}
|
||||
elseif ($tid) { //Task-ID is set and we get the other IDs from the node
|
||||
$node = node_load($tid);
|
||||
$type = t('Task');
|
||||
}
|
||||
elseif ($pid) { //Project-ID is set and we get the other IDs from the node
|
||||
$node = node_load($pid);
|
||||
$type = t('Project');
|
||||
}
|
||||
elseif ($oid) { //Organization-ID is set and we get the other IDs from the node
|
||||
$node = node_load($oid);
|
||||
$type = t('Organization');
|
||||
}
|
||||
else { //No ID is set which shouldn't be possible
|
||||
return '<div class="info">'. t('An error occured.') .'</div>';
|
||||
}
|
||||
$output .= '<div class="time">'. t('Started !time', array('!time' => stormquicktt_start_link())) .'</div>';
|
||||
$output .= '<div class="info">'. t('Timetracking is active for %type !title.', array('%type' => $type, '!title' => l($node->title, 'node/'.$node->nid))) .'</div>';
|
||||
$output .= '<div class="note">'. t('Take a note: !noteform', array('!noteform' => stormquicktt_noteform())) .'</div>';
|
||||
}
|
||||
else {
|
||||
$output .= '<div class="info">'. t('Currently not tracking any time.') .'</div>';
|
||||
}
|
||||
$output .= '';
|
||||
return $output;
|
||||
}
|
||||
|
||||
function stormquicktt_start_link() {
|
||||
if (!empty($_SESSION['stormquicktt_kid'])) {
|
||||
$nid = $_SESSION['stormquicktt_kid'];
|
||||
}
|
||||
elseif (!empty($_SESSION['stormquicktt_tid'])) {
|
||||
$nid = $_SESSION['stormquicktt_tid'];
|
||||
}
|
||||
elseif (!empty($_SESSION['stormquicktt_pid'])) {
|
||||
$nid = $_SESSION['stormquicktt_pid'];
|
||||
}
|
||||
elseif (!empty($_SESSION['stormquicktt_oid'])) {
|
||||
$nid = $_SESSION['stormquicktt_oid'];
|
||||
}
|
||||
if (!empty($nid)) {
|
||||
if (!empty($_SESSION['stormquicktt_pause_start'])) {
|
||||
$style_pause = ' style="display:none"';
|
||||
$style_resume = '';
|
||||
}
|
||||
else {
|
||||
$style_pause = '';
|
||||
$style_resume = ' style="display:none"';
|
||||
}
|
||||
$text_paused = '<span class="storm-quicktt-resume"'. $style_resume .'>'. t('Paused') .'</span>';
|
||||
/* $path = drupal_get_path('module', 'storm');
|
||||
$path = variable_get('storm_icons_path', drupal_get_path('module', 'storm') .'/icons');
|
||||
*/ $path = url(variable_get('storm_icons_path', drupal_get_path('module', 'storm') .'/icons'), array('absolute' => TRUE, 'language' => ''));
|
||||
$title_pause = t('Pause');
|
||||
$title_resume = t('Resume');
|
||||
|
||||
$text = '<div class="storm-quicktt-time">'. format_date($_SESSION['stormquicktt_start']) .'</div>';
|
||||
$text .= '<div class="storm-quicktt-timer-box"><span class="storm-quicktt-timer">'. stormquicktt_elapsed_time() .'</span>'. $text_paused .'</div>';
|
||||
$text .= '<span class="storm-quicktt-pause"'. $style_pause .'><img src="'. $path .'/status_on_hold.png" title="'. $title_pause .'" alt="'. $title_pause .'"/></span>';
|
||||
$text .= '<span class="storm-quicktt-resume"'. $style_resume .'><img src="'. $path .'/status_in_progress.png" title="'. $title_resume .'" alt="'. $title_resume .'"/></span>';
|
||||
$text .= stormquicktt_timetracking_trigger($nid, FALSE);
|
||||
return $text;
|
||||
}
|
||||
return format_date(time());
|
||||
}
|
||||
|
||||
function stormquicktt_noteform() {
|
||||
return '<div><form><input id="edit-storm-quicktt-note" type="text" size="40"/></form></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sanitized clickable icon to start/stop time tracking
|
||||
*/
|
||||
function stormquicktt_timetracking_trigger($nid = 0, $info = TRUE) {
|
||||
if (!user_access('Storm timetracking: add')) {
|
||||
return '';
|
||||
}
|
||||
stormquicktt_add_resources();
|
||||
$active = FALSE;
|
||||
if (!empty($nid) && stormquicktt_tracking_active() && stormquicktt_tracking_active_nid() == $nid) {
|
||||
$active = TRUE;
|
||||
}
|
||||
|
||||
if (!$active) {
|
||||
$title = t('Start time tracking.');
|
||||
$img_src = url(drupal_get_path('module', 'storm') .'/images/timetrackings.png', array('absolute' => TRUE, 'language' => ''));
|
||||
$class = "";
|
||||
$info_txt = ' '.t('Click to start timetracking');
|
||||
}
|
||||
else {
|
||||
$title = t('Stop time tracking.');
|
||||
$img_src = url(variable_get('storm_icons_path', drupal_get_path('module', 'storm') .'/icons') .'/dialog_close.png', array('absolute' => TRUE, 'language' => ''));
|
||||
$class = "timetracking-active";
|
||||
$info_txt = ' '.t('Click to stop timetracking');
|
||||
}
|
||||
if (!$info) {
|
||||
$info_txt = '';
|
||||
}
|
||||
return '<span id="storm-tt-'. $nid .'" class="sqtt-timetracking-trigger '.$class.' storm-tt-'. $nid .'"><span>'.
|
||||
'<img src="'. $img_src .'" title="'. $title .'" alt="'. $title .'"/>'.
|
||||
'</span>' . $info_txt . '</span>';
|
||||
}
|
||||
|
||||
function stormquicktt_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
|
||||
|
||||
if (!in_array($node->type, array('stormproject', 'stormorganization', 'stormtask', 'stormticket')) || !user_access('Storm timetracking: add')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($op == 'view') {
|
||||
$node->content['links']['stormquicktt_timetracking_trigger'] = array(
|
||||
'#value' => stormquicktt_timetracking_trigger($node->nid),
|
||||
'#weight' => 12,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue