@@ -44,6 +44,7 @@ function exchAttachments(aDocument, aWindow)
4444}
4545
4646exchAttachments . prototype = {
47+ _initialized : false ,
4748
4849 addAttachmentDialog : function _addAttachmentDialog ( )
4950 {
@@ -227,45 +228,75 @@ exchAttachments.prototype = {
227228 }
228229 } ,
229230
231+ /**
232+ * Receives asynchronous messages from the parent context that contains the iframe.
233+ *
234+ * @param {MessageEvent } aEvent Contains the message being received
235+ */
236+ receiveMessage : function _receiveMessage ( aEvent ) {
237+ let validOrigin = gTabmail ? "chrome://messenger" : "chrome://calendar" ;
238+ if ( aEvent . origin !== validOrigin ) {
239+ return ;
240+ }
241+ switch ( aEvent . data . command ) {
242+ case "exchWebService_addAttachmentDialog" : this . addAttachmentDialog ( ) ; break ;
243+ }
244+ } ,
245+
230246 onLoad : function _onLoad ( )
231247 {
248+ if ( this . _initialized ) {
249+ return ;
250+ }
251+
252+ var self = this ;
253+
232254 if ( this . _document . getElementById ( "calendar-task-tree" ) ) {
233255 this . globalFunctions . LOG ( " -- calendar-task-tree --" ) ;
234- var self = this ;
235256 this . _document . getElementById ( "calendar-task-tree" ) . addEventListener ( "select" , function ( ) { self . onSelectTask ( ) ; } , true ) ;
236257 return ;
237- }
258+ }
238259
239260 var args = this . _window . arguments [ 0 ] ;
240261 var item = args . calendarEvent ;
241262
242- //this.globalFunctions.LOG(" -- onLoad 2 ("+this.globalFunctions.STACKshort()+")");
243263 this . attachmentListboxVisible = false ;
244264
265+ // We can't update toolbar from iframe
245266 if ( ( item . calendar ) && ( item . calendar . type == "exchangecalendar" ) ) {
246267 this . globalFunctions . LOG ( " -- It is an Exchange Calendar event:" + item . title ) ;
247268
248-
249- try {
250- // Hide Lightning URL button
251- this . _document . getElementById ( "button-url" ) . hidden = true ;
252- this . _document . getElementById ( "event-toolbar" ) . setAttribute ( "currentset" , "button-save,button-attendees,button-privacy,button-url,exchWebService-add-attachment-button,button-delete" ) ;
253- this . _document . getElementById ( "exchWebService-add-attachment-button" ) . hidden = false ;
254- if ( this . _document . getElementById ( "options-attachments-menuitem" ) ) {
255- this . _document . getElementById ( "options-attachments-menuitem" ) . setAttribute ( "label" , this . _document . getElementById ( "exchWebService-add-attachment-button" ) . getAttribute ( "label" ) ) ;
256- this . _document . getElementById ( "options-attachments-menuitem" ) . setAttribute ( "command" , "exchWebService_addAttachmentDialog" ) ;
257- }
269+ if ( this . _document . getElementById ( "event-grid-attachment-row" ) ) {
270+ this . _document . getElementById ( "event-grid-attachment-row" ) . collapsed = true ;
258271 }
259- catch ( ex ) { this . globalFunctions . LOG ( " -- Could not add exchange attachment buttons:" + ex . toString ( ) ) ; }
260272
261- // calendar-event-dialog (hide existing attachment view)
262- try {
263- this . _document . getElementById ( "event-grid-attachment-row" ) . setAttribute ( "collapsed" , "true" ) ;
264- }
265- catch ( ex ) { }
273+ // Modify context menu for the attachment list inside the "Attachment" panel
274+ let attachmentListbox = this . _document . getElementById ( "attachment-link" ) ;
275+
276+ attachmentListbox . context = "exchWebService-attachment-popup" ;
277+ attachmentListbox . onkeypress = function ( aEvent ) { self . onKeyPress ( aEvent ) ; } ;
278+ attachmentListbox . onclick = function ( aEvent ) { self . onSelect ( aEvent ) ; } ;
279+ attachmentListbox . ondblclick = function ( aEvent ) { self . onDblClick ( aEvent ) ; } ;
266280
267281 this . addAttachmentsFromItem ( item ) ;
282+ } else {
283+ if ( this . _document . getElementById ( "event-grid-attachment-row" ) ) {
284+ this . _document . getElementById ( "event-grid-attachment-row" ) . collapsed = false ;
285+ }
286+
287+ // Modify context menu for the attachment list inside the "Attachment" panel
288+ let attachmentListbox = this . _document . getElementById ( "attachment-link" ) ;
289+
290+ attachmentListbox . context = "attachment-popup" ;
291+ attachmentListbox . onkeypress = "attachmentLinkKeyPress(event)" ;
292+ attachmentListbox . onclick = "attachmentClick(event);" ;
293+ attachmentListbox . ondblclick = "attachmentDblClick(event)" ;
268294 }
295+
296+ // Add message listener to be able to receive message from parent window or tab
297+ window . addEventListener ( "message" , function ( aEvent ) { self . receiveMessage ( aEvent ) ; } , false ) ;
298+
299+ this . _initialized = true ;
269300 } ,
270301
271302 addAttachmentsFromItem : function _addAttachmentsFromItem ( aItem )
@@ -584,6 +615,6 @@ exchAttachments.prototype = {
584615}
585616
586617var tmpAttachment = new exchAttachments ( document , window ) ;
587- window . addEventListener ( "load" , function _onLoad ( ) { window . removeEventListener ( "load" , arguments . callee , false ) ; tmpAttachment . onLoad ( ) ; } , true ) ;
618+ window . addEventListener ( "load" , function _onLoad ( ) { tmpAttachment . onLoad ( ) ; } , false ) ;
588619
589620
0 commit comments