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

	requires: [
		'treps.controller.SAMP.SAMPManager'
	],

	views: ['Viewport'],

	init: function() {
		var me = this;
		this.control({
			'viewport': {
				render: this.onInitApplication,
				scope: me
			},
			'tool': {
				click: this.onRequestHelp,
				scope: me
			}
		});

		this.application.on(
			{
				helppage: me.onChangeHelp,
				scope: me
			}
		);

		Ext.EventManager.onWindowUnload(
			function() {
				var sampManager = treps.controller.SAMP.SAMPManager;
				sampManager.disconnect();
			},
			me
		);
	},

	onInitApplication: function()	{
		//init samp manager
		var sampManager = treps.controller.SAMP.SAMPManager;
		sampManager.onReceiveFile      = this.onReceiveSAMPFile;
		sampManager.onConnect          = this.onConnectSAMP;
		sampManager.onDisconnect       = this.onDisconnectSAMP;
		sampManager.onClientsUpdate    = this.onClientsUpdateSAMP;
		treps.controller.SAMP.SAMPManager.initSAMP();

		//fire an event to start a new operation when the viewport is ready
		this.application.fireEvent('initapp');
	},

	onConnectSAMP: function()
	{
		treps.getApplication().fireEvent('samp_connect');
	},

	onDisconnectSAMP: function()
	{
		treps.getApplication().fireEvent('samp_disconnect');
	},

	onReceiveSAMPFile: function(client, file, format)
	{
		var re = /http:\/\/127.0.0.1:/;
		if (!re.test(file))
			treps.getApplication().fireEvent('receivesource','url',file);
		else
			treps.Messages.showError("Cannot receive file from a local application");
	},

	onClientsUpdateSAMP: function()
	{
		treps.getApplication().fireEvent('samp_clients');
	},

	onRequestHelp: function(tool, e, eOpts)
	{
		if (!tool.pageId)
			return;
		var helpController = treps.app.getController('Application.Help.Help');
		helpController.setHelp(tool.pageId);
	},

	onChangeHelp: function(pageId)
	{
		var helpController = treps.app.getController('Application.Help.Help');
		helpController.setHelp(pageId);
	},

	setVersion: function(kernelVersion)
	{
		Ext.fly('header-version').update("Kernel Version: "+kernelVersion);
	}
});