Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add a job (on the client side)

  • Loading branch information...
commit cd66d95c5f72d12b32e9f74fe2c7d1b57526aa07 1 parent 3498598
Cédric Soulas authored October 09, 2012

Showing 1 changed file with 40 additions and 1 deletion. Show diff stats Hide diff stats

  1. 41  main.opa
41  main.opa
... ...
@@ -1,5 +1,44 @@
1 1
 import stdlib.themes.bootstrap.{css, icons, responsive}
2 2
 
  3
+client module Action {
  4
+
  5
+    function msg(url, class, msg) {
  6
+        // Add a log on top of the logs list
  7
+        #info += <div>
  8
+                    <span class="label">{Date.to_string_time_only(Date.now())}</span>
  9
+                    <span class="label {class}">{url} {msg}</span>
  10
+                 </div>
  11
+    }
  12
+
  13
+    function add_job(name, url, uri, freq) {
  14
+        // Add a new line on top of the job list
  15
+        #jobs += <tr id=#{name}>
  16
+                    <td>{url} each {freq} sec</td>
  17
+                    <td></td>
  18
+                 </tr>;
  19
+
  20
+    }
  21
+
  22
+    function submit_job(_) {
  23
+        function p(f, d, error){
  24
+            match (f(Dom.get_value(d))) {
  25
+            case {none}: msg("ERROR:", "label-error", error); none
  26
+            case r: r
  27
+            }
  28
+        }
  29
+
  30
+        // Parse formular inputs and add the job
  31
+        uri  = p(Uri.of_string, #url,  "the url is invalid");
  32
+        name = p(Parser.ident,  #name, "the log name is not a valid ident name");
  33
+        freq = p(Parser.int,    #freq, "the frequency is not an integer");
  34
+
  35
+        match ((uri, name, freq)) {
  36
+        case ({some:uri}, {some:name}, {some:freq}): add_job(name, Dom.get_value(#url), uri, freq)
  37
+        default: void // some invalid inputs, don't add the job
  38
+        }
  39
+    }
  40
+
  41
+}
3 42
 module View {
4 43
 
5 44
     function page() {
@@ -15,7 +54,7 @@ module View {
15 54
                 <label>Monitored Url</label><input type="text" id=#url value="http://opalang.org"/><span class="help-inline"></span>
16 55
                 <label>Frequency</label><input class="input-mini" type="text" id=#freq value="3"/><span class="help-inline">sec</span>
17 56
                 </div>
18  
-                <a class="btn btn-primary"><i class="icon-plus icon-white"/> Add and run</a>
  57
+                <a class="btn btn-primary" onclick={Action.submit_job}><i class="icon-plus icon-white"/> Add and run</a>
19 58
                 <a class="btn btn-small btn-inverse"><i class="icon-fire icon-white"/> Simulate a failure</a>
20 59
             </form>
21 60
         </div>

0 notes on commit cd66d95

Please sign in to comment.
Something went wrong with that request. Please try again.