Add project calendars (merge/refactoring of #490)
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -65,6 +65,22 @@ var Kanboard = (function() {
|
||||
return true;
|
||||
},
|
||||
|
||||
// Save preferences in local storage
|
||||
SetStorageItem: function(key, value) {
|
||||
if (typeof(Storage) !== "undefined") {
|
||||
localStorage.setItem(key, value);
|
||||
}
|
||||
},
|
||||
|
||||
GetStorageItem: function(key) {
|
||||
|
||||
if (typeof(Storage) !== "undefined") {
|
||||
return localStorage.getItem(key);
|
||||
}
|
||||
|
||||
return '';
|
||||
},
|
||||
|
||||
// Generate Markdown preview
|
||||
MarkdownPreview: function(e) {
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Board related functions
|
||||
Kanboard.Board = (function() {
|
||||
|
||||
var checkInterval = null;
|
||||
@@ -191,6 +190,7 @@ Kanboard.Board = (function() {
|
||||
var selectedUserId = $("#form-user_id").val();
|
||||
var selectedCategoryId = $("#form-category_id").val();
|
||||
var filterDueDate = $("#filter-due-date").hasClass("filter-on");
|
||||
var projectId = $('#board').data('project-id');
|
||||
|
||||
$("[data-task-id]").each(function(index, item) {
|
||||
|
||||
@@ -214,43 +214,36 @@ Kanboard.Board = (function() {
|
||||
}
|
||||
});
|
||||
|
||||
// Save filter settings for active project to localStorage
|
||||
if (typeof(Storage) !== "undefined") {
|
||||
var projectId = $('#board').data('project-id');
|
||||
localStorage.setItem("filters_" + projectId + "_form-user_id", selectedUserId);
|
||||
localStorage.setItem("filters_" + projectId + "_form-category_id", selectedCategoryId);
|
||||
localStorage.setItem("filters_" + projectId + "_filter-due-date", ~~(filterDueDate));
|
||||
}
|
||||
// Save filter settings
|
||||
Kanboard.SetStorageItem("board_filter_" + projectId + "_form-user_id", selectedUserId);
|
||||
Kanboard.SetStorageItem("board_filter_" + projectId + "_form-category_id", selectedCategoryId);
|
||||
Kanboard.SetStorageItem("board_filter_" + projectId + "_filter-due-date", ~~(filterDueDate));
|
||||
}
|
||||
|
||||
// Load filter events
|
||||
function filter_load_events()
|
||||
{
|
||||
var projectId = $('#board').data('project-id');
|
||||
|
||||
$("#form-user_id").change(filter_apply);
|
||||
|
||||
$("#form-category_id").change(filter_apply);
|
||||
|
||||
$("#filter-due-date").click(function(e) {
|
||||
$(this).toggleClass("filter-on");
|
||||
filter_apply();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
// Get and set filters from localStorage for active project
|
||||
if (typeof(Storage) !== "undefined") {
|
||||
var projectId = $('#board').data('project-id');
|
||||
|
||||
$("#form-user_id").val(localStorage.getItem("filters_" + projectId + "_form-user_id") || -1);
|
||||
$("#form-category_id").val(localStorage.getItem("filters_" + projectId + "_form-category_id") || -1);
|
||||
|
||||
if (+localStorage.getItem("filters_" + projectId + "_filter-due-date")) {
|
||||
$("#filter-due-date").addClass("filter-on");
|
||||
} else {
|
||||
$("#filter-due-date").removeClass("filter-on");
|
||||
}
|
||||
|
||||
filter_apply();
|
||||
// Get and set filters from localStorage
|
||||
$("#form-user_id").val(Kanboard.GetStorageItem("board_filter_" + projectId + "_form-user_id") || -1);
|
||||
$("#form-category_id").val(Kanboard.GetStorageItem("board_filter_" + projectId + "_form-category_id") || -1);
|
||||
|
||||
if (+Kanboard.GetStorageItem("board_filter_" + projectId + "_filter-due-date")) {
|
||||
$("#filter-due-date").addClass("filter-on");
|
||||
} else {
|
||||
$("#filter-due-date").removeClass("filter-on");
|
||||
}
|
||||
|
||||
filter_apply();
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
103
assets/js/calendar.js
Normal file
103
assets/js/calendar.js
Normal file
@@ -0,0 +1,103 @@
|
||||
Kanboard.Calendar = (function() {
|
||||
|
||||
// Show the empty calendar
|
||||
function show_calendar()
|
||||
{
|
||||
var calendar = $("#calendar");
|
||||
var translations = calendar.data("translations");
|
||||
|
||||
calendar.fullCalendar({
|
||||
editable: true,
|
||||
eventLimit: true,
|
||||
header: {
|
||||
left: 'prev,next today',
|
||||
center: 'title',
|
||||
right: ''
|
||||
},
|
||||
eventDrop: move_calendar_event,
|
||||
monthNames: [translations.January, translations.February, translations.March, translations.April, translations.May, translations.June, translations.July, translations.August, translations.September, translations.October, translations.November, translations.December],
|
||||
monthNamesShort: [translations.Jan, translations.Feb, translations.Mar, translations.Apr, translations.May, translations.Jun, translations.Jul, translations.Aug, translations.Sep, translations.Oct, translations.Nov, translations.Dec],
|
||||
buttonText: {today: translations.Today},
|
||||
dayNames: [translations.Sunday, translations.Monday, translations.Tuesday, translations.Wednesday, translations.Thursday, translations.Friday, translations.Saturday],
|
||||
dayNamesShort: [translations.Sun, translations.Mon, translations.Tue, translations.Wed, translations.Thu, translations.Fri, translations.Sat]
|
||||
});
|
||||
}
|
||||
|
||||
// Save the new due date for a moved task
|
||||
function move_calendar_event(calendar_event)
|
||||
{
|
||||
$.ajax({
|
||||
cache: false,
|
||||
url: $("#calendar").data("save-url"),
|
||||
contentType: "application/json",
|
||||
type: "POST",
|
||||
processData: false,
|
||||
data: JSON.stringify({
|
||||
"task_id": calendar_event.id,
|
||||
"date_due": calendar_event.start.format()
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// Refresh the calendar events
|
||||
function refresh_calendar(filters)
|
||||
{
|
||||
var calendar = $("#calendar");
|
||||
var url = calendar.data("check-url");
|
||||
var params = {
|
||||
"start": calendar.fullCalendar('getView').start.format(),
|
||||
"end": calendar.fullCalendar('getView').end.format()
|
||||
}
|
||||
|
||||
jQuery.extend(params, filters);
|
||||
|
||||
for (var key in params) {
|
||||
url += "&" + key + "=" + params[key];
|
||||
}
|
||||
|
||||
$.getJSON(url, function(events) {
|
||||
calendar.fullCalendar('removeEvents');
|
||||
calendar.fullCalendar('addEventSource', events);
|
||||
calendar.fullCalendar('rerenderEvents');
|
||||
});
|
||||
}
|
||||
|
||||
// Restore saved filters
|
||||
function load_filters()
|
||||
{
|
||||
var filters = Kanboard.GetStorageItem('calendar_filters');
|
||||
|
||||
if (filters !== "undefined" && filters !== "") {
|
||||
filters = JSON.parse(filters);
|
||||
|
||||
for (var filter in filters) {
|
||||
$("select[name=" + filter + "]").val(filters[filter]);
|
||||
}
|
||||
}
|
||||
|
||||
refresh_calendar(filters || {});
|
||||
|
||||
$('.calendar-filter').change(apply_filters);
|
||||
}
|
||||
|
||||
// Apply filters on change
|
||||
function apply_filters()
|
||||
{
|
||||
var filters = {};
|
||||
|
||||
$('.calendar-filter').each(function(index, element) {
|
||||
filters[$(this).attr("name")] = $(this).val();
|
||||
});
|
||||
|
||||
Kanboard.SetStorageItem("calendar_filters", JSON.stringify(filters));
|
||||
refresh_calendar(filters);
|
||||
}
|
||||
|
||||
return {
|
||||
Init: function() {
|
||||
show_calendar();
|
||||
load_filters();
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
8
assets/js/fullcalendar.min.js
vendored
Normal file
8
assets/js/fullcalendar.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -6,6 +6,9 @@ $(function() {
|
||||
if (Kanboard.Exists("board")) {
|
||||
Kanboard.Board.Init();
|
||||
}
|
||||
else if (Kanboard.Exists("calendar")) {
|
||||
Kanboard.Calendar.Init();
|
||||
}
|
||||
else if (Kanboard.Exists("task-section")) {
|
||||
Kanboard.Task.Init();
|
||||
}
|
||||
|
||||
6
assets/js/moment.min.js
vendored
Normal file
6
assets/js/moment.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user