From 4637b6676ff57b38687d84f140c79b2413351382 Mon Sep 17 00:00:00 2001 From: Aaron Boodman Date: Wed, 4 Dec 2013 20:42:12 -0800 Subject: [PATCH] Add a 'clear selection' button per Brad request. Also clean up dispatch of the related events somewhat. Change-Id: I6c0e5fe20f2d985463cc434f9efd5796108da869 --- server/camlistored/ui/blob_item_container.js | 8 +++---- server/camlistored/ui/index.js | 25 ++++---------------- server/camlistored/ui/toolbar.js | 17 +++++++++++++ 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/server/camlistored/ui/blob_item_container.js b/server/camlistored/ui/blob_item_container.js index bf04759ea..20c9d75d8 100644 --- a/server/camlistored/ui/blob_item_container.js +++ b/server/camlistored/ui/blob_item_container.js @@ -144,8 +144,7 @@ camlistore.BlobItemContainer.prototype.dragActiveElement_ = null; * @enum {string} */ camlistore.BlobItemContainer.EventType = { - BLOB_ITEMS_CHOSEN: 'Camlistore_BlobItemContainer_BlobItems_Chosen', - SINGLE_NODE_CHOSEN: 'Camlistore_BlobItemContainer_SingleNode_Chosen' + SELECTION_CHANGED: 'Camlistore_BlobItemContainer_SelectionChanged', }; @@ -441,7 +440,6 @@ camlistore.BlobItemContainer.prototype.handleBlobItemChecked_ = function(e) { this.checkedBlobItems_.push(item); } } - this.dispatchEvent(camlistore.BlobItemContainer.EventType.BLOB_ITEMS_CHOSEN); } else if (isCtrlMultiSelect) { if (isCheckingItem) { blobItem.setState(goog.ui.Component.State.CHECKED, true); @@ -469,7 +467,6 @@ camlistore.BlobItemContainer.prototype.handleBlobItemChecked_ = function(e) { } } } - this.dispatchEvent(camlistore.BlobItemContainer.EventType.BLOB_ITEMS_CHOSEN); } else { blobItem.setState(goog.ui.Component.State.CHECKED, isCheckingItem); if (isCheckingItem) { @@ -477,8 +474,8 @@ camlistore.BlobItemContainer.prototype.handleBlobItemChecked_ = function(e) { } else { goog.array.remove(this.checkedBlobItems_, blobItem); } - this.dispatchEvent(camlistore.BlobItemContainer.EventType.SINGLE_NODE_CHOSEN); } + this.dispatchEvent(camlistore.BlobItemContainer.EventType.SELECTION_CHANGED); }; /** @@ -488,6 +485,7 @@ camlistore.BlobItemContainer.prototype.unselectAll = function() { item.setState(goog.ui.Component.State.CHECKED, false); }); this.checkedBlobItems_ = []; + this.dispatchEvent(camlistore.BlobItemContainer.EventType.SELECTION_CHANGED); } /** diff --git a/server/camlistored/ui/index.js b/server/camlistored/ui/index.js index 0652e3b4c..fae4bb1aa 100644 --- a/server/camlistored/ui/index.js +++ b/server/camlistored/ui/index.js @@ -154,6 +154,10 @@ camlistore.IndexPage.prototype.enterDocument = function() { this.createNewSetWithItems_(blobItems); }); + this.eh_.listen( + this.toolbar_, camlistore.Toolbar.EventType.CLEAR_SELECTION, + this.blobItemContainer_.unselectAll.bind(this.blobItemContainer_)); + this.eh_.listen( this.toolbar_, camlistore.Toolbar.EventType.CREATE_PERMANODE, function() { @@ -193,28 +197,9 @@ camlistore.IndexPage.prototype.enterDocument = function() { this.blobItemContainer_.showRoots.bind( this.blobItemContainer_, this.config_.signing)); - // 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, + camlistore.BlobItemContainer.EventType.SELECTION_CHANGED, function() { var blobItems = this.blobItemContainer_.getCheckedBlobItems(); this.toolbar_.setCheckedBlobItemCount(blobItems.length); diff --git a/server/camlistored/ui/toolbar.js b/server/camlistored/ui/toolbar.js index 4bf9f4eb8..a3e11bcb1 100644 --- a/server/camlistored/ui/toolbar.js +++ b/server/camlistored/ui/toolbar.js @@ -53,6 +53,13 @@ camlistore.Toolbar = function(opt_domHelper) { this.checkedItemsCreateSetButton_.addClassName('cam-checked-items'); this.checkedItemsCreateSetButton_.setVisible(false); + /** + * @type {goog.ui.Button} + * @private + * / + this.clearSelectionButton_ = new goog.ui.Button('Clear Selection'); + this.clearSelectionButton_.setVisible(false); + /** * @type {goog.ui.Button} * @private @@ -108,6 +115,7 @@ camlistore.Toolbar.EventType = { SMALLER: 'Camlistore_Toolbar_Smaller', ROOTS: 'Camlistore_Toolbar_SearchRoots', CHECKED_ITEMS_ADDTO_SET: 'Camlistore_Toolbar_Checked_Items_Addto_set', + CLEAR_SELECTION: 'Clear_Selection', SELECT_COLLEC: 'Camlistore_Toolbar_Select_collec', CHECKED_ITEMS_CREATE_SET: 'Camlistore_Toolbar_Checked_Items_Create_set', CREATE_PERMANODE: 'Camlistore_Toolbar_Create_Permanode', @@ -152,6 +160,7 @@ camlistore.Toolbar.prototype.decorateInternal = function(el) { this.addChild(this.smallerButton_, true); this.addChild(this.biggerButton_, true); this.addChild(this.checkedItemsCreateSetButton_, true); + this.addChild(this.clearSelectionButton_, true); this.addChild(this.createPermanodeButton_, true); this.addChild(this.setAsCollecButton_, true); this.addChild(this.checkedItemsAddToSetButton_, true); @@ -206,6 +215,12 @@ camlistore.Toolbar.prototype.enterDocument = function() { goog.bind(this.dispatch_, this, camlistore.Toolbar.EventType.CHECKED_ITEMS_CREATE_SET)); + this.eh_.listen( + this.clearSelectionButton_.getElement(), + goog.events.EventType.CLICK, + goog.bind(this.dispatch_, this, + camlistore.Toolbar.EventType.CLEAR_SELECTION)); + this.eh_.listen( this.createPermanodeButton_.getElement(), goog.events.EventType.CLICK, @@ -254,9 +269,11 @@ camlistore.Toolbar.prototype.setCheckedBlobItemCount = function(count) { var txt = 'Create set w/ ' + count + ' item' + (count > 1 ? 's' : ''); this.checkedItemsCreateSetButton_.setContent(txt); this.checkedItemsCreateSetButton_.setVisible(true); + this.clearSelectionButton_.setVisible(true); } else { this.checkedItemsCreateSetButton_.setContent(''); this.checkedItemsCreateSetButton_.setVisible(false); + this.clearSelectionButton_.setVisible(false); } };