summaryrefslogtreecommitdiff
path: root/js/prefs.js
blob: 3600c5fb11843eecb3601de58b1cd506d3fe67f2 (plain)
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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
'use strict'
/* global dijit, __ */

let App;
let CommonDialogs;
let Filters;
let Users;
let Prefs;

require(["dojo/_base/kernel",
	"dojo/_base/declare",
	"dojo/ready",
	"dojo/parser",
	"fox/AppBase",
	"dojo/_base/loader",
	"dojo/_base/html",
	"dijit/ColorPalette",
	"dijit/Dialog",
	"dijit/form/Button",
	"dijit/form/CheckBox",
	"dijit/form/DropDownButton",
	"dijit/form/FilteringSelect",
	"dijit/form/MultiSelect",
	"dijit/form/Form",
	"dijit/form/RadioButton",
	"dijit/form/ComboButton",
	"dijit/form/Select",
	"dijit/form/SimpleTextarea",
	"dijit/form/TextBox",
	"dijit/form/ValidationTextBox",
	"dijit/InlineEditBox",
	"dijit/layout/AccordionContainer",
	"dijit/layout/AccordionPane",
	"dijit/layout/BorderContainer",
	"dijit/layout/ContentPane",
	"dijit/layout/TabContainer",
	"dijit/Menu",
	"dijit/ProgressBar",
	"dijit/Toolbar",
	"dijit/Tree",
	"dijit/tree/dndSource",
	"dojo/data/ItemFileWriteStore",
	"lib/CheckBoxStoreModel",
	"lib/CheckBoxTree",
	"fox/CommonDialogs",
	"fox/CommonFilters",
	"fox/PrefUsers",
	"fox/PrefHelpers",
	"fox/PrefFeedStore",
	"fox/PrefFilterStore",
	"fox/PrefFeedTree",
	"fox/PrefFilterTree",
	"fox/PrefLabelTree"], function (dojo, declare, ready, parser, AppBase) {

	ready(function () {
		try {
			const _App = declare("fox.App", AppBase, {
				constructor: function() {
					window.onerror = function (message, filename, lineno, colno, error) {
						report_error(message, filename, lineno, colno, error);
					};

					CommonDialogs = fox.CommonDialogs();
					Filters = fox.CommonFilters();
					Users = fox.PrefUsers();
					Prefs = fox.PrefHelpers();

					parser.parse();

					this.setLoadingProgress(50);

					const clientTzOffset = new Date().getTimezoneOffset() * 60;
					const params = {op: "rpc", method: "sanityCheck", clientTzOffset: clientTzOffset};

					xhrPost("backend.php", params, (transport) => {
						try {
							this.backendSanityCallback(transport);
						} catch (e) {
							exception_error(e);
						}
					});
				},
				initSecondStage: function() {
					this.enableCsrfSupport();

					document.onkeydown = (event) => { App.hotkeyHandler(event) };
					App.setLoadingProgress(50);
					Notify.close();

					let tab = App.urlParam('tab');

					if (tab) {
						tab = dijit.byId(tab + "Tab");
						if (tab) {
							dijit.byId("pref-tabs").selectChild(tab);

							switch (App.urlParam('method')) {
								case "editfeed":
									window.setTimeout(function () {
										CommonDialogs.editFeed(App.urlParam('methodparam'))
									}, 100);
									break;
								default:
									console.warn("initSecondStage, unknown method:", App.urlParam("method"));
							}
						}
					} else {
						let tab = localStorage.getItem("ttrss:prefs-tab");

						if (tab) {
							tab = dijit.byId(tab);
							if (tab) {
								dijit.byId("pref-tabs").selectChild(tab);
							}
						}
					}

					dojo.connect(dijit.byId("pref-tabs"), "selectChild", function (elem) {
						localStorage.setItem("ttrss:prefs-tab", elem.id);
					});

				},
				hotkeyHandler: function (event) {
					if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return;

					const action_name = App.keyeventToAction(event);

					if (action_name) {
						switch (action_name) {
							case "feed_subscribe":
								CommonDialogs.quickAddFeed();
								return false;
							case "create_label":
								CommonDialogs.addLabel();
								return false;
							case "create_filter":
								Filters.quickAddFilter();
								return false;
							case "help_dialog":
								App.helpDialog("main");
								return false;
							default:
								console.log("unhandled action: " + action_name + "; keycode: " + event.which);
						}
					}
				},
				isPrefs: function() {
					return true;
				}
			});

			App = new _App();

		} catch (e) {
			exception_error(e);
		}
	});
});

function opmlImportComplete(iframe) {
	if (!iframe.contentDocument.body.innerHTML) return false;

	Element.show(iframe);

	Notify.close();

	if (dijit.byId('opmlImportDlg'))
		dijit.byId('opmlImportDlg').destroyRecursive();

	const content = iframe.contentDocument.body.innerHTML;

	const dialog = new dijit.Dialog({
		id: "opmlImportDlg",
		title: __("OPML Import"),
		style: "width: 600px",
		onCancel: function () {
			window.location.reload();
		},
		execute: function () {
			window.location.reload();
		},
		content: content
	});

	dialog.show();
}

function opmlImport() {

	const opml_file = $("opml_file");

	if (opml_file.value.length == 0) {
		alert(__("Please choose an OPML file first."));
		return false;
	} else {
		Notify.progress("Importing, please wait...", true);

		Element.show("upload_iframe");

		return true;
	}
}

function opmlRegenKey() {
	if (confirm(__("Replace current OPML publishing address with a new one?"))) {
		Notify.progress("Trying to change address...", true);

		xhrJson("backend.php", { op: "pref-feeds", method: "regenOPMLKey" }, (reply) => {
			if (reply) {
				const new_link = reply.link;
				const e = $('pub_opml_url');

				if (new_link) {
					e.href = new_link;
					e.innerHTML = new_link;

					new Effect.Highlight(e);

					Notify.close();

				} else {
					Notify.error("Could not change feed URL.");
				}
			}
		});
	}
	return false;
}

function gotoExportOpml(filename, settings) {
	const tmp = settings ? 1 : 0;
	document.location.href = "backend.php?op=opml&method=export&filename=" + filename + "&settings=" + tmp;
}