snappymail/dev/Settings/Admin/Social.js

182 lines
5.1 KiB
JavaScript
Raw Normal View History

2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
(function () {
2014-08-25 23:49:01 +08:00
'use strict';
2014-08-21 23:08:34 +08:00
var
2014-08-25 23:49:01 +08:00
_ = require('_'),
ko = require('ko'),
2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
Enums = require('Common/Enums'),
Utils = require('Common/Utils')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
*/
function SocialAdminSettings()
2014-08-21 23:08:34 +08:00
{
var SocialStore = require('Stores/Social');
2014-08-25 15:10:51 +08:00
this.googleEnable = SocialStore.google.enabled;
this.googleEnableAuth = SocialStore.google.capa.auth;
this.googleEnableDrive = SocialStore.google.capa.drive;
this.googleEnablePreview = SocialStore.google.capa.preview;
this.googleEnableRequireClientSettings = SocialStore.google.require.clientSettings;
this.googleEnableRequireApiKey = SocialStore.google.require.apiKeySettings;
this.googleClientID = SocialStore.google.clientID;
this.googleClientSecret = SocialStore.google.clientSecret;
this.googleApiKey = SocialStore.google.apiKey;
2014-08-21 23:08:34 +08:00
this.googleTrigger1 = ko.observable(Enums.SaveSettingsStep.Idle);
this.googleTrigger2 = ko.observable(Enums.SaveSettingsStep.Idle);
this.googleTrigger3 = ko.observable(Enums.SaveSettingsStep.Idle);
this.facebookSupported = SocialStore.facebook.supported;
this.facebookEnable = SocialStore.facebook.enabled;
this.facebookAppID = SocialStore.facebook.appID;
this.facebookAppSecret = SocialStore.facebook.appSecret;
2014-08-21 23:08:34 +08:00
this.facebookTrigger1 = ko.observable(Enums.SaveSettingsStep.Idle);
this.facebookTrigger2 = ko.observable(Enums.SaveSettingsStep.Idle);
this.twitterEnable = SocialStore.twitter.enabled;
this.twitterConsumerKey = SocialStore.twitter.consumerKey;
this.twitterConsumerSecret = SocialStore.twitter.consumerSecret;
2014-08-21 23:08:34 +08:00
this.twitterTrigger1 = ko.observable(Enums.SaveSettingsStep.Idle);
this.twitterTrigger2 = ko.observable(Enums.SaveSettingsStep.Idle);
this.dropboxEnable = SocialStore.dropbox.enabled;
this.dropboxApiKey = SocialStore.dropbox.apiKey;
2014-08-21 23:08:34 +08:00
this.dropboxTrigger1 = ko.observable(Enums.SaveSettingsStep.Idle);
}
SocialAdminSettings.prototype.onBuild = function ()
2014-08-21 23:08:34 +08:00
{
2014-08-25 15:10:51 +08:00
var
self = this,
2015-02-23 00:35:17 +08:00
Remote = require('Remote/Admin/Ajax')
2014-08-25 15:10:51 +08:00
;
2014-08-21 23:08:34 +08:00
_.delay(function () {
var
f1 = Utils.settingsSaveHelperSimpleFunction(self.facebookTrigger1, self),
f2 = Utils.settingsSaveHelperSimpleFunction(self.facebookTrigger2, self),
f3 = Utils.settingsSaveHelperSimpleFunction(self.twitterTrigger1, self),
f4 = Utils.settingsSaveHelperSimpleFunction(self.twitterTrigger2, self),
f5 = Utils.settingsSaveHelperSimpleFunction(self.googleTrigger1, self),
f6 = Utils.settingsSaveHelperSimpleFunction(self.googleTrigger2, self),
f7 = Utils.settingsSaveHelperSimpleFunction(self.googleTrigger3, self),
f8 = Utils.settingsSaveHelperSimpleFunction(self.dropboxTrigger1, self)
;
self.facebookEnable.subscribe(function (bValue) {
if (self.facebookSupported())
{
Remote.saveAdminConfig(Utils.emptyFunction, {
'FacebookEnable': bValue ? '1' : '0'
});
}
});
self.facebookAppID.subscribe(function (sValue) {
if (self.facebookSupported())
{
Remote.saveAdminConfig(f1, {
'FacebookAppID': Utils.trim(sValue)
});
}
});
self.facebookAppSecret.subscribe(function (sValue) {
if (self.facebookSupported())
{
Remote.saveAdminConfig(f2, {
'FacebookAppSecret': Utils.trim(sValue)
});
}
});
self.twitterEnable.subscribe(function (bValue) {
Remote.saveAdminConfig(Utils.emptyFunction, {
'TwitterEnable': bValue ? '1' : '0'
});
});
self.twitterConsumerKey.subscribe(function (sValue) {
Remote.saveAdminConfig(f3, {
'TwitterConsumerKey': Utils.trim(sValue)
});
});
self.twitterConsumerSecret.subscribe(function (sValue) {
Remote.saveAdminConfig(f4, {
'TwitterConsumerSecret': Utils.trim(sValue)
});
});
self.googleEnable.subscribe(function (bValue) {
Remote.saveAdminConfig(Utils.emptyFunction, {
'GoogleEnable': bValue ? '1' : '0'
});
});
self.googleEnableAuth.subscribe(function (bValue) {
Remote.saveAdminConfig(Utils.emptyFunction, {
'GoogleEnableAuth': bValue ? '1' : '0'
});
});
self.googleEnableDrive.subscribe(function (bValue) {
Remote.saveAdminConfig(Utils.emptyFunction, {
'GoogleEnableDrive': bValue ? '1' : '0'
});
});
self.googleEnablePreview.subscribe(function (bValue) {
Remote.saveAdminConfig(Utils.emptyFunction, {
'GoogleEnablePreview': bValue ? '1' : '0'
});
});
2014-08-21 23:08:34 +08:00
self.googleClientID.subscribe(function (sValue) {
Remote.saveAdminConfig(f5, {
'GoogleClientID': Utils.trim(sValue)
});
});
self.googleClientSecret.subscribe(function (sValue) {
Remote.saveAdminConfig(f6, {
'GoogleClientSecret': Utils.trim(sValue)
});
});
self.googleApiKey.subscribe(function (sValue) {
Remote.saveAdminConfig(f7, {
'GoogleApiKey': Utils.trim(sValue)
});
});
self.dropboxEnable.subscribe(function (bValue) {
Remote.saveAdminConfig(Utils.emptyFunction, {
'DropboxEnable': bValue ? '1' : '0'
});
});
self.dropboxApiKey.subscribe(function (sValue) {
Remote.saveAdminConfig(f8, {
'DropboxApiKey': Utils.trim(sValue)
});
});
}, 50);
};
module.exports = SocialAdminSettings;
2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
}());