Remove DownloadManager dependency
We can pass it in using the options object. Note that that this also avoids creating a DownloadManager object for each separate link (instead, having only one is enough).
This commit is contained in:
		
							parent
							
								
									733882ac25
								
							
						
					
					
						commit
						4c6ca1c78f
					
				@ -14,7 +14,7 @@
 | 
				
			|||||||
 * See the License for the specific language governing permissions and
 | 
					 * See the License for the specific language governing permissions and
 | 
				
			||||||
 * limitations under the License.
 | 
					 * limitations under the License.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
/* globals DownloadManager, getFileName */
 | 
					/* globals getFileName */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
'use strict';
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -22,6 +22,7 @@ var PDFAttachmentView = (function PDFAttachmentViewClosure() {
 | 
				
			|||||||
  function PDFAttachmentView(options) {
 | 
					  function PDFAttachmentView(options) {
 | 
				
			||||||
    this.container = options.container;
 | 
					    this.container = options.container;
 | 
				
			||||||
    this.attachments = options.attachments;
 | 
					    this.attachments = options.attachments;
 | 
				
			||||||
 | 
					    this.downloadManager = options.downloadManager;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  PDFAttachmentView.prototype = {
 | 
					  PDFAttachmentView.prototype = {
 | 
				
			||||||
@ -34,12 +35,11 @@ var PDFAttachmentView = (function PDFAttachmentViewClosure() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    _bindLink: function PDFAttachmentView_bindLink(button, item) {
 | 
					    _bindLink: function PDFAttachmentView_bindLink(button, item) {
 | 
				
			||||||
      button.onclick = function downloadFile(e) {
 | 
					      button.onclick = function downloadFile(e) {
 | 
				
			||||||
        var downloadManager = new DownloadManager();
 | 
					 | 
				
			||||||
        var content = item.content;
 | 
					        var content = item.content;
 | 
				
			||||||
        var filename = item.filename;
 | 
					        var filename = item.filename;
 | 
				
			||||||
        downloadManager.downloadData(content, getFileName(filename), '');
 | 
					        this.downloadManager.downloadData(content, getFileName(filename), '');
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
      };
 | 
					      }.bind(this);
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    render: function PDFAttachmentView_render() {
 | 
					    render: function PDFAttachmentView_render() {
 | 
				
			||||||
 | 
				
			|||||||
@ -988,7 +988,8 @@ var PDFViewerApplication = {
 | 
				
			|||||||
        var container = document.getElementById('attachmentsView');
 | 
					        var container = document.getElementById('attachmentsView');
 | 
				
			||||||
        self.attachments = new PDFAttachmentView({
 | 
					        self.attachments = new PDFAttachmentView({
 | 
				
			||||||
          container: container,
 | 
					          container: container,
 | 
				
			||||||
          attachments: attachments
 | 
					          attachments: attachments,
 | 
				
			||||||
 | 
					          downloadManager: new DownloadManager()
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        self.attachments.render();
 | 
					        self.attachments.render();
 | 
				
			||||||
        document.getElementById('viewAttachments').disabled = !attachments;
 | 
					        document.getElementById('viewAttachments').disabled = !attachments;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user