11$ ( ( ) => {
2+ let form ;
3+ let $movieInfoContainer ;
4+
25 $ ( '#scheduler' ) . dxScheduler ( {
36 timeZone : 'America/Los_Angeles' ,
47 dataSource : data ,
@@ -12,10 +15,8 @@ $(() => {
1215 height : 600 ,
1316 groups : [ 'theatreId' ] ,
1417 crossScrollingEnabled : true ,
18+ maxAppointmentsPerCell : 1 ,
1519 cellDuration : 20 ,
16- editing : {
17- allowAdding : false ,
18- } ,
1920 resources : [ {
2021 fieldExpr : 'movieId' ,
2122 dataSource : moviesData ,
@@ -24,85 +25,88 @@ $(() => {
2425 fieldExpr : 'theatreId' ,
2526 dataSource : theatreData ,
2627 } ] ,
27- appointmentTooltipTemplate ( model ) {
28- return getTooltipTemplate ( getMovieById ( model . targetedAppointmentData . movieId ) ) ;
28+ appointmentTemplate,
29+ appointmentTooltipTemplate : ( model ) => {
30+ const movie = getMovieById ( model . targetedAppointmentData . movieId ) ;
31+ return movieInfoTemplate ( movie ) ;
2932 } ,
30- appointmentTemplate ( model ) {
31- const movieInfo = getMovieById ( model . targetedAppointmentData . movieId ) || { } ;
33+ onAppointmentFormOpening ( e ) {
34+ form = e . form ;
35+ window . x = form ;
3236
33- return $ ( `${ "<div class='showtime-preview'>"
34- + '<div>' } ${ movieInfo . text } </div>`
35- + `<div>Ticket Price: <strong>$${ model . targetedAppointmentData . price } </strong>`
36- + '</div>'
37- + `<div>${ DevExpress . localization . formatDate ( model . targetedAppointmentData . displayStartDate , 'shortTime' )
38- } - ${ DevExpress . localization . formatDate ( model . targetedAppointmentData . displayEndDate , 'shortTime' )
39- } </div>`
40- + '</div>' ) ;
37+ form . on ( 'fieldDataChanged' , ( e ) => {
38+ if ( e . dataField === 'startDate' ) {
39+ const movie = getMovieById ( form . option ( 'formData' ) . movieId ) ;
40+ updateEndDate ( form , movie ) ;
41+ }
42+ } ) ;
4143 } ,
42- onAppointmentFormOpening ( data ) {
43- const { form } = data ;
44- let movieInfo = getMovieById ( data . appointmentData . movieId ) || { } ;
45- let { startDate } = data . appointmentData ;
44+ editing : {
45+ allowAdding : false ,
46+ form : {
47+ items : [
48+ {
49+ template : ( ) => {
50+ $movieInfoContainer = $ ( '<div class="movie-info-container">' ) ;
51+ return $movieInfoContainer ;
52+ } ,
53+ } ,
54+ {
55+ itemType : 'group' ,
56+ colCount : 2 ,
57+ colCountByScreen : { xs : 2 } ,
58+ items : [
59+ {
60+ label : { text : 'Movie' } ,
61+ colSpan : 1 ,
62+ editorType : 'dxSelectBox' ,
63+ dataField : 'movieId' ,
64+ editorOptions : {
65+ items : moviesData ,
66+ displayExpr : 'text' ,
67+ valueExpr : 'id' ,
68+ stylingMode : getEditorStylingMode ( ) ,
69+ onValueChanged ( e ) {
70+ const movie = getMovieById ( e . value ) ;
4671
47- form . option ( 'items' , [ {
48- label : {
49- text : 'Movie' ,
50- } ,
51- editorType : 'dxSelectBox' ,
52- dataField : 'movieId' ,
53- editorOptions : {
54- items : moviesData ,
55- displayExpr : 'text' ,
56- valueExpr : 'id' ,
57- onValueChanged ( args ) {
58- movieInfo = getMovieById ( args . value ) ;
72+ const $movieInfo = movieInfoTemplate ( movie ) ;
73+ $movieInfoContainer . empty ( ) . append ( $movieInfo ) ;
5974
60- form . updateData ( 'director' , movieInfo . director ) ;
61- form . updateData ( 'endDate' , new Date ( startDate . getTime ( ) + 60 * 1000 * movieInfo . duration ) ) ;
62- } ,
63- } ,
64- } , {
65- label : {
66- text : 'Director' ,
67- } ,
68- name : 'director' ,
69- editorType : 'dxTextBox' ,
70- editorOptions : {
71- value : movieInfo . director ,
72- readOnly : true ,
73- } ,
74- } , {
75- dataField : 'startDate' ,
76- editorType : 'dxDateBox' ,
77- editorOptions : {
78- width : '100%' ,
79- type : 'datetime' ,
80- onValueChanged ( args ) {
81- startDate = args . value ;
75+ if ( ! form ) {
76+ return ;
77+ }
8278
83- form . updateData ( 'endDate' , new Date ( startDate . getTime ( ) + 60 * 1000 * movieInfo . duration ) ) ;
79+ form . updateData ( 'director' , movie . director ) ;
80+ updateEndDate ( form , movie ) ;
81+ } ,
82+ onContentReady : ( e ) => {
83+ e . component . option ( 'stylingMode' , getEditorStylingMode ( ) ) ;
84+ } ,
85+ } ,
86+ } ,
87+ {
88+ label : { text : 'Price' } ,
89+ colSpan : 1 ,
90+ editorType : 'dxSelectBox' ,
91+ dataField : 'price' ,
92+ editorOptions : {
93+ items : [ 5 , 10 , 15 , 20 ] ,
94+ displayExpr : ( value ) => `$${ value } ` ,
95+ stylingMode : getEditorStylingMode ( ) ,
96+ onContentReady : ( e ) => {
97+ e . component . option ( 'stylingMode' , getEditorStylingMode ( ) ) ;
98+ } ,
99+ } ,
100+ } ,
101+ ] ,
84102 } ,
85- } ,
86- } , {
87- name : 'endDate' ,
88- dataField : 'endDate' ,
89- editorType : 'dxDateBox' ,
90- editorOptions : {
91- width : '100%' ,
92- type : 'datetime' ,
93- readOnly : true ,
94- } ,
95- } , {
96- dataField : 'price' ,
97- editorType : 'dxRadioGroup' ,
98- editorOptions : {
99- dataSource : [ 5 , 10 , 15 , 20 ] ,
100- itemTemplate ( itemData ) {
101- return `$${ itemData } ` ;
103+ 'startDateGroup' ,
104+ {
105+ name : 'endDateGroup' ,
106+ disabled : true ,
102107 } ,
103- } ,
108+ ] ,
104109 } ,
105- ] ) ;
106110 } ,
107111 } ) . dxScheduler ( 'instance' ) ;
108112
@@ -112,20 +116,50 @@ $(() => {
112116 . toArray ( ) [ 0 ] ;
113117 }
114118
115- function getTooltipTemplate ( movieData ) {
116- return $ ( `${ "<div class='movie-tooltip'>"
117- + "<img src='" } ${ movieData . image } ' />`
118- + '<div class=\'movie-info\'>'
119- + `<div class='movie-title'>${
120- movieData . text } (${ movieData . year } )`
121- + '</div>'
122- + '<div>'
123- + `Director: ${ movieData . director
124- } </div>`
125- + '<div>'
126- + `Duration: ${ movieData . duration } minutes`
127- + '</div>'
128- + '</div>'
129- + '</div>' ) ;
119+ function updateEndDate ( form , movie ) {
120+ const { startDate } = form . option ( 'formData' ) ;
121+ const newEndDate = new Date ( startDate . getTime ( ) + 60 * 1000 * movie . duration ) ;
122+
123+ form . updateData ( 'endDate' , newEndDate ) ;
124+ }
125+
126+ function appointmentTemplate ( model ) {
127+ const { movieId, displayStartDate, displayEndDate, price } = model . targetedAppointmentData ;
128+ const movie = getMovieById ( movieId ) || { } ;
129+
130+ return $ ( `
131+ <div class='movie-preview'>
132+ <div class='movie-preview-image'>
133+ <img src='${ movie . image } ' />
134+ </div>
135+ <div class='movie-details'>
136+ <div class='title'>${ movie . text } </div>
137+ <div>Ticket Price: <b>$${ price } </b></div>
138+ <div>
139+ ${ DevExpress . localization . formatDate ( displayStartDate , 'shortTime' ) }
140+ - ${ DevExpress . localization . formatDate ( displayEndDate , 'shortTime' ) }
141+ </div>
142+ </div>
143+ </div>
144+ ` ) ;
145+ }
146+
147+ function movieInfoTemplate ( movie ) {
148+ return $ ( `
149+ <div class='movie-info'>
150+ <div class='movie-preview-image'>
151+ <img src='${ movie . image } ' />
152+ </div>
153+ <div class='movie-details'>
154+ <div class='title'>${ movie . text } (${ movie . year } )</div>
155+ <div>Director: ${ movie . director } </div>
156+ <div>Duration: ${ movie . duration } minutes</div>
157+ </div>
158+ </div>
159+ ` ) ;
160+ }
161+
162+ function getEditorStylingMode ( ) {
163+ return $ ( '.dx-theme-fluent, .dx-theme-material' ) . length > 0 ? 'filled' : 'outlined' ;
130164 }
131165} ) ;
0 commit comments