Commit 68c01140 authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

Add a document list tab to officejs.

parent 515f6023
......@@ -111,6 +111,15 @@
<!-- </div> -->
</article>
</script>
<script id="document_list" type="text/html">
<article>
<ul>
{{#DocumentList}}
<li><a href="#/texteditor:fileName={{fileName}}">{{fileName}}</a>, created: {{creationDate}}, last modified: {{lastModified}}</li>
{{/DocumentList}}
</ul>
</article>
</script>
</head>
<body>
......@@ -145,7 +154,7 @@
<li class="texteditor">
<a href="#/texteditor"><i class="icon-font"></i>Text Editor</a>
</li>
<li class="nav-header">Document List</li>
<li class="nav-header"><a href="#/doclist">Document List</a></li>
<div id="document_list"></div>
</ul>
</div>
......
......@@ -26,42 +26,68 @@ require(['OfficeJS'],function (OJS) {
current_hash = 'default',
ich_object = {DocumentList:[],CurrentFileName:''},
current_editor = null,
route_param = {},
// conf vars
routes = {
'default' : {template:'home'},
'/home' : {template:'home'},
'/about' : {template:'about'},
'/login' : {template:'login'},
'/doclist' : {template:'document_list'},
'/texteditor' : {
template:'text_editor',
onload:function(){
// todo
var intervalid;
if (!text_editor_loaded_once) {
xinha_init();
text_editor_loaded_once = true;
}
document.querySelector('#text_editor').style.display = 'block';
current_editor = 'xinha';
if (typeof route_param.fileName !== 'undefined') {
intervalid = setInterval(function(){
try {
getCurrentEditor().getHTML();
} catch (e) {
return;
}
$('#input_fileName').attr(
'value',route_param.fileName);
OfficeJS.load();
clearInterval(intervalid);
},50);
}
},
onunload:function(){
document.querySelector('#text_editor').style.display = 'none';
ich_object.CurrentFileName = $('#input_fileName').attr('value');
current_editor = null;
},
onrestart: function(){
this.onload();
}
}
},
////////////////////////////////////////////////////////////////////////////
// load current page
loadcurrentpage = function () {
var new_hash;
var new_hash, params, i;
// get new hash
new_hash = location.hash.split('#');
if (typeof new_hash[1] !== "undefined") {
// new direction
new_hash = new_hash[1];
params = new_hash.split(':');
new_hash = params[0];
if (typeof routes[new_hash] === "undefined") {
return current_hash;
}
// set route_parameters
route_param = {};
for (i = 1; i < params.length; i += 1) {
var tmp = params[i].split('=');
route_param[tmp[0]] = tmp[1];
}
} else {
// default home
new_hash = 'default';
......@@ -90,6 +116,10 @@ require(['OfficeJS'],function (OJS) {
if (typeof routes[current_hash].onload === 'function') {
routes[current_hash].onload();
}
} else {
if (typeof routes[current_hash].onrestart === 'function') {
routes[current_hash].onrestart();
}
}
},
// end change page according to the event
......@@ -155,6 +185,7 @@ require(['OfficeJS'],function (OJS) {
alert ('No Jio set yet.');
return;
}
loading_object.load();
filename = $('#input_fileName').attr('value');
priv.jio.loadDocument({
'fileName':filename,
......@@ -166,6 +197,7 @@ require(['OfficeJS'],function (OJS) {
} else {
alert ('Error: ' + result.message);
}
loading_object.end_load();
}
});
};
......@@ -193,15 +225,24 @@ require(['OfficeJS'],function (OJS) {
priv.jio.getDocumentList({
'maxtries':3,
'callback':function (result) {
var htmlString = '', i;
var htmlString = '', i, document_array = [];
for (i = 0; i < result.list.length; i += 1) {
htmlString += '<li>\n';
htmlString += result.list[i].fileName;
htmlString += '</li>\n';
htmlString += '<li><a href="#/texteditor:fileName='+
result.list[i].fileName + '">\n' +
result.list[i].fileName;
result.list[i].creationDate =
(new Date(result.list[i].creationDate)).
toLocaleString();
result.list[i].lastModified =
(new Date(result.list[i].lastModified)).
toLocaleString();
document_array.push (result.list[i]);
htmlString += '</a></li>\n';
}
if (htmlString === '') {
htmlString = 'No document';
}
ich_object.DocumentList = document_array;
document.querySelector ('#document_list').
innerHTML = htmlString;
}
......
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