eslint (additional rules)

This commit is contained in:
RainLoop Team 2016-06-30 03:02:45 +03:00
parent 77a1d3f3df
commit 8e8a041032
150 changed files with 21911 additions and 23106 deletions

View file

@ -1,52 +1,45 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Utils = require('Common/Utils'),
var
_ = require('_'),
ko = require('ko'),
AbstractModel = require('Knoin/AbstractModel');
Utils = require('Common/Utils'),
/**
* @constructor
*
* @param {string} sEmail
* @param {boolean=} bCanBeDelete = true
* @param {number=} iCount = 0
*/
function AccountModel(sEmail, bCanBeDelete, iCount)
{
AbstractModel.call(this, 'AccountModel');
AbstractModel = require('Knoin/AbstractModel')
;
this.email = sEmail;
/**
* @constructor
*
* @param {string} sEmail
* @param {boolean=} bCanBeDelete = true
* @param {number=} iCount = 0
*/
function AccountModel(sEmail, bCanBeDelete, iCount)
{
AbstractModel.call(this, 'AccountModel');
this.count = ko.observable(iCount || 0);
this.email = sEmail;
this.deleteAccess = ko.observable(false);
this.canBeDeleted = ko.observable(Utils.isUnd(bCanBeDelete) ? true : !!bCanBeDelete);
this.canBeEdit = this.canBeDeleted;
}
this.count = ko.observable(iCount || 0);
_.extend(AccountModel.prototype, AbstractModel.prototype);
this.deleteAccess = ko.observable(false);
this.canBeDeleted = ko.observable(Utils.isUnd(bCanBeDelete) ? true : !!bCanBeDelete);
this.canBeEdit = this.canBeDeleted;
}
/**
* @type {string}
*/
AccountModel.prototype.email = '';
_.extend(AccountModel.prototype, AbstractModel.prototype);
/**
* @returns {string}
*/
AccountModel.prototype.changeAccountLink = function()
{
return require('Common/Links').change(this.email);
};
/**
* @type {string}
*/
AccountModel.prototype.email = '';
/**
* @return {string}
*/
AccountModel.prototype.changeAccountLink = function ()
{
return require('Common/Links').change(this.email);
};
module.exports = AccountModel;
}());
module.exports = AccountModel;

File diff suppressed because it is too large Load diff

View file

@ -1,130 +1,123 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Utils = require('Common/Utils'),
var
_ = require('_'),
ko = require('ko'),
AttachmentModel = require('Model/Attachment'),
Utils = require('Common/Utils'),
AbstractModel = require('Knoin/AbstractModel');
AttachmentModel = require('Model/Attachment'),
/**
* @constructor
* @param {string} sId
* @param {string} sFileName
* @param {?number=} nSize
* @param {boolean=} bInline
* @param {boolean=} bLinked
* @param {string=} sCID
* @param {string=} sContentLocation
*/
function ComposeAttachmentModel(sId, sFileName, nSize, bInline, bLinked, sCID, sContentLocation)
{
AbstractModel.call(this, 'ComposeAttachmentModel');
AbstractModel = require('Knoin/AbstractModel')
;
this.id = sId;
this.isInline = Utils.isUnd(bInline) ? false : !!bInline;
this.isLinked = Utils.isUnd(bLinked) ? false : !!bLinked;
this.CID = Utils.isUnd(sCID) ? '' : sCID;
this.contentLocation = Utils.isUnd(sContentLocation) ? '' : sContentLocation;
this.fromMessage = false;
/**
* @constructor
* @param {string} sId
* @param {string} sFileName
* @param {?number=} nSize
* @param {boolean=} bInline
* @param {boolean=} bLinked
* @param {string=} sCID
* @param {string=} sContentLocation
*/
function ComposeAttachmentModel(sId, sFileName, nSize, bInline, bLinked, sCID, sContentLocation)
this.fileName = ko.observable(sFileName);
this.size = ko.observable(Utils.isUnd(nSize) ? null : nSize);
this.tempName = ko.observable('');
this.progress = ko.observable(0);
this.error = ko.observable('');
this.waiting = ko.observable(true);
this.uploading = ko.observable(false);
this.enabled = ko.observable(true);
this.complete = ko.observable(false);
this.progressText = ko.computed(function() {
var iP = this.progress();
return 0 === iP ? '' : '' + (98 < iP ? 100 : iP) + '%';
}, this);
this.progressStyle = ko.computed(function() {
var iP = this.progress();
return 0 === iP ? '' : 'width:' + (98 < iP ? 100 : iP) + '%';
}, this);
this.title = ko.computed(function() {
var sError = this.error();
return '' !== sError ? sError : this.fileName();
}, this);
this.friendlySize = ko.computed(function() {
var mSize = this.size();
return null === mSize ? '' : Utils.friendlySize(this.size());
}, this);
this.mimeType = ko.computed(function() {
return Utils.mimeContentType(this.fileName());
}, this);
this.fileExt = ko.computed(function() {
return Utils.getFileExtension(this.fileName());
}, this);
this.regDisposables([this.progressText, this.progressStyle, this.title, this.friendlySize, this.mimeType, this.fileExt]);
}
_.extend(ComposeAttachmentModel.prototype, AbstractModel.prototype);
ComposeAttachmentModel.prototype.id = '';
ComposeAttachmentModel.prototype.isInline = false;
ComposeAttachmentModel.prototype.isLinked = false;
ComposeAttachmentModel.prototype.CID = '';
ComposeAttachmentModel.prototype.contentLocation = '';
ComposeAttachmentModel.prototype.fromMessage = false;
ComposeAttachmentModel.prototype.cancel = Utils.noop;
/**
* @param {AjaxJsonComposeAttachment} oJsonAttachment
* @returns {boolean}
*/
ComposeAttachmentModel.prototype.initByUploadJson = function(oJsonAttachment)
{
var bResult = false;
if (oJsonAttachment)
{
AbstractModel.call(this, 'ComposeAttachmentModel');
this.fileName(oJsonAttachment.Name);
this.size(Utils.isUnd(oJsonAttachment.Size) ? 0 : Utils.pInt(oJsonAttachment.Size));
this.tempName(Utils.isUnd(oJsonAttachment.TempName) ? '' : oJsonAttachment.TempName);
this.isInline = false;
this.id = sId;
this.isInline = Utils.isUnd(bInline) ? false : !!bInline;
this.isLinked = Utils.isUnd(bLinked) ? false : !!bLinked;
this.CID = Utils.isUnd(sCID) ? '' : sCID;
this.contentLocation = Utils.isUnd(sContentLocation) ? '' : sContentLocation;
this.fromMessage = false;
this.fileName = ko.observable(sFileName);
this.size = ko.observable(Utils.isUnd(nSize) ? null : nSize);
this.tempName = ko.observable('');
this.progress = ko.observable(0);
this.error = ko.observable('');
this.waiting = ko.observable(true);
this.uploading = ko.observable(false);
this.enabled = ko.observable(true);
this.complete = ko.observable(false);
this.progressText = ko.computed(function () {
var iP = this.progress();
return 0 === iP ? '' : '' + (98 < iP ? 100 : iP) + '%';
}, this);
this.progressStyle = ko.computed(function () {
var iP = this.progress();
return 0 === iP ? '' : 'width:' + (98 < iP ? 100 : iP) + '%';
}, this);
this.title = ko.computed(function () {
var sError = this.error();
return '' !== sError ? sError : this.fileName();
}, this);
this.friendlySize = ko.computed(function () {
var mSize = this.size();
return null === mSize ? '' : Utils.friendlySize(this.size());
}, this);
this.mimeType = ko.computed(function () {
return Utils.mimeContentType(this.fileName());
}, this);
this.fileExt = ko.computed(function () {
return Utils.getFileExtension(this.fileName());
}, this);
this.regDisposables([this.progressText, this.progressStyle, this.title, this.friendlySize, this.mimeType, this.fileExt]);
bResult = true;
}
_.extend(ComposeAttachmentModel.prototype, AbstractModel.prototype);
return bResult;
};
ComposeAttachmentModel.prototype.id = '';
ComposeAttachmentModel.prototype.isInline = false;
ComposeAttachmentModel.prototype.isLinked = false;
ComposeAttachmentModel.prototype.CID = '';
ComposeAttachmentModel.prototype.contentLocation = '';
ComposeAttachmentModel.prototype.fromMessage = false;
ComposeAttachmentModel.prototype.cancel = Utils.noop;
/**
* @returns {string}
*/
ComposeAttachmentModel.prototype.iconClass = function()
{
return AttachmentModel.staticIconClass(
AttachmentModel.staticFileType(this.fileExt(), this.mimeType()))[0];
};
/**
* @param {AjaxJsonComposeAttachment} oJsonAttachment
* @return {boolean}
*/
ComposeAttachmentModel.prototype.initByUploadJson = function (oJsonAttachment)
{
var bResult = false;
if (oJsonAttachment)
{
this.fileName(oJsonAttachment.Name);
this.size(Utils.isUnd(oJsonAttachment.Size) ? 0 : Utils.pInt(oJsonAttachment.Size));
this.tempName(Utils.isUnd(oJsonAttachment.TempName) ? '' : oJsonAttachment.TempName);
this.isInline = false;
/**
* @returns {string}
*/
ComposeAttachmentModel.prototype.iconText = function()
{
return AttachmentModel.staticIconClass(
AttachmentModel.staticFileType(this.fileExt(), this.mimeType()))[1];
};
bResult = true;
}
return bResult;
};
/**
* @return {string}
*/
ComposeAttachmentModel.prototype.iconClass = function ()
{
return AttachmentModel.staticIconClass(
AttachmentModel.staticFileType(this.fileExt(), this.mimeType()))[0];
};
/**
* @return {string}
*/
ComposeAttachmentModel.prototype.iconText = function ()
{
return AttachmentModel.staticIconClass(
AttachmentModel.staticFileType(this.fileExt(), this.mimeType()))[1];
};
module.exports = ComposeAttachmentModel;
}());
module.exports = ComposeAttachmentModel;

View file

@ -1,140 +1,132 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Links = require('Common/Links'),
AbstractModel = require('Knoin/AbstractModel');
/**
* @constructor
*/
function ContactModel()
{
AbstractModel.call(this, 'ContactModel');
this.idContact = 0;
this.display = '';
this.properties = [];
this.readOnly = false;
this.focused = ko.observable(false);
this.selected = ko.observable(false);
this.checked = ko.observable(false);
this.deleted = ko.observable(false);
}
_.extend(ContactModel.prototype, AbstractModel.prototype);
/**
* @returns {Array|null}
*/
ContactModel.prototype.getNameAndEmailHelper = function()
{
var
_ = require('_'),
ko = require('ko'),
sName = '',
sEmail = '';
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Links = require('Common/Links'),
AbstractModel = require('Knoin/AbstractModel')
;
/**
* @constructor
*/
function ContactModel()
if (Utils.isNonEmptyArray(this.properties))
{
AbstractModel.call(this, 'ContactModel');
this.idContact = 0;
this.display = '';
this.properties = [];
this.readOnly = false;
this.focused = ko.observable(false);
this.selected = ko.observable(false);
this.checked = ko.observable(false);
this.deleted = ko.observable(false);
_.each(this.properties, function(aProperty) {
if (aProperty)
{
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];
}
}
}, this);
}
_.extend(ContactModel.prototype, AbstractModel.prototype);
return '' === sEmail ? null : [sEmail, sName];
};
/**
* @return {Array|null}
*/
ContactModel.prototype.getNameAndEmailHelper = function ()
ContactModel.prototype.parse = function(oItem)
{
var bResult = false;
if (oItem && 'Object/Contact' === oItem['@Object'])
{
var
sName = '',
sEmail = ''
;
this.idContact = Utils.pInt(oItem.IdContact);
this.display = Utils.pString(oItem.Display);
this.readOnly = !!oItem.ReadOnly;
if (Utils.isNonEmptyArray(this.properties))
if (Utils.isNonEmptyArray(oItem.Properties))
{
_.each(this.properties, function (aProperty) {
if (aProperty)
_.each(oItem.Properties, function(oProperty) {
if (oProperty && oProperty.Type && Utils.isNormal(oProperty.Value) && Utils.isNormal(oProperty.TypeStr))
{
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];
}
this.properties.push([Utils.pInt(oProperty.Type), Utils.pString(oProperty.Value), Utils.pString(oProperty.TypeStr)]);
}
}, this);
}
return '' === sEmail ? null : [sEmail, sName];
};
bResult = true;
}
ContactModel.prototype.parse = function (oItem)
return bResult;
};
/**
* @returns {string}
*/
ContactModel.prototype.srcAttr = function()
{
return Links.emptyContactPic();
};
/**
* @returns {string}
*/
ContactModel.prototype.generateUid = function()
{
return '' + this.idContact;
};
/**
* @return string
*/
ContactModel.prototype.lineAsCss = function()
{
var aResult = [];
if (this.deleted())
{
var bResult = false;
if (oItem && 'Object/Contact' === oItem['@Object'])
{
this.idContact = Utils.pInt(oItem.IdContact);
this.display = Utils.pString(oItem.Display);
this.readOnly = !!oItem.ReadOnly;
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);
}
bResult = true;
}
return bResult;
};
/**
* @return {string}
*/
ContactModel.prototype.srcAttr = function ()
aResult.push('deleted');
}
if (this.selected())
{
return Links.emptyContactPic();
};
/**
* @return {string}
*/
ContactModel.prototype.generateUid = function ()
aResult.push('selected');
}
if (this.checked())
{
return '' + this.idContact;
};
/**
* @return string
*/
ContactModel.prototype.lineAsCss = function ()
aResult.push('checked');
}
if (this.focused())
{
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');
}
aResult.push('focused');
}
return aResult.join(' ');
};
return aResult.join(' ');
};
module.exports = ContactModel;
}());
module.exports = ContactModel;

View file

@ -1,52 +1,45 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
var
_ = require('_'),
ko = require('ko'),
AbstractModel = require('Knoin/AbstractModel');
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
/**
* @constructor
* @param {number=} iType = Enums.ContactPropertyType.Unknown
* @param {string=} sTypeStr = ''
* @param {string=} sValue = ''
* @param {boolean=} bFocused = false
* @param {string=} sPlaceholder = ''
*/
function ContactPropertyModel(iType, sTypeStr, sValue, bFocused, sPlaceholder)
{
AbstractModel.call(this, 'ContactPropertyModel');
AbstractModel = require('Knoin/AbstractModel')
;
this.type = ko.observable(Utils.isUnd(iType) ? Enums.ContactPropertyType.Unknown : iType);
this.typeStr = ko.observable(Utils.isUnd(sTypeStr) ? '' : sTypeStr);
this.focused = ko.observable(Utils.isUnd(bFocused) ? false : !!bFocused);
this.value = ko.observable(Utils.pString(sValue));
/**
* @constructor
* @param {number=} iType = Enums.ContactPropertyType.Unknown
* @param {string=} sTypeStr = ''
* @param {string=} sValue = ''
* @param {boolean=} bFocused = false
* @param {string=} sPlaceholder = ''
*/
function ContactPropertyModel(iType, sTypeStr, sValue, bFocused, sPlaceholder)
{
AbstractModel.call(this, 'ContactPropertyModel');
this.placeholder = ko.observable(sPlaceholder || '');
this.type = ko.observable(Utils.isUnd(iType) ? Enums.ContactPropertyType.Unknown : iType);
this.typeStr = ko.observable(Utils.isUnd(sTypeStr) ? '' : sTypeStr);
this.focused = ko.observable(Utils.isUnd(bFocused) ? false : !!bFocused);
this.value = ko.observable(Utils.pString(sValue));
this.placeholderValue = ko.computed(function() {
var value = this.placeholder();
return value ? Translator.i18n(value) : '';
}, this);
this.placeholder = ko.observable(sPlaceholder || '');
this.largeValue = ko.computed(function() {
return Enums.ContactPropertyType.Note === this.type();
}, this);
this.placeholderValue = ko.computed(function () {
var value = this.placeholder();
return value ? Translator.i18n(value) : '';
}, this);
this.regDisposables([this.placeholderValue, this.largeValue]);
}
this.largeValue = ko.computed(function () {
return Enums.ContactPropertyType.Note === this.type();
}, this);
_.extend(ContactPropertyModel.prototype, AbstractModel.prototype);
this.regDisposables([this.placeholderValue, this.largeValue]);
}
_.extend(ContactPropertyModel.prototype, AbstractModel.prototype);
module.exports = ContactPropertyModel;
}());
module.exports = ContactPropertyModel;

View file

