Commit ad35eb90 authored by Thibaut Frain's avatar Thibaut Frain Committed by Marco Mariani

working with RSVP

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