-
Notifications
You must be signed in to change notification settings - Fork 0
/
StaticDocView.js
100 lines (69 loc) · 3.94 KB
/
StaticDocView.js
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
96
97
98
99
100
// This file is part of DQX - (C) Copyright 2014, Paul Vauterin, Ben Jeffery, Alistair Miles <[email protected]>
// This program is free software licensed under the GNU Affero General Public License.
// You can find a copy of this license in LICENSE in the top directory of the source code or at <http://opensource.org/licenses/AGPL-3.0>
/************************************************************************************************************************************
*************************************************************************************************************************************
Implements a Framework.ViewSet that can be used to browse a set of static html pages, emulating navigation tools in the browser
This listens to ShowStaticDoc messages to show a html document
*************************************************************************************************************************************
*************************************************************************************************************************************/
define(["require", "DQX/Framework", "DQX/HistoryManager", "DQX/Msg", "DQX/Utils", "DQX/DocEl", "DQX/Controls"],
function (require, Framework, HistoryManager, Msg, DQX, DocEl, Controls) {
StaticDocViewModule = {
Instance: function (iPage, iFrame) {
var that = Framework.ViewSet(iFrame, 'doc');
that.myPage = iPage;
that.registerView();
//Called automatically
that.createPanels = function () {
this.panelStaticDoc = Framework.Form(this.getFrame());
this.panelStaticDoc.render();
};
//Called automatically
that.createFramework = function () {
};
that.loadPage = function (url) {
that.activeUrl = url;
HistoryManager.setState(that.getStateKeys());
}
that.activateState = function (stateKeys) {
var st = stateKeys.doc;
this.activeUrl = st.replace(/\*/g, "/");
this.getFrame().makeVisible();
DQX.setProcessing("Downloading...");
$.get(this.activeUrl, {})
.done(function (data) {
DQX.stopProcessing();
//fetch the title
var docParser = new DOMParser();
try {
var xmlDoc = docParser.parseFromString(data, "text/xml");
var title = xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
} catch (e) {
DQX.reportError('Unable to fetch static document title:\n\n' + e);
}
that.getFrame().modifyDisplayTitle(title);
//fetch the html content
var content = $('<div/>').append(data).find('.DQXStaticContent').html();
that.panelStaticDoc.clear();
that.panelStaticDoc.addHtml('<div class="DQXStaticContent">' + content + '</div>');
that.panelStaticDoc.render();
})
.fail(function () {
DQX.stopProcessing();
alert("Failed to download documentation item '" + that.activeUrl + "'");
});
}
that.getStateKeys = function () {
var encoded = that.activeUrl.replace(/\//g, "*");
return { doc: encoded };
};
Msg.listen('', { type: 'ShowStaticDoc' }, function (scope, url) {
that.loadPage(url);
});
return that;
},
end: true
};
return StaticDocViewModule;
});