Commit 769179ee authored by François Billioud's avatar François Billioud

implements svg-editor

implements save/load from local document
parent ccd821cd
...@@ -11,12 +11,10 @@ var Xinha = function() { ...@@ -11,12 +11,10 @@ var Xinha = function() {
xinha_init(); xinha_init();
} }
this.saveEdition = function() { this.saveEdition = function() {
var textArea = $("#input_area"); getCurrentDocument().saveEdition($("#input_area").attr("value"));
getCurrentDocument().saveEdition(textArea.content);
} }
this.loadContent = function() { this.loadContentFromDocument = function(doc) {
var textArea = $("input_area"); $("#input_area").attr("value",doc.getContent());
textArea.content = getCurrentDocument().getContent();
} }
this.load(); this.load();
} }
...@@ -28,11 +26,11 @@ var Xinha = function() { ...@@ -28,11 +26,11 @@ var Xinha = function() {
*/ */
var JSONTextDocument = function() { var JSONTextDocument = function() {
JSONDocument.call(this);//inherits from JSONDocument JSONDocument.call(this);//inherits properties from JSONDocument
this.type = "text"; this.type = "text";
} }
JSONTextDocument.prototype = new JSONDocument(); JSONTextDocument.prototype = new JSONDocument();//inherits methods from JSONDocument
JSONTextDocument.prototype.saveEdition = function(content) { JSONTextDocument.prototype.saveEdition = function(content) {
this.setContent(content); this.setContent(content);
...@@ -42,6 +40,7 @@ JSONTextDocument.prototype.saveEdition = function(content) { ...@@ -42,6 +40,7 @@ JSONTextDocument.prototype.saveEdition = function(content) {
JSONTextDocument.prototype.setAsCurrentDocument = function() { JSONTextDocument.prototype.setAsCurrentDocument = function() {
getCurrentPage().displayDocumentTitle(this); getCurrentPage().displayDocumentTitle(this);
getCurrentPage().displayDocumentState(this); getCurrentPage().displayDocumentState(this);
getCurrentPage().displayDocumentContent(this);
getCurrentPage().displayAuthorName(this); getCurrentPage().displayAuthorName(this);
getCurrentPage().displayLastModification(this); getCurrentPage().displayLastModification(this);
setCurrentDocument(this); setCurrentDocument(this);
...@@ -53,19 +52,10 @@ getCurrentDocument = function() { ...@@ -53,19 +52,10 @@ getCurrentDocument = function() {
return doc; return doc;
} }
saveCurrentDocument = function() {
getCurrentPage().getEditor().saveEdition();
//saveJIO(); : JIO function
}
/*
// save // save
saveCurrentDocument = function() { saveXHR = function() {
//gestion fichier
var currentDocument = getLocalDocument();
currentDocument.updateDocument();
//create request //create request
var xhr=null; var xhr=null;
try try
...@@ -83,7 +73,7 @@ saveCurrentDocument = function() { ...@@ -83,7 +73,7 @@ saveCurrentDocument = function() {
//xhr.open("PUT", keyToUrl(key, wallet), true, wallet.userAddress, wallet.davToken); //xhr.open("PUT", keyToUrl(key, wallet), true, wallet.userAddress, wallet.davToken);
//HACK: //HACK:
xhr.open("PUT", currentUser.storage+"/dav/temp.json", true); xhr.open("PUT", "dav/temp.json", true);
xhr.setRequestHeader("Authorization", "Basic "+"nom:test"); xhr.setRequestHeader("Authorization", "Basic "+"nom:test");
//END HACK. //END HACK.
...@@ -91,17 +81,15 @@ saveCurrentDocument = function() { ...@@ -91,17 +81,15 @@ saveCurrentDocument = function() {
if(xhr.readyState == 4) { if(xhr.readyState == 4) {
if(xhr.status != 200 && xhr.status != 201 && xhr.status != 204) { if(xhr.status != 200 && xhr.status != 201 && xhr.status != 204) {
alert("error: got status "+xhr.status+" when doing basic auth PUT on url "+Base64.encode("nom:test")+" " + xhr.statusText); alert("error: got status "+xhr.status+" when doing basic auth PUT on url "+Base64.encode("nom:test")+" " + xhr.statusText);
} else {
lastModificationArea.innerHTML = currentDocument.getLastModification();
} }
} }
} }
xhr.withCredentials = "true"; xhr.withCredentials = "true";
xhr.send(JSON.stringify(currentDocument.getDocument())); xhr.send(JSON.stringify(getCurrentDocument()));
} }
// load // load
loadDocument = function() { loadXHR = function() {
//create request //create request
var xhr=null; var xhr=null;
...@@ -118,20 +106,18 @@ loadDocument = function() { ...@@ -118,20 +106,18 @@ loadDocument = function() {
} }
} }
xhr.open("GET", currentUser.storage+"/dav/temp.json", false); xhr.open("GET", "dav/temp.json", false);
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if(xhr.readyState == 4) { if(xhr.readyState == 4) {
var cDoc = null; var cDoc = new JSONTextDocument();
if(xhr.status == 200) { if(xhr.status == 200) {
cDoc = new Document(JSON.parse(xhr.responseText)); cDoc.load(JSON.parse(xhr.responseText));
} else { } else {
alert("error: got status "+xhr.status+" when doing basic auth GET on url "+"nom:test"+" " + xhr.statusText); alert("error: got status "+xhr.status+" when doing basic auth GET on url "+"nom:test"+" " + xhr.statusText);
cDoc = new Document(null);
} }
cDoc.updateHTML(); cDoc.setAsCurrentDocument();
setLocalDocument(cDoc);
} }
} }
xhr.send(); xhr.send();
}*/ }
/**
* Editors
*/
SVGEditor = function() {
this.name = "svg-editor";
this.load = function() {$("#svgframe").attr("src", "svg-editor/svg-editor.html")}
this.saveEdition = function() {
var s = "svgframe";
getCurrentDocument().saveEdition(window.frames[s].svgCanvas.getSvgString());
}
this.loadContentFromDocument = function(doc) {
var s = "svgframe";
window.frames[s].svgCanvas.setSvgString(doc.getContent());
}
var s = "svgframe";
this.svgCanvas = window.frames[s].svgCanvas;
this.load();
}
/**
* SVG documents
*/
var JSONIllustrationDocument = function() {
JSONDocument.call(this);//inherits properties from JSONDocument
this.type = "illustration";
}
JSONIllustrationDocument.prototype = new JSONDocument();//inherits methods from JSONDocument
JSONIllustrationDocument.prototype.saveEdition = function(content) {
this.setContent(content);
this.setLastModification(currentTime());
this.setAsCurrentDocument();
}
JSONIllustrationDocument.prototype.setAsCurrentDocument = function() {
getCurrentPage().displayDocumentTitle(this);
getCurrentPage().displayDocumentState(this);
getCurrentPage().displayDocumentContent(this);
getCurrentPage().displayAuthorName(this);
getCurrentPage().displayLastModification(this);
setCurrentDocument(this);
}
getCurrentDocument = function() {
var doc = new JSONIllustrationDocument();
doc.load(JSON.parse(localStorage.getItem("currentDocument")));
return doc;
}
// save
saveXHR = function() {
//create request
var xhr=null;
try
{
xhr = new XMLHttpRequest();
} catch(e)
{
try {xhr = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e2)
{
try {xhr = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e) {alert("Please install a more recent browser")}
}
}
//xhr.open("PUT", keyToUrl(key, wallet), true, wallet.userAddress, wallet.davToken);
//HACK:
xhr.open("PUT", "dav/temp2.json", true);
xhr.setRequestHeader("Authorization", "Basic "+"nom:test");
//END HACK.
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if(xhr.status != 200 && xhr.status != 201 && xhr.status != 204) {
alert("error: got status "+xhr.status+" when doing basic auth PUT on url "+Base64.encode("nom:test")+" " + xhr.statusText);
}
}
}
xhr.withCredentials = "true";
xhr.send(JSON.stringify(getCurrentDocument()));
}
// load
loadXHR = function() {
//create request
var xhr=null;
try
{
xhr = new XMLHttpRequest();
} catch(e)
{
try {xhr = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e2)
{
try {xhr = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e) {}
}
}
xhr.open("GET", "dav/temp2.json", false);
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
var cDoc = new JSONIllustrationDocument();
if(xhr.status == 200) {
cDoc.load(JSON.parse(xhr.responseText));
} else {
alert("error: got status "+xhr.status+" when doing basic auth GET on url "+"nom:test"+" " + xhr.statusText);
}
cDoc.setAsCurrentDocument();
}
}
xhr.send();
}
\ No newline at end of file
/**
* Editors
*/
SheetEditor = function() {
this.name = "JQuery Sheet Editor";
this.load = function() {
$("#jQuerySheet0").sheet({
buildSheet: '10x15',
title: 'Spreadsheet Playground',
inlineMenu: inlineMenu($.sheet.instance)
});
}
this.saveEdition = function() {}
this.loadContentFromDocument = function(doc) {}
this.load();
}
/*** /***
* Spreadsheet documents * Spreadsheet documents
*/ */
...@@ -26,6 +45,7 @@ JSONSheetDocument.prototype.load({ ...@@ -26,6 +45,7 @@ JSONSheetDocument.prototype.load({
//display document information //display document information
setAsCurrentDocument: function() { setAsCurrentDocument: function() {
getCurrentPage().displayDocumentTitle(this); getCurrentPage().displayDocumentTitle(this);
//getCurrentPage().displayDocumentContent(this);
getCurrentPage().displayDocumentState(this); getCurrentPage().displayDocumentState(this);
getCurrentPage().displayAuthorName(this); getCurrentPage().displayAuthorName(this);
getCurrentPage().displayLastModification(this); getCurrentPage().displayLastModification(this);
...@@ -34,17 +54,11 @@ JSONSheetDocument.prototype.load({ ...@@ -34,17 +54,11 @@ JSONSheetDocument.prototype.load({
}); });
getCurrentDocument = function() { getCurrentDocument = function() {
var doc = new JSONTextDocument(); var doc = new JSONSheetDocument();
doc.load(JSON.parse(localStorage.getItem("currentDocument"))); doc.load(JSON.parse(localStorage.getItem("currentDocument")));
return doc; return doc;
} }
saveCurrentDocument = function() {
getCurrentPage().getEditor().saveEdition();
//saveJIO(); : JIO function
}
...@@ -89,12 +103,4 @@ function goToObj(s) { ...@@ -89,12 +103,4 @@ function goToObj(s) {
return false; return false;
} }
$("#jQuerySheet0").sheet({
buildSheet: '10x15',
title: 'Spreadsheet Playground',
inlineMenu: inlineMenu($.sheet.instance)
});
/*
*/
\ No newline at end of file
...@@ -48,16 +48,25 @@ Page.prototype = { ...@@ -48,16 +48,25 @@ Page.prototype = {
}, },
/* update the HTML page from the XML document */ /* update the HTML page from the XML document */
loadPage: function() { loadPage: function() {
//Page content
this.displayPageTitle(); this.displayPageTitle();
this.displayPageContent(); this.displayPageContent();
var dependencies = this.getDependencies(); var dependencies = this.getDependencies();
$(dependencies).find("linkfile").each(function() {currentPage.include($(this).text(),"link");});//includes css $(dependencies).find("linkfile").each(function() {currentPage.include($(this).text(),"link");});//includes css
$(dependencies).find("scriptfile").each(function() {currentPage.include($(this).text(),"script");});//includes js $(dependencies).find("scriptfile").each(function() {currentPage.include($(this).text(),"script");});//includes js
switch(this.name) { switch(this.name) {
case "editor": case "editor":
this.editor = new Xinha(); this.editor = new Xinha();
break; break;
case "table":
this.editor = new SheetEditor();
break;
case "illustration":
this.editor = new SVGEditor();
break;
} }
}, },
/* include a javascript or a css file */ /* include a javascript or a css file */
include: function(file,type) { include: function(file,type) {
...@@ -101,6 +110,7 @@ Page.prototype = { ...@@ -101,6 +110,7 @@ Page.prototype = {
displayAuthorName: function(doc) {this.getHTML().getElementById("author").innerHTML = doc.getAuthor();}, displayAuthorName: function(doc) {this.getHTML().getElementById("author").innerHTML = doc.getAuthor();},
displayLastModification: function(doc) {this.getHTML().getElementById("last_update").innerHTML = doc.getLastModification();}, displayLastModification: function(doc) {this.getHTML().getElementById("last_update").innerHTML = doc.getLastModification();},
displayDocumentTitle: function(doc) {this.getHTML().getElementById("document_title").innerHTML = doc.getTitle();}, displayDocumentTitle: function(doc) {this.getHTML().getElementById("document_title").innerHTML = doc.getTitle();},
displayDocumentContent: function(doc) {this.getEditor().loadContentFromDocument(doc);},
displayDocumentState: function(doc) { displayDocumentState: function(doc) {
var stateArea = this.getHTML().getElementById("document_state"); var stateArea = this.getHTML().getElementById("document_state");
stateArea.innerHTML = doc.getState()[getCurrentUser().getLanguage()]; stateArea.innerHTML = doc.getState()[getCurrentUser().getLanguage()];
...@@ -164,7 +174,7 @@ setCurrentUser = function(user) {localStorage.setItem("currentUser", JSON.string ...@@ -164,7 +174,7 @@ setCurrentUser = function(user) {localStorage.setItem("currentUser", JSON.string
/* JSON document */ /* JSON document */
var JSONDocument = function() { var JSONDocument = function() {
this.type = "text"; this.type = null;
this.language = getCurrentUser().getLanguage(); this.language = getCurrentUser().getLanguage();
this.version = null; this.version = null;
...@@ -173,7 +183,7 @@ var JSONDocument = function() { ...@@ -173,7 +183,7 @@ var JSONDocument = function() {
this.content=""; this.content="";
this.creation=currentTime(); this.creation=currentTime();
this.lastModification=currentTime(); this.lastModification=currentTime();
this.state=Document.states.draft; this.state=this.states.draft;
} }
JSONDocument.prototype = new UngObject(); JSONDocument.prototype = new UngObject();
...@@ -216,7 +226,7 @@ JSONDocument.prototype.load({ ...@@ -216,7 +226,7 @@ JSONDocument.prototype.load({
save: function() {} save: function() {}
}); });
Document.states = { JSONDocument.prototype.states = {
draft:{"fr":"Brouillon","en":"Draft"}, draft:{"fr":"Brouillon","en":"Draft"},
saved:{"fr":"Enregistré","en":"Saved"}, saved:{"fr":"Enregistré","en":"Saved"},
deleted:{"fr":"Supprimé","en":"Deleted"} deleted:{"fr":"Supprimé","en":"Deleted"}
...@@ -235,7 +245,7 @@ setCurrentDocument = function(doc) {localStorage.setItem("currentDocument",JSON. ...@@ -235,7 +245,7 @@ setCurrentDocument = function(doc) {localStorage.setItem("currentDocument",JSON.
editDocumentSettings = function() { editDocumentSettings = function() {
$("#edit_document").dialog({ $("#edit_document").dialog({
autoOpen: false, autoOpen: true,
height: 131, height: 131,
width: 389, width: 389,
modal: true, modal: true,
...@@ -258,6 +268,12 @@ editDocumentSettings = function() { ...@@ -258,6 +268,12 @@ editDocumentSettings = function() {
}); });
} }
saveCurrentDocument = function() {
getCurrentPage().getEditor().saveEdition();
saveXHR();
//saveJIO(); : JIO function
}
changeLanguage = function(language) { changeLanguage = function(language) {
var user = getCurrentUser(); var user = getCurrentUser();
user.setLanguage(language); user.setLanguage(language);
......
...@@ -25,12 +25,20 @@ UngObject.prototype.load = function(data) { ...@@ -25,12 +25,20 @@ UngObject.prototype.load = function(data) {
/* Load methods from a class to another class */ /* Load methods from a class to another class */
UngObject.prototype.inherits = function(superClass) { UngObject.prototype.inherits = function(superClass) {
for (var element in superClass.prototype ) { this.prototype.load(superClass.prototype);
this.prototype[element] = superClass.prototype[element]
}
} }
/** /**
* returns the current date * returns the current date
*/ */
currentTime = function() {return (new Date()).toUTCString();} currentTime = function() {return (new Date()).toUTCString();}
\ No newline at end of file
/*
* wait an event before execute an action
*/
waitBeforeExecution = function(event, func) {
var waitBefore = function() {
if(event) {func.call();} else {setTimeout(waitBefore,1000)}
}
setTimeout(waitBefore,1000);
}
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<title> Page web - Web Page </title> <title> Page web - Web Page </title>
<content> <content>
<label> <label>
Contenu de la page Page Content
</label> </label>
<div class="input"> <div class="input">
......
<root>
<title> Illustration Web - Web Illustration </title>
<content>
<label>
Page Content
</label>
<div class="input"><div >
<iframe name="svgframe" id="svgframe" width="100%" height="600"/>
</div></div>
</content>
<dependencies>
<scriptfile>js/illustration.js</scriptfile>
<stylefile>css/jquery-ui.css</stylefile>
</dependencies>
</root>
...@@ -10,57 +10,7 @@ ...@@ -10,57 +10,7 @@
<link rel="stylesheet" href="js/jquery/plugin/sheet/jquery.sheet.css" type="text/css" /> <link rel="stylesheet" href="js/jquery/plugin/sheet/jquery.sheet.css" type="text/css" />
<link rel="stylesheet" href="jquery_sheet_editor/jquery.sheet.erp5.css" type="text/css" /> <link rel="stylesheet" href="jquery_sheet_editor/jquery.sheet.erp5.css" type="text/css" />
<link rel="stylesheet" href="js/jquery/plugin/colorpicker/jquery.colorPicker.css" type="text/css" /> <link rel="stylesheet" href="js/jquery/plugin/colorpicker/jquery.colorPicker.css" type="text/css" />
<link rel="stylesheet" href="js/jquery/plugin/colorpicker/menu.css" type="text/css" /> <!--<link rel="stylesheet" href="js/jquery/plugin/colorpicker/menu.css" type="text/css" />-->
<script type="text/javascript">
$("button.save").click(function(event){
source = $.sheet.instance[0].getSource(true);
$("input#my_text_content").attr("value", source)
});
$(function() {
$('#jQuerySheet0').sheet({
title: 'Spreadsheet Playground',
inlineMenu: inlineMenu($.sheet.instance),
urlGet: './getTextContent',
});
});
function inlineMenu(instance) {
var I = (instance ? instance.length : 0);
var html = $('#inlineMenu').html().replace(/sheetInstance/g, "$.sheet.instance[" + I + "]");
var menu = $(html);
menu.find('.colorPickerCell')
.colorPicker()
.change(function() {
$.sheet.instance[I].cellUndoable.add($.sheet.instance[I].obj.cellHighlighted());
$.sheet.instance[I].obj.cellHighlighted().css('background-color', $(this).val());
$.sheet.instance[I].cellUndoable.add($.sheet.instance[I].obj.cellHighlighted());
});
menu.find('.colorPickerFont')
.colorPicker()
.change(function() {
$.sheet.instance[I].cellUndoable.add($.sheet.instance[I].obj.cellHighlighted());
$.sheet.instance[I].obj.cellHighlighted().css('color', $(this).val());
$.sheet.instance[I].cellUndoable.add($.sheet.instance[I].obj.cellHighlighted());
});
menu.find('.colorPickers')
.children().eq(1).css('background-image', "url('jquery_sheet_image/palette.png')");
menu.find('.colorPickers')
.children().eq(3).css('background-image', "url('jquery_sheet_image/palette_bg.png')");
return menu;
}
function goToObj(s) {
$('html, body').animate({
scrollTop: $(s).offset().top
}, 'slow');
return false;
}
</script>
<div id="jQuerySheet0" style="height: 400px;"></div> <div id="jQuerySheet0" style="height: 400px;"></div>
...@@ -145,7 +95,7 @@ ...@@ -145,7 +95,7 @@
</span> </span>
<a href="#" onclick="sheetInstance.obj.formula().val('=HYPERLINK(\'' + prompt('Enter Web Address', 'http://www.visop-dev.com/') + '\')').keydown(); return false;" title="HyperLink"> <a href="#" onclick="sheetInstance.obj.formula().val('=HYPERLINK(\'' + prompt('Enter Web Address', 'http://www.visop-dev.com/') + '\')').keydown(); return false;" title="HyperLink">
<img alt="Web Link" src="jquery_sheet_image/page_link.png" /> <img alt="Web Link" src="jquery_sheet_editor/jquery_sheet_image/page_link.png" />
</a> </a>
<a href="#" onclick="sheetInstance.toggleFullScreen(); $('#lockedMenu').toggle(); return false;" title="Toggle Full Screen"> <a href="#" onclick="sheetInstance.toggleFullScreen(); $('#lockedMenu').toggle(); return false;" title="Toggle Full Screen">
<img alt="Web Link" src="jquery_sheet_editor/jquery_sheet_image/arrow_out.png" /> <img alt="Web Link" src="jquery_sheet_editor/jquery_sheet_image/arrow_out.png" />
...@@ -157,12 +107,15 @@ ...@@ -157,12 +107,15 @@
<dependencies> <dependencies>
<scriptfile>js/jquery/plugin/sheet/jquery.sheet.js</scriptfile> <scriptfile>js/jquery/plugin/sheet/jquery.sheet.js</scriptfile>
<scriptfile>js/jquery/plugin/mbmenu/mbMenu.min.js</scriptfile> <scriptfile>js/jquery/plugin/mbmenu/mbMenu.min.js</scriptfile>
<scriptfile>js/jquery/plugin/jqcharts/jgcharts.min.js</scriptfile> <scriptfile>js/jquery/plugin/jqchart/jgcharts.min.js</scriptfile>
<scriptfile>js/jquery/plugin/colorpicker/jquery.colorPicker.min.js</scriptfile> <scriptfile>js/jquery/plugin/colorpicker/jquery.colorPicker.min.js</scriptfile>
<scriptfile>js/jquery/plugin/elastic/jquery.elastic.min.js</scriptfile> <scriptfile>js/jquery/plugin/elastic/jquery.elastic.min.js</scriptfile>
<scriptfile>js/jquery/plugin/sheet/jquery.sheet.erp5.js</scriptfile> <scriptfile>js/jquery/plugin/sheet/jquery.sheet.js</scriptfile>
<scriptfile>js/jquery/plugin/jqcharts/jgcharts.min.js</scriptfile> <scriptfile>js/table.js</scriptfile>
<stylefile>js/jquery/plugin/sheet/jquery.sheet.css</stylefile> <stylefile>js/jquery/plugin/sheet/jquery.sheet.css</stylefile>
<stylefile>css/table.css</stylefile>
<stylefile>js/jquery/plugin/colorpicker/jquery.colorPicker.css</stylefile> <stylefile>js/jquery/plugin/colorpicker/jquery.colorPicker.css</stylefile>
<stylefile>css/jquery-ui.css</stylefile>
</dependencies> </dependencies>
</root> </root>
<link rel="stylesheet" href="css/jquery.sheet.erp5.css" type="text/css" />
\ No newline at end of file
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