Commit e9454c02 authored by Romain Courteaud's avatar Romain Courteaud

WIP jio drive which support URL handling.

parent fb7add3f
......@@ -7,40 +7,38 @@
.ready(function (gadget) {
// Initialize the gadget local parameters
gadget.state_parameter_dict = {};
gadget.state_parameter_dict.jio_storage = jIO.createJIO({
"type": "localstorage"
});
// })
//
// .declareMethod('render', function () {
// var gadget = this;
// // Create the Jio storage only the first time
// if (!gadget.state_parameter_dict.hasOwnProperty("jio_storage")) {
// }
})
.declareMethod('createJio', function (jio_options) {
this.state_parameter_dict.jio_storage = jIO.createJIO(jio_options);
})
.declareMethod('allDocs', function () {
var storage = this.state_parameter_dict.jio_storage;
console.log("allDocs");
return storage.allDocs.apply(storage, arguments);
})
.declareMethod('get', function () {
var storage = this.state_parameter_dict.jio_storage;
console.log("get");
return storage.get.apply(storage, arguments);
})
.declareMethod('getAttachment', function () {
var storage = this.state_parameter_dict.jio_storage;
return storage.getAttachment.apply(storage, arguments)
// XXX Where to put this &@! blob reading
.then(function (response) {
return jIO.util.readBlobAsText(response.data);
})
.then(function (lala) {
console.log(lala.target.result);
return lala.target.result;
});
})
.declareMethod('putAttachment', function () {
var storage = this.state_parameter_dict.jio_storage;
return storage.putAttachment.apply(storage, arguments);
})
.declareMethod('post', function () {
var storage = this.state_parameter_dict.jio_storage;
return storage.post.apply(storage, arguments);
});
// return jio_storage.allDocs({"query": '__root__'})
// // XXX How to get root information?
// return jio_storage.get({"_id": undefined});
// return jio_storage.get(
// {"_id": options.jio_key},
// {"_view": options.action_view}
// );
// jio_storage.get(
// {"_id": uri.segment(2)},
// {"_view": options.action_view}
// )
//
// window.jio_storage = jio_storage;
}(rJS, jIO));
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>About Jio Drive</title>
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script>
</head>
<body>
<h2>About OfficeJS</h2>
<p>
OfficeJS is designed by the ERP5 company Nexedi.
</p>
<h3>License</h3>
<p>
Under the ? license.
</p>
<h3>See</h3>
<ul>
<li><a href="http://jquery.com/">jQuery</a></li>
<li><a href="http://twitter.github.com/bootstrap/">Bootstrap</a></li>
<li><a href="https://code.google.com/p/svg-edit/">svg-edit</a></li>
<li><a href="http://elrte.org/">elRTE</a></li>
<li><a href="https://github.com/mleibman/SlickGrid/wiki">SlickGrid</a></li>
</ul>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>About Jio Drive</title>
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script>
</head>
<body>
<h2>Contact us</h2>
<h3>E-mail</h3>
<p>
Jean-Paul Smets &lt;<a>jp@nexedi.com</a>&gt;
</p>
<h3>Address</h3>
<p>
Nexedi<br />
270, Boulevard Georges Clemenceau<br />
59700 MARCQ EN BAROEUL<br />
FRANCE
</p>
</body>
</html>
......@@ -9,53 +9,23 @@
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script>
<script src="../<%= curl.jquery.relative_dest %>" type="text/javascript"></script>
<script src="jio_drive.js" type="text/javascript"></script>
<script src="../<%= curl.jquerymobilejs.relative_dest %>" type="text/javascript"></script>
<link rel="http://www.renderjs.org/rel/interface"
href="http://www.renderjs.org/interface/officejs"/>
<script src="jio_drive.js" type="text/javascript"></script>
</head>
<body>
<div data-role="page" id="index">
<!-- header -->
<div data-role="header">
<a href="#menu"
data-rel="panel"
data-role="button"
data-icon="bars"
data-iconpos="notext"
data-dismissable="false">Menu</a>
<h1>Office JS</h1>
</div>
<!-- panel -->
<div data-role="panel" id="menu" data-theme="a" class="bare_panel"></div>
<!--div class="catalog_location"></div-->
<!-- content -->
<div data-role="content">
<!-- editor A -->
<div class="editor_a">
<div data-role="fieldcontain" class="editor_a_safe">
</div>
<div data-role="fieldcontain" class="editor_a">
</div>
</div>
<!-- editor B -->
<div class="editor_b">
<div data-role="fieldcontain" class="editor_b_safe">
</div>
<div data-role="fieldcontain" class="editor_b">
</div>
</div>
</div>
</div>
<header data-role="header">
<a class="home_link">Home</a>
<h1>Office JS</h1>
<a class="about_link">About</a>
</header>
<article class="gadget_container"></article>
<aside>
<section data-gadget-url="../catalog_static/index.html"
data-gadget-scope="catalog"></section>
<section data-gadget-url="../jio_bridge/index.html"
data-gadget-scope="jio"></section>
</aside>
</body>
</html>
This diff is collapsed.
......@@ -2,6 +2,6 @@ iframe {
border:0;
margin:0;
padding:0;
width:80%;
height:300px;
width:90%;
height:500px;
}
/*global console, rJS, RSVP, Handlebars */
/*jslint nomen: true */
(function (window, rJS, RSVP, Handlebars) {
"use strict";
// Precompile the templates while loading the first gadget instance
var gadget_klass = rJS(window),
source = gadget_klass.__template_element
.getElementById("table-template")
.innerHTML,
table_template = Handlebars.compile(source);
gadget_klass
// Assign the element to a variable
.ready(function (g) {
return g.getElement()
.push(function (element) {
g.element = element;
});
})
.declareAcquiredMethod("aq_allDocs", "allDocs")
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")
.declareAcquiredMethod("whoWantToDisplayThisPage",
"whoWantToDisplayThisPage")
.declareAcquiredMethod("whoWantToDisplayThisDocument",
"whoWantToDisplayThisDocument")
.declareMethod("render", function (options) {
var gadget = this;
return gadget.aq_allDocs({"select_list": ["title"]})
.push(function (document_list) {
var result_list = [gadget.whoWantToDisplayThisPage("new")],
doc,
i;
for (i = 0; i < document_list.data.total_rows; i += 1) {
doc = document_list.data.rows[i];
result_list.push(RSVP.all([
gadget.whoWantToDisplayThisDocument(doc.id),
doc.value.title
]));
}
return RSVP.all(result_list);
})
.push(function (document_list) {
// Create new doc if nothing exists
if (document_list.length === 1) {
return gadget.pleaseRedirectMyHash(document_list[0]);
}
var i,
parameter_list = [],
doc;
for (i = 1; i < document_list.length; i += 1) {
doc = document_list[i];
parameter_list[i - 1] = {
link: doc[0],
title: doc[1]
};
}
gadget.element.querySelector('a').href = document_list[0];
gadget.element.querySelector('.document_list').innerHTML =
table_template({
documentlist: parameter_list
});
});
});
}(window, rJS, RSVP, Handlebars));
/*global console, rJS, RSVP */
(function (window, rJS, RSVP) {
"use strict";
function promiseEventListener(target, type, useCapture) {
//////////////////////////
// Resolve the promise as soon as the event is triggered
// eventListener is removed when promise is cancelled/resolved/rejected
//////////////////////////
var handle_event_callback;
function canceller() {
target.removeEventListener(type, handle_event_callback, useCapture);
}
function resolver(resolve) {
handle_event_callback = function (evt) {
canceller();
evt.stopPropagation();
evt.preventDefault();
resolve(evt);
return false;
};
target.addEventListener(type, handle_event_callback, useCapture);
}
return new RSVP.Promise(resolver, canceller);
}
rJS(window)
.declareAcquiredMethod("aq_post", "jio_post")
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")
.declareAcquiredMethod("whoWantToDisplayThisDocument",
"whoWantToDisplayThisDocument")
.declareMethod("render", function (options) {
var gadget = this,
filename;
return this.getElement()
.push(function (element) {
var input = element.getElementsByClassName("filename_input")[0];
input.focus();
input.select();
return promiseEventListener(
element.getElementsByClassName("new_web_page_form")[0],
'submit',
false
);
})
.push(function (evt) {
filename = evt.target[0].value;
var now = new Date();
return gadget.aq_post({
title: filename,
// type: "Spreadsheet",
// format: "application/json",
type: "WebPage",
format: "text/html",
date: now.getFullYear() + "-" + (now.getMonth() + 1) + "-" +
now.getDate()
});
})
.push(function (result) {
return gadget.whoWantToDisplayThisDocument(result.id);
})
.push(function (url) {
return gadget.pleaseRedirectMyHash(url);
});
// .push(undefined, function (error) {
// if (error.status === 404) {
// }
// console.error(error);
// throw error;
// // // Unexpected success! File is already there.
// // return gadget.aq_get(filename);
// });
});
}(window, rJS, RSVP));
/*global console, rJS, RSVP */
/*jslint nomen: true */
(function (window, rJS, RSVP) {
"use strict";
function loopEventListener(target, type, useCapture, callback) {
//////////////////////////
// Infinite event listener (promise is never resolved)
// eventListener is removed when promise is cancelled/rejected
//////////////////////////
var handle_event_callback,
callback_promise;
function cancelResolver() {
if ((callback_promise !== undefined) &&
(typeof callback_promise.cancel === "function")) {
callback_promise.cancel();
}
}
function canceller() {
if (handle_event_callback !== undefined) {
target.removeEventListener(type, handle_event_callback, useCapture);
}
cancelResolver();
}
function itsANonResolvableTrap(resolve, reject) {
handle_event_callback = function (evt) {
evt.stopPropagation();
evt.preventDefault();
cancelResolver();
callback_promise = new RSVP.Queue()
.push(function () {
return callback(evt);
})
.push(undefined, function (error) {
if (!(error instanceof RSVP.CancellationError)) {
canceller();
reject(error);
}
});
};
target.addEventListener(type, handle_event_callback, useCapture);
}
return new RSVP.Promise(itsANonResolvableTrap, canceller);
}
rJS(window)
// Assign the element to a variable
.ready(function (g) {
return g.getElement()
.push(function (element) {
g.element = element;
});
})
.declareAcquiredMethod("aq_get", "jio_get")
.declareAcquiredMethod("aq_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("aq_putAttachment", "jio_putAttachment")
.declareMethod("render", function (options) {
var gadget = this,
editor_gadget,
doc;
return gadget.aq_get({"_id": options.id})
.push(function (result) {
var element = gadget.element.querySelector("div");
doc = result.data;
gadget.element.querySelector("h2").textContent = doc.title || "";
// XXX Non stateless
element.innerHTML = "";
if (doc.type === "WebPage") {
return gadget.declareGadget("../editor_jqte/index.html", {
element: element,
scope: "editor"
});
}
if (doc.type === "Spreadsheet") {
return gadget.declareGadget("../jquery_sheet/index.html", {
element: element,
scope: "editor"
// sandbox: "iframe"
});
}
throw new Error("Can not display " + JSON.stringify(result.data));
})
.push(function (new_gadget) {
editor_gadget = new_gadget;
return gadget.aq_getAttachment({
"_id": doc._id,
"_attachment": "body"
});
})
.push(function (attachment) {
console.log(attachment);
return editor_gadget.setContent(attachment);
}, function (error) {
if ((error.status === 404) && (error.method === "getAttachment")) {
return;
}
throw error;
})
.push(function () {
function formSubmit() {
return editor_gadget.getContent()
.then(function (value) {
return gadget.aq_putAttachment({
"_id": doc._id,
"_attachment": "body",
"_data": value,
"_mime_type": doc.format
});
});
}
return loopEventListener(
gadget.element.querySelector("form"),
'submit',
false,
formSubmit
);
});
});
}(window, rJS, RSVP));
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Jio Drive | Document List</title>
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.handlebars.relative_dest %>" type="text/javascript"></script>
<script id="table-template" type="text/x-handlebars-template">
<ul data-role="listview" data-inset="true" class="document-listview">
{{#documentlist}}
<li><a href="{{link}}">{{title}}</a></li>
{{/documentlist}}
</ul>
</script>
<script src="jio_drive_document_list.js" type="text/javascript"></script>
</head>
<body>
<h2>Document List</h2>
<section class="document_list"></section>
<a>New document</a>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Jio Drive | Document List</title>
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script>
<script src="jio_drive_new_document.js" type="text/javascript"></script>
</head>
<body>
<h2>New document</h2>
<form class="new_web_page_form">
<div data-role='fieldcontain'>
<label for="document_name">Filename</label>
<input name="document_name" type="text" spellcheck="false" required
value="my_first_page.html" class="filename_input"></input>
</div>
<input type="submit" value="Add web page" />
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Jio Drive | Plumb</title>
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script>
<script src="jio_drive_plumber.js" type="text/javascript"></script>
</head>
<body>
<h2></h2>
<form class="edit_form">
<input type="submit" value="Save" />
</form>
<div></div>
</body>
</html>
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