Commit 6316bf99 authored by Lingnan Wu's avatar Lingnan Wu

change the table editor for using the jquery sheet

parent f1163e98
......@@ -4,104 +4,75 @@
*/
SheetEditor = function() {
this.name = "JQuery Sheet Editor";
this.objectName = "SheetEditor" // name of the object reference
this.load = function() {
$("#jQuerySheet0").sheet({
buildSheet: '10x15',
title: 'Spreadsheet Playground',
inlineMenu: inlineMenu($.sheet.instance)
});
$('#jQuerySheet').sheet({
title: 'Spreadsheet Playground',
inlineMenu: inlineMenu(jQuery.sheet.instance),
buildSheet: '10x20',
autoFiller: true
});
}
this.saveEdition = function() {}
this.loadContentFromDocument = function(doc) {}
this.load();
}
/***
* 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.load({
getWidth: function() {return this.width;},
setWidth: function(newWidth) {this.width = newWidth;},
getHeight: function() {return this.height;},
setHeight: function(newHeight) {this.height = newHeight;},
//save process
saveEdition: function(content) {
this.setLastUser(getCurrentUser());
this.setContent(content);
this.setLastModification(getCurrentTime());
this.setAsCurrentDocument();
},
//display document information
setAsCurrentDocument: function() {
getCurrentPage().displayDocumentTitle(this);
//getCurrentPage().displayDocumentContent(this);
getCurrentPage().displayDocumentState(this);
getCurrentPage().displayLastUserName(this);
getCurrentPage().displayLastModification(this);
setCurrentDocument(this);
this.saveEdition = function() {
var sheetNumber = jQuery.sheet.instance[0].exportSheet.html().length;
var a="";
for(var i=0;i<sheetNumber;i++){
var objE=document.createElement("div");
objE.appendChild(jQuery.sheet.instance[0].exportSheet.html()[i]);
a=a+objE.innerHTML;
}
getCurrentDocument().saveEdition(a);
}
});
getCurrentDocument = function() {
var doc = new JSONSheetDocument();
doc.load(JSON.parse(localStorage.getItem("currentDocument")));
return doc;
this.loadContentFromDocument = function(doc) {
if(doc.getContent()){
jQuery.sheet.instance[0].killTab();
var o=parseDom(doc.getContent());
tryUntilSucceed(load = function() {
$('#jQuerySheet').sheet({
title: 'Spreadsheet Playground',
inlineMenu: inlineMenu(jQuery.sheet.instance),
buildSheet: o,
autoFiller:true
});
}
);
}
}
this.load();
}
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;
function inlineMenu(I){
I = (I ? I.length : 0);
//we want to be able to edit the html for the menu to make them multi-instance
var html = $('#inlineMenu').html().replace(/sheetInstance/g, "$.sheet.instance[" + I + "]");
var menu = $(html);
//The following is just so you get an idea of how to style cells
menu.find('.colorPickerCell').colorPicker().change(function(){
$.sheet.instance[I].cellChangeStyle('background-color', $(this).val());
});
menu.find('.colorPickerFont').colorPicker().change(function(){
$.sheet.instance[I].cellChangeStyle('color', $(this).val());
});
menu.find('.colorPickers').children().eq(1).css('background-image', "url('jquery.sheet/images/palette.png')");
menu.find('.colorPickers').children().eq(3).css('background-image', "url('jquery.sheet/images/palette_bg.png')");
return menu;
}
JSONDocument.prototype.type = "table";
JSONDocument.prototype.saveEdition = function(content) {
this.setLastUser(getCurrentUser().getName());
this.setContent(content);
this.setLastModification(getCurrentTime());
getCurrentPage().displayDocumentInformation(this);
}
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