jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/usersettings/usersettingsbuilder.js

104 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-03-01 21:46:10 -07:00
define(['appSettings', 'apiClientResolver', 'events'], function (appsettings, apiClientResolver, events) {
return function (configuredUserId) {
2016-03-01 21:46:10 -07:00
var self = this;
2016-03-01 21:46:10 -07:00
2016-07-13 11:23:01 -07:00
function getUserId(apiClient) {
2016-03-01 21:46:10 -07:00
if (configuredUserId) {
return configuredUserId;
}
2016-03-01 21:46:10 -07:00
2016-07-13 11:23:01 -07:00
var apiClientInstance = apiClient || apiClientResolver();
2016-03-01 21:46:10 -07:00
2016-07-13 11:23:01 -07:00
if (apiClientInstance) {
return apiClientInstance.getCurrentUserId();
}
return null;
}
2016-03-01 21:46:10 -07:00
self.set = function (name, value) {
var userId = getUserId();
if (!userId) {
throw new Error('userId cannot be null');
}
var currentValue = self.get(name);
appsettings.set(name, value, userId);
if (currentValue != value) {
events.trigger(self, 'change', [name]);
}
};
self.get = function (name) {
var userId = getUserId();
if (!userId) {
throw new Error('userId cannot be null');
}
return appsettings.get(name, userId);
};
self.enableCinemaMode = function (val) {
if (val != null) {
self.set('enableCinemaMode', val.toString());
}
val = self.get('enableCinemaMode');
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-07-13 11:23:01 -07:00
var apiClient = apiClientResolver();
2016-03-01 21:46:10 -07:00
if (config) {
2016-07-13 11:23:01 -07:00
return apiClient.updateUserConfiguration(getUserId(apiClient), config);
2016-03-01 21:46:10 -07:00
} else {
2016-07-13 11:23:01 -07:00
return apiClient.getUser(getUserId(apiClient)).then(function (user) {
2016-03-01 21:46:10 -07:00
return user.Configuration;
});
}
};
};
2016-03-01 21:46:10 -07:00
});