Skip to content
This repository was archived by the owner on Aug 27, 2018. It is now read-only.

Commit af8e823

Browse files
committed
Add save/cancel button to lesson hours expansion panel
1 parent 0f695b1 commit af8e823

File tree

10 files changed

+394
-216
lines changed

10 files changed

+394
-216
lines changed

3-panel/src/imports/materialdesign/components/TimePicker/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export default class TimePicker extends Component {
8585

8686
if (hoursTickIndex < 0) console.log('cant find hour tick index')
8787
if (minutesTickIndex < 0) console.log('cant find minutes tick index')
88-
console.log(hoursTickIndex, minutesTickIndex)
8988

9089
const hoursTick = hoursClock.ticks[hoursTickIndex]
9190
const minutesTick = minutesClock.ticks[minutesTickIndex]

3-panel/src/views/Pages/LessonsPlan/components/AddLessonDialog/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ export default class AddLessonDialog extends Component {
5959
const error = DialogManager.checkForErrors(this)
6060

6161
if (!error) {
62-
lessonsPlanPage.lessonsPlan[index].subjects.push(this.textField.getValue())
62+
lessonsPlanPage.lessonsPlan.plan[index].subjects.push(this.textField.getValue())
6363
this.day.addSubjects()
64-
this.day.toggleActionButtons(true)
64+
this.day.isEdited = true
65+
lessonsPlanPage.toggleActionButtons(true, this.day.actionButtons)
6566

6667
dialog.toggle(false)
6768
}

3-panel/src/views/Pages/LessonsPlan/components/Day/components/Subject/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ export default class Subject extends Component {
7171
this.touched = true
7272
}
7373

74+
setTime () {
75+
const day = this.props.getDay()
76+
const lessonsPlanPage = day.props.getLessonsPlanPage()
77+
78+
const indexInSubjects = day.subjects.indexOf(this)
79+
const index = (indexInSubjects < 0) ? day.subjects.length : indexInSubjects
80+
81+
this.elements.hour.innerHTML = lessonsPlanPage.lessonsPlan.start[index] + ' - ' + lessonsPlanPage.lessonsPlan.finish[index]
82+
}
83+
7484
render () {
7585
return (
7686
<div className='subject' ref='root' onMouseDown={this.onMouseDown} onMouseEnter={this.onMouseEnter}>
@@ -88,13 +98,10 @@ export default class Subject extends Component {
8898
afterRender () {
8999
const props = this.props
90100
const day = props.getDay()
91-
const lessonsPlanPage = day.props.getLessonsPlanPage()
92101

102+
this.setTime()
93103
day.subjects.push(this)
94104

95-
const index = day.subjects.length - 1
96-
this.elements.hour.innerHTML = lessonsPlanPage.lessonsStart[index] + ' - ' + lessonsPlanPage.lessonsFinish[index]
97-
98105
if (props.menuIconRippleStyle == null) {
99106
props.menuIconRippleStyle = {
100107
backgroundColor: '#000',

3-panel/src/views/Pages/LessonsPlan/components/Day/index.js

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default class Day extends Component {
1616

1717
this.lastEnteredSubject = null
1818

19+
this.isEdited = false
1920
this.isSaving = false
2021

2122
this.materialButtonRippleStyle = {
@@ -77,23 +78,24 @@ export default class Day extends Component {
7778
* @param {Subject} moved subject
7879
*/
7980
toggleMovingMode (flag, subject) {
81+
const lessonsPlanPage = this.props.getLessonsPlanPage()
82+
8083
if (flag) {
8184
this.isMovingMode = true
8285
this.movedSubject = subject
8386

8487
window.addEventListener('mouseup', this.onWindowMouseUp)
8588

86-
this.toggleActionButtons(true)
89+
this.isEdited = true
90+
lessonsPlanPage.toggleActionButtons(true, this.actionButtons)
8791
} else {
8892
window.removeEventListener('mouseup', this.onWindowMouseUp)
8993

9094
if (this.lastEnteredSubject != null) {
9195
const oldIndex = this.subjects.indexOf(this.movedSubject)
9296
const newIndex = this.subjects.indexOf(this.lastEnteredSubject)
9397

94-
const lessonsPlanPage = this.props.getLessonsPlanPage()
95-
96-
lessonsPlanPage.lessonsPlan[lessonsPlanPage.days.indexOf(this)].subjects = this.props.data.subjects.move(oldIndex, newIndex)
98+
lessonsPlanPage.lessonsPlan.plan[lessonsPlanPage.days.indexOf(this)].subjects = this.props.data.subjects.move(oldIndex, newIndex)
9799

98100
this.clearBorderFromLastEnterSubject()
99101
this.addSubjects()
@@ -133,11 +135,12 @@ export default class Day extends Component {
133135
const lessonsPlanPage = this.props.getLessonsPlanPage()
134136

135137
const index = lessonsPlanPage.days.indexOf(this)
136-
lessonsPlanPage.lessonsPlan[index].subjects = JSON.parse(JSON.stringify(lessonsPlanPage.lessonsPlanCopy[index])).subjects // Same weird problem. Can't clone object copy of lessons plan.
138+
lessonsPlanPage.lessonsPlan.plan[index].subjects = JSON.parse(JSON.stringify(lessonsPlanPage.lessonsPlanCopy.plan[index])).subjects // Same weird problem. Can't clone object copy of lessons plan.
137139

138140
this.addSubjects()
141+
this.isEdited = false
139142

140-
this.toggleActionButtons(false)
143+
lessonsPlanPage.toggleActionButtons(false, this.actionButtons)
141144
}
142145
}
143146

@@ -149,32 +152,42 @@ export default class Day extends Component {
149152
onSaveButtonClick = (e) => {
150153
const self = this
151154

152-
const subjectsContainer = this.subjectsContainer
153-
const buttonsContainer = this.buttonsContainer
154-
155155
const lessonsPlanPage = this.props.getLessonsPlanPage()
156-
const preloaderRoot = this.preloader.getRoot()
156+
const lessonHours = lessonsPlanPage.elements.lessonHours
157157

158-
subjectsContainer.style.opacity = '0'
159-
subjectsContainer.classList.add('disable-cursor-pointer')
160-
161-
buttonsContainer.style.height = '0px'
162-
this.toggleActionButtons(false)
158+
lessonsPlanPage.toggleSavingAnimation(true, this)
163159
this.isSaving = true
160+
this.isEdited = false
164161

165-
preloaderRoot.style.display = 'block'
162+
const edited = []
166163

167-
setTimeout(function () {
168-
subjectsContainer.style.opacity = '1'
169-
subjectsContainer.classList.remove('disable-cursor-pointer')
164+
if (lessonHours.isEdited) {
165+
edited.push(lessonHours)
166+
lessonsPlanPage.toggleSavingAnimation(true, lessonHours)
167+
}
170168

171-
buttonsContainer.style.height = buttonsContainer.scrollHeight + 'px'
169+
for (var i = 0; i < lessonsPlanPage.days.length; i++) {
170+
const day = lessonsPlanPage.days[i]
172171

173-
self.isSaving = false
172+
if (day.isEdited) {
173+
edited.push(day)
174+
lessonsPlanPage.toggleSavingAnimation(true, day)
175+
}
176+
}
174177

175-
preloaderRoot.style.display = 'none'
178+
setTimeout(function () {
179+
self.isSaving = false
176180

177181
lessonsPlanPage.lessonsPlanCopy = JSON.parse(JSON.stringify(lessonsPlanPage.lessonsPlan))
182+
lessonsPlanPage.toggleActionButtons(false, lessonsPlanPage.elements.lessonHours.actionButtons)
183+
lessonsPlanPage.toggleSavingAnimation(false, self)
184+
185+
for (var i = 0; i < edited.length; i++) {
186+
edited[i].isEdited = false
187+
lessonsPlanPage.toggleSavingAnimation(false, edited[i])
188+
}
189+
190+
lessonHours.isEdited = false
178191
}, 1000)
179192
}
180193

@@ -186,12 +199,15 @@ export default class Day extends Component {
186199

187200
const length = this.props.data.subjects.length + 1
188201

189-
if (lessonsPlanPage.lessonsStart.length < length) {
190-
error = 'Brakuje godziny rozpoczynającej lekcję (po ' + lessonsPlanPage.lessonsStart[lessonsPlanPage.lessonsStart.length - 1] + ')'
202+
const lessonsPlanStart = lessonsPlanPage.lessonsPlan.start
203+
const lessonsPlanFinish = lessonsPlanPage.lessonsPlan.finish
204+
205+
if (lessonsPlanStart.length < length) {
206+
error = 'Brakuje godziny rozpoczynającej lekcję (po ' + lessonsPlanStart[lessonsPlanStart.length - 1] + ')'
191207
}
192208

193-
if (lessonsPlanPage.lessonsFinish.length < length) {
194-
error = ((error) ? (error + '<br>') : '') + 'Brakuje godziny kończącej lekcję (' + lessonsPlanPage.lessonsFinish[lessonsPlanPage.lessonsFinish.length - 1] + ')'
209+
if (lessonsPlanFinish.length < length) {
210+
error = ((error) ? (error + '<br>') : '') + 'Brakuje godziny kończącej lekcję (' + lessonsPlanFinish[lessonsPlanFinish.length - 1] + ')'
195211
}
196212

197213
if (!error) {
@@ -201,20 +217,6 @@ export default class Day extends Component {
201217
}
202218
}
203219

204-
/**
205-
* Shows or hides action buttons container (save and cancel)
206-
* @param {Boolean}
207-
*/
208-
toggleActionButtons (flag) {
209-
const actionButtons = this.actionButtons
210-
211-
actionButtons.style[(flag) ? 'display' : 'opacity'] = (flag) ? 'block' : '0'
212-
213-
setTimeout(function () {
214-
actionButtons.style[(flag) ? 'opacity' : 'display'] = (flag) ? '1' : 'none'
215-
}, (flag) ? 20 : 300)
216-
}
217-
218220
render () {
219221
return (
220222
<ExpansionPanel className='day-expansion-panel' ref='root'>
@@ -228,9 +230,10 @@ export default class Day extends Component {
228230
}} />
229231
</div>
230232
<MaterialButton className='add' text='DODAJ' onClick={this.onAddButtonClick} shadow={false} rippleStyle={this.materialButtonRippleStyle} />
231-
<div className='clear-both' />
232233
</div>
233-
<Preloader ref={(e) => { this.preloader = e }} />
234+
<div className='preloader-container' ref={(e) => { this.preloaderContainer = e }}>
235+
<Preloader ref={(e) => { this.preloader = e }} />
236+
</div>
234237
</ExpansionPanel>
235238
)
236239
}
Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
.day-expansion-panel {
22
& .subjects-container {
3-
opacity: 1;
4-
transition: 0.3s opacity;
5-
63
& .subject {
74
width: 100%;
85
padding-top: 15px;
@@ -44,57 +41,5 @@
4441
border-bottom: $border;
4542
}
4643
}
47-
48-
&.disable-cursor-pointer .subject {
49-
cursor: default;
50-
51-
& .menu-icon {
52-
cursor: default;
53-
}
54-
}
55-
}
56-
57-
& .buttons-container {
58-
width: 100%;
59-
height: 37px;
60-
position: relative;
61-
transition: 0.3s ease height;
62-
margin-top: 8px;
63-
margin-bottom: 8px;
64-
overflow: hidden;
65-
66-
& .action-buttons {
67-
width: 192px;
68-
float: right;
69-
display: none;
70-
opacity: 0;
71-
transition: 0.3s opacity;
72-
}
73-
74-
& .material-button {
75-
float: right;
76-
margin-right: 8px;
77-
background-color: transparent;
78-
color: #3f51b5;
79-
padding-left: 10px;
80-
padding-right: 10px;
81-
82-
&.cancel {
83-
color: #000;
84-
}
85-
86-
&.add {
87-
margin-left: 8px;
88-
float: left;
89-
}
90-
}
91-
}
92-
93-
& .material-preloader {
94-
position: absolute;
95-
@include center;
96-
width: 54px;
97-
height: 54px;
98-
display: none;
9944
}
10045
}

3-panel/src/views/Pages/LessonsPlan/components/ExpansionPanel/style.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@
4242
}
4343
}
4444
}
45+
46+
& .content {
47+
position: relative;
48+
}
4549
}

3-panel/src/views/Pages/LessonsPlan/components/LessonHours/components/Item/index.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ export default class Item extends Component {
99
return this.elements.root
1010
}
1111

12-
editStart = (e) => {
12+
toggleEditing (time, isStart) {
1313
const app = window.app
14+
const lessonsPlanPage = this.props.getLessonsPlanPage()
1415
const timePicker = app.elements.timePicker
1516

16-
const time = this.props.start
1717
const split = time.split('.')
1818
let hour = split[0]
1919
const minutes = split[1]
@@ -27,23 +27,30 @@ export default class Item extends Component {
2727

2828
timePicker.setTime(hour, minutes)
2929
timePicker.toggle(true, false)
30+
31+
lessonsPlanPage.editedTime = {
32+
time: time,
33+
start: isStart,
34+
item: this
35+
}
36+
}
37+
38+
setTime () {
39+
this.elements.start.innerHTML = this.props.start
40+
this.elements.finish.innerHTML = this.props.finish
3041
}
3142

3243
render () {
3344
return (
3445
<div className='item'>
35-
<div className='start' ref='start' onClick={this.editStart} />
36-
<div className='finish' ref='finish' />
46+
<div className='start' ref='start' onClick={() => { this.toggleEditing(this.props.start, true) }} />
47+
<div className='finish' ref='finish' onClick={() => { this.toggleEditing(this.props.finish, false) }} />
3748
</div>
3849
)
3950
}
4051

4152
afterRender () {
42-
const props = this.props
43-
44-
props.getLessonHours().items.push(this)
45-
46-
this.elements.start.innerHTML = props.start
47-
this.elements.finish.innerHTML = props.finish
53+
this.setTime()
54+
this.props.getLessonHours().items.push(this)
4855
}
4956
}

0 commit comments

Comments
 (0)