OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * Constructor for the tab UI governing setup and initial running of capture |
| 7 * baselines. All HTML controls under tag #capture-tab, plus the tab label |
| 8 * #capture-tab-label are controlled by this class. |
| 9 * @param {!Object} cyclerUI The master UI class, needed for global state |
| 10 * such as current capture name. |
| 11 * @param {!Object} cyclerData The local FileSystem-based database of |
| 12 * available captures to play back. |
| 13 * @param {!Object} playbackTab The class governing playback selections. |
| 14 * We need this in order to update its choices when we get asynchronous |
| 15 * callbacks for successfully completed capture baselines. |
| 16 */ |
| 17 var CaptureTab = function (cyclerUI, cyclerData, playbackTab) { |
| 18 // Members for all UI elements subject to programmatic adjustment. |
| 19 this.tabLabel_ = $('#capture-tab-label'); |
| 20 this.captureTab_ = $('#capture-tab'); |
| 21 this.captureName_ = $('#capture-name'); |
| 22 this.captureURLs_ = $('#capture-urls'); |
| 23 this.doCaptureButton_ = $('#do-capture'); |
| 24 |
| 25 // References to other major components of the extension. |
| 26 this.cyclerUI_ = cyclerUI; |
| 27 this.cyclerData_ = cyclerData; |
| 28 this.playbackTab_ = playbackTab; |
| 29 |
| 30 /* |
| 31 * Enable the capture tab and its label. |
| 32 */ |
| 33 this.enable = function() { |
| 34 this.captureTab_.hidden = false; |
| 35 this.tabLabel_.classList.add('selected'); |
| 36 }; |
| 37 |
| 38 /* |
| 39 * Disable the capture tab and its label. |
| 40 */ |
| 41 this.disable = function() { |
| 42 this.captureTab_.hidden = true; |
| 43 this.tabLabel_.classList.remove('selected'); |
| 44 }; |
| 45 |
| 46 /** |
| 47 * Do a capture using current data from the capture tab. Post an error |
| 48 * dialog if said data is incorrect or incomplete. Otherwise pass |
| 49 * control to the browser side. |
| 50 * @private |
| 51 */ |
| 52 this.doCapture_ = function() { |
| 53 var errors = []; |
| 54 var captureName = this.captureName_.value.trim(); |
| 55 var urlList; |
| 56 |
| 57 urlList = this.captureURLs_.value.split('\n'); |
| 58 if (captureName.length == 0) |
| 59 errors.push('Must give a capture name'); |
| 60 if (urlList.length == 0) |
| 61 errors.push('Must give at least one URL'); |
| 62 |
| 63 if (errors.length > 0) { |
| 64 this.cyclerUI_.showMessage(errors.join('\n'), 'Ok'); |
| 65 } else { |
| 66 this.doCaptureButton_.disabled = true; |
| 67 chrome.experimental.record.captureURLs(captureName, urlList, |
| 68 this.onCaptureDone.bind(this)); |
| 69 } |
| 70 } |
| 71 |
| 72 /** |
| 73 * Callback for completed (or possibly failed) capture. Post a message |
| 74 * box, either with errors or "Success!" message. |
| 75 * @param {!Array.<string>} errors List of errors that occured |
| 76 * during capture, if any. |
| 77 */ |
| 78 this.onCaptureDone = function(errors) { |
| 79 this.doCaptureButton_.disabled = false; |
| 80 |
| 81 if (errors.length > 0) { |
| 82 this.cyclerUI_.showMessage(errors.join('\n'), 'Ok'); |
| 83 } else { |
| 84 this.cyclerUI_.showMessage('Success!', 'Ok'); |
| 85 this.cyclerUI_.currentCaptureName = this.captureName_.value.trim(); |
| 86 this.cyclerData_.saveCapture(this.cyclerUI_.currentCaptureName); |
| 87 } |
| 88 } |
| 89 |
| 90 // Set up listener for capture button. |
| 91 this.doCaptureButton_.addEventListener('click', this.doCapture_.bind(this)); |
| 92 }; |
OLD | NEW |