import Ember from "ember";

var controller = Ember.Controller.extend({
    applicationController: Ember.inject.controller('application'),
    actions: {
        get_file_from_url: function(url, filename) {
            return this.ajaxRequest({
                url: url,
                type: 'GET',
                data: {}
            }, true).then(function(data){
                var xhr = data[2];
                var data = data[0];
                var element = document.createElement('a');
                element.setAttribute(
                    'href',
                    'data:' +
                    xhr.getResponseHeader('Content-Type') +
                    'charset=utf-8,' +
                    encodeURIComponent(data)
                );
                element.setAttribute(
                    'download',
                    filename
                );
                element.style.display = 'none';
                document.body.appendChild(element);
                element.click();

                document.body.removeChild(element);
            }.bind(this), function(msg){
                this.error_message(
                    `An error was encountered while ` +
                    `downloading your certificate: ${msg}`
                );
            }.bind(this));
        }
    }
});

export default controller;

@@ -223,16 +223,43 @@
 rn this.
+applicationController.get('
 ajaxRequ
@@ -261,16 +261,18 @@
 xRequest
+')
 (%7B%0A     

Fix reference to ajaxRequest.