forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgradingPeriod.js
More file actions
105 lines (94 loc) · 3.49 KB
/
Copy pathgradingPeriod.js
File metadata and controls
105 lines (94 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import tz from 'timezone'
import React from 'react'
import $ from 'jquery'
import I18n from 'i18n!external_tools'
import _ from 'underscore'
import GradingPeriodTemplate from 'jsx/grading/gradingPeriodTemplate'
import DateHelper from 'jsx/shared/helpers/dateHelper'
var Types = React.PropTypes;
var GradingPeriod = React.createClass({
propTypes: {
title: Types.string.isRequired,
weight: Types.number,
weighted: Types.bool.isRequired,
startDate: Types.instanceOf(Date).isRequired,
endDate: Types.instanceOf(Date).isRequired,
closeDate: Types.instanceOf(Date).isRequired,
id: Types.string.isRequired,
updateGradingPeriodCollection: Types.func.isRequired,
onDeleteGradingPeriod: Types.func.isRequired,
disabled: Types.bool.isRequired,
readOnly: Types.bool.isRequired,
permissions: Types.shape({
update: Types.bool.isRequired,
delete: Types.bool.isRequired,
}).isRequired
},
getDefaultProps () {
return {
weight: null
};
},
getInitialState: function(){
return {
title: this.props.title,
startDate: this.props.startDate,
endDate: this.props.endDate,
weight: this.props.weight
};
},
componentWillReceiveProps: function(nextProps) {
this.setState({
title: nextProps.title,
startDate: nextProps.startDate,
endDate: nextProps.endDate,
weight: nextProps.weight
});
},
onTitleChange: function(event) {
this.setState({title: event.target.value}, function () {
this.props.updateGradingPeriodCollection(this);
});
},
onDateChange: function(dateType, id) {
var $date = $("#" + id);
var isValidDate = ! ( $date.data('invalid') ||
$date.data('blank') );
var updatedDate = isValidDate ?
$date.data('unfudged-date') :
new Date('invalid date');
if (dateType === "endDate" && DateHelper.isMidnight(updatedDate)) {
updatedDate = tz.changeToTheSecondBeforeMidnight(updatedDate);
}
var updatedState = {};
updatedState[dateType] = updatedDate;
this.setState(updatedState, function() {
this.replaceInputWithDate(dateType, $date);
this.props.updateGradingPeriodCollection(this);
});
},
replaceInputWithDate: function(dateType, dateElement) {
var date = this.state[dateType];
dateElement.val(DateHelper.formatDatetimeForDisplay(date));
},
render: function () {
return (
<GradingPeriodTemplate key={this.props.id}
ref="template"
id={this.props.id}
title={this.props.title}
weight={this.props.weight}
weighted={this.props.weighted}
startDate={this.props.startDate}
endDate={this.props.endDate}
closeDate={this.props.closeDate || this.props.endDate}
permissions={this.props.permissions}
disabled={this.props.disabled}
readOnly={this.props.readOnly}
onDeleteGradingPeriod={this.props.onDeleteGradingPeriod}
onDateChange={this.onDateChange}
onTitleChange={this.onTitleChange}/>
);
}
});
export default GradingPeriod