@ -1,406 +1,396 @@
(function () {
var Utils = require('Common/Utils');
'use strict';
/**
* @constructor
* @param {string=} sEmail
* @param {string=} sName
* @param {string=} sDkimStatus
* @param {string=} sDkimValue
*/
function EmailModel(sEmail, sName, sDkimStatus, sDkimValue)
{
this.email = sEmail || '';
this.name = sName || '';
this.dkimStatus = sDkimStatus || 'none';
this.dkimValue = sDkimValue || '';
this.clearDuplicateName();
}
/**
* @static
* @param {AjaxJsonEmail} oJsonEmail
* @returns {?EmailModel}
*/
EmailModel.newInstanceFromJson = function(oJsonEmail)
{
var oEmailModel = new EmailModel();
return oEmailModel.initByJson(oJsonEmail) ? oEmailModel : null;
};
/**
* @static
* @param {string} sLine
* @param {string=} sDelimiter = ';'
* @returns {Array}
*/
EmailModel.splitHelper = function(sLine, sDelimiter)
{
sDelimiter = sDelimiter || ';';
sLine = sLine.replace(/[\r\n]+/g, '; ').replace(/[\s]+/g, ' ');
var
Utils = require('Common/Utils')
;
iIndex = 0,
iLen = sLine.length,
bAt = false,
sChar = '',
sResult = '';
/**
* @param {string=} sEmail
* @param {string=} sName
* @param {string=} sDkimStatus
* @param {string=} sDkimValue
*
* @constructor
*/
function EmailModel(sEmail, sName, sDkimStatus, sDkimValue)
for (; iIndex < iLen; iIndex++)
{
this.email = sEmail || '';
this.name = sName || '';
this.dkimStatus = sDkimStatus || 'none';
this.dkimValue = sDkimValue || '';
sChar = sLine.charAt(iIndex);
switch (sChar)
{
case '@':
bAt = true;
break;
case ' ':
if (bAt)
{
bAt = false;
sResult += sDelimiter;
}
break;
// no default
}
sResult += sChar;
}
return sResult.split(sDelimiter);
};
/**
* @type {string}
*/
EmailModel.prototype.name = '';
/**
* @type {string}
*/
EmailModel.prototype.email = '';
/**
* @type {string}
*/
EmailModel.prototype.dkimStatus = 'none';
/**
* @type {string}
*/
EmailModel.prototype.dkimValue = '';
EmailModel.prototype.clear = function()
{
this.email = '';
this.name = '';
this.dkimStatus = 'none';
this.dkimValue = '';
};
/**
* @returns {boolean}
*/
EmailModel.prototype.validate = function()
{
return '' !== this.name || '' !== this.email;
};
/**
* @param {boolean} bWithoutName = false
* @returns {string}
*/
EmailModel.prototype.hash = function(bWithoutName)
{
return '#' + (bWithoutName ? '' : this.name) + '#' + this.email + '#';
};
EmailModel.prototype.clearDuplicateName = function()
{
if (this.name === this.email)
{
this.name = '';
}
};
/**
* @param {string} sQuery
* @returns {boolean}
*/
EmailModel.prototype.search = function(sQuery)
{
return -1 < (this.name + ' ' + this.email).toLowerCase().indexOf(sQuery.toLowerCase());
};
/**
* @param {string} sString
*/
EmailModel.prototype.parse = function(sString)
{
this.clear();
sString = Utils.trim(sString);
var
mRegex = /(?:"([^"]+)")? ?[<]?(.*?@[^>,]+)>?,? ?/g,
mMatch = mRegex.exec(sString);
if (mMatch)
{
this.name = mMatch[1] || '';
this.email = mMatch[2] || '';
this.clearDuplicateName();
}
/**
* @static
* @param {AjaxJsonEmail} oJsonEmail
* @return {?EmailModel}
*/
EmailModel.newInstanceFromJson = function (oJsonEmail)
else if ((/^[^@]+@[^@]+$/).test(sString))
{
var oEmailModel = new EmailModel();
return oEmailModel.initByJson(oJsonEmail) ? oEmailModel : null;
};
/**
* @static
* @param {string} sLine
* @param {string=} sDelimiter = ';'
* @return {Array}
*/
EmailModel.splitHelper = function (sLine, sDelimiter)
{
sDelimiter = sDelimiter || ';';
sLine = sLine.replace(/[\r\n]+/g, '; ').replace(/[\s]+/g, ' ');
var
iIndex = 0,
iLen = sLine.length,
bAt = false,
sChar = '',
sResult = ''
;
for (; iIndex < iLen; iIndex++)
{
sChar = sLine.charAt(iIndex);
switch (sChar)
{
case '@':
bAt = true;
break;
case ' ':
if (bAt)
{
bAt = false;
sResult += sDelimiter;
}
break;
}
sResult += sChar;
}
return sResult.split(sDelimiter);
};
/**
* @type {string}
*/
EmailModel.prototype.name = '';
/**
* @type {string}
*/
EmailModel.prototype.email = '';
/**
* @type {string}
*/
EmailModel.prototype.dkimStatus = 'none';
/**
* @type {string}
*/
EmailModel.prototype.dkimValue = '';
EmailModel.prototype.clear = function ()
{
this.email = '';
this.name = '';
this.email = sString;
}
};
this.dkimStatus = 'none';
this.dkimValue = '';
};
/**
* @return {boolean}
*/
EmailModel.prototype.validate = function ()
/**
* @param {AjaxJsonEmail} oJsonEmail
* @returns {boolean}
*/
EmailModel.prototype.initByJson = function(oJsonEmail)
{
var bResult = false;
if (oJsonEmail && 'Object/Email' === oJsonEmail['@Object'])
{
return '' !== this.name || '' !== this.email;
};
/**
* @param {boolean} bWithoutName = false
* @return {string}
*/
EmailModel.prototype.hash = function (bWithoutName)
{
return '#' + (bWithoutName ? '' : this.name) + '#' + this.email + '#';
};
EmailModel.prototype.clearDuplicateName = function ()
{
if (this.name === this.email)
{
this.name = '';
}
};
/**
* @param {string} sQuery
* @return {boolean}
*/
EmailModel.prototype.search = function (sQuery)
{
return -1 < (this.name + ' ' + this.email).toLowerCase().indexOf(sQuery.toLowerCase());
};
/**
* @param {string} sString
*/
EmailModel.prototype.parse = function (sString)
{
this.clear();
sString = Utils.trim(sString);
var
mRegex = /(?:"([^"]+)")? ?[<]?(.*?@[^>,]+)>?,? ?/g,
mMatch = mRegex.exec(sString)
;
if (mMatch)
{
this.name = mMatch[1] || '';
this.email = mMatch[2] || '';
this.clearDuplicateName();
}
else if ((/^[^@]+@[^@]+$/).test(sString))
{
this.name = '';
this.email = sString;
}
};
/**
* @param {AjaxJsonEmail} oJsonEmail
* @return {boolean}
*/
EmailModel.prototype.initByJson = function (oJsonEmail)
{
var bResult = false;
if (oJsonEmail && 'Object/Email' === oJsonEmail['@Object'])
{
this.name = Utils.trim(oJsonEmail.Name);
this.email = Utils.trim(oJsonEmail.Email);
this.dkimStatus = Utils.trim(oJsonEmail.DkimStatus || '');
this.dkimValue = Utils.trim(oJsonEmail.DkimValue || '');
bResult = '' !== this.email;
this.clearDuplicateName();
}
return bResult;
};
/**
* @param {boolean} bFriendlyView
* @param {boolean=} bWrapWithLink = false
* @param {boolean=} bEncodeHtml = false
* @return {string}
*/
EmailModel.prototype.toLine = function (bFriendlyView, bWrapWithLink, bEncodeHtml)
{
var sResult = '';
if ('' !== this.email)
{
bWrapWithLink = Utils.isUnd(bWrapWithLink) ? false : !!bWrapWithLink;
bEncodeHtml = Utils.isUnd(bEncodeHtml) ? false : !!bEncodeHtml;
if (bFriendlyView && '' !== this.name)
{
sResult = bWrapWithLink ? '<a href="mailto:' + Utils.encodeHtml('"' + this.name + '" <' + this.email + '>') +
'" target="_blank" tabindex="-1">' + Utils.encodeHtml(this.name) + '</a>' :
(bEncodeHtml ? Utils.encodeHtml(this.name) : this.name);
}
else
{
sResult = this.email;
if ('' !== this.name)
{
if (bWrapWithLink)
{
sResult = Utils.encodeHtml('"' + this.name + '" <') + '<a href="mailto:' +
Utils.encodeHtml('"' + this.name + '" <' + this.email + '>') +
'" target="_blank" tabindex="-1">' +
Utils.encodeHtml(sResult) +
'</a>' +
Utils.encodeHtml('>');
}
else
{
sResult = '"' + this.name + '" <' + sResult + '>';
if (bEncodeHtml)
{
sResult = Utils.encodeHtml(sResult);
}
}
}
else if (bWrapWithLink)
{
sResult = '<a href="mailto:' + Utils.encodeHtml(this.email) + '" target="_blank" tabindex="-1">' + Utils.encodeHtml(this.email) + '</a>';
}
}
}
return sResult;
};
/**
* @param {string} $sEmailAddress
* @return {boolean}
*/
EmailModel.prototype.mailsoParse = function ($sEmailAddress)
{
$sEmailAddress = Utils.trim($sEmailAddress);
if ('' === $sEmailAddress)
{
return false;
}
var
substr = function (str, start, len) {
str += '';
var end = str.length;
if (start < 0) {
start += end;
}
end = typeof len === 'undefined' ? end : (len < 0 ? len + end : len + start);
return start >= str.length || start < 0 || start > end ? false : str.slice(start, end);
},
substr_replace = function (str, replace, start, length) {
if (start < 0) {
start += str.length;
}
length = typeof length !== 'undefined' ? length : str.length;
if (length < 0) {
length = length + str.length - start;
}
return str.slice(0, start) + replace.substr(0, length) + replace.slice(length) + str.slice(start + length);
},
$sName = '',
$sEmail = '',
$sComment = '',
$bInName = false,
$bInAddress = false,
$bInComment = false,
$aRegs = null,
$iStartIndex = 0,
$iEndIndex = 0,
$iCurrentIndex = 0
;
while ($iCurrentIndex < $sEmailAddress.length)
{
switch ($sEmailAddress.substr($iCurrentIndex, 1))
{
case '"':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
$bInName = true;
$iStartIndex = $iCurrentIndex;
}
else if ((!$bInAddress) && (!$bInComment))
{
$iEndIndex = $iCurrentIndex;
$sName = substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInName = false;
}
break;
case '<':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
if ($iCurrentIndex > 0 && $sName.length === 0)
{
$sName = substr($sEmailAddress, 0, $iCurrentIndex);
}
$bInAddress = true;
$iStartIndex = $iCurrentIndex;
}
break;
case '>':
if ($bInAddress)
{
$iEndIndex = $iCurrentIndex;
$sEmail = substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInAddress = false;
}
break;
case '(':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
$bInComment = true;
$iStartIndex = $iCurrentIndex;
}
break;
case ')':
if ($bInComment)
{
$iEndIndex = $iCurrentIndex;
$sComment = substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInComment = false;
}
break;
case '\\':
$iCurrentIndex++;
break;
}
$iCurrentIndex++;
}
if ($sEmail.length === 0)
{
$aRegs = $sEmailAddress.match(/[^@\s]+@\S+/i);
if ($aRegs && $aRegs[0])
{
$sEmail = $aRegs[0];
}
else
{
$sName = $sEmailAddress;
}
}
if ($sEmail.length > 0 && $sName.length === 0 && $sComment.length === 0)
{
$sName = $sEmailAddress.replace($sEmail, '');
}
$sEmail = Utils.trim($sEmail).replace(/^[<]+/, '').replace(/[>]+$/, '');
$sName = Utils.trim($sName).replace(/^["']+/, '').replace(/["']+$/, '');
$sComment = Utils.trim($sComment).replace(/^[(]+/, '').replace(/[)]+$/, '');
// Remove backslash
$sName = $sName.replace(/\\\\(.)/g, '$1');
$sComment = $sComment.replace(/\\\\(.)/g, '$1');
this.name = $sName;
this.email = $sEmail;
this.name = Utils.trim(oJsonEmail.Name);
this.email = Utils.trim(oJsonEmail.Email);
this.dkimStatus = Utils.trim(oJsonEmail.DkimStatus || '');
this.dkimValue = Utils.trim(oJsonEmail.DkimValue || '');
bResult = '' !== this.email;
this.clearDuplicateName();
return true;
};
}
module.exports = EmailModel;
return bResult;
};
}());
/**
* @param {boolean} bFriendlyView
* @param {boolean=} bWrapWithLink = false
* @param {boolean=} bEncodeHtml = false
* @returns {string}
*/
EmailModel.prototype.toLine = function(bFriendlyView, bWrapWithLink, bEncodeHtml)
{
var sResult = '';
if ('' !== this.email)
{
bWrapWithLink = Utils.isUnd(bWrapWithLink) ? false : !!bWrapWithLink;
bEncodeHtml = Utils.isUnd(bEncodeHtml) ? false : !!bEncodeHtml;
if (bFriendlyView && '' !== this.name)
{
sResult = bWrapWithLink ? '<a href="mailto:' + Utils.encodeHtml('"' + this.name + '" <' + this.email + '>') +
'" target="_blank" tabindex="-1">' + Utils.encodeHtml(this.name) + '</a>' :
(bEncodeHtml ? Utils.encodeHtml(this.name) : this.name);
}
else
{
sResult = this.email;
if ('' !== this.name)
{
if (bWrapWithLink)
{
sResult = Utils.encodeHtml('"' + this.name + '" <') + '<a href="mailto:' +
Utils.encodeHtml('"' + this.name + '" <' + this.email + '>') +
'" target="_blank" tabindex="-1">' +
Utils.encodeHtml(sResult) +
'</a>' +
Utils.encodeHtml('>');
}
else
{
sResult = '"' + this.name + '" <' + sResult + '>';
if (bEncodeHtml)
{
sResult = Utils.encodeHtml(sResult);
}
}
}
else if (bWrapWithLink)
{
sResult = '<a href="mailto:' + Utils.encodeHtml(this.email) + '" target="_blank" tabindex="-1">' + Utils.encodeHtml(this.email) + '</a>';
}
}
}
return sResult;
};
/**
* @param {string} $sEmailAddress
* @returns {boolean}
*/
EmailModel.prototype.mailsoParse = function($sEmailAddress)
{
$sEmailAddress = Utils.trim($sEmailAddress);
if ('' === $sEmailAddress)
{
return false;
}
var
substr = function(str, start, len) {
str += '';
var end = str.length;
if (0 > start) {
start += end;
}
end = 'undefined' === typeof len ? end : (0 > len ? len + end : len + start);
return start >= str.length || 0 > start || start > end ? false : str.slice(start, end);
},
substrReplace = function(str, replace, start, length) {
if (0 > start) {
start += str.length;
}
length = 'undefined' === typeof length ? length : str.length;
if (0 > length) {
length = length + str.length - start;
}
return str.slice(0, start) + replace.substr(0, length) + replace.slice(length) + str.slice(start + length);
},
$sName = '',
$sEmail = '',
$sComment = '',
$bInName = false,
$bInAddress = false,
$bInComment = false,
$aRegs = null,
$iStartIndex = 0,
$iEndIndex = 0,
$iCurrentIndex = 0;
while ($iCurrentIndex < $sEmailAddress.length)
{
switch ($sEmailAddress.substr($iCurrentIndex, 1))
{
case '"':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
$bInName = true;
$iStartIndex = $iCurrentIndex;
}
else if ((!$bInAddress) && (!$bInComment))
{
$iEndIndex = $iCurrentIndex;
$sName = substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = substrReplace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInName = false;
}
break;
case '<':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
if (0 < $iCurrentIndex && 0 === $sName.length)
{
$sName = substr($sEmailAddress, 0, $iCurrentIndex);
}
$bInAddress = true;
$iStartIndex = $iCurrentIndex;
}
break;
case '>':
if ($bInAddress)
{
$iEndIndex = $iCurrentIndex;
$sEmail = substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = substrReplace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInAddress = false;
}
break;
case '(':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
$bInComment = true;
$iStartIndex = $iCurrentIndex;
}
break;
case ')':
if ($bInComment)
{
$iEndIndex = $iCurrentIndex;
$sComment = substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = substrReplace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInComment = false;
}
break;
case '\\':
$iCurrentIndex += 1;
break;
// no default
}
$iCurrentIndex += 1;
}
if (0 === $sEmail.length)
{
$aRegs = $sEmailAddress.match(/[^@\s]+@\S+/i);
if ($aRegs && $aRegs[0])
{
$sEmail = $aRegs[0];
}
else
{
$sName = $sEmailAddress;
}
}
if (0 < $sEmail.length && 0 === $sName.length && 0 === $sComment.length)
{
$sName = $sEmailAddress.replace($sEmail, '');
}
$sEmail = Utils.trim($sEmail).replace(/^[<]+/, '').replace(/[>]+$/, '');
$sName = Utils.trim($sName).replace(/^["']+/, '').replace(/["']+$/, '');
$sComment = Utils.trim($sComment).replace(/^[(]+/, '').replace(/[)]+$/, '');
// Remove backslash
$sName = $sName.replace(/\\\\(.)/g, '$1');
$sComment = $sComment.replace(/\\\\(.)/g, '$1');
this.name = $sName;
this.email = $sEmail;
this.clearDuplicateName();
return true;
};
module.exports = EmailModel;

View file

@ -1,325 +1,318 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
var
_ = require('_'),
ko = require('ko'),
Cache = require('Common/Cache'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
FilterConditionModel = require('Model/FilterCondition'),
Cache = require('Common/Cache'),
AbstractModel = require('Knoin/AbstractModel');
FilterConditionModel = require('Model/FilterCondition'),
/**
* @constructor
*/
function FilterModel()
{
AbstractModel.call(this, 'FilterModel');
AbstractModel = require('Knoin/AbstractModel')
;
this.enabled = ko.observable(true);
/**
* @constructor
*/
function FilterModel()
{
AbstractModel.call(this, 'FilterModel');
this.id = '';
this.enabled = ko.observable(true);
this.name = ko.observable('');
this.name.error = ko.observable(false);
this.name.focused = ko.observable(false);
this.id = '';
this.conditions = ko.observableArray([]);
this.conditionsType = ko.observable(Enums.FilterRulesType.Any);
this.name = ko.observable('');
this.name.error = ko.observable(false);
this.name.focused = ko.observable(false);
// Actions
this.actionValue = ko.observable('');
this.actionValue.error = ko.observable(false);
this.conditions = ko.observableArray([]);
this.conditionsType = ko.observable(Enums.FilterRulesType.Any);
this.actionValueSecond = ko.observable('');
this.actionValueThird = ko.observable('');
// Actions
this.actionValue = ko.observable('');
this.actionValue.error = ko.observable(false);
this.actionValueFourth = ko.observable('');
this.actionValueFourth.error = ko.observable(false);
this.actionValueSecond = ko.observable('');
this.actionValueThird = ko.observable('');
this.actionMarkAsRead = ko.observable(false);
this.actionValueFourth = ko.observable('');
this.actionValueFourth.error = ko.observable(false);
this.actionKeep = ko.observable(true);
this.actionNoStop = ko.observable(false);
this.actionMarkAsRead = ko.observable(false);
this.actionType = ko.observable(Enums.FiltersAction.MoveTo);
this.actionKeep = ko.observable(true);
this.actionNoStop = ko.observable(false);
this.actionType.subscribe(function() {
this.actionValue('');
this.actionValue.error(false);
this.actionValueSecond('');
this.actionValueThird('');
this.actionValueFourth('');
this.actionValueFourth.error(false);
}, this);
this.actionType = ko.observable(Enums.FiltersAction.MoveTo);
this.actionType.subscribe(function () {
this.actionValue('');
this.actionValue.error(false);
this.actionValueSecond('');
this.actionValueThird('');
this.actionValueFourth('');
this.actionValueFourth.error(false);
}, this);
var fGetRealFolderName = function (sFolderFullNameRaw) {
var oFolder = Cache.getFolderFromCacheList(sFolderFullNameRaw);
return oFolder ? oFolder.fullName.replace(
'.' === oFolder.delimiter ? /\./ : /[\\\/]+/, ' / ') : sFolderFullNameRaw;
};
this.nameSub = ko.computed(function () {
var
sResult = '',
sActionValue = this.actionValue()
;
switch (this.actionType())
{
case Enums.FiltersAction.MoveTo:
sResult = Translator.i18n('SETTINGS_FILTERS/SUBNAME_MOVE_TO', {
FOLDER: fGetRealFolderName(sActionValue)
});
break;
case Enums.FiltersAction.Forward:
sResult = Translator.i18n('SETTINGS_FILTERS/SUBNAME_FORWARD_TO', {
EMAIL: sActionValue
});
break;
case Enums.FiltersAction.Vacation:
sResult = Translator.i18n('SETTINGS_FILTERS/SUBNAME_VACATION_MESSAGE');
break;
case Enums.FiltersAction.Reject:
sResult = Translator.i18n('SETTINGS_FILTERS/SUBNAME_REJECT');
break;
case Enums.FiltersAction.Discard:
sResult = Translator.i18n('SETTINGS_FILTERS/SUBNAME_DISCARD');
break;
}
return sResult ? '(' + sResult + ')' : '';
}, this);
this.actionTemplate = ko.computed(function () {
var sTemplate = '';
switch (this.actionType())
{
default:
case Enums.FiltersAction.MoveTo:
sTemplate = 'SettingsFiltersActionMoveToFolder';
break;
case Enums.FiltersAction.Forward:
sTemplate = 'SettingsFiltersActionForward';
break;
case Enums.FiltersAction.Vacation:
sTemplate = 'SettingsFiltersActionVacation';
break;
case Enums.FiltersAction.Reject:
sTemplate = 'SettingsFiltersActionReject';
break;
case Enums.FiltersAction.None:
sTemplate = 'SettingsFiltersActionNone';
break;
case Enums.FiltersAction.Discard:
sTemplate = 'SettingsFiltersActionDiscard';
break;
}
return sTemplate;
}, this);
this.regDisposables(this.conditions.subscribe(Utils.windowResizeCallback));
this.regDisposables(this.name.subscribe(function (sValue) {
this.name.error('' === sValue);
}, this));
this.regDisposables(this.actionValue.subscribe(function (sValue) {
this.actionValue.error('' === sValue);
}, this));
this.regDisposables([this.actionNoStop, this.actionTemplate]);
this.deleteAccess = ko.observable(false);
this.canBeDeleted = ko.observable(true);
}
_.extend(FilterModel.prototype, AbstractModel.prototype);
FilterModel.prototype.generateID = function ()
{
this.id = Utils.fakeMd5();
var fGetRealFolderName = function(sFolderFullNameRaw) {
var oFolder = Cache.getFolderFromCacheList(sFolderFullNameRaw);
return oFolder ? oFolder.fullName.replace(
'.' === oFolder.delimiter ? /\./ : /[\\\/]+/, ' / ') : sFolderFullNameRaw;
};
FilterModel.prototype.verify = function ()
{
if ('' === this.name())
this.nameSub = ko.computed(function() {
var
sResult = '',
sActionValue = this.actionValue();
switch (this.actionType())
{
case Enums.FiltersAction.MoveTo:
sResult = Translator.i18n('SETTINGS_FILTERS/SUBNAME_MOVE_TO', {
FOLDER: fGetRealFolderName(sActionValue)
});
break;
case Enums.FiltersAction.Forward:
sResult = Translator.i18n('SETTINGS_FILTERS/SUBNAME_FORWARD_TO', {
EMAIL: sActionValue
});
break;
case Enums.FiltersAction.Vacation:
sResult = Translator.i18n('SETTINGS_FILTERS/SUBNAME_VACATION_MESSAGE');
break;
case Enums.FiltersAction.Reject:
sResult = Translator.i18n('SETTINGS_FILTERS/SUBNAME_REJECT');
break;
case Enums.FiltersAction.Discard:
sResult = Translator.i18n('SETTINGS_FILTERS/SUBNAME_DISCARD');
break;
// no default
}
return sResult ? '(' + sResult + ')' : '';
}, this);
this.actionTemplate = ko.computed(function() {
var sTemplate = '';
switch (this.actionType())
{
case Enums.FiltersAction.Forward:
sTemplate = 'SettingsFiltersActionForward';
break;
case Enums.FiltersAction.Vacation:
sTemplate = 'SettingsFiltersActionVacation';
break;
case Enums.FiltersAction.Reject:
sTemplate = 'SettingsFiltersActionReject';
break;
case Enums.FiltersAction.None:
sTemplate = 'SettingsFiltersActionNone';
break;
case Enums.FiltersAction.Discard:
sTemplate = 'SettingsFiltersActionDiscard';
break;
case Enums.FiltersAction.MoveTo:
default:
sTemplate = 'SettingsFiltersActionMoveToFolder';
break;
}
return sTemplate;
}, this);
this.regDisposables(this.conditions.subscribe(Utils.windowResizeCallback));
this.regDisposables(this.name.subscribe(function(sValue) {
this.name.error('' === sValue);
}, this));
this.regDisposables(this.actionValue.subscribe(function(sValue) {
this.actionValue.error('' === sValue);
}, this));
this.regDisposables([this.actionNoStop, this.actionTemplate]);
this.deleteAccess = ko.observable(false);
this.canBeDeleted = ko.observable(true);
}
_.extend(FilterModel.prototype, AbstractModel.prototype);
FilterModel.prototype.generateID = function()
{
this.id = Utils.fakeMd5();
};
FilterModel.prototype.verify = function()
{
if ('' === this.name())
{
this.name.error(true);
return false;
}
if (0 < this.conditions().length)
{
if (_.find(this.conditions(), function(oCond) {
return oCond && !oCond.verify();
}))
{
this.name.error(true);
return false;
}
}
if (0 < this.conditions().length)
{
if (_.find(this.conditions(), function (oCond) {
return oCond && !oCond.verify();
}))
{
return false;
}
}
if ('' === this.actionValue())
{
if (-1 < Utils.inArray(this.actionType(), [
Enums.FiltersAction.MoveTo,
Enums.FiltersAction.Forward,
Enums.FiltersAction.Reject,
Enums.FiltersAction.Vacation
]))
{
this.actionValue.error(true);
return false;
}
}
if (Enums.FiltersAction.Forward === this.actionType() &&
-1 === this.actionValue().indexOf('@'))
if ('' === this.actionValue())
{
if (-1 < Utils.inArray(this.actionType(), [
Enums.FiltersAction.MoveTo,
Enums.FiltersAction.Forward,
Enums.FiltersAction.Reject,
Enums.FiltersAction.Vacation
]))
{
this.actionValue.error(true);
return false;
}
}
if (Enums.FiltersAction.Vacation === this.actionType() &&
'' !== this.actionValueFourth() && -1 === this.actionValueFourth().indexOf('@')
)
if (Enums.FiltersAction.Forward === this.actionType() &&
-1 === this.actionValue().indexOf('@'))
{
this.actionValue.error(true);
return false;
}
if (Enums.FiltersAction.Vacation === this.actionType() &&
'' !== this.actionValueFourth() && -1 === this.actionValueFourth().indexOf('@')
)
{
this.actionValueFourth.error(true);
return false;
}
this.name.error(false);
this.actionValue.error(false);
return true;
};
FilterModel.prototype.toJson = function()
{
return {
ID: this.id,
Enabled: this.enabled() ? '1' : '0',
Name: this.name(),
ConditionsType: this.conditionsType(),
Conditions: _.map(this.conditions(), function(oItem) {
return oItem.toJson();
}),
ActionValue: this.actionValue(),
ActionValueSecond: this.actionValueSecond(),
ActionValueThird: this.actionValueThird(),
ActionValueFourth: this.actionValueFourth(),
ActionType: this.actionType(),
Stop: this.actionNoStop() ? '0' : '1',
Keep: this.actionKeep() ? '1' : '0',
MarkAsRead: this.actionMarkAsRead() ? '1' : '0'
};
};
FilterModel.prototype.addCondition = function()
{
this.conditions.push(new FilterConditionModel());
};
FilterModel.prototype.removeCondition = function(oConditionToDelete)
{
this.conditions.remove(oConditionToDelete);
Utils.delegateRunOnDestroy(oConditionToDelete);
};
FilterModel.prototype.setRecipients = function()
{
this.actionValueFourth(require('Stores/User/Account').accountsEmails().join(', '));
};
FilterModel.prototype.parse = function(oItem)
{
var bResult = false;
if (oItem && 'Object/Filter' === oItem['@Object'])
{
this.id = Utils.pString(oItem.ID);
this.name(Utils.pString(oItem.Name));
this.enabled(!!oItem.Enabled);
this.conditionsType(Utils.pString(oItem.ConditionsType));
this.conditions([]);
if (Utils.isNonEmptyArray(oItem.Conditions))
{
this.actionValueFourth.error(true);
return false;
this.conditions(_.compact(_.map(oItem.Conditions, function(aData) {
var oFilterCondition = new FilterConditionModel();
return oFilterCondition && oFilterCondition.parse(aData) ?
oFilterCondition : null;
})));
}
this.name.error(false);
this.actionValue.error(false);
this.actionType(Utils.pString(oItem.ActionType));
return true;
};
this.actionValue(Utils.pString(oItem.ActionValue));
this.actionValueSecond(Utils.pString(oItem.ActionValueSecond));
this.actionValueThird(Utils.pString(oItem.ActionValueThird));
this.actionValueFourth(Utils.pString(oItem.ActionValueFourth));
FilterModel.prototype.toJson = function ()
{
return {
ID: this.id,
Enabled: this.enabled() ? '1' : '0',
Name: this.name(),
ConditionsType: this.conditionsType(),
Conditions: _.map(this.conditions(), function (oItem) {
return oItem.toJson();
}),
this.actionNoStop(!oItem.Stop);
this.actionKeep(!!oItem.Keep);
this.actionMarkAsRead(!!oItem.MarkAsRead);
ActionValue: this.actionValue(),
ActionValueSecond: this.actionValueSecond(),
ActionValueThird: this.actionValueThird(),
ActionValueFourth: this.actionValueFourth(),
ActionType: this.actionType(),
bResult = true;
}
Stop: this.actionNoStop() ? '0' : '1',
Keep: this.actionKeep() ? '1' : '0',
MarkAsRead: this.actionMarkAsRead() ? '1' : '0'
};
};
return bResult;
};
FilterModel.prototype.addCondition = function ()
{
this.conditions.push(new FilterConditionModel());
};
FilterModel.prototype.cloneSelf = function()
{
var oClone = new FilterModel();
FilterModel.prototype.removeCondition = function (oConditionToDelete)
{
this.conditions.remove(oConditionToDelete);
Utils.delegateRunOnDestroy(oConditionToDelete);
};
oClone.id = this.id;
FilterModel.prototype.setRecipients = function ()
{
this.actionValueFourth(require('Stores/User/Account').accountsEmails().join(', '));
};
oClone.enabled(this.enabled());
FilterModel.prototype.parse = function (oItem)
{
var bResult = false;
if (oItem && 'Object/Filter' === oItem['@Object'])
{
this.id = Utils.pString(oItem.ID);
this.name(Utils.pString(oItem.Name));
this.enabled(!!oItem.Enabled);
oClone.name(this.name());
oClone.name.error(this.name.error());
this.conditionsType(Utils.pString(oItem.ConditionsType));
oClone.conditionsType(this.conditionsType());
this.conditions([]);
oClone.actionMarkAsRead(this.actionMarkAsRead());
if (Utils.isNonEmptyArray(oItem.Conditions))
{
this.conditions(_.compact(_.map(oItem.Conditions, function (aData) {
var oFilterCondition = new FilterConditionModel();
return oFilterCondition && oFilterCondition.parse(aData) ?
oFilterCondition : null;
})));
}
oClone.actionType(this.actionType());
this.actionType(Utils.pString(oItem.ActionType));
oClone.actionValue(this.actionValue());
oClone.actionValue.error(this.actionValue.error());
this.actionValue(Utils.pString(oItem.ActionValue));
this.actionValueSecond(Utils.pString(oItem.ActionValueSecond));
this.actionValueThird(Utils.pString(oItem.ActionValueThird));
this.actionValueFourth(Utils.pString(oItem.ActionValueFourth));
oClone.actionValueSecond(this.actionValueSecond());
oClone.actionValueThird(this.actionValueThird());
oClone.actionValueFourth(this.actionValueFourth());
this.actionNoStop(!oItem.Stop);
this.actionKeep(!!oItem.Keep);
this.actionMarkAsRead(!!oItem.MarkAsRead);
oClone.actionKeep(this.actionKeep());
oClone.actionNoStop(this.actionNoStop());
bResult = true;
}
oClone.conditions(_.map(this.conditions(), function(oCondition) {
return oCondition.cloneSelf();
}));
return bResult;
};
return oClone;
};
FilterModel.prototype.cloneSelf = function ()
{
var oClone = new FilterModel();
oClone.id = this.id;
oClone.enabled(this.enabled());
oClone.name(this.name());
oClone.name.error(this.name.error());
oClone.conditionsType(this.conditionsType());
oClone.actionMarkAsRead(this.actionMarkAsRead());
oClone.actionType(this.actionType());
oClone.actionValue(this.actionValue());
oClone.actionValue.error(this.actionValue.error());
oClone.actionValueSecond(this.actionValueSecond());
oClone.actionValueThird(this.actionValueThird());
oClone.actionValueFourth(this.actionValueFourth());
oClone.actionKeep(this.actionKeep());
oClone.actionNoStop(this.actionNoStop());
oClone.conditions(_.map(this.conditions(), function (oCondition) {
return oCondition.cloneSelf();
}));
return oClone;
};
module.exports = FilterModel;
}());
module.exports = FilterModel;

View file

@ -1,117 +1,110 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
var
_ = require('_'),
ko = require('ko'),
AbstractModel = require('Knoin/AbstractModel');
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
/**
* @constructor
*/
function FilterConditionModel()
{
AbstractModel.call(this, 'FilterConditionModel');
AbstractModel = require('Knoin/AbstractModel')
;
this.field = ko.observable(Enums.FilterConditionField.From);
this.type = ko.observable(Enums.FilterConditionType.Contains);
this.value = ko.observable('');
this.value.error = ko.observable(false);
/**
* @constructor
*/
function FilterConditionModel()
this.valueSecond = ko.observable('');
this.valueSecond.error = ko.observable(false);
this.template = ko.computed(function() {
var sTemplate = '';
switch (this.field())
{
case Enums.FilterConditionField.Size:
sTemplate = 'SettingsFiltersConditionSize';
break;
case Enums.FilterConditionField.Header:
sTemplate = 'SettingsFiltersConditionMore';
break;
default:
sTemplate = 'SettingsFiltersConditionDefault';
break;
}
return sTemplate;
}, this);
this.field.subscribe(function() {
this.value('');
this.valueSecond('');
}, this);
this.regDisposables([this.template]);
}
_.extend(FilterConditionModel.prototype, AbstractModel.prototype);
FilterConditionModel.prototype.verify = function()
{
if ('' === this.value())
{
AbstractModel.call(this, 'FilterConditionModel');
this.field = ko.observable(Enums.FilterConditionField.From);
this.type = ko.observable(Enums.FilterConditionType.Contains);
this.value = ko.observable('');
this.value.error = ko.observable(false);
this.valueSecond = ko.observable('');
this.valueSecond.error = ko.observable(false);
this.template = ko.computed(function () {
var sTemplate = '';
switch (this.field())
{
case Enums.FilterConditionField.Size:
sTemplate = 'SettingsFiltersConditionSize';
break;
case Enums.FilterConditionField.Header:
sTemplate = 'SettingsFiltersConditionMore';
break;
default:
sTemplate = 'SettingsFiltersConditionDefault';
break;
}
return sTemplate;
}, this);
this.field.subscribe(function () {
this.value('');
this.valueSecond('');
}, this);
this.regDisposables([this.template]);
this.value.error(true);
return false;
}
_.extend(FilterConditionModel.prototype, AbstractModel.prototype);
FilterConditionModel.prototype.verify = function ()
if (Enums.FilterConditionField.Header === this.field() && '' === this.valueSecond())
{
if ('' === this.value())
{
this.value.error(true);
return false;
}
this.valueSecond.error(true);
return false;
}
if (Enums.FilterConditionField.Header === this.field() && '' === this.valueSecond())
{
this.valueSecond.error(true);
return false;
}
return true;
};
FilterConditionModel.prototype.parse = function(oItem)
{
if (oItem && oItem.Field && oItem.Type)
{
this.field(Utils.pString(oItem.Field));
this.type(Utils.pString(oItem.Type));
this.value(Utils.pString(oItem.Value));
this.valueSecond(Utils.pString(oItem.ValueSecond));
return true;
}
return false;
};
FilterConditionModel.prototype.toJson = function()
{
return {
Field: this.field(),
Type: this.type(),
Value: this.value(),
ValueSecond: this.valueSecond()
};
};
FilterConditionModel.prototype.parse = function (oItem)
{
if (oItem && oItem.Field && oItem.Type)
{
this.field(Utils.pString(oItem.Field));
this.type(Utils.pString(oItem.Type));
this.value(Utils.pString(oItem.Value));
this.valueSecond(Utils.pString(oItem.ValueSecond));
FilterConditionModel.prototype.cloneSelf = function()
{
var oClone = new FilterConditionModel();
return true;
}
oClone.field(this.field());
oClone.type(this.type());
oClone.value(this.value());
oClone.valueSecond(this.valueSecond());
return false;
};
return oClone;
};
FilterConditionModel.prototype.toJson = function ()
{
return {
Field: this.field(),
Type: this.type(),
Value: this.value(),
ValueSecond: this.valueSecond()
};
};
FilterConditionModel.prototype.cloneSelf = function ()
{
var oClone = new FilterConditionModel();
oClone.field(this.field());
oClone.type(this.type());
oClone.value(this.value());
oClone.valueSecond(this.valueSecond());
return oClone;
};
module.exports = FilterConditionModel;
}());
module.exports = FilterConditionModel;

