@@ -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 }
0 commit comments