Help.js 2.67 KB
Ext.define('treps.controller.Application.Help.Help', {
	extend: 'Ext.app.Controller',

	views: [
		'Application.Help.HelpPanel',
		'Application.Footer.FooterToolbar'
	],

	stores: [
		'Helps'
	],

	refs: [
                {
			ref: 'helpPanel',
			selector: 'app_help'
                },
		{
			ref: 'pageCombo',
			selector: 'app_help > combo'
		},
		{
			ref: 'rendererPanel',
			selector: 'app_help > panel'
		}
	],

	init: function() {
		var me = this;

		this.control({
			'footer_toolbar > #aboutButton': {
				click: me.onAbout,
				scope: me
			},
			'app_help > combo': {
				change: me.onSelectPage,
				scope: me
			}
		});

		var store = this.getHelpsStore();
		store.on(
			{
				scope: me,
				load : function(sore,records,successful,eOpts )
					{
						if (successful)
							me.setHelp('about',false);
					}
			}
		);
	},

	onAbout: function()
	{
		this.setHelp('about');
	},

	renderPage: function(pageId)
	{
		var me = this;
		var store = this.getHelpsStore();
		if (store == null)
			return;

		var page  = store.getById(pageId);
		if (page == null)
		{
			treps.Messages.showError("Cannot retrieve help page id");
			return;
		}

		var file  = page.get('file');
		var renderer = this.getRendererPanel();

		renderer.getLoader().load({
			url: file,
			//loadMask: true,
			nocache: true,
			scripts: true,
			renderer: function(loader, response, active) {
				var text = response.responseText;

				store.each(function(record)
					{
						var re = new RegExp("@@"+record.get("id")+"@@","g");

						text = text.replace(re,'<a href="#" onclick="treps.getApplication().fireEvent(\'helppage\',\''+record.get("id")+'\');return false;">'+record.get("title")+'</a>');
					});

				//treps_logo
				text = text.replace(/@@treps_logo@@/g,'resources/images/logo/logo_TREPS.png');

				//treps_version
				text = text.replace(/@@treps_version@@/g,"<div id='about-version' style='display: inline;'>"+treps.model.Session.get('kernelVersion')+"</div>");

				//3DView WS documentation
				text = text.replace(/@@treps_wsdoc@@/g, treps.Constants.WS_DOC);

				loader.getTarget().update(text);
				return true;
			}
		});
	},

	onSelectPage: function(combo, newValue, oldValue, eOpts)
	{
		this.renderPage(newValue);
	},

	setHelp: function(pageId, forceCollapse) {
		var forceColl = true;
		if (forceCollapse != null)
			forceColl = forceCollapse;

		var panel = this.getHelpPanel();

		if ((panel.getCollapsed() !== false) && forceColl)
			panel.expand();

		var combo = this.getPageCombo();

		if (combo != null)
			combo.setValue(pageId);
	},

	setVersion: function(kernelVersion)
	{
		var versionDiv = Ext.fly('about-version');
		if (versionDiv)
			Ext.fly('about-version').update("Kernel Version: "+kernelVersion);
	}
});