View file

@ -1,379 +1,367 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Events = require('Common/Events'),
Translator = require('Common/Translator'),
var
_ = require('_'),
ko = require('ko'),
Cache = require('Common/Cache'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Events = require('Common/Events'),
Translator = require('Common/Translator'),
AbstractModel = require('Knoin/AbstractModel');
Cache = require('Common/Cache'),
/**
* @constructor
*/
function FolderModel()
{
AbstractModel.call(this, 'FolderModel');
AbstractModel = require('Knoin/AbstractModel')
;
this.name = ko.observable('');
this.fullName = '';
this.fullNameRaw = '';
this.fullNameHash = '';
this.delimiter = '';
this.namespace = '';
this.deep = 0;
this.interval = 0;
/**
* @constructor
*/
function FolderModel()
{
AbstractModel.call(this, 'FolderModel');
this.selectable = false;
this.existen = true;
this.name = ko.observable('');
this.fullName = '';
this.fullNameRaw = '';
this.fullNameHash = '';
this.delimiter = '';
this.namespace = '';
this.deep = 0;
this.interval = 0;
this.type = ko.observable(Enums.FolderType.User);
this.selectable = false;
this.existen = true;
this.focused = ko.observable(false);
this.selected = ko.observable(false);
this.edited = ko.observable(false);
this.collapsed = ko.observable(true);
this.subScribed = ko.observable(true);
this.checkable = ko.observable(false);
this.subFolders = ko.observableArray([]);
this.deleteAccess = ko.observable(false);
this.actionBlink = ko.observable(false).extend({'falseTimeout': 1000});
this.type = ko.observable(Enums.FolderType.User);
this.nameForEdit = ko.observable('');
this.focused = ko.observable(false);
this.selected = ko.observable(false);
this.edited = ko.observable(false);
this.collapsed = ko.observable(true);
this.subScribed = ko.observable(true);
this.checkable = ko.observable(false);
this.subFolders = ko.observableArray([]);
this.deleteAccess = ko.observable(false);
this.actionBlink = ko.observable(false).extend({'falseTimeout': 1000});
this.privateMessageCountAll = ko.observable(0);
this.privateMessageCountUnread = ko.observable(0);
this.nameForEdit = ko.observable('');
this.collapsedPrivate = ko.observable(true);
}
this.privateMessageCountAll = ko.observable(0);
this.privateMessageCountUnread = ko.observable(0);
_.extend(FolderModel.prototype, AbstractModel.prototype);
this.collapsedPrivate = ko.observable(true);
}
/**
* @static
* @param {AjaxJsonFolder} oJsonFolder
* @returns {?FolderModel}
*/
FolderModel.newInstanceFromJson = function(oJsonFolder)
{
var oFolderModel = new FolderModel();
return oFolderModel.initByJson(oJsonFolder) ? oFolderModel.initComputed() : null;
};
_.extend(FolderModel.prototype, AbstractModel.prototype);
/**
* @returns {FolderModel}
*/
FolderModel.prototype.initComputed = function()
{
var sInboxFolderName = Cache.getFolderInboxName();
/**
* @static
* @param {AjaxJsonFolder} oJsonFolder
* @return {?FolderModel}
*/
FolderModel.newInstanceFromJson = function (oJsonFolder)
{
var oFolderModel = new FolderModel();
return oFolderModel.initByJson(oJsonFolder) ? oFolderModel.initComputed() : null;
};
this.isInbox = ko.computed(function() {
return Enums.FolderType.Inbox === this.type();
}, this);
/**
* @return {FolderModel}
*/
FolderModel.prototype.initComputed = function ()
{
var sInboxFolderName = Cache.getFolderInboxName();
this.hasSubScribedSubfolders = ko.computed(function() {
return !!_.find(this.subFolders(), function(oFolder) {
return (oFolder.subScribed() || oFolder.hasSubScribedSubfolders()) && !oFolder.isSystemFolder();
});
}, this);
this.isInbox = ko.computed(function () {
return Enums.FolderType.Inbox === this.type();
}, this);
this.canBeEdited = ko.computed(function() {
return Enums.FolderType.User === this.type() && this.existen && this.selectable;
}, this);
this.hasSubScribedSubfolders = ko.computed(function () {
return !!_.find(this.subFolders(), function (oFolder) {
return (oFolder.subScribed() || oFolder.hasSubScribedSubfolders()) && !oFolder.isSystemFolder();
});
}, this);
this.visible = ko.computed(function() {
this.canBeEdited = ko.computed(function () {
return Enums.FolderType.User === this.type() && this.existen && this.selectable;
}, this);
var
bSubScribed = this.subScribed(),
bSubFolders = this.hasSubScribedSubfolders();
this.visible = ko.computed(function () {
return (bSubScribed || (bSubFolders && (!this.existen || !this.selectable)));
var
bSubScribed = this.subScribed(),
bSubFolders = this.hasSubScribedSubfolders()
;
}, this);
return (bSubScribed || (bSubFolders && (!this.existen || !this.selectable)));
this.isSystemFolder = ko.computed(function() {
return Enums.FolderType.User !== this.type();
}, this);
}, this);
this.hidden = ko.computed(function() {
this.isSystemFolder = ko.computed(function () {
return Enums.FolderType.User !== this.type();
}, this);
var
bSystem = this.isSystemFolder(),
bSubFolders = this.hasSubScribedSubfolders();
this.hidden = ko.computed(function () {
return (bSystem && !bSubFolders) || (!this.selectable && !bSubFolders);
var
bSystem = this.isSystemFolder(),
bSubFolders = this.hasSubScribedSubfolders()
;
}, this);
return (bSystem && !bSubFolders) || (!this.selectable && !bSubFolders);
this.selectableForFolderList = ko.computed(function() {
return !this.isSystemFolder() && this.selectable;
}, this);
}, this);
this.selectableForFolderList = ko.computed(function () {
return !this.isSystemFolder() && this.selectable;
}, this);
this.messageCountAll = ko.computed({
'read': this.privateMessageCountAll,
'write': function (iValue) {
if (Utils.isPosNumeric(iValue, true))
{
this.privateMessageCountAll(iValue);
}
else
{
this.privateMessageCountAll.valueHasMutated();
}
},
'owner': this
}).extend({'notify': 'always'});
this.messageCountUnread = ko.computed({
'read': this.privateMessageCountUnread,
'write': function (iValue) {
if (Utils.isPosNumeric(iValue, true))
{
this.privateMessageCountUnread(iValue);
}
else
{
this.privateMessageCountUnread.valueHasMutated();
}
},
'owner': this
}).extend({'notify': 'always'});
this.printableUnreadCount = ko.computed(function () {
var
iCount = this.messageCountAll(),
iUnread = this.messageCountUnread(),
iType = this.type()
;
if (0 < iCount)
this.messageCountAll = ko.computed({
'read': this.privateMessageCountAll,
'write': function(iValue) {
if (Utils.isPosNumeric(iValue, true))
{
if (Enums.FolderType.Draft === iType)
{
return '' + iCount;
}
else if (0 < iUnread && Enums.FolderType.Trash !== iType && Enums.FolderType.Archive !== iType && Enums.FolderType.SentItems !== iType)
{
return '' + iUnread;
}
this.privateMessageCountAll(iValue);
}
else
{
this.privateMessageCountAll.valueHasMutated();
}
},
'owner': this
}).extend({'notify': 'always'});
return '';
this.messageCountUnread = ko.computed({
'read': this.privateMessageCountUnread,
'write': function(iValue) {
if (Utils.isPosNumeric(iValue, true))
{
this.privateMessageCountUnread(iValue);
}
else
{
this.privateMessageCountUnread.valueHasMutated();
}
},
'owner': this
}).extend({'notify': 'always'});
}, this);
this.printableUnreadCount = ko.computed(function() {
var
iCount = this.messageCountAll(),
iUnread = this.messageCountUnread(),
iType = this.type();
this.canBeDeleted = ko.computed(function () {
var
bSystem = this.isSystemFolder()
;
return !bSystem && 0 === this.subFolders().length && sInboxFolderName !== this.fullNameRaw;
}, this);
if (0 < iCount)
{
if (Enums.FolderType.Draft === iType)
{
return '' + iCount;
}
else if (0 < iUnread && Enums.FolderType.Trash !== iType && Enums.FolderType.Archive !== iType && Enums.FolderType.SentItems !== iType)
{
return '' + iUnread;
}
}
this.canBeSubScribed = ko.computed(function () {
return !this.isSystemFolder() && this.selectable && sInboxFolderName !== this.fullNameRaw;
}, this);
return '';
this.canBeChecked = this.canBeSubScribed;
}, this);
// this.visible.subscribe(function () {
// Utils.timeOutAction('folder-list-folder-visibility-change', function () {
this.canBeDeleted = ko.computed(function() {
var
bSystem = this.isSystemFolder();
return !bSystem && 0 === this.subFolders().length && sInboxFolderName !== this.fullNameRaw;
}, this);
this.canBeSubScribed = ko.computed(function() {
return !this.isSystemFolder() && this.selectable && sInboxFolderName !== this.fullNameRaw;
}, this);
this.canBeChecked = this.canBeSubScribed;
// this.visible.subscribe(function() {
// Utils.timeOutAction('folder-list-folder-visibility-change', function() {
// Globals.$win.trigger('folder-list-folder-visibility-change');
// }, 100);
// });
this.localName = ko.computed(function () {
this.localName = ko.computed(function() {
Translator.trigger();
Translator.trigger();
var
iType = this.type(),
sName = this.name()
;
if (this.isSystemFolder())
{
switch (iType)
{
case Enums.FolderType.Inbox:
sName = Translator.i18n('FOLDER_LIST/INBOX_NAME');
break;
case Enums.FolderType.SentItems:
sName = Translator.i18n('FOLDER_LIST/SENT_NAME');
break;
case Enums.FolderType.Draft:
sName = Translator.i18n('FOLDER_LIST/DRAFTS_NAME');
break;
case Enums.FolderType.Spam:
sName = Translator.i18n('FOLDER_LIST/SPAM_NAME');
break;
case Enums.FolderType.Trash:
sName = Translator.i18n('FOLDER_LIST/TRASH_NAME');
break;
case Enums.FolderType.Archive:
sName = Translator.i18n('FOLDER_LIST/ARCHIVE_NAME');
break;
}
}
return sName;
}, this);
this.manageFolderSystemName = ko.computed(function () {
Translator.trigger();
var
sSuffix = '',
iType = this.type(),
sName = this.name()
;
if (this.isSystemFolder())
{
switch (iType)
{
case Enums.FolderType.Inbox:
sSuffix = '(' + Translator.i18n('FOLDER_LIST/INBOX_NAME') + ')';
break;
case Enums.FolderType.SentItems:
sSuffix = '(' + Translator.i18n('FOLDER_LIST/SENT_NAME') + ')';
break;
case Enums.FolderType.Draft:
sSuffix = '(' + Translator.i18n('FOLDER_LIST/DRAFTS_NAME') + ')';
break;
case Enums.FolderType.Spam:
sSuffix = '(' + Translator.i18n('FOLDER_LIST/SPAM_NAME') + ')';
break;
case Enums.FolderType.Trash:
sSuffix = '(' + Translator.i18n('FOLDER_LIST/TRASH_NAME') + ')';
break;
case Enums.FolderType.Archive:
sSuffix = '(' + Translator.i18n('FOLDER_LIST/ARCHIVE_NAME') + ')';
break;
}
}
if ('' !== sSuffix && '(' + sName + ')' === sSuffix || '(inbox)' === sSuffix.toLowerCase())
{
sSuffix = '';
}
return sSuffix;
}, this);
this.collapsed = ko.computed({
'read': function () {
return !this.hidden() && this.collapsedPrivate();
},
'write': function (mValue) {
this.collapsedPrivate(mValue);
},
'owner': this
});
this.hasUnreadMessages = ko.computed(function () {
return 0 < this.messageCountUnread() && '' !== this.printableUnreadCount();
}, this);
this.hasSubScribedUnreadMessagesSubfolders = ko.computed(function () {
return !!_.find(this.subFolders(), function (oFolder) {
return oFolder.hasUnreadMessages() || oFolder.hasSubScribedUnreadMessagesSubfolders();
});
}, this);
// subscribe
this.name.subscribe(function (sValue) {
this.nameForEdit(sValue);
}, this);
this.edited.subscribe(function (bValue) {
if (bValue)
{
this.nameForEdit(this.name());
}
}, this);
this.messageCountUnread.subscribe(function (iUnread) {
if (Enums.FolderType.Inbox === this.type())
{
Events.pub('mailbox.inbox-unread-count', [iUnread]);
}
}, this);
return this;
};
FolderModel.prototype.fullName = '';
FolderModel.prototype.fullNameRaw = '';
FolderModel.prototype.fullNameHash = '';
FolderModel.prototype.delimiter = '';
FolderModel.prototype.namespace = '';
FolderModel.prototype.deep = 0;
FolderModel.prototype.interval = 0;
/**
* @return {string}
*/
FolderModel.prototype.collapsedCss = function ()
{
return this.hasSubScribedSubfolders() ?
(this.collapsed() ? 'icon-right-mini e-collapsed-sign' : 'icon-down-mini e-collapsed-sign') : 'icon-none e-collapsed-sign';
};
/**
* @param {AjaxJsonFolder} oJsonFolder
* @return {boolean}
*/
FolderModel.prototype.initByJson = function (oJsonFolder)
{
var
bResult = false,
sInboxFolderName = Cache.getFolderInboxName()
;
iType = this.type(),
sName = this.name();
if (oJsonFolder && 'Object/Folder' === oJsonFolder['@Object'])
if (this.isSystemFolder())
{
this.name(oJsonFolder.Name);
this.delimiter = oJsonFolder.Delimiter;
this.fullName = oJsonFolder.FullName;
this.fullNameRaw = oJsonFolder.FullNameRaw;
this.fullNameHash = oJsonFolder.FullNameHash;
this.deep = oJsonFolder.FullNameRaw.split(this.delimiter).length - 1;
this.selectable = !!oJsonFolder.IsSelectable;
this.existen = !!oJsonFolder.IsExists;
this.subScribed(!!oJsonFolder.IsSubscribed);
this.checkable(!!oJsonFolder.Checkable);
this.type(sInboxFolderName === this.fullNameRaw ? Enums.FolderType.Inbox : Enums.FolderType.User);
bResult = true;
switch (iType)
{
case Enums.FolderType.Inbox:
sName = Translator.i18n('FOLDER_LIST/INBOX_NAME');
break;
case Enums.FolderType.SentItems:
sName = Translator.i18n('FOLDER_LIST/SENT_NAME');
break;
case Enums.FolderType.Draft:
sName = Translator.i18n('FOLDER_LIST/DRAFTS_NAME');
break;
case Enums.FolderType.Spam:
sName = Translator.i18n('FOLDER_LIST/SPAM_NAME');
break;
case Enums.FolderType.Trash:
sName = Translator.i18n('FOLDER_LIST/TRASH_NAME');
break;
case Enums.FolderType.Archive:
sName = Translator.i18n('FOLDER_LIST/ARCHIVE_NAME');
break;
// no default
}
}
return bResult;
};
return sName;
/**
* @return {string}
*/
FolderModel.prototype.printableFullName = function ()
}, this);
this.manageFolderSystemName = ko.computed(function() {
Translator.trigger();
var
sSuffix = '',
iType = this.type(),
sName = this.name();
if (this.isSystemFolder())
{
switch (iType)
{
case Enums.FolderType.Inbox:
sSuffix = '(' + Translator.i18n('FOLDER_LIST/INBOX_NAME') + ')';
break;
case Enums.FolderType.SentItems:
sSuffix = '(' + Translator.i18n('FOLDER_LIST/SENT_NAME') + ')';
break;
case Enums.FolderType.Draft:
sSuffix = '(' + Translator.i18n('FOLDER_LIST/DRAFTS_NAME') + ')';
break;
case Enums.FolderType.Spam:
sSuffix = '(' + Translator.i18n('FOLDER_LIST/SPAM_NAME') + ')';
break;
case Enums.FolderType.Trash:
sSuffix = '(' + Translator.i18n('FOLDER_LIST/TRASH_NAME') + ')';
break;
case Enums.FolderType.Archive:
sSuffix = '(' + Translator.i18n('FOLDER_LIST/ARCHIVE_NAME') + ')';
break;
// no default
}
}
if ('' !== sSuffix && '(' + sName + ')' === sSuffix || '(inbox)' === sSuffix.toLowerCase())
{
sSuffix = '';
}
return sSuffix;
}, this);
this.collapsed = ko.computed({
'read': function() {
return !this.hidden() && this.collapsedPrivate();
},
'write': function(mValue) {
this.collapsedPrivate(mValue);
},
'owner': this
});
this.hasUnreadMessages = ko.computed(function() {
return 0 < this.messageCountUnread() && '' !== this.printableUnreadCount();
}, this);
this.hasSubScribedUnreadMessagesSubfolders = ko.computed(function() {
return !!_.find(this.subFolders(), function(oFolder) {
return oFolder.hasUnreadMessages() || oFolder.hasSubScribedUnreadMessagesSubfolders();
});
}, this);
// subscribe
this.name.subscribe(function(sValue) {
this.nameForEdit(sValue);
}, this);
this.edited.subscribe(function(bValue) {
if (bValue)
{
this.nameForEdit(this.name());
}
}, this);
this.messageCountUnread.subscribe(function(iUnread) {
if (Enums.FolderType.Inbox === this.type())
{
Events.pub('mailbox.inbox-unread-count', [iUnread]);
}
}, this);
return this;
};
FolderModel.prototype.fullName = '';
FolderModel.prototype.fullNameRaw = '';
FolderModel.prototype.fullNameHash = '';
FolderModel.prototype.delimiter = '';
FolderModel.prototype.namespace = '';
FolderModel.prototype.deep = 0;
FolderModel.prototype.interval = 0;
/**
* @returns {string}
*/
FolderModel.prototype.collapsedCss = function()
{
return this.hasSubScribedSubfolders() ?
(this.collapsed() ? 'icon-right-mini e-collapsed-sign' : 'icon-down-mini e-collapsed-sign') : 'icon-none e-collapsed-sign';
};
/**
* @param {AjaxJsonFolder} oJsonFolder
* @returns {boolean}
*/
FolderModel.prototype.initByJson = function(oJsonFolder)
{
var
bResult = false,
sInboxFolderName = Cache.getFolderInboxName();
if (oJsonFolder && 'Object/Folder' === oJsonFolder['@Object'])
{
return this.fullName.split(this.delimiter).join(' / ');
};
this.name(oJsonFolder.Name);
this.delimiter = oJsonFolder.Delimiter;
this.fullName = oJsonFolder.FullName;
this.fullNameRaw = oJsonFolder.FullNameRaw;
this.fullNameHash = oJsonFolder.FullNameHash;
this.deep = oJsonFolder.FullNameRaw.split(this.delimiter).length - 1;
this.selectable = !!oJsonFolder.IsSelectable;
this.existen = !!oJsonFolder.IsExists;
module.exports = FolderModel;
this.subScribed(!!oJsonFolder.IsSubscribed);
this.checkable(!!oJsonFolder.Checkable);
}());
this.type(sInboxFolderName === this.fullNameRaw ? Enums.FolderType.Inbox : Enums.FolderType.User);
bResult = true;
}
return bResult;
};
/**
* @returns {string}
*/
FolderModel.prototype.printableFullName = function()
{
return this.fullName.split(this.delimiter).join(' / ');
};
module.exports = FolderModel;

