2016-09-05 23:45:22 -07:00
|
|
|
define(['appSettings', 'events'], function (appsettings, events) {
|
2016-03-01 21:46:10 -07:00
|
|
|
|
2016-09-05 23:45:22 -07:00
|
|
|
return function () {
|
2016-03-01 21:46:10 -07:00
|
|
|
|
2016-07-11 12:25:27 -07:00
|
|
|
var self = this;
|
2016-09-05 23:45:22 -07:00
|
|
|
var currentUserId;
|
|
|
|
var currentApiClient;
|
|
|
|
var displayPrefs;
|
2016-03-01 21:46:10 -07:00
|
|
|
|
2016-09-05 23:45:22 -07:00
|
|
|
self.setUserInfo = function (userId, apiClient) {
|
2016-03-01 21:46:10 -07:00
|
|
|
|
2016-09-05 23:45:22 -07:00
|
|
|
currentUserId = userId;
|
|
|
|
currentApiClient = apiClient;
|
2016-03-01 21:46:10 -07:00
|
|
|
|
2016-09-05 23:45:22 -07:00
|
|
|
if (!userId) {
|
|
|
|
displayPrefs = null;
|
|
|
|
return Promise.resolve();
|
2016-07-11 12:25:27 -07:00
|
|
|
}
|
|
|
|
|
2016-09-05 23:45:22 -07:00
|
|
|
return apiClient.getDisplayPreferences('usersettings', userId, 'emby').then(function (result) {
|
|
|
|
result.CustomPrefs = result.CustomPrefs || {};
|
|
|
|
displayPrefs = result;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-09-06 20:38:01 -07:00
|
|
|
var saveTimeout;
|
|
|
|
function onSaveTimeout() {
|
|
|
|
saveTimeout = null;
|
2016-09-05 23:45:22 -07:00
|
|
|
currentApiClient.updateDisplayPreferences('usersettings', displayPrefs, currentUserId, 'emby');
|
2016-07-11 12:25:27 -07:00
|
|
|
}
|
2016-09-06 20:38:01 -07:00
|
|
|
function saveServerPreferences() {
|
|
|
|
if (saveTimeout) {
|
|
|
|
clearTimeout(saveTimeout);
|
|
|
|
}
|
|
|
|
saveTimeout = setTimeout(onSaveTimeout, 50);
|
|
|
|
}
|
2016-03-01 21:46:10 -07:00
|
|
|
|
2016-09-05 23:45:22 -07:00
|
|
|
self.set = function (name, value, enableOnServer) {
|
2016-03-01 21:46:10 -07:00
|
|
|
|
2016-09-05 23:45:22 -07:00
|
|
|
var userId = currentUserId;
|
2016-03-01 21:46:10 -07:00
|
|
|
if (!userId) {
|
|
|
|
throw new Error('userId cannot be null');
|
|
|
|
}
|
|
|
|
|
|
|
|
var currentValue = self.get(name);
|
|
|
|
appsettings.set(name, value, userId);
|
|
|
|
|
2016-09-05 23:45:22 -07:00
|
|
|
if (enableOnServer !== false && displayPrefs) {
|
|
|
|
displayPrefs.CustomPrefs[name] = value == null ? value : value.toString();
|
|
|
|
saveServerPreferences();
|
|
|
|
}
|
|
|
|
|
2016-03-01 21:46:10 -07:00
|
|
|
if (currentValue != value) {
|
|
|
|
events.trigger(self, 'change', [name]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-05 23:45:22 -07:00
|
|
|
self.get = function (name, enableOnServer) {
|
|
|
|
var userId = currentUserId;
|
2016-03-01 21:46:10 -07:00
|
|
|
if (!userId) {
|
|
|
|
throw new Error('userId cannot be null');
|
|
|
|
}
|
2016-09-05 23:45:22 -07:00
|
|
|
|
|
|
|
if (enableOnServer !== false) {
|
|
|
|
if (displayPrefs) {
|
|
|
|
return displayPrefs.CustomPrefs[name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-01 21:46:10 -07:00
|
|
|
return appsettings.get(name, userId);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.enableCinemaMode = function (val) {
|
|
|
|
|
|
|
|
if (val != null) {
|
|
|
|
self.set('enableCinemaMode', val.toString());
|
|
|
|
}
|
|
|
|
|
2016-09-05 23:45:22 -07:00
|
|
|
val = self.get('enableCinemaMode', false);
|
2016-03-01 21:46:10 -07:00
|
|
|
|
|
|
|
if (val) {
|
|
|
|
return val != 'false';
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
self.language = function (val) {
|
|
|
|
|
|
|
|
if (val != null) {
|
|
|
|
self.set('language', val.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.get('language');
|
|
|
|
};
|
|
|
|
|
2016-03-06 21:56:45 -07:00
|
|
|
self.skipBackLength = function (val) {
|
2016-03-04 20:39:49 -07:00
|
|
|
|
|
|
|
if (val != null) {
|
2016-03-06 21:56:45 -07:00
|
|
|
self.set('skipBackLength', val.toString());
|
2016-03-04 20:39:49 -07:00
|
|
|
}
|
|
|
|
|
2016-03-06 21:56:45 -07:00
|
|
|
return parseInt(self.get('skipBackLength') || '15000');
|
|
|
|
};
|
|
|
|
|
|
|
|
self.skipForwardLength = function (val) {
|
|
|
|
|
|
|
|
if (val != null) {
|
|
|
|
self.set('skipForwardLength', val.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseInt(self.get('skipForwardLength') || '15000');
|
2016-03-04 20:39:49 -07:00
|
|
|
};
|
|
|
|
|
2016-03-01 21:46:10 -07:00
|
|
|
self.serverConfig = function (config) {
|
|
|
|
|
2016-09-05 23:45:22 -07:00
|
|
|
var apiClient = currentApiClient;
|
2016-07-13 11:23:01 -07:00
|
|
|
|
2016-03-01 21:46:10 -07:00
|
|
|
if (config) {
|
|
|
|
|
2016-09-05 23:45:22 -07:00
|
|
|
return apiClient.updateUserConfiguration(currentUserId, config);
|
2016-03-01 21:46:10 -07:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2016-09-05 23:45:22 -07:00
|
|
|
return apiClient.getUser(currentUserId).then(function (user) {
|
2016-03-01 21:46:10 -07:00
|
|
|
|
|
|
|
return user.Configuration;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2016-07-11 12:25:27 -07:00
|
|
|
};
|
2016-03-01 21:46:10 -07:00
|
|
|
});
|