Added Markdown editor and Javascript code refactoring

This commit is contained in:
Frederic Guillot
2016-03-20 15:45:02 -04:00
parent 787e91ca41
commit f77d6c590b
64 changed files with 1154 additions and 3644 deletions

View File

@@ -1,5 +1,5 @@
// Based on jQuery.ganttView v.0.8.8 Copyright (c) 2010 JC Grubbs - jc.grubbs@devmynd.com - MIT License
function Gantt(app) {
Kanboard.Gantt = function(app) {
this.app = app;
this.data = [];
@@ -13,10 +13,16 @@ function Gantt(app) {
slideWidth: 1000,
vHeaderWidth: 200
};
}
};
Kanboard.Gantt.prototype.execute = function() {
if (this.app.hasId("gantt-chart")) {
this.show();
}
};
// Save record after a resize or move
Gantt.prototype.saveRecord = function(record) {
Kanboard.Gantt.prototype.saveRecord = function(record) {
this.app.showLoadingIcon();
$.ajax({
@@ -31,7 +37,7 @@ Gantt.prototype.saveRecord = function(record) {
};
// Build the Gantt chart
Gantt.prototype.execute = function() {
Kanboard.Gantt.prototype.show = function() {
this.data = this.prepareData($(this.options.container).data('records'));
var minDays = Math.floor((this.options.slideWidth / this.options.cellWidth) + 5);
@@ -60,7 +66,7 @@ Gantt.prototype.execute = function() {
};
// Render record list on the left
Gantt.prototype.renderVerticalHeader = function() {
Kanboard.Gantt.prototype.renderVerticalHeader = function() {
var headerDiv = jQuery("<div>", { "class": "ganttview-vtheader" });
var itemDiv = jQuery("<div>", { "class": "ganttview-vtheader-item" });
var seriesDiv = jQuery("<div>", { "class": "ganttview-vtheader-series" });
@@ -92,7 +98,7 @@ Gantt.prototype.renderVerticalHeader = function() {
};
// Render right part of the chart (top header + grid + bars)
Gantt.prototype.renderSlider = function(startDate, endDate) {
Kanboard.Gantt.prototype.renderSlider = function(startDate, endDate) {
var slideDiv = jQuery("<div>", {"class": "ganttview-slide-container"});
var dates = this.getDates(startDate, endDate);
@@ -105,7 +111,7 @@ Gantt.prototype.renderSlider = function(startDate, endDate) {
};
// Render top header (days)
Gantt.prototype.renderHorizontalHeader = function(dates) {
Kanboard.Gantt.prototype.renderHorizontalHeader = function(dates) {
var headerDiv = jQuery("<div>", { "class": "ganttview-hzheader" });
var monthsDiv = jQuery("<div>", { "class": "ganttview-hzheader-months" });
var daysDiv = jQuery("<div>", { "class": "ganttview-hzheader-days" });
@@ -135,7 +141,7 @@ Gantt.prototype.renderHorizontalHeader = function(dates) {
};
// Render grid
Gantt.prototype.renderGrid = function(dates) {
Kanboard.Gantt.prototype.renderGrid = function(dates) {
var gridDiv = jQuery("<div>", { "class": "ganttview-grid" });
var rowDiv = jQuery("<div>", { "class": "ganttview-grid-row" });
@@ -162,7 +168,7 @@ Gantt.prototype.renderGrid = function(dates) {
};
// Render bar containers
Gantt.prototype.addBlockContainers = function() {
Kanboard.Gantt.prototype.addBlockContainers = function() {
var blocksDiv = jQuery("<div>", { "class": "ganttview-blocks" });
for (var i = 0; i < this.data.length; i++) {
@@ -173,7 +179,7 @@ Gantt.prototype.addBlockContainers = function() {
};
// Render bars
Gantt.prototype.addBlocks = function(slider, start) {
Kanboard.Gantt.prototype.addBlocks = function(slider, start) {
var rows = jQuery("div.ganttview-blocks div.ganttview-block-container", slider);
var rowIdx = 0;
@@ -219,7 +225,7 @@ Gantt.prototype.addBlocks = function(slider, start) {
};
// Get tooltip for vertical header
Gantt.prototype.getVerticalHeaderTooltip = function(record) {
Kanboard.Gantt.prototype.getVerticalHeaderTooltip = function(record) {
var tooltip = "";
if (record.type == "task") {
@@ -246,7 +252,7 @@ Gantt.prototype.getVerticalHeaderTooltip = function(record) {
};
// Get tooltip for bars
Gantt.prototype.getBarTooltip = function(record) {
Kanboard.Gantt.prototype.getBarTooltip = function(record) {
var tooltip = "";
if (record.not_defined) {
@@ -266,7 +272,7 @@ Gantt.prototype.getBarTooltip = function(record) {
};
// Set bar color
Gantt.prototype.setBarColor = function(block, record) {
Kanboard.Gantt.prototype.setBarColor = function(block, record) {
if (record.not_defined) {
block.addClass("ganttview-block-not-defined");
}
@@ -277,7 +283,7 @@ Gantt.prototype.setBarColor = function(block, record) {
};
// Setup jquery-ui resizable
Gantt.prototype.listenForBlockResize = function(startDate) {
Kanboard.Gantt.prototype.listenForBlockResize = function(startDate) {
var self = this;
jQuery("div.ganttview-block", this.options.container).resizable({
@@ -293,7 +299,7 @@ Gantt.prototype.listenForBlockResize = function(startDate) {
};
// Setup jquery-ui drag and drop
Gantt.prototype.listenForBlockMove = function(startDate) {
Kanboard.Gantt.prototype.listenForBlockMove = function(startDate) {
var self = this;
jQuery("div.ganttview-block", this.options.container).draggable({
@@ -309,7 +315,7 @@ Gantt.prototype.listenForBlockMove = function(startDate) {
};
// Update the record data and the position on the chart
Gantt.prototype.updateDataAndPosition = function(block, startDate) {
Kanboard.Gantt.prototype.updateDataAndPosition = function(block, startDate) {
var container = jQuery("div.ganttview-slide-container", this.options.container);
var scroll = container.scrollLeft();
var offset = block.offset().left - container.offset().left - 1 + scroll;
@@ -349,7 +355,7 @@ Gantt.prototype.updateDataAndPosition = function(block, startDate) {
// Creates a 3 dimensional array [year][month][day] of every day
// between the given start and end dates
Gantt.prototype.getDates = function(start, end) {
Kanboard.Gantt.prototype.getDates = function(start, end) {
var dates = [];
dates[start.getFullYear()] = [];
dates[start.getFullYear()][start.getMonth()] = [start];
@@ -374,7 +380,7 @@ Gantt.prototype.getDates = function(start, end) {
};
// Convert data to Date object
Gantt.prototype.prepareData = function(data) {
Kanboard.Gantt.prototype.prepareData = function(data) {
for (var i = 0; i < data.length; i++) {
var start = new Date(data[i].start[0], data[i].start[1] - 1, data[i].start[2], 0, 0, 0, 0);
data[i].start = start;
@@ -387,7 +393,7 @@ Gantt.prototype.prepareData = function(data) {
};
// Get the start and end date from the data provided
Gantt.prototype.getDateRange = function(minDays) {
Kanboard.Gantt.prototype.getDateRange = function(minDays) {
var minStart = new Date();
var maxEnd = new Date();
@@ -425,7 +431,7 @@ Gantt.prototype.getDateRange = function(minDays) {
};
// Returns the number of day between 2 dates
Gantt.prototype.daysBetween = function(start, end) {
Kanboard.Gantt.prototype.daysBetween = function(start, end) {
if (! start || ! end) {
return 0;
}
@@ -441,17 +447,17 @@ Gantt.prototype.daysBetween = function(start, end) {
};
// Return true if it's the weekend
Gantt.prototype.isWeekend = function(date) {
Kanboard.Gantt.prototype.isWeekend = function(date) {
return date.getDay() % 6 == 0;
};
// Clone Date object
Gantt.prototype.cloneDate = function(date) {
Kanboard.Gantt.prototype.cloneDate = function(date) {
return new Date(date.getTime());
};
// Add days to a Date object
Gantt.prototype.addDays = function(date, value) {
Kanboard.Gantt.prototype.addDays = function(date, value) {
date.setDate(date.getDate() + value * 1);
return date;
};
@@ -463,7 +469,7 @@ Gantt.prototype.addDays = function(date, value) {
* 0 = values are equal
* 1 = date1 is greaterthan date2.
*/
Gantt.prototype.compareDate = function(date1, date2) {
Kanboard.Gantt.prototype.compareDate = function(date1, date2) {
if (isNaN(date1) || isNaN(date2)) {
throw new Error(date1 + " - " + date2);
} else if (date1 instanceof Date && date2 instanceof Date) {