Skip to content

Commit

Permalink
replace planning listYear by a 10years list; fix #1281
Browse files Browse the repository at this point in the history
  • Loading branch information
orthagh committed Jan 12, 2017
1 parent 2868ceb commit 4bb3503
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 69 deletions.
5 changes: 4 additions & 1 deletion inc/commonitiltask.class.php
Expand Up @@ -942,7 +942,10 @@ static function genericPopulatePlanning($itemtype, $options=array()) {

$DONE_EVENTS = '';
if (!$options['display_done_events']) {
$DONE_EVENTS = "`".$item->getTable()."`.`state` != ".Planning::DONE." AND";
$DONE_EVENTS = "(`".$item->getTable()."`.`state` = ".Planning::TODO."
OR (`".$item->getTable()."`.`state` = ".Planning::INFO."
AND `".$item->getTable()."`.`end` > NOW()))
AND ";
}

$addrestrict = '';
Expand Down
102 changes: 83 additions & 19 deletions inc/planning.class.php
Expand Up @@ -547,13 +547,15 @@ static function showPlanning($fullview = true) {
$header = "{
left: 'prev,next,today',
center: 'title',
right: 'month,agendaWeek,agendaDay,listYear'
right: 'month,agendaWeek,agendaDay,listFull'
}";
$default_date = 'null';
} else {
$default_view = "listYear";
$default_view = "listFull";
$header = "false";
$pl_height = "400";
$rand = rand();
$default_date = "moment().subtract(5, 'years')";
}

