Commit 6ac75ea9 authored by Romain Courteaud's avatar Romain Courteaud Committed by Jérome Perrin

Update static version.

parent bd84d954
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dream Simulation</title> <title>Dream Simulation</title>
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" href="../lib/jquerymobile.css"> <link rel="stylesheet" href="../lib/jquerymobile.css">
<link rel="stylesheet" href="index.css" /> <link rel="stylesheet" href="index.css" />
......
...@@ -6,12 +6,17 @@ ...@@ -6,12 +6,17 @@
<title>Manage document</title> <title>Manage document</title>
<script src="../lib/rsvp.min.js" type="text/javascript"></script> <script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script> <script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../lib/jquerymobile.js" type="text/javascript"></script>
<script src="document_page_mixin.js" type="text/javascript"></script> <script src="document_page_mixin.js" type="text/javascript"></script>
<script src="manage_document.js" type="text/javascript"></script> <script src="manage_document.js" type="text/javascript"></script>
</head> </head>
<body> <body>
<a class="export_link ui-btn ui-btn-inline ui-icon-action ui-btn-icon-right">Export</a> <a class="export_link ui-btn ui-btn-inline ui-icon-action ui-btn-icon-right">Export</a>
<form class="knowledge_form">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline ui-icon-refresh ui-btn-icon-right">Run Knowledge Extraction</button>
</form>
<form class="delete_form"> <form class="delete_form">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline ui-icon-delete ui-btn-icon-right">Delete</button> <button type="submit" class="ui-btn ui-btn-b ui-btn-inline ui-icon-delete ui-btn-icon-right">Delete</button>
</form> </form>
......
/*global console, rJS, RSVP, initDocumentPageMixin */ /*global console, rJS, RSVP, initDocumentPageMixin, jQuery */
(function(window, rJS, RSVP, initDocumentPageMixin) { (function(window, rJS, RSVP, initDocumentPageMixin, $) {
"use strict"; "use strict";
function datatouri(data, mime_type) { function datatouri(data, mime_type) {
var result = "data:"; var result = "data:";
...@@ -29,6 +29,70 @@ ...@@ -29,6 +29,70 @@
} }
return new RSVP.Promise(resolver, canceller); return new RSVP.Promise(resolver, canceller);
} }
function disableAllButtons(gadget) {
// Prevent double click
var i, button_list = gadget.props.element.getElementsByClassName("ui-btn");
for (i = 0; i < button_list.length; i += 1) {
button_list[i].disabled = true;
}
}
function waitForKnowledgeExtraction(gadget) {
return new RSVP.Queue().push(function() {
return promiseEventListener(gadget.props.element.getElementsByClassName("knowledge_form")[0], "submit", false);
}).push(function() {
disableAllButtons(gadget);
return gadget.aq_getAttachment({
_id: gadget.props.jio_key,
_attachment: "body.json"
});
}).push(function(body_json) {
$.mobile.loading("show");
// XXX Hardcoded relative URL
return gadget.aq_ajax({
url: "../../runKnowledgeExtraction",
type: "POST",
data: body_json,
headers: {
"Content-Type": "application/json"
}
});
}).push(undefined, function(error) {
// Always drop the loader
$.mobile.loading("hide");
throw error;
}).push(function(evt) {
$.mobile.loading("hide");
var json_data = JSON.parse(evt.target.responseText);
if (json_data.success !== true) {
throw new Error(json_data.error);
}
return gadget.aq_putAttachment({
_id: gadget.props.jio_key,
_attachment: "body.json",
_data: JSON.stringify(json_data.data, null, 2),
_mimetype: "application/json"
});
}).push(function() {
return gadget.whoWantToDisplayThisDocument(gadget.props.jio_key);
}).push(function(url) {
return gadget.pleaseRedirectMyHash(url);
});
}
function waitForDeletion(gadget) {
return new RSVP.Queue().push(function() {
return promiseEventListener(gadget.props.element.getElementsByClassName("delete_form")[0], "submit", false);
}).push(function() {
disableAllButtons(gadget);
// Delete jIO document
return gadget.aq_remove({
_id: gadget.props.jio_key
});
}).push(function(result) {
return gadget.whoWantToDisplayHome();
}).push(function(url) {
return gadget.pleaseRedirectMyHash(url);
});
}
var gadget_klass = rJS(window); var gadget_klass = rJS(window);
initDocumentPageMixin(gadget_klass); initDocumentPageMixin(gadget_klass);
gadget_klass.ready(function(g) { gadget_klass.ready(function(g) {
...@@ -37,7 +101,7 @@ ...@@ -37,7 +101,7 @@
return g.getElement().push(function(element) { return g.getElement().push(function(element) {
g.props.element = element; g.props.element = element;
}); });
}).declareAcquiredMethod("aq_remove", "jio_remove").declareAcquiredMethod("aq_getAttachment", "jio_getAttachment").declareAcquiredMethod("aq_get", "jio_get").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareAcquiredMethod("whoWantToDisplayHome", "whoWantToDisplayHome").declareMethod("render", function(options) { }).declareAcquiredMethod("aq_remove", "jio_remove").declareAcquiredMethod("aq_getAttachment", "jio_getAttachment").declareAcquiredMethod("aq_putAttachment", "jio_putAttachment").declareAcquiredMethod("aq_get", "jio_get").declareAcquiredMethod("aq_ajax", "jio_ajax").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareAcquiredMethod("whoWantToDisplayThisDocument", "whoWantToDisplayThisDocument").declareAcquiredMethod("whoWantToDisplayHome", "whoWantToDisplayHome").declareMethod("render", function(options) {
this.props.jio_key = options.id; this.props.jio_key = options.id;
var gadget = this; var gadget = this;
return new RSVP.Queue().push(function() { return new RSVP.Queue().push(function() {
...@@ -53,20 +117,6 @@ ...@@ -53,20 +117,6 @@
export_link.href = datatouri(result_list[1], "application/json"); export_link.href = datatouri(result_list[1], "application/json");
}); });
}).declareMethod("startService", function() { }).declareMethod("startService", function() {
var gadget = this; return RSVP.all([ waitForDeletion(this), waitForKnowledgeExtraction(this) ]);
return new RSVP.Queue().push(function() {
return promiseEventListener(gadget.props.element.getElementsByClassName("delete_form")[0], "submit", false);
}).push(function() {
// Prevent double click
gadget.props.element.getElementsByClassName("ui-btn")[0].disabled = true;
// Delete jIO document
return gadget.aq_remove({
_id: gadget.props.jio_key
});
}).push(function(result) {
return gadget.whoWantToDisplayHome();
}).push(function(url) {
return gadget.pleaseRedirectMyHash(url);
});
}); });
})(window, rJS, RSVP, initDocumentPageMixin); })(window, rJS, RSVP, initDocumentPageMixin, jQuery);
\ No newline at end of file \ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>Listfield</title>
<!-- renderjs -->
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="../lib/handlebars.min.js" type="text/javascript"></script>
<!-- custom script -->
<script src="listfield.js" type="text/javascript"></script>
<script id="option-template" type="text/x-handlebars-template">
<option value="{{value}}">{{text}}</option>
</script>
<script id="selected-option-template" type="text/x-handlebars-template">
<option selected="selected" value="{{value}}">{{text}}</option>
</script>
</head>
<body>
<select />
</body>
</html>
/*global window, rJS, console, RSVP, Handlebars */
/*jslint nomen: true */
(function(window, rJS, console, RSVP, Handlebars) {
"use strict";
/////////////////////////////////////////////////////////////////
// Handlebars
/////////////////////////////////////////////////////////////////
// Precompile the templates while loading the first gadget instance
var gadget_klass = rJS(window), option_source = gadget_klass.__template_element.getElementById("option-template").innerHTML, option_template = Handlebars.compile(option_source), selected_option_source = gadget_klass.__template_element.getElementById("option-template").innerHTML, selected_option_template = Handlebars.compile(selected_option_source);
gadget_klass.ready(function(g) {
return g.getElement().push(function(element) {
g.element = element;
});
}).declareMethod("render", function(options) {
var select = this.element.getElementsByTagName("select")[0], i, template, field_json = options.field_json, tmp = "";
select.setAttribute("name", field_json.key);
for (i = 0; i < field_json.items.length; i += 1) {
if (field_json.items[i][1] === field_json.default[0]) {
template = selected_option_template;
} else {
template = option_template;
}
tmp += template({
value: field_json.items[i][1],
text: field_json.items[i][0]
});
}
select.innerHTML += tmp;
});
})(window, rJS, console, RSVP, Handlebars);
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment