OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This Source Code is subject to the terms of the Mozilla Public License |
| 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
| 4 * http://mozilla.org/MPL/2.0/. |
| 5 */ |
| 6 |
| 7 var {Long_Task} = require( "task" ); |
| 8 var {Counting_Task} = require( "counter_task" ); |
| 9 let {Logger} = require( "logger" ); |
| 10 |
| 11 var current_task = null; |
| 12 |
| 13 function update_status( s, perform_log ) |
| 14 { |
| 15 var status_field = document.getElementById( "task_status" ); |
| 16 if ( status_field.childNodes.length > 0 ) |
| 17 { |
| 18 status_field.removeChild( status_field.childNodes[0] ); |
| 19 } |
| 20 status_field.appendChild( document.createTextNode( s ) ); |
| 21 if ( arguments.length >= 2 && perform_log ) |
| 22 { |
| 23 log( s ); |
| 24 } |
| 25 } |
| 26 |
| 27 function update_button( b ) |
| 28 { |
| 29 var button = document.getElementById( "task_go" ); |
| 30 if ( b ) |
| 31 { |
| 32 button.label = "Cancel" |
| 33 } else |
| 34 { |
| 35 button.label = "Start" |
| 36 } |
| 37 |
| 38 } |
| 39 |
| 40 function task_finished() |
| 41 { |
| 42 if ( current_task.cancelled ) |
| 43 { |
| 44 var status = "Cancelled"; |
| 45 } |
| 46 else |
| 47 { |
| 48 status = "Finished"; |
| 49 } |
| 50 update_status( status ); |
| 51 update_button( false ); |
| 52 current_task = null; |
| 53 } |
| 54 |
| 55 function task_count( n ) |
| 56 { |
| 57 update_status( "Count " + n, false ); |
| 58 } |
| 59 |
| 60 /* |
| 61 * We're overloading the start button also to handle cancellation. |
| 62 */ |
| 63 function task_start_click() |
| 64 { |
| 65 if ( !current_task ) |
| 66 { |
| 67 log( "Clicked start" ); |
| 68 if ( !Counting_Task ) |
| 69 { |
| 70 log( "No Counting_Task" ); |
| 71 } |
| 72 if ( !Long_Task ) |
| 73 { |
| 74 log( "No Long_Task" ); |
| 75 } |
| 76 log( "require counter_task: " + require( "counter_task" ).toString() ); |
| 77 |
| 78 let count = document.getElementById( "task_count" ).value; |
| 79 let limit = document.getElementById( "task_limit" ).value; |
| 80 var variant; |
| 81 switch ( document.getElementById( "counting_variant" ).selectedIndex ) |
| 82 { |
| 83 case 0: |
| 84 variant = { type: "continuous" }; |
| 85 break; |
| 86 case 1: |
| 87 variant = { type: "segmented fast" }; |
| 88 break; |
| 89 case 2: |
| 90 variant = { type: "segmented slow", interval: document.getElementById( "
slow_interval" ).value}; |
| 91 break; |
| 92 default: |
| 93 log( "Unknown variant. This is an implementation defect." ); |
| 94 throw "bad variant"; |
| 95 } |
| 96 current_task = new Long_Task( new Counting_Task( count, task_count, task_fin
ished, variant ), false, limit ); |
| 97 update_status( "Started" ); |
| 98 update_button( true ); |
| 99 current_task.run(); |
| 100 } |
| 101 else |
| 102 { |
| 103 current_task.cancel(); |
| 104 update_button( false ); |
| 105 // We have a running task, so cancel it. |
| 106 } |
| 107 } |
| 108 |
| 109 var log = (new Logger( "task_ui" )).make_log(); |
OLD | NEW |