Commit 37b13101 authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

add officejs simple tests

parent fbc8f77d
This diff is collapsed.
...@@ -22,6 +22,12 @@ nav#left_navbar { ...@@ -22,6 +22,12 @@ nav#left_navbar {
display: inline-block; display: inline-block;
width: 15%; width: 15%;
} }
.nav_header
{
font-style: italic;
list-style: none outside none;
}
section { section {
display: inline-block; display: inline-block;
margin: 0; margin: 0;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<litk rel="icon" href="img/officejs/favicon.png" /> <litk rel="icon" href="img/officejs/favicon.png" />
<link rel="shortcut icon" href="img/officejs/favicon.png" /> <link rel="shortcut icon" href="img/officejs/favicon.png" />
<link rel="stylesheet" href="css/officejs.css" /> <link rel="stylesheet" href="css/bootstrap.min.css" />
<title>OfficeJS</title> <title>OfficeJS</title>
<!-- js scripts --> <!-- js scripts -->
<script type="text/javascript" src="lib/icanhaz/ICanHaz.min.js"></script> <script type="text/javascript" src="lib/icanhaz/ICanHaz.min.js"></script>
...@@ -12,39 +12,112 @@ ...@@ -12,39 +12,112 @@
type="text/javascript" type="text/javascript"
src="lib/require/require.js"></script> src="lib/require/require.js"></script>
<!-- html scripts --> <!-- html scripts -->
<script id="test" type="text/html"> <script id="home" type="text/html">
<article> <article>
<p> <p>
test home
</p> </p>
</article> </article>
</script> </script>
<script id="about" type="text/html">
<article>
<p>
about
</p>
</article>
</script>
<script id="login" type="text/html">
<article>
<div class="control-group">
<label class="control-label" for="input_json_storage">JSON Storage</label>
<div class="controls docs-input-sizes">
<input class="input-xlarge"
type="text" name="JSONstorage" id="input_json_storage"
value="{&quot;type&quot;:&quot;local&quot;,&quot;userName&quot;:&quot;tristan&quot;}"
placeholder="storage" />
</div>
<label class="control-label" for="JSONapplicantID">JSON Applicant</label>
<div class="controls docs-input-sizes">
<input class="input-xlarge"
type="text" name="JSONapplicant" id="input_json_applicant"
value="{&quot;ID&quot;:&quot;jiotests&quot;}"
placeholder="applicant" />
</div>
</div>
<button type="submit" class="btn" onclick="OfficeJS.setJio()">Create New JIO</button>
</article>
</script>
<script id="text_editor" type="text/html">
<article>
<div class="control-group">
<label class="control-label" for="fileName">File Name</label>
<div class="controls docs-input-sizes">
<input type="text" name="fileName" id="input_fileName"
value="" placeholder="file name" />
</div>
<label class="control-label" for="fileContent">File Content</label>
<div class="controls docs-input-sizes">
<input type="text" name="fileContent" id="input_content"
value="" placeholder="content" />
</div>
<button type="submit" class="btn btn-primary" onclick="OfficeJS.save()"><i class="icon-download-alt icon-white"></i> Save</button>&nbsp;
<button type="submit" class="btn" onclick="OfficeJS.load()"><i class="icon-upload"></i> Load</button>&nbsp;
<button type="submit" class="btn btn-danger" onclick="OfficeJS.remove()"><i class="icon-remove icon-white"></i> Remove</button>&nbsp;
<button type="submit" class="btn" onclick="OfficeJS.getlist()"><i class="icon-refresh"></i> Get List</button>&nbsp;
</div>
<div id="document_list" class="span4">
<ul>
{{#DocumentList}}
<li>{{fileName}}</li>
{{/DocumentList}}
</ul>
</div>
</article>
</script>
</head> </head>
<body> <body>
<header>
<aside> <div id="loading" style="position: absolute; right: 20px; top: 20px;"></div>
<nav id="header_navbar"> <div class="navbar">
<div class="navbar-inner">
<div class="container-fluid">
<div class="row-fluid">
<div class="span2">
<h1>OfficeJS</h1>
</div>
<div class="span10">
<ul class="nav"> <ul class="nav">
<li><a href="#">Nav</a></li> <li><a href="#">Nav</a></li>
<li><a href="#about">About</a></li> <li><a href="#/about">About</a></li>
<li><a href="#contact">Contact</a></li> <li><a href="#/contact">Contact</a></li>
</ul> </ul>
</nav> </div>
</aside> </div>
<h1>OfficeJS</h1> </div>
</header> </div>
</div>
<nav id="left_navbar"> <div class="container-fluid">
<ul class="nav"> <div class="row-fluid">
<div class="span2">
<div class="well">
<ul class="nav nav-list">
<li class="nav-header">Nav</li>
<li><a href="#/login"><i class="icon-ok"></i>Login</a></li>
<li class="nav-header">Documents</li> <li class="nav-header">Documents</li>
<li class="create_document"><a href="#/create_document">Create Document</a></li> <li class="texteditor"><a href="#/texteditor"><i class="icon-font"></i>Text Editor</a></li>
<li><a href="#/test">Test</a></li>
<li class="other">Other</li>
</ul> </ul>
</nav> </div>
</div>
<section id="main"> <section class="span10" id="main">
<!-- Body content --> <!-- Body content -->
<article>
<p>
Loading...
</p>
</article>
</section> </section>
</div>
</div>
</body> </body>
</html> </html>
// NEXEDI
// Author: Tristan Cavelier <tristan.cavelier@tiolive.com>
// Date: Wed May 16 14:31:08 2012
require.config ({ require.config ({
paths: { paths: {
...@@ -13,10 +16,160 @@ require.config ({ ...@@ -13,10 +16,160 @@ require.config ({
} }
}); });
require(['OfficeJS'],function (OJS) { require(['OfficeJS'],function (OJS) {
// globals
var JIO = OJS.JIO, var JIO = OJS.JIO,
$ = OJS.jQuery, $ = OJS.jQuery,
Base64 = OJS.Base64, Base64 = OJS.Base64,
ich = OJS.ich; ich = OJS.ich,
// conf vars
routes = {
'default' : 'home',
'/home' : 'home',
'/about' : 'about',
'/login' : 'login',
'/texteditor' : 'text_editor'
},
// some vars
current_page = 'home',
ich_object = {DocumentList:[]},
////////////////////////////////////////////////////////////////////////////
// load current page
loadcurrentpage = function () {
var new_hash;
// get new hash
new_hash = location.hash.split('#');
if (typeof new_hash[1] !== "undefined") {
// new direction
new_hash = new_hash[1];
if (typeof routes[new_hash] === "undefined") {
return current_page;
}
} else {
// default home
new_hash = 'default';
}
return routes[new_hash];
},
// end load current page
////////////////////////////////////////////////////////////////////////////
// Repaint main page
repaint = function () {
$('#main').html(ich[current_page](ich_object,true));
},
// end repaint main page
////////////////////////////////////////////////////////////////////////////
// change page according to the event
hrefClicked = function () {
var new_page = loadcurrentpage();
if (current_page !== new_page) {
// check if it is necessary to repaint the page.
current_page = new_page;
repaint();
}
};
// end change page according to the event
////////////////////////////////////////////////////////////////////////////
current_page = loadcurrentpage();
repaint();
$('#main').html(ich['test']({},true)); window.OfficeJS = (function () {
var publ = {}, priv = {};
priv.jioIsSet = function () {
return (typeof priv.jio === 'object');
};
publ.setJio = function () {
if (priv.jioIsSet()) {
alert ('Jio already set.');
return;
}
alert ($('#input_json_storage').attr('value'));
// if there is not any jio created
priv.jio = JIO.createNew (
JSON.parse ( $('#input_json_storage').attr('value') ),
JSON.parse ( $('#input_json_applicant').attr('value') )
);
};
publ.save = function () {
var filename, filecontent;
if (!priv.jioIsSet()) {
alert ('No Jio set yet.');
return;
}
filename = $('#input_fileName').attr('value');
filecontent = $('#input_content').attr('value');
priv.jio.saveDocument({
'fileName':filename,
'fileContent':filecontent,
'maxtries':3,
'callback':function (result){
alert (result.isSaved ? 'Document Saved.' :
'Error: ' + result.message);
}
});
};
publ.load = function () {
var filename;
if (!priv.jioIsSet()) {
alert ('No Jio set yet.');
return;
}
filename = $('#input_fileName').attr('value');
priv.jio.loadDocument({
'fileName':filename,
'maxtries':3,
'callback':function (result){
if (result.document.fileName) {
$('#input_content').attr(
'value',result.document.fileContent);
alert ('Document loaded');
} else {
alert ('Error: ' + result.message);
}
}
});
};
publ.remove = function () {
var filename;
if (!priv.jioIsSet()) {
alert ('No Jio set yet.');
return;
}
filename = $('#input_fileName').attr('value');
priv.jio.removeDocument({
'fileName':filename,
'maxtries':3,
'callback':function (result) {
alert (result.isRemoved?'Document Removed.':
'Error: '+result.message);
}
});
};
publ.getlist = function () {
if (!priv.jioIsSet()) {
alert ('No Jio set yet.');
return;
}
priv.jio.getDocumentList({
'maxtries':3,
'callback':function (result) {
var htmlList, i;
htmlList = '<ul>\n';
for (i in result.list) {
htmlList += '<li>\n';
htmlList += result.list[i].fileName;
htmlList += '</li>\n';
}
htmlList += '</ul>\n';
$('#document_list').html(htmlList);
ich_object.DocumentList = result.list;
console.log (result.list);
alert (result.message);
}
});
};
return publ;
}());
// When someone clicks on a <a href..>..</a>, the interface may change.
$(window).bind('hashchange', hrefClicked);
}); });
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