2013-11-16 06:21:12 +08:00
|
|
|
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
(function (module) {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2014-05-13 16:29:36 +08:00
|
|
|
var
|
2014-08-20 23:03:12 +08:00
|
|
|
_ = require('../External/underscore.js'),
|
|
|
|
ko = require('../External/ko.js'),
|
|
|
|
Enums = require('../Common/Enums.js'),
|
|
|
|
Utils = require('../Common/Utils.js')
|
2013-12-07 05:50:19 +08:00
|
|
|
;
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function ContactModel()
|
2013-12-07 05:50:19 +08:00
|
|
|
{
|
2014-08-20 23:03:12 +08:00
|
|
|
this.idContact = 0;
|
|
|
|
this.display = '';
|
|
|
|
this.properties = [];
|
|
|
|
this.tags = '';
|
|
|
|
this.readOnly = false;
|
2013-12-07 05:50:19 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
this.focused = ko.observable(false);
|
|
|
|
this.selected = ko.observable(false);
|
|
|
|
this.checked = ko.observable(false);
|
|
|
|
this.deleted = ko.observable(false);
|
|
|
|
}
|
2013-12-07 05:50:19 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
|
|
|
* @return {Array|null}
|
|
|
|
*/
|
|
|
|
ContactModel.prototype.getNameAndEmailHelper = function ()
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-20 23:03:12 +08:00
|
|
|
var
|
|
|
|
sName = '',
|
|
|
|
sEmail = ''
|
|
|
|
;
|
2013-12-07 05:50:19 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
if (Utils.isNonEmptyArray(this.properties))
|
2013-12-07 05:50:19 +08:00
|
|
|
{
|
2014-08-20 23:03:12 +08:00
|
|
|
_.each(this.properties, function (aProperty) {
|
|
|
|
if (aProperty)
|
2013-12-07 05:50:19 +08:00
|
|
|
{
|
2014-08-20 23:03:12 +08:00
|
|
|
if (Enums.ContactPropertyType.FirstName === aProperty[0])
|
|
|
|
{
|
|
|
|
sName = Utils.trim(aProperty[1] + ' ' + sName);
|
|
|
|
}
|
|
|
|
else if (Enums.ContactPropertyType.LastName === aProperty[0])
|
|
|
|
{
|
|
|
|
sName = Utils.trim(sName + ' ' + aProperty[1]);
|
|
|
|
}
|
|
|
|
else if ('' === sEmail && Enums.ContactPropertyType.Email === aProperty[0])
|
|
|
|
{
|
|
|
|
sEmail = aProperty[1];
|
|
|
|
}
|
2013-12-07 05:50:19 +08:00
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
}
|
2013-12-19 00:05:30 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
return '' === sEmail ? null : [sEmail, sName];
|
|
|
|
};
|
|
|
|
|
|
|
|
ContactModel.prototype.parse = function (oItem)
|
|
|
|
{
|
|
|
|
var bResult = false;
|
|
|
|
if (oItem && 'Object/Contact' === oItem['@Object'])
|
2014-05-13 16:29:36 +08:00
|
|
|
{
|
2014-08-20 23:03:12 +08:00
|
|
|
this.idContact = Utils.pInt(oItem['IdContact']);
|
|
|
|
this.display = Utils.pString(oItem['Display']);
|
|
|
|
this.readOnly = !!oItem['ReadOnly'];
|
|
|
|
this.tags = '';
|
|
|
|
|
|
|
|
if (Utils.isNonEmptyArray(oItem['Properties']))
|
|
|
|
{
|
|
|
|
_.each(oItem['Properties'], function (oProperty) {
|
|
|
|
if (oProperty && oProperty['Type'] && Utils.isNormal(oProperty['Value']) && Utils.isNormal(oProperty['TypeStr']))
|
|
|
|
{
|
|
|
|
this.properties.push([Utils.pInt(oProperty['Type']), Utils.pString(oProperty['Value']), Utils.pString(oProperty['TypeStr'])]);
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Utils.isNonEmptyArray(oItem['Tags']))
|
|
|
|
{
|
|
|
|
this.tags = oItem['Tags'].join(',');
|
|
|
|
}
|
|
|
|
|
|
|
|
bResult = true;
|
2014-05-13 16:29:36 +08:00
|
|
|
}
|
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
return bResult;
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
ContactModel.prototype.srcAttr = function ()
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-20 23:03:12 +08:00
|
|
|
return RL.link().emptyContactPic(); // TODO cjs
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
ContactModel.prototype.generateUid = function ()
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-20 23:03:12 +08:00
|
|
|
return '' + this.idContact;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
ContactModel.prototype.lineAsCcc = function ()
|
2014-04-08 05:03:58 +08:00
|
|
|
{
|
2014-08-20 23:03:12 +08:00
|
|
|
var aResult = [];
|
|
|
|
if (this.deleted())
|
|
|
|
{
|
|
|
|
aResult.push('deleted');
|
|
|
|
}
|
|
|
|
if (this.selected())
|
|
|
|
{
|
|
|
|
aResult.push('selected');
|
|
|
|
}
|
|
|
|
if (this.checked())
|
|
|
|
{
|
|
|
|
aResult.push('checked');
|
|
|
|
}
|
|
|
|
if (this.focused())
|
|
|
|
{
|
|
|
|
aResult.push('focused');
|
|
|
|
}
|
|
|
|
|
|
|
|
return aResult.join(' ');
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ContactModel;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
}(module));
|