View file

@ -1,52 +1,44 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
AbstractModel = require('Knoin/AbstractModel');
/**
* @constructor
* @param {string} sId
* @param {string} sEmail
*/
function IdentityModel(sId, sEmail)
{
AbstractModel.call(this, 'IdentityModel');
this.id = ko.observable(sId || '');
this.email = ko.observable(sEmail);
this.name = ko.observable('');
this.replyTo = ko.observable('');
this.bcc = ko.observable('');
this.signature = ko.observable('');
this.signatureInsertBefore = ko.observable(false);
this.deleteAccess = ko.observable(false);
this.canBeDeleted = ko.computed(function() {
return '' !== this.id();
}, this);
}
_.extend(IdentityModel.prototype, AbstractModel.prototype);
IdentityModel.prototype.formattedName = function()
{
var
_ = require('_'),
ko = require('ko'),
sName = this.name(),
sEmail = this.email();
AbstractModel = require('Knoin/AbstractModel')
;
return ('' !== sName) ? sName + ' (' + sEmail + ')' : sEmail;
};
/**
* @param {string} sId
* @param {string} sEmail
* @constructor
*/
function IdentityModel(sId, sEmail)
{
AbstractModel.call(this, 'IdentityModel');
this.id = ko.observable(sId || '');
this.email = ko.observable(sEmail);
this.name = ko.observable('');
this.replyTo = ko.observable('');
this.bcc = ko.observable('');
this.signature = ko.observable('');
this.signatureInsertBefore = ko.observable(false);
this.deleteAccess = ko.observable(false);
this.canBeDeleted = ko.computed(function () {
return '' !== this.id();
}, this);
}
_.extend(IdentityModel.prototype, AbstractModel.prototype);
IdentityModel.prototype.formattedName = function ()
{
var
sName = this.name(),
sEmail = this.email()
;
return ('' !== sName) ? sName + ' (' + sEmail + ')' : sEmail;
};
module.exports = IdentityModel;
}());
module.exports = IdentityModel;

