ko cleaning up

This commit is contained in:
RainLoop Team 2014-10-04 15:58:01 +04:00
parent fcac46f60e
commit d8321a522e
25 changed files with 396 additions and 131 deletions

View file

@ -4,9 +4,12 @@
'use strict';
var
_ = require('_'),
ko = require('ko'),
Utils = require('Common/Utils')
Utils = require('Common/Utils'),
AbstractModel = require('Knoin/AbstractModel')
;
/**
@ -17,12 +20,16 @@
*/
function AccountModel(sEmail, bCanBeDelete)
{
AbstractModel.call(this, 'AccountModel');
this.email = sEmail;
this.deleteAccess = ko.observable(false);
this.canBeDalete = ko.observable(Utils.isUnd(bCanBeDelete) ? true : !!bCanBeDelete);
}
_.extend(AccountModel.prototype, AbstractModel.prototype);
/**
* @type {string}
*/

View file

@ -5,10 +5,13 @@
var
window = require('window'),
_ = require('_'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
LinkBuilder = require('Common/LinkBuilder')
LinkBuilder = require('Common/LinkBuilder'),
AbstractModel = require('Knoin/AbstractModel')
;
/**
@ -16,6 +19,8 @@
*/
function AttachmentModel()
{
AbstractModel.call(this, 'AttachmentModel');
this.mimeType = '';
this.fileName = '';
this.estimatedSize = 0;
@ -31,6 +36,8 @@
this.mimeIndex = '';
}
_.extend(AttachmentModel.prototype, AbstractModel.prototype);
/**
* @static
* @param {AjaxJsonAttachment} oJsonAttachment

View file

@ -4,9 +4,12 @@
'use strict';
var
_ = require('_'),
ko = require('ko'),
Utils = require('Common/Utils')
Utils = require('Common/Utils'),
AbstractModel = require('Knoin/AbstractModel')
;
/**
@ -21,6 +24,8 @@
*/
function ComposeAttachmentModel(sId, sFileName, nSize, bInline, bLinked, sCID, sContentLocation)
{
AbstractModel.call(this, 'ComposeAttachmentModel');
this.id = sId;
this.isInline = Utils.isUnd(bInline) ? false : !!bInline;
this.isLinked = Utils.isUnd(bLinked) ? false : !!bLinked;
@ -42,8 +47,12 @@
var mSize = this.size();
return null === mSize ? '' : Utils.friendlySize(this.size());
}, this);
this.regDisposables([this.friendlySize]);
}
_.extend(ComposeAttachmentModel.prototype, AbstractModel.prototype);
ComposeAttachmentModel.prototype.id = '';
ComposeAttachmentModel.prototype.isInline = false;
ComposeAttachmentModel.prototype.isLinked = false;

View file

@ -9,7 +9,9 @@
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
LinkBuilder = require('Common/LinkBuilder')
LinkBuilder = require('Common/LinkBuilder'),
AbstractModel = require('Knoin/AbstractModel')
;
/**
@ -17,6 +19,8 @@
*/
function ContactModel()
{
AbstractModel.call(this, 'ContactModel');
this.idContact = 0;
this.display = '';
this.properties = [];
@ -28,6 +32,8 @@
this.deleted = ko.observable(false);
}
_.extend(ContactModel.prototype, AbstractModel.prototype);
/**
* @return {Array|null}
*/

View file

@ -4,10 +4,13 @@
'use strict';
var
_ = require('_'),
ko = require('ko'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils')
Utils = require('Common/Utils'),
AbstractModel = require('Knoin/AbstractModel')
;
/**
@ -20,6 +23,8 @@
*/
function ContactPropertyModel(iType, sTypeStr, sValue, bFocused, sPlaceholder)
{
AbstractModel.call(this, 'ContactPropertyModel');
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);
@ -35,8 +40,12 @@
this.largeValue = ko.computed(function () {
return Enums.ContactPropertyType.Note === this.type();
}, this);
this.regDisposables([this.placeholderValue, this.largeValue]);
}
_.extend(ContactPropertyModel.prototype, AbstractModel.prototype);
module.exports = ContactPropertyModel;
}());

View file

