2013-06-11 09:50:56 +00:00
|
|
|
/**
|
|
|
|
* @fileoverview Entry point for the blob browser UI.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
goog.provide('camlistore.IndexPage');
|
2012-11-09 18:35:59 +00:00
|
|
|
|
2013-06-11 09:50:56 +00:00
|
|
|
goog.require('goog.array');
|
|
|
|
goog.require('goog.dom');
|
|
|
|
goog.require('goog.dom.classes');
|
|
|
|
goog.require('goog.events.EventHandler');
|
|
|
|
goog.require('goog.events.EventType');
|
|
|
|
goog.require('goog.ui.Component');
|
|
|
|
goog.require('goog.ui.Textarea');
|
|
|
|
goog.require('camlistore.BlobItemContainer');
|
|
|
|
goog.require('camlistore.ServerConnection');
|
|
|
|
goog.require('camlistore.Toolbar');
|
|
|
|
goog.require('camlistore.Toolbar.EventType');
|
|
|
|
goog.require('camlistore.ServerType');
|
2012-11-09 18:35:59 +00:00
|
|
|
|
|
|
|
|
2013-06-11 09:50:56 +00:00
|
|
|
/**
|
|
|
|
* @param {camlistore.ServerType.DiscoveryDocument} config Global config
|
|
|
|
* of the current server this page is being rendered for.
|
|
|
|
* @param {goog.dom.DomHelper=} opt_domHelper DOM helper to use.
|
|
|
|
*
|
|
|
|
* @extends {goog.ui.Component}
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
camlistore.IndexPage = function(config, opt_domHelper) {
|
|
|
|
goog.base(this, opt_domHelper);
|
2012-11-09 18:35:59 +00:00
|
|
|
|
2013-06-11 09:50:56 +00:00
|
|
|
/**
|
|
|
|
* @type {Object}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.config_ = config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {camlistore.ServerConnection}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.connection_ = new camlistore.ServerConnection(config);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {camlistore.BlobItemContainer}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.blobItemContainer_ = new camlistore.BlobItemContainer(
|
|
|
|
this.connection_, opt_domHelper);
|
2013-09-29 23:51:09 +00:00
|
|
|
this.blobItemContainer_.isSelectionEnabled = true;
|
|
|
|
this.blobItemContainer_.isFileDragEnabled = true;
|
2013-06-11 09:50:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {Element}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.serverInfo_;
|
2012-12-12 03:33:15 +00:00
|
|
|
|
2013-06-11 09:50:56 +00:00
|
|
|
/**
|
|
|
|
* @type {camlistore.Toolbar}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.toolbar_ = new camlistore.Toolbar(opt_domHelper);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {goog.events.EventHandler}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.eh_ = new goog.events.EventHandler(this);
|
2012-12-12 03:33:15 +00:00
|
|
|
};
|
2013-06-11 09:50:56 +00:00
|
|
|
goog.inherits(camlistore.IndexPage, goog.ui.Component);
|
|
|
|
|
2012-12-12 03:33:15 +00:00
|
|
|
|
2013-06-11 09:50:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an initial DOM representation for the component.
|
|
|
|
*/
|
|
|
|
camlistore.IndexPage.prototype.createDom = function() {
|
|
|
|
this.decorateInternal(this.dom_.createElement('div'));
|
2012-12-12 03:33:15 +00:00
|
|
|
};
|
|
|
|
|
2013-06-11 09:50:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decorates an existing HTML DIV element.
|
|
|
|
* @param {Element} element The DIV element to decorate.
|
|
|
|
*/
|
|
|
|
camlistore.IndexPage.prototype.decorateInternal = function(element) {
|
|
|
|
camlistore.IndexPage.superClass_.decorateInternal.call(this, element);
|
|
|
|
|
|
|
|
var el = this.getElement();
|
|
|
|
goog.dom.classes.add(el, 'cam-index-page');
|
|
|
|
|
|
|
|
var titleEl = this.dom_.createDom('h1', 'cam-index-title');
|
|
|
|
this.dom_.setTextContent(titleEl, this.config_.ownerName + '\'s Vault');
|
|
|
|
this.dom_.appendChild(el, titleEl);
|
|
|
|
|
|
|
|
this.serverInfo_ = this.dom_.createDom('div', 'cam-index-serverinfo');
|
|
|
|
this.dom_.appendChild(el, this.serverInfo_);
|
|
|
|
|
|
|
|
this.addChild(this.toolbar_, true);
|
|
|
|
this.addChild(this.blobItemContainer_, true);
|
2012-12-12 03:33:15 +00:00
|
|
|
};
|
2012-12-12 01:45:15 +00:00
|
|
|
|
2013-06-11 09:50:56 +00:00
|
|
|
|
|
|
|
/** @override */
|
|
|
|
camlistore.IndexPage.prototype.disposeInternal = function() {
|
|
|
|
camlistore.IndexPage.superClass_.disposeInternal.call(this);
|
|
|
|
this.eh_.dispose();
|
2012-12-12 03:06:47 +00:00
|
|
|
};
|
|
|
|
|
2013-06-11 09:50:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when component's element is known to be in the document.
|
|
|
|
*/
|
|
|
|
camlistore.IndexPage.prototype.enterDocument = function() {
|
|
|
|
camlistore.IndexPage.superClass_.enterDocument.call(this);
|
|
|
|
|
2013-09-29 09:01:46 +00:00
|
|
|
this.connection_.serverStatus(
|
|
|
|
goog.bind(function(resp) {
|
|
|
|
this.handleServerStatus_(resp);
|
|
|
|
}, this)
|
|
|
|
);
|
2013-06-11 09:50:56 +00:00
|
|
|
|
|
|
|
this.eh_.listen(
|
|
|
|
this.toolbar_, camlistore.Toolbar.EventType.BIGGER,
|
|
|
|
function() {
|
|
|
|
if (this.blobItemContainer_.bigger()) {
|
|
|
|
this.blobItemContainer_.showRecent();
|
2012-12-12 03:33:15 +00:00
|
|
|
}
|
2013-06-11 09:50:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.eh_.listen(
|
|
|
|
this.toolbar_, camlistore.Toolbar.EventType.SMALLER,
|
|
|
|
function() {
|
|
|
|
if (this.blobItemContainer_.smaller()) {
|
|
|
|
this.blobItemContainer_.showRecent();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.eh_.listen(
|
|
|
|
this.toolbar_, camlistore.Toolbar.EventType.GOSEARCH,
|
|
|
|
function() {
|
2013-07-16 14:43:03 +00:00
|
|
|
window.location.href = "./search.html";
|
2013-06-11 09:50:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.eh_.listen(
|
|
|
|
this.toolbar_, camlistore.Toolbar.EventType.CHECKED_ITEMS_CREATE_SET,
|
|
|
|
function() {
|
|
|
|
var blobItems = this.blobItemContainer_.getCheckedBlobItems();
|
|
|
|
this.createNewSetWithItems_(blobItems);
|
|
|
|
});
|
|
|
|
|
2013-09-29 09:01:46 +00:00
|
|
|
this.eh_.listen(
|
|
|
|
this.toolbar_, camlistore.Toolbar.EventType.CREATE_PERMANODE,
|
|
|
|
function() {
|
|
|
|
this.connection_.createPermanode(
|
|
|
|
function(p) {
|
|
|
|
window.location = './?p=' + p;
|
|
|
|
}, function(failMsg) {
|
|
|
|
console.error('Failed to create permanode: ' + failMsg);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-06-11 09:50:56 +00:00
|
|
|
this.eh_.listen(
|
|
|
|
this.toolbar_, camlistore.Toolbar.EventType.CHECKED_ITEMS_ADDTO_SET,
|
|
|
|
function() {
|
|
|
|
var blobItems = this.blobItemContainer_.getCheckedBlobItems();
|
|
|
|
this.addItemsToSet_(blobItems);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.eh_.listen(
|
|
|
|
this.toolbar_, camlistore.Toolbar.EventType.SELECT_COLLEC,
|
|
|
|
function() {
|
|
|
|
var blobItems = this.blobItemContainer_.getCheckedBlobItems();
|
|
|
|
// there should be only one item selected
|
|
|
|
if (blobItems.length != 1) {
|
|
|
|
alert("Cannet set multiple items as current collection");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.blobItemContainer_.currentCollec_ = blobItems[0].blobRef_;
|
|
|
|
this.blobItemContainer_.unselectAll();
|
|
|
|
this.toolbar_.setCheckedBlobItemCount(0);
|
|
|
|
this.toolbar_.toggleCollecButton(false);
|
|
|
|
this.toolbar_.toggleAddToSetButton(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO(mpl): those are getting large. make dedicated funcs.
|
|
|
|
this.eh_.listen(
|
|
|
|
this.blobItemContainer_,
|
|
|
|
camlistore.BlobItemContainer.EventType.BLOB_ITEMS_CHOSEN,
|
|
|
|
function() {
|
|
|
|
var blobItems = this.blobItemContainer_.getCheckedBlobItems();
|
|
|
|
this.toolbar_.setCheckedBlobItemCount(blobItems.length);
|
|
|
|
// set checkedItemsAddToSetButton_
|
|
|
|
if (this.blobItemContainer_.currentCollec_ &&
|
|
|
|
this.blobItemContainer_.currentCollec_ != "" &&
|
|
|
|
blobItems.length > 0) {
|
|
|
|
this.toolbar_.toggleAddToSetButton(true);
|
|
|
|
} else {
|
|
|
|
this.toolbar_.toggleAddToSetButton(false);
|
|
|
|
}
|
|
|
|
// set setAsCollecButton_
|
|
|
|
this.toolbar_.toggleCollecButton(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.eh_.listen(
|
|
|
|
this.blobItemContainer_,
|
|
|
|
camlistore.BlobItemContainer.EventType.SINGLE_NODE_CHOSEN,
|
|
|
|
function() {
|
|
|
|
var blobItems = this.blobItemContainer_.getCheckedBlobItems();
|
|
|
|
this.toolbar_.setCheckedBlobItemCount(blobItems.length);
|
|
|
|
// set checkedItemsAddToSetButton_
|
|
|
|
if (this.blobItemContainer_.currentCollec_ &&
|
|
|
|
this.blobItemContainer_.currentCollec_ != "" &&
|
|
|
|
blobItems.length > 0) {
|
|
|
|
this.toolbar_.toggleAddToSetButton(true);
|
|
|
|
} else {
|
|
|
|
this.toolbar_.toggleAddToSetButton(false);
|
|
|
|
}
|
|
|
|
// set setAsCollecButton_
|
|
|
|
if (blobItems.length == 1 &&
|
|
|
|
blobItems[0].isCollection()) {
|
|
|
|
this.toolbar_.toggleCollecButton(true);
|
|
|
|
} else {
|
|
|
|
this.toolbar_.toggleCollecButton(false);
|
|
|
|
}
|
|
|
|
});
|
2012-12-12 03:33:15 +00:00
|
|
|
|
2013-06-11 09:50:56 +00:00
|
|
|
this.blobItemContainer_.showRecent();
|
2012-12-12 03:06:47 +00:00
|
|
|
};
|
|
|
|
|
2013-06-11 09:50:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when component's element is known to have been removed from the
|
|
|
|
* document.
|
|
|
|
*/
|
|
|
|
camlistore.IndexPage.prototype.exitDocument = function() {
|
|
|
|
camlistore.IndexPage.superClass_.exitDocument.call(this);
|
|
|
|
// Clear event handlers here
|
2012-12-12 03:06:47 +00:00
|
|
|
};
|
2012-11-09 18:35:59 +00:00
|
|
|
|
2012-11-28 18:15:39 +00:00
|
|
|
|
2013-06-11 09:50:56 +00:00
|
|
|
/**
|
|
|
|
* @param {Array.<camlistore.BlobItem>} blobItems Items to add to the permanode.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
camlistore.IndexPage.prototype.createNewSetWithItems_ = function(blobItems) {
|
|
|
|
this.connection_.createPermanode(
|
|
|
|
goog.bind(this.addMembers_, this, true, blobItems));
|
2012-12-12 03:33:15 +00:00
|
|
|
};
|
|
|
|
|
2013-06-11 09:50:56 +00:00
|
|
|
/**
|
|
|
|
* @param {Array.<camlistore.BlobItem>} blobItems Items to add to the permanode.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
camlistore.IndexPage.prototype.addItemsToSet_ = function(blobItems) {
|
|
|
|
if (!this.blobItemContainer_.currentCollec_ ||
|
|
|
|
this.blobItemContainer_.currentCollec_ == "") {
|
|
|
|
alert("no destination collection selected");
|
2012-12-12 03:33:15 +00:00
|
|
|
}
|
2013-06-11 09:50:56 +00:00
|
|
|
this.addMembers_(false, blobItems, this.blobItemContainer_.currentCollec_);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {boolean} newSet Whether the containing set has just been created.
|
|
|
|
* @param {Array.<camlistore.BlobItem>} blobItems Items to add to the permanode.
|
|
|
|
* @param {string} permanode Node to add the items to.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
camlistore.IndexPage.prototype.addMembers_ =
|
|
|
|
function(newSet, blobItems, permanode) {
|
|
|
|
var deferredList = [];
|
|
|
|
var complete = goog.bind(this.addItemsToSetDone_, this, permanode);
|
|
|
|
var callback = function() {
|
|
|
|
deferredList.push(1);
|
|
|
|
if (deferredList.length == blobItems.length) {
|
|
|
|
complete();
|
2012-12-07 01:14:18 +00:00
|
|
|
}
|
|
|
|
};
|
2013-06-11 09:50:56 +00:00
|
|
|
|
|
|
|
// TODO(mpl): newSet is a lame trick. Do better.
|
|
|
|
if (newSet) {
|
|
|
|
this.connection_.newSetAttributeClaim(
|
|
|
|
permanode, 'title', 'My new set', function() {}
|
|
|
|
);
|
2012-12-07 01:14:18 +00:00
|
|
|
}
|
2013-06-11 09:50:56 +00:00
|
|
|
goog.array.forEach(blobItems, function(blobItem, index) {
|
|
|
|
this.connection_.newAddAttributeClaim(
|
|
|
|
permanode, 'camliMember', blobItem.getBlobRef(), callback);
|
|
|
|
}, this);
|
|
|
|
};
|
2012-12-07 01:14:18 +00:00
|
|
|
|
|
|
|
|
2013-06-11 09:50:56 +00:00
|
|
|
/**
|
|
|
|
* @param {string} permanode Node to which the items were added.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
camlistore.IndexPage.prototype.addItemsToSetDone_ = function(permanode) {
|
|
|
|
this.blobItemContainer_.unselectAll();
|
|
|
|
this.toolbar_.setCheckedBlobItemCount(0);
|
|
|
|
this.toolbar_.toggleCollecButton(false);
|
|
|
|
this.toolbar_.toggleAddToSetButton(false);
|
|
|
|
this.blobItemContainer_.showRecent();
|
|
|
|
};
|
2012-12-07 01:14:18 +00:00
|
|
|
|
2013-06-11 09:50:56 +00:00
|
|
|
/**
|
|
|
|
* @param {camlistore.ServerType.StatusResponse} resp response for a status request
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
camlistore.IndexPage.prototype.handleServerStatus_ =
|
|
|
|
function(resp) {
|
|
|
|
if (resp == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
goog.dom.removeChildren(this.serverInfo_);
|
|
|
|
if (resp.version) {
|
|
|
|
var version = "Camlistore version: " + resp.version + "\n";
|
|
|
|
var div = this.dom_.createDom('div');
|
|
|
|
goog.dom.setTextContent(div, version);
|
|
|
|
goog.dom.appendChild(this.serverInfo_, div);
|
|
|
|
}
|
2012-12-12 03:06:47 +00:00
|
|
|
};
|
2012-11-09 18:35:59 +00:00
|
|
|
|