11$ ( ( ) => {
2+ let form ;
3+ let $movieInfoContainer ;
4+
25 $ ( '#scheduler' ) . dxScheduler ( {
36 timeZone : 'America/Los_Angeles' ,
47 dataSource : data ,
@@ -13,9 +16,6 @@ $(() => {
1316 groups : [ 'theatreId' ] ,
1417 crossScrollingEnabled : true ,
1518 cellDuration : 20 ,
16- editing : {
17- allowAdding : false ,
18- } ,
1919 resources : [ {
2020 fieldExpr : 'movieId' ,
2121 dataSource : moviesData ,
@@ -24,85 +24,95 @@ $(() => {
2424 fieldExpr : 'theatreId' ,
2525 dataSource : theatreData ,
2626 } ] ,
27- appointmentTooltipTemplate ( model ) {
28- return getTooltipTemplate ( getMovieById ( model . targetedAppointmentData . movieId ) ) ;
27+ appointmentTemplate,
28+ appointmentTooltipTemplate : ( model ) => {
29+ const movie = getMovieById ( model . targetedAppointmentData . movieId ) ;
30+ return movieInfoTemplate ( movie ) ;
2931 } ,
30- appointmentTemplate ( model ) {
31- const movieInfo = getMovieById ( model . targetedAppointmentData . movieId ) || { } ;
32-
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>' ) ;
41- } ,
42- onAppointmentFormOpening ( data ) {
43- const { form } = data ;
44- let movieInfo = getMovieById ( data . appointmentData . movieId ) || { } ;
45- let { startDate } = data . appointmentData ;
32+ editing : {
33+ allowAdding : false ,
34+ form : {
35+ onInitialized : ( e ) => {
36+ form = e . component ;
4637
47- form . option ( 'items' , [ {
48- label : {
49- text : 'Movie' ,
38+ form . on ( 'fieldDataChanged' , ( e ) => {
39+ if ( e . dataField === 'startDate' ) {
40+ const movie = getMovieById ( form . option ( 'formData' ) . movieId ) ;
41+ updateEndDate ( form , movie ) ;
42+ }
43+ } ) ;
5044 } ,
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 ) ;
59-
60- form . updateData ( 'director' , movieInfo . director ) ;
61- form . updateData ( 'endDate' , new Date ( startDate . getTime ( ) + 60 * 1000 * movieInfo . duration ) ) ;
45+ items : [
46+ {
47+ template : ( ) => {
48+ $movieInfoContainer = $ ( '<div class="movie-info-container">' ) ;
49+ updateMovieInfoContainer ( { } ) ;
50+ return $movieInfoContainer ;
51+ } ,
6252 } ,
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 ;
53+ {
54+ itemType : 'group' ,
55+ colCount : 2 ,
56+ colCountByScreen : { xs : 2 } ,
57+ items : [
58+ {
59+ label : { text : 'Movie' } ,
60+ colSpan : 1 ,
61+ editorType : 'dxSelectBox' ,
62+ dataField : 'movieId' ,
63+ editorOptions : {
64+ items : moviesData ,
65+ displayExpr : 'text ' ,
66+ valueExpr : 'id ' ,
67+ stylingMode : getEditorStylingMode ( ) ,
68+ onValueChanged ( e ) {
69+ const movie = getMovieById ( e . value ) ;
70+
71+ form . updateData ( 'director' , movie . director ) ;
8272
83- form . updateData ( 'endDate' , new Date ( startDate . getTime ( ) + 60 * 1000 * movieInfo . duration ) ) ;
73+ updateMovieInfoContainer ( movie ) ;
74+ updateEndDate ( form , movie ) ;
75+ } ,
76+ onContentReady : ( e ) => {
77+ e . component . option ( 'stylingMode' , getEditorStylingMode ( ) ) ;
78+ } ,
79+ } ,
80+ } ,
81+ {
82+ label : { text : 'Price' } ,
83+ colSpan : 1 ,
84+ editorType : 'dxSelectBox' ,
85+ dataField : 'price' ,
86+ editorOptions : {
87+ items : [ 5 , 10 , 15 , 20 ] ,
88+ displayExpr : ( value ) => `$${ value } ` ,
89+ stylingMode : getEditorStylingMode ( ) ,
90+ onContentReady : ( e ) => {
91+ e . component . option ( 'stylingMode' , getEditorStylingMode ( ) ) ;
92+ } ,
93+ } ,
94+ } ,
95+ ] ,
8496 } ,
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 } ` ;
97+ 'startDateGroup' ,
98+ {
99+ name : 'endDateGroup' ,
100+ disabled : true ,
102101 } ,
102+ ] ,
103+ } ,
104+ popup : {
105+ maxWidth : 440 ,
106+ onOptionChanged : ( e ) => {
107+ if ( e . fullName === 'toolbarItems' && e . value ) {
108+ e . value . forEach ( ( item , index ) => {
109+ if ( item . shortcut === 'done' || item . shortcut === 'cancel' ) {
110+ e . component . option ( `toolbarItems[${ index } ].toolbar` , 'bottom' ) ;
111+ }
112+ } ) ;
113+ }
103114 } ,
104115 } ,
105- ] ) ;
106116 } ,
107117 } ) . dxScheduler ( 'instance' ) ;
108118
@@ -112,20 +122,55 @@ $(() => {
112122 . toArray ( ) [ 0 ] ;
113123 }
114124
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>' ) ;
125+ function updateEndDate ( form , movie ) {
126+ const { startDate } = form . option ( 'formData' ) ;
127+ const newEndDate = new Date ( startDate . getTime ( ) + 60 * 1000 * movie . duration ) ;
128+
129+ form . updateData ( 'endDate' , newEndDate ) ;
130+ }
131+
132+ function appointmentTemplate ( model ) {
133+ const { movieId, displayStartDate, displayEndDate, price } = model . targetedAppointmentData ;
134+ const movie = getMovieById ( movieId ) || { } ;
135+
136+ return $ ( `
137+ <div class='movie-preview'>
138+ <div class='movie-preview-image'>
139+ <img src='${ movie . image } ' />
140+ </div>
141+ <div class='movie-details'>
142+ <div class='title'>${ movie . text } </div>
143+ <div>Ticket Price: <b>$${ price } </b></div>
144+ <div>
145+ ${ DevExpress . localization . formatDate ( displayStartDate , 'shortTime' ) }
146+ - ${ DevExpress . localization . formatDate ( displayEndDate , 'shortTime' ) }
147+ </div>
148+ </div>
149+ </div>
150+ ` ) ;
151+ }
152+
153+ function movieInfoTemplate ( movie ) {
154+ return $ ( `
155+ <div class='movie-info'>
156+ <div class='movie-preview-image'>
157+ <img src='${ movie . image } ' />
158+ </div>
159+ <div class='movie-details'>
160+ <div class='title'>${ movie . text } (${ movie . year } )</div>
161+ <div>Director: ${ movie . director } </div>
162+ <div>Duration: ${ movie . duration } minutes</div>
163+ </div>
164+ </div>
165+ ` ) ;
166+ }
167+
168+ function updateMovieInfoContainer ( movie ) {
169+ const $movieInfo = movieInfoTemplate ( movie ) ;
170+ $movieInfoContainer . empty ( ) . append ( $movieInfo ) ;
171+ }
172+
173+ function getEditorStylingMode ( ) {
174+ return $ ( '.dx-theme-fluent, .dx-theme-material' ) . length > 0 ? 'filled' : 'outlined' ;
130175 }
131176} ) ;
0 commit comments