Ext.define("Portfolio.ux.pdf.Viewer", {

    xtype: "portfolio-pdf-viewer",

    extend: "Ext.panel.Panel",

    layout: "fit",

    mixins: [
        "Ext.mixin.Mashup"
    ],

    config: {
        src: "/pdfjs/web/compressed.tracemonkey-pldi-09.pdf",
        viewer: null
    },

    initComponent: function() {

        var i_self = this;
        i_self.callParent(arguments);
        i_self.add(i_self.createCanvas());

    },

    createCanvas: function() {

        var i_self = this;

        var i_component = Ext.widget("component", {
            autoEl: {
                tag: "iframe",
                style: "height: 100%; width: 100%; border: none;",
                src: "/pdfjs/web/viewer.html?file="+ i_self.getSrc()
            }
        });

        i_self.setViewer(i_component);

        return i_component;
    },

    updateSrc: function(s_src) {

        var i_self = this;
        var i_viewer = i_self.getViewer();

        if (s_src && i_viewer && i_viewer.getEl()) {

            var i_element = i_viewer.getEl();
            var i_dom = i_element.dom;
            var i_contentWindow = i_dom.contentWindow;

            i_contentWindow.PDFViewerApplication.open(s_src);
        }
    }
});
