Commit a969eb49 authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

Add Xinha text editor.

parent 21ddc353
...@@ -62,40 +62,44 @@ ...@@ -62,40 +62,44 @@
<script id="text_editor" type="text/html"> <script id="text_editor" type="text/html">
<article> <article>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="fileName">File Name</label> <div class="span5">
<div class="controls docs-input-sizes"> <label class="control-label" for="fileName">File Name</label>
<input type="text" name="fileName" id="input_fileName" <div class="controls docs-input-sizes">
value="" placeholder="file name" /> <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> -->
</div> </div>
<label class="control-label" for="fileContent">File Content</label> <div class="span5">
<div class="controls docs-input-sizes"> <button type="submit"
<input type="text" name="fileContent" id="input_content" class="btn btn-primary"
value="" placeholder="content" /> 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>
<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>
<!-- <div id="document_list" class="span4"> --> <!-- <div id="document_list" class="span4"> -->
<!-- <ul> --> <!-- <ul> -->
...@@ -153,6 +157,11 @@ ...@@ -153,6 +157,11 @@
</p> </p>
</article> </article>
</section> </section>
<section class="span10" id="text_editor" style="display: none">
<textarea name="textEditor" id="textEditor" rows="25" cols="50"
style="width: 100%">
</textarea>
</section>
</div> </div>
</div> </div>
</body> </body>
......
...@@ -21,17 +21,34 @@ require(['OfficeJS'],function (OJS) { ...@@ -21,17 +21,34 @@ require(['OfficeJS'],function (OJS) {
$ = OJS.jQuery, $ = OJS.jQuery,
Base64 = OJS.Base64, Base64 = OJS.Base64,
ich = OJS.ich, ich = OJS.ich,
// some vars
text_editor_loaded_once = false,
current_hash = 'default',
ich_object = {DocumentList:[]},
current_editor = null,
// conf vars // conf vars
routes = { routes = {
'default' : 'home', 'default' : {template:'home'},
'/home' : 'home', '/home' : {template:'home'},
'/about' : 'about', '/about' : {template:'about'},
'/login' : 'login', '/login' : {template:'login'},
'/texteditor' : 'text_editor' '/texteditor' : {
template:'text_editor',
onload:function(){
// todo
if (!text_editor_loaded_once) {
xinha_init();
text_editor_loaded_once = true;
}
document.querySelector('#text_editor').style.display = 'block';
current_editor = 'xinha';
},
onunload:function(){
document.querySelector('#text_editor').style.display = 'none';
current_editor = null;
},
}
}, },
// some vars
current_page = 'home',
ich_object = {DocumentList:[]},
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// load current page // load current page
loadcurrentpage = function () { loadcurrentpage = function () {
...@@ -42,36 +59,58 @@ require(['OfficeJS'],function (OJS) { ...@@ -42,36 +59,58 @@ require(['OfficeJS'],function (OJS) {
// new direction // new direction
new_hash = new_hash[1]; new_hash = new_hash[1];
if (typeof routes[new_hash] === "undefined") { if (typeof routes[new_hash] === "undefined") {
return current_page; return current_hash;
} }
} else { } else {
// default home // default home
new_hash = 'default'; new_hash = 'default';
} }
return routes[new_hash]; return new_hash;
}, },
// end load current page // end load current page
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Repaint main page // Repaint main page
repaint = function () { repaint = function () {
$('#main').html(ich[current_page](ich_object,true)); $('#main').html(ich[routes[current_hash].template](ich_object,true));
}, },
// end repaint main page // end repaint main page
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// change page according to the event // change page according to the event
hrefClicked = function () { hrefClicked = function () {
var new_page = loadcurrentpage(); var new_hash = loadcurrentpage(), prev_hash = 'default';
if (current_page !== new_page) { if (routes[current_hash].template !== routes[new_hash].template) {
// check if it is necessary to repaint the page. // check if it is necessary to repaint the page.
current_page = new_page; prev_hash = current_hash;
current_hash = new_hash;
if (typeof routes[prev_hash].onunload === 'function') {
routes[prev_hash].onunload();
}
repaint(); repaint();
if (typeof routes[current_hash].onload === 'function') {
routes[current_hash].onload();
}
} }
}; },
// end change page according to the event // end change page according to the event
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// get the currrent editor
getCurrentEditor = function () {
switch (current_editor) {
case 'xinha':
return xinha_editors['textEditor'];
case 'svg':
return null;
case 'calc':
return null;
default:
return null;
}
};
// end get the current editor
////////////////////////////////////////////////////////////////////////////
current_page = loadcurrentpage(); // repaint the page
repaint(); hrefClicked();
window.OfficeJS = (function () { window.OfficeJS = (function () {
var publ = {}, priv = {}; var publ = {}, priv = {};
...@@ -98,7 +137,7 @@ require(['OfficeJS'],function (OJS) { ...@@ -98,7 +137,7 @@ require(['OfficeJS'],function (OJS) {
return; return;
} }
filename = $('#input_fileName').attr('value'); filename = $('#input_fileName').attr('value');
filecontent = $('#input_content').attr('value'); filecontent = getCurrentEditor().getHTML();
priv.jio.saveDocument({ priv.jio.saveDocument({
'fileName':filename, 'fileName':filename,
'fileContent':filecontent, 'fileContent':filecontent,
...@@ -106,6 +145,7 @@ require(['OfficeJS'],function (OJS) { ...@@ -106,6 +145,7 @@ require(['OfficeJS'],function (OJS) {
'callback':function (result){ 'callback':function (result){
alert (result.isSaved ? 'Document Saved.' : alert (result.isSaved ? 'Document Saved.' :
'Error: ' + result.message); 'Error: ' + result.message);
publ.getlist();
} }
}); });
}; };
...@@ -121,12 +161,12 @@ require(['OfficeJS'],function (OJS) { ...@@ -121,12 +161,12 @@ require(['OfficeJS'],function (OJS) {
'maxtries':3, 'maxtries':3,
'callback':function (result){ 'callback':function (result){
if (result.document.fileName) { if (result.document.fileName) {
$('#input_content').attr( getCurrentEditor().setHTML(
'value',result.document.fileContent); result.document.fileContent);
alert ('Document loaded'); alert ('Document loaded');
} else { } else {
alert ('Error: ' + result.message); alert ('Error: ' + result.message);
} }
} }
}); });
}; };
...@@ -143,6 +183,7 @@ require(['OfficeJS'],function (OJS) { ...@@ -143,6 +183,7 @@ require(['OfficeJS'],function (OJS) {
'callback':function (result) { 'callback':function (result) {
alert (result.isRemoved?'Document Removed.': alert (result.isRemoved?'Document Removed.':
'Error: '+result.message); 'Error: '+result.message);
publ.getlist();
} }
}); });
}; };
...@@ -155,7 +196,7 @@ require(['OfficeJS'],function (OJS) { ...@@ -155,7 +196,7 @@ require(['OfficeJS'],function (OJS) {
'maxtries':3, 'maxtries':3,
'callback':function (result) { 'callback':function (result) {
var htmlString = '', i; var htmlString = '', i;
for (i in result.list) { for (i = 0; i < result.list.length; i += 1) {
htmlString += '<li>\n'; htmlString += '<li>\n';
htmlString += result.list[i].fileName; htmlString += result.list[i].fileName;
htmlString += '</li>\n'; htmlString += '</li>\n';
......
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