[% WRAPPER templates/rapidapp/ext_page.tt %]

<script type="text/javascript">

	Ext.onReady(function(){

		[% IF onReady_first %] [% onReady_first %] [% END %]

		var config_url = '[% config_url %]';
		var config_params = [% IF config_params %] [% config_params %] [% ELSE %] {} [% END %]

        var BodyEl = Ext.getBody();
        BodyEl.addClass('rapidapp-printview');
        
        var ldMask = new Ext.LoadMask(BodyEl, {msg:"Loading Printview..."});
        ldMask.show();

        Ext.Ajax.request({
            callback: function(){ ldMask.hide() },
            url: config_url,
            params: config_params,
				headers: { 'X-RapidApp-View': 'print' },
            success: function(response, opts) {
				if(response.responseText) {
					var cmpconf = Ext.decode(response.responseText);

                    //TODO: Come up with a better/safer way to handle this scroll
                    // logic:
                    if(cmpconf.autoScroll && Ext.isObject(cmpconf.items)){
                        cmpconf = cmpconf.items;
                    }

                    Ext.ComponentMgr.create(cmpconf,'panel').render(BodyEl);
                }
            }
        });
	});

</script>

[% END %]