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