Commit 4ae73e5a authored by François Billioud's avatar François Billioud

fix a bug when saving

fix Object.prototype issue
implement dialog box for document settings
create class JSONSheetDocument
parent 3e76914b
......@@ -11,11 +11,11 @@ var Xinha = function() {
xinha_init();
}
this.saveEdition = function() {
var textArea = getCurrentPage().getHTML().getElementById("input_area");
var textArea = $("#input_area");
getCurrentDocument().saveEdition(textArea.content);
}
this.loadContent = function() {
var textArea = getCurrentPage().getHTML().getElementById("input_area");
var textArea = $("input_area");
textArea.content = getCurrentDocument().getContent();
}
this.load();
......@@ -37,7 +37,7 @@ JSONTextDocument.prototype = new JSONDocument();
JSONTextDocument.prototype.saveEdition = function(content) {
this.setContent(content);
this.setLastModification(currentTime());
setCurrentDocument(this);
this.setAsCurrentDocument();
}
JSONTextDocument.prototype.setAsCurrentDocument = function() {
getCurrentPage().displayDocumentTitle(this);
......
/***
* Spreadsheet documents
*/
var JSONSheetDocument = function() {
JSONDocument.call(this);//inherits from JSONDocument
this.type = "sheet";
this.width = 10;
this.height = 15;
}
JSONSheetDocument.prototype = new JSONDocument();//inheritance
//accessors
JSONSheetDocument.prototype.getWidth = function() {return this.width;}
JSONSheetDocument.prototype.setWidth = function(newWidth) {this.width = newWidth;}
JSONSheetDocument.prototype.getHeight = function() {return this.height;}
JSONSheetDocument.prototype.setHeight = function(newHeight) {this.height = newHeight;}
//save process
JSONSheetDocument.prototype.saveEdition = function(content) {
this.setContent(content);
this.setLastModification(currentTime());
this.setAsCurrentDocument();
}
//display document information
JSONSheetDocument.prototype.setAsCurrentDocument = function() {
getCurrentPage().displayDocumentTitle(this);
getCurrentPage().displayDocumentState(this);
getCurrentPage().displayAuthorName(this);
getCurrentPage().displayLastModification(this);
setCurrentDocument(this);
}
getCurrentDocument = function() {
var doc = new JSONTextDocument();
doc.load(JSON.parse(localStorage.getItem("currentDocument")));
return doc;
}
saveCurrentDocument = function() {
getCurrentPage().getEditor().saveEdition();
//saveJIO(); : JIO function
}
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_editor/jquery_sheet_image/palette.png')");
menu.find('.colorPickers')
.children().eq(3).css('background-image', "url('jquery_sheet_editor/jquery_sheet_image/palette_bg.png')");
return menu;
}
function goToObj(s) {
$('html, body').animate({
scrollTop: $(s).offset().top
}, 'slow');
return false;
}
$("#jQuerySheet0").sheet({
buildSheet: '10x15',
title: 'Spreadsheet Playground',
inlineMenu: inlineMenu($.sheet.instance)
});
/*
*/
\ No newline at end of file
/***
* return true if this object implements the interface
* Class UngObject
*/
Object.prototype.Implements = function(myInterface)
UngObject = function() {}
/* return true if this object implements the interface */
UngObject.prototype.Implements = function(myInterface)
{
for(var property in myInterface)
{
......@@ -14,15 +16,19 @@ Object.prototype.Implements = function(myInterface)
return true;
};
/**
* Load a JSON data into an object
*/
Object.prototype.load = function(data) {
/* Load a JSON data into an object */
UngObject.prototype.load = function(data) {
for(var property in data) {
this[property] = data[property];
}
};
/* Load methods from a class to another class */
UngObject.prototype.inherits = function(superClass) {
for (var element in superClass.prototype ) {
this.prototype[element] = superClass.prototype[element]
}
}
/**
* returns the current date
......
......@@ -24,7 +24,6 @@
<link rel="stylesheet" type="text/css" href="css/theme.css" />
<script type="text/javascript"></script>
<script type="text/javascript" src="js/base64.js"></script>
<script type="text/javascript" src="js/tools.js"></script>
<script type="text/javascript" src="js/theme.js"></script>
......@@ -35,10 +34,12 @@
setCurrentPage("editor");
var user = getCurrentUser();
(user==null) ? (new User()).setAsCurrentDocument() : user.setAsCurrentUser();
if(!user) { user = new User();}
user.setAsCurrentUser();
var doc = getCurrentDocument();
(doc==null) ? (new JSONTextDocument()).setAsCurrentDocument() : doc.setAsCurrentDocument();
if(!doc) {doc = new JSONTextDocument();}
doc.setAsCurrentDocument();
}
$(document).ready(init);
</script>
......@@ -148,7 +149,7 @@
<a id="document_state" name="document_state">...</a>
<div id="edit_document" title="Rename Document">
<form>
<form action="#">
<fieldset>
<label for="name">Insert a new name:</label>
<input type="text" class="title" id="name" name="name" value=""/><br/>
......
......@@ -13,5 +13,6 @@
</content>
<dependencies>
<scriptfile>js/editor.js</scriptfile>
<stylefile>css/jquery-ui.css</stylefile>
</dependencies>
</root>
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