mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-06-30 07:46:27 +00:00
Merge new-contacts-api
New interface Contact storage move to plugin
This commit is contained in:
@@ -13,7 +13,7 @@ function MailBoxFolderListViewModel()
|
||||
|
||||
this.iDropOverTimer = 0;
|
||||
|
||||
this.allowContacts = !!RL.settingsGet('ContactsIsSupported') && !!RL.settingsGet('ContactsIsAllowed');
|
||||
this.allowContacts = !!RL.settingsGet('ContactsIsAllowed');
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('MailBoxFolderListViewModel', MailBoxFolderListViewModel);
|
||||
|
||||
@@ -497,7 +497,7 @@ PopupsComposeViewModel.prototype.sendMessageResponse = function (sResult, oData)
|
||||
else
|
||||
{
|
||||
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,12 +8,22 @@ function PopupsContactsViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsContacts');
|
||||
|
||||
var self = this;
|
||||
var
|
||||
self = this,
|
||||
aNameTypes = [Enums.ContactPropertyType.FullName, Enums.ContactPropertyType.FirstName, Enums.ContactPropertyType.SurName, Enums.ContactPropertyType.MiddleName],
|
||||
aEmailTypes = [Enums.ContactPropertyType.EmailPersonal, Enums.ContactPropertyType.EmailBussines, Enums.ContactPropertyType.EmailOther],
|
||||
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.imageUploader = ko.observable(null);
|
||||
this.imageDom = ko.observable(null);
|
||||
this.imageTrigger = ko.observable(false);
|
||||
|
||||
this.search = ko.observable('');
|
||||
this.contacts = ko.observableArray([]);
|
||||
this.contacts.loading = ko.observable(false).extend({'throttle': 200});
|
||||
@@ -23,11 +33,50 @@ function PopupsContactsViewModel()
|
||||
this.viewClearSearch = ko.observable(false);
|
||||
|
||||
this.viewID = ko.observable('');
|
||||
this.viewName = ko.observable('');
|
||||
this.viewName.focused = ko.observable(false);
|
||||
this.viewEmail = ko.observable('').validateEmail();
|
||||
this.viewEmail.focused = ko.observable(false);
|
||||
this.viewImageUrl = ko.observable(RL.link().emptyContactPic());
|
||||
this.viewProperties = ko.observableArray([]);
|
||||
|
||||
this.viewPropertiesNames = this.viewProperties.filter(function(oProperty) {
|
||||
return -1 < Utils.inArray(oProperty.type(), aNameTypes);
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
@@ -41,8 +90,8 @@ function PopupsContactsViewModel()
|
||||
Utils.windowResize();
|
||||
}, this);
|
||||
|
||||
this.viewImageUrl.subscribe(function (sUrl) {
|
||||
this.imageDom()['src'] = sUrl;
|
||||
this.viewProperties.subscribe(function () {
|
||||
Utils.windowResize();
|
||||
}, this);
|
||||
|
||||
this.contactsChecked = ko.computed(function () {
|
||||
@@ -103,22 +152,26 @@ function PopupsContactsViewModel()
|
||||
if (Utils.isNonEmptyArray(aC))
|
||||
{
|
||||
aE = _.map(aC, function (oItem) {
|
||||
if (oItem && oItem['emails'])
|
||||
if (oItem)
|
||||
{
|
||||
var oEmail = new EmailModel(oItem['emails'][0] || '', oItem['name']);
|
||||
if (oEmail.validate())
|
||||
var
|
||||
aData = oItem.getNameAndEmailHelper(),
|
||||
oEmail = aData ? new EmailModel(aData[0], aData[1]) : null
|
||||
;
|
||||
|
||||
if (oEmail && oEmail.validate())
|
||||
{
|
||||
return oEmail;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
aE = _.compact(aE);
|
||||
}
|
||||
|
||||
if (Utils.isNonEmptyArray(aC))
|
||||
if (Utils.isNonEmptyArray(aE))
|
||||
{
|
||||
kn.hideScreenPopup(PopupsContactsViewModel);
|
||||
kn.showScreenPopup(PopupsComposeViewModel, [Enums.ComposeType.Empty, null, aE]);
|
||||
@@ -133,12 +186,21 @@ function PopupsContactsViewModel()
|
||||
});
|
||||
|
||||
this.saveCommand = Utils.createCommand(this, function () {
|
||||
var
|
||||
|
||||
this.viewSaving(true);
|
||||
|
||||
var
|
||||
sRequestUid = Utils.fakeMd5(),
|
||||
bImageTrigger = this.imageTrigger()
|
||||
aProperties = []
|
||||
;
|
||||
|
||||
this.viewSaving(true);
|
||||
_.each(this.viewProperties(), function (oItem) {
|
||||
if (oItem.type() && '' !== Utils.trim(oItem.value()))
|
||||
{
|
||||
aProperties.push([oItem.type(), oItem.value()]);
|
||||
}
|
||||
});
|
||||
|
||||
RL.remote().contactSave(function (sResult, oData) {
|
||||
|
||||
self.viewSaving(false);
|
||||
@@ -151,31 +213,42 @@ function PopupsContactsViewModel()
|
||||
}
|
||||
|
||||
self.reloadContactList();
|
||||
if (bImageTrigger)
|
||||
{
|
||||
RL.emailsPicsHashes();
|
||||
}
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// // TODO
|
||||
// }
|
||||
|
||||
}, sRequestUid, this.viewID(), this.viewName(), this.viewEmail(), bImageTrigger ? this.imageDom()['src'] : '');
|
||||
}, sRequestUid, this.viewID(), aProperties);
|
||||
|
||||
}, function () {
|
||||
var
|
||||
sViewName = this.viewName(),
|
||||
sViewEmail = this.viewEmail()
|
||||
;
|
||||
|
||||
return !this.viewSaving() &&
|
||||
('' !== sViewName || '' !== sViewEmail);
|
||||
var bV = this.viewHasNonEmptyRequaredProperties();
|
||||
return !this.viewSaving() && bV;
|
||||
});
|
||||
}
|
||||
|
||||
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 ()
|
||||
{
|
||||
var
|
||||
@@ -241,28 +314,51 @@ PopupsContactsViewModel.prototype.deleteResponse = function (sResult, oData)
|
||||
}
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.removeProperty = function (oProp)
|
||||
{
|
||||
this.viewProperties.remove(oProp);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {?ContactModel} oContact
|
||||
*/
|
||||
PopupsContactsViewModel.prototype.populateViewContact = function (oContact)
|
||||
{
|
||||
this.imageTrigger(false);
|
||||
var
|
||||
sId = '',
|
||||
bHasName = false,
|
||||
aList = []
|
||||
;
|
||||
|
||||
this.emptySelection(false);
|
||||
|
||||
if (oContact)
|
||||
{
|
||||
this.viewID(oContact.idContact);
|
||||
this.viewName(oContact.name);
|
||||
this.viewEmail(oContact.emails[0] || '');
|
||||
this.viewImageUrl(oContact.srcAttr());
|
||||
sId = oContact.idContact;
|
||||
|
||||
if (Utils.isNonEmptyArray(oContact.properties))
|
||||
{
|
||||
_.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('');
|
||||
this.viewName('');
|
||||
this.viewEmail('');
|
||||
this.viewImageUrl(RL.link().emptyContactPic());
|
||||
aList.push(new ContactPropertyModel(Enums.ContactPropertyType.FullName, ''));
|
||||
}
|
||||
|
||||
this.viewID(sId);
|
||||
this.viewProperties([]);
|
||||
this.viewProperties(aList);
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.reloadContactList = function ()
|
||||
@@ -293,20 +389,16 @@ PopupsContactsViewModel.prototype.reloadContactList = function ()
|
||||
self.contacts.setSelectedByUid('' + self.viewID());
|
||||
}
|
||||
|
||||
}, this.search());
|
||||
}, 0, 20, this.search());
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.onBuild = function (oDom)
|
||||
{
|
||||
this.initUploader();
|
||||
|
||||
this.oContentVisible = $('.b-list-content', oDom);
|
||||
this.oContentScrollable = $('.content', this.oContentVisible);
|
||||
|
||||
this.selector.init(this.oContentVisible, this.oContentScrollable);
|
||||
|
||||
this.viewImageUrl.valueHasMutated();
|
||||
|
||||
ko.computed(function () {
|
||||
var
|
||||
bModalVisibility = this.modalVisibility(),
|
||||
@@ -316,56 +408,6 @@ PopupsContactsViewModel.prototype.onBuild = function (oDom)
|
||||
}, 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 ()
|
||||
{
|
||||
kn.routeOff();
|
||||
|
||||
Reference in New Issue
Block a user