@@ -9,9 +9,16 @@ var interimRequest = {
99 // bind functions
1010 $ ( '.select2-field' ) . select2 ( ) ;
1111 $ ( '#add_session' ) . click ( interimRequest . addSession ) ;
12+ $ ( '.btn-delete' ) . click ( interimRequest . deleteSession ) ;
1213 $ ( '#id_face_to_face' ) . change ( interimRequest . toggleLocation ) ;
1314 $ ( 'input[name="meeting_type"]' ) . change ( interimRequest . checkAddButton ) ;
14- // init
15+ $ ( 'input[name$="-duration"]' ) . blur ( interimRequest . calculateEndTime ) ;
16+ $ ( 'input[name$="-time"]' ) . blur ( interimRequest . calculateEndTime ) ;
17+ //$('input[name$="-time"]').blur(interimRequest.setUTC);
18+ $ ( 'input[name$="-time"]' ) . blur ( interimRequest . updateInfo ) ;
19+ $ ( 'input[name$="-end_time"]' ) . change ( interimRequest . updateInfo ) ;
20+ $ ( 'select[name$="-timezone"]' ) . change ( interimRequest . timezoneChange ) ;
21+ // init
1522 interimRequest . faceToFace . each ( interimRequest . toggleLocation ) ;
1623 interimRequest . checkAddButton ( ) ;
1724 } ,
@@ -46,19 +53,69 @@ var interimRequest = {
4653 setupSelect2Field ( $ ( this ) ) ;
4754 } ) ;
4855
49- if ( interimRequest . faceToFace . prop ( 'checked' ) ) {
56+ // if(interimRequest.faceToFace.prop('checked')){
5057 var first_session = $ ( ".fieldset:first" ) ;
5158 el . find ( "input[name$='city']" ) . val ( first_session . find ( "input[name$='city']" ) . val ( ) ) ;
5259 el . find ( "select[name$='country']" ) . val ( first_session . find ( "select[name$='country']" ) . val ( ) ) ;
5360 el . find ( "select[name$='timezone']" ) . val ( first_session . find ( "select[name$='timezone']" ) . val ( ) ) ;
54- }
61+ // }
5562
5663 if ( meeting_type == 'multi-day' ) {
5764 el . find ( ".location" ) . prop ( 'disabled' , true ) ;
5865 }
66+
67+ $ ( '.btn-delete' ) . removeClass ( "hidden" ) ;
68+ } ,
5969
70+ updateInfo : function ( ) {
71+ //var url = liaisonForm.form.data("ajaxInfoUrl");
72+ //alert('called update');
73+ var url = "/meeting/ajax/get-utc" ;
74+ var fieldset = $ ( this ) . parents ( ".fieldset" ) ;
75+ var time = $ ( this ) . val ( ) ;
76+ var timezone_field = fieldset . find ( '[name$="timezone"]' ) ;
77+ var timezone = timezone_field . val ( ) ;
78+ var name = $ ( this ) . attr ( "id" ) + "_utc" ;
79+ var utc = fieldset . find ( "#" + name ) ;
80+ $ . ajax ( {
81+ url : url ,
82+ type : 'GET' ,
83+ cache : false ,
84+ async : true ,
85+ dataType : 'json' ,
86+ data : { time : time ,
87+ timezone : timezone } ,
88+ success : function ( response ) {
89+ if ( ! response . error ) {
90+ utc . val ( response . utc + " UTC" ) ;
91+ }
92+ }
93+ } ) ;
94+ return false ;
6095 } ,
6196
97+
98+ calculateEndTime : function ( ) {
99+ // gets called when either start_time or duration change
100+ var fieldset = $ ( this ) . parents ( ".fieldset" ) ;
101+ var start_time = fieldset . find ( "input[name$='-time']" ) ;
102+ var end_time = fieldset . find ( "input[name$='-end_time']" ) ;
103+ var duration = fieldset . find ( "input[name$='-duration']" ) ;
104+ if ( ! start_time . val ( ) || ! duration . val ( ) ) {
105+ return ;
106+ }
107+ var start_values = start_time . val ( ) . split ( ":" ) ;
108+ var duration_values = duration . val ( ) . split ( ":" ) ;
109+ var d = new Date ( 2000 , 1 , 1 , start_values [ 0 ] , start_values [ 1 ] ) ;
110+ var d1 = new Date ( d . getTime ( ) + ( duration_values [ 0 ] * 60 * 60 * 1000 ) ) ;
111+ var d2 = new Date ( d1 . getTime ( ) + ( duration_values [ 1 ] * 60 * 1000 ) ) ;
112+ end_time . val ( interimRequest . get_formatted_time ( d2 ) ) ;
113+ end_time . trigger ( 'change' ) ;
114+ //interimRequest.updateInfo(end_time);
115+ //alert( d2 );
116+ //alert( end_time.attr("id") );
117+ } ,
118+
62119 checkAddButton : function ( ) {
63120 var meeting_type = $ ( 'input[name="meeting_type"]:checked' ) . val ( ) ;
64121 if ( meeting_type == 'single' ) {
@@ -68,6 +125,59 @@ var interimRequest = {
68125 }
69126 } ,
70127
128+ get_formatted_time : function ( d ) {
129+ // returns time from Date object as HH:MM
130+ var minutes = d . getMinutes ( ) . toString ( ) ;
131+ var hours = d . getHours ( ) . toString ( ) ;
132+ return interimRequest . pad ( hours ) + ":" + interimRequest . pad ( minutes ) ;
133+ } ,
134+
135+ deleteSession : function ( ) {
136+ var fieldset = $ ( this ) . parents ( ".fieldset" ) ;
137+ fieldset . remove ( ) ;
138+ var totalField = $ ( '#id_form-TOTAL_FORMS' ) ;
139+ var total = + totalField . val ( ) ;
140+ -- total ;
141+ totalField . val ( total ) ;
142+ if ( total == 2 ) {
143+ $ ( ".btn-delete" ) . addClass ( "hidden" ) ;
144+ }
145+ } ,
146+
147+ get_formatted_utc_time : function ( d ) {
148+ // returns time from Date object as HH:MM
149+ var minutes = d . getUTCMinutes ( ) . toString ( ) ;
150+ var hours = d . getUTCHours ( ) . toString ( ) ;
151+ return interimRequest . pad ( hours ) + ":" + interimRequest . pad ( minutes ) ;
152+ } ,
153+
154+ pad : function ( str ) {
155+ // zero pads string 00
156+ if ( str . length == 1 ) {
157+ str = "0" + str ;
158+ }
159+ return str ;
160+ } ,
161+
162+ setUTC : function ( ) {
163+ var fieldset = $ ( this ) . parents ( ".fieldset" ) ;
164+ var values = $ ( this ) . val ( ) . split ( ":" ) ;
165+ var name = $ ( this ) . attr ( "id" ) + "_utc" ;
166+ var utc = fieldset . find ( "#" + name ) ;
167+ var d = new Date ( 2000 , 1 , 1 , values [ 0 ] , values [ 1 ] ) ;
168+ utc . val ( interimRequest . get_formatted_utc_time ( d ) + " UTC" ) ;
169+ //alert(utc.attr("id"));
170+ } ,
171+
172+ timezoneChange : function ( ) {
173+ //alert("tz change");
174+ var fieldset = $ ( this ) . parents ( ".fieldset" ) ;
175+ var start_time = fieldset . find ( "input[name$='-time']" ) ;
176+ var end_time = fieldset . find ( "input[name$='-end_time']" ) ;
177+ start_time . trigger ( 'blur' ) ;
178+ end_time . trigger ( 'change' ) ;
179+ } ,
180+
71181 toggleLocation : function ( ) {
72182 if ( this . checked ) {
73183 $ ( ".location" ) . prop ( 'disabled' , false ) ;
0 commit comments