@ -4,11 +4,14 @@
'use strict';
var
_ = require('_'),
ko = require('ko'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
FilterConditionModel = require('Model/FilterCondition')
FilterConditionModel = require('Model/FilterCondition'),
AbstractModel = require('Knoin/AbstractModel')
;
/**
@ -16,6 +19,8 @@
*/
function FilterModel()
{
AbstractModel.call(this, 'FilterModel');
this.isNew = ko.observable(true);
this.enabled = ko.observable(true);
@ -25,9 +30,9 @@
this.conditions = ko.observableArray([]);
this.conditions.subscribe(function () {
this.regDisposables(this.conditions.subscribe(function () {
Utils.windowResize();
});
}));
// Actions
this.actionMarkAsRead = ko.observable(false);
@ -69,8 +74,12 @@
return sTemplate;
}, this);
this.regDisposables([this.actionMarkAsReadVisiblity, this.actionTemplate]);
}
_.extend(FilterModel.prototype, AbstractModel.prototype);
FilterModel.prototype.addCondition = function ()
{
this.conditions.push(new FilterConditionModel(this.conditions));

View file

@ -4,9 +4,12 @@
'use strict';
var
_ = require('_'),
ko = require('ko'),
Enums = require('Common/Enums')
Enums = require('Common/Enums'),
AbstractModel = require('Knoin/AbstractModel')
;
/**
@ -15,6 +18,8 @@
*/
function FilterConditionModel(oKoList)
{
AbstractModel.call(this, 'FilterConditionModel');
this.parentList = oKoList;
this.field = ko.observable(Enums.FilterConditionField.From);
@ -50,8 +55,12 @@
return sTemplate;
}, this);
this.regDisposables([this.template]);
}
_.extend(FilterConditionModel.prototype, AbstractModel.prototype);
FilterConditionModel.prototype.removeSelf = function ()
{
this.parentList.remove(this);

View file

@ -10,7 +10,9 @@
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
Events = require('Common/Events')
Events = require('Common/Events'),
AbstractModel = require('Knoin/AbstractModel')
;
/**
@ -18,6 +20,8 @@
*/
function FolderModel()
{
AbstractModel.call(this, 'FolderModel');
this.name = ko.observable('');
this.fullName = '';
this.fullNameRaw = '';
@ -49,6 +53,8 @@
this.collapsedPrivate = ko.observable(true);
}
_.extend(FolderModel.prototype, AbstractModel.prototype);
/**
* @static
* @param {AjaxJsonFolder} oJsonFolder

View file

@ -4,9 +4,12 @@
'use strict';
var
_ = require('_'),
ko = require('ko'),
Utils = require('Common/Utils')
Utils = require('Common/Utils'),
AbstractModel = require('Knoin/AbstractModel')
;
/**
@ -17,6 +20,8 @@
*/
function IdentityModel(sId, sEmail, bCanBeDelete)
{
AbstractModel.call(this, 'IdentityModel');
this.id = sId;
this.email = ko.observable(sEmail);
this.name = ko.observable('');
@ -27,6 +32,8 @@
this.canBeDalete = ko.observable(bCanBeDelete);
}
_.extend(IdentityModel.prototype, AbstractModel.prototype);
IdentityModel.prototype.formattedName = function ()
{
var sName = this.name();

View file

@ -16,7 +16,9 @@
LinkBuilder = require('Common/LinkBuilder'),
EmailModel = require('Model/Email'),
AttachmentModel = require('Model/Attachment')
AttachmentModel = require('Model/Attachment'),
AbstractModel = require('Knoin/AbstractModel')
;
/**
@ -24,6 +26,8 @@
*/
function MessageModel()
{
AbstractModel.call(this, 'MessageModel');
this.folderFullNameRaw = '';
this.uid = '';
this.hash = '';
@ -68,9 +72,9 @@
this.checked = ko.observable(false);
this.hasAttachments = ko.observable(false);
this.attachmentsMainType = ko.observable('');
this.moment = ko.observable(moment(moment.unix(0)));
this.attachmentIconClass = ko.computed(function () {
var sClass = '';
if (this.hasAttachments())
@ -102,10 +106,10 @@
this.momentDate = Utils.createMomentDate(this);
this.momentShortDate = Utils.createMomentShortDate(this);
this.dateTimeStampInUTC.subscribe(function (iValue) {
this.regDisposables(this.dateTimeStampInUTC.subscribe(function (iValue) {
var iNow = moment().unix();
this.moment(moment.unix(iNow < iValue ? iNow : iValue));
}, this);
}, this));
this.body = null;
this.plainRaw = '';
@ -139,8 +143,12 @@
var iCount = this.threadsLen();
return 0 === this.parentUid() && 0 < iCount ? iCount + 1 : '';
}, this);
this.regDisposables([this.attachmentIconClass, this.fullFormatDateValue, this.threadsLenResult]);
}
_.extend(MessageModel.prototype, AbstractModel.prototype);
/**
* @static
* @param {AjaxJsonMessage} oJsonMessage

View file

@ -4,7 +4,10 @@
'use strict';
var
ko = require('ko')
_ = require('_'),
ko = require('ko'),
AbstractModel = require('Knoin/AbstractModel')
;
/**
@ -19,6 +22,8 @@
*/
function OpenPgpKeyModel(iIndex, sGuID, sID, sUserID, sEmail, bIsPrivate, sArmor)
{
AbstractModel.call(this, 'OpenPgpKeyModel');
this.index = iIndex;
this.id = sID;
this.guid = sGuID;
@ -30,6 +35,8 @@
this.deleteAccess = ko.observable(false);
}
_.extend(OpenPgpKeyModel.prototype, AbstractModel.prototype);
OpenPgpKeyModel.prototype.index = 0;
OpenPgpKeyModel.prototype.id = '';
OpenPgpKeyModel.prototype.guid = '';