summaryrefslogtreecommitdiff
path: root/plugins/updater/updater.js
blob: 40fcc871b15df7df5a176b822b6ea4d4a4a61c6f (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
function updateSelf() {
	try {
		var query = "backend.php?op=pluginhandler&plugin=updater&method=updateSelf";

		if (dijit.byId("updateSelfDlg"))
			dijit.byId("updateSelfDlg").destroyRecursive();

		var dialog = new dijit.Dialog({
			id: "updateSelfDlg",
			title: __("Update Tiny Tiny RSS"),
			style: "width: 600px",
			closable: false,
			performUpdate: function(step) {
				dijit.byId("self_update_start_btn").attr("disabled", true);
				dijit.byId("self_update_stop_btn").attr("disabled", true);

				notify_progress("Loading, please wait...", true);
				new Ajax.Request("backend.php", {
				parameters: "op=pluginhandler&plugin=updater&method=performUpdate&step=" + step +
					"&params=" + param_escape(JSON.stringify(dialog.attr("update-params"))),
				onComplete: function(transport) {
					try {
						rv = JSON.parse(transport.responseText);
						if (rv) {
							notify('');

							rv['log'].each(function(line) {
								$("self_update_log").innerHTML += "<li>" + line + "</li>";
							});

							dialog.attr("update-params", rv['params']);

							if (!rv['stop']) {
								window.setTimeout("dijit.byId('updateSelfDlg').performUpdate("+(step+1)+")", 500);
							} else {
								dijit.byId("self_update_stop_btn").attr("disabled", false);
							}

						} else {
							console.log(transport.responseText);
							notify_error("Received invalid data from server.");
						}

						dialog.attr("updated", true);
					} catch (e) {
						exception_error("updateSelf/inner", e);
					}
				} });
			},
			close: function() {
				if (dialog.attr("updated")) {
					window.location.reload();
				} else {
					dialog.hide();
				}
			},
			start: function() {
				if (prompt(__("Live updating is considered experimental. Backup your tt-rss directory before continuing. Please type 'yes' to continue.")) == 'yes') {
					dialog.performUpdate(0);
				}
			},
			href: query});

		dialog.show();
	} catch (e) {
		exception_error("batchSubscribe", e);
	}
}