Added support for PostgreSQL and SQLite in contacts (beta)

This commit is contained in:
RainLoop Team 2013-12-13 19:59:36 +04:00
parent 5877ff77dd
commit 76ce119980
11 changed files with 658 additions and 148 deletions

View file

@ -7,9 +7,86 @@ function AdminContacts()
{
// var oData = RL.data();
this.contactsSupported = !!RL.settingsGet('ContactsIsSupported');
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
this.enableContacts = ko.observable(!!RL.settingsGet('ContactsEnable'));
var
aTypes = ['sqlite', 'mysql', 'pgsql'],
aSupportedTypes = [],
getTypeName = function(sName) {
switch (sName)
{
case 'sqlite':
sName = 'SQLite';
break;
case 'mysql':
sName = 'MySQL';
break;
case 'pgsql':
sName = 'PostgreSQL';
break;
}
return sName;
}
;
if (!!RL.settingsGet('SQLiteIsSupported'))
{
aSupportedTypes.push('sqlite');
}
if (!!RL.settingsGet('MySqlIsSupported'))
{
aSupportedTypes.push('mysql');
}
if (!!RL.settingsGet('PostgreSqlIsSupported'))
{
aSupportedTypes.push('pgsql');
}
this.contactsSupported = 0 < aSupportedTypes.length;
this.contactsTypes = ko.observableArray([]);
this.contactsTypesOptions = this.contactsTypes.map(function (sValue) {
var bDisabled = -1 === Utils.inArray(sValue, aSupportedTypes);
return {
'id': sValue,
'name': getTypeName(sValue) + (bDisabled ? ' (not supported)' : ''),
'disable': bDisabled
};
});
this.contactsTypes(aTypes);
this.contactsType = ko.observable('');
this.mainContactsType = ko.computed({
'owner': this,
'read': this.contactsType,
'write': function (sValue) {
if (sValue !== this.contactsType())
{
if (-1 < Utils.inArray(sValue, aSupportedTypes))
{
this.contactsType(sValue);
}
else if (0 < aSupportedTypes.length)
{
this.contactsType('');
}
}
else
{
this.contactsType.valueHasMutated();
}
}
});
this.contactsType.subscribe(function () {
this.testContactsSuccess(false);
this.testContactsError(false);
this.testContactsErrorMessage('');
}, this);
this.pdoDsn = ko.observable(RL.settingsGet('ContactsPdoDsn'));
this.pdoUser = ko.observable(RL.settingsGet('ContactsPdoUser'));
this.pdoPassword = ko.observable(RL.settingsGet('ContactsPdoPassword'));
@ -17,6 +94,7 @@ function AdminContacts()
this.pdoDsnTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.pdoUserTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.pdoPasswordTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.contactsTypeTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.testing = ko.observable(false);
this.testContactsSuccess = ko.observable(false);
@ -31,6 +109,7 @@ function AdminContacts()
this.testing(true);
RL.remote().testContacts(this.onTestContactsResponse, {
'ContactsPdoType': this.contactsType(),
'ContactsPdoDsn': this.pdoDsn(),
'ContactsPdoUser': this.pdoUser(),
'ContactsPdoPassword': this.pdoPassword()
@ -40,6 +119,8 @@ function AdminContacts()
return '' !== this.pdoDsn() && '' !== this.pdoUser();
});
this.contactsType(RL.settingsGet('ContactsPdoType'));
this.onTestContactsResponse = _.bind(this.onTestContactsResponse, this);
}
@ -58,7 +139,14 @@ AdminContacts.prototype.onTestContactsResponse = function (sResult, oData)
else
{
this.testContactsError(true);
this.testContactsErrorMessage(oData.Result.Message || '');
if (oData && oData.Result)
{
this.testContactsErrorMessage(oData.Result.Message || '');
}
else
{
this.testContactsErrorMessage('');
}
}
this.testing(false);
@ -78,8 +166,9 @@ AdminContacts.prototype.onBuild = function ()
var
f1 = Utils.settingsSaveHelperSimpleFunction(self.pdoDsnTrigger, self),
f2 = Utils.settingsSaveHelperSimpleFunction(self.pdoUserTrigger, self),
f3 = Utils.settingsSaveHelperSimpleFunction(self.pdoPasswordTrigger, self)
f3 = Utils.settingsSaveHelperSimpleFunction(self.pdoUserTrigger, self),
f4 = Utils.settingsSaveHelperSimpleFunction(self.pdoPasswordTrigger, self),
f5 = Utils.settingsSaveHelperSimpleFunction(self.contactsTypeTrigger, self)
;
self.enableContacts.subscribe(function (bValue) {
@ -88,23 +177,31 @@ AdminContacts.prototype.onBuild = function ()
});
});
self.contactsType.subscribe(function (sValue) {
RL.remote().saveAdminConfig(f5, {
'ContactsPdoType': sValue
});
});
self.pdoDsn.subscribe(function (sValue) {
RL.remote().saveAdminConfig(f1, {
'ContactsPdoDsn': Utils.trim(sValue)
});
});
self.pdoUser.subscribe(function (sValue) {
RL.remote().saveAdminConfig(f2, {
RL.remote().saveAdminConfig(f3, {
'ContactsPdoUser': Utils.trim(sValue)
});
});
self.pdoPassword.subscribe(function (sValue) {
RL.remote().saveAdminConfig(f3, {
RL.remote().saveAdminConfig(f4, {
'ContactsPdoPassword': Utils.trim(sValue)
});
});
self.contactsType(RL.settingsGet('ContactsPdoType'));
}, 50);
};

View file

@ -402,7 +402,7 @@ ko.bindingHandlers.saveTrigger = {
var $oEl = $(oElement);
$oEl.data('save-trigger-type', $oEl.is('input[type=text],select,textarea') ? 'input' : 'custom');
$oEl.data('save-trigger-type', $oEl.is('input[type=text],input[type=email],input[type=password],select,textarea') ? 'input' : 'custom');
if ('custom' === $oEl.data('save-trigger-type'))
{