Completed
Push — master ( 2e96ee...51b9e4 )
by Rain
01:37
created

plugins/custom-settings-tab/js/CustomUserSettings.js   A

Complexity

Total Complexity 14
Complexity/F 2

Size

Lines of Code 72
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
wmc 14
nc 72
mnd 1
bc 11
fnc 7
dl 0
loc 72
rs 10
bpm 1.5713
cpm 2
noi 1
c 0
b 0
f 0
1
2
(function () {
3
4
	/**
5
	 * @constructor
6
	 */
7
	function CustomUserSettings()
8
	{
9
		this.userSkype = ko.observable('');
10
		this.userFacebook = ko.observable('');
11
12
		this.loading = ko.observable(false);
13
		this.saving = ko.observable(false);
14
15
		this.savingOrLoading = ko.computed(function () {
16
			return this.loading() || this.saving();
17
		}, this);
18
	}
19
20
	CustomUserSettings.prototype.customAjaxSaveData = function ()
21
	{
22
		var self = this;
23
24
		if (this.saving())
25
		{
26
			return false;
27
		}
28
29
		this.saving(true);
30
31
		window.rl.pluginRemoteRequest(function (sResult, oData) {
32
33
			self.saving(false);
34
35
			if (window.rl.Enums.StorageResultType.Success === sResult && oData && oData.Result)
36
			{
37
				// true
38
			}
39
			else
40
			{
41
				// false
42
			}
43
44
		}, 'AjaxSaveCustomUserData', {
45
			'UserSkype': this.userSkype(),
46
			'UserFacebook': this.userFacebook()
47
		});
48
	};
49
50
	CustomUserSettings.prototype.onBuild = function () // special function
51
	{
52
		var self = this;
53
54
		this.loading(true);
55
56
		window.rl.pluginRemoteRequest(function (sResult, oData) {
57
58
			self.loading(false);
59
60
			if (window.rl.Enums.StorageResultType.Success === sResult && oData && oData.Result)
61
			{
62
				self.userSkype(oData.Result.UserSkype || '');
63
				self.userFacebook(oData.Result.UserFacebook || '');
64
			}
65
66
		}, 'AjaxGetCustomUserData');
67
68
	};
69
70
	window.rl.addSettingsViewModel(CustomUserSettings, 'PluginCustomSettingsTab',
71
		'SETTINGS_CUSTOM_PLUGIN/TAB_NAME', 'custom');
72
73
}());