2018-03-08 18:00:20 +00:00
|
|
|
/* global i18n: false */
|
|
|
|
/* global Whisper: false */
|
2018-07-13 15:57:30 +00:00
|
|
|
/* global $: false */
|
2018-03-08 18:00:20 +00:00
|
|
|
|
2018-07-03 22:33:50 +00:00
|
|
|
/* eslint-disable no-new */
|
2018-03-08 18:00:20 +00:00
|
|
|
|
2018-07-03 22:33:50 +00:00
|
|
|
// eslint-disable-next-line func-names
|
2018-04-27 21:25:04 +00:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
const { Settings } = window.Signal.Types;
|
2016-02-19 00:13:53 +00:00
|
|
|
|
2018-07-03 22:33:50 +00:00
|
|
|
const CheckboxView = Whisper.View.extend({
|
|
|
|
initialize(options) {
|
|
|
|
this.setFn = options.setFn;
|
|
|
|
this.value = options.value;
|
2018-04-27 21:25:04 +00:00
|
|
|
this.populate();
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
change: 'change',
|
|
|
|
},
|
2018-07-03 22:33:50 +00:00
|
|
|
change(e) {
|
|
|
|
const value = e.target.checked;
|
|
|
|
this.setFn(value);
|
2018-04-27 21:25:04 +00:00
|
|
|
console.log(this.name, 'changed to', value);
|
|
|
|
},
|
2018-07-03 22:33:50 +00:00
|
|
|
populate() {
|
|
|
|
this.$('input').prop('checked', !!this.value);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const MediaPermissionsSettingView = Whisper.View.extend({
|
|
|
|
initialize(options) {
|
|
|
|
this.value = options.value;
|
|
|
|
this.setFn = options.setFn;
|
|
|
|
this.populate();
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
change: 'change',
|
|
|
|
},
|
|
|
|
change(e) {
|
|
|
|
this.value = e.target.checked;
|
|
|
|
this.setFn(this.value);
|
|
|
|
console.log('media-permissions changed to', this.value);
|
|
|
|
},
|
|
|
|
populate() {
|
|
|
|
this.$('input').prop('checked', Boolean(this.value));
|
2018-04-27 21:25:04 +00:00
|
|
|
},
|
|
|
|
});
|
2018-07-03 22:33:50 +00:00
|
|
|
|
|
|
|
const RadioButtonGroupView = Whisper.View.extend({
|
|
|
|
initialize(options) {
|
2018-04-27 21:25:04 +00:00
|
|
|
this.name = options.name;
|
2018-07-03 22:33:50 +00:00
|
|
|
this.setFn = options.setFn;
|
|
|
|
this.value = options.value;
|
2018-04-27 21:25:04 +00:00
|
|
|
this.populate();
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
change: 'change',
|
|
|
|
},
|
2018-07-03 22:33:50 +00:00
|
|
|
change(e) {
|
|
|
|
const value = this.$(e.target).val();
|
|
|
|
this.setFn(value);
|
2018-04-27 21:25:04 +00:00
|
|
|
console.log(this.name, 'changed to', value);
|
|
|
|
},
|
2018-07-03 22:33:50 +00:00
|
|
|
populate() {
|
|
|
|
this.$(`#${this.name}-${this.value}`).attr('checked', 'checked');
|
2018-04-27 21:25:04 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
Whisper.SettingsView = Whisper.View.extend({
|
|
|
|
className: 'settings modal expand',
|
|
|
|
templateName: 'settings',
|
2018-07-03 22:33:50 +00:00
|
|
|
initialize() {
|
2018-04-27 21:25:04 +00:00
|
|
|
this.render();
|
|
|
|
new RadioButtonGroupView({
|
|
|
|
el: this.$('.notification-settings'),
|
|
|
|
name: 'notification-setting',
|
2018-07-03 22:33:50 +00:00
|
|
|
value: window.initialData.notificationSetting,
|
|
|
|
setFn: window.setNotificationSetting,
|
2018-04-27 21:25:04 +00:00
|
|
|
});
|
|
|
|
new RadioButtonGroupView({
|
|
|
|
el: this.$('.theme-settings'),
|
|
|
|
name: 'theme-setting',
|
2018-07-03 22:33:50 +00:00
|
|
|
value: window.initialData.themeSetting,
|
2018-07-13 15:57:30 +00:00
|
|
|
setFn: theme => {
|
|
|
|
$(document.body)
|
|
|
|
.removeClass('android')
|
|
|
|
.removeClass('android-dark')
|
|
|
|
.removeClass('ios')
|
|
|
|
.addClass(theme);
|
|
|
|
window.setThemeSetting(theme);
|
|
|
|
},
|
2018-04-27 21:25:04 +00:00
|
|
|
});
|
|
|
|
if (Settings.isAudioNotificationSupported()) {
|
|
|
|
new CheckboxView({
|
|
|
|
el: this.$('.audio-notification-setting'),
|
2018-07-03 22:33:50 +00:00
|
|
|
value: window.initialData.audioNotification,
|
|
|
|
setFn: window.setAudioNotification,
|
2018-04-27 21:25:04 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
new CheckboxView({
|
|
|
|
el: this.$('.menu-bar-setting'),
|
2018-07-03 22:33:50 +00:00
|
|
|
value: window.initialData.hideMenuBar,
|
|
|
|
setFn: window.setHideMenuBar,
|
2018-04-27 21:25:04 +00:00
|
|
|
});
|
2018-07-03 22:33:50 +00:00
|
|
|
new MediaPermissionsSettingView({
|
|
|
|
el: this.$('.media-permissions'),
|
|
|
|
value: window.initialData.mediaPermissions,
|
|
|
|
setFn: window.setMediaPermissions,
|
|
|
|
});
|
|
|
|
if (!window.initialData.isPrimary) {
|
|
|
|
const syncView = new SyncView().render();
|
2018-04-27 21:25:04 +00:00
|
|
|
this.$('.sync-setting').append(syncView.el);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
events: {
|
2018-07-03 22:33:50 +00:00
|
|
|
'click .close': 'onClose',
|
2018-04-27 21:25:04 +00:00
|
|
|
'click .clear-data': 'onClearData',
|
|
|
|
},
|
2018-07-03 22:33:50 +00:00
|
|
|
render_attributes() {
|
2018-04-27 21:25:04 +00:00
|
|
|
return {
|
|
|
|
deviceNameLabel: i18n('deviceName'),
|
2018-07-03 22:33:50 +00:00
|
|
|
deviceName: window.initialData.deviceName,
|
2018-04-27 21:25:04 +00:00
|
|
|
theme: i18n('theme'),
|
|
|
|
notifications: i18n('notifications'),
|
|
|
|
notificationSettingsDialog: i18n('notificationSettingsDialog'),
|
|
|
|
settings: i18n('settings'),
|
|
|
|
disableNotifications: i18n('disableNotifications'),
|
|
|
|
nameAndMessage: i18n('nameAndMessage'),
|
|
|
|
noNameOrMessage: i18n('noNameOrMessage'),
|
|
|
|
nameOnly: i18n('nameOnly'),
|
|
|
|
audioNotificationDescription: i18n('audioNotificationDescription'),
|
|
|
|
isAudioNotificationSupported: Settings.isAudioNotificationSupported(),
|
|
|
|
themeAndroidDark: i18n('themeAndroidDark'),
|
|
|
|
hideMenuBar: i18n('hideMenuBar'),
|
|
|
|
clearDataHeader: i18n('clearDataHeader'),
|
|
|
|
clearDataButton: i18n('clearDataButton'),
|
|
|
|
clearDataExplanation: i18n('clearDataExplanation'),
|
2018-07-03 22:33:50 +00:00
|
|
|
permissions: i18n('permissions'),
|
|
|
|
mediaPermissionsDescription: i18n('mediaPermissionsDescription'),
|
2018-04-27 21:25:04 +00:00
|
|
|
};
|
|
|
|
},
|
2018-07-03 22:33:50 +00:00
|
|
|
onClose() {
|
|
|
|
window.closeSettings();
|
2018-03-08 18:00:20 +00:00
|
|
|
},
|
2018-07-03 22:33:50 +00:00
|
|
|
onClearData() {
|
|
|
|
window.deleteAllData();
|
|
|
|
window.closeSettings();
|
2018-03-08 18:00:20 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-07-03 22:33:50 +00:00
|
|
|
const SyncView = Whisper.View.extend({
|
2018-04-27 21:25:04 +00:00
|
|
|
templateName: 'syncSettings',
|
|
|
|
className: 'syncSettings',
|
|
|
|
events: {
|
|
|
|
'click .sync': 'sync',
|
|
|
|
},
|
2018-07-03 22:33:50 +00:00
|
|
|
initialize() {
|
|
|
|
this.lastSyncTime = window.initialData.lastSyncTime;
|
|
|
|
},
|
|
|
|
enable() {
|
2018-04-27 21:25:04 +00:00
|
|
|
this.$('.sync').text(i18n('syncNow'));
|
|
|
|
this.$('.sync').removeAttr('disabled');
|
|
|
|
},
|
2018-07-03 22:33:50 +00:00
|
|
|
disable() {
|
2018-04-27 21:25:04 +00:00
|
|
|
this.$('.sync').attr('disabled', 'disabled');
|
|
|
|
this.$('.sync').text(i18n('syncing'));
|
|
|
|
},
|
2018-07-03 22:33:50 +00:00
|
|
|
onsuccess() {
|
|
|
|
window.setLastSyncTime(Date.now());
|
|
|
|
this.lastSyncTime = Date.now();
|
2018-04-27 21:25:04 +00:00
|
|
|
console.log('sync successful');
|
|
|
|
this.enable();
|
|
|
|
this.render();
|
|
|
|
},
|
2018-07-03 22:33:50 +00:00
|
|
|
ontimeout() {
|
2018-04-27 21:25:04 +00:00
|
|
|
console.log('sync timed out');
|
|
|
|
this.$('.synced_at').hide();
|
|
|
|
this.$('.sync_failed').show();
|
|
|
|
this.enable();
|
|
|
|
},
|
2018-07-03 22:33:50 +00:00
|
|
|
async sync() {
|
2018-04-27 21:25:04 +00:00
|
|
|
this.$('.sync_failed').hide();
|
2018-07-03 22:33:50 +00:00
|
|
|
if (window.initialData.isPrimary) {
|
2018-04-27 21:25:04 +00:00
|
|
|
console.log('Tried to sync from device 1');
|
2018-07-03 22:33:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.disable();
|
|
|
|
try {
|
|
|
|
await window.makeSyncRequest();
|
|
|
|
this.onsuccess();
|
|
|
|
} catch (error) {
|
|
|
|
this.ontimeout();
|
2018-04-27 21:25:04 +00:00
|
|
|
}
|
|
|
|
},
|
2018-07-03 22:33:50 +00:00
|
|
|
render_attributes() {
|
|
|
|
const attrs = {
|
2018-04-27 21:25:04 +00:00
|
|
|
sync: i18n('sync'),
|
|
|
|
syncNow: i18n('syncNow'),
|
|
|
|
syncExplanation: i18n('syncExplanation'),
|
|
|
|
syncFailed: i18n('syncFailed'),
|
|
|
|
};
|
2018-07-03 22:33:50 +00:00
|
|
|
let date = this.lastSyncTime;
|
2018-04-27 21:25:04 +00:00
|
|
|
if (date) {
|
|
|
|
date = new Date(date);
|
|
|
|
attrs.lastSynced = i18n('lastSynced');
|
|
|
|
attrs.syncDate = date.toLocaleDateString();
|
|
|
|
attrs.syncTime = date.toLocaleTimeString();
|
|
|
|
}
|
|
|
|
return attrs;
|
|
|
|
},
|
|
|
|
});
|
2016-02-19 00:13:53 +00:00
|
|
|
})();
|