mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Merge new-contacts-api
New interface Contact storage move to plugin
This commit is contained in:
commit
efdca7ef77
44 changed files with 3454 additions and 1012 deletions
10
Gruntfile.js
10
Gruntfile.js
|
|
@ -127,6 +127,7 @@ module.exports = function (grunt) {
|
||||||
"vendors/routes/hasher.min.js",
|
"vendors/routes/hasher.min.js",
|
||||||
"vendors/routes/crossroads.min.js",
|
"vendors/routes/crossroads.min.js",
|
||||||
"vendors/knockout/knockout-3.0.0.js",
|
"vendors/knockout/knockout-3.0.0.js",
|
||||||
|
"vendors/knockout-projections/knockout-projections-1.0.0.min.js",
|
||||||
"vendors/jua/jua.min.js",
|
"vendors/jua/jua.min.js",
|
||||||
"vendors/jquery-magnific-popup/jquery.magnific-popup.min.js",
|
"vendors/jquery-magnific-popup/jquery.magnific-popup.min.js",
|
||||||
"vendors/bootstrap/js/bootstrap.min.js",
|
"vendors/bootstrap/js/bootstrap.min.js",
|
||||||
|
|
@ -241,6 +242,7 @@ module.exports = function (grunt) {
|
||||||
|
|
||||||
"dev/Models/EmailModel.js",
|
"dev/Models/EmailModel.js",
|
||||||
"dev/Models/ContactModel.js",
|
"dev/Models/ContactModel.js",
|
||||||
|
"dev/Models/ContactPropertyModel.js",
|
||||||
"dev/Models/AttachmentModel.js",
|
"dev/Models/AttachmentModel.js",
|
||||||
"dev/Models/ComposeAttachmentModel.js",
|
"dev/Models/ComposeAttachmentModel.js",
|
||||||
"dev/Models/MessageModel.js",
|
"dev/Models/MessageModel.js",
|
||||||
|
|
@ -430,13 +432,13 @@ module.exports = function (grunt) {
|
||||||
grunt.registerTask('rlmin', ['uglify:min_app', 'uglify:min_admin']);
|
grunt.registerTask('rlmin', ['uglify:min_app', 'uglify:min_admin']);
|
||||||
|
|
||||||
// uglify (optional)
|
// uglify (optional)
|
||||||
grunt.registerTask('mousewheel', ['uglify:mousewheel']);
|
grunt.registerTask('rl', ['uglify:rl']);
|
||||||
grunt.registerTask('wakeup', ['uglify:wakeup']);
|
|
||||||
grunt.registerTask('nano', ['uglify:nano']);
|
grunt.registerTask('nano', ['uglify:nano']);
|
||||||
grunt.registerTask('pace', ['uglify:pace']);
|
grunt.registerTask('pace', ['uglify:pace']);
|
||||||
grunt.registerTask('rl', ['uglify:rl']);
|
grunt.registerTask('wakeup', ['uglify:wakeup']);
|
||||||
grunt.registerTask('inputosaurus', ['uglify:inputosaurus']);
|
|
||||||
grunt.registerTask('cookie', ['uglify:cookie']);
|
grunt.registerTask('cookie', ['uglify:cookie']);
|
||||||
|
grunt.registerTask('mousewheel', ['uglify:mousewheel']);
|
||||||
|
grunt.registerTask('inputosaurus', ['uglify:inputosaurus']);
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
grunt.registerTask('default', ['less', 'concat', 'cssmin', 'jshint', 'rlmin']);
|
grunt.registerTask('default', ['less', 'concat', 'cssmin', 'jshint', 'rlmin']);
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,6 @@ function AdminGeneral()
|
||||||
return Utils.convertLangName(this.mainLanguage());
|
return Utils.convertLangName(this.mainLanguage());
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
this.contactsSupported = RL.settingsGet('ContactsIsSupported');
|
|
||||||
this.contactsIsAllowed = RL.settingsGet('ContactsIsAllowed');
|
|
||||||
this.weakPassword = !!RL.settingsGet('WeakPassword');
|
this.weakPassword = !!RL.settingsGet('WeakPassword');
|
||||||
|
|
||||||
this.titleTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
|
this.titleTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
|
||||||
|
|
|
||||||
|
|
@ -539,9 +539,9 @@ RainLoopApp.prototype.getAutocomplete = function (sQuery, fCallback)
|
||||||
;
|
;
|
||||||
|
|
||||||
RL.remote().suggestions(function (sResult, oData) {
|
RL.remote().suggestions(function (sResult, oData) {
|
||||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result && Utils.isArray(oData.Result.List))
|
if (Enums.StorageResultType.Success === sResult && oData && Utils.isArray(oData.Result))
|
||||||
{
|
{
|
||||||
aData = _.map(oData.Result.List, function (aItem) {
|
aData = _.map(oData.Result, function (aItem) {
|
||||||
return aItem && aItem[0] ? new EmailModel(aItem[0], aItem[1]) : null;
|
return aItem && aItem[0] ? new EmailModel(aItem[0], aItem[1]) : null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -551,6 +551,7 @@ RainLoopApp.prototype.getAutocomplete = function (sQuery, fCallback)
|
||||||
{
|
{
|
||||||
fCallback([]);
|
fCallback([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, sQuery);
|
}, sQuery);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -578,7 +579,7 @@ RainLoopApp.prototype.bootstart = function ()
|
||||||
bTwitter = RL.settingsGet('AllowTwitterSocial')
|
bTwitter = RL.settingsGet('AllowTwitterSocial')
|
||||||
;
|
;
|
||||||
|
|
||||||
if (!RL.settingsGet('AllowChangePassword'))
|
if (!RL.settingsGet('ChangePasswordIsAllowed'))
|
||||||
{
|
{
|
||||||
Utils.removeSettingsViewModel(SettingsChangePasswordScreen);
|
Utils.removeSettingsViewModel(SettingsChangePasswordScreen);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -231,6 +231,45 @@ Enums.InterfaceAnimation = {
|
||||||
'Full': 'Full'
|
'Full': 'Full'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @enum {number}
|
||||||
|
*/
|
||||||
|
Enums.ContactPropertyType = {
|
||||||
|
|
||||||
|
'Unknown': 0,
|
||||||
|
|
||||||
|
'FullName': 10,
|
||||||
|
|
||||||
|
'FirstName': 15,
|
||||||
|
'SurName': 16,
|
||||||
|
'MiddleName': 17,
|
||||||
|
'Nick': 18,
|
||||||
|
|
||||||
|
'EmailPersonal': 30,
|
||||||
|
'EmailBussines': 31,
|
||||||
|
'EmailOther': 32,
|
||||||
|
|
||||||
|
'PhonePersonal': 50,
|
||||||
|
'PhoneBussines': 51,
|
||||||
|
'PhoneOther': 52,
|
||||||
|
|
||||||
|
'MobilePersonal': 60,
|
||||||
|
'MobileBussines': 61,
|
||||||
|
'MobileOther': 62,
|
||||||
|
|
||||||
|
'FaxPesonal': 70,
|
||||||
|
'FaxBussines': 71,
|
||||||
|
'FaxOther': 72,
|
||||||
|
|
||||||
|
'Facebook': 90,
|
||||||
|
'Skype': 91,
|
||||||
|
'GitHub': 92,
|
||||||
|
|
||||||
|
'Description': 110,
|
||||||
|
|
||||||
|
'Custom': 250
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum {number}
|
* @enum {number}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -631,6 +631,12 @@ ko.extenders.falseTimeout = function (oTarget, iOption)
|
||||||
return oTarget;
|
return oTarget;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ko.observable.fn.validateNone = function ()
|
||||||
|
{
|
||||||
|
this.hasError = ko.observable(false);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
ko.observable.fn.validateEmail = function ()
|
ko.observable.fn.validateEmail = function ()
|
||||||
{
|
{
|
||||||
this.hasError = ko.observable(false);
|
this.hasError = ko.observable(false);
|
||||||
|
|
|
||||||
|
|
@ -886,7 +886,6 @@ Utils.initDataConstructorBySettings = function (oData)
|
||||||
oData.dropboxEnable = ko.observable(false);
|
oData.dropboxEnable = ko.observable(false);
|
||||||
oData.dropboxApiKey = ko.observable('');
|
oData.dropboxApiKey = ko.observable('');
|
||||||
|
|
||||||
oData.contactsIsSupported = ko.observable(false);
|
|
||||||
oData.contactsIsAllowed = ko.observable(false);
|
oData.contactsIsAllowed = ko.observable(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,26 +6,65 @@
|
||||||
function ContactModel()
|
function ContactModel()
|
||||||
{
|
{
|
||||||
this.idContact = 0;
|
this.idContact = 0;
|
||||||
this.imageHash = '';
|
this.display = '';
|
||||||
this.listName = '';
|
this.properties = [];
|
||||||
this.name = '';
|
|
||||||
this.emails = [];
|
|
||||||
|
|
||||||
this.checked = ko.observable(false);
|
this.checked = ko.observable(false);
|
||||||
this.selected = ko.observable(false);
|
this.selected = ko.observable(false);
|
||||||
this.deleted = ko.observable(false);
|
this.deleted = ko.observable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {Array|null}
|
||||||
|
*/
|
||||||
|
ContactModel.prototype.getNameAndEmailHelper = function ()
|
||||||
|
{
|
||||||
|
var
|
||||||
|
sName = '',
|
||||||
|
sEmail = ''
|
||||||
|
;
|
||||||
|
|
||||||
|
if (Utils.isNonEmptyArray(this.properties))
|
||||||
|
{
|
||||||
|
_.each(this.properties, function (aProperty) {
|
||||||
|
if (aProperty)
|
||||||
|
{
|
||||||
|
if ('' === sName && Enums.ContactPropertyType.FullName === aProperty[0])
|
||||||
|
{
|
||||||
|
sName = aProperty[1];
|
||||||
|
}
|
||||||
|
else if ('' === sEmail && -1 < Utils.inArray(aProperty[0], [
|
||||||
|
Enums.ContactPropertyType.EmailPersonal,
|
||||||
|
Enums.ContactPropertyType.EmailBussines,
|
||||||
|
Enums.ContactPropertyType.EmailOther
|
||||||
|
]))
|
||||||
|
{
|
||||||
|
sEmail = aProperty[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return '' === sEmail ? null : [sEmail, sName];
|
||||||
|
};
|
||||||
|
|
||||||
ContactModel.prototype.parse = function (oItem)
|
ContactModel.prototype.parse = function (oItem)
|
||||||
{
|
{
|
||||||
var bResult = false;
|
var bResult = false;
|
||||||
if (oItem && 'Object/Contact' === oItem['@Object'])
|
if (oItem && 'Object/Contact' === oItem['@Object'])
|
||||||
{
|
{
|
||||||
this.idContact = Utils.pInt(oItem['IdContact']);
|
this.idContact = Utils.pInt(oItem['IdContact']);
|
||||||
this.listName = Utils.pString(oItem['ListName']);
|
this.display = Utils.pString(oItem['Display']);
|
||||||
this.name = Utils.pString(oItem['Name']);
|
|
||||||
this.emails = Utils.isNonEmptyArray(oItem['Emails']) ? oItem['Emails'] : [];
|
if (Utils.isNonEmptyArray(oItem['Properties']))
|
||||||
this.imageHash = Utils.pString(oItem['ImageHash']);
|
{
|
||||||
|
_.each(oItem['Properties'], function (oProperty) {
|
||||||
|
if (oProperty && oProperty['Type'] && Utils.isNormal(oProperty['Value']))
|
||||||
|
{
|
||||||
|
this.properties.push([Utils.pInt(oProperty['Type']), Utils.pString(oProperty['Value'])]);
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
|
}
|
||||||
|
|
||||||
bResult = true;
|
bResult = true;
|
||||||
}
|
}
|
||||||
|
|
@ -38,8 +77,7 @@ ContactModel.prototype.parse = function (oItem)
|
||||||
*/
|
*/
|
||||||
ContactModel.prototype.srcAttr = function ()
|
ContactModel.prototype.srcAttr = function ()
|
||||||
{
|
{
|
||||||
return '' === this.imageHash ? RL.link().emptyContactPic() :
|
return RL.link().emptyContactPic();
|
||||||
RL.link().getUserPicUrlFromHash(this.imageHash);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
14
dev/Models/ContactPropertyModel.js
Normal file
14
dev/Models/ContactPropertyModel.js
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number=} iType = Enums.ContactPropertyType.Unknown
|
||||||
|
* @param {string=} sValue = ''
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
function ContactPropertyModel(iType, sValue)
|
||||||
|
{
|
||||||
|
this.type = ko.observable(Utils.isUnd(iType) ? Enums.ContactPropertyType.Unknown : iType);
|
||||||
|
this.focused = ko.observable(false);
|
||||||
|
this.value = ko.observable(Utils.pString(sValue));
|
||||||
|
}
|
||||||
|
|
@ -65,6 +65,5 @@ AbstractData.prototype.populateDataOnStart = function()
|
||||||
this.dropboxEnable(!!RL.settingsGet('AllowDropboxSocial'));
|
this.dropboxEnable(!!RL.settingsGet('AllowDropboxSocial'));
|
||||||
this.dropboxApiKey(RL.settingsGet('DropboxApiKey'));
|
this.dropboxApiKey(RL.settingsGet('DropboxApiKey'));
|
||||||
|
|
||||||
this.contactsIsSupported(!!RL.settingsGet('ContactsIsSupported'));
|
|
||||||
this.contactsIsAllowed(!!RL.settingsGet('ContactsIsAllowed'));
|
this.contactsIsAllowed(!!RL.settingsGet('ContactsIsAllowed'));
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -538,11 +538,15 @@ WebMailAjaxRemoteStorage.prototype.quota = function (fCallback)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {?Function} fCallback
|
* @param {?Function} fCallback
|
||||||
|
* @param {number} iOffset
|
||||||
|
* @param {number} iLimit
|
||||||
* @param {string} sSearch
|
* @param {string} sSearch
|
||||||
*/
|
*/
|
||||||
WebMailAjaxRemoteStorage.prototype.contacts = function (fCallback, sSearch)
|
WebMailAjaxRemoteStorage.prototype.contacts = function (fCallback, iOffset, iLimit, sSearch)
|
||||||
{
|
{
|
||||||
this.defaultRequest(fCallback, 'Contacts', {
|
this.defaultRequest(fCallback, 'Contacts', {
|
||||||
|
'Offset': iOffset,
|
||||||
|
'Limit': iLimit,
|
||||||
'Search': sSearch
|
'Search': sSearch
|
||||||
}, null, '', ['Contacts']);
|
}, null, '', ['Contacts']);
|
||||||
};
|
};
|
||||||
|
|
@ -550,15 +554,12 @@ WebMailAjaxRemoteStorage.prototype.contacts = function (fCallback, sSearch)
|
||||||
/**
|
/**
|
||||||
* @param {?Function} fCallback
|
* @param {?Function} fCallback
|
||||||
*/
|
*/
|
||||||
WebMailAjaxRemoteStorage.prototype.contactSave = function (fCallback, sRequestUid, sUid, sName, sEmail, sImageData)
|
WebMailAjaxRemoteStorage.prototype.contactSave = function (fCallback, sRequestUid, sUid, aProperties)
|
||||||
{
|
{
|
||||||
sUid = Utils.trim(sUid);
|
|
||||||
this.defaultRequest(fCallback, 'ContactSave', {
|
this.defaultRequest(fCallback, 'ContactSave', {
|
||||||
'RequestUid': sRequestUid,
|
'RequestUid': sRequestUid,
|
||||||
'Uid': sUid,
|
'Uid': Utils.trim(sUid),
|
||||||
'Name': sName,
|
'Properties': aProperties
|
||||||
'Email': sEmail,
|
|
||||||
'ImageData': sImageData
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -215,20 +215,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.top-part {
|
.top-part {
|
||||||
margin-top: 20px;
|
padding-top: 20px;
|
||||||
|
|
||||||
.control-label {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.image-wrapper {
|
.property-line {
|
||||||
margin-left: 30px;
|
margin-bottom: 5px;
|
||||||
border-radius: 10px;
|
|
||||||
|
|
||||||
img {
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.top-row {
|
.top-row {
|
||||||
|
|
@ -236,35 +227,10 @@
|
||||||
height: 30px;
|
height: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.contactEmptyValueClick, .contactValueClick, .contactValueInput {
|
.add-link {
|
||||||
display: inline-block;
|
padding-top: 5px;
|
||||||
font-size: 24px;
|
font-size: 12px;
|
||||||
line-height: 28px;
|
color: #aaa;
|
||||||
height: 28px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.contactEmptyValueClick, .contactValueClick {
|
|
||||||
color: #ddd;
|
|
||||||
cursor: pointer;
|
|
||||||
margin: 5px 0 0 7px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.contactValueInput {
|
|
||||||
padding-left: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.contactEmptyValueClick {
|
|
||||||
border-bottom: 1px dashed #ddd;
|
|
||||||
}
|
|
||||||
|
|
||||||
.contactValueClick {
|
|
||||||
color: #555;
|
|
||||||
border-bottom: 11px dashed transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
.contactValueClick:hover {
|
|
||||||
color: #000;
|
|
||||||
border-bottom: 1px dashed #000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.contactValueInput {
|
.contactValueInput {
|
||||||
|
|
@ -272,7 +238,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.hasError {
|
.hasError {
|
||||||
.contactValueClick, .contactValueInput {
|
.contactValueInput {
|
||||||
color: #ee5f5b;
|
color: #ee5f5b;
|
||||||
border: 1px solid #ee5f5b;
|
border: 1px solid #ee5f5b;
|
||||||
}
|
}
|
||||||
|
|
@ -280,7 +246,7 @@
|
||||||
|
|
||||||
.button-save-contact {
|
.button-save-contact {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 20px;
|
top: 20px;
|
||||||
right: 20px;
|
right: 20px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ function MailBoxFolderListViewModel()
|
||||||
|
|
||||||
this.iDropOverTimer = 0;
|
this.iDropOverTimer = 0;
|
||||||
|
|
||||||
this.allowContacts = !!RL.settingsGet('ContactsIsSupported') && !!RL.settingsGet('ContactsIsAllowed');
|
this.allowContacts = !!RL.settingsGet('ContactsIsAllowed');
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils.extendAsViewModel('MailBoxFolderListViewModel', MailBoxFolderListViewModel);
|
Utils.extendAsViewModel('MailBoxFolderListViewModel', MailBoxFolderListViewModel);
|
||||||
|
|
|
||||||
|
|
@ -497,7 +497,7 @@ PopupsComposeViewModel.prototype.sendMessageResponse = function (sResult, oData)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.sendError(true);
|
this.sendError(true);
|
||||||
window.alert(Utils.getNotification(oData.ErrorCode ? oData.ErrorCode : Enums.Notification.CantSendMessage));
|
window.alert(Utils.getNotification(oData && oData.ErrorCode ? oData.ErrorCode : Enums.Notification.CantSendMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,21 @@ function PopupsContactsViewModel()
|
||||||
{
|
{
|
||||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsContacts');
|
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsContacts');
|
||||||
|
|
||||||
var self = this;
|
var
|
||||||
|
self = this,
|
||||||
this.imageUploader = ko.observable(null);
|
aNameTypes = [Enums.ContactPropertyType.FullName, Enums.ContactPropertyType.FirstName, Enums.ContactPropertyType.SurName, Enums.ContactPropertyType.MiddleName],
|
||||||
this.imageDom = ko.observable(null);
|
aEmailTypes = [Enums.ContactPropertyType.EmailPersonal, Enums.ContactPropertyType.EmailBussines, Enums.ContactPropertyType.EmailOther],
|
||||||
this.imageTrigger = ko.observable(false);
|
aPhonesTypes = [
|
||||||
|
Enums.ContactPropertyType.PhonePersonal, Enums.ContactPropertyType.PhoneBussines, Enums.ContactPropertyType.PhoneOther,
|
||||||
|
Enums.ContactPropertyType.MobilePersonal, Enums.ContactPropertyType.MobileBussines, Enums.ContactPropertyType.MobileOther,
|
||||||
|
Enums.ContactPropertyType.FaxPesonal, Enums.ContactPropertyType.FaxBussines, Enums.ContactPropertyType.FaxOther
|
||||||
|
],
|
||||||
|
fFastClearEmptyListHelper = function (aList) {
|
||||||
|
if (aList && 0 < aList.length) {
|
||||||
|
self.viewProperties.removeAll(aList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
this.search = ko.observable('');
|
this.search = ko.observable('');
|
||||||
this.contacts = ko.observableArray([]);
|
this.contacts = ko.observableArray([]);
|
||||||
|
|
@ -23,11 +33,50 @@ function PopupsContactsViewModel()
|
||||||
this.viewClearSearch = ko.observable(false);
|
this.viewClearSearch = ko.observable(false);
|
||||||
|
|
||||||
this.viewID = ko.observable('');
|
this.viewID = ko.observable('');
|
||||||
this.viewName = ko.observable('');
|
this.viewProperties = ko.observableArray([]);
|
||||||
this.viewName.focused = ko.observable(false);
|
|
||||||
this.viewEmail = ko.observable('').validateEmail();
|
this.viewPropertiesNames = this.viewProperties.filter(function(oProperty) {
|
||||||
this.viewEmail.focused = ko.observable(false);
|
return -1 < Utils.inArray(oProperty.type(), aNameTypes);
|
||||||
this.viewImageUrl = ko.observable(RL.link().emptyContactPic());
|
});
|
||||||
|
|
||||||
|
this.viewPropertiesEmails = this.viewProperties.filter(function(oProperty) {
|
||||||
|
return -1 < Utils.inArray(oProperty.type(), aEmailTypes);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.viewHasNonEmptyRequaredProperties = ko.computed(function() {
|
||||||
|
|
||||||
|
var
|
||||||
|
aNames = this.viewPropertiesNames(),
|
||||||
|
aEmail = this.viewPropertiesEmails(),
|
||||||
|
fHelper = function (oProperty) {
|
||||||
|
return '' !== Utils.trim(oProperty.value());
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
return !!(_.find(aNames, fHelper) || _.find(aEmail, fHelper));
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
this.viewPropertiesPhones = this.viewProperties.filter(function(oProperty) {
|
||||||
|
return -1 < Utils.inArray(oProperty.type(), aPhonesTypes);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.viewPropertiesEmailsEmptyAndOnFocused = this.viewPropertiesEmails.filter(function(oProperty) {
|
||||||
|
var bF = oProperty.focused();
|
||||||
|
return '' === Utils.trim(oProperty.value()) && !bF;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.viewPropertiesPhonesEmptyAndOnFocused = this.viewPropertiesPhones.filter(function(oProperty) {
|
||||||
|
var bF = oProperty.focused();
|
||||||
|
return '' === Utils.trim(oProperty.value()) && !bF;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.viewPropertiesEmailsEmptyAndOnFocused.subscribe(function(aList) {
|
||||||
|
fFastClearEmptyListHelper(aList);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.viewPropertiesPhonesEmptyAndOnFocused.subscribe(function(aList) {
|
||||||
|
fFastClearEmptyListHelper(aList);
|
||||||
|
});
|
||||||
|
|
||||||
this.viewSaving = ko.observable(false);
|
this.viewSaving = ko.observable(false);
|
||||||
|
|
||||||
|
|
@ -41,8 +90,8 @@ function PopupsContactsViewModel()
|
||||||
Utils.windowResize();
|
Utils.windowResize();
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
this.viewImageUrl.subscribe(function (sUrl) {
|
this.viewProperties.subscribe(function () {
|
||||||
this.imageDom()['src'] = sUrl;
|
Utils.windowResize();
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
this.contactsChecked = ko.computed(function () {
|
this.contactsChecked = ko.computed(function () {
|
||||||
|
|
@ -103,10 +152,14 @@ function PopupsContactsViewModel()
|
||||||
if (Utils.isNonEmptyArray(aC))
|
if (Utils.isNonEmptyArray(aC))
|
||||||
{
|
{
|
||||||
aE = _.map(aC, function (oItem) {
|
aE = _.map(aC, function (oItem) {
|
||||||
if (oItem && oItem['emails'])
|
if (oItem)
|
||||||
{
|
{
|
||||||
var oEmail = new EmailModel(oItem['emails'][0] || '', oItem['name']);
|
var
|
||||||
if (oEmail.validate())
|
aData = oItem.getNameAndEmailHelper(),
|
||||||
|
oEmail = aData ? new EmailModel(aData[0], aData[1]) : null
|
||||||
|
;
|
||||||
|
|
||||||
|
if (oEmail && oEmail.validate())
|
||||||
{
|
{
|
||||||
return oEmail;
|
return oEmail;
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +171,7 @@ function PopupsContactsViewModel()
|
||||||
aE = _.compact(aE);
|
aE = _.compact(aE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.isNonEmptyArray(aC))
|
if (Utils.isNonEmptyArray(aE))
|
||||||
{
|
{
|
||||||
kn.hideScreenPopup(PopupsContactsViewModel);
|
kn.hideScreenPopup(PopupsContactsViewModel);
|
||||||
kn.showScreenPopup(PopupsComposeViewModel, [Enums.ComposeType.Empty, null, aE]);
|
kn.showScreenPopup(PopupsComposeViewModel, [Enums.ComposeType.Empty, null, aE]);
|
||||||
|
|
@ -133,12 +186,21 @@ function PopupsContactsViewModel()
|
||||||
});
|
});
|
||||||
|
|
||||||
this.saveCommand = Utils.createCommand(this, function () {
|
this.saveCommand = Utils.createCommand(this, function () {
|
||||||
var
|
|
||||||
sRequestUid = Utils.fakeMd5(),
|
|
||||||
bImageTrigger = this.imageTrigger()
|
|
||||||
;
|
|
||||||
|
|
||||||
this.viewSaving(true);
|
this.viewSaving(true);
|
||||||
|
|
||||||
|
var
|
||||||
|
sRequestUid = Utils.fakeMd5(),
|
||||||
|
aProperties = []
|
||||||
|
;
|
||||||
|
|
||||||
|
_.each(this.viewProperties(), function (oItem) {
|
||||||
|
if (oItem.type() && '' !== Utils.trim(oItem.value()))
|
||||||
|
{
|
||||||
|
aProperties.push([oItem.type(), oItem.value()]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
RL.remote().contactSave(function (sResult, oData) {
|
RL.remote().contactSave(function (sResult, oData) {
|
||||||
|
|
||||||
self.viewSaving(false);
|
self.viewSaving(false);
|
||||||
|
|
@ -151,31 +213,42 @@ function PopupsContactsViewModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
self.reloadContactList();
|
self.reloadContactList();
|
||||||
if (bImageTrigger)
|
|
||||||
{
|
|
||||||
RL.emailsPicsHashes();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
// // TODO
|
// // TODO
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}, sRequestUid, this.viewID(), this.viewName(), this.viewEmail(), bImageTrigger ? this.imageDom()['src'] : '');
|
}, sRequestUid, this.viewID(), aProperties);
|
||||||
|
|
||||||
}, function () {
|
}, function () {
|
||||||
var
|
var bV = this.viewHasNonEmptyRequaredProperties();
|
||||||
sViewName = this.viewName(),
|
return !this.viewSaving() && bV;
|
||||||
sViewEmail = this.viewEmail()
|
|
||||||
;
|
|
||||||
|
|
||||||
return !this.viewSaving() &&
|
|
||||||
('' !== sViewName || '' !== sViewEmail);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils.extendAsViewModel('PopupsContactsViewModel', PopupsContactsViewModel);
|
Utils.extendAsViewModel('PopupsContactsViewModel', PopupsContactsViewModel);
|
||||||
|
|
||||||
|
PopupsContactsViewModel.prototype.addNewEmail = function ()
|
||||||
|
{
|
||||||
|
// if (0 === this.viewPropertiesEmailsEmpty().length)
|
||||||
|
// {
|
||||||
|
var oItem = new ContactPropertyModel(Enums.ContactPropertyType.EmailPersonal, '');
|
||||||
|
oItem.focused(true);
|
||||||
|
this.viewProperties.push(oItem);
|
||||||
|
// }
|
||||||
|
};
|
||||||
|
|
||||||
|
PopupsContactsViewModel.prototype.addNewPhone = function ()
|
||||||
|
{
|
||||||
|
// if (0 === this.viewPropertiesPhonesEmpty().length)
|
||||||
|
// {
|
||||||
|
var oItem = new ContactPropertyModel(Enums.ContactPropertyType.PhonePersonal, '');
|
||||||
|
oItem.focused(true);
|
||||||
|
this.viewProperties.push(oItem);
|
||||||
|
// }
|
||||||
|
};
|
||||||
|
|
||||||
PopupsContactsViewModel.prototype.removeCheckedOrSelectedContactsFromList = function ()
|
PopupsContactsViewModel.prototype.removeCheckedOrSelectedContactsFromList = function ()
|
||||||
{
|
{
|
||||||
var
|
var
|
||||||
|
|
@ -241,28 +314,51 @@ PopupsContactsViewModel.prototype.deleteResponse = function (sResult, oData)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PopupsContactsViewModel.prototype.removeProperty = function (oProp)
|
||||||
|
{
|
||||||
|
this.viewProperties.remove(oProp);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {?ContactModel} oContact
|
* @param {?ContactModel} oContact
|
||||||
*/
|
*/
|
||||||
PopupsContactsViewModel.prototype.populateViewContact = function (oContact)
|
PopupsContactsViewModel.prototype.populateViewContact = function (oContact)
|
||||||
{
|
{
|
||||||
this.imageTrigger(false);
|
var
|
||||||
|
sId = '',
|
||||||
|
bHasName = false,
|
||||||
|
aList = []
|
||||||
|
;
|
||||||
|
|
||||||
this.emptySelection(false);
|
this.emptySelection(false);
|
||||||
|
|
||||||
if (oContact)
|
if (oContact)
|
||||||
{
|
{
|
||||||
this.viewID(oContact.idContact);
|
sId = oContact.idContact;
|
||||||
this.viewName(oContact.name);
|
|
||||||
this.viewEmail(oContact.emails[0] || '');
|
if (Utils.isNonEmptyArray(oContact.properties))
|
||||||
this.viewImageUrl(oContact.srcAttr());
|
{
|
||||||
|
_.each(oContact.properties, function (aProperty) {
|
||||||
|
if (aProperty && aProperty[0])
|
||||||
|
{
|
||||||
|
aList.push(new ContactPropertyModel(aProperty[0], aProperty[1]));
|
||||||
|
if (Enums.ContactPropertyType.FullName === aProperty[0])
|
||||||
|
{
|
||||||
|
bHasName = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (!bHasName)
|
||||||
{
|
{
|
||||||
this.viewID('');
|
aList.push(new ContactPropertyModel(Enums.ContactPropertyType.FullName, ''));
|
||||||
this.viewName('');
|
|
||||||
this.viewEmail('');
|
|
||||||
this.viewImageUrl(RL.link().emptyContactPic());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.viewID(sId);
|
||||||
|
this.viewProperties([]);
|
||||||
|
this.viewProperties(aList);
|
||||||
};
|
};
|
||||||
|
|
||||||
PopupsContactsViewModel.prototype.reloadContactList = function ()
|
PopupsContactsViewModel.prototype.reloadContactList = function ()
|
||||||
|
|
@ -293,20 +389,16 @@ PopupsContactsViewModel.prototype.reloadContactList = function ()
|
||||||
self.contacts.setSelectedByUid('' + self.viewID());
|
self.contacts.setSelectedByUid('' + self.viewID());
|
||||||
}
|
}
|
||||||
|
|
||||||
}, this.search());
|
}, 0, 20, this.search());
|
||||||
};
|
};
|
||||||
|
|
||||||
PopupsContactsViewModel.prototype.onBuild = function (oDom)
|
PopupsContactsViewModel.prototype.onBuild = function (oDom)
|
||||||
{
|
{
|
||||||
this.initUploader();
|
|
||||||
|
|
||||||
this.oContentVisible = $('.b-list-content', oDom);
|
this.oContentVisible = $('.b-list-content', oDom);
|
||||||
this.oContentScrollable = $('.content', this.oContentVisible);
|
this.oContentScrollable = $('.content', this.oContentVisible);
|
||||||
|
|
||||||
this.selector.init(this.oContentVisible, this.oContentScrollable);
|
this.selector.init(this.oContentVisible, this.oContentScrollable);
|
||||||
|
|
||||||
this.viewImageUrl.valueHasMutated();
|
|
||||||
|
|
||||||
ko.computed(function () {
|
ko.computed(function () {
|
||||||
var
|
var
|
||||||
bModalVisibility = this.modalVisibility(),
|
bModalVisibility = this.modalVisibility(),
|
||||||
|
|
@ -316,56 +408,6 @@ PopupsContactsViewModel.prototype.onBuild = function (oDom)
|
||||||
}, this).extend({'notify': 'always'});
|
}, this).extend({'notify': 'always'});
|
||||||
};
|
};
|
||||||
|
|
||||||
PopupsContactsViewModel.prototype.initUploader = function ()
|
|
||||||
{
|
|
||||||
var self = this, oJua = null;
|
|
||||||
if (window.File && window.FileReader && this.imageUploader())
|
|
||||||
{
|
|
||||||
oJua = new Jua({
|
|
||||||
'queueSize': 1,
|
|
||||||
'multipleSizeLimit': 1,
|
|
||||||
'clickElement': this.imageUploader(),
|
|
||||||
'disableDragAndDrop': true,
|
|
||||||
'disableMultiple': true,
|
|
||||||
'onSelect': function (sId, oData) {
|
|
||||||
|
|
||||||
if (oData && oData['File'] && oData['File']['type'])
|
|
||||||
{
|
|
||||||
var
|
|
||||||
oReader = null,
|
|
||||||
oFile = oData['File'],
|
|
||||||
sType = oData['File']['type']
|
|
||||||
;
|
|
||||||
|
|
||||||
if (!sType.match(/image.*/))
|
|
||||||
{
|
|
||||||
window.alert('this file is not an image.');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
oReader = new window.FileReader();
|
|
||||||
oReader.onload = function (oEvent) {
|
|
||||||
if (oEvent && oEvent.target && oEvent.target.result)
|
|
||||||
{
|
|
||||||
Utils.resizeAndCrop(oEvent.target.result, 150, function (sUrl) {
|
|
||||||
self.viewImageUrl(sUrl);
|
|
||||||
self.imageTrigger(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
oReader.readAsDataURL(oFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return oJua;
|
|
||||||
};
|
|
||||||
|
|
||||||
PopupsContactsViewModel.prototype.onShow = function ()
|
PopupsContactsViewModel.prototype.onShow = function ()
|
||||||
{
|
{
|
||||||
kn.routeOff();
|
kn.routeOff();
|
||||||
|
|
|
||||||
20
plugins/personal-address-book-mysql/LICENSE
Normal file
20
plugins/personal-address-book-mysql/LICENSE
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2013 RainLoop Team
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
@ -0,0 +1,757 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use \RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType;
|
||||||
|
|
||||||
|
class MySqlPersonalAddressBookDriver
|
||||||
|
extends \RainLoop\Common\PdoAbstract
|
||||||
|
implements \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $sDsn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $sUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $sPassword;
|
||||||
|
|
||||||
|
public function __construct($sDsn, $sUser, $sPassword)
|
||||||
|
{
|
||||||
|
$this->sDsn = $sDsn;
|
||||||
|
$this->sUser = $sUser;
|
||||||
|
$this->sPassword = $sPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function Version()
|
||||||
|
{
|
||||||
|
return 'MySqlPersonalAddressBookDriver-v1';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function IsSupported()
|
||||||
|
{
|
||||||
|
$aDrivers = \class_exists('PDO') ? \PDO::getAvailableDrivers() : array();
|
||||||
|
return \is_array($aDrivers) ? \in_array('mysql', $aDrivers) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
* @param \RainLoop\Providers\PersonalAddressBook\Classes\Contact $oContact
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function ContactSave($oAccount, &$oContact)
|
||||||
|
{
|
||||||
|
$iUserID = $this->getUserId($oAccount->ParentEmailHelper());
|
||||||
|
$iIdContact = \strlen($oContact->IdContact) && \is_numeric($oContact->IdContact) ? (int) $oContact->IdContact : 0;
|
||||||
|
|
||||||
|
$bUpdate = 0 < $iIdContact;
|
||||||
|
|
||||||
|
$oContact->UpdateDependentValues();
|
||||||
|
$oContact->Changed = \time();
|
||||||
|
|
||||||
|
if (!$oContact->Auto)
|
||||||
|
{
|
||||||
|
$aEmail = $oContact->GetEmails();
|
||||||
|
if (0 < \count($aEmail))
|
||||||
|
{
|
||||||
|
$aEmail = \array_map(function ($sValue) {
|
||||||
|
return \strtolower(\trim($sValue));
|
||||||
|
}, $aEmail);
|
||||||
|
|
||||||
|
$aEmail = \array_filter($aEmail, function ($sValue) {
|
||||||
|
return !empty($sValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (0 < \count($aEmail))
|
||||||
|
{
|
||||||
|
$self = $this;
|
||||||
|
$aEmail = \array_map(function ($sValue) use ($self) {
|
||||||
|
return $self->quoteValue($sValue);
|
||||||
|
}, $aEmail);
|
||||||
|
|
||||||
|
|
||||||
|
// clear autocreated contacts
|
||||||
|
$this->prepareAndExecute(
|
||||||
|
'DELETE FROM `rainloop_pab_contacts` WHERE `id_user` = :id_user AND `auto` = 1 AND `display_email` IN ('.\implode(',', $aEmail).')',
|
||||||
|
array(
|
||||||
|
':id_user' => array($iUserID, \PDO::PARAM_INT)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$this->beginTransaction();
|
||||||
|
|
||||||
|
$aFreq = array();
|
||||||
|
if ($bUpdate)
|
||||||
|
{
|
||||||
|
$aFreq = $this->getContactFreq($iUserID, $iIdContact);
|
||||||
|
|
||||||
|
$sSql = 'UPDATE `rainloop_pab_contacts` SET `display` = :display, `display_name` = :display_name, `display_email` = :display_email, '.
|
||||||
|
'`auto` = :auto, `changed` = :changed WHERE id_user = :id_user AND `id_contact` = :id_contact';
|
||||||
|
|
||||||
|
$this->prepareAndExecute($sSql,
|
||||||
|
array(
|
||||||
|
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||||
|
':id_contact' => array($iIdContact, \PDO::PARAM_INT),
|
||||||
|
':display' => array($oContact->Display, \PDO::PARAM_STR),
|
||||||
|
':display_name' => array($oContact->DisplayName, \PDO::PARAM_STR),
|
||||||
|
':display_email' => array($oContact->DisplayEmail, \PDO::PARAM_STR),
|
||||||
|
':auto' => array($oContact->Auto, \PDO::PARAM_INT),
|
||||||
|
':changed' => array($oContact->Changed, \PDO::PARAM_INT),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// clear previos props
|
||||||
|
$this->prepareAndExecute(
|
||||||
|
'DELETE FROM `rainloop_pab_prop` WHERE `id_user` = :id_user AND `id_contact` = :id_contact',
|
||||||
|
array(
|
||||||
|
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||||
|
':id_contact' => array($iIdContact, \PDO::PARAM_INT)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sSql = 'INSERT INTO `rainloop_pab_contacts` '.
|
||||||
|
'(`id_user`, `display`, `display_name`, `display_email`, `auto`, `changed`) VALUES '.
|
||||||
|
'(:id_user, :display, :display_name, :display_email, :auto, :changed)';
|
||||||
|
|
||||||
|
$this->prepareAndExecute($sSql,
|
||||||
|
array(
|
||||||
|
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||||
|
':display' => array($oContact->Display, \PDO::PARAM_STR),
|
||||||
|
':display_name' => array($oContact->DisplayName, \PDO::PARAM_STR),
|
||||||
|
':display_email' => array($oContact->DisplayEmail, \PDO::PARAM_STR),
|
||||||
|
':auto' => array($oContact->Auto, \PDO::PARAM_INT),
|
||||||
|
':changed' => array($oContact->Changed, \PDO::PARAM_INT)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$sLast = $this->lastInsertId('id_contact');
|
||||||
|
if (\is_numeric($sLast) && 0 < (int) $sLast)
|
||||||
|
{
|
||||||
|
$iIdContact = (int) $sLast;
|
||||||
|
$oContact->IdContact = (string) $iIdContact;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 < $iIdContact)
|
||||||
|
{
|
||||||
|
$aParams = array();
|
||||||
|
foreach ($oContact->Properties as /* @var $oProp \RainLoop\Providers\PersonalAddressBook\Classes\Property */ $oProp)
|
||||||
|
{
|
||||||
|
$iFreq = $oProp->Frec;
|
||||||
|
if ($oProp->IsEmail() && isset($aFreq[$oProp->Value]))
|
||||||
|
{
|
||||||
|
$iFreq = $aFreq[$oProp->Value];
|
||||||
|
}
|
||||||
|
|
||||||
|
$aParams[] = array(
|
||||||
|
':id_contact' => array($iIdContact, \PDO::PARAM_INT),
|
||||||
|
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||||
|
':type' => array($oProp->Type, \PDO::PARAM_INT),
|
||||||
|
':type_custom' => array($oProp->TypeCustom, \PDO::PARAM_STR),
|
||||||
|
':value' => array($oProp->Value, \PDO::PARAM_STR),
|
||||||
|
':value_custom' => array($oProp->ValueClear, \PDO::PARAM_STR),
|
||||||
|
':frec' => array($iFreq, \PDO::PARAM_INT),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sSql = 'INSERT INTO `rainloop_pab_prop` '.
|
||||||
|
'(`id_contact`, `id_user`, `type`, `type_custom`, `value`, `value_custom`, `frec`) VALUES '.
|
||||||
|
'(:id_contact, :id_user, :type, :type_custom, :value, :value_custom, :frec)';
|
||||||
|
|
||||||
|
$this->prepareAndExecute($sSql, $aParams, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (\Exception $oException)
|
||||||
|
{
|
||||||
|
$this->rollBack();
|
||||||
|
throw $oException;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->commit();
|
||||||
|
|
||||||
|
return 0 < $iIdContact;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
* @param array $aContactIds
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function DeleteContacts($oAccount, $aContactIds)
|
||||||
|
{
|
||||||
|
$iUserID = $this->getUserId($oAccount->ParentEmailHelper());
|
||||||
|
|
||||||
|
$aContactIds = \array_filter($aContactIds, function (&$mItem) {
|
||||||
|
$mItem = (int) \trim($mItem);
|
||||||
|
return 0 < $mItem;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (0 === \count($aContactIds))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !!$this->prepareAndExecute(
|
||||||
|
'DELETE FROM `rainloop_pab_contacts` WHERE `id_user` = :id_user AND `id_contact` IN ('.\implode(',', $aContactIds).')',
|
||||||
|
array(':id_user' => array($iUserID, \PDO::PARAM_INT)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
* @param int $iOffset = 0
|
||||||
|
* @param int $iLimit = 20
|
||||||
|
* @param string $sSearch = ''
|
||||||
|
* @param bool $bAutoOnly = false
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function GetContacts($oAccount, $iOffset = 0, $iLimit = 20, $sSearch = '', $bAutoOnly = false)
|
||||||
|
{
|
||||||
|
$iOffset = 0 <= $iOffset ? $iOffset : 0;
|
||||||
|
$iLimit = 0 < $iLimit ? (int) $iLimit : 20;
|
||||||
|
$sSearch = \trim($sSearch);
|
||||||
|
|
||||||
|
$iUserID = $this->getUserId($oAccount->ParentEmailHelper());
|
||||||
|
|
||||||
|
$sSql = 'SELECT * FROM `rainloop_pab_contacts` WHERE id_user = :id_user AND `auto` = :auto';
|
||||||
|
$aParams = array(
|
||||||
|
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||||
|
':auto' => array($bAutoOnly ? 1 : 0, \PDO::PARAM_INT)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (0 < \strlen($sSearch))
|
||||||
|
{
|
||||||
|
$sSql .= ' AND `id_contact` IN ('.
|
||||||
|
'SELECT DISTINCT `id_contact` FROM `rainloop_pab_prop` WHERE id_user = :id_user AND `value` LIKE :search ESCAPE \'=\''.
|
||||||
|
')';
|
||||||
|
|
||||||
|
$aParams[':search'] = array($this->specialConvertSearchValue($sSearch, '='), \PDO::PARAM_STR);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sSql .= ' ORDER BY `display` ASC LIMIT :limit OFFSET :offset';
|
||||||
|
$aParams[':limit'] = array($iLimit, \PDO::PARAM_INT);
|
||||||
|
$aParams[':offset'] = array($iOffset, \PDO::PARAM_INT);
|
||||||
|
|
||||||
|
$oStmt = $this->prepareAndExecute($sSql, $aParams);
|
||||||
|
if ($oStmt)
|
||||||
|
{
|
||||||
|
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
$aContacts = array();
|
||||||
|
$aIdContacts = array();
|
||||||
|
if (\is_array($aFetch) && 0 < \count($aFetch))
|
||||||
|
{
|
||||||
|
foreach ($aFetch as $aItem)
|
||||||
|
{
|
||||||
|
$iIdContact = $aItem && isset($aItem['id_contact']) ? (int) $aItem['id_contact'] : 0;
|
||||||
|
if (0 < $iIdContact)
|
||||||
|
{
|
||||||
|
$aIdContacts[] = $iIdContact;
|
||||||
|
$oContact = new \RainLoop\Providers\PersonalAddressBook\Classes\Contact();
|
||||||
|
|
||||||
|
$oContact->IdContact = (string) $iIdContact;
|
||||||
|
$oContact->Display = isset($aItem['display']) ? (string) $aItem['display'] : '';
|
||||||
|
$oContact->DisplayName = isset($aItem['display_name']) ? (string) $aItem['display_name'] : '';
|
||||||
|
$oContact->DisplayEmail = isset($aItem['display_email']) ? (string) $aItem['display_email'] : '';
|
||||||
|
$oContact->Auto = isset($aItem['auto']) ? (bool) $aItem['auto'] : false;
|
||||||
|
$oContact->Changed = isset($aItem['changed']) ? (int) $aItem['changed'] : 0;
|
||||||
|
|
||||||
|
$aContacts[$iIdContact] = $oContact;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($aFetch);
|
||||||
|
|
||||||
|
if (0 < count($aIdContacts))
|
||||||
|
{
|
||||||
|
$oStmt->closeCursor();
|
||||||
|
|
||||||
|
$sSql = 'SELECT * FROM `rainloop_pab_prop` WHERE id_user = :id_user AND `id_contact` IN ('.\implode(',', $aIdContacts).')';
|
||||||
|
$oStmt = $this->prepareAndExecute($sSql, array(
|
||||||
|
':id_user' => array($iUserID, \PDO::PARAM_INT)
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($oStmt)
|
||||||
|
{
|
||||||
|
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
|
if (\is_array($aFetch) && 0 < \count($aFetch))
|
||||||
|
{
|
||||||
|
foreach ($aFetch as $aItem)
|
||||||
|
{
|
||||||
|
if ($aItem && isset($aItem['id_prop'], $aItem['id_contact'], $aItem['type'], $aItem['value']))
|
||||||
|
{
|
||||||
|
$iId = (int) $aItem['id_contact'];
|
||||||
|
if (0 < $iId && isset($aContacts[$iId]))
|
||||||
|
{
|
||||||
|
$oProperty = new \RainLoop\Providers\PersonalAddressBook\Classes\Property();
|
||||||
|
$oProperty->Type = (int) $aItem['type'];
|
||||||
|
$oProperty->TypeCustom = isset($aItem['type_custom']) ? (string) $aItem['type_custom'] : '';
|
||||||
|
$oProperty->Value = (string) $aItem['value'];
|
||||||
|
$oProperty->ValueClear = isset($aItem['value_clear']) ? (string) $aItem['value_clear'] : '';
|
||||||
|
$oProperty->Frec = isset($aItem['frec']) ? (int) $aItem['frec'] : 0;
|
||||||
|
|
||||||
|
$aContacts[$iId]->Properties[] = $oProperty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($aFetch);
|
||||||
|
|
||||||
|
foreach ($aContacts as &$oItem)
|
||||||
|
{
|
||||||
|
$oItem->UpdateDependentValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
return \array_values($aContacts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
* @param string $sSearch
|
||||||
|
* @param int $iLimit = 20
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function GetSuggestions($oAccount, $sSearch, $iLimit = 20)
|
||||||
|
{
|
||||||
|
$sSearch = \trim($sSearch);
|
||||||
|
if (0 === \strlen($sSearch))
|
||||||
|
{
|
||||||
|
throw new \InvalidArgumentException('Empty Search argument');
|
||||||
|
}
|
||||||
|
|
||||||
|
$iUserID = $this->getUserId($oAccount->ParentEmailHelper());
|
||||||
|
|
||||||
|
$sTypes = implode(',', array(
|
||||||
|
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER, PropertyType::FULLNAME
|
||||||
|
));
|
||||||
|
|
||||||
|
$sSql = 'SELECT `id_contact`, `id_prop`, `type`, `value` FROM `rainloop_pab_prop` '.
|
||||||
|
'WHERE id_user = :id_user AND `type` IN ('.$sTypes.') AND `value` LIKE :search ESCAPE \'=\'';
|
||||||
|
|
||||||
|
$aParams = array(
|
||||||
|
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||||
|
':limit' => array($iLimit, \PDO::PARAM_INT),
|
||||||
|
':search' => array($this->specialConvertSearchValue($sSearch, '='), \PDO::PARAM_STR)
|
||||||
|
);
|
||||||
|
|
||||||
|
$sSql .= ' ORDER BY `frec` DESC LIMIT :limit';
|
||||||
|
|
||||||
|
$aResult = array();
|
||||||
|
$aFirstResult = array();
|
||||||
|
$aSkipIds = array();
|
||||||
|
|
||||||
|
$oStmt = $this->prepareAndExecute($sSql, $aParams);
|
||||||
|
if ($oStmt)
|
||||||
|
{
|
||||||
|
$aIdContacts = array();
|
||||||
|
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
|
if (\is_array($aFetch) && 0 < \count($aFetch))
|
||||||
|
{
|
||||||
|
foreach ($aFetch as $aItem)
|
||||||
|
{
|
||||||
|
$iIdContact = $aItem && isset($aItem['id_contact']) ? (int) $aItem['id_contact'] : 0;
|
||||||
|
if (0 < $iIdContact)
|
||||||
|
{
|
||||||
|
$aIdContacts[$iIdContact] = $iIdContact;
|
||||||
|
$iType = isset($aItem['type']) ? (int) $aItem['type'] : PropertyType::UNKNOWN;
|
||||||
|
|
||||||
|
if (\in_array($iType, array(PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER, PropertyType::FULLNAME)))
|
||||||
|
{
|
||||||
|
if (!\in_array($iIdContact, $aSkipIds))
|
||||||
|
{
|
||||||
|
if (PropertyType::FULLNAME === $iType)
|
||||||
|
{
|
||||||
|
$aSkipIds[] = $iIdContact;
|
||||||
|
}
|
||||||
|
|
||||||
|
$aFirstResult[] = array(
|
||||||
|
'id_prop' => isset($aItem['id_prop']) ? (int) $aItem['id_prop'] : 0,
|
||||||
|
'id_contact' => $iIdContact,
|
||||||
|
'value' => isset($aItem['value']) ? (string) $aItem['value'] : '',
|
||||||
|
'type' => $iType
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($aFetch);
|
||||||
|
|
||||||
|
$aIdContacts = \array_values($aIdContacts);
|
||||||
|
if (0 < count($aIdContacts))
|
||||||
|
{
|
||||||
|
$oStmt->closeCursor();
|
||||||
|
|
||||||
|
$sTypes = \implode(',', array(
|
||||||
|
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER, PropertyType::FULLNAME
|
||||||
|
));
|
||||||
|
|
||||||
|
$sSql = 'SELECT `id_prop`, `id_contact`, `type`, `value` FROM `rainloop_pab_prop` '.
|
||||||
|
'WHERE id_user = :id_user AND `type` IN ('.$sTypes.') AND `id_contact` IN ('.\implode(',', $aIdContacts).')';
|
||||||
|
|
||||||
|
$oStmt = $this->prepareAndExecute($sSql, array(
|
||||||
|
':id_user' => array($iUserID, \PDO::PARAM_INT)
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($oStmt)
|
||||||
|
{
|
||||||
|
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
|
if (\is_array($aFetch) && 0 < \count($aFetch))
|
||||||
|
{
|
||||||
|
$aNames = array();
|
||||||
|
$aEmails = array();
|
||||||
|
|
||||||
|
foreach ($aFetch as $aItem)
|
||||||
|
{
|
||||||
|
if ($aItem && isset($aItem['id_prop'], $aItem['id_contact'], $aItem['type'], $aItem['value']))
|
||||||
|
{
|
||||||
|
$iIdContact = (int) $aItem['id_contact'];
|
||||||
|
$iType = (int) $aItem['type'];
|
||||||
|
|
||||||
|
if (PropertyType::FULLNAME === $iType)
|
||||||
|
{
|
||||||
|
$aNames[$iIdContact] = $aItem['value'];
|
||||||
|
}
|
||||||
|
else if (\in_array($iType,
|
||||||
|
array(PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER)))
|
||||||
|
{
|
||||||
|
if (!isset($aEmails[$iIdContact]))
|
||||||
|
{
|
||||||
|
$aEmails[$iIdContact] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$aEmails[$iIdContact][] = $aItem['value'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($aFirstResult as $aItem)
|
||||||
|
{
|
||||||
|
if ($aItem && !empty($aItem['value']))
|
||||||
|
{
|
||||||
|
$iIdContact = (int) $aItem['id_contact'];
|
||||||
|
$iType = (int) $aItem['type'];
|
||||||
|
|
||||||
|
if (PropertyType::FULLNAME === $iType)
|
||||||
|
{
|
||||||
|
if (isset($aEmails[$iIdContact]) && \is_array($aEmails[$iIdContact]))
|
||||||
|
{
|
||||||
|
foreach ($aEmails[$iIdContact] as $sEmail)
|
||||||
|
{
|
||||||
|
if (!empty($sEmail))
|
||||||
|
{
|
||||||
|
$aResult[] = array($sEmail, (string) $aItem['value']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (\in_array($iType,
|
||||||
|
array(PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER)))
|
||||||
|
{
|
||||||
|
$aResult[] = array((string) $aItem['value'],
|
||||||
|
isset($aNames[$iIdContact]) ? (string) $aNames[$iIdContact] : '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($aFetch);
|
||||||
|
|
||||||
|
if ($iLimit < \count($aResult))
|
||||||
|
{
|
||||||
|
$aResult = \array_slice($aResult, 0, $iLimit);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $aResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
* @param array $aEmails
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function IncFrec($oAccount, $aEmails)
|
||||||
|
{
|
||||||
|
$iUserID = $this->getUserId($oAccount->ParentEmailHelper());
|
||||||
|
|
||||||
|
$self = $this;
|
||||||
|
$aEmailsObjects = \array_map(function ($mItem) {
|
||||||
|
$oResult = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$oResult = \MailSo\Mime\Email::Parse(\trim($mItem));
|
||||||
|
}
|
||||||
|
catch (\Exception $oException) {}
|
||||||
|
return $oResult;
|
||||||
|
}, $aEmails);
|
||||||
|
|
||||||
|
if (0 === \count($aEmailsObjects))
|
||||||
|
{
|
||||||
|
throw new \InvalidArgumentException('Empty Emails argument');
|
||||||
|
}
|
||||||
|
|
||||||
|
$sTypes = \implode(',', array(
|
||||||
|
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER
|
||||||
|
));
|
||||||
|
|
||||||
|
$sSql = 'SELECT `value` FROM `rainloop_pab_prop` WHERE id_user = :id_user AND `type` IN ('.$sTypes.')';
|
||||||
|
$oStmt = $this->prepareAndExecute($sSql, array(
|
||||||
|
':id_user' => array($iUserID, \PDO::PARAM_INT)
|
||||||
|
));
|
||||||
|
|
||||||
|
$aExists = array();
|
||||||
|
if ($oStmt)
|
||||||
|
{
|
||||||
|
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
|
if (\is_array($aFetch) && 0 < \count($aFetch))
|
||||||
|
{
|
||||||
|
foreach ($aFetch as $aItem)
|
||||||
|
{
|
||||||
|
if ($aItem && !empty($aItem['value']))
|
||||||
|
{
|
||||||
|
$aExists[] = \strtolower(\trim($aItem['value']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$aEmailsToUpdate = array();
|
||||||
|
$aEmailsToCreate = \array_filter($aEmailsObjects, function ($oItem) use ($aExists, &$aEmailsToUpdate) {
|
||||||
|
if ($oItem)
|
||||||
|
{
|
||||||
|
$sEmail = \strtolower(\trim($oItem->GetEmail()));
|
||||||
|
if (0 < \strlen($sEmail))
|
||||||
|
{
|
||||||
|
$aEmailsToUpdate[] = $sEmail;
|
||||||
|
return !\in_array($sEmail, $aExists);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
unset($aEmails, $aEmailsObjects);
|
||||||
|
|
||||||
|
if (0 < \count($aEmailsToCreate))
|
||||||
|
{
|
||||||
|
$oContact = new \RainLoop\Providers\PersonalAddressBook\Classes\Contact();
|
||||||
|
foreach ($aEmailsToCreate as $oEmail)
|
||||||
|
{
|
||||||
|
$oContact->Auto = true;
|
||||||
|
|
||||||
|
if ('' !== \trim($oEmail->GetEmail()))
|
||||||
|
{
|
||||||
|
$oPropEmail = new \RainLoop\Providers\PersonalAddressBook\Classes\Property();
|
||||||
|
$oPropEmail->Type = \RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType::EMAIl_PERSONAL;
|
||||||
|
$oPropEmail->Value = \strtolower(\trim($oEmail->GetEmail()));
|
||||||
|
|
||||||
|
$oContact->Properties[] = $oPropEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('' !== \trim($oEmail->GetDisplayName()))
|
||||||
|
{
|
||||||
|
$oPropName = new \RainLoop\Providers\PersonalAddressBook\Classes\Property();
|
||||||
|
$oPropName->Type = \RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType::FULLNAME;
|
||||||
|
$oPropName->Value = \trim($oEmail->GetDisplayName());
|
||||||
|
|
||||||
|
$oContact->Properties[] = $oPropName;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 < \count($oContact->Properties))
|
||||||
|
{
|
||||||
|
$this->ContactSave($oAccount, $oContact);
|
||||||
|
}
|
||||||
|
|
||||||
|
$oContact->Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sSql = 'UPDATE `rainloop_pab_prop` SET `frec` = `frec` + 1 WHERE id_user = :id_user AND `type` IN ('.$sTypes;
|
||||||
|
|
||||||
|
$aEmailsQuoted = \array_map(function ($mItem) use ($self) {
|
||||||
|
return $self->quoteValue($mItem);
|
||||||
|
}, $aEmailsToUpdate);
|
||||||
|
|
||||||
|
if (1 === \count($aEmailsQuoted))
|
||||||
|
{
|
||||||
|
$sSql .= ') AND `value` = '.$aEmailsQuoted[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sSql .= ') AND `value` IN ('.\implode(',', $aEmailsQuoted).')';
|
||||||
|
}
|
||||||
|
|
||||||
|
return !!$this->prepareAndExecute($sSql, array(
|
||||||
|
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function SynchronizeStorage()
|
||||||
|
{
|
||||||
|
return $this->dataBaseUpgrade('mysql-pab-version', array(
|
||||||
|
1 => array(
|
||||||
|
|
||||||
|
// -- rainloop_pab_contacts --
|
||||||
|
'CREATE TABLE IF NOT EXISTS `rainloop_pab_contacts` (
|
||||||
|
|
||||||
|
`id_contact` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`id_user` int(11) UNSIGNED NOT NULL,
|
||||||
|
`display` varchar(255) NOT NULL DEFAULT \'\',
|
||||||
|
`display_name` varchar(255) NOT NULL DEFAULT \'\',
|
||||||
|
`display_email` varchar(255) NOT NULL DEFAULT \'\',
|
||||||
|
`auto` int(1) UNSIGNED NOT NULL DEFAULT \'0\',
|
||||||
|
`changed` int(11) UNSIGNED NOT NULL DEFAULT \'0\',
|
||||||
|
|
||||||
|
PRIMARY KEY(`id_contact`),
|
||||||
|
CONSTRAINT `id_user_fk_rainloop_pab_contacts` FOREIGN KEY (`id_user`)
|
||||||
|
REFERENCES `rainloop_users` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
|
||||||
|
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;',
|
||||||
|
|
||||||
|
// -- rainloop_pab_prop --
|
||||||
|
'CREATE TABLE IF NOT EXISTS `rainloop_pab_prop` (
|
||||||
|
|
||||||
|
`id_prop` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`id_contact` int(11) UNSIGNED NOT NULL,
|
||||||
|
`id_user` int(11) UNSIGNED NOT NULL,
|
||||||
|
`type` int(11) UNSIGNED NOT NULL,
|
||||||
|
`type_custom` varchar(50) /*!40101 CHARACTER SET ascii COLLATE ascii_general_ci */ NOT NULL DEFAULT \'\',
|
||||||
|
`value` varchar(255) NOT NULL DEFAULT \'\',
|
||||||
|
`value_custom` varchar(255) NOT NULL DEFAULT \'\',
|
||||||
|
`frec` int(11) UNSIGNED NOT NULL DEFAULT \'0\',
|
||||||
|
|
||||||
|
PRIMARY KEY(`id_prop`),
|
||||||
|
INDEX `id_user_id_contact_index` (`id_user`, `id_contact`),
|
||||||
|
INDEX `id_user_value_index` (`id_user`, `value`),
|
||||||
|
CONSTRAINT `id_contact_fk_rainloop_pab_prop` FOREIGN KEY (`id_contact`)
|
||||||
|
REFERENCES `rainloop_pab_contacts` (`id_contact`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
|
||||||
|
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;',
|
||||||
|
|
||||||
|
// -- rainloop_pab_tags --
|
||||||
|
'CREATE TABLE IF NOT EXISTS `rainloop_pab_tags` (
|
||||||
|
|
||||||
|
`id_tag` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`id_contact` int(11) UNSIGNED NOT NULL,
|
||||||
|
`id_user` int(11) UNSIGNED NOT NULL,
|
||||||
|
`name` varchar(255) NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY(`id_tag`),
|
||||||
|
UNIQUE `id_user_name_unique` (`id_user`, `name`),
|
||||||
|
CONSTRAINT `id_user_fk_rainloop_pab_tags` FOREIGN KEY (`id_user`)
|
||||||
|
REFERENCES `rainloop_users` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
|
||||||
|
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;',
|
||||||
|
|
||||||
|
// -- rainloop_pab_tags_contacts --
|
||||||
|
'CREATE TABLE IF NOT EXISTS `rainloop_pab_tags_contacts` (
|
||||||
|
|
||||||
|
`id_tag` int(11) UNSIGNED NOT NULL,
|
||||||
|
`id_contact` int(11) UNSIGNED NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT `id_contact_fk_rainloop_tags_contacts` FOREIGN KEY (`id_contact`)
|
||||||
|
REFERENCES `rainloop_pab_contacts` (`id_contact`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `id_tag_fk_rainloop_tags_contacts` FOREIGN KEY (`id_tag`)
|
||||||
|
REFERENCES `rainloop_pab_tags` (`id_tag`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
|
||||||
|
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;'
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $iUserID
|
||||||
|
* @param int $iIdContact
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getContactFreq($iUserID, $iIdContact)
|
||||||
|
{
|
||||||
|
$aResult = array();
|
||||||
|
|
||||||
|
$sTypes = \implode(',', array(
|
||||||
|
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER
|
||||||
|
));
|
||||||
|
|
||||||
|
$sSql = 'SELECT `value`, `frec` FROM `rainloop_pab_prop` WHERE id_user = :id_user AND `id_contact` = :id_contact AND `type` IN ('.$sTypes.')';
|
||||||
|
$aParams = array(
|
||||||
|
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||||
|
':id_contact' => array($iIdContact, \PDO::PARAM_INT)
|
||||||
|
);
|
||||||
|
|
||||||
|
$oStmt = $this->prepareAndExecute($sSql, $aParams);
|
||||||
|
if ($oStmt)
|
||||||
|
{
|
||||||
|
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
|
if (\is_array($aFetch))
|
||||||
|
{
|
||||||
|
foreach ($aFetch as $aItem)
|
||||||
|
{
|
||||||
|
if ($aItem && !empty($aItem['value']) && !empty($aItem['frec']))
|
||||||
|
{
|
||||||
|
$aResult[$aItem['value']] = (int) $aItem['frec'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $aResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sSearch
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function specialConvertSearchValue($sSearch, $sEscapeSign = '=')
|
||||||
|
{
|
||||||
|
return '%'.\str_replace(array($sEscapeSign, '_', '%'),
|
||||||
|
array($sEscapeSign.$sEscapeSign, $sEscapeSign.'_', $sEscapeSign.'%'), $sSearch).'%';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getPdoAccessData()
|
||||||
|
{
|
||||||
|
return array('mysql', $this->sDsn, $this->sUser, $this->sPassword);
|
||||||
|
}
|
||||||
|
}
|
||||||
1
plugins/personal-address-book-mysql/README
Normal file
1
plugins/personal-address-book-mysql/README
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Personal addressbook plugin (MySQL)
|
||||||
1
plugins/personal-address-book-mysql/VERSION
Normal file
1
plugins/personal-address-book-mysql/VERSION
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
1.0
|
||||||
70
plugins/personal-address-book-mysql/index.php
Normal file
70
plugins/personal-address-book-mysql/index.php
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class PersonalAddressBookMysqlPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function Init()
|
||||||
|
{
|
||||||
|
$this->addHook('main.fabrica', 'MainFabrica');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function Supported()
|
||||||
|
{
|
||||||
|
if (!extension_loaded('pdo') || !class_exists('PDO'))
|
||||||
|
{
|
||||||
|
return 'The PHP exention PDO (mysql) must be installed to use this plugin';
|
||||||
|
}
|
||||||
|
|
||||||
|
$aDrivers = \PDO::getAvailableDrivers();
|
||||||
|
if (!is_array($aDrivers) || !in_array('mysql', $aDrivers))
|
||||||
|
{
|
||||||
|
return 'The PHP exention PDO (mysql) must be installed to use this plugin';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sName
|
||||||
|
* @param mixed $oProvider
|
||||||
|
*/
|
||||||
|
public function MainFabrica($sName, &$oProvider)
|
||||||
|
{
|
||||||
|
if (!$oProvider && 'personal-address-book' === $sName &&
|
||||||
|
$this->Config()->Get('plugin', 'enabled', false))
|
||||||
|
{
|
||||||
|
$sDsn = \trim($this->Config()->Get('plugin', 'pdo_dsn', ''));
|
||||||
|
$sUser = \trim($this->Config()->Get('plugin', 'user', ''));
|
||||||
|
$sPassword = (string) $this->Config()->Get('plugin', 'password', '');
|
||||||
|
|
||||||
|
include_once __DIR__.'/MySqlPersonalAddressBookDriver.php';
|
||||||
|
|
||||||
|
$oProvider = new MySqlPersonalAddressBookDriver($sDsn, $sUser, $sPassword);
|
||||||
|
$oProvider->SetLogger($this->Manager()->Actions()->Logger());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function configMapping()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
\RainLoop\Plugins\Property::NewInstance('enabled')->SetLabel('Enable')
|
||||||
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
|
->SetDefaultValue(false),
|
||||||
|
\RainLoop\Plugins\Property::NewInstance('pdo_dsn')->SetLabel('PDO dsn')
|
||||||
|
->SetDefaultValue('mysql:host=127.0.0.1;port=3306;dbname=rainloop'),
|
||||||
|
\RainLoop\Plugins\Property::NewInstance('user')->SetLabel('DB User')
|
||||||
|
->SetDefaultValue('root'),
|
||||||
|
\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('DB Password')
|
||||||
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
|
||||||
|
->SetDefaultValue('')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
109
plugins/personal-address-book-mysql/mysql-schema.sql
Normal file
109
plugins/personal-address-book-mysql/mysql-schema.sql
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
-- RainLoop Webmail initial contacts database structure
|
||||||
|
|
||||||
|
/*!40014 SET FOREIGN_KEY_CHECKS=0 */;
|
||||||
|
|
||||||
|
-- Table structure for table `rainloop_system`
|
||||||
|
CREATE TABLE IF NOT EXISTS `rainloop_system` (
|
||||||
|
`name` varchar(50) NOT NULL,
|
||||||
|
`value_int` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`value_str` varchar(255) NOT NULL DEFAULT ''
|
||||||
|
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
|
||||||
|
|
||||||
|
-- Table structure for table `rainloop_users`
|
||||||
|
CREATE TABLE IF NOT EXISTS `rainloop_users` (
|
||||||
|
`id_user` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`email` varchar(255) /*!40101 CHARACTER SET ascii COLLATE ascii_general_ci */ NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE `email_unique` (`email`),
|
||||||
|
PRIMARY KEY(`id_user`)
|
||||||
|
) /*!40000 ENGINE=INNODB */;
|
||||||
|
|
||||||
|
-- Table structure for table `rainloop_pab_contacts`
|
||||||
|
CREATE TABLE IF NOT EXISTS `rainloop_pab_contacts` (
|
||||||
|
`id_contact` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`id_user` int(11) UNSIGNED NOT NULL,
|
||||||
|
`display_in_list` varchar(255) NOT NULL DEFAULT '',
|
||||||
|
`type` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
`changed` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
|
||||||
|
CONSTRAINT `id_user_fk_rainloop_pab_contacts` FOREIGN KEY (`id_user`)
|
||||||
|
REFERENCES `rainloop_users` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
PRIMARY KEY(`id_contact`)
|
||||||
|
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
|
||||||
|
|
||||||
|
-- Table structure for table `rainloop_pab_prop`
|
||||||
|
CREATE TABLE IF NOT EXISTS `rainloop_pab_prop` (
|
||||||
|
`id_prop` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`id_contact` int(11) UNSIGNED NOT NULL,
|
||||||
|
`id_user` int(11) UNSIGNED NOT NULL,
|
||||||
|
`type` int(11) UNSIGNED NOT NULL,
|
||||||
|
`type_custom` varchar(50) /*!40101 CHARACTER SET ascii COLLATE ascii_general_ci */ NOT NULL DEFAULT '',
|
||||||
|
`value` varchar(255) NOT NULL DEFAULT '',
|
||||||
|
`value_custom` varchar(255) NOT NULL DEFAULT '',
|
||||||
|
`frec` int(11) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
|
||||||
|
INDEX `id_user_id_contact_index` (`id_user`, `id_contact`),
|
||||||
|
INDEX `id_user_value_index` (`id_user`, `value`),
|
||||||
|
CONSTRAINT `id_contact_fk_rainloop_pab_prop` FOREIGN KEY (`id_contact`)
|
||||||
|
REFERENCES `rainloop_pab_contacts` (`id_contact`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
|
||||||
|
|
||||||
|
-- Table structure for table `rainloop_pab_tags`
|
||||||
|
CREATE TABLE IF NOT EXISTS `rainloop_pab_tags` (
|
||||||
|
`id_tag` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`id_contact` int(11) UNSIGNED NOT NULL,
|
||||||
|
`id_user` int(11) UNSIGNED NOT NULL,
|
||||||
|
`name` varchar(255) NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE `id_user_name_unique` (`id_user`, `name`),
|
||||||
|
CONSTRAINT `id_user_fk_rainloop_pab_tags` FOREIGN KEY (`id_user`)
|
||||||
|
REFERENCES `rainloop_users` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
PRIMARY KEY(`id_tag`)
|
||||||
|
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
|
||||||
|
|
||||||
|
-- Table structure for table `rainloop_pab_tags_contacts`
|
||||||
|
CREATE TABLE IF NOT EXISTS `rainloop_pab_tags_contacts` (
|
||||||
|
`id_tag` int(11) UNSIGNED NOT NULL,
|
||||||
|
`id_contact` int(11) UNSIGNED NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE `id_user_name_unique` (`id_user`, `name`),
|
||||||
|
CONSTRAINT `id_contact_fk_rainloop_tags_contacts` FOREIGN KEY (`id_contact`)
|
||||||
|
REFERENCES `rainloop_pab_contacts` (`id_contact`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `id_tag_fk_rainloop_tags_contacts` FOREIGN KEY (`id_tag`)
|
||||||
|
REFERENCES `rainloop_pab_tags` (`id_tag`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
|
||||||
|
|
||||||
|
-- RainLoop Webmail update contacts database structure
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
|
||||||
|
DROP PROCEDURE IF EXISTS rainloop_pab_upgrade_database $$
|
||||||
|
|
||||||
|
CREATE PROCEDURE rainloop_pab_upgrade_database()
|
||||||
|
BEGIN
|
||||||
|
DECLARE new_version INT DEFAULT 1;
|
||||||
|
DECLARE current_version INT DEFAULT 0;
|
||||||
|
SELECT IFNULL(MAX(`value_int`), 0) INTO current_version FROM `rainloop_system` WHERE `name` = 'rainloop-pab-db-version';
|
||||||
|
|
||||||
|
-- TODO
|
||||||
|
--
|
||||||
|
-- IF current_version < 1 THEN
|
||||||
|
-- ALTER TABLE `rainloop_pab_prop` ADD INDEX `id_user_id_contact_index` (`id_user`, `id_contact`);
|
||||||
|
-- END IF;
|
||||||
|
--
|
||||||
|
-- IF current_version < 2 THEN
|
||||||
|
-- ALTER TABLE `rainloop_pab_prop` ADD INDEX `id_user_id_contact_index` (`id_user`, `id_contact`);
|
||||||
|
-- END IF;
|
||||||
|
|
||||||
|
DELETE FROM `rainloop_system` WHERE `name` = 'rainloop-pab-db-version' AND `value_int` <= new_version;
|
||||||
|
INSERT INTO `rainloop_system` (`name`, `value_int`) VALUES ('rainloop-pab-db-version', new_version);
|
||||||
|
END$$
|
||||||
|
|
||||||
|
-- TODO
|
||||||
|
-- CALL rainloop_pab_upgrade_database() $$
|
||||||
|
|
||||||
|
DROP PROCEDURE IF EXISTS rainloop_pab_upgrade_database $$
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
|
|
||||||
|
/*!40014 SET FOREIGN_KEY_CHECKS=1 */;
|
||||||
|
|
@ -1090,6 +1090,11 @@ class Utils
|
||||||
*/
|
*/
|
||||||
public static function Utf8Clear($sUtfString, $sReplaceOn = '')
|
public static function Utf8Clear($sUtfString, $sReplaceOn = '')
|
||||||
{
|
{
|
||||||
|
if ('' === $sUtfString)
|
||||||
|
{
|
||||||
|
return $sUtfString;
|
||||||
|
}
|
||||||
|
|
||||||
$sUtfString = @\iconv('UTF-8', 'UTF-8//IGNORE', $sUtfString);
|
$sUtfString = @\iconv('UTF-8', 'UTF-8//IGNORE', $sUtfString);
|
||||||
|
|
||||||
$sUtfString = \preg_replace(
|
$sUtfString = \preg_replace(
|
||||||
|
|
|
||||||
|
|
@ -77,9 +77,9 @@ class Actions
|
||||||
private $oLoginProvider;
|
private $oLoginProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \RainLoop\Providers\Contacts
|
* @var \RainLoop\Providers\PersonalAddressBook
|
||||||
*/
|
*/
|
||||||
private $oContactsProvider;
|
private $oPersonalAddressBookProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \RainLoop\Providers\Suggestions
|
* @var \RainLoop\Providers\Suggestions
|
||||||
|
|
@ -121,6 +121,7 @@ class Actions
|
||||||
$this->oSettingsProvider = null;
|
$this->oSettingsProvider = null;
|
||||||
$this->oDomainProvider = null;
|
$this->oDomainProvider = null;
|
||||||
$this->oLoginProvider = null;
|
$this->oLoginProvider = null;
|
||||||
|
$this->oPersonalAddressBookProvider = null;
|
||||||
$this->oSuggestionsProvider = null;
|
$this->oSuggestionsProvider = null;
|
||||||
$this->oChangePasswordProvider = null;
|
$this->oChangePasswordProvider = null;
|
||||||
|
|
||||||
|
|
@ -222,9 +223,8 @@ class Actions
|
||||||
// \RainLoop\Providers\Domain\DomainAdminInterface
|
// \RainLoop\Providers\Domain\DomainAdminInterface
|
||||||
$oResult = new \RainLoop\Providers\Domain\DefaultDomain(APP_PRIVATE_DATA.'domains');
|
$oResult = new \RainLoop\Providers\Domain\DefaultDomain(APP_PRIVATE_DATA.'domains');
|
||||||
break;
|
break;
|
||||||
case 'contacts':
|
case 'personal-address-book':
|
||||||
// \RainLoop\Providers\Contacts\ContactsInterface
|
// \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface
|
||||||
$oResult = new \RainLoop\Providers\Contacts\DefaultContacts($this->Logger());
|
|
||||||
break;
|
break;
|
||||||
case 'suggestions':
|
case 'suggestions':
|
||||||
// \RainLoop\Providers\Suggestions\SuggestionsInterface
|
// \RainLoop\Providers\Suggestions\SuggestionsInterface
|
||||||
|
|
@ -529,18 +529,36 @@ class Actions
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \RainLoop\Providers\Contacts
|
* @return \RainLoop\Providers\PersonalAddressBook
|
||||||
*/
|
*/
|
||||||
public function ContactsProvider()
|
public function PersonalAddressBookProvider($oAccount = null)
|
||||||
{
|
{
|
||||||
if (null === $this->oContactsProvider)
|
if (null === $this->oPersonalAddressBookProvider)
|
||||||
{
|
{
|
||||||
$this->oContactsProvider = new \RainLoop\Providers\Contacts(
|
$this->oPersonalAddressBookProvider = new \RainLoop\Providers\PersonalAddressBook(
|
||||||
$this->Config()->Get('labs', 'allow_contacts', true) ?
|
$this->fabrica('personal-address-book', $oAccount));
|
||||||
$this->fabrica('contacts') : null);
|
|
||||||
|
$sPabVersion = $this->oPersonalAddressBookProvider->Version();
|
||||||
|
$sVersion = (string) $this->StorageProvider()->Get(null,
|
||||||
|
\RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY, 'PersonalAddressBookVersion', '');
|
||||||
|
|
||||||
|
if ($sVersion !== $sPabVersion &&
|
||||||
|
$this->oPersonalAddressBookProvider->IsActive())
|
||||||
|
{
|
||||||
|
if ($this->oPersonalAddressBookProvider->SynchronizeStorage())
|
||||||
|
{
|
||||||
|
$this->StorageProvider()->Put(null, \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY,
|
||||||
|
'PersonalAddressBookVersion', $sPabVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->oContactsProvider;
|
if ($oAccount)
|
||||||
|
{
|
||||||
|
$this->oPersonalAddressBookProvider->SetAccount($oAccount);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->oPersonalAddressBookProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -877,9 +895,8 @@ class Actions
|
||||||
'AllowThemes' => (bool) $oConfig->Get('webmail', 'allow_themes', true),
|
'AllowThemes' => (bool) $oConfig->Get('webmail', 'allow_themes', true),
|
||||||
'AllowCustomTheme' => (bool) $oConfig->Get('webmail', 'allow_custom_theme', true),
|
'AllowCustomTheme' => (bool) $oConfig->Get('webmail', 'allow_custom_theme', true),
|
||||||
'SuggestionsLimit' => (int) $oConfig->Get('labs', 'suggestions_limit', 50),
|
'SuggestionsLimit' => (int) $oConfig->Get('labs', 'suggestions_limit', 50),
|
||||||
'AllowChangePassword' => false,
|
'ChangePasswordIsAllowed' => false,
|
||||||
'ContactsIsSupported' => (bool) $this->ContactsProvider()->IsSupported(),
|
'ContactsIsAllowed' => false,
|
||||||
'ContactsIsAllowed' => (bool) $this->ContactsProvider()->IsActive(),
|
|
||||||
'JsHash' => \md5(\RainLoop\Utils::GetConnectionToken()),
|
'JsHash' => \md5(\RainLoop\Utils::GetConnectionToken()),
|
||||||
'UseImapThread' => (bool) $oConfig->Get('labs', 'use_imap_thread', false),
|
'UseImapThread' => (bool) $oConfig->Get('labs', 'use_imap_thread', false),
|
||||||
'UseImapSubscribe' => (bool) $oConfig->Get('labs', 'use_imap_list_subscribe', true),
|
'UseImapSubscribe' => (bool) $oConfig->Get('labs', 'use_imap_list_subscribe', true),
|
||||||
|
|
@ -904,7 +921,8 @@ class Actions
|
||||||
$aResult['IncLogin'] = $oAccount->IncLogin();
|
$aResult['IncLogin'] = $oAccount->IncLogin();
|
||||||
$aResult['OutLogin'] = $oAccount->OutLogin();
|
$aResult['OutLogin'] = $oAccount->OutLogin();
|
||||||
$aResult['AccountHash'] = $oAccount->Hash();
|
$aResult['AccountHash'] = $oAccount->Hash();
|
||||||
$aResult['AllowChangePassword'] = $this->ChangePasswordProvider()->PasswordChangePossibility($oAccount);
|
$aResult['ChangePasswordIsAllowed'] = $this->ChangePasswordProvider()->PasswordChangePossibility($oAccount);
|
||||||
|
$aResult['ContactsIsAllowed'] = $this->PersonalAddressBookProvider($oAccount)->IsActive();
|
||||||
|
|
||||||
$oSettings = $this->SettingsProvider()->Load($oAccount);
|
$oSettings = $this->SettingsProvider()->Load($oAccount);
|
||||||
}
|
}
|
||||||
|
|
@ -3745,10 +3763,10 @@ class Actions
|
||||||
|
|
||||||
$this->Plugins()->RunHook('filter.smtp-credentials', array($oAccount, &$aSmtpCredentials));
|
$this->Plugins()->RunHook('filter.smtp-credentials', array($oAccount, &$aSmtpCredentials));
|
||||||
|
|
||||||
$bHookConnect = $bHookAuth = $bHookFrom = $bHookFrom = $bHookTo = $bHookData = false;
|
$bHookConnect = $bHookAuth = $bHookFrom = $bHookFrom = $bHookTo = $bHookData = $bHookLogoutAndDisconnect = false;
|
||||||
$this->Plugins()->RunHook('filter.smtp-connect', array($oAccount, $aSmtpCredentials,
|
$this->Plugins()->RunHook('filter.smtp-connect', array($oAccount, $aSmtpCredentials,
|
||||||
&$oSmtpClient, $oMessage, &$oRcpt,
|
&$oSmtpClient, $oMessage, &$oRcpt,
|
||||||
&$bHookConnect, &$bHookAuth, &$bHookFrom, &$bHookTo, &$bHookData));
|
&$bHookConnect, &$bHookAuth, &$bHookFrom, &$bHookTo, &$bHookData, &$bHookLogoutAndDisconnect));
|
||||||
|
|
||||||
if (!$bHookConnect)
|
if (!$bHookConnect)
|
||||||
{
|
{
|
||||||
|
|
@ -3794,7 +3812,10 @@ class Actions
|
||||||
$oSmtpClient->DataWithStream($rMessageStream);
|
$oSmtpClient->DataWithStream($rMessageStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
$oSmtpClient->LogoutAndDisconnect();
|
if (!$bHookLogoutAndDisconnect)
|
||||||
|
{
|
||||||
|
$oSmtpClient->LogoutAndDisconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (\MailSo\Net\Exceptions\ConnectionException $oException)
|
catch (\MailSo\Net\Exceptions\ConnectionException $oException)
|
||||||
{
|
{
|
||||||
|
|
@ -3849,22 +3870,6 @@ class Actions
|
||||||
$rMessageStream, $iMessageStreamSize, $sSentFolder, array(
|
$rMessageStream, $iMessageStreamSize, $sSentFolder, array(
|
||||||
\MailSo\Imap\Enumerations\MessageFlag::SEEN
|
\MailSo\Imap\Enumerations\MessageFlag::SEEN
|
||||||
));
|
));
|
||||||
|
|
||||||
// TODO
|
|
||||||
// $rAppendMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
|
|
||||||
//
|
|
||||||
// $iAppendMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter(
|
|
||||||
// $oMessage->ToStream(false), array($rAppendMessageStream), 8192, true, true, true);
|
|
||||||
//
|
|
||||||
// $this->MailClient()->MessageAppendStream(
|
|
||||||
// $rAppendMessageStream, $iAppendMessageStreamSize, $sSentFolder, array(
|
|
||||||
// \MailSo\Imap\Enumerations\MessageFlag::SEEN
|
|
||||||
// ));
|
|
||||||
//
|
|
||||||
// if (\is_resource($rAppendMessageStream))
|
|
||||||
// {
|
|
||||||
// @\fclose($rAppendMessageStream);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
catch (\Exception $oException)
|
catch (\Exception $oException)
|
||||||
{
|
{
|
||||||
|
|
@ -3912,26 +3917,24 @@ class Actions
|
||||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantSendMessage);
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantSendMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if ($oMessage && $this->ContactsProvider()->IsActive())
|
if ($oMessage && $this->PersonalAddressBookProvider($oAccount)->IsActive())
|
||||||
// {
|
{
|
||||||
// $oToCollection = $oMessage->GetTo();
|
$aArrayToFrec = array();
|
||||||
// $oTo = $oToCollection->GetByIndex(0);
|
$oToCollection = $oMessage->GetTo();
|
||||||
// if ($oTo)
|
if ($oToCollection)
|
||||||
// {
|
{
|
||||||
// $oContact = new \RainLoop\Providers\Contacts\Classes\Contact();
|
$aTo =& $oToCollection->GetAsArray();
|
||||||
// /* @var $oTo \MailSo\Mime\Email */
|
foreach ($aTo as /* @var $oEmail \MailSo\Mime\Email */ $oEmail)
|
||||||
// $oContact->Name = $oTo->GetDisplayName();
|
{
|
||||||
//
|
$aArrayToFrec[$oEmail->GetEmail()] = $oEmail->ToString();
|
||||||
// $i = 30;
|
}
|
||||||
// while ($i > 0)
|
}
|
||||||
// {
|
|
||||||
// $i--;
|
if (0 < \count($aArrayToFrec))
|
||||||
// $oContact->Emails = array('u'.$i.'-'.$oTo->GetEmail());
|
{
|
||||||
// $this->ContactsProvider()->CreateContact($oAccount, $oContact);
|
$this->PersonalAddressBookProvider($oAccount)->IncFrec($oAccount, \array_values($aArrayToFrec));
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
return $this->TrueResponse(__FUNCTION__);
|
return $this->TrueResponse(__FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
@ -3961,26 +3964,23 @@ class Actions
|
||||||
public function DoContacts()
|
public function DoContacts()
|
||||||
{
|
{
|
||||||
$oAccount = $this->getAccountFromToken();
|
$oAccount = $this->getAccountFromToken();
|
||||||
$sSearch = \trim($this->GetActionParam('Search', ''));
|
|
||||||
|
|
||||||
$bMore = false;
|
$sSearch = \trim($this->GetActionParam('Search', ''));
|
||||||
$mResult = false;
|
$iOffset = (int) $this->GetActionParam('Offset', 0);
|
||||||
if ($this->ContactsProvider()->IsActive())
|
$iLimit = (int) $this->GetActionParam('Limit', 20);
|
||||||
|
$iOffset = 0 > $iOffset ? 0 : $iOffset;
|
||||||
|
$iLimit = 0 > $iLimit ? 20 : $iLimit;
|
||||||
|
|
||||||
|
if ($this->PersonalAddressBookProvider($oAccount)->IsActive())
|
||||||
{
|
{
|
||||||
$mResult = $this->ContactsProvider()->GetContacts($oAccount, 0, RL_CONTACTS_MAX + 1, $sSearch);
|
$mResult = $this->PersonalAddressBookProvider($oAccount)->GetContacts($oAccount,
|
||||||
if (is_array($mResult))
|
$iOffset, $iLimit, $sSearch, false);
|
||||||
{
|
|
||||||
$bMore = RL_CONTACTS_MAX < \count($mResult);
|
|
||||||
if ($bMore)
|
|
||||||
{
|
|
||||||
$mResult = \array_slice($mResult, 0, RL_CONTACTS_MAX);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->DefaultResponse(__FUNCTION__, array(
|
return $this->DefaultResponse(__FUNCTION__, array(
|
||||||
'Limit' => RL_CONTACTS_MAX,
|
'Offset' => $iOffset,
|
||||||
'More' => $bMore,
|
'Limit' => $iLimit,
|
||||||
|
'Search' => $sSearch,
|
||||||
'List' => $mResult
|
'List' => $mResult
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -3999,9 +3999,9 @@ class Actions
|
||||||
});
|
});
|
||||||
|
|
||||||
$bResult = false;
|
$bResult = false;
|
||||||
if ($this->ContactsProvider()->IsActive())
|
if (0 < \count($aFilteredUids) && $this->PersonalAddressBookProvider($oAccount)->IsActive())
|
||||||
{
|
{
|
||||||
$bResult = $this->ContactsProvider()->DeleteContacts($oAccount, $aFilteredUids);
|
$bResult = $this->PersonalAddressBookProvider($oAccount)->DeleteContacts($oAccount, $aFilteredUids);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->DefaultResponse(__FUNCTION__, $bResult);
|
return $this->DefaultResponse(__FUNCTION__, $bResult);
|
||||||
|
|
@ -4012,77 +4012,45 @@ class Actions
|
||||||
*/
|
*/
|
||||||
public function DoContactSave()
|
public function DoContactSave()
|
||||||
{
|
{
|
||||||
sleep(1);
|
|
||||||
$oAccount = $this->getAccountFromToken();
|
$oAccount = $this->getAccountFromToken();
|
||||||
|
|
||||||
$bResult = false;
|
$bResult = false;
|
||||||
$sResultID = '';
|
|
||||||
|
|
||||||
|
$oPab = $this->PersonalAddressBookProvider($oAccount);
|
||||||
$sRequestUid = \trim($this->GetActionParam('RequestUid', ''));
|
$sRequestUid = \trim($this->GetActionParam('RequestUid', ''));
|
||||||
if ($this->ContactsProvider()->IsActive() && 0 < \strlen($sRequestUid))
|
if ($oPab && $oPab->IsActive() && 0 < \strlen($sRequestUid))
|
||||||
{
|
{
|
||||||
$sUid = \trim($this->GetActionParam('Uid', ''));
|
$sUid = \trim($this->GetActionParam('Uid', ''));
|
||||||
$sName = \trim($this->GetActionParam('Name', ''));
|
|
||||||
$sEmail = \trim($this->GetActionParam('Email', ''));
|
|
||||||
|
|
||||||
$sImageData = \trim($this->GetActionParam('ImageData', ''));
|
$oContact = new \RainLoop\Providers\PersonalAddressBook\Classes\Contact();
|
||||||
|
|
||||||
$oContact = null;
|
|
||||||
if (0 < \strlen($sUid))
|
if (0 < \strlen($sUid))
|
||||||
{
|
{
|
||||||
if (\is_numeric($sUid))
|
$oContact->IdContact = $sUid;
|
||||||
{
|
|
||||||
$oContact = $this->ContactsProvider()->GetContactById($oAccount, (int) $sUid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$oContact = new \RainLoop\Providers\Contacts\Classes\Contact();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($oContact)
|
$aProperties = $this->GetActionParam('Properties', array());
|
||||||
|
if (\is_array($aProperties))
|
||||||
{
|
{
|
||||||
$oContact->Name = $sName;
|
foreach ($aProperties as $aItem)
|
||||||
$oContact->Emails = array($sEmail);
|
|
||||||
|
|
||||||
if (0 < \strlen($sImageData) && 'data:image/' === substr($sImageData, 0, 11))
|
|
||||||
{
|
{
|
||||||
$oContact->ImageHash = \md5($sImageData);
|
if ($aItem && isset($aItem[0], $aItem[1]) &&
|
||||||
}
|
\is_numeric($aItem[0]))
|
||||||
|
|
||||||
if (0 < $oContact->IdContact)
|
|
||||||
{
|
|
||||||
$bResult = $this->ContactsProvider()->UpdateContact($oAccount, $oContact);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$bResult = $this->ContactsProvider()->CreateContact($oAccount, $oContact);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($bResult && 0 < $oContact->IdContact)
|
|
||||||
{
|
|
||||||
$sResultID = $oContact->IdContact;
|
|
||||||
$aMatches = array();
|
|
||||||
if ($bResult && $oContact && 0 < $oContact->IdContact && 0 < \strlen($oContact->ImageHash) &&
|
|
||||||
0 < \strlen($sImageData) &&
|
|
||||||
\preg_match('/^data:(image\/(jpeg|jpg|png|bmp));base64,(.+)$/i', $sImageData, $aMatches) &&
|
|
||||||
!empty($aMatches[1]) && !empty($aMatches[3]))
|
|
||||||
{
|
{
|
||||||
$this->StorageProvider()->Put($oAccount,
|
$oProp = new \RainLoop\Providers\PersonalAddressBook\Classes\Property();
|
||||||
\RainLoop\Providers\Storage\Enumerations\StorageType::USER,
|
$oProp->Type = (int) $aItem[0];
|
||||||
'contacts/'.$oContact->ImageHash, $aMatches[1].'|||'.$aMatches[3]);
|
$oProp->Value = $aItem[1];
|
||||||
|
|
||||||
|
$oContact->Properties[] = $oProp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
$bResult = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$bResult = $oPab->ContactSave($oAccount, $oContact);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->DefaultResponse(__FUNCTION__, array(
|
return $this->DefaultResponse(__FUNCTION__, array(
|
||||||
'RequestUid' => $sRequestUid,
|
'RequestUid' => $sRequestUid,
|
||||||
'ResultID' => $sResultID,
|
'ResultID' => $bResult ? $oContact->IdContact : '',
|
||||||
'Result' => $bResult
|
'Result' => $bResult
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -4097,114 +4065,13 @@ class Actions
|
||||||
$sQuery = \trim($this->GetActionParam('Query', ''));
|
$sQuery = \trim($this->GetActionParam('Query', ''));
|
||||||
|
|
||||||
$aResult = array();
|
$aResult = array();
|
||||||
if (0 < \strlen($sQuery) && $this->ContactsProvider()->IsActive())
|
$oPab = $this->PersonalAddressBookProvider($oAccount);
|
||||||
|
if (0 < \strlen($sQuery) && $oPab->IsActive())
|
||||||
{
|
{
|
||||||
$mResult = $this->ContactsProvider()->GetContacts($oAccount, 0, RL_CONTACTS_PER_PAGE, $sQuery);
|
$aResult = $oPab->GetSuggestions($oAccount, $sQuery);
|
||||||
if (\is_array($mResult) && 0 < \count($mResult))
|
|
||||||
{
|
|
||||||
$mResult = \array_slice($mResult, 0, RL_CONTACTS_PER_PAGE);
|
|
||||||
|
|
||||||
foreach ($mResult as $oItem)
|
|
||||||
{
|
|
||||||
/* @var $oItem \RainLoop\Providers\Contacts\Classes\Contact */
|
|
||||||
$aEmails = $oItem->Emails;
|
|
||||||
if (0 < \count($aEmails))
|
|
||||||
{
|
|
||||||
foreach ($aEmails as $sEmail)
|
|
||||||
{
|
|
||||||
if (0 < \strlen($sEmail))
|
|
||||||
{
|
|
||||||
$aResult[] = array($sEmail, $oItem->Name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->DefaultResponse(__FUNCTION__, array(
|
return $this->DefaultResponse(__FUNCTION__, $aResult);
|
||||||
'More' => false,
|
|
||||||
'List' => $aResult
|
|
||||||
));
|
|
||||||
|
|
||||||
// $oAccount = $this->getAccountFromToken();
|
|
||||||
//
|
|
||||||
// $aResult = array();
|
|
||||||
// $sQuery = \trim($this->GetActionParam('Query', ''));
|
|
||||||
// if (0 < \strlen($sQuery) && $oAccount)
|
|
||||||
// {
|
|
||||||
// $aResult = $this->SuggestionsProvider()->Process($oAccount, $sQuery);
|
|
||||||
//
|
|
||||||
// if (0 === count($aResult) && false !== \strpos(strtolower($oAccount->Email()), \strtolower($sQuery)))
|
|
||||||
// {
|
|
||||||
// $aResult[] = array($oAccount->Email(), $oAccount->Name());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return $this->DefaultResponse(__FUNCTION__, $aResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function DoSuggestionsDep()
|
|
||||||
{
|
|
||||||
$oAccount = $this->getAccountFromToken();
|
|
||||||
|
|
||||||
$sQuery = \trim($this->GetActionParam('Query', ''));
|
|
||||||
$iPage = (int) $this->GetActionParam('Page', 0);
|
|
||||||
|
|
||||||
$bMore = false;
|
|
||||||
$aResult = array();
|
|
||||||
if (0 < \strlen($sQuery) && 0 < $iPage && $this->ContactsProvider()->IsActive())
|
|
||||||
{
|
|
||||||
$mResult = $this->ContactsProvider()->GetContacts($oAccount, ($iPage - 1) * RL_CONTACTS_PER_PAGE, RL_CONTACTS_PER_PAGE + 1, $sQuery);
|
|
||||||
if (\is_array($mResult) && 0 < \count($mResult))
|
|
||||||
{
|
|
||||||
$bMore = RL_CONTACTS_PER_PAGE < \count($mResult);
|
|
||||||
if ($bMore)
|
|
||||||
{
|
|
||||||
$mResult = \array_slice($mResult, 0, RL_CONTACTS_PER_PAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($mResult as $oItem)
|
|
||||||
{
|
|
||||||
/* @var $oItem \RainLoop\Providers\Contacts\Classes\Contact */
|
|
||||||
$aEmails = $oItem->Emails;
|
|
||||||
if (0 < \count($aEmails))
|
|
||||||
{
|
|
||||||
foreach ($aEmails as $sEmail)
|
|
||||||
{
|
|
||||||
if (0 < \strlen($sEmail))
|
|
||||||
{
|
|
||||||
$aResult[] = array($sEmail, $oItem->Name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->DefaultResponse(__FUNCTION__, array(
|
|
||||||
'More' => $bMore,
|
|
||||||
'List' => $aResult
|
|
||||||
));
|
|
||||||
|
|
||||||
// $oAccount = $this->getAccountFromToken();
|
|
||||||
//
|
|
||||||
// $aResult = array();
|
|
||||||
// $sQuery = \trim($this->GetActionParam('Query', ''));
|
|
||||||
// if (0 < \strlen($sQuery) && $oAccount)
|
|
||||||
// {
|
|
||||||
// $aResult = $this->SuggestionsProvider()->Process($oAccount, $sQuery);
|
|
||||||
//
|
|
||||||
// if (0 === count($aResult) && false !== \strpos(strtolower($oAccount->Email()), \strtolower($sQuery)))
|
|
||||||
// {
|
|
||||||
// $aResult[] = array($oAccount->Email(), $oAccount->Name());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return $this->DefaultResponse(__FUNCTION__, $aResult);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -4212,19 +4079,8 @@ class Actions
|
||||||
*/
|
*/
|
||||||
public function DoEmailsPicsHashes()
|
public function DoEmailsPicsHashes()
|
||||||
{
|
{
|
||||||
$oAccount = $this->getAccountFromToken();
|
// $oAccount = $this->getAccountFromToken();
|
||||||
|
return $this->DefaultResponse(__FUNCTION__, array());
|
||||||
$aResult = array();
|
|
||||||
if ($this->ContactsProvider()->IsActive())
|
|
||||||
{
|
|
||||||
$mResult = $this->ContactsProvider()->GetContactsImageHashes($oAccount);
|
|
||||||
if (\is_array($mResult) && 0 < \count($mResult))
|
|
||||||
{
|
|
||||||
$aResult = $mResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->DefaultResponse(__FUNCTION__, $aResult);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -5686,7 +5542,7 @@ class Actions
|
||||||
if ($oAttachment)
|
if ($oAttachment)
|
||||||
{
|
{
|
||||||
$sContentLocation = $oAttachment->ContentLocation();
|
$sContentLocation = $oAttachment->ContentLocation();
|
||||||
if ($sContentLocation && 0 < strlen($sContentLocation))
|
if ($sContentLocation && 0 < \strlen($sContentLocation))
|
||||||
{
|
{
|
||||||
$aContentLocationUrls[] = $oAttachment->ContentLocation();
|
$aContentLocationUrls[] = $oAttachment->ContentLocation();
|
||||||
}
|
}
|
||||||
|
|
@ -5746,6 +5602,25 @@ class Actions
|
||||||
'Emails' => $mResponse->Emails
|
'Emails' => $mResponse->Emails
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
else if ('RainLoop\Providers\PersonalAddressBook\Classes\Contact' === $sClassName)
|
||||||
|
{
|
||||||
|
$mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array(
|
||||||
|
/* @var $mResponse \RainLoop\Providers\PersonalAddressBook\Classes\Contact */
|
||||||
|
'IdContact' => $mResponse->IdContact,
|
||||||
|
'Display' => \MailSo\Base\Utils::Utf8Clear($mResponse->Display),
|
||||||
|
'Properties' => $this->responseObject($mResponse->Properties, $sParent, $aParameters)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
else if ('RainLoop\Providers\PersonalAddressBook\Classes\Property' === $sClassName)
|
||||||
|
{
|
||||||
|
$mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array(
|
||||||
|
/* @var $mResponse \RainLoop\Providers\PersonalAddressBook\Classes\Property */
|
||||||
|
'Type' => $mResponse->Type,
|
||||||
|
'TypeCustom' => $mResponse->TypeCustom,
|
||||||
|
'Value' => \MailSo\Base\Utils::Utf8Clear($mResponse->Value),
|
||||||
|
'ValueClear' => \MailSo\Base\Utils::Utf8Clear($mResponse->ValueClear)
|
||||||
|
));
|
||||||
|
}
|
||||||
else if ('MailSo\Mail\Attachment' === $sClassName)
|
else if ('MailSo\Mail\Attachment' === $sClassName)
|
||||||
{
|
{
|
||||||
$oAccount = $this->getAccountFromToken(false);
|
$oAccount = $this->getAccountFromToken(false);
|
||||||
|
|
|
||||||
430
rainloop/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php
Normal file
430
rainloop/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php
Normal file
|
|
@ -0,0 +1,430 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RainLoop\Common;
|
||||||
|
|
||||||
|
abstract class PdoAbstract
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \PDO
|
||||||
|
*/
|
||||||
|
protected $oPDO = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \MailSo\Log\Logger
|
||||||
|
*/
|
||||||
|
protected $oLogger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $sDbType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function IsSupported()
|
||||||
|
{
|
||||||
|
return !!\class_exists('PDO');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \MailSo\Log\Logger $oLogger
|
||||||
|
*/
|
||||||
|
public function SetLogger($oLogger)
|
||||||
|
{
|
||||||
|
$this->oLogger = $oLogger instanceof \MailSo\Log\Logger ? $oLogger : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getPdoAccessData()
|
||||||
|
{
|
||||||
|
return array('', '', '', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \PDO
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
protected function getPDO()
|
||||||
|
{
|
||||||
|
if ($this->oPDO)
|
||||||
|
{
|
||||||
|
return $this->oPDO;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!\class_exists('PDO'))
|
||||||
|
{
|
||||||
|
throw new \Exception('Class PDO does not exist');
|
||||||
|
}
|
||||||
|
|
||||||
|
$sType = $sDsn = $sDbLogin = $sDbPassword = '';
|
||||||
|
list($sType, $sDsn, $sDbLogin, $sDbPassword) = $this->getPdoAccessData();
|
||||||
|
$this->sDbType = $sType;
|
||||||
|
|
||||||
|
$oPdo = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$oPdo = new \PDO($sDsn, $sDbLogin, $sDbPassword);
|
||||||
|
if ($oPdo)
|
||||||
|
{
|
||||||
|
$oPdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||||
|
if ('mysql' === $oPdo->getAttribute(\PDO::ATTR_DRIVER_NAME))
|
||||||
|
{
|
||||||
|
$oPdo->exec('SET NAMES utf8 COLLATE utf8_general_ci');
|
||||||
|
// $oPdo->exec('SET NAMES utf8');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (\Exception $oException)
|
||||||
|
{
|
||||||
|
throw $oException;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($oPdo)
|
||||||
|
{
|
||||||
|
$this->oPDO = $oPdo;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new \Exception('PDO = false');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $oPdo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sName = null
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function lastInsertId($sName = null)
|
||||||
|
{
|
||||||
|
return $this->getPDO()->lastInsertId($sName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return nool
|
||||||
|
*/
|
||||||
|
protected function beginTransaction()
|
||||||
|
{
|
||||||
|
return $this->getPDO()->beginTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return nool
|
||||||
|
*/
|
||||||
|
protected function commit()
|
||||||
|
{
|
||||||
|
return $this->getPDO()->commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return nool
|
||||||
|
*/
|
||||||
|
protected function rollBack()
|
||||||
|
{
|
||||||
|
return $this->getPDO()->rollBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
* @param string $sSql
|
||||||
|
* @param array $aParams
|
||||||
|
* @param bool $bMultParams = false
|
||||||
|
*
|
||||||
|
* @return \PDOStatement|null
|
||||||
|
*/
|
||||||
|
protected function prepareAndExecute($sSql, $aParams = array(), $bMultParams = false)
|
||||||
|
{
|
||||||
|
$mResult = null;
|
||||||
|
|
||||||
|
$this->writeLog($sSql);
|
||||||
|
$oStmt = $this->getPDO()->prepare($sSql);
|
||||||
|
if ($oStmt)
|
||||||
|
{
|
||||||
|
$aRootParams = $bMultParams ? $aParams : array($aParams);
|
||||||
|
foreach ($aRootParams as $aSubParams)
|
||||||
|
{
|
||||||
|
foreach ($aSubParams as $sName => $aValue)
|
||||||
|
{
|
||||||
|
$oStmt->bindValue($sName, $aValue[0], $aValue[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$mResult = $oStmt->execute() && !$bMultParams ? $oStmt : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $mResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sSql
|
||||||
|
*/
|
||||||
|
protected function writeLog($sSql)
|
||||||
|
{
|
||||||
|
if ($this->oLogger)
|
||||||
|
{
|
||||||
|
$this->oLogger->Write($sSql, \MailSo\Log\Enumerations\Type::INFO, 'SQL');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sEmail
|
||||||
|
* @param bool $bSkipInsert = false
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
protected function getUserId($sEmail, $bSkipInsert = false)
|
||||||
|
{
|
||||||
|
$sEmail = \strtolower(\trim($sEmail));
|
||||||
|
if (empty($sEmail))
|
||||||
|
{
|
||||||
|
throw new \InvalidArgumentException('Empty Email argument');
|
||||||
|
}
|
||||||
|
|
||||||
|
$oStmt = $this->prepareAndExecute('SELECT id_user FROM rainloop_users WHERE rl_email = :rl_email',
|
||||||
|
array(':rl_email' => array($sEmail, \PDO::PARAM_STR)));
|
||||||
|
|
||||||
|
$mRow = $oStmt->fetch(\PDO::FETCH_ASSOC);
|
||||||
|
if ($mRow && isset($mRow['id_user']) && \is_numeric($mRow['id_user']))
|
||||||
|
{
|
||||||
|
return (int) $mRow['id_user'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$bSkipInsert)
|
||||||
|
{
|
||||||
|
$oStmt->closeCursor();
|
||||||
|
|
||||||
|
$oStmt = $this->prepareAndExecute('INSERT INTO rainloop_users (rl_email) VALUES (:rl_email)',
|
||||||
|
array(':rl_email' => array($sEmail, \PDO::PARAM_STR)));
|
||||||
|
|
||||||
|
return $this->getUserId($sEmail, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \Exception('id_user = 0');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sValue
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function quoteValue($sValue)
|
||||||
|
{
|
||||||
|
$oPdo = $this->getPDO();
|
||||||
|
return $oPdo ? $oPdo->quote((string) $sValue, \PDO::PARAM_STR) : '\'\'';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sType
|
||||||
|
* @param bool $bReturnIntValue = true
|
||||||
|
*
|
||||||
|
* @return int|string|bool
|
||||||
|
*/
|
||||||
|
protected function getSystemValue($sName, $bReturnIntValue = true)
|
||||||
|
{
|
||||||
|
$oPdo = $this->getPDO();
|
||||||
|
if ($oPdo)
|
||||||
|
{
|
||||||
|
$sQuery = 'SELECT * FROM rainloop_system WHERE sys_name = ?';
|
||||||
|
$this->writeLog($sQuery);
|
||||||
|
|
||||||
|
$oStmt = $oPdo->prepare($sQuery);
|
||||||
|
if ($oStmt->execute(array($sName)))
|
||||||
|
{
|
||||||
|
$mRow = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
|
if ($mRow && isset($mRow[0]['sys_name'], $mRow[0]['value_int'], $mRow[0]['value_str']))
|
||||||
|
{
|
||||||
|
return $bReturnIntValue ? (int) $mRow[0]['value_int'] : (string) $mRow[0]['value_str'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sType
|
||||||
|
* @param bool $bReturnIntValue = true
|
||||||
|
*
|
||||||
|
* @return int|string|bool
|
||||||
|
*/
|
||||||
|
protected function getVersion($sName)
|
||||||
|
{
|
||||||
|
return $this->getSystemValue($sName.'_version', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sType
|
||||||
|
* @param int $iVersion
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function setVersion($sName, $iVersion)
|
||||||
|
{
|
||||||
|
$bResult = false;
|
||||||
|
$oPdo = $this->getPDO();
|
||||||
|
if ($oPdo)
|
||||||
|
{
|
||||||
|
$oPdo->beginTransaction();
|
||||||
|
|
||||||
|
$sQuery = 'DELETE FROM rainloop_system WHERE sys_name = ? AND value_int <= ?;';
|
||||||
|
$this->writeLog($sQuery);
|
||||||
|
|
||||||
|
$oStmt = $oPdo->prepare($sQuery);
|
||||||
|
$bResult = !!$oStmt->execute(array($sName.'_version', $iVersion));
|
||||||
|
if ($bResult)
|
||||||
|
{
|
||||||
|
$sQuery = 'INSERT INTO rainloop_system (sys_name, value_int) VALUES (?, ?);';
|
||||||
|
$this->writeLog($sQuery);
|
||||||
|
|
||||||
|
$oStmt = $oPdo->prepare($sQuery);
|
||||||
|
if ($oStmt)
|
||||||
|
{
|
||||||
|
$bResult = !!$oStmt->execute(array($sName.'_version', $iVersion));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($bResult)
|
||||||
|
{
|
||||||
|
$oPdo->commit();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$oPdo->rollBack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
protected function initSystemTables()
|
||||||
|
{
|
||||||
|
$bResult = true;
|
||||||
|
|
||||||
|
$oPdo = $this->getPDO();
|
||||||
|
if ($oPdo)
|
||||||
|
{
|
||||||
|
$aQ = array();
|
||||||
|
if ('mysql' === $this->sDbType)
|
||||||
|
{
|
||||||
|
$aQ[] = 'CREATE TABLE IF NOT EXISTS `rainloop_system` (
|
||||||
|
`sys_name` varchar(50) NOT NULL,
|
||||||
|
`value_int` int(11) UNSIGNED NOT NULL DEFAULT \'0\',
|
||||||
|
`value_str` varchar(255) NOT NULL DEFAULT \'\'
|
||||||
|
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;';
|
||||||
|
|
||||||
|
$aQ[] = 'CREATE TABLE IF NOT EXISTS `rainloop_users` (
|
||||||
|
`id_user` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`rl_email` varchar(255) NOT NULL,
|
||||||
|
UNIQUE `email_unique` (`rl_email`),
|
||||||
|
PRIMARY KEY(`id_user`)
|
||||||
|
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET ascii COLLATE ascii_general_ci */ ;';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 < \count($aQ))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$oPdo->beginTransaction();
|
||||||
|
|
||||||
|
foreach ($aQ as $sQuery)
|
||||||
|
{
|
||||||
|
if ($bResult)
|
||||||
|
{
|
||||||
|
$this->writeLog($sQuery);
|
||||||
|
$bResult = false !== $oPdo->exec($sQuery);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($bResult)
|
||||||
|
{
|
||||||
|
$oPdo->rollBack();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$oPdo->commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (\Exception $oException)
|
||||||
|
{
|
||||||
|
$oPdo->rollBack();
|
||||||
|
|
||||||
|
$this->oLogger->WriteException($oException);
|
||||||
|
throw $oException;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sName
|
||||||
|
* @param array $aData = array()
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function dataBaseUpgrade($sName, $aData = array())
|
||||||
|
{
|
||||||
|
$this->initSystemTables();
|
||||||
|
|
||||||
|
$iFromVersion = $this->getVersion($sName);
|
||||||
|
|
||||||
|
$bResult = false;
|
||||||
|
$oPdo = $this->getPDO();
|
||||||
|
if ($oPdo)
|
||||||
|
{
|
||||||
|
$bResult = true;
|
||||||
|
foreach ($aData as $iVersion => $aQuery)
|
||||||
|
{
|
||||||
|
if ($iFromVersion < $iVersion)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$oPdo->beginTransaction();
|
||||||
|
|
||||||
|
foreach ($aQuery as $sQuery)
|
||||||
|
{
|
||||||
|
$this->writeLog($sQuery);
|
||||||
|
if (false === $oPdo->exec($sQuery))
|
||||||
|
{
|
||||||
|
$bResult = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($bResult)
|
||||||
|
{
|
||||||
|
$oPdo->commit();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$oPdo->rollBack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (\Exception $oException)
|
||||||
|
{
|
||||||
|
$oPdo->rollBack();
|
||||||
|
throw $oException;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$bResult)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setVersion($sName, $iVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -212,7 +212,6 @@ Enables caching in the system'),
|
||||||
'in_iframe' => array(false),
|
'in_iframe' => array(false),
|
||||||
'custom_login_link' => array(''),
|
'custom_login_link' => array(''),
|
||||||
'custom_logout_link' => array(''),
|
'custom_logout_link' => array(''),
|
||||||
'allow_contacts' => array(true),
|
|
||||||
'allow_external_login' => array(false),
|
'allow_external_login' => array(false),
|
||||||
'allow_admin_panel' => array(true),
|
'allow_admin_panel' => array(true),
|
||||||
'fast_cache_memcache_host' => array('127.0.0.1'),
|
'fast_cache_memcache_host' => array('127.0.0.1'),
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,11 @@ namespace RainLoop\Providers;
|
||||||
|
|
||||||
abstract class AbstractProvider
|
abstract class AbstractProvider
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var \RainLoop\Account
|
||||||
|
*/
|
||||||
|
protected $oAccount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
|
@ -11,4 +16,12 @@ abstract class AbstractProvider
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
*/
|
||||||
|
public function SetAccount($oAccount)
|
||||||
|
{
|
||||||
|
$this->oAccount = $oAccount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,115 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RainLoop\Providers;
|
||||||
|
|
||||||
|
class PersonalAddressBook extends \RainLoop\Providers\AbstractProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface
|
||||||
|
*/
|
||||||
|
private $oDriver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface $oDriver
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct($oDriver)
|
||||||
|
{
|
||||||
|
$this->oDriver = null;
|
||||||
|
if ($oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface)
|
||||||
|
{
|
||||||
|
$this->oDriver = $oDriver;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function Version()
|
||||||
|
{
|
||||||
|
return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface ?
|
||||||
|
$this->oDriver->Version() : 'null';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function IsActive()
|
||||||
|
{
|
||||||
|
return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface &&
|
||||||
|
$this->oDriver->IsSupported();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
* @param \RainLoop\Providers\PersonalAddressBook\Classes\Contact $oContact
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function ContactSave($oAccount, &$oContact)
|
||||||
|
{
|
||||||
|
return $this->IsActive() ? $this->oDriver->ContactSave($oAccount, $oContact) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
* @param array $aContactIds
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function DeleteContacts($oAccount, $aContactIds)
|
||||||
|
{
|
||||||
|
return $this->IsActive() ? $this->oDriver->DeleteContacts($oAccount, $aContactIds) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
* @param int $iOffset = 0
|
||||||
|
* @param type $iLimit = 20
|
||||||
|
* @param string $sSearch = ''
|
||||||
|
* @param bool $bAutoOnly = false
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function GetContacts($oAccount,
|
||||||
|
$iOffset = 0, $iLimit = 20, $sSearch = '', $bAutoOnly = false)
|
||||||
|
{
|
||||||
|
return $this->IsActive() ? $this->oDriver->GetContacts($oAccount,
|
||||||
|
$iOffset, $iLimit, $sSearch, $bAutoOnly) : array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
* @param string $sSearch
|
||||||
|
* @param int $iLimit = 20
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function GetSuggestions($oAccount, $sSearch, $iLimit = 20)
|
||||||
|
{
|
||||||
|
return $this->IsActive() ? $this->oDriver->GetSuggestions($oAccount, $sSearch, $iLimit) : array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
* @param array $aEmails
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function IncFrec($oAccount, $aEmails)
|
||||||
|
{
|
||||||
|
return $this->IsActive() ? $this->oDriver->IncFrec($oAccount, $aEmails) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function SynchronizeStorage()
|
||||||
|
{
|
||||||
|
return $this->IsActive() && \method_exists($this->oDriver, 'SynchronizeStorage') &&
|
||||||
|
$this->oDriver->SynchronizeStorage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,111 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RainLoop\Providers\PersonalAddressBook\Classes;
|
||||||
|
|
||||||
|
class Contact
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $IdContact;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $Display;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $DisplayName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $DisplayEmail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $Auto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $Changed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $Tags;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $Properties;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Clear()
|
||||||
|
{
|
||||||
|
$this->IdContact = '';
|
||||||
|
$this->IdUser = 0;
|
||||||
|
$this->Display = '';
|
||||||
|
$this->DisplayName = '';
|
||||||
|
$this->DisplayEmail = '';
|
||||||
|
$this->Auto = false;
|
||||||
|
$this->Changed = \time();
|
||||||
|
$this->Tags = array();
|
||||||
|
$this->Properties = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function UpdateDependentValues()
|
||||||
|
{
|
||||||
|
$sDisplayName = '';
|
||||||
|
$sDisplayEmail = '';
|
||||||
|
|
||||||
|
foreach ($this->Properties as /* @var $oProperty \RainLoop\Providers\PersonalAddressBook\Classes\Property */ &$oProperty)
|
||||||
|
{
|
||||||
|
if ($oProperty)
|
||||||
|
{
|
||||||
|
$oProperty->UpdateDependentValues();
|
||||||
|
|
||||||
|
if ('' === $sDisplayName && \RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType::FULLNAME === $oProperty->Type &&
|
||||||
|
0 < \strlen($oProperty->Value))
|
||||||
|
{
|
||||||
|
$sDisplayName = $oProperty->Value;
|
||||||
|
}
|
||||||
|
else if ('' === $sDisplayEmail && $oProperty->IsEmail() &&
|
||||||
|
0 < \strlen($oProperty->Value))
|
||||||
|
{
|
||||||
|
$sDisplayEmail = $oProperty->Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->DisplayName = $sDisplayName;
|
||||||
|
$this->DisplayEmail = $sDisplayEmail;
|
||||||
|
|
||||||
|
$this->Display = 0 < \strlen($sDisplayName) ? $sDisplayName : (!empty($sDisplayEmail) ? $sDisplayEmail : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function GetEmails()
|
||||||
|
{
|
||||||
|
$aResult = array();
|
||||||
|
foreach ($this->Properties as /* @var $oProperty \RainLoop\Providers\PersonalAddressBook\Classes\Property */ &$oProperty)
|
||||||
|
{
|
||||||
|
if ($oProperty && $oProperty->IsEmail())
|
||||||
|
{
|
||||||
|
$aResult[] = $oProperty->Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return \array_unique($aResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,97 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RainLoop\Providers\PersonalAddressBook\Classes;
|
||||||
|
|
||||||
|
use RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType;
|
||||||
|
|
||||||
|
class Property
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $Type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $TypeCustom;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $Value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $ValueClear;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $Frec;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Clear()
|
||||||
|
{
|
||||||
|
$this->Type = PropertyType::UNKNOWN;
|
||||||
|
$this->TypeCustom = '';
|
||||||
|
|
||||||
|
$this->Value = '';
|
||||||
|
$this->ValueClear = '';
|
||||||
|
|
||||||
|
$this->Frec = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function IsEmail()
|
||||||
|
{
|
||||||
|
return \in_array($this->Type, array(
|
||||||
|
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function IsPhone()
|
||||||
|
{
|
||||||
|
return \in_array($this->Type, array(
|
||||||
|
PropertyType::PHONE_PERSONAL, PropertyType::PHONE_BUSSINES, PropertyType::PHONE_OTHER,
|
||||||
|
PropertyType::MOBILE_PERSONAL, PropertyType::MOBILE_BUSSINES, PropertyType::MOBILE_OTHER,
|
||||||
|
PropertyType::FAX_BUSSINES, PropertyType::FAX_OTHER
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function UpdateDependentValues()
|
||||||
|
{
|
||||||
|
// trimer
|
||||||
|
$this->Value = \trim($this->Value);
|
||||||
|
$this->ValueClear = \trim($this->ValueClear);
|
||||||
|
$this->TypeCustom = \trim($this->TypeCustom);
|
||||||
|
|
||||||
|
if (0 < \strlen($this->Value))
|
||||||
|
{
|
||||||
|
// lower
|
||||||
|
if ($this->IsEmail())
|
||||||
|
{
|
||||||
|
$this->Value = \strtolower($this->Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// phones clear value for searching
|
||||||
|
if ($this->IsPhone())
|
||||||
|
{
|
||||||
|
$sPhone = $this->Value;
|
||||||
|
$sPhone = \preg_replace('/^[+]+/', '', $sPhone);
|
||||||
|
$sPhone = \preg_replace('/[^\d]/', '', $sPhone);
|
||||||
|
$this->ValueClear = $sPhone;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RainLoop\Providers\PersonalAddressBook\Enumerations;
|
||||||
|
|
||||||
|
class PropertyType
|
||||||
|
{
|
||||||
|
const UNKNOWN = 0;
|
||||||
|
|
||||||
|
const FULLNAME = 10;
|
||||||
|
|
||||||
|
const FIRST_NAME = 15;
|
||||||
|
const SUR_NAME = 16;
|
||||||
|
const MIDDLE_NAME = 17;
|
||||||
|
const NICK = 18;
|
||||||
|
|
||||||
|
const EMAIl_PERSONAL = 30;
|
||||||
|
const EMAIl_BUSSINES = 31;
|
||||||
|
const EMAIl_OTHER = 32;
|
||||||
|
|
||||||
|
const PHONE_PERSONAL = 50;
|
||||||
|
const PHONE_BUSSINES = 51;
|
||||||
|
const PHONE_OTHER = 52;
|
||||||
|
|
||||||
|
const MOBILE_PERSONAL = 60;
|
||||||
|
const MOBILE_BUSSINES = 61;
|
||||||
|
const MOBILE_OTHER = 62;
|
||||||
|
|
||||||
|
const FAX_PERSONAL = 70;
|
||||||
|
const FAX_BUSSINES = 71;
|
||||||
|
const FAX_OTHER = 72;
|
||||||
|
|
||||||
|
const FACEBOOK = 90;
|
||||||
|
const SKYPE = 91;
|
||||||
|
const GITHUB = 92;
|
||||||
|
|
||||||
|
const DESCRIPTION = 110;
|
||||||
|
|
||||||
|
const CUSTOM = 250;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RainLoop\Providers\PersonalAddressBook;
|
||||||
|
|
||||||
|
interface PersonalAddressBookInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function Version();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function IsSupported();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
* @param \RainLoop\Providers\PersonalAddressBook\Classes\Contact $oContact
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function ContactSave($oAccount, &$oContact);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
* @param array $aContactIds
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function DeleteContacts($oAccount, $aContactIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
* @param int $iOffset = 0
|
||||||
|
* @param type $iLimit = 20
|
||||||
|
* @param string $sSearch = ''
|
||||||
|
* @param bool $bAutoOnly = false
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function GetContacts($oAccount,
|
||||||
|
$iOffset = 0, $iLimit = 20, $sSearch = '', $bAutoOnly = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
* @param string $sSearch
|
||||||
|
* @param int $iLimit = 20
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function GetSuggestions($oAccount, $sSearch, $iLimit = 20);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
* @param array $aEmails
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function IncFrec($oAccount, $aEmails);
|
||||||
|
}
|
||||||
|
|
@ -9,15 +9,6 @@
|
||||||
password to something else now.
|
password to something else now.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row" data-bind="visible: !contactsSupported">
|
|
||||||
<div class="alert span8">
|
|
||||||
<h4>Notice!</h4>
|
|
||||||
<br />
|
|
||||||
<strong>Contacts</strong> functions are not supported.
|
|
||||||
<br />
|
|
||||||
You need to install or enable <strong>PDO (sqlite)</strong> exstenstion on your server.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-horizontal">
|
<div class="form-horizontal">
|
||||||
<div class="legend">
|
<div class="legend">
|
||||||
General
|
General
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@
|
||||||
<i class="checkboxItem" data-bind="css: checked() || selected() ? 'checkboxMessage icon-checkbox-checked' : 'checkboxMessage icon-checkbox-unchecked'"></i>
|
<i class="checkboxItem" data-bind="css: checked() || selected() ? 'checkboxMessage icon-checkbox-checked' : 'checkboxMessage icon-checkbox-unchecked'"></i>
|
||||||
</div>
|
</div>
|
||||||
<div class="nameParent actionHandle">
|
<div class="nameParent actionHandle">
|
||||||
<span class="listName" data-bind="text: listName"></span>
|
<span class="listName" data-bind="text: display"></span>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -63,28 +63,45 @@
|
||||||
<div data-bind="visible: !emptySelection()">
|
<div data-bind="visible: !emptySelection()">
|
||||||
<div class="form-horizontal top-part">
|
<div class="form-horizontal top-part">
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<div class="control-label" data-bind="initDom: imageUploader">
|
<label class="control-label">
|
||||||
<div class="image-wrapper" style="width: 100px; height: 100px;">
|
<span class="i18n">Display name</span>
|
||||||
<img data-bind="initDom: imageDom" style="width: 100px; height: 100px;" />
|
</label>
|
||||||
</div>
|
<div class="controls" data-bind="foreach: viewPropertiesNames">
|
||||||
</div>
|
<div class="property-line">
|
||||||
<div class="controls">
|
<input type="text" class="contactValueInput" data-bind="value: value, valueUpdate: 'keyup'" />
|
||||||
<div class="top-row">
|
|
||||||
<span class="contactEmptyValueClick" data-bind="visible: !viewName.focused() && '' === viewName(), click: function() { viewName.focused(true); }">display name</span>
|
|
||||||
<span class="contactValueClick" data-bind="visible: !viewName.focused() && '' !== viewName(), click: function() { viewName.focused(true); }, text: viewName"></span>
|
|
||||||
<input class="contactValueInput span5" type="text" placeholder="display name" data-bind="value: viewName, visible: viewName.focused, hasfocus: viewName.focused, onEnter: function () { viewName.focused(false); }">
|
|
||||||
</div>
|
|
||||||
<div class="top-row" data-bind="css: { hasError: viewEmail.hasError() }">
|
|
||||||
<span class="contactEmptyValueClick" data-bind="visible: !viewEmail.focused() && '' === viewEmail(), click: function() { viewEmail.focused(true); }">email</span>
|
|
||||||
<span class="contactValueClick" data-bind="visible: !viewEmail.focused() && !viewEmail.hasError() && '' !== viewEmail(), click: function() { viewEmail.focused(true); }, text: viewEmail"></span>
|
|
||||||
<input class="contactValueInput span5" type="text" placeholder="email" data-bind="value: viewEmail, visible: viewEmail.hasError() || viewEmail.focused(), hasfocus: viewEmail.focused, onEnter: function () { viewEmail.focused(false); }">
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<div class="control-label">
|
<label class="control-label">
|
||||||
</div>
|
<span class="i18n">Emails</span>
|
||||||
|
</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
|
<div data-bind="foreach: viewPropertiesEmails">
|
||||||
|
<div class="property-line">
|
||||||
|
<input type="email" class="contactValueInput" data-bind="value: value, hasFocus: focused, valueUpdate: 'keyup'" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="g-ui-link add-link" data-bind="click: addNewEmail">Add an email address</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label">
|
||||||
|
<span class="i18n">Phones</span>
|
||||||
|
</label>
|
||||||
|
<div class="controls">
|
||||||
|
<div data-bind="foreach: viewPropertiesPhones">
|
||||||
|
<div class="property-line">
|
||||||
|
<input type="email" class="contactValueInput" data-bind="value: value, hasFocus: focused, valueUpdate: 'keyup'" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="g-ui-link add-link" data-bind="click: addNewPhone">Add a phone</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<div class="controls">
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -7250,58 +7250,27 @@ html.rl-message-fullscreen .messageView .b-content .buttonFull {
|
||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
.b-contacts-content.modal .b-view-content .top-part {
|
.b-contacts-content.modal .b-view-content .top-part {
|
||||||
margin-top: 20px;
|
padding-top: 20px;
|
||||||
}
|
}
|
||||||
.b-contacts-content.modal .b-view-content .top-part .control-label {
|
.b-contacts-content.modal .b-view-content .property-line {
|
||||||
text-align: center;
|
margin-bottom: 5px;
|
||||||
}
|
|
||||||
.b-contacts-content.modal .b-view-content .image-wrapper {
|
|
||||||
margin-left: 30px;
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
.b-contacts-content.modal .b-view-content .image-wrapper img {
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
}
|
||||||
.b-contacts-content.modal .b-view-content .top-row {
|
.b-contacts-content.modal .b-view-content .top-row {
|
||||||
padding: 10px 0;
|
padding: 10px 0;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
}
|
}
|
||||||
.b-contacts-content.modal .b-view-content .contactEmptyValueClick,
|
.b-contacts-content.modal .b-view-content .add-link {
|
||||||
.b-contacts-content.modal .b-view-content .contactValueClick,
|
padding-top: 5px;
|
||||||
.b-contacts-content.modal .b-view-content .contactValueInput {
|
font-size: 12px;
|
||||||
display: inline-block;
|
color: #aaa;
|
||||||
font-size: 24px;
|
|
||||||
line-height: 28px;
|
|
||||||
height: 28px;
|
|
||||||
}
|
}
|
||||||
.b-contacts-content.modal .b-view-content .contactEmptyValueClick,
|
|
||||||
.b-contacts-content.modal .b-view-content .contactValueClick {
|
|
||||||
color: #ddd;
|
|
||||||
cursor: pointer;
|
|
||||||
margin: 5px 0 0 7px;
|
|
||||||
}
|
|
||||||
.b-contacts-content.modal .b-view-content .contactValueInput {
|
|
||||||
padding-left: 6px;
|
|
||||||
}
|
|
||||||
.b-contacts-content.modal .b-view-content .contactEmptyValueClick {
|
|
||||||
border-bottom: 1px dashed #ddd;
|
|
||||||
}
|
|
||||||
.b-contacts-content.modal .b-view-content .contactValueClick {
|
|
||||||
color: #555;
|
|
||||||
border-bottom: 11px dashed transparent;
|
|
||||||
}
|
|
||||||
.b-contacts-content.modal .b-view-content .contactValueClick:hover {
|
|
||||||
color: #000;
|
|
||||||
border-bottom: 1px dashed #000;
|
|
||||||
}
|
|
||||||
.b-contacts-content.modal .b-view-content .hasError .contactValueClick,
|
|
||||||
.b-contacts-content.modal .b-view-content .hasError .contactValueInput {
|
.b-contacts-content.modal .b-view-content .hasError .contactValueInput {
|
||||||
color: #ee5f5b;
|
color: #ee5f5b;
|
||||||
border: 1px solid #ee5f5b;
|
border: 1px solid #ee5f5b;
|
||||||
}
|
}
|
||||||
.b-contacts-content.modal .b-view-content .button-save-contact {
|
.b-contacts-content.modal .b-view-content .button-save-contact {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 20px;
|
top: 20px;
|
||||||
right: 20px;
|
right: 20px;
|
||||||
}
|
}
|
||||||
.b-contacts-content .e-contact-item {
|
.b-contacts-content .e-contact-item {
|
||||||
|
|
|
||||||
2
rainloop/v/0.0.0/static/css/app.min.css
vendored
2
rainloop/v/0.0.0/static/css/app.min.css
vendored
File diff suppressed because one or more lines are too long
|
|
@ -5095,58 +5095,27 @@ html.rl-message-fullscreen .messageView .b-content .buttonFull {
|
||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
.b-contacts-content.modal .b-view-content .top-part {
|
.b-contacts-content.modal .b-view-content .top-part {
|
||||||
margin-top: 20px;
|
padding-top: 20px;
|
||||||
}
|
}
|
||||||
.b-contacts-content.modal .b-view-content .top-part .control-label {
|
.b-contacts-content.modal .b-view-content .property-line {
|
||||||
text-align: center;
|
margin-bottom: 5px;
|
||||||
}
|
|
||||||
.b-contacts-content.modal .b-view-content .image-wrapper {
|
|
||||||
margin-left: 30px;
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
.b-contacts-content.modal .b-view-content .image-wrapper img {
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
}
|
||||||
.b-contacts-content.modal .b-view-content .top-row {
|
.b-contacts-content.modal .b-view-content .top-row {
|
||||||
padding: 10px 0;
|
padding: 10px 0;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
}
|
}
|
||||||
.b-contacts-content.modal .b-view-content .contactEmptyValueClick,
|
.b-contacts-content.modal .b-view-content .add-link {
|
||||||
.b-contacts-content.modal .b-view-content .contactValueClick,
|
padding-top: 5px;
|
||||||
.b-contacts-content.modal .b-view-content .contactValueInput {
|
font-size: 12px;
|
||||||
display: inline-block;
|
color: #aaa;
|
||||||
font-size: 24px;
|
|
||||||
line-height: 28px;
|
|
||||||
height: 28px;
|
|
||||||
}
|
}
|
||||||
.b-contacts-content.modal .b-view-content .contactEmptyValueClick,
|
|
||||||
.b-contacts-content.modal .b-view-content .contactValueClick {
|
|
||||||
color: #ddd;
|
|
||||||
cursor: pointer;
|
|
||||||
margin: 5px 0 0 7px;
|
|
||||||
}
|
|
||||||
.b-contacts-content.modal .b-view-content .contactValueInput {
|
|
||||||
padding-left: 6px;
|
|
||||||
}
|
|
||||||
.b-contacts-content.modal .b-view-content .contactEmptyValueClick {
|
|
||||||
border-bottom: 1px dashed #ddd;
|
|
||||||
}
|
|
||||||
.b-contacts-content.modal .b-view-content .contactValueClick {
|
|
||||||
color: #555;
|
|
||||||
border-bottom: 11px dashed transparent;
|
|
||||||
}
|
|
||||||
.b-contacts-content.modal .b-view-content .contactValueClick:hover {
|
|
||||||
color: #000;
|
|
||||||
border-bottom: 1px dashed #000;
|
|
||||||
}
|
|
||||||
.b-contacts-content.modal .b-view-content .hasError .contactValueClick,
|
|
||||||
.b-contacts-content.modal .b-view-content .hasError .contactValueInput {
|
.b-contacts-content.modal .b-view-content .hasError .contactValueInput {
|
||||||
color: #ee5f5b;
|
color: #ee5f5b;
|
||||||
border: 1px solid #ee5f5b;
|
border: 1px solid #ee5f5b;
|
||||||
}
|
}
|
||||||
.b-contacts-content.modal .b-view-content .button-save-contact {
|
.b-contacts-content.modal .b-view-content .button-save-contact {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 20px;
|
top: 20px;
|
||||||
right: 20px;
|
right: 20px;
|
||||||
}
|
}
|
||||||
.b-contacts-content .e-contact-item {
|
.b-contacts-content .e-contact-item {
|
||||||
|
|
|
||||||
|
|
@ -487,6 +487,45 @@ Enums.InterfaceAnimation = {
|
||||||
'Full': 'Full'
|
'Full': 'Full'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @enum {number}
|
||||||
|
*/
|
||||||
|
Enums.ContactPropertyType = {
|
||||||
|
|
||||||
|
'Unknown': 0,
|
||||||
|
|
||||||
|
'FullName': 10,
|
||||||
|
|
||||||
|
'FirstName': 15,
|
||||||
|
'SurName': 16,
|
||||||
|
'MiddleName': 17,
|
||||||
|
'Nick': 18,
|
||||||
|
|
||||||
|
'EmailPersonal': 30,
|
||||||
|
'EmailBussines': 31,
|
||||||
|
'EmailOther': 32,
|
||||||
|
|
||||||
|
'PhonePersonal': 50,
|
||||||
|
'PhoneBussines': 51,
|
||||||
|
'PhoneOther': 52,
|
||||||
|
|
||||||
|
'MobilePersonal': 60,
|
||||||
|
'MobileBussines': 61,
|
||||||
|
'MobileOther': 62,
|
||||||
|
|
||||||
|
'FaxPesonal': 70,
|
||||||
|
'FaxBussines': 71,
|
||||||
|
'FaxOther': 72,
|
||||||
|
|
||||||
|
'Facebook': 90,
|
||||||
|
'Skype': 91,
|
||||||
|
'GitHub': 92,
|
||||||
|
|
||||||
|
'Description': 110,
|
||||||
|
|
||||||
|
'Custom': 250
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum {number}
|
* @enum {number}
|
||||||
*/
|
*/
|
||||||
|
|
@ -1427,7 +1466,6 @@ Utils.initDataConstructorBySettings = function (oData)
|
||||||
oData.dropboxEnable = ko.observable(false);
|
oData.dropboxEnable = ko.observable(false);
|
||||||
oData.dropboxApiKey = ko.observable('');
|
oData.dropboxApiKey = ko.observable('');
|
||||||
|
|
||||||
oData.contactsIsSupported = ko.observable(false);
|
|
||||||
oData.contactsIsAllowed = ko.observable(false);
|
oData.contactsIsAllowed = ko.observable(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -2679,6 +2717,12 @@ ko.extenders.falseTimeout = function (oTarget, iOption)
|
||||||
return oTarget;
|
return oTarget;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ko.observable.fn.validateNone = function ()
|
||||||
|
{
|
||||||
|
this.hasError = ko.observable(false);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
ko.observable.fn.validateEmail = function ()
|
ko.observable.fn.validateEmail = function ()
|
||||||
{
|
{
|
||||||
this.hasError = ko.observable(false);
|
this.hasError = ko.observable(false);
|
||||||
|
|
@ -4866,8 +4910,6 @@ function AdminGeneral()
|
||||||
return Utils.convertLangName(this.mainLanguage());
|
return Utils.convertLangName(this.mainLanguage());
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
this.contactsSupported = RL.settingsGet('ContactsIsSupported');
|
|
||||||
this.contactsIsAllowed = RL.settingsGet('ContactsIsAllowed');
|
|
||||||
this.weakPassword = !!RL.settingsGet('WeakPassword');
|
this.weakPassword = !!RL.settingsGet('WeakPassword');
|
||||||
|
|
||||||
this.titleTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
|
this.titleTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
|
||||||
|
|
@ -5588,7 +5630,6 @@ AbstractData.prototype.populateDataOnStart = function()
|
||||||
this.dropboxEnable(!!RL.settingsGet('AllowDropboxSocial'));
|
this.dropboxEnable(!!RL.settingsGet('AllowDropboxSocial'));
|
||||||
this.dropboxApiKey(RL.settingsGet('DropboxApiKey'));
|
this.dropboxApiKey(RL.settingsGet('DropboxApiKey'));
|
||||||
|
|
||||||
this.contactsIsSupported(!!RL.settingsGet('ContactsIsSupported'));
|
|
||||||
this.contactsIsAllowed(!!RL.settingsGet('ContactsIsAllowed'));
|
this.contactsIsAllowed(!!RL.settingsGet('ContactsIsAllowed'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
6
rainloop/v/0.0.0/static/js/admin.min.js
vendored
6
rainloop/v/0.0.0/static/js/admin.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -487,6 +487,45 @@ Enums.InterfaceAnimation = {
|
||||||
'Full': 'Full'
|
'Full': 'Full'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @enum {number}
|
||||||
|
*/
|
||||||
|
Enums.ContactPropertyType = {
|
||||||
|
|
||||||
|
'Unknown': 0,
|
||||||
|
|
||||||
|
'FullName': 10,
|
||||||
|
|
||||||
|
'FirstName': 15,
|
||||||
|
'SurName': 16,
|
||||||
|
'MiddleName': 17,
|
||||||
|
'Nick': 18,
|
||||||
|
|
||||||
|
'EmailPersonal': 30,
|
||||||
|
'EmailBussines': 31,
|
||||||
|
'EmailOther': 32,
|
||||||
|
|
||||||
|
'PhonePersonal': 50,
|
||||||
|
'PhoneBussines': 51,
|
||||||
|
'PhoneOther': 52,
|
||||||
|
|
||||||
|
'MobilePersonal': 60,
|
||||||
|
'MobileBussines': 61,
|
||||||
|
'MobileOther': 62,
|
||||||
|
|
||||||
|
'FaxPesonal': 70,
|
||||||
|
'FaxBussines': 71,
|
||||||
|
'FaxOther': 72,
|
||||||
|
|
||||||
|
'Facebook': 90,
|
||||||
|
'Skype': 91,
|
||||||
|
'GitHub': 92,
|
||||||
|
|
||||||
|
'Description': 110,
|
||||||
|
|
||||||
|
'Custom': 250
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum {number}
|
* @enum {number}
|
||||||
*/
|
*/
|
||||||
|
|
@ -1427,7 +1466,6 @@ Utils.initDataConstructorBySettings = function (oData)
|
||||||
oData.dropboxEnable = ko.observable(false);
|
oData.dropboxEnable = ko.observable(false);
|
||||||
oData.dropboxApiKey = ko.observable('');
|
oData.dropboxApiKey = ko.observable('');
|
||||||
|
|
||||||
oData.contactsIsSupported = ko.observable(false);
|
|
||||||
oData.contactsIsAllowed = ko.observable(false);
|
oData.contactsIsAllowed = ko.observable(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -2679,6 +2717,12 @@ ko.extenders.falseTimeout = function (oTarget, iOption)
|
||||||
return oTarget;
|
return oTarget;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ko.observable.fn.validateNone = function ()
|
||||||
|
{
|
||||||
|
this.hasError = ko.observable(false);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
ko.observable.fn.validateEmail = function ()
|
ko.observable.fn.validateEmail = function ()
|
||||||
{
|
{
|
||||||
this.hasError = ko.observable(false);
|
this.hasError = ko.observable(false);
|
||||||
|
|
@ -5652,26 +5696,65 @@ EmailModel.prototype.inputoTagLine = function ()
|
||||||
function ContactModel()
|
function ContactModel()
|
||||||
{
|
{
|
||||||
this.idContact = 0;
|
this.idContact = 0;
|
||||||
this.imageHash = '';
|
this.display = '';
|
||||||
this.listName = '';
|
this.properties = [];
|
||||||
this.name = '';
|
|
||||||
this.emails = [];
|
|
||||||
|
|
||||||
this.checked = ko.observable(false);
|
this.checked = ko.observable(false);
|
||||||
this.selected = ko.observable(false);
|
this.selected = ko.observable(false);
|
||||||
this.deleted = ko.observable(false);
|
this.deleted = ko.observable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {Array|null}
|
||||||
|
*/
|
||||||
|
ContactModel.prototype.getNameAndEmailHelper = function ()
|
||||||
|
{
|
||||||
|
var
|
||||||
|
sName = '',
|
||||||
|
sEmail = ''
|
||||||
|
;
|
||||||
|
|
||||||
|
if (Utils.isNonEmptyArray(this.properties))
|
||||||
|
{
|
||||||
|
_.each(this.properties, function (aProperty) {
|
||||||
|
if (aProperty)
|
||||||
|
{
|
||||||
|
if ('' === sName && Enums.ContactPropertyType.FullName === aProperty[0])
|
||||||
|
{
|
||||||
|
sName = aProperty[1];
|
||||||
|
}
|
||||||
|
else if ('' === sEmail && -1 < Utils.inArray(aProperty[0], [
|
||||||
|
Enums.ContactPropertyType.EmailPersonal,
|
||||||
|
Enums.ContactPropertyType.EmailBussines,
|
||||||
|
Enums.ContactPropertyType.EmailOther
|
||||||
|
]))
|
||||||
|
{
|
||||||
|
sEmail = aProperty[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return '' === sEmail ? null : [sEmail, sName];
|
||||||
|
};
|
||||||
|
|
||||||
ContactModel.prototype.parse = function (oItem)
|
ContactModel.prototype.parse = function (oItem)
|
||||||
{
|
{
|
||||||
var bResult = false;
|
var bResult = false;
|
||||||
if (oItem && 'Object/Contact' === oItem['@Object'])
|
if (oItem && 'Object/Contact' === oItem['@Object'])
|
||||||
{
|
{
|
||||||
this.idContact = Utils.pInt(oItem['IdContact']);
|
this.idContact = Utils.pInt(oItem['IdContact']);
|
||||||
this.listName = Utils.pString(oItem['ListName']);
|
this.display = Utils.pString(oItem['Display']);
|
||||||
this.name = Utils.pString(oItem['Name']);
|
|
||||||
this.emails = Utils.isNonEmptyArray(oItem['Emails']) ? oItem['Emails'] : [];
|
if (Utils.isNonEmptyArray(oItem['Properties']))
|
||||||
this.imageHash = Utils.pString(oItem['ImageHash']);
|
{
|
||||||
|
_.each(oItem['Properties'], function (oProperty) {
|
||||||
|
if (oProperty && oProperty['Type'] && Utils.isNormal(oProperty['Value']))
|
||||||
|
{
|
||||||
|
this.properties.push([Utils.pInt(oProperty['Type']), Utils.pString(oProperty['Value'])]);
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
|
}
|
||||||
|
|
||||||
bResult = true;
|
bResult = true;
|
||||||
}
|
}
|
||||||
|
|
@ -5684,8 +5767,7 @@ ContactModel.prototype.parse = function (oItem)
|
||||||
*/
|
*/
|
||||||
ContactModel.prototype.srcAttr = function ()
|
ContactModel.prototype.srcAttr = function ()
|
||||||
{
|
{
|
||||||
return '' === this.imageHash ? RL.link().emptyContactPic() :
|
return RL.link().emptyContactPic();
|
||||||
RL.link().getUserPicUrlFromHash(this.imageHash);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -5718,6 +5800,19 @@ ContactModel.prototype.lineAsCcc = function ()
|
||||||
return aResult.join(' ');
|
return aResult.join(' ');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number=} iType = Enums.ContactPropertyType.Unknown
|
||||||
|
* @param {string=} sValue = ''
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
function ContactPropertyModel(iType, sValue)
|
||||||
|
{
|
||||||
|
this.type = ko.observable(Utils.isUnd(iType) ? Enums.ContactPropertyType.Unknown : iType);
|
||||||
|
this.focused = ko.observable(false);
|
||||||
|
this.value = ko.observable(Utils.pString(sValue));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
|
|
@ -8060,7 +8155,7 @@ PopupsComposeViewModel.prototype.sendMessageResponse = function (sResult, oData)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.sendError(true);
|
this.sendError(true);
|
||||||
window.alert(Utils.getNotification(oData.ErrorCode ? oData.ErrorCode : Enums.Notification.CantSendMessage));
|
window.alert(Utils.getNotification(oData && oData.ErrorCode ? oData.ErrorCode : Enums.Notification.CantSendMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -8948,11 +9043,21 @@ function PopupsContactsViewModel()
|
||||||
{
|
{
|
||||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsContacts');
|
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsContacts');
|
||||||
|
|
||||||
var self = this;
|
var
|
||||||
|
self = this,
|
||||||
this.imageUploader = ko.observable(null);
|
aNameTypes = [Enums.ContactPropertyType.FullName, Enums.ContactPropertyType.FirstName, Enums.ContactPropertyType.SurName, Enums.ContactPropertyType.MiddleName],
|
||||||
this.imageDom = ko.observable(null);
|
aEmailTypes = [Enums.ContactPropertyType.EmailPersonal, Enums.ContactPropertyType.EmailBussines, Enums.ContactPropertyType.EmailOther],
|
||||||
this.imageTrigger = ko.observable(false);
|
aPhonesTypes = [
|
||||||
|
Enums.ContactPropertyType.PhonePersonal, Enums.ContactPropertyType.PhoneBussines, Enums.ContactPropertyType.PhoneOther,
|
||||||
|
Enums.ContactPropertyType.MobilePersonal, Enums.ContactPropertyType.MobileBussines, Enums.ContactPropertyType.MobileOther,
|
||||||
|
Enums.ContactPropertyType.FaxPesonal, Enums.ContactPropertyType.FaxBussines, Enums.ContactPropertyType.FaxOther
|
||||||
|
],
|
||||||
|
fFastClearEmptyListHelper = function (aList) {
|
||||||
|
if (aList && 0 < aList.length) {
|
||||||
|
self.viewProperties.removeAll(aList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
this.search = ko.observable('');
|
this.search = ko.observable('');
|
||||||
this.contacts = ko.observableArray([]);
|
this.contacts = ko.observableArray([]);
|
||||||
|
|
@ -8963,11 +9068,50 @@ function PopupsContactsViewModel()
|
||||||
this.viewClearSearch = ko.observable(false);
|
this.viewClearSearch = ko.observable(false);
|
||||||
|
|
||||||
this.viewID = ko.observable('');
|
this.viewID = ko.observable('');
|
||||||
this.viewName = ko.observable('');
|
this.viewProperties = ko.observableArray([]);
|
||||||
this.viewName.focused = ko.observable(false);
|
|
||||||
this.viewEmail = ko.observable('').validateEmail();
|
this.viewPropertiesNames = this.viewProperties.filter(function(oProperty) {
|
||||||
this.viewEmail.focused = ko.observable(false);
|
return -1 < Utils.inArray(oProperty.type(), aNameTypes);
|
||||||
this.viewImageUrl = ko.observable(RL.link().emptyContactPic());
|
});
|
||||||
|
|
||||||
|
this.viewPropertiesEmails = this.viewProperties.filter(function(oProperty) {
|
||||||
|
return -1 < Utils.inArray(oProperty.type(), aEmailTypes);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.viewHasNonEmptyRequaredProperties = ko.computed(function() {
|
||||||
|
|
||||||
|
var
|
||||||
|
aNames = this.viewPropertiesNames(),
|
||||||
|
aEmail = this.viewPropertiesEmails(),
|
||||||
|
fHelper = function (oProperty) {
|
||||||
|
return '' !== Utils.trim(oProperty.value());
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
return !!(_.find(aNames, fHelper) || _.find(aEmail, fHelper));
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
this.viewPropertiesPhones = this.viewProperties.filter(function(oProperty) {
|
||||||
|
return -1 < Utils.inArray(oProperty.type(), aPhonesTypes);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.viewPropertiesEmailsEmptyAndOnFocused = this.viewPropertiesEmails.filter(function(oProperty) {
|
||||||
|
var bF = oProperty.focused();
|
||||||
|
return '' === Utils.trim(oProperty.value()) && !bF;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.viewPropertiesPhonesEmptyAndOnFocused = this.viewPropertiesPhones.filter(function(oProperty) {
|
||||||
|
var bF = oProperty.focused();
|
||||||
|
return '' === Utils.trim(oProperty.value()) && !bF;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.viewPropertiesEmailsEmptyAndOnFocused.subscribe(function(aList) {
|
||||||
|
fFastClearEmptyListHelper(aList);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.viewPropertiesPhonesEmptyAndOnFocused.subscribe(function(aList) {
|
||||||
|
fFastClearEmptyListHelper(aList);
|
||||||
|
});
|
||||||
|
|
||||||
this.viewSaving = ko.observable(false);
|
this.viewSaving = ko.observable(false);
|
||||||
|
|
||||||
|
|
@ -8981,8 +9125,8 @@ function PopupsContactsViewModel()
|
||||||
Utils.windowResize();
|
Utils.windowResize();
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
this.viewImageUrl.subscribe(function (sUrl) {
|
this.viewProperties.subscribe(function () {
|
||||||
this.imageDom()['src'] = sUrl;
|
Utils.windowResize();
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
this.contactsChecked = ko.computed(function () {
|
this.contactsChecked = ko.computed(function () {
|
||||||
|
|
@ -9043,10 +9187,14 @@ function PopupsContactsViewModel()
|
||||||
if (Utils.isNonEmptyArray(aC))
|
if (Utils.isNonEmptyArray(aC))
|
||||||
{
|
{
|
||||||
aE = _.map(aC, function (oItem) {
|
aE = _.map(aC, function (oItem) {
|
||||||
if (oItem && oItem['emails'])
|
if (oItem)
|
||||||
{
|
{
|
||||||
var oEmail = new EmailModel(oItem['emails'][0] || '', oItem['name']);
|
var
|
||||||
if (oEmail.validate())
|
aData = oItem.getNameAndEmailHelper(),
|
||||||
|
oEmail = aData ? new EmailModel(aData[0], aData[1]) : null
|
||||||
|
;
|
||||||
|
|
||||||
|
if (oEmail && oEmail.validate())
|
||||||
{
|
{
|
||||||
return oEmail;
|
return oEmail;
|
||||||
}
|
}
|
||||||
|
|
@ -9058,7 +9206,7 @@ function PopupsContactsViewModel()
|
||||||
aE = _.compact(aE);
|
aE = _.compact(aE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.isNonEmptyArray(aC))
|
if (Utils.isNonEmptyArray(aE))
|
||||||
{
|
{
|
||||||
kn.hideScreenPopup(PopupsContactsViewModel);
|
kn.hideScreenPopup(PopupsContactsViewModel);
|
||||||
kn.showScreenPopup(PopupsComposeViewModel, [Enums.ComposeType.Empty, null, aE]);
|
kn.showScreenPopup(PopupsComposeViewModel, [Enums.ComposeType.Empty, null, aE]);
|
||||||
|
|
@ -9073,12 +9221,21 @@ function PopupsContactsViewModel()
|
||||||
});
|
});
|
||||||
|
|
||||||
this.saveCommand = Utils.createCommand(this, function () {
|
this.saveCommand = Utils.createCommand(this, function () {
|
||||||
var
|
|
||||||
sRequestUid = Utils.fakeMd5(),
|
|
||||||
bImageTrigger = this.imageTrigger()
|
|
||||||
;
|
|
||||||
|
|
||||||
this.viewSaving(true);
|
this.viewSaving(true);
|
||||||
|
|
||||||
|
var
|
||||||
|
sRequestUid = Utils.fakeMd5(),
|
||||||
|
aProperties = []
|
||||||
|
;
|
||||||
|
|
||||||
|
_.each(this.viewProperties(), function (oItem) {
|
||||||
|
if (oItem.type() && '' !== Utils.trim(oItem.value()))
|
||||||
|
{
|
||||||
|
aProperties.push([oItem.type(), oItem.value()]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
RL.remote().contactSave(function (sResult, oData) {
|
RL.remote().contactSave(function (sResult, oData) {
|
||||||
|
|
||||||
self.viewSaving(false);
|
self.viewSaving(false);
|
||||||
|
|
@ -9091,31 +9248,42 @@ function PopupsContactsViewModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
self.reloadContactList();
|
self.reloadContactList();
|
||||||
if (bImageTrigger)
|
|
||||||
{
|
|
||||||
RL.emailsPicsHashes();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
// // TODO
|
// // TODO
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}, sRequestUid, this.viewID(), this.viewName(), this.viewEmail(), bImageTrigger ? this.imageDom()['src'] : '');
|
}, sRequestUid, this.viewID(), aProperties);
|
||||||
|
|
||||||
}, function () {
|
}, function () {
|
||||||
var
|
var bV = this.viewHasNonEmptyRequaredProperties();
|
||||||
sViewName = this.viewName(),
|
return !this.viewSaving() && bV;
|
||||||
sViewEmail = this.viewEmail()
|
|
||||||
;
|
|
||||||
|
|
||||||
return !this.viewSaving() &&
|
|
||||||
('' !== sViewName || '' !== sViewEmail);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils.extendAsViewModel('PopupsContactsViewModel', PopupsContactsViewModel);
|
Utils.extendAsViewModel('PopupsContactsViewModel', PopupsContactsViewModel);
|
||||||
|
|
||||||
|
PopupsContactsViewModel.prototype.addNewEmail = function ()
|
||||||
|
{
|
||||||
|
// if (0 === this.viewPropertiesEmailsEmpty().length)
|
||||||
|
// {
|
||||||
|
var oItem = new ContactPropertyModel(Enums.ContactPropertyType.EmailPersonal, '');
|
||||||
|
oItem.focused(true);
|
||||||
|
this.viewProperties.push(oItem);
|
||||||
|
// }
|
||||||
|
};
|
||||||
|
|
||||||
|
PopupsContactsViewModel.prototype.addNewPhone = function ()
|
||||||
|
{
|
||||||
|
// if (0 === this.viewPropertiesPhonesEmpty().length)
|
||||||
|
// {
|
||||||
|
var oItem = new ContactPropertyModel(Enums.ContactPropertyType.PhonePersonal, '');
|
||||||
|
oItem.focused(true);
|
||||||
|
this.viewProperties.push(oItem);
|
||||||
|
// }
|
||||||
|
};
|
||||||
|
|
||||||
PopupsContactsViewModel.prototype.removeCheckedOrSelectedContactsFromList = function ()
|
PopupsContactsViewModel.prototype.removeCheckedOrSelectedContactsFromList = function ()
|
||||||
{
|
{
|
||||||
var
|
var
|
||||||
|
|
@ -9181,28 +9349,51 @@ PopupsContactsViewModel.prototype.deleteResponse = function (sResult, oData)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PopupsContactsViewModel.prototype.removeProperty = function (oProp)
|
||||||
|
{
|
||||||
|
this.viewProperties.remove(oProp);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {?ContactModel} oContact
|
* @param {?ContactModel} oContact
|
||||||
*/
|
*/
|
||||||
PopupsContactsViewModel.prototype.populateViewContact = function (oContact)
|
PopupsContactsViewModel.prototype.populateViewContact = function (oContact)
|
||||||
{
|
{
|
||||||
this.imageTrigger(false);
|
var
|
||||||
|
sId = '',
|
||||||
|
bHasName = false,
|
||||||
|
aList = []
|
||||||
|
;
|
||||||
|
|
||||||
this.emptySelection(false);
|
this.emptySelection(false);
|
||||||
|
|
||||||
if (oContact)
|
if (oContact)
|
||||||
{
|
{
|
||||||
this.viewID(oContact.idContact);
|
sId = oContact.idContact;
|
||||||
this.viewName(oContact.name);
|
|
||||||
this.viewEmail(oContact.emails[0] || '');
|
if (Utils.isNonEmptyArray(oContact.properties))
|
||||||
this.viewImageUrl(oContact.srcAttr());
|
{
|
||||||
|
_.each(oContact.properties, function (aProperty) {
|
||||||
|
if (aProperty && aProperty[0])
|
||||||
|
{
|
||||||
|
aList.push(new ContactPropertyModel(aProperty[0], aProperty[1]));
|
||||||
|
if (Enums.ContactPropertyType.FullName === aProperty[0])
|
||||||
|
{
|
||||||
|
bHasName = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (!bHasName)
|
||||||
{
|
{
|
||||||
this.viewID('');
|
aList.push(new ContactPropertyModel(Enums.ContactPropertyType.FullName, ''));
|
||||||
this.viewName('');
|
|
||||||
this.viewEmail('');
|
|
||||||
this.viewImageUrl(RL.link().emptyContactPic());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.viewID(sId);
|
||||||
|
this.viewProperties([]);
|
||||||
|
this.viewProperties(aList);
|
||||||
};
|
};
|
||||||
|
|
||||||
PopupsContactsViewModel.prototype.reloadContactList = function ()
|
PopupsContactsViewModel.prototype.reloadContactList = function ()
|
||||||
|
|
@ -9233,20 +9424,16 @@ PopupsContactsViewModel.prototype.reloadContactList = function ()
|
||||||
self.contacts.setSelectedByUid('' + self.viewID());
|
self.contacts.setSelectedByUid('' + self.viewID());
|
||||||
}
|
}
|
||||||
|
|
||||||
}, this.search());
|
}, 0, 20, this.search());
|
||||||
};
|
};
|
||||||
|
|
||||||
PopupsContactsViewModel.prototype.onBuild = function (oDom)
|
PopupsContactsViewModel.prototype.onBuild = function (oDom)
|
||||||
{
|
{
|
||||||
this.initUploader();
|
|
||||||
|
|
||||||
this.oContentVisible = $('.b-list-content', oDom);
|
this.oContentVisible = $('.b-list-content', oDom);
|
||||||
this.oContentScrollable = $('.content', this.oContentVisible);
|
this.oContentScrollable = $('.content', this.oContentVisible);
|
||||||
|
|
||||||
this.selector.init(this.oContentVisible, this.oContentScrollable);
|
this.selector.init(this.oContentVisible, this.oContentScrollable);
|
||||||
|
|
||||||
this.viewImageUrl.valueHasMutated();
|
|
||||||
|
|
||||||
ko.computed(function () {
|
ko.computed(function () {
|
||||||
var
|
var
|
||||||
bModalVisibility = this.modalVisibility(),
|
bModalVisibility = this.modalVisibility(),
|
||||||
|
|
@ -9256,56 +9443,6 @@ PopupsContactsViewModel.prototype.onBuild = function (oDom)
|
||||||
}, this).extend({'notify': 'always'});
|
}, this).extend({'notify': 'always'});
|
||||||
};
|
};
|
||||||
|
|
||||||
PopupsContactsViewModel.prototype.initUploader = function ()
|
|
||||||
{
|
|
||||||
var self = this, oJua = null;
|
|
||||||
if (window.File && window.FileReader && this.imageUploader())
|
|
||||||
{
|
|
||||||
oJua = new Jua({
|
|
||||||
'queueSize': 1,
|
|
||||||
'multipleSizeLimit': 1,
|
|
||||||
'clickElement': this.imageUploader(),
|
|
||||||
'disableDragAndDrop': true,
|
|
||||||
'disableMultiple': true,
|
|
||||||
'onSelect': function (sId, oData) {
|
|
||||||
|
|
||||||
if (oData && oData['File'] && oData['File']['type'])
|
|
||||||
{
|
|
||||||
var
|
|
||||||
oReader = null,
|
|
||||||
oFile = oData['File'],
|
|
||||||
sType = oData['File']['type']
|
|
||||||
;
|
|
||||||
|
|
||||||
if (!sType.match(/image.*/))
|
|
||||||
{
|
|
||||||
window.alert('this file is not an image.');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
oReader = new window.FileReader();
|
|
||||||
oReader.onload = function (oEvent) {
|
|
||||||
if (oEvent && oEvent.target && oEvent.target.result)
|
|
||||||
{
|
|
||||||
Utils.resizeAndCrop(oEvent.target.result, 150, function (sUrl) {
|
|
||||||
self.viewImageUrl(sUrl);
|
|
||||||
self.imageTrigger(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
oReader.readAsDataURL(oFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return oJua;
|
|
||||||
};
|
|
||||||
|
|
||||||
PopupsContactsViewModel.prototype.onShow = function ()
|
PopupsContactsViewModel.prototype.onShow = function ()
|
||||||
{
|
{
|
||||||
kn.routeOff();
|
kn.routeOff();
|
||||||
|
|
@ -10112,7 +10249,7 @@ function MailBoxFolderListViewModel()
|
||||||
|
|
||||||
this.iDropOverTimer = 0;
|
this.iDropOverTimer = 0;
|
||||||
|
|
||||||
this.allowContacts = !!RL.settingsGet('ContactsIsSupported') && !!RL.settingsGet('ContactsIsAllowed');
|
this.allowContacts = !!RL.settingsGet('ContactsIsAllowed');
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils.extendAsViewModel('MailBoxFolderListViewModel', MailBoxFolderListViewModel);
|
Utils.extendAsViewModel('MailBoxFolderListViewModel', MailBoxFolderListViewModel);
|
||||||
|
|
@ -12507,7 +12644,6 @@ AbstractData.prototype.populateDataOnStart = function()
|
||||||
this.dropboxEnable(!!RL.settingsGet('AllowDropboxSocial'));
|
this.dropboxEnable(!!RL.settingsGet('AllowDropboxSocial'));
|
||||||
this.dropboxApiKey(RL.settingsGet('DropboxApiKey'));
|
this.dropboxApiKey(RL.settingsGet('DropboxApiKey'));
|
||||||
|
|
||||||
this.contactsIsSupported(!!RL.settingsGet('ContactsIsSupported'));
|
|
||||||
this.contactsIsAllowed(!!RL.settingsGet('ContactsIsAllowed'));
|
this.contactsIsAllowed(!!RL.settingsGet('ContactsIsAllowed'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -14218,11 +14354,15 @@ WebMailAjaxRemoteStorage.prototype.quota = function (fCallback)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {?Function} fCallback
|
* @param {?Function} fCallback
|
||||||
|
* @param {number} iOffset
|
||||||
|
* @param {number} iLimit
|
||||||
* @param {string} sSearch
|
* @param {string} sSearch
|
||||||
*/
|
*/
|
||||||
WebMailAjaxRemoteStorage.prototype.contacts = function (fCallback, sSearch)
|
WebMailAjaxRemoteStorage.prototype.contacts = function (fCallback, iOffset, iLimit, sSearch)
|
||||||
{
|
{
|
||||||
this.defaultRequest(fCallback, 'Contacts', {
|
this.defaultRequest(fCallback, 'Contacts', {
|
||||||
|
'Offset': iOffset,
|
||||||
|
'Limit': iLimit,
|
||||||
'Search': sSearch
|
'Search': sSearch
|
||||||
}, null, '', ['Contacts']);
|
}, null, '', ['Contacts']);
|
||||||
};
|
};
|
||||||
|
|
@ -14230,15 +14370,12 @@ WebMailAjaxRemoteStorage.prototype.contacts = function (fCallback, sSearch)
|
||||||
/**
|
/**
|
||||||
* @param {?Function} fCallback
|
* @param {?Function} fCallback
|
||||||
*/
|
*/
|
||||||
WebMailAjaxRemoteStorage.prototype.contactSave = function (fCallback, sRequestUid, sUid, sName, sEmail, sImageData)
|
WebMailAjaxRemoteStorage.prototype.contactSave = function (fCallback, sRequestUid, sUid, aProperties)
|
||||||
{
|
{
|
||||||
sUid = Utils.trim(sUid);
|
|
||||||
this.defaultRequest(fCallback, 'ContactSave', {
|
this.defaultRequest(fCallback, 'ContactSave', {
|
||||||
'RequestUid': sRequestUid,
|
'RequestUid': sRequestUid,
|
||||||
'Uid': sUid,
|
'Uid': Utils.trim(sUid),
|
||||||
'Name': sName,
|
'Properties': aProperties
|
||||||
'Email': sEmail,
|
|
||||||
'ImageData': sImageData
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -15865,9 +16002,9 @@ RainLoopApp.prototype.getAutocomplete = function (sQuery, fCallback)
|
||||||
;
|
;
|
||||||
|
|
||||||
RL.remote().suggestions(function (sResult, oData) {
|
RL.remote().suggestions(function (sResult, oData) {
|
||||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result && Utils.isArray(oData.Result.List))
|
if (Enums.StorageResultType.Success === sResult && oData && Utils.isArray(oData.Result))
|
||||||
{
|
{
|
||||||
aData = _.map(oData.Result.List, function (aItem) {
|
aData = _.map(oData.Result, function (aItem) {
|
||||||
return aItem && aItem[0] ? new EmailModel(aItem[0], aItem[1]) : null;
|
return aItem && aItem[0] ? new EmailModel(aItem[0], aItem[1]) : null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -15877,6 +16014,7 @@ RainLoopApp.prototype.getAutocomplete = function (sQuery, fCallback)
|
||||||
{
|
{
|
||||||
fCallback([]);
|
fCallback([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, sQuery);
|
}, sQuery);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -15904,7 +16042,7 @@ RainLoopApp.prototype.bootstart = function ()
|
||||||
bTwitter = RL.settingsGet('AllowTwitterSocial')
|
bTwitter = RL.settingsGet('AllowTwitterSocial')
|
||||||
;
|
;
|
||||||
|
|
||||||
if (!RL.settingsGet('AllowChangePassword'))
|
if (!RL.settingsGet('ChangePasswordIsAllowed'))
|
||||||
{
|
{
|
||||||
Utils.removeSettingsViewModel(SettingsChangePasswordScreen);
|
Utils.removeSettingsViewModel(SettingsChangePasswordScreen);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
rainloop/v/0.0.0/static/js/app.min.js
vendored
14
rainloop/v/0.0.0/static/js/app.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -183,6 +183,17 @@ new a.J;a.La(a.J.Aa);a.b("nativeTemplateEngine",a.J);(function(){a.Ba=function()
|
||||||
new a.w;var b=new a.Ba;0<b.Rb&&a.La(b);a.b("jqueryTmplTemplateEngine",a.Ba)})()})})();})();
|
new a.w;var b=new a.Ba;0<b.Rb&&a.La(b);a.b("jqueryTmplTemplateEngine",a.Ba)})()})})();})();
|
||||||
|
|
||||||
|
|
||||||
|
/*! Knockout projections plugin
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
Copyright (c) Microsoft Corporation
|
||||||
|
All rights reserved.
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||||
|
See the Apache Version 2.0 License for specific language governing permissions and limitations under the License.
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
!function(a){"use strict";function b(a,b,c,d,e,f,g){this.inputItem=b,this.stateArrayIndex=c,this.mapping=e,this.arrayOfState=f,this.outputObservableArray=g,this.outputArray=this.outputObservableArray.peek(),this.isIncluded=null,this.suppressNotification=!1,this.outputArrayIndex=a.observable(d),this.mappedValueComputed=a.computed(this.mappingEvaluator,this),this.mappedValueComputed.subscribe(this.onMappingResultChanged,this),this.previousMappedValue=this.mappedValueComputed.peek()}function c(a,b){if(!a)return null;switch(a.status){case"added":return a.index;case"deleted":return a.index+b;default:throw new Error("Unknown diff status: "+a.status)}}function d(a,c,d,e,f,g,h,i,j){var k="number"==typeof c.moved,l=k?d[c.moved]:new b(a,c.value,e,f,g,h,i);return h.splice(e,0,l),l.isIncluded&&j.splice(f,0,l.mappedValueComputed.peek()),k&&(l.stateArrayIndex=e,l.setOutputArrayIndexSilently(f)),l}function e(a,b,c,d,e){var f=b.splice(c,1)[0];f.isIncluded&&e.splice(d,1),"number"!=typeof a.moved&&f.dispose()}function f(a,b,c){return a.stateArrayIndex=b,a.setOutputArrayIndexSilently(c),c+(a.isIncluded?1:0)}function g(a,b){for(var c={},d=0;d<a.length;d++){var e=a[d];"added"===e.status&&"number"==typeof e.moved&&(c[e.moved]=b[e.moved])}return c}function h(a,b,c){return c.length&&b[a.index]?b[a.index].outputArrayIndex.peek():c.length}function i(a,b,i,j,k,l){return b.subscribe(function(b){if(b.length){for(var m=g(b,i),n=0,o=b[0],p=0,q=o&&h(o,i,j),r=o.index;o||r<i.length;r++)if(c(o,p)===r){switch(o.status){case"added":var s=d(a,o,m,r,q,l,i,k,j);s.isIncluded&&q++,p++;break;case"deleted":e(o,i,r,q,j),p--,r--;break;default:throw new Error("Unknown diff status: "+o.status)}n++,o=b[n]}else r<i.length&&(q=f(i[r],r,q));k.valueHasMutated()}},null,"arrayChange")}function j(a,c){for(var d=this,e=[],f=[],g=a.observableArray(f),h=d.peek(),j=0;j<h.length;j++){var k=h[j],l=new b(a,k,j,f.length,c,e,g),n=l.mappedValueComputed.peek();e.push(l),l.isIncluded&&f.push(n)}var o=i(a,d,e,f,g,c),p=a.computed(g).extend({trackArrayChanges:!0}),q=p.dispose;return p.dispose=function(){o.dispose(),a.utils.arrayForEach(e,function(a){a.dispose()}),q.call(this,arguments)},m(a,p),p}function k(a,b){return j.call(this,a,function(a){return b(a)?a:p})}function l(a){function b(a,b){return function(){return b.apply(this,[a].concat(Array.prototype.slice.call(arguments,0)))}}a[q]={map:b(a,j),filter:b(a,k)}}function m(a,b){return a.utils.extend(b,a[q]),b}function n(a){a.projections={_exclusionMarker:p},l(a),m(a,a.observableArray.fn)}function o(){if("undefined"!=typeof module){var b=require("knockout");n(b),module.exports=b}else"ko"in a&&n(a.ko)}var p={};b.prototype.dispose=function(){this.mappedValueComputed.dispose()},b.prototype.mappingEvaluator=function(){var a=this.mapping(this.inputItem,this.outputArrayIndex),b=a!==p;return this.isIncluded!==b&&(null!==this.isIncluded&&this.moveSubsequentItemsBecauseInclusionStateChanged(b),this.isIncluded=b),a},b.prototype.onMappingResultChanged=function(a){a!==this.previousMappedValue&&(this.isIncluded&&this.outputArray.splice(this.outputArrayIndex.peek(),1,a),this.suppressNotification||this.outputObservableArray.valueHasMutated(),this.previousMappedValue=a)},b.prototype.moveSubsequentItemsBecauseInclusionStateChanged=function(a){var b,c,d=this.outputArrayIndex.peek();if(a)for(this.outputArray.splice(d,0,null),b=this.stateArrayIndex+1;b<this.arrayOfState.length;b++)c=this.arrayOfState[b],c.setOutputArrayIndexSilently(c.outputArrayIndex.peek()+1);else for(this.outputArray.splice(d,1),b=this.stateArrayIndex+1;b<this.arrayOfState.length;b++)c=this.arrayOfState[b],c.setOutputArrayIndexSilently(c.outputArrayIndex.peek()-1)},b.prototype.setOutputArrayIndexSilently=function(a){this.suppressNotification=!0,this.outputArrayIndex(a),this.suppressNotification=!1};var q="_ko.projections.cache";o()}(this);
|
||||||
|
|
||||||
/*! JUA v1.0 MIT */
|
/*! JUA v1.0 MIT */
|
||||||
(function(){function a(a){function l(){if(g&&d<a){var b=g,c=b[0],f=Array.prototype.slice.call(b,1),m=b.index;g===h?g=h=null:g=g.next,++d,f.push(function(a,b){--d;if(i)return;a?e&&k(i=a,e=j=g=h=null):(j[m]=b,--e?l():k(null,j))}),c.apply(null,f)}}var c={},d=0,e=0,f=-1,g,h,i=null,j=[],k=b;return arguments.length<1&&(a=Infinity),c.defer=function(){if(!i){var a=arguments;a.index=++f,h?(h.next=a,h=h.next):g=h=a,++e,l()}return c},c.await=function(a){return k=a,e||k(i,j),c},c}function b(){}typeof module=="undefined"?self.queue=a:module.exports=a,a.version="0.0.2"})();var e=!0,f=null,g=!1,j,k=jQuery,l=window,m=queue;function n(a){return"undefined"===typeof a}function r(a){0<a&&clearTimeout(a)}function u(a){a=a&&(a.originalEvent?a.originalEvent:a)||l.event;return a.dataTransfer?a:f}function v(a,b,c){return!a||!b||n(a[b])?c:a[b]}function y(){for(var a=16,b="",a=n(a)?32:parseInt(a||0,10);b.length<a;)b+="0123456789abcdefghijklmnopqrstuvwxyz".substr(Math.round(36*Math.random()),1);return"jua-uid-"+b+"-"+(new Date).getTime().toString()}
|
(function(){function a(a){function l(){if(g&&d<a){var b=g,c=b[0],f=Array.prototype.slice.call(b,1),m=b.index;g===h?g=h=null:g=g.next,++d,f.push(function(a,b){--d;if(i)return;a?e&&k(i=a,e=j=g=h=null):(j[m]=b,--e?l():k(null,j))}),c.apply(null,f)}}var c={},d=0,e=0,f=-1,g,h,i=null,j=[],k=b;return arguments.length<1&&(a=Infinity),c.defer=function(){if(!i){var a=arguments;a.index=++f,h?(h.next=a,h=h.next):g=h=a,++e,l()}return c},c.await=function(a){return k=a,e||k(i,j),c},c}function b(){}typeof module=="undefined"?self.queue=a:module.exports=a,a.version="0.0.2"})();var e=!0,f=null,g=!1,j,k=jQuery,l=window,m=queue;function n(a){return"undefined"===typeof a}function r(a){0<a&&clearTimeout(a)}function u(a){a=a&&(a.originalEvent?a.originalEvent:a)||l.event;return a.dataTransfer?a:f}function v(a,b,c){return!a||!b||n(a[b])?c:a[b]}function y(){for(var a=16,b="",a=n(a)?32:parseInt(a||0,10);b.length<a;)b+="0123456789abcdefghijklmnopqrstuvwxyz".substr(Math.round(36*Math.random()),1);return"jua-uid-"+b+"-"+(new Date).getTime().toString()}
|
||||||
function z(a,b){return{FileName:n(a.fileName)?n(a.name)?f:a.name:a.fileName,Size:n(a.fileSize)?n(a.size)?f:a.size:a.fileSize,Type:n(a.type)?f:a.type,Folder:n(b)?"":b,File:a}}
|
function z(a,b){return{FileName:n(a.fileName)?n(a.name)?f:a.name:a.fileName,Size:n(a.fileSize)?n(a.size)?f:a.size:a.fileSize,Type:n(a.type)?f:a.type,Folder:n(b)?"":b,File:a}}
|
||||||
|
|
|
||||||
115
vendors/knockout-projections/README.md
vendored
Normal file
115
vendors/knockout-projections/README.md
vendored
Normal file
|
|
@ -0,0 +1,115 @@
|
||||||
|
knockout-projections
|
||||||
|
============
|
||||||
|
|
||||||
|
Knockout.js observable arrays get smarter.
|
||||||
|
|
||||||
|
This plugin adds observable `map` and `filter` features to observable arrays, so you can transform collections in arbitrary ways and have the results automatically update whenever the underlying source data changes.
|
||||||
|
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
Download a copy of `knockout-projections-x.y.z.js` from [the `dist` directory](https://github.com/SteveSanderson/knockout-projections/tree/master/dist) and reference it in your web application:
|
||||||
|
|
||||||
|
<script src='knockout-x.y.z.js'></script> <!-- First reference KO itself -->
|
||||||
|
<script src='knockout-projections-x.y.z.js'></script> <!-- Then reference knockout-projections -->
|
||||||
|
|
||||||
|
Be sure to reference it *after* you reference Knockout itself, and of course replace `x.y.z` with the version number of the file you downloaded.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
=====
|
||||||
|
|
||||||
|
**Mapping**
|
||||||
|
|
||||||
|
More info to follow. For now, here's a simple example:
|
||||||
|
|
||||||
|
var sourceItems = ko.observableArray([1, 2, 3, 4, 5]);
|
||||||
|
|
||||||
|
There's a plain observable array. Now let's say we want to keep track of the squares of these values:
|
||||||
|
|
||||||
|
var squares = sourceItems.map(function(x) { return x*x; });
|
||||||
|
|
||||||
|
Now `squares` is an observable array containing `[1, 4, 9, 16, 25]`. Let's modify the source data:
|
||||||
|
|
||||||
|
sourceItems.push(6);
|
||||||
|
// 'squares' has automatically updated and now contains [1, 4, 9, 16, 25, 36]
|
||||||
|
|
||||||
|
This works with any transformation of the source data, e.g.:
|
||||||
|
|
||||||
|
sourceItems.reverse();
|
||||||
|
// 'squares' now contains [36, 25, 16, 9, 4, 1]
|
||||||
|
|
||||||
|
The key point of this library is that these transformations are done *efficiently*. Specifically, your callback
|
||||||
|
function that performs the mapping is only called when strictly necessary (usually, that's only for newly-added
|
||||||
|
items). When you add new items to the source data, we *don't* need to re-map the existing ones. When you reorder
|
||||||
|
the source data, the output order is correspondingly changed *without* remapping anything.
|
||||||
|
|
||||||
|
This efficiency might not matter much if you're just squaring numbers, but when you are mapping complex nested
|
||||||
|
graphs of custom objects, it can be important to perform each mapping update with the minumum of work.
|
||||||
|
|
||||||
|
**Filtering**
|
||||||
|
|
||||||
|
As well as `map`, this plugin also provides `filter`:
|
||||||
|
|
||||||
|
var evenSquares = squares.filter(function(x) { return x % 2 === 0; });
|
||||||
|
// evenSquares is now an observable containing [36, 16, 4]
|
||||||
|
|
||||||
|
sourceItems.push(9);
|
||||||
|
// This has no effect on evenSquares, because 9*9=81 is odd
|
||||||
|
|
||||||
|
sourceItems.push(10);
|
||||||
|
// evenSquares now contains [36, 16, 4, 100]
|
||||||
|
|
||||||
|
Again, your `filter` callbacks are only called when strictly necessary. Re-ordering or deleting source items don't
|
||||||
|
require any refiltering - the output is simply updated to match. Only newly-added source items must be subjected
|
||||||
|
to your `filter` callback.
|
||||||
|
|
||||||
|
**Chaining**
|
||||||
|
|
||||||
|
The above code also demonstrates that you can chain together successive `map` and `filter` transformations.
|
||||||
|
|
||||||
|
When the underlying data changes, the effects will ripple out through the chain of computed arrays with the
|
||||||
|
minimum necessary invocation of your `map` and `filter` callbacks.
|
||||||
|
|
||||||
|
How to build from source
|
||||||
|
========================
|
||||||
|
|
||||||
|
First, install [NPM](https://npmjs.org/) if you don't already have it. It comes with Node.js.
|
||||||
|
|
||||||
|
Second, install Grunt globally, if you don't already have it:
|
||||||
|
|
||||||
|
npm install -g grunt-cli
|
||||||
|
|
||||||
|
Third, use NPM to download all the dependencies for this module:
|
||||||
|
|
||||||
|
cd wherever_you_cloned_this_repo
|
||||||
|
npm install
|
||||||
|
|
||||||
|
Now you can build the package (linting and running tests along the way):
|
||||||
|
|
||||||
|
grunt
|
||||||
|
|
||||||
|
Or you can just run the linting tool and tests:
|
||||||
|
|
||||||
|
grunt test
|
||||||
|
|
||||||
|
Or you can make Grunt watch for changes to the sources/specs and auto-rebuild after each change:
|
||||||
|
|
||||||
|
grunt watch
|
||||||
|
|
||||||
|
The browser-ready output files will be dumped at the following locations:
|
||||||
|
|
||||||
|
* `dist/knockout-projections.js`
|
||||||
|
* `dist/knockout-projections.min.js`
|
||||||
|
|
||||||
|
License - Apache 2.0
|
||||||
|
====================
|
||||||
|
|
||||||
|
Copyright (c) Microsoft Corporation
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||||
|
|
||||||
|
See the Apache Version 2.0 License for specific language governing permissions and limitations under the License.
|
||||||
342
vendors/knockout-projections/knockout-projections-1.0.0.js
vendored
Normal file
342
vendors/knockout-projections/knockout-projections-1.0.0.js
vendored
Normal file
|
|
@ -0,0 +1,342 @@
|
||||||
|
/*! Knockout projections plugin
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
Copyright (c) Microsoft Corporation
|
||||||
|
All rights reserved.
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||||
|
See the Apache Version 2.0 License for specific language governing permissions and limitations under the License.
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
(function(global, undefined) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var exclusionMarker = {};
|
||||||
|
|
||||||
|
function StateItem(ko, inputItem, initialStateArrayIndex, initialOutputArrayIndex, mapping, arrayOfState, outputObservableArray) {
|
||||||
|
// Capture state for later use
|
||||||
|
this.inputItem = inputItem;
|
||||||
|
this.stateArrayIndex = initialStateArrayIndex;
|
||||||
|
this.mapping = mapping;
|
||||||
|
this.arrayOfState = arrayOfState;
|
||||||
|
this.outputObservableArray = outputObservableArray;
|
||||||
|
this.outputArray = this.outputObservableArray.peek();
|
||||||
|
this.isIncluded = null; // Means 'not yet determined'
|
||||||
|
this.suppressNotification = false; // TODO: Instead of this technique, consider raising a sparse diff with a "mutated" entry when a single item changes, and not having any other change logic inside StateItem
|
||||||
|
|
||||||
|
// Set up observables
|
||||||
|
this.outputArrayIndex = ko.observable(initialOutputArrayIndex); // When excluded, it's the position the item would go if it became included
|
||||||
|
this.mappedValueComputed = ko.computed(this.mappingEvaluator, this);
|
||||||
|
this.mappedValueComputed.subscribe(this.onMappingResultChanged, this);
|
||||||
|
this.previousMappedValue = this.mappedValueComputed.peek();
|
||||||
|
}
|
||||||
|
|
||||||
|
StateItem.prototype.dispose = function() {
|
||||||
|
this.mappedValueComputed.dispose();
|
||||||
|
};
|
||||||
|
|
||||||
|
StateItem.prototype.mappingEvaluator = function() {
|
||||||
|
var mappedValue = this.mapping(this.inputItem, this.outputArrayIndex),
|
||||||
|
newInclusionState = mappedValue !== exclusionMarker;
|
||||||
|
|
||||||
|
// Inclusion state changes can *only* happen as a result of changing an individual item.
|
||||||
|
// Structural changes to the array can't cause this (because they don't cause any remapping;
|
||||||
|
// they only map newly added items which have no earlier inclusion state to change).
|
||||||
|
if (this.isIncluded !== newInclusionState) {
|
||||||
|
if (this.isIncluded !== null) { // i.e., not first run
|
||||||
|
this.moveSubsequentItemsBecauseInclusionStateChanged(newInclusionState);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isIncluded = newInclusionState;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mappedValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
StateItem.prototype.onMappingResultChanged = function(newValue) {
|
||||||
|
if (newValue !== this.previousMappedValue) {
|
||||||
|
if (this.isIncluded) {
|
||||||
|
this.outputArray.splice(this.outputArrayIndex.peek(), 1, newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.suppressNotification) {
|
||||||
|
this.outputObservableArray.valueHasMutated();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.previousMappedValue = newValue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
StateItem.prototype.moveSubsequentItemsBecauseInclusionStateChanged = function(newInclusionState) {
|
||||||
|
var outputArrayIndex = this.outputArrayIndex.peek(),
|
||||||
|
iterationIndex,
|
||||||
|
stateItem;
|
||||||
|
|
||||||
|
if (newInclusionState) {
|
||||||
|
// Shift all subsequent items along by one space, and increment their indexes.
|
||||||
|
// Note that changing their indexes might cause remapping, but won't affect their
|
||||||
|
// inclusion status (by definition, inclusion status must not be affected by index,
|
||||||
|
// otherwise you get undefined results) so there's no risk of a chain reaction.
|
||||||
|
this.outputArray.splice(outputArrayIndex, 0, null);
|
||||||
|
for (iterationIndex = this.stateArrayIndex + 1; iterationIndex < this.arrayOfState.length; iterationIndex++) {
|
||||||
|
stateItem = this.arrayOfState[iterationIndex];
|
||||||
|
stateItem.setOutputArrayIndexSilently(stateItem.outputArrayIndex.peek() + 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Shift all subsequent items back by one space, and decrement their indexes
|
||||||
|
this.outputArray.splice(outputArrayIndex, 1);
|
||||||
|
for (iterationIndex = this.stateArrayIndex + 1; iterationIndex < this.arrayOfState.length; iterationIndex++) {
|
||||||
|
stateItem = this.arrayOfState[iterationIndex];
|
||||||
|
stateItem.setOutputArrayIndexSilently(stateItem.outputArrayIndex.peek() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
StateItem.prototype.setOutputArrayIndexSilently = function(newIndex) {
|
||||||
|
// We only want to raise one output array notification per input array change,
|
||||||
|
// so during processing, we suppress notifications
|
||||||
|
this.suppressNotification = true;
|
||||||
|
this.outputArrayIndex(newIndex);
|
||||||
|
this.suppressNotification = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
function getDiffEntryPostOperationIndex(diffEntry, editOffset) {
|
||||||
|
// The diff algorithm's "index" value refers to the output array for additions,
|
||||||
|
// but the "input" array for deletions. Get the output array position.
|
||||||
|
if (!diffEntry) { return null; }
|
||||||
|
switch (diffEntry.status) {
|
||||||
|
case 'added':
|
||||||
|
return diffEntry.index;
|
||||||
|
case 'deleted':
|
||||||
|
return diffEntry.index + editOffset;
|
||||||
|
default:
|
||||||
|
throw new Error('Unknown diff status: ' + diffEntry.status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertOutputItem(ko, diffEntry, movedStateItems, stateArrayIndex, outputArrayIndex, mapping, arrayOfState, outputObservableArray, outputArray) {
|
||||||
|
// Retain the existing mapped value if this is a move, otherwise perform mapping
|
||||||
|
var isMoved = typeof diffEntry.moved === 'number',
|
||||||
|
stateItem = isMoved ?
|
||||||
|
movedStateItems[diffEntry.moved] :
|
||||||
|
new StateItem(ko, diffEntry.value, stateArrayIndex, outputArrayIndex, mapping, arrayOfState, outputObservableArray);
|
||||||
|
arrayOfState.splice(stateArrayIndex, 0, stateItem);
|
||||||
|
if (stateItem.isIncluded) {
|
||||||
|
outputArray.splice(outputArrayIndex, 0, stateItem.mappedValueComputed.peek());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update indexes
|
||||||
|
if (isMoved) {
|
||||||
|
// We don't change the index until *after* updating this item's position in outputObservableArray,
|
||||||
|
// because changing the index may trigger re-mapping, which in turn would cause the new
|
||||||
|
// value to be written to the 'index' position in the output array
|
||||||
|
stateItem.stateArrayIndex = stateArrayIndex;
|
||||||
|
stateItem.setOutputArrayIndexSilently(outputArrayIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return stateItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteOutputItem(diffEntry, arrayOfState, stateArrayIndex, outputArrayIndex, outputArray) {
|
||||||
|
var stateItem = arrayOfState.splice(stateArrayIndex, 1)[0];
|
||||||
|
if (stateItem.isIncluded) {
|
||||||
|
outputArray.splice(outputArrayIndex, 1);
|
||||||
|
}
|
||||||
|
if (typeof diffEntry.moved !== 'number') {
|
||||||
|
// Be careful to dispose only if this item really was deleted and not moved
|
||||||
|
stateItem.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateRetainedOutputItem(stateItem, stateArrayIndex, outputArrayIndex) {
|
||||||
|
// Just have to update its indexes
|
||||||
|
stateItem.stateArrayIndex = stateArrayIndex;
|
||||||
|
stateItem.setOutputArrayIndexSilently(outputArrayIndex);
|
||||||
|
|
||||||
|
// Return the new value for outputArrayIndex
|
||||||
|
return outputArrayIndex + (stateItem.isIncluded ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeLookupOfMovedStateItems(diff, arrayOfState) {
|
||||||
|
// Before we mutate arrayOfComputedMappedValues at all, grab a reference to each moved item
|
||||||
|
var movedStateItems = {};
|
||||||
|
for (var diffIndex = 0; diffIndex < diff.length; diffIndex++) {
|
||||||
|
var diffEntry = diff[diffIndex];
|
||||||
|
if (diffEntry.status === 'added' && (typeof diffEntry.moved === 'number')) {
|
||||||
|
movedStateItems[diffEntry.moved] = arrayOfState[diffEntry.moved];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return movedStateItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFirstModifiedOutputIndex(firstDiffEntry, arrayOfState, outputArray) {
|
||||||
|
// Work out where the first edit will affect the output array
|
||||||
|
// Then we can update outputArrayIndex incrementally while walking the diff list
|
||||||
|
if (!outputArray.length || !arrayOfState[firstDiffEntry.index]) {
|
||||||
|
// The first edit is beyond the end of the output or state array, so we must
|
||||||
|
// just be appending items.
|
||||||
|
return outputArray.length;
|
||||||
|
} else {
|
||||||
|
// The first edit corresponds to an existing state array item, so grab
|
||||||
|
// the first output array index from it.
|
||||||
|
return arrayOfState[firstDiffEntry.index].outputArrayIndex.peek();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function respondToArrayStructuralChanges(ko, inputObservableArray, arrayOfState, outputArray, outputObservableArray, mapping) {
|
||||||
|
return inputObservableArray.subscribe(function(diff) {
|
||||||
|
if (!diff.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var movedStateItems = makeLookupOfMovedStateItems(diff, arrayOfState),
|
||||||
|
diffIndex = 0,
|
||||||
|
diffEntry = diff[0],
|
||||||
|
editOffset = 0, // A running total of (num(items added) - num(items deleted)) not accounting for filtering
|
||||||
|
outputArrayIndex = diffEntry && getFirstModifiedOutputIndex(diffEntry, arrayOfState, outputArray);
|
||||||
|
|
||||||
|
// Now iterate over the state array, at each stage checking whether the current item
|
||||||
|
// is the next one to have been edited. We can skip all the state array items whose
|
||||||
|
// indexes are less than the first edit index (i.e., diff[0].index).
|
||||||
|
for (var stateArrayIndex = diffEntry.index; diffEntry || (stateArrayIndex < arrayOfState.length); stateArrayIndex++) {
|
||||||
|
// Does the current diffEntry correspond to this position in the state array?
|
||||||
|
if (getDiffEntryPostOperationIndex(diffEntry, editOffset) === stateArrayIndex) {
|
||||||
|
// Yes - insert or delete the corresponding state and output items
|
||||||
|
switch (diffEntry.status) {
|
||||||
|
case 'added':
|
||||||
|
// Add to output, and update indexes
|
||||||
|
var stateItem = insertOutputItem(ko, diffEntry, movedStateItems, stateArrayIndex, outputArrayIndex, mapping, arrayOfState, outputObservableArray, outputArray);
|
||||||
|
if (stateItem.isIncluded) {
|
||||||
|
outputArrayIndex++;
|
||||||
|
}
|
||||||
|
editOffset++;
|
||||||
|
break;
|
||||||
|
case 'deleted':
|
||||||
|
// Just erase from the output, and update indexes
|
||||||
|
deleteOutputItem(diffEntry, arrayOfState, stateArrayIndex, outputArrayIndex, outputArray);
|
||||||
|
editOffset--;
|
||||||
|
stateArrayIndex--; // To compensate for the "for" loop incrementing it
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error('Unknown diff status: ' + diffEntry.status);
|
||||||
|
}
|
||||||
|
|
||||||
|
// We're done with this diff entry. Move on to the next one.
|
||||||
|
diffIndex++;
|
||||||
|
diffEntry = diff[diffIndex];
|
||||||
|
} else if (stateArrayIndex < arrayOfState.length) {
|
||||||
|
// No - the current item was retained. Just update its index.
|
||||||
|
outputArrayIndex = updateRetainedOutputItem(arrayOfState[stateArrayIndex], stateArrayIndex, outputArrayIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
outputObservableArray.valueHasMutated();
|
||||||
|
}, null, 'arrayChange');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mapping
|
||||||
|
function observableArrayMap(ko, mapping) {
|
||||||
|
var inputObservableArray = this,
|
||||||
|
arrayOfState = [],
|
||||||
|
outputArray = [],
|
||||||
|
outputObservableArray = ko.observableArray(outputArray),
|
||||||
|
originalInputArrayContents = inputObservableArray.peek();
|
||||||
|
|
||||||
|
// Initial state: map each of the inputs
|
||||||
|
for (var i = 0; i < originalInputArrayContents.length; i++) {
|
||||||
|
var inputItem = originalInputArrayContents[i],
|
||||||
|
stateItem = new StateItem(ko, inputItem, i, outputArray.length, mapping, arrayOfState, outputObservableArray),
|
||||||
|
mappedValue = stateItem.mappedValueComputed.peek();
|
||||||
|
arrayOfState.push(stateItem);
|
||||||
|
|
||||||
|
if (stateItem.isIncluded) {
|
||||||
|
outputArray.push(mappedValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the input array changes structurally (items added or removed), update the outputs
|
||||||
|
var inputArraySubscription = respondToArrayStructuralChanges(ko, inputObservableArray, arrayOfState, outputArray, outputObservableArray, mapping);
|
||||||
|
|
||||||
|
// Return value is a readonly computed which can track its own changes to permit chaining.
|
||||||
|
// When disposed, it cleans up everything it created.
|
||||||
|
var returnValue = ko.computed(outputObservableArray).extend({ trackArrayChanges: true }),
|
||||||
|
originalDispose = returnValue.dispose;
|
||||||
|
returnValue.dispose = function() {
|
||||||
|
inputArraySubscription.dispose();
|
||||||
|
ko.utils.arrayForEach(arrayOfState, function(stateItem) {
|
||||||
|
stateItem.dispose();
|
||||||
|
});
|
||||||
|
originalDispose.call(this, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Make projections chainable
|
||||||
|
addProjectionFunctions(ko, returnValue);
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filtering
|
||||||
|
function observableArrayFilter(ko, predicate) {
|
||||||
|
return observableArrayMap.call(this, ko, function(item) {
|
||||||
|
return predicate(item) ? item : exclusionMarker;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attaching projection functions
|
||||||
|
// ------------------------------
|
||||||
|
//
|
||||||
|
// Builds a collection of projection functions that can quickly be attached to any object.
|
||||||
|
// The functions are predefined to retain 'this' and prefix the arguments list with the
|
||||||
|
// relevant 'ko' instance.
|
||||||
|
|
||||||
|
var projectionFunctionsCacheName = '_ko.projections.cache';
|
||||||
|
|
||||||
|
function attachProjectionFunctionsCache(ko) {
|
||||||
|
// Wraps callback so that, when invoked, its arguments list is prefixed by 'ko' and 'this'
|
||||||
|
function makeCaller(ko, callback) {
|
||||||
|
return function() {
|
||||||
|
return callback.apply(this, [ko].concat(Array.prototype.slice.call(arguments, 0)));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
ko[projectionFunctionsCacheName] = {
|
||||||
|
map: makeCaller(ko, observableArrayMap),
|
||||||
|
filter: makeCaller(ko, observableArrayFilter)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function addProjectionFunctions(ko, target) {
|
||||||
|
ko.utils.extend(target, ko[projectionFunctionsCacheName]);
|
||||||
|
return target; // Enable chaining
|
||||||
|
}
|
||||||
|
|
||||||
|
// Module initialisation
|
||||||
|
// ---------------------
|
||||||
|
//
|
||||||
|
// When this script is first evaluated, it works out what kind of module loading scenario
|
||||||
|
// it is in (Node.js or a browser `<script>` tag), and then attaches itself to whichever
|
||||||
|
// instance of Knockout.js it can find.
|
||||||
|
|
||||||
|
function attachToKo(ko) {
|
||||||
|
ko.projections = {
|
||||||
|
_exclusionMarker: exclusionMarker
|
||||||
|
};
|
||||||
|
attachProjectionFunctionsCache(ko);
|
||||||
|
addProjectionFunctions(ko, ko.observableArray.fn); // Make all observable arrays projectable
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determines which module loading scenario we're in, grabs dependencies, and attaches to KO
|
||||||
|
function prepareExports() {
|
||||||
|
if (typeof module !== 'undefined') {
|
||||||
|
// Node.js case - load KO synchronously
|
||||||
|
var ko = require('knockout');
|
||||||
|
attachToKo(ko);
|
||||||
|
module.exports = ko;
|
||||||
|
} else if ('ko' in global) {
|
||||||
|
// Non-module case - attach to the global instance
|
||||||
|
attachToKo(global.ko);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prepareExports();
|
||||||
|
|
||||||
|
})(this);
|
||||||
10
vendors/knockout-projections/knockout-projections-1.0.0.min.js
vendored
Normal file
10
vendors/knockout-projections/knockout-projections-1.0.0.min.js
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
/*! Knockout projections plugin
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
Copyright (c) Microsoft Corporation
|
||||||
|
All rights reserved.
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||||
|
See the Apache Version 2.0 License for specific language governing permissions and limitations under the License.
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
!function(a){"use strict";function b(a,b,c,d,e,f,g){this.inputItem=b,this.stateArrayIndex=c,this.mapping=e,this.arrayOfState=f,this.outputObservableArray=g,this.outputArray=this.outputObservableArray.peek(),this.isIncluded=null,this.suppressNotification=!1,this.outputArrayIndex=a.observable(d),this.mappedValueComputed=a.computed(this.mappingEvaluator,this),this.mappedValueComputed.subscribe(this.onMappingResultChanged,this),this.previousMappedValue=this.mappedValueComputed.peek()}function c(a,b){if(!a)return null;switch(a.status){case"added":return a.index;case"deleted":return a.index+b;default:throw new Error("Unknown diff status: "+a.status)}}function d(a,c,d,e,f,g,h,i,j){var k="number"==typeof c.moved,l=k?d[c.moved]:new b(a,c.value,e,f,g,h,i);return h.splice(e,0,l),l.isIncluded&&j.splice(f,0,l.mappedValueComputed.peek()),k&&(l.stateArrayIndex=e,l.setOutputArrayIndexSilently(f)),l}function e(a,b,c,d,e){var f=b.splice(c,1)[0];f.isIncluded&&e.splice(d,1),"number"!=typeof a.moved&&f.dispose()}function f(a,b,c){return a.stateArrayIndex=b,a.setOutputArrayIndexSilently(c),c+(a.isIncluded?1:0)}function g(a,b){for(var c={},d=0;d<a.length;d++){var e=a[d];"added"===e.status&&"number"==typeof e.moved&&(c[e.moved]=b[e.moved])}return c}function h(a,b,c){return c.length&&b[a.index]?b[a.index].outputArrayIndex.peek():c.length}function i(a,b,i,j,k,l){return b.subscribe(function(b){if(b.length){for(var m=g(b,i),n=0,o=b[0],p=0,q=o&&h(o,i,j),r=o.index;o||r<i.length;r++)if(c(o,p)===r){switch(o.status){case"added":var s=d(a,o,m,r,q,l,i,k,j);s.isIncluded&&q++,p++;break;case"deleted":e(o,i,r,q,j),p--,r--;break;default:throw new Error("Unknown diff status: "+o.status)}n++,o=b[n]}else r<i.length&&(q=f(i[r],r,q));k.valueHasMutated()}},null,"arrayChange")}function j(a,c){for(var d=this,e=[],f=[],g=a.observableArray(f),h=d.peek(),j=0;j<h.length;j++){var k=h[j],l=new b(a,k,j,f.length,c,e,g),n=l.mappedValueComputed.peek();e.push(l),l.isIncluded&&f.push(n)}var o=i(a,d,e,f,g,c),p=a.computed(g).extend({trackArrayChanges:!0}),q=p.dispose;return p.dispose=function(){o.dispose(),a.utils.arrayForEach(e,function(a){a.dispose()}),q.call(this,arguments)},m(a,p),p}function k(a,b){return j.call(this,a,function(a){return b(a)?a:p})}function l(a){function b(a,b){return function(){return b.apply(this,[a].concat(Array.prototype.slice.call(arguments,0)))}}a[q]={map:b(a,j),filter:b(a,k)}}function m(a,b){return a.utils.extend(b,a[q]),b}function n(a){a.projections={_exclusionMarker:p},l(a),m(a,a.observableArray.fn)}function o(){if("undefined"!=typeof module){var b=require("knockout");n(b),module.exports=b}else"ko"in a&&n(a.ko)}var p={};b.prototype.dispose=function(){this.mappedValueComputed.dispose()},b.prototype.mappingEvaluator=function(){var a=this.mapping(this.inputItem,this.outputArrayIndex),b=a!==p;return this.isIncluded!==b&&(null!==this.isIncluded&&this.moveSubsequentItemsBecauseInclusionStateChanged(b),this.isIncluded=b),a},b.prototype.onMappingResultChanged=function(a){a!==this.previousMappedValue&&(this.isIncluded&&this.outputArray.splice(this.outputArrayIndex.peek(),1,a),this.suppressNotification||this.outputObservableArray.valueHasMutated(),this.previousMappedValue=a)},b.prototype.moveSubsequentItemsBecauseInclusionStateChanged=function(a){var b,c,d=this.outputArrayIndex.peek();if(a)for(this.outputArray.splice(d,0,null),b=this.stateArrayIndex+1;b<this.arrayOfState.length;b++)c=this.arrayOfState[b],c.setOutputArrayIndexSilently(c.outputArrayIndex.peek()+1);else for(this.outputArray.splice(d,1),b=this.stateArrayIndex+1;b<this.arrayOfState.length;b++)c=this.arrayOfState[b],c.setOutputArrayIndexSilently(c.outputArrayIndex.peek()-1)},b.prototype.setOutputArrayIndexSilently=function(a){this.suppressNotification=!0,this.outputArrayIndex(a),this.suppressNotification=!1};var q="_ko.projections.cache";o()}(this);
|
||||||
29
vendors/knockout-projections/package.json
vendored
Normal file
29
vendors/knockout-projections/package.json
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"name": "knockout-projections",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Knockout.js observable arrays get smarter",
|
||||||
|
"main": "knockout-projections.js",
|
||||||
|
"directories": {
|
||||||
|
"test": "test"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"knockout": "~3.0.0",
|
||||||
|
"jasmine-reporters": "~0.2.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"grunt": "~0.4.1",
|
||||||
|
"grunt-contrib-jshint": "~0.4.3",
|
||||||
|
"grunt-contrib-uglify": "~0.2.0",
|
||||||
|
"grunt-contrib-concat": "~0.3.0",
|
||||||
|
"grunt-contrib-watch": "~0.4.3",
|
||||||
|
"grunt-jasmine-node": "~0.1.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": "",
|
||||||
|
"author": "Microsoft Corporation",
|
||||||
|
"licenses" : [
|
||||||
|
{ "type" : "Apache 2.0", "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" }
|
||||||
|
]
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue