Commit 2bba2325 authored by Thibaut Frain's avatar Thibaut Frain

working with RSVP

parent cfb3aab4
...@@ -7,10 +7,9 @@ ...@@ -7,10 +7,9 @@
$.mobile.hashListeningEnabled = false; $.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false; $.mobile.pushStateEnabled = false;
rJS(window).ready(function () { rJS(window).ready(function (g) {
var g = rJS(this), var body = g.element,
body = g.context, main_context = window.document.getElementById('.ui-content'),
main_context = g.context.find('.ui-content').first(),
ioGadgetConfig = {"type": "local", ioGadgetConfig = {"type": "local",
"username": "officejs", "username": "officejs",
"application_name": "officejs" "application_name": "officejs"
...@@ -18,12 +17,12 @@ ...@@ -18,12 +17,12 @@
jioGadget; jioGadget;
function setTitle(title) { function setTitle(title) {
g.context.find("#headergadget").find("h1").text(title); g.element.find("#headergadget").find("h1").text(title);
return $('title').text("OfficeJS | " + title); return $('title').text("OfficeJS | " + title);
} }
function enhanceGadgetRendering(gadget) { function enhanceGadgetRendering(gadget) {
gadget.context.enhanceWithin(); gadget.element.enhanceWithin();
return gadget.getTitle() return gadget.getTitle()
.then(setTitle); .then(setTitle);
} }
...@@ -64,77 +63,83 @@ ...@@ -64,77 +63,83 @@
function initializeRoute() { function initializeRoute() {
body body
.route("add", "", 1) .route("add", "", 1)
.done(function () { .then(function () {
$.url.redirect('/login/'); $.url.redirect('/login/');
}); });
body body
.route("add", "/about/", 1) .route("add", "/about/", 1)
.done(function () { .then(function () {
g.declareGadget('./about.html', main_context) g.declareGadget('./about.html', {element: main_context})
.then(enhanceGadgetRendering); .then(enhanceGadgetRendering);
}); });
body body
.route("add", "/contact/", 1) .route("add", "/contact/", 1)
.done(function () { .then(function () {
g.declareGadget('./contact.html', main_context) g.declareGadget('./contact.html', {element: main_context})
.then(enhanceGadgetRendering); .then(enhanceGadgetRendering);
}); });
body body
.route("add", "/login/", 1) .route("add", "/login/", 1)
.done(function () { .then(function () {
g.declareGadget('./login.html', main_context) g.declareGadget('./login.html', {element: main_context})
.then(enhanceGadgetRendering); .then(enhanceGadgetRendering);
}); });
body body
.route("add", "/spreadsheet/", 1) .route("add", "/spreadsheet/", 1)
.done(function () { .then(function () {
g.declareIframedGadget('./jqs.html', main_context) g.declareGadget('./jqs.html',
{sandbox: "iframe", element: main_context})
.then(registerIOButtons); .then(registerIOButtons);
}); });
body body
.route("add", "/bootstrap-wysiwyg/", 1) .route("add", "/bootstrap-wysiwyg/", 1)
.done(function () { .then(function () {
g.declareIframedGadget('./bootstrap-wysiwyg.html', main_context) g.declareGadget('./bootstrap-wysiwyg.html',
{sandbox: "iframe", element: main_context})
.then(registerIOButtons); .then(registerIOButtons);
}); });
body body
.route("add", "/mercury/", 1) .route("add", "/mercury/", 1)
.done(function () { .then(function () {
g.declareIframedGadget('./mercury.html', main_context) g.declareGadget('./mercury.html',
{sandbox: "iframe", element: main_context})
.then(registerIOButtons); .then(registerIOButtons);
}); });
body body
.route("add", "/codemirror/", 1) .route("add", "/codemirror/", 1)
.done(function () { .then(function () {
g.declareIframedGadget('./codemirror.html', main_context) g.declareGadget('./codemirror.html',
{sandbox: "iframe", element: main_context})
.then(registerIOButtons); .then(registerIOButtons);
}); });
body body
.route("add", "/svgedit/", 1) .route("add", "/svgedit/", 1)
.done(function () { .then(function () {
g.declareIframedGadget('./svg-editor.html', main_context) g.declareGadget('./svg-editor.html',
{sandbox: "iframe", element: main_context})
.then(registerIOButtons); .then(registerIOButtons);
}); });
} }
g.declareGadget('./io.html', g.context.find("#iogadget")) g.declareGadget('./io.html',
.done(function (ioGadget) { {element: document.getElementById("iogadget")})
.then(function (ioGadget) {
window.jio = ioGadget; window.jio = ioGadget;
jioGadget = ioGadget; jioGadget = ioGadget;
// Trigger route change // Trigger route change
initializeRoute(); initializeRoute();
$.url.onhashchange(function () { $.url.onhashchange(function () {
body.route("go", $.url.getPath()) body.route("go", $.url.getPath())
.fail(function () { .then(null, function () {
g.declareGadget('./error.html', main_context) g.declareGadget('./error.html', {element: main_context})
.then(enhanceGadgetRendering) .then(enhanceGadgetRendering)
.then(initializeRoute); .then(initializeRoute);
}); });
......
/*global window, jQuery, jIO, rJS */ /*global window, jIO, rJS, RSVP */
/*jslint unparam: true*/ /*jslint unparam: true*/
"use strict"; "use strict";
(function (window, $, jIO, rJS) { (function (window, jIO, rJS, RSVP) {
var gk = rJS(window); var gk = rJS(window);
gk.declareMethod('configureIO', function (json_configuration, key) { gk.declareMethod('configureIO', function (json_configuration, key) {
rJS(this).jio = jIO.newJio(json_configuration); rJS(this).jio = jIO.newJio(json_configuration);
rJS(this).jio_key = key; rJS(this).jio_key = key;
//console.log(rJS(this).jio);
return key; return key;
}) })
.declareMethod('getIO', function () { .declareMethod('getIO', function () {
var deferred = $.Deferred(),
default_value = "",
gadget = rJS(this);
gadget.jio.getAttachment({ return new RSVP.Promise(function(resolve, reject) {
"_id": gadget.jio_key, var default_value = "",
"_attachment": "body.txt" gadget = rJS(this);
}, function (err, response) {
if (err) { gadget.jio.getAttachment({
if (err.status === 404) { "_id": gadget.jio_key,
deferred.resolve(default_value); "_attachment": "body.txt"
}, function (err, response) {
if (err) {
if (err.status === 404) {
resolve(default_value);
} else {
reject(err);
}
} else { } else {
deferred.reject(err); resolve(response || default_value);
} }
} else { });
//console.log("getIO: " + response);
deferred.resolve(response || default_value);
}
}); });
return deferred.promise();
}) })
.declareMethod('setIO', function (value) { .declareMethod('setIO', function (value) {
//console.log("couscous");
var deferred = $.Deferred(), return new RSVP.Promise(function(resolve, reject) {
gadget = rJS(this); var gadget = rJS(this);
gadget.jio.put({"_id": gadget.jio_key},
function (err, response) { gadget.jio.put({
"_id": gadget.jio_key
}, function (err, response) {
if (err) { if (err) {
deferred.reject(err); reject(err);
} else { } else {
gadget.jio.putAttachment({ gadget.jio.putAttachment({
"_id": gadget.jio_key, "_id": gadget.jio_key,
"_attachment": "body.txt", "_attachment": "body.txt",
"_data": value, "_data": value,
"_mimetype": "text/plain" "_mimetype": "text/plain"
}, function (err, response) { }, function (err, response) {
if (err) { if (err) {
deferred.reject(err); reject(err);
} else { } else {
//console.log("putIO: " + value); //console.log("putIO: " + value);
deferred.resolve(); resolve();
} }
}); });
} }
}); });
return deferred.promise(); });
}); });
}(window, jQuery, jIO, rJS)); }(window, jIO, rJS, RSVP));
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height"/> <meta name="viewport" content="width=device-width, height=device-height"/>
<title>Test Bootstrap Wysiwyg gadget</title> <title>Test Codemirror gadget</title>
<link rel="stylesheet" href="../src/lib/qunit/qunit.css"> <link rel="stylesheet" href="../src/lib/qunit/qunit.css">
......
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