File diff suppressed because it is too large Load diff

View file

@ -1,89 +1,80 @@
(function () {
var
_ = require('_'),
'use strict';
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
var
_ = require('_'),
MessageSimpleModel = require('Model/MessageSimple');
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
/**
* @constructor
*/
function MessageFullModel()
{
MessageSimpleModel.call(this, 'MessageFullModel');
}
// MessageHelper = require('Helper/Message').default,
_.extend(MessageFullModel.prototype, MessageSimpleModel.prototype);
MessageSimpleModel = require('Model/MessageSimple')
;
MessageFullModel.prototype.priority = 0;
MessageFullModel.prototype.hash = '';
MessageFullModel.prototype.requestHash = '';
MessageFullModel.prototype.proxy = false;
MessageFullModel.prototype.hasAttachments = false;
/**
* @constructor
*/
function MessageFullModel()
MessageFullModel.prototype.clear = function()
{
MessageSimpleModel.prototype.clear.call(this);
this.priority = 0;
this.hash = '';
this.requestHash = '';
this.proxy = false;
this.hasAttachments = false;
};
/**
* @param {AjaxJsonMessage} oJson
* @returns {boolean}
*/
MessageFullModel.prototype.initByJson = function(oJson)
{
var bResult = false;
if (oJson && 'Object/Message' === oJson['@Object'])
{
MessageSimpleModel.call(this, 'MessageFullModel');
if (MessageSimpleModel.prototype.initByJson.call(this, oJson))
{
this.priority = Utils.pInt(oJson.Priority);
this.priority = Utils.inArray(this.priority, [Enums.MessagePriority.High, Enums.MessagePriority.Low]) ?
this.priority : Enums.MessagePriority.Normal;
this.hash = Utils.pString(oJson.Hash);
this.requestHash = Utils.pString(oJson.RequestHash);
this.proxy = !!oJson.ExternalProxy;
this.hasAttachments = !!oJson.HasAttachments;
bResult = true;
}
}
_.extend(MessageFullModel.prototype, MessageSimpleModel.prototype);
return bResult;
};
MessageFullModel.prototype.priority = 0;
MessageFullModel.prototype.hash = '';
MessageFullModel.prototype.requestHash = '';
MessageFullModel.prototype.proxy = false;
MessageFullModel.prototype.hasAttachments = false;
/**
* @static
* @param {AjaxJsonMessage} oJson
* @returns {?MessageFullModel}
*/
MessageFullModel.newInstanceFromJson = function(oJson)
{
var oItem = oJson ? new MessageFullModel() : null;
return oItem && oItem.initByJson(oJson) ? oItem : null;
};
MessageFullModel.prototype.clear = function ()
{
MessageSimpleModel.prototype.clear.call(this);
this.priority = 0;
this.hash = '';
this.requestHash = '';
this.proxy = false;
this.hasAttachments = false;
};
/**
* @param {AjaxJsonMessage} oJson
* @return {boolean}
*/
MessageFullModel.prototype.initByJson = function (oJson)
{
var bResult = false;
if (oJson && 'Object/Message' === oJson['@Object'])
{
if (MessageSimpleModel.prototype.initByJson.call(this, oJson))
{
this.priority = Utils.pInt(oJson.Priority);
this.priority = Utils.inArray(this.priority, [Enums.MessagePriority.High, Enums.MessagePriority.Low]) ?
this.priority : Enums.MessagePriority.Normal;
this.hash = Utils.pString(oJson.Hash);
this.requestHash = Utils.pString(oJson.RequestHash);
this.proxy = !!oJson.ExternalProxy;
this.hasAttachments = !!oJson.HasAttachments;
bResult = true;
}
}
return bResult;
};
/**
* @static
* @param {AjaxJsonMessage} oJson
* @return {?MessageFullModel}
*/
MessageFullModel.newInstanceFromJson = function (oJson)
{
var oItem = oJson ? new MessageFullModel() : null;
return oItem && oItem.initByJson(oJson) ? oItem : null;
};
module.exports = MessageFullModel;
}());
module.exports = MessageFullModel;

