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