Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Unified Diff: chrome/common/extensions/docs/examples/apps/cycler/capture_tab.js

Issue 10832191: Major revision of page cycler UI. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Newer version with requested decomposition into separate sources Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/examples/apps/cycler/capture_tab.js
diff --git a/chrome/common/extensions/docs/examples/apps/cycler/capture_tab.js b/chrome/common/extensions/docs/examples/apps/cycler/capture_tab.js
new file mode 100644
index 0000000000000000000000000000000000000000..cf5af9c1d45e6677b8f08332810c3b85d9917087
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/apps/cycler/capture_tab.js
@@ -0,0 +1,78 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var CaptureTab = function (cyclerUI, cyclerData, playbackTab) {
+ // Members for all UI elements subject to programmatic adjustment.
+ this.captureTab_ = $('#capture-tab');
+ this.captureName_ = $('#capture-name');
+ this.captureURLs_ = $('#capture-urls');
+ this.doCaptureButton_ = $('#do-capture');
+
+ // References to other major components of the extension.
+ this.cyclerUI_ = cyclerUI;
+ this.cyclerData_ = cyclerData;
+ this.playbackTab_ = playbackTab;
+
+ /*
+ * Enable the capture tab.
+ */
+ this.enable = function() {
+ this.captureTab_.hidden = false;
+ };
+
+ /*
+ * Disable the capture tab.
+ */
+ this.disable = function() {
+ this.captureTab_.hidden = true;
+ };
+
+ /**
+ * Do a capture using current data from the capture tab. Post an error
+ * dialog if said data is incorrect or incomplete. Otherwise pass
+ * control to the browser side.
+ * @private
+ */
+ this.doCapture_ = function() {
+ var errors = [];
+ var captureName = this.captureName_.value.trim();
+ var urlList;
+
+ urlList = this.captureURLs_.value.split('\n');
+ if (captureName.length == 0)
+ errors.push('Must give a capture name');
+ if (urlList.length == 0)
+ errors.push('Must give at least one URL');
+
+ if (errors.length > 0) {
+ this.cyclerUI_.showMessage(errors.join('\n'), 'Ok');
+ } else {
+ this.doCaptureButton_.disabled = true;
+ chrome.experimental.record.captureURLs(captureName, urlList,
+ this.onCaptureDone.bind(this));
+ }
+ }
+
+ /**
+ * Callback for completed (or possibly failed) capture. Post a message
+ * box, either with errors or "Success!" message.
+ * @param {!Array.<string>} errors List of errors that occured
+ * during capture, if any.
+ */
+ this.onCaptureDone = function(errors) {
+ this.doCaptureButton_.disabled = false;
+
+ if (errors.length > 0) {
+ this.cyclerUI_.showMessage(errors.join('\n'), 'Ok');
+ } else {
+ this.cyclerUI_.showMessage('Success!', 'Ok');
+ this.cyclerUI_.currentCaptureName = this.captureName_.value.trim();
+ this.cyclerData_.saveCapture(this.cyclerUI_.currentCaptureName);
+ this.playbackTab_.updatePlaybackChoices_();
Jeffrey Yasskin 2012/08/15 01:03:59 It seems odd to update this here without showing t
clintstaley 2012/08/15 23:54:20 This is an asynchronous return, and it may be some
Jeffrey Yasskin 2012/08/16 20:19:31 Ah, yes. I hadn't thought of the user switching ta
clintstaley 2012/08/17 04:12:25 A later CL will include the ability to cancel an o
Jeffrey Yasskin 2012/08/17 19:32:14 You may want to make the cyclerData observable (ya
+ }
+ }
+
+ // Set up listener for capture button.
+ this.doCaptureButton_.addEventListener('click', this.doCapture_.bind(this));
+};

Powered by Google App Engine
This is Rietveld 408576698