2012-12-23 19:45:22 +00:00
|
|
|
/**
|
|
|
|
* @fileoverview TODO
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
goog.provide('camlistore.BlobItem');
|
|
|
|
|
|
|
|
goog.require('goog.dom');
|
|
|
|
goog.require('goog.dom.classes');
|
|
|
|
goog.require('goog.events.EventHandler');
|
|
|
|
goog.require('goog.events.EventType');
|
|
|
|
goog.require('goog.ui.Component');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-12-23 20:43:46 +00:00
|
|
|
* @param {string} blobRef BlobRef for the item.
|
|
|
|
* @param {camlistore.ServerType.IndexerMetaBag} metaBag Maps blobRefs to
|
|
|
|
* metadata for this blob and related blobs.
|
2012-12-23 19:45:22 +00:00
|
|
|
* @param {goog.dom.DomHelper=} opt_domHelper DOM helper to use.
|
|
|
|
*
|
|
|
|
* @extends {goog.ui.Component}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2012-12-23 20:43:46 +00:00
|
|
|
camlistore.BlobItem = function(blobRef, metaBag, opt_domHelper) {
|
2012-12-23 19:45:22 +00:00
|
|
|
goog.base(this, opt_domHelper);
|
|
|
|
|
2012-12-23 20:43:46 +00:00
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.blobRef_ = blobRef;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {camlistore.ServerType.IndexerMetaBag}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.metaBag_ = metaBag;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Metadata for the blobref this item represents.
|
|
|
|
* @type {camlistore.ServerType.IndexerMeta}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.metaData_ = this.metaBag_[this.blobRef_];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Metadata for the underlying blobref for this item; for example, this
|
|
|
|
* would be the blobref that is currently the content for the permanode
|
2012-12-23 21:37:42 +00:00
|
|
|
* specified by 'blobRef'.
|
2012-12-23 20:43:46 +00:00
|
|
|
*
|
|
|
|
* @type {camlistore.ServerType.IndexerMeta}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.resolvedMetaData_ = camlistore.BlobItem.resolve(
|
|
|
|
this.blobRef_, this.metaBag_);
|
|
|
|
|
2012-12-23 19:45:22 +00:00
|
|
|
/**
|
|
|
|
* @type {goog.events.EventHandler}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.eh_ = new goog.events.EventHandler(this);
|
|
|
|
};
|
|
|
|
goog.inherits(camlistore.BlobItem, goog.ui.Component);
|
|
|
|
|
|
|
|
|
2012-12-23 21:37:42 +00:00
|
|
|
/**
|
|
|
|
* TODO: Handle more permanode types.
|
|
|
|
*
|
|
|
|
* @param {string} blobRef string BlobRef to resolve.
|
|
|
|
* @param {camlistore.ServerType.IndexerMetaBag} metaBag Metadata bag to use
|
|
|
|
* for resolving the blobref.
|
|
|
|
* @return {camlistore.ServerType.IndexerMeta}
|
|
|
|
*/
|
2012-12-23 20:43:46 +00:00
|
|
|
camlistore.BlobItem.resolve = function(blobRef, metaBag) {
|
2012-12-23 21:37:42 +00:00
|
|
|
var metaData = metaBag[blobRef];
|
|
|
|
if (metaData.camliType == 'permanode' && !!metaData.permanode &&
|
|
|
|
!!metaData.permanode.attr && !!metaData.permanode.attr.camliContent) {
|
|
|
|
var content = metaData.permanode.attr.camliContent;
|
|
|
|
if (content.length == 1) {
|
|
|
|
return metaBag[content[0]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-23 20:43:46 +00:00
|
|
|
return null;
|
2012-12-23 21:37:42 +00:00
|
|
|
|
2012-12-23 20:43:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-12-23 21:37:42 +00:00
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2012-12-23 20:43:46 +00:00
|
|
|
camlistore.BlobItem.prototype.getThumbSrc_ = function() {
|
|
|
|
// TODO(bslatkin): Make this prefix configured by globals, discovered by
|
|
|
|
// the page at initialization.
|
|
|
|
return '../' + this.metaData_.thumbnailSrc;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-12-23 21:37:42 +00:00
|
|
|
/**
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2012-12-23 20:43:46 +00:00
|
|
|
camlistore.BlobItem.prototype.getThumbHeight_ = function() {
|
|
|
|
return this.metaData_.thumbnailHeight;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-12-23 21:37:42 +00:00
|
|
|
/**
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2012-12-23 20:43:46 +00:00
|
|
|
camlistore.BlobItem.prototype.getThumbWidth_ = function() {
|
|
|
|
return this.metaData_.thumbnailWidth;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-12-23 21:37:42 +00:00
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2012-12-23 20:43:46 +00:00
|
|
|
camlistore.BlobItem.prototype.getTitle_ = function() {
|
2012-12-23 21:37:42 +00:00
|
|
|
if (this.resolvedMetaData_ && this.resolvedMetaData_.camliType == 'file' &&
|
|
|
|
!!this.resolvedMetaData_.file) {
|
|
|
|
return this.resolvedMetaData_.file.fileName;
|
|
|
|
}
|
|
|
|
return 'Unknown title';
|
2012-12-23 20:43:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-12-23 19:45:22 +00:00
|
|
|
/**
|
|
|
|
* Creates an initial DOM representation for the component.
|
|
|
|
*/
|
|
|
|
camlistore.BlobItem.prototype.createDom = function() {
|
|
|
|
this.decorateInternal(this.dom_.createElement('div'));
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decorates an existing HTML DIV element.
|
|
|
|
* @param {Element} element The DIV element to decorate.
|
|
|
|
*/
|
|
|
|
camlistore.BlobItem.prototype.decorateInternal = function(element) {
|
|
|
|
camlistore.BlobItem.superClass_.decorateInternal.call(this, element);
|
|
|
|
|
2012-12-23 20:43:46 +00:00
|
|
|
var el = this.getElement();
|
|
|
|
goog.dom.classes.add(el, 'cam-blobitem', 'cam-blobitem-150');
|
|
|
|
|
|
|
|
var thumbEl = this.dom_.createDom('img', 'cam-blobitem-thumb');
|
|
|
|
thumbEl.src = this.getThumbSrc_();
|
|
|
|
thumbEl.height = this.getThumbHeight_();
|
|
|
|
thumbEl.width = this.getThumbWidth_();
|
|
|
|
this.dom_.appendChild(el, thumbEl);
|
|
|
|
|
|
|
|
var titleEl = this.dom_.createDom('p', 'cam-blobitem-thumbtitle');
|
|
|
|
this.dom_.setTextContent(titleEl, this.getTitle_());
|
|
|
|
this.dom_.appendChild(el, titleEl);
|
2012-12-23 19:45:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** @override */
|
|
|
|
camlistore.BlobItem.prototype.disposeInternal = function() {
|
|
|
|
camlistore.BlobItem.superClass_.disposeInternal.call(this);
|
|
|
|
this.eh_.dispose();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when component's element is known to be in the document.
|
|
|
|
*/
|
|
|
|
camlistore.BlobItem.prototype.enterDocument = function() {
|
|
|
|
camlistore.BlobItem.superClass_.enterDocument.call(this);
|
2012-12-23 21:37:42 +00:00
|
|
|
// Add event handlers here
|
2012-12-23 19:45:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when component's element is known to have been removed from the
|
|
|
|
* document.
|
|
|
|
*/
|
|
|
|
camlistore.BlobItem.prototype.exitDocument = function() {
|
|
|
|
camlistore.BlobItem.superClass_.exitDocument.call(this);
|
2012-12-23 21:37:42 +00:00
|
|
|
// Clear event handlers here
|
2012-12-23 19:45:22 +00:00
|
|
|
};
|