Blame view

ihm/app/controller/Application/Help/Help.js 2.67 KB
346b85c6   Benjamin Renard   First commit with...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
e314c376   Myriam Bouchemit   add help/tools an...
96
				text = text.replace(/@@treps_version@@/g,"<div id='about-version' style='display: inline;'>"+treps.model.Session.get('kernelVersion')+"</div>");
346b85c6   Benjamin Renard   First commit with...
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

				//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);
	}
});