snappymail/dev/Model/ComposeAttachment.js

124 lines
3.3 KiB
JavaScript
Raw Normal View History

2014-09-05 06:49:03 +08:00
(function () {
2014-08-20 23:03:12 +08:00
2014-08-25 23:49:01 +08:00
'use strict';
2014-08-20 23:03:12 +08:00
var
2014-10-04 19:58:01 +08:00
_ = require('_'),
2014-08-25 23:49:01 +08:00
ko = require('ko'),
2014-10-04 19:58:01 +08:00
Utils = require('Common/Utils'),
AttachmentModel = require('Model/Attachment'),
2014-10-04 19:58:01 +08:00
AbstractModel = require('Knoin/AbstractModel')
2014-08-20 23:03:12 +08:00
;
/**
* @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)
{
2014-10-04 19:58:01 +08:00
AbstractModel.call(this, 'ComposeAttachmentModel');
2014-08-20 23:03:12 +08:00
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;
2014-08-20 23:03:12 +08:00
this.fileName = ko.observable(sFileName);
this.size = ko.observable(Utils.isUnd(nSize) ? null : nSize);
this.tempName = ko.observable('');
this.progress = ko.observable(0);
2014-08-20 23:03:12 +08:00
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();
2015-03-04 05:15:17 +08:00
return 0 === iP ? '' : '' + (98 < iP ? 100 : iP) + '%';
}, this);
this.progressStyle = ko.computed(function () {
var iP = this.progress();
2015-03-04 05:15:17 +08:00
return 0 === iP ? '' : 'width:' + (98 < iP ? 100 : iP) + '%';
}, this);
this.title = ko.computed(function () {
var sError = this.error();
return '' !== sError ? sError : this.fileName();
}, this);
2014-08-20 23:03:12 +08:00
this.friendlySize = ko.computed(function () {
var mSize = this.size();
return null === mSize ? '' : Utils.friendlySize(this.size());
}, this);
2014-10-04 19:58:01 +08:00
this.mimeType = ko.computed(function () {
return Utils.mimeContentType(this.fileName());
}, this);
2014-10-04 19:58:01 +08:00
this.regDisposables([this.friendlySize]);
}
2014-10-04 19:58:01 +08:00
_.extend(ComposeAttachmentModel.prototype, AbstractModel.prototype);
2014-08-20 23:03:12 +08:00
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.emptyFunction;
/**
* @param {AjaxJsonComposeAttachment} oJsonAttachment
* @return {boolean}
2014-08-20 23:03:12 +08:00
*/
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;
bResult = true;
}
return bResult;
};
/**
* @return {string}
*/
ComposeAttachmentModel.prototype.iconClass = function ()
{
2015-01-09 07:31:31 +08:00
return AttachmentModel.staticIconClassHelper(this.mimeType())[0];
};
2015-01-09 07:31:31 +08:00
/**
* @return {string}
*/
ComposeAttachmentModel.prototype.iconText = function ()
{
return AttachmentModel.staticIconClassHelper(this.mimeType())[1];
};
2014-08-20 23:03:12 +08:00
module.exports = ComposeAttachmentModel;
2014-09-05 06:49:03 +08:00
}());