echo "<div id='planning$rand'></div>";
Expand All @@ -572,15 +574,36 @@ static function showPlanning($fullview = true) {
var window_focused = true;
var loaded = false;
var lastView;
var lastDate;
var lastDateDirty = false;
window.onblur = function() { window_focused = false; }
window.onfocus = function() { window_focused = true; }
// datepicker for planning
var initFCDatePicker = function() {
$('#planning_datepicker').datepicker({
changeMonth: true,
changeYear: true,
numberOfMonths: 3,
showOn: 'button',
buttonImage: '".$CFG_GLPI['root_doc']."/pics/calendar.png',
buttonImageOnly: true,
dateFormat: 'DD, d MM, yy',
onSelect: function(dateText, inst) {
var selected_date = $(this).datepicker('getDate');
$('#planning').fullCalendar('gotoDate', selected_date);
}
});
}
$('#planning$rand').fullCalendar({
height: $pl_height,
theme: true,
weekNumbers: ".($fullview?'true':'false').",
defaultView: '$default_view',
timeFormat: 'H:mm',
defaultDate: $default_date,
eventLimit: true, // show 'more' button when too mmany events
minTime: '".$CFG_GLPI['planning_begin']."',
maxTime: '".$CFG_GLPI['planning_end']."',
Expand All @@ -598,6 +621,11 @@ static function showPlanning($fullview = true) {
},
agendaDay: {
titleFormat: '$date_format'
},
listFull: {
type: 'list',
duration: { years: 10 },
titleFormat: '[]',
}
},
viewRender: function(view){ // on date changes, replicate to datepicker
Expand All @@ -611,7 +639,9 @@ static function showPlanning($fullview = true) {
var content = event.content;
var tooltip = event.tooltip;
if(view.name !== 'month' && view.name !== 'listYear' && !event.allDay){
if(view.name !== 'month'
&& view.name.indexOf('list') < 0
&& !event.allDay){
element
.append('<div class=\"content\">'+content+'</div>');
}
Expand All @@ -638,7 +668,7 @@ static function showPlanning($fullview = true) {
var qtip_position = {
viewport: 'auto'
};
if (view.name === 'listYear') {
if (view.name.indexOf('list') >= 0) {
qtip_position.target= element.find('a');
}
element.qtip({
Expand Down Expand Up @@ -670,6 +700,52 @@ classes: 'qtip-shadow qtip-bootstrap'
if (loaded) {
$('#planning$rand').fullCalendar('refetchEvents')
}
// specific process for full list
if (view.name == 'listFull') {
// hide datepick on full list (which have virtually no limit)
$('#planning_datepicker').datepicker('destroy')
.hide();
// hide control buttons
$('#planning .fc-left .fc-button-group').hide();
// set date to today - 5 years
if (!lastDateDirty) {
lastDate = $('#planning').fullCalendar('getDate');
// tag lastDate to dirty as viewRender will be called again with gotoDate
lastDateDirty = true
$('#planning').fullCalendar('gotoDate',
moment().subtract(5, 'years'));
}
} else {
// reinit datepicker
$('#planning_datepicker').show();
initFCDatePicker();
// show controls buttons
$('#planning .fc-left .fc-button-group').show();
// return to previous save date
if (lastView != view.name
&& !lastDateDirty
&& typeof lastDate != 'undefined'
&& lastDate != $('#planning').fullCalendar('getDate')) {
// tag lastDate to dirty as viewRender will be called again with gotoDate
lastDateDirty = true
$('#planning').fullCalendar('gotoDate', lastDate);
}
lastDate = $('#planning').fullCalendar('getDate');
//console.log(lastDate);
}
// remove dirty on lastDate
lastDateDirty = false
// store current view name (to avoid a new call of gotoDate)
lastView = view.name;
},
eventAfterAllRender: function(view) {
// set a var to force refetch events (see viewRender callback)
Expand All @@ -696,7 +772,7 @@ classes: 'qtip-shadow qtip-bootstrap'
data: function() {
var view_name = $('#planning$rand').fullCalendar('getView').name;
var display_done_events = 1;
if (view_name == 'listYear') {
if (view_name.indexOf('list') >= 0) {
display_done_events = 0;
}
return {
Expand Down Expand Up @@ -842,20 +918,8 @@ function() {
$('#planning$rand').fullCalendar('refetchEvents')
})
// datepicker behavior
$('#planning_datepicker').datepicker({
changeMonth: true,
changeYear: true,
numberOfMonths: 3,
showOn: 'button',
buttonImage: '".$CFG_GLPI['root_doc']."/pics/calendar.png',
buttonImageOnly: true,
dateFormat: 'DD, d MM, yy',
onSelect: function(dateText, inst) {
var selected_date = $(this).datepicker('getDate');
$('#planning$rand').fullCalendar('gotoDate', selected_date);
}
});
// attach the date picker to planning
initFCDatePicker()
});"
);
return;
Expand Down
4 changes: 3 additions & 1 deletion inc/reminder.class.php
Expand Up @@ -878,7 +878,9 @@ static function populatePlanning($options=array()) {

$DONE_EVENTS = '';
if (!$options['display_done_events']) {
$DONE_EVENTS = "AND state != ".Planning::DONE;
$DONE_EVENTS = "AND (state = ".Planning::TODO."
OR (state = ".Planning::INFO."
AND `end` > NOW()))";
}

if ($ASSIGN) {
Expand Down
11 changes: 11 additions & 0 deletions lib/jqueryplugins/fullcalendar/CHANGELOG.txt
@@ -1,4 +1,15 @@

v3.0.1 (2016-09-26)
-------------------

Bugfixes:
- list view rendering event times incorrectly (#3334)
- list view rendering events/days out of order (#3347)
- events with no title rendering as "undefined"
- add .fc scope to table print styles (#3343)
- "display no events" text fix for German (#3354)


v3.0.0 (2016-09-04)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion lib/jqueryplugins/fullcalendar/demos/gcal.html
Expand Up @@ -20,7 +20,7 @@
right: 'month,listYear'
},

listTime: false, // don't show the time column in list view
displayEventTime: false, // don't show the time column in list view

// THIS KEY WON'T WORK IN PRODUCTION!!!
// To make your own Google API key, follow the directions here:
Expand Down
2 changes: 1 addition & 1 deletion lib/jqueryplugins/fullcalendar/fullcalendar.css
@@ -1,5 +1,5 @@
/*!
* FullCalendar v3.0.0 Stylesheet
* FullCalendar v3.0.1 Stylesheet
* Docs & License: http://fullcalendar.io/
* (c) 2016 Adam Shaw
*/
Expand Down

0 comments on commit 4bb3503

Please sign in to comment.