|
|
@ -29,20 +29,24 @@ var _overlay_manager = require('./overlay_manager'); |
|
|
|
|
|
|
|
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var DEFAULT_FIELD_CONTENT = '-'; |
|
|
|
|
|
|
|
|
|
|
|
var PDFDocumentProperties = function () { |
|
|
|
var PDFDocumentProperties = function () { |
|
|
|
function PDFDocumentProperties(options) { |
|
|
|
function PDFDocumentProperties(_ref) { |
|
|
|
|
|
|
|
var overlayName = _ref.overlayName, |
|
|
|
|
|
|
|
fields = _ref.fields, |
|
|
|
|
|
|
|
container = _ref.container, |
|
|
|
|
|
|
|
closeButton = _ref.closeButton; |
|
|
|
|
|
|
|
|
|
|
|
_classCallCheck(this, PDFDocumentProperties); |
|
|
|
_classCallCheck(this, PDFDocumentProperties); |
|
|
|
|
|
|
|
|
|
|
|
this.overlayName = options.overlayName; |
|
|
|
this.overlayName = overlayName; |
|
|
|
this.fields = options.fields; |
|
|
|
this.fields = fields; |
|
|
|
this.container = options.container; |
|
|
|
this.container = container; |
|
|
|
this.rawFileSize = 0; |
|
|
|
this._reset(); |
|
|
|
this.url = null; |
|
|
|
if (closeButton) { |
|
|
|
this.pdfDocument = null; |
|
|
|
closeButton.addEventListener('click', this.close.bind(this)); |
|
|
|
if (options.closeButton) { |
|
|
|
|
|
|
|
options.closeButton.addEventListener('click', this.close.bind(this)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
this._dataAvailableCapability = (0, _pdfjs.createPromiseCapability)(); |
|
|
|
|
|
|
|
_overlay_manager.OverlayManager.register(this.overlayName, this.container, this.close.bind(this)); |
|
|
|
_overlay_manager.OverlayManager.register(this.overlayName, this.container, this.close.bind(this)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -51,8 +55,47 @@ var PDFDocumentProperties = function () { |
|
|
|
value: function open() { |
|
|
|
value: function open() { |
|
|
|
var _this = this; |
|
|
|
var _this = this; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var freezeFieldData = function freezeFieldData(data) { |
|
|
|
|
|
|
|
Object.defineProperty(_this, 'fieldData', { |
|
|
|
|
|
|
|
value: Object.freeze(data), |
|
|
|
|
|
|
|
writable: false, |
|
|
|
|
|
|
|
enumerable: true, |
|
|
|
|
|
|
|
configurable: true |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
Promise.all([_overlay_manager.OverlayManager.open(this.overlayName), this._dataAvailableCapability.promise]).then(function () { |
|
|
|
Promise.all([_overlay_manager.OverlayManager.open(this.overlayName), this._dataAvailableCapability.promise]).then(function () { |
|
|
|
_this._getProperties(); |
|
|
|
if (_this.fieldData) { |
|
|
|
|
|
|
|
_this._updateUI(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
_this.pdfDocument.getMetadata().then(function (_ref2) { |
|
|
|
|
|
|
|
var info = _ref2.info, |
|
|
|
|
|
|
|
metadata = _ref2.metadata; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
freezeFieldData({ |
|
|
|
|
|
|
|
'fileName': (0, _ui_utils.getPDFFileNameFromURL)(_this.url), |
|
|
|
|
|
|
|
'fileSize': _this._parseFileSize(_this.maybeFileSize), |
|
|
|
|
|
|
|
'title': info.Title, |
|
|
|
|
|
|
|
'author': info.Author, |
|
|
|
|
|
|
|
'subject': info.Subject, |
|
|
|
|
|
|
|
'keywords': info.Keywords, |
|
|
|
|
|
|
|
'creationDate': _this._parseDate(info.CreationDate), |
|
|
|
|
|
|
|
'modificationDate': _this._parseDate(info.ModDate), |
|
|
|
|
|
|
|
'creator': info.Creator, |
|
|
|
|
|
|
|
'producer': info.Producer, |
|
|
|
|
|
|
|
'version': info.PDFFormatVersion, |
|
|
|
|
|
|
|
'pageCount': _this.pdfDocument.numPages |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
_this._updateUI(); |
|
|
|
|
|
|
|
return _this.pdfDocument.getDownloadInfo(); |
|
|
|
|
|
|
|
}).then(function (_ref3) { |
|
|
|
|
|
|
|
var length = _ref3.length; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var data = (0, _ui_utils.cloneObj)(_this.fieldData); |
|
|
|
|
|
|
|
data['fileSize'] = _this._parseFileSize(length); |
|
|
|
|
|
|
|
freezeFieldData(data); |
|
|
|
|
|
|
|
_this._updateUI(); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
@ -61,66 +104,60 @@ var PDFDocumentProperties = function () { |
|
|
|
_overlay_manager.OverlayManager.close(this.overlayName); |
|
|
|
_overlay_manager.OverlayManager.close(this.overlayName); |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: 'setFileSize', |
|
|
|
key: 'setDocument', |
|
|
|
value: function setFileSize(fileSize) { |
|
|
|
value: function setDocument(pdfDocument, url) { |
|
|
|
if (fileSize > 0) { |
|
|
|
if (this.pdfDocument) { |
|
|
|
this.rawFileSize = fileSize; |
|
|
|
this._reset(); |
|
|
|
|
|
|
|
this._updateUI(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!pdfDocument) { |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}, { |
|
|
|
|
|
|
|
key: 'setDocumentAndUrl', |
|
|
|
|
|
|
|
value: function setDocumentAndUrl(pdfDocument, url) { |
|
|
|
|
|
|
|
this.pdfDocument = pdfDocument; |
|
|
|
this.pdfDocument = pdfDocument; |
|
|
|
this.url = url; |
|
|
|
this.url = url; |
|
|
|
this._dataAvailableCapability.resolve(); |
|
|
|
this._dataAvailableCapability.resolve(); |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: '_getProperties', |
|
|
|
key: 'setFileSize', |
|
|
|
value: function _getProperties() { |
|
|
|
value: function setFileSize(fileSize) { |
|
|
|
var _this2 = this; |
|
|
|
if (typeof fileSize === 'number' && fileSize > 0) { |
|
|
|
|
|
|
|
this.maybeFileSize = fileSize; |
|
|
|
if (!_overlay_manager.OverlayManager.active) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
this.pdfDocument.getDownloadInfo().then(function (data) { |
|
|
|
} |
|
|
|
if (data.length === _this2.rawFileSize) { |
|
|
|
}, { |
|
|
|
return; |
|
|
|
key: '_reset', |
|
|
|
} |
|
|
|
value: function _reset() { |
|
|
|
_this2.setFileSize(data.length); |
|
|
|
this.pdfDocument = null; |
|
|
|
_this2._updateUI(_this2.fields['fileSize'], _this2._parseFileSize()); |
|
|
|
this.url = null; |
|
|
|
}); |
|
|
|
this.maybeFileSize = 0; |
|
|
|
this.pdfDocument.getMetadata().then(function (data) { |
|
|
|
delete this.fieldData; |
|
|
|
var content = { |
|
|
|
this._dataAvailableCapability = (0, _pdfjs.createPromiseCapability)(); |
|
|
|
'fileName': (0, _ui_utils.getPDFFileNameFromURL)(_this2.url), |
|
|
|
|
|
|
|
'fileSize': _this2._parseFileSize(), |
|
|
|
|
|
|
|
'title': data.info.Title, |
|
|
|
|
|
|
|
'author': data.info.Author, |
|
|
|
|
|
|
|
'subject': data.info.Subject, |
|
|
|
|
|
|
|
'keywords': data.info.Keywords, |
|
|
|
|
|
|
|
'creationDate': _this2._parseDate(data.info.CreationDate), |
|
|
|
|
|
|
|
'modificationDate': _this2._parseDate(data.info.ModDate), |
|
|
|
|
|
|
|
'creator': data.info.Creator, |
|
|
|
|
|
|
|
'producer': data.info.Producer, |
|
|
|
|
|
|
|
'version': data.info.PDFFormatVersion, |
|
|
|
|
|
|
|
'pageCount': _this2.pdfDocument.numPages |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
for (var identifier in content) { |
|
|
|
|
|
|
|
_this2._updateUI(_this2.fields[identifier], content[identifier]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: '_updateUI', |
|
|
|
key: '_updateUI', |
|
|
|
value: function _updateUI(field, content) { |
|
|
|
value: function _updateUI() { |
|
|
|
if (field && content !== undefined && content !== '') { |
|
|
|
var reset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; |
|
|
|
field.textContent = content; |
|
|
|
|
|
|
|
|
|
|
|
if (reset || !this.fieldData) { |
|
|
|
|
|
|
|
for (var id in this.fields) { |
|
|
|
|
|
|
|
this.fields[id].textContent = DEFAULT_FIELD_CONTENT; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (_overlay_manager.OverlayManager.active !== this.overlayName) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (var _id in this.fields) { |
|
|
|
|
|
|
|
var content = this.fieldData[_id]; |
|
|
|
|
|
|
|
this.fields[_id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: '_parseFileSize', |
|
|
|
key: '_parseFileSize', |
|
|
|
value: function _parseFileSize() { |
|
|
|
value: function _parseFileSize() { |
|
|
|
var fileSize = this.rawFileSize, |
|
|
|
var fileSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; |
|
|
|
kb = fileSize / 1024; |
|
|
|
|
|
|
|
|
|
|
|
var kb = fileSize / 1024; |
|
|
|
if (!kb) { |
|
|
|
if (!kb) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} else if (kb < 1024) { |
|
|
|
} else if (kb < 1024) { |
|
|
@ -137,10 +174,10 @@ var PDFDocumentProperties = function () { |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: '_parseDate', |
|
|
|
key: '_parseDate', |
|
|
|
value: function _parseDate(inputDate) { |
|
|
|
value: function _parseDate(inputDate) { |
|
|
|
var dateToParse = inputDate; |
|
|
|
if (!inputDate) { |
|
|
|
if (dateToParse === undefined) { |
|
|
|
return; |
|
|
|
return ''; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var dateToParse = inputDate; |
|
|
|
if (dateToParse.substring(0, 2) === 'D:') { |
|
|
|
if (dateToParse.substring(0, 2) === 'D:') { |
|
|
|
dateToParse = dateToParse.substring(2); |
|
|
|
dateToParse = dateToParse.substring(2); |
|
|
|
} |
|
|
|
} |
|
|
|