Welcome to mirror list, hosted at ThFree Co, Russian Federation.

personal.js « src - github.com/nextcloud/richdocuments.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b84d7f9247af289fb34a7de78f742c2b63f47cb6 (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
import '../css/admin.scss'

$(function() {

	$('[data-toggle="tooltip"]').tooltip()

	var PersonalSettings = function() {
		this.templateInput = document.getElementById('templateInputField')
		this.templateSelectButton = document.getElementById('templateSelectButton')
		this.templateResetButton = document.getElementById('templateResetButton')

		var self = this
		this.templateSelectButton.addEventListener('click', function() {
			OC.dialogs.filepicker(t('richdocuments', 'Select a personal template folder'), function(datapath, returntype) {
				self.updateSetting(datapath)
			}, false, 'httpd/unix-directory', true, OC.dialogs.FILEPICKER_TYPE_CHOOSE)
		})

		this.templateResetButton.addEventListener('click', this.resetSettings.bind(this))
	}

	PersonalSettings.prototype.updateSetting = function(path) {
		var self = this
		this._updateSetting({ templateFolder: path }, function() {
			self.templateInput.value = path
		}, function() {

		})
	}

	PersonalSettings.prototype.resetSettings = function() {
		var self = this
		this._updateSetting({ templateFolder: '' }, function() {
			self.templateInput.value = ''
		}, function() {

		})
	}

	PersonalSettings.prototype._updateSetting = function(data, successCallback, errorCallback) {
		OC.msg.startAction('#documents-admin-msg', t('richdocuments', 'Saving…'))
		var request = new XMLHttpRequest()
		request.open('POST', OC.filePath('richdocuments', 'ajax', 'personal.php'), true)
		request.setRequestHeader('Content-Type', 'application/json')
		request.setRequestHeader('requesttoken', OC.requestToken)
		request.onload = function() {
			if (request.status >= 200 && request.status < 400) {
				var response = JSON.parse(request.response)
				OC.msg.finishedAction('#documents-admin-msg', response)
				successCallback(response)
			} else {
				errorCallback(this.response)
			}
		}

		request.onerror = function() {
			errorCallback(this.response)
		}

		request.send(JSON.stringify(data))
	}

	return new PersonalSettings()
})