Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a job (on the client side)

  • Loading branch information...
commit cd66d95c5f72d12b32e9f74fe2c7d1b57526aa07 1 parent 3498598
Cédric Soulas authored
Showing with 40 additions and 1 deletion.
  1. +40 −1 main.opa
41 main.opa
View
@@ -1,5 +1,44 @@
import stdlib.themes.bootstrap.{css, icons, responsive}
+client module Action {
+
+ function msg(url, class, msg) {
+ // Add a log on top of the logs list
+ #info += <div>
+ <span class="label">{Date.to_string_time_only(Date.now())}</span>
+ <span class="label {class}">{url} {msg}</span>
+ </div>
+ }
+
+ function add_job(name, url, uri, freq) {
+ // Add a new line on top of the job list
+ #jobs += <tr id=#{name}>
+ <td>{url} each {freq} sec</td>
+ <td></td>
+ </tr>;
+
+ }
+
+ function submit_job(_) {
+ function p(f, d, error){
+ match (f(Dom.get_value(d))) {
+ case {none}: msg("ERROR:", "label-error", error); none
+ case r: r
+ }
+ }
+
+ // Parse formular inputs and add the job
+ uri = p(Uri.of_string, #url, "the url is invalid");
+ name = p(Parser.ident, #name, "the log name is not a valid ident name");
+ freq = p(Parser.int, #freq, "the frequency is not an integer");
+
+ match ((uri, name, freq)) {
+ case ({some:uri}, {some:name}, {some:freq}): add_job(name, Dom.get_value(#url), uri, freq)
+ default: void // some invalid inputs, don't add the job
+ }
+ }
+
+}
module View {
function page() {
@@ -15,7 +54,7 @@ module View {
<label>Monitored Url</label><input type="text" id=#url value="http://opalang.org"/><span class="help-inline"></span>
<label>Frequency</label><input class="input-mini" type="text" id=#freq value="3"/><span class="help-inline">sec</span>
</div>
- <a class="btn btn-primary"><i class="icon-plus icon-white"/> Add and run</a>
+ <a class="btn btn-primary" onclick={Action.submit_job}><i class="icon-plus icon-white"/> Add and run</a>
<a class="btn btn-small btn-inverse"><i class="icon-fire icon-white"/> Simulate a failure</a>
</form>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.