View file

@ -1,174 +1,167 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Utils = require('Common/Utils'),
var
_ = require('_'),
ko = require('ko'),
MessageHelper = require('Helper/Message').default,
Utils = require('Common/Utils'),
AbstractModel = require('Knoin/AbstractModel');
MessageHelper = require('Helper/Message').default,
/**
* @constructor
* @param {string=} sSuperName
*/
function MessageSimpleModel(sSuperName)
{
AbstractModel.call(this, sSuperName || 'MessageSimpleModel');
AbstractModel = require('Knoin/AbstractModel')
;
this.flagged = ko.observable(false);
this.selected = ko.observable(false);
}
/**
* @param {string=} sSuperName
* @constructor
*/
function MessageSimpleModel(sSuperName)
_.extend(MessageSimpleModel.prototype, AbstractModel.prototype);
MessageSimpleModel.prototype.isSimpleMessage = true;
MessageSimpleModel.prototype.folder = '';
MessageSimpleModel.prototype.folderFullNameRaw = '';
MessageSimpleModel.prototype.uid = '';
MessageSimpleModel.prototype.subject = '';
MessageSimpleModel.prototype.to = [];
MessageSimpleModel.prototype.from = [];
MessageSimpleModel.prototype.cc = [];
MessageSimpleModel.prototype.bcc = [];
MessageSimpleModel.prototype.replyTo = [];
MessageSimpleModel.prototype.deliveredTo = [];
MessageSimpleModel.prototype.fromAsString = '';
MessageSimpleModel.prototype.fromAsStringClear = '';
MessageSimpleModel.prototype.toAsString = '';
MessageSimpleModel.prototype.toAsStringClear = '';
MessageSimpleModel.prototype.senderAsString = '';
MessageSimpleModel.prototype.senderAsStringClear = '';
MessageSimpleModel.prototype.size = 0;
MessageSimpleModel.prototype.timestamp = 0;
MessageSimpleModel.prototype.clear = function()
{
this.folder = '';
this.folderFullNameRaw = '';
this.uid = '';
this.subject = '';
this.to = [];
this.from = [];
this.cc = [];
this.bcc = [];
this.replyTo = [];
this.deliveredTo = [];
this.fromAsString = '';
this.fromAsStringClear = '';
this.toAsString = '';
this.toAsStringClear = '';
this.senderAsString = '';
this.senderAsStringClear = '';
this.size = 0;
this.timestamp = 0;
this.flagged(false);
this.selected(false);
};
/**
* @param {Object} oJson
* @returns {boolean}
*/
MessageSimpleModel.prototype.initByJson = function(oJson)
{
var bResult = false;
if (oJson && 'Object/Message' === oJson['@Object'])
{
AbstractModel.call(this, sSuperName || 'MessageSimpleModel');
this.folder = Utils.pString(oJson.Folder);
this.folderFullNameRaw = this.folder;
this.flagged = ko.observable(false);
this.selected = ko.observable(false);
}
this.uid = Utils.pString(oJson.Uid);
_.extend(MessageSimpleModel.prototype, AbstractModel.prototype);
this.subject = Utils.pString(oJson.Subject);
MessageSimpleModel.prototype.__simple_message__ = true;
if (Utils.isArray(oJson.SubjectParts))
{
this.subjectPrefix = Utils.pString(oJson.SubjectParts[0]);
this.subjectSuffix = Utils.pString(oJson.SubjectParts[1]);
}
else
{
this.subjectPrefix = '';
this.subjectSuffix = this.subject;
}
MessageSimpleModel.prototype.folder = '';
MessageSimpleModel.prototype.folderFullNameRaw = '';
this.from = MessageHelper.emailArrayFromJson(oJson.From);
this.to = MessageHelper.emailArrayFromJson(oJson.To);
this.cc = MessageHelper.emailArrayFromJson(oJson.Cc);
this.bcc = MessageHelper.emailArrayFromJson(oJson.Bcc);
this.replyTo = MessageHelper.emailArrayFromJson(oJson.ReplyTo);
this.deliveredTo = MessageHelper.emailArrayFromJson(oJson.DeliveredTo);
MessageSimpleModel.prototype.uid = '';
MessageSimpleModel.prototype.subject = '';
this.size = Utils.pInt(oJson.Size);
this.timestamp = Utils.pInt(oJson.DateTimeStampInUTC);
MessageSimpleModel.prototype.to = [];
MessageSimpleModel.prototype.from = [];
MessageSimpleModel.prototype.cc = [];
MessageSimpleModel.prototype.bcc = [];
MessageSimpleModel.prototype.replyTo = [];
MessageSimpleModel.prototype.deliveredTo = [];
this.fromAsString = MessageHelper.emailArrayToString(this.from, true);
this.fromAsStringClear = MessageHelper.emailArrayToStringClear(this.from);
MessageSimpleModel.prototype.fromAsString = '';
MessageSimpleModel.prototype.fromAsStringClear = '';
MessageSimpleModel.prototype.toAsString = '';
MessageSimpleModel.prototype.toAsStringClear = '';
MessageSimpleModel.prototype.senderAsString = '';
MessageSimpleModel.prototype.senderAsStringClear = '';
MessageSimpleModel.prototype.size = 0;
MessageSimpleModel.prototype.timestamp = 0;
MessageSimpleModel.prototype.clear = function ()
{
this.folder = '';
this.folderFullNameRaw = '';
this.uid = '';
this.subject = '';
this.to = [];
this.from = [];
this.cc = [];
this.bcc = [];
this.replyTo = [];
this.deliveredTo = [];
this.fromAsString = '';
this.fromAsStringClear = '';
this.toAsString = '';
this.toAsStringClear = '';
this.senderAsString = '';
this.senderAsStringClear = '';
this.size = 0;
this.timestamp = 0;
this.toAsString = MessageHelper.emailArrayToString(this.to, true);
this.toAsStringClear = MessageHelper.emailArrayToStringClear(this.to);
this.flagged(false);
this.selected(false);
};
/**
* @param {Object} oJson
* @return {boolean}
*/
MessageSimpleModel.prototype.initByJson = function (oJson)
this.populateSenderEmail();
bResult = true;
}
return bResult;
};
MessageSimpleModel.prototype.populateSenderEmail = function(bDraftOrSentFolder)
{
this.senderAsString = this.fromAsString;
this.senderAsStringClear = this.fromAsStringClear;
if (bDraftOrSentFolder)
{
var bResult = false;
this.senderAsString = this.toAsString;
this.senderAsStringClear = this.toAsStringClear;
}
};
if (oJson && 'Object/Message' === oJson['@Object'])
{
this.folder = Utils.pString(oJson.Folder);
this.folderFullNameRaw = this.folder;
/**
* @returns {Array}
*/
MessageSimpleModel.prototype.threads = function()
{
return [];
};
this.uid = Utils.pString(oJson.Uid);
/**
* @static
* @param {Object} oJson
* @returns {?MessageSimpleModel}
*/
MessageSimpleModel.newInstanceFromJson = function(oJson)
{
var oItem = oJson ? new MessageSimpleModel() : null;
return oItem && oItem.initByJson(oJson) ? oItem : null;
};
this.subject = Utils.pString(oJson.Subject);
if (Utils.isArray(oJson.SubjectParts))
{
this.subjectPrefix = Utils.pString(oJson.SubjectParts[0]);
this.subjectSuffix = Utils.pString(oJson.SubjectParts[1]);
}
else
{
this.subjectPrefix = '';
this.subjectSuffix = this.subject;
}
this.from = MessageHelper.emailArrayFromJson(oJson.From);
this.to = MessageHelper.emailArrayFromJson(oJson.To);
this.cc = MessageHelper.emailArrayFromJson(oJson.Cc);
this.bcc = MessageHelper.emailArrayFromJson(oJson.Bcc);
this.replyTo = MessageHelper.emailArrayFromJson(oJson.ReplyTo);
this.deliveredTo = MessageHelper.emailArrayFromJson(oJson.DeliveredTo);
this.size = Utils.pInt(oJson.Size);
this.timestamp = Utils.pInt(oJson.DateTimeStampInUTC);
this.fromAsString = MessageHelper.emailArrayToString(this.from, true);
this.fromAsStringClear = MessageHelper.emailArrayToStringClear(this.from);
this.toAsString = MessageHelper.emailArrayToString(this.to, true);
this.toAsStringClear = MessageHelper.emailArrayToStringClear(this.to);
this.flagged(false);
this.selected(false);
this.populateSenderEmail();
bResult = true;
}
return bResult;
};
MessageSimpleModel.prototype.populateSenderEmail = function (bDraftOrSentFolder)
{
this.senderAsString = this.fromAsString;
this.senderAsStringClear = this.fromAsStringClear;
if (bDraftOrSentFolder)
{
this.senderAsString = this.toAsString;
this.senderAsStringClear = this.toAsStringClear;
}
};
/**
* @return {Array}
*/
MessageSimpleModel.prototype.threads = function ()
{
return [];
};
/**
* @static
* @param {Object} oJson
* @return {?MessageSimpleModel}
*/
MessageSimpleModel.newInstanceFromJson = function (oJson)
{
var oItem = oJson ? new MessageSimpleModel() : null;
return oItem && oItem.initByJson(oJson) ? oItem : null;
};
module.exports = MessageSimpleModel;
}());
module.exports = MessageSimpleModel;

View file

@ -1,111 +1,103 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Utils = require('Common/Utils'),
var
_ = require('_'),
ko = require('ko'),
PgpStore = require('Stores/User/Pgp'),
Utils = require('Common/Utils'),
AbstractModel = require('Knoin/AbstractModel');
PgpStore = require('Stores/User/Pgp'),
/**
* @constructor
* @param {string} iIndex
* @param {string} sGuID
* @param {string} sID
* @param {array} aIDs
* @param {array} aUserIDs
* @param {array} aEmails
* @param {boolean} bIsPrivate
* @param {string} sArmor
* @param {string} sUserID
*/
function OpenPgpKeyModel(iIndex, sGuID, sID, aIDs, aUserIDs, aEmails, bIsPrivate, sArmor, sUserID)
{
AbstractModel.call(this, 'OpenPgpKeyModel');
AbstractModel = require('Knoin/AbstractModel')
;
this.index = iIndex;
this.id = sID;
this.ids = Utils.isNonEmptyArray(aIDs) ? aIDs : [sID];
this.guid = sGuID;
this.users = aUserIDs;
this.emails = aEmails;
this.armor = sArmor;
this.isPrivate = !!bIsPrivate;
/**
* @param {string} iIndex
* @param {string} sGuID
* @param {string} sID
* @param {array} aIDs
* @param {array} aUserIDs
* @param {array} aEmails
* @param {boolean} bIsPrivate
* @param {string} sArmor
* @param {string} sUserID
* @constructor
*/
function OpenPgpKeyModel(iIndex, sGuID, sID, aIDs, aUserIDs, aEmails, bIsPrivate, sArmor, sUserID)
this.selectUser(sUserID);
this.deleteAccess = ko.observable(false);
}
_.extend(OpenPgpKeyModel.prototype, AbstractModel.prototype);
OpenPgpKeyModel.prototype.index = 0;
OpenPgpKeyModel.prototype.id = '';
OpenPgpKeyModel.prototype.ids = [];
OpenPgpKeyModel.prototype.guid = '';
OpenPgpKeyModel.prototype.user = '';
OpenPgpKeyModel.prototype.users = [];
OpenPgpKeyModel.prototype.email = '';
OpenPgpKeyModel.prototype.emails = [];
OpenPgpKeyModel.prototype.armor = '';
OpenPgpKeyModel.prototype.isPrivate = false;
OpenPgpKeyModel.prototype.getNativeKey = function()
{
var oKey = null;
try
{
AbstractModel.call(this, 'OpenPgpKeyModel');
this.index = iIndex;
this.id = sID;
this.ids = Utils.isNonEmptyArray(aIDs) ? aIDs : [sID];
this.guid = sGuID;
this.users = aUserIDs;
this.emails = aEmails;
this.armor = sArmor;
this.isPrivate = !!bIsPrivate;
this.selectUser(sUserID);
this.deleteAccess = ko.observable(false);
oKey = PgpStore.openpgp.key.readArmored(this.armor);
if (oKey && !oKey.err && oKey.keys && oKey.keys[0])
{
return oKey;
}
}
catch (e)
{
Utils.log(e);
}
_.extend(OpenPgpKeyModel.prototype, AbstractModel.prototype);
return null;
};
OpenPgpKeyModel.prototype.index = 0;
OpenPgpKeyModel.prototype.id = '';
OpenPgpKeyModel.prototype.ids = [];
OpenPgpKeyModel.prototype.guid = '';
OpenPgpKeyModel.prototype.user = '';
OpenPgpKeyModel.prototype.users = [];
OpenPgpKeyModel.prototype.email = '';
OpenPgpKeyModel.prototype.emails = [];
OpenPgpKeyModel.prototype.armor = '';
OpenPgpKeyModel.prototype.isPrivate = false;
OpenPgpKeyModel.prototype.getNativeKeys = function()
{
var oKey = this.getNativeKey();
return oKey && oKey.keys ? oKey.keys : null;
};
OpenPgpKeyModel.prototype.getNativeKey = function ()
OpenPgpKeyModel.prototype.select = function(sPattern, sProperty)
{
if (this[sProperty])
{
var oKey = null;
try
var index = this[sProperty].indexOf(sPattern);
if (-1 !== index)
{
oKey = PgpStore.openpgp.key.readArmored(this.armor);
if (oKey && !oKey.err && oKey.keys && oKey.keys[0])
{
return oKey;
}
}
catch (e)
{
Utils.log(e);
this.user = this.users[index];
this.email = this.emails[index];
}
}
};
return null;
};
OpenPgpKeyModel.prototype.selectUser = function(sUser)
{
this.select(sUser, 'users');
};
OpenPgpKeyModel.prototype.getNativeKeys = function ()
{
var oKey = this.getNativeKey();
return oKey && oKey.keys ? oKey.keys : null;
};
OpenPgpKeyModel.prototype.select = function (sPattern, sProperty)
{
if (this[sProperty])
{
var index = this[sProperty].indexOf(sPattern);
if (index !== -1)
{
this.user = this.users[index];
this.email = this.emails[index];
}
}
};
OpenPgpKeyModel.prototype.selectUser = function (sUser)
{
this.select(sUser, 'users');
};
OpenPgpKeyModel.prototype.selectEmail = function (sEmail)
{
this.select(sEmail, 'emails');
};
module.exports = OpenPgpKeyModel;
}());
OpenPgpKeyModel.prototype.selectEmail = function(sEmail)
{
this.select(sEmail, 'emails');
};
module.exports = OpenPgpKeyModel;

View file

@ -1,77 +1,69 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Utils = require('Common/Utils'),
var
_ = require('_'),
ko = require('ko'),
AbstractModel = require('Knoin/AbstractModel');
Utils = require('Common/Utils'),
/**
* @constructor
* @param {string} sID
* @param {string} sName
* @param {string} sBody
*/
function TemplateModel(sID, sName, sBody)
{
AbstractModel.call(this, 'TemplateModel');
AbstractModel = require('Knoin/AbstractModel')
;
this.id = sID;
this.name = sName;
this.body = sBody;
this.populated = true;
/**
* @constructor
*
* @param {string} sID
* @param {string} sName
* @param {string} sBody
*/
function TemplateModel(sID, sName, sBody)
this.deleteAccess = ko.observable(false);
}
_.extend(TemplateModel.prototype, AbstractModel.prototype);
/**
* @type {string}
*/
TemplateModel.prototype.id = '';
/**
* @type {string}
*/
TemplateModel.prototype.name = '';
/**
* @type {string}
*/
TemplateModel.prototype.body = '';
/**
* @type {boolean}
*/
TemplateModel.prototype.populated = true;
/**
* @type {boolean}
*/
TemplateModel.prototype.parse = function(oItem)
{
var bResult = false;
if (oItem && 'Object/Template' === oItem['@Object'])
{
AbstractModel.call(this, 'TemplateModel');
this.id = Utils.pString(oItem.ID);
this.name = Utils.pString(oItem.Name);
this.body = Utils.pString(oItem.Body);
this.populated = !!oItem.Populated;
this.id = sID;
this.name = sName;
this.body = sBody;
this.populated = true;
this.deleteAccess = ko.observable(false);
bResult = true;
}
_.extend(TemplateModel.prototype, AbstractModel.prototype);
return bResult;
};
/**
* @type {string}
*/
TemplateModel.prototype.id = '';
/**
* @type {string}
*/
TemplateModel.prototype.name = '';
/**
* @type {string}
*/
TemplateModel.prototype.body = '';
/**
* @type {boolean}
*/
TemplateModel.prototype.populated = true;
/**
* @type {boolean}
*/
TemplateModel.prototype.parse = function (oItem)
{
var bResult = false;
if (oItem && 'Object/Template' === oItem['@Object'])
{
this.id = Utils.pString(oItem.ID);
this.name = Utils.pString(oItem.Name);
this.body = Utils.pString(oItem.Body);
this.populated = !!oItem.Populated;
bResult = true;
}
return bResult;
};
module.exports = TemplateModel;
}());
module.exports = TemplateModel;