Commit 8b66f91e authored by Tristan Cavelier's avatar Tristan Cavelier

OfficeJS: updated to work with jio, and security improved

parent b7e3ff26
<div id="basic_conflict_solver_div" style="text-align:center;" class="well"> <div id="basic_conflict_solver_div" style="text-align:center;" class="well">
<div class="row-fluid"> <div class="row-fluid">
<div class="span12"> <div class="span12">
A conflict occured while saving this document: There is a conflict in document <span id="basic_conflict_solver_docid"></span>
</div> </div>
</div> </div>
<div id="revisions"> <div id="revisions">
</div> </div>
<div class="row-fluid"> <div class="row-fluid">
<div class="span12"> <div class="span12">
<button onclick="basic_conflict_solver.abort()">Abort</button> <button onclick="OfficeJS_basic_conflict_solver.abort();">Abort</button>
</div> </div>
</div> </div>
</div> </div>
<script type="text/javascript">
<!--
window.basic_conflict_solver = {
conflict_object:{},
addRevision: function (doc) {
document.querySelector ('#basic_conflict_solver_div #revisions').
innerHTML += '<div class="row-fluid"><div class="span12">'+
'<div>'+(new Date(doc.last_modified)).toString()+'</div>'+
'<div><textarea id="'+doc.revision+'">'+doc.content+'</textarea></div>'+
'<div><button onclick="'+
//'console.log('+"'"+revision+"'"+');'+
"basic_conflict_solver.keepRevision('"+doc.revision+"');"+
'">Save this one</button></div><hr/>'+
'</div></div>';
},
addRemovedRevision: function (doc) {
document.querySelector ('#basic_conflict_solver_div #revisions').
innerHTML += '<div class="row-fluid"><div class="span12">'+
'<div>'+(new Date(doc.last_modified)).toString()+'</div>'+
'<div>Removed</div>'+
'<div><button onclick="'+
//'console.log('+"'"+revision+"'"+');'+
"basic_conflict_solver.removeRevision();"+
'">Save this one</button></div><hr/>'+
'</div></div>';
},
removeRevision: function () {
OfficeJS.solveConflict(this.conflict_object);
},
keepRevision: function (revision) {
OfficeJS.solveConflict(
this.conflict_object,
$('#'+revision).text()
);
},
abort: function () {
OfficeJS.abortSolveConflict();
}
};
//-->
</script>
...@@ -32,16 +32,18 @@ ...@@ -32,16 +32,18 @@
</script> </script>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
<!-- <!--
$().ready(function() { (function () {
var opts = { $().ready(function() {
cssClass : 'el-rte', var opts = {
lang : 'en', cssClass : 'el-rte',
height : 450, lang : 'en',
toolbar : 'complete', height : 450,
cssfiles : ['lib/elrte/css/elrte-inner.css'] toolbar : 'complete',
} cssfiles : ['lib/elrte/css/elrte-inner.css']
$('#elrte_editor').elrte(opts); }
}) $('#elrte_editor').elrte(opts);
});
}());
//--> //-->
</script> </script>
</head> </head>
...@@ -49,12 +51,12 @@ $().ready(function() { ...@@ -49,12 +51,12 @@ $().ready(function() {
<div> <div>
<input type="text" <input type="text"
name="fileName" name="fileName"
id="input_file_name" id="elrte_docid"
value="" value=""
placeholder="File name here" />&nbsp; placeholder="File name here" />&nbsp;
<button type="submit" <button type="submit"
class="btn btn-primary" class="btn btn-primary"
onclick="OfficeJS.save($('#input_file_name').attr('value'));"> onclick="OfficeJS_elrte.save();">
<i class="icon-download-alt icon-white"></i> <i class="icon-download-alt icon-white"></i>
Save Save
</button>&nbsp; </button>&nbsp;
......
...@@ -59,101 +59,7 @@ ...@@ -59,101 +59,7 @@
<!--/Optional--> <!--/Optional-->
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
$(function(){ OfficeJS_jquerysheet.firstload();
//Here is where we initiate the sheets
//every time sheet is created it creates a new jQuery.sheet.instance
//(array), to manipulate each sheet, the jQuery object is returned
$('#jQuerySheet').sheet({
title: '',
inlineMenu: inlineMenu($.sheet.instance),
urlGet: 'component/newspreadsheet.html',
// buildSheet: true,
editable: true,
autoFiller: true
});
//examples of how to use jQuery.sheet
/*
//Inline sheet(s), non-editable (like a gridview)
$('.jQuerySheet').sheet({
title: 'jQuery.sheet - The Web Based Spreadsheet Demo',
buildSheet: true, //will turn object #jQuerySheet's child tables into sheets
editable: false,
calcOff: true
});
//New single custom sized sheet
$('#jQuerySheet').sheet({
title: 'jQuery.sheet - The Web Based Spreadsheet Demo',
inlineMenu: inlineMenu(jQuery.sheet.instance),
buildSheet: '5x100'
});
//Custom object sheet(s)
$('#jQuerySheet').sheet({
title: 'jQuery.sheet - The Web Based Spreadsheet Demo',
inlineMenu: inlineMenu(jQuery.sheet.instance),
buildSheet: $('#jQuerySheet').find('table')
});
//Custom object sheet(s)
$('#jQuerySheet').sheet({
title: 'jQuery.sheet - The Web Based Spreadsheet Demo',
inlineMenu: inlineMenu(jQuery.sheet.instance),
buildSheet: $.sheet.makeTable.fromSize('5x100').add($.sheet.makeTable.fromSize('5x100'))
});
*/
//This is to give a themeswitcher on the page
//$('#themeSwitcher').themeswitcher();
//This is for some fancy menu stuff
var o = $('#structures');
var top = o.offset().top - 300;
$(document).scroll(function(e){
if ($(this).scrollTop() > top) {
$('#lockedMenu').removeClass('locked');
}
else {
$('#lockedMenu').addClass('locked');
}
}).scroll();
});
//This function builds the inline menu to make it easy to interact with each sheet instance
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('lib/jquery.sheet/images/palette.png')");
menu.find('.colorPickers').children().eq(3).
css('background-image',
"url('lib/jquery.sheet/images/palette_bg.png')");
return menu;
}
function goToObj(s){
$('html, body').animate({
scrollTop: $(s).offset().top
}, 'slow');
return false;
}
//--> //-->
</script> </script>
<!--Page styles--> <!--Page styles-->
...@@ -208,12 +114,12 @@ function goToObj(s){ ...@@ -208,12 +114,12 @@ function goToObj(s){
<div> <div>
<input type="text" <input type="text"
name="fileName" name="fileName"
id="input_file_name" id="jquery-sheet_docid"
value="" value=""
placeholder="File name here" />&nbsp; placeholder="File name here" />&nbsp;
<button type="submit" <button type="submit"
class="btn btn-primary" class="btn btn-primary"
onclick="OfficeJS.save($('#input_file_name').attr('value'));"> onclick="OfficeJS_jquerysheet.save();">
<i class="icon-download-alt icon-white"></i> <i class="icon-download-alt icon-white"></i>
Save Save
</button>&nbsp; </button>&nbsp;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<li> <li>
<a href="#/login" <a href="#/login"
onclick="javascript: onclick="javascript:
OfficeJS.open({app:'login'}); OfficeJS_left_nav_bar.login();
return false;"> return false;">
<i class="icon-ok"> <i class="icon-ok">
</i> </i>
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<li class="texteditor left-nav-tools"> <li class="texteditor left-nav-tools">
<a href="#/texteditor" <a href="#/texteditor"
onclick="javascript: onclick="javascript:
OfficeJS.open({app:'text_editor'}); OfficeJS_left_nav_bar.newTextDocument();
return false;"> return false;">
<i class="icon-font"></i> <i class="icon-font"></i>
New Text Document New Text Document
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<li class="imgeditor left-nav-tools"> <li class="imgeditor left-nav-tools">
<a href="#/imgeditor" <a href="#/imgeditor"
onclick="javascript: onclick="javascript:
OfficeJS.open({app:'img_editor'}); OfficeJS_left_nav_bar.newImage();
return false;"> return false;">
<i class="icon-pencil"></i> <i class="icon-pencil"></i>
New Image New Image
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<li class="spreadsheet left-nav-tools"> <li class="spreadsheet left-nav-tools">
<a href="#/spreadsheet" <a href="#/spreadsheet"
onclick="javascript: onclick="javascript:
OfficeJS.open({app:'spreadsheet'}); OfficeJS_left_nav_bar.newSpreadSheet();
return false;"> return false;">
<i class="icon-signal"></i> <i class="icon-signal"></i>
New Spreadsheet New Spreadsheet
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
<li class="spreadsheet left-nav-tools"> <li class="spreadsheet left-nav-tools">
<a href="#/workinprogress" <a href="#/workinprogress"
onclick="javascript: onclick="javascript:
OfficeJS.open({app:'workinprogress'}); OfficeJS_left_nav_bar.showActivities();
return false;"> return false;">
<i class="icon-tasks"></i> <i class="icon-tasks"></i>
Show Activity Show Activity
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
<!-- <li class="editpreferences left-nav-tools"> --> <!-- <li class="editpreferences left-nav-tools"> -->
<!-- <a href="#/edit_preferences" --> <!-- <a href="#/edit_preferences" -->
<!-- onclick="javascript: --> <!-- onclick="javascript: -->
<!-- OfficeJS.open({app:'edit_preferences'}); --> <!-- OfficeJS_left_nav_bar.editPreference(); -->
<!-- return false;"> --> <!-- return false;"> -->
<!-- <i class="icon-check"></i> --> <!-- <i class="icon-check"></i> -->
<!-- Edit Preferences --> <!-- Edit Preferences -->
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
<li id="nav_document_list_header left-nav-tools"> <li id="nav_document_list_header left-nav-tools">
<a href="#/doclist" <a href="#/doclist"
onclick="javascript: onclick="javascript:
OfficeJS.open({app:'document_lister'}); OfficeJS_left_nav_bar.showDocumentList();
return false;"> return false;">
<i class="icon-list"></i> <i class="icon-list"></i>
Document List Document List
......
...@@ -14,61 +14,66 @@ ...@@ -14,61 +14,66 @@
<div> <div>
Remember me&nbsp;&nbsp; Remember me&nbsp;&nbsp;
<input id="remember_me" type="checkbox" <input id="remember_me" type="checkbox"
onclick="window.OfficeJS_login.toggleRememberMe();"/> onclick="OfficeJS_login.object.toggleRememberMe();"/>
</div> </div>
<div> <div>
<button type="submit" <button type="submit"
class="btn" class="btn"
onclick="window.OfficeJS_login.createJIO();"> onclick="OfficeJS_login.object.connect();">
Create New JIO Create New JIO
</button> </button>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
window.OfficeJS_login = { (function () {
storageId:'#login-gadget #login_input', "use strict";
storagePath:'OfficeJS/login/login', var odf = function (obj,name,value) {
rememberId:'#login-gadget #remember_me', Object.defineProperty(obj,name,{
rememberPath:'OfficeJS/login/remember_me', configurable:false,enumerable:false,writable:false,value:value
localStorage: LocalOrCookieStorage, });
};
fillLogin: function () { odf(OfficeJS_login,'object',{});
$(this.storageId).attr( var that = OfficeJS_login.object;
'value',this.localStorage.getItem(this.storagePath) || ''); odf(OfficeJS_login.object,'storage_id','#login-gadget #login_input');
}, odf(OfficeJS_login.object,'storage_path','OfficeJS/login/login');
odf(OfficeJS_login.object,'remember_id','#login-gadget #remember_me');
isRememberMe: function () { odf(OfficeJS_login.object,'remember_path','OfficeJS/login/remember_me');
return $(this.rememberId).attr('checked'); odf(OfficeJS_login.object,'fillLogin',function () {
}, $(that.storage_id).attr(
fillRememberMe: function () { 'value',localStorage.getItem(that.storage_path) || '');
var t = this.localStorage.getItem(this.rememberPath); });
odf(OfficeJS_login.object,'isRememberMe',function () {
return $(that.remember_id).attr('checked');
});
odf(OfficeJS_login.object,'fillRememberMe',function () {
var t = localStorage.getItem(that.remember_path);
if (t) { if (t) {
this.rememberMe(); that.rememberMe();
} }
}, });
rememberMe: function () { odf(OfficeJS_login.object,'rememberMe',function () {
$(this.rememberId).attr('checked','1'); $(that.remember_id).attr('checked','1');
this.localStorage.setItem(this.rememberPath,'1'); localStorage.setItem(that.remember_path,'1');
}, });
dontRememberMe: function () { odf(OfficeJS_login.object,'dontRememberMe',function () {
$(this.rememberId).removeAttr('checked'); $(that.remember_id).removeAttr('checked');
this.localStorage.deleteItem(this.rememberPath); localStorage.deleteItem(that.remember_path);
}, });
toggleRememberMe: function () { odf(OfficeJS_login.object,'toggleRememberMe',function () {
var t = this.localStorage.getItem(this.rememberPath); var t = localStorage.getItem(that.remember_path);
if (t) { this.dontRememberMe() } else { this.rememberMe(); } if (t) { that.dontRememberMe() } else { that.rememberMe(); }
}, });
odf(OfficeJS_login.object,'connect',function () {
createJIO: function() {
var spec = $('#login-gadget #login_input').attr('value'); var spec = $('#login-gadget #login_input').attr('value');
this.localStorage.setItem(this.storagePath,spec); localStorage.setItem(that.storage_path,spec);
OfficeJS.setJio(spec); OfficeJS_login.connect (spec);
});
that.fillRememberMe();
if (that.isRememberMe()) {
that.fillLogin();
} }
}; }());
window.OfficeJS_login.fillRememberMe();
if (window.OfficeJS_login.isRememberMe()) {
window.OfficeJS_login.fillLogin();
}
//--> //-->
</script> </script>
</div> </div>
...@@ -24,8 +24,15 @@ ...@@ -24,8 +24,15 @@
<i class="icon-remove icon-white"></i> <i class="icon-remove icon-white"></i>
Remove Selected Remove Selected
</button> </button>
<button type="submit"
id="slickgrid_document_lister_refresh"
class="btn"
onclick="OfficeJS_slickgrid.refresh();">
<i class="icon-refresh"></i>
Refresh
</button>
</div> </div>
<div id="myDocumentList" style="width:100%;height:300px"></div> <div id="slickgrid_documentlist" style="width:100%;height:300px"></div>
<script type="text/javascript" <script type="text/javascript"
src="lib/jquery/jquery.js"></script> src="lib/jquery/jquery.js"></script>
<script type="text/javascript" <script type="text/javascript"
...@@ -42,135 +49,7 @@ ...@@ -42,135 +49,7 @@
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
window.OfficeJS_slickgrid = {}; OfficeJS_slickgrid.load();
window.OfficeJS_slickgrid.reload = function () {
$('#myDocumentList').html('');
var grid, onSortFunction, onClickFunction, check_box_selector,
onRemoveSeveral, showIconFormatter,
document_list = OfficeJS.cloneCurrentDocumentList(),
columns = [],
options = {
enableCellNavigation: true,
enableColumnReorder: false,
multiColumnSort: true,
forceFitColumns: true
};
showIconFormatter = function (row,cell,value,columnDef,dataContext) {
return dataContext.icon;
};
(function (array) {
var i, lm, cd, split, mime;
for (i = 0; i < array.length; i += 1) {
// file names
split = array[i].name.split('.');
array[i].ext = '';
if (split.length > 1) {
array[i].ext = split[split.length-1];
split.length -= 1;
}
array[i].base_name = split.join('.');
// app & icon
mime = OfficeJS.getMimeOfExt (array[i].ext);
if (!mime) {
array[i].icon = '?';
array[i].app = 'text_editor';
} else {
array[i].icon = mime.icon;
array[i].app = mime.preferred_application || mime.application;
}
if (array[i].revision) {
array[i].conflict = array[i].revision_object[
array[i].revision].conflict?'X':'';
} else {
array[i].conflict = '';
}
// dates
// FIXME : we can have 2012/1/1 12:5
// we should have 2012/01/01 12:05
lm = (new Date(array[i].last_modified));
cd = (new Date(array[i].creation_date));
array[i].last_modified = lm.getFullYear()+'/'+
(lm.getMonth()+1)+'/'+lm.getDate()+' '+
lm.getHours()+':'+lm.getMinutes();
array[i].creation_date = cd.getFullYear()+'/'+
(cd.getMonth()+1)+'/'+cd.getDate()+' '+
cd.getHours()+':'+cd.getMinutes();
}
}(document_list));
$(function () {
check_box_selector = new Slick.CheckboxSelectColumn({
cssClass: "slick-cell-checkboxsel"
});
columns.push(check_box_selector.getColumnDefinition());
columns.push({id:"icon",name:"",field:"icon",
sortable:true,resizable:false,width:24,
formatter:showIconFormatter});
columns.push({id:"file_name",name:"Document",
field:"base_name",sortable:true});
columns.push({id:"last_modified",name:"Modified",
field:"last_modified",sortable:true});
columns.push({id:"creation_date",name:"Created",
field:"creation_date",sortable:true});
columns.push({id:'on_conflict',name:'',
field:'conflict',sortable:true,
resizable:false,width:24});
grid = new Slick.Grid("#myDocumentList",
document_list,
columns,
options);
grid.setSelectionModel(new Slick.RowSelectionModel(
{selectActiveRow: false}));
grid.registerPlugin(check_box_selector);
onSortFunction = function (e, args) {
var cols = args.sortCols;
document_list.sort(function (data_row1, data_row2) {
var i, l, field, sign, value1, value2, result;
for (i = 0, l = cols.length; i < l; i++) {
field = cols[i].sortCol.field;
sign = cols[i].sortAsc ? 1 : -1;
value1 = data_row1[field];
value2 = data_row2[field];
result = (value1==value2?0:(value1>value2?1:-1))*sign;
if (result != 0) {
return result;
}
}
return 0;
});
grid.invalidate();
grid.render();
};
onClickFunction = function (e) {
var cell = grid.getCellFromEvent(e);
if (cell.cell === grid.getColumnIndex('file_name')) {
OfficeJS.open({app:document_list[cell.row].app,
file_name:document_list[cell.row].name});
}
};
onRemoveSeveral = function () {
var document_name_array = [], selected, i, l;
selected = grid.getSelectedRows();
for (i = 0, l = selected.length; i < l; i+= 1) {
document_name_array.push(document_list[selected[i]].name);
}
OfficeJS.removeSeveralFromArray (document_name_array);
};
document.querySelector ('#slickgrid_document_lister_remove_selected').
onclick = onRemoveSeveral;
grid.onClick.subscribe(onClickFunction);
grid.onSort.subscribe(onSortFunction);
});
};
window.OfficeJS_slickgrid.reload();
//--> //-->
</script> </script>
</body> </body>
......
<div> <div>
<input type="text" <input type="text"
name="fileName" name="fileName"
id="input_file_name" id="svg-edit_docid"
value="" value=""
placeholder="File name here" />&nbsp; placeholder="File name here" />&nbsp;
<button type="submit" <button type="submit"
class="btn btn-primary" class="btn btn-primary"
onclick="OfficeJS.save($('#input_file_name').attr('value'));"> onclick="OfficeJS_svgedit.save();">
<i class="icon-download-alt icon-white"></i> <i class="icon-download-alt icon-white"></i>
Save Save
</button>&nbsp; </button>&nbsp;
</div> </div>
<iframe src="lib/svg-edit/svg-editor.html" <iframe src="lib/svg-edit/svg-editor.html"
id="svg_edit_frame" id="svg-edit_frame"
style="width:100%; style="width:100%;
height:500px;" height:500px;"
scrolling="no"> scrolling="no">
......
...@@ -44,11 +44,11 @@ ...@@ -44,11 +44,11 @@
<li><h1>OfficeJS</h1></li> <li><h1>OfficeJS</h1></li>
<li><a href="#/about" <li><a href="#/about"
onclick="javascript: onclick="javascript:
OfficeJS.open({app:'about'}); OfficeJS_top_nav_bar.about();
return false;">About</a></li> return false;">About</a></li>
<li><a href="#/contact" <li><a href="#/contact"
onclick="javascript: onclick="javascript:
OfficeJS.open({app:'contact'}); OfficeJS_top_nav_bar.contact();
return false;">Contact</a></li> return false;">Contact</a></li>
</ul> </ul>
</div> </div>
......
<h2>Activities</h2> <h2>Activities</h2>
<div id="activities"></div> <div id="workinprogress_activities"></div>
<script type="text/javascript">
<!--
(function() {
var id;
if (typeof work_in_progress !== 'object') {
id = null;
work_in_progress = {
start:function(){
if (id === null) {
var update = function () {
var act = OfficeJS.getActivity(), i, str = '';
for (i = 0; i < act.length; i+= 1) {
str += act[i] + '<br />';
}
if (str === '') {
str = 'There is no on going tasks.<br />';
}
document.getElementById('activities').innerHTML = str;
};
update();
id = setInterval (update, 200);
}
},
stop:function(){
if (id !== null) {
clearInterval(id);
id = null;
}
}
};
}
}());
//-->
</script>
(function () { (function (scope) {
// Tools "use strict";
var baseName = function (file_name) { var odf = function (obj,name,value) {
var split = file_name.split('.'); Object.defineProperty(obj,name,{
if (split.length > 1) { configurable:false,enumerable:false,writable:false,value:value
split.length -= 1; });
return split.join('.');
} else {
return file_name;
}
}; };
var JIO = jio; var OfficeJS = {};
//////////////////////////////////////////////////////////////////////
/** odf(OfficeJS,'env',{});
* OfficeJS Object odf(OfficeJS,'tmp',{});
*/ odf(OfficeJS,'system',{});
window.OfficeJS = (function () { odf(OfficeJS,'run',{});
var that = {}, priv = {}; odf(OfficeJS,'lib',{});
// Attributes // odf(OfficeJS,'command',{});
priv.preference_object = {
document_lister:'slickgrid', //////////////////////////////////////////////////////////////////////
edit_preferences:'simplepreferenceeditor',
text_editor:'elrte', OfficeJS.system.preferences = {};
img_editor:'svg-edit', OfficeJS.system.applications = {};
spreadsheet:'jquery-sheet' OfficeJS.system.mime = {};
}; OfficeJS.system.icon = {};
priv.conflict_solver_object = {
// ext: "solver_name" // Top Nav Bar //
// default: "basic_conflict_solver" OfficeJS.system.applications['top_nav_bar'] = {
// ... name: 'top_nav_bar',
}; componentpath: 'component/top_nav_bar.html',
priv.app_object = { gadgetid: 'page-top_nav_bar',
topnavbar: { varname: 'OfficeJS_top_nav_bar',
type:'nav', api: {
path:'component/top_nav_bar.html', about: function () {
gadget_id:'page-top_nav_bar' OfficeJS.lib.openApplication(
}, OfficeJS.system.applications['about']);
leftnavbar: {
type:'nav',
path:'component/left_nav_bar.html',
gadget_id:'page-left_nav_bar',
bar_tools: false,
update: function () {
var elmt;
if (priv.isJioSet() && !this.bar_tools) {
// add tools to nav bar
elmt = document.querySelector ('script#left-nav-tools');
document.querySelector ('#left-nav-bar').innerHTML +=
elmt.innerHTML;
this.bar_tools = true;
}
}
},
login: {
type:'loader',
path:'component/login.html',
gadget_id:'page-content',
getContent: function () {
var tmp = {
user_name: 'NoName',
password: 'NoPwd'
};
// NOTE : stringify or not ?
return JSON.stringify (tmp);
}
},
about: {
type:'viewer',
path:'component/about.html',
gadget_id:'page-content'
},
contact: {
type:'viewer',
path:'component/contact.html',
gadget_id:'page-content'
},
simplepreferenceeditor: {
// NOTE
type:'editor',
path:''
// ...
},
elrte: {
type:'editor', // means it can edit a content
path:'component/elrte.html',
gadget_id:'page-content',
ext:'html',
element:'#elrte_editor',
getContent: function () {
$(this.element).elrte('updateSource');
return $(this.element).elrte('val');
},
setContent: function (content) {
$(this.element).elrte('val', content);
},
onload: function (param) {
// FIXME : wait for initialization end
setTimeout(function () {
if (typeof param.file_name !== 'undefined') {
$('#input_file_name').attr('value',
baseName(param.file_name));
that.load(baseName(param.file_name));
}
},1000);
}
// TODO : onunload, are you sure? leave without saving?
},
'jquery-sheet': {
type:'editor',
path:'component/jquery-sheet.html',
gadget_id:'page-content',
ext:'jqs',
getContent: function () {
return JSON.stringify (
$.sheet.instance[0].exportSheet.json()
);
},
setContent: function (content) {
$('#jQuerySheet').sheet({
title: '',
inlineMenu: inlineMenu($.sheet.instance),
buildSheet: $.sheet.makeTable.json(
JSON.parse(content)
),
autoFiller: true
});
},
onload: function (param) {
// FIXME : wait for initialization end
setTimeout(function () {
if (typeof param.file_name !== 'undefined') {
$('#input_file_name').attr('value',
baseName(param.file_name));
that.load(baseName(param.file_name));
}
},1000);
}
},
'svg-edit': {
type:'editor',
path:'component/svg-edit.html',
gadget_id:'page-content',
ext:'svg',
frameid:'svg_edit_frame',
getContent: function () {
return document.getElementById (this.frameid).
contentWindow.svgCanvas.getSvgString();
},
setContent: function (content) {
document.getElementById (this.frameid).
contentWindow.svgCanvas.setSvgString(content);
},
onload: function (param) {
var waitForInit = function (fun) {
// FIXME : wait for init end
setTimeout(fun,1000);
}
waitForInit(function () {
if (typeof param.file_name !== 'undefined') {
$('#input_file_name').attr('value',
baseName(param.file_name));
that.load(baseName(param.file_name));
}
});
}
},
slickgrid: {
type:'editor',
path:'component/slickgrid_document_lister.html',
gadget_id:'page-content',
interval_id:null,
onload: function () {
var t = this;
if (this.interval_id === null) {
this.interval_id = setInterval (function() {
that.getList(t.update);
}, 5000);
}
},
update: function () {
window.OfficeJS_slickgrid.reload();
},
onunload: function () {
if (this.interval_id !== null) {
clearInterval (this.interval_id);
this.interval_id = null;
}
delete window.OfficeJS_slickgrid;
return true;
}
}, },
workinprogress: { contact: function () {
type:'viewer', OfficeJS.lib.openApplication(
path:'component/workinprogress.html', OfficeJS.system.applications['contact']);
gadget_id:'page-content', }
onload: function () { },
var i = null, wait = function() { lib: {
// wait for workinprogress initialization end. spin:function (state) {
if (window.work_in_progress) { OfficeJS.system.applications['top_nav_bar'].spin[state]();
window.work_in_progress.start();
clearInterval(i);
}
}
i = setInterval (wait,100);
},
onunload: function () {
window.work_in_progress.stop();
delete window.work_in_progress;
return true;
}
}, },
basic_conflict_solver: { endspin:function (state) {
type:'solver', OfficeJS.system.applications['top_nav_bar'].spin['end'+state]();
path:'component/basic_conflict_solver.html',
gadget_id:'page-conflict',
onload: function (param) {
var rev_list = [], i;
for (var rev in param.conflict_object.revision_object) {
rev_list.push(rev);
}
// FIXME : load jobs are in conflict ! redesign jio !
var load = function (rev,i) {
if (rev) {
i++;
setTimeout(function() {
priv.jio.loadDocument(
param.conflict_object.path,{
revision: rev,
max_retry:3,
success: function (result) {
var doc = {
path:param.conflict_object.path,
content:result.content,
last_modified:result.last_modified,
creation_date:result.creation_date,
revision:rev
};
window.basic_conflict_solver.
conflict_object =
param.conflict_object;
window.basic_conflict_solver.
addRevision(doc);
load(rev_list[i],i);
},
error: function (error) {
var doc = {
path:param.conflict_object.path,
revision:rev
};
window.basic_conflict_solver.
conflict_object =
param.conflict_object;
if (error.status === 404) {
window.basic_conflict_solver.
addRemovedRevision(doc);
} else {
console.error (error.message);
}
load(rev_list[i],i);
}
});
});
}
};
load (rev_list[0],0);
// NOTE : improve, don't load already loaded revision
}
} }
}; },
priv.mime_object = { spin: {
// <preferred_application> if the name of the app set in
// preferences.
// If <preferred_application> does not exist it means that the
// extension is very specific, so <application> is called instead of
// the default editor.
// NOTE : the icon may be set in the app in app_object.
html:{preferred_application:'text_editor',application:'elrte',
icon:'<i class="icon-font"></i>'},
svg:{preferred_application:'img_editor',application:'svg-edit',
icon:'<i class="icon-pencil"></i>'},
jqs:{application:'jquery-sheet',
icon:'<i class="icon-signal"></i>'}
};
priv.data_object = {
documentList:[],
gadget_object:{}, // contains current gadgets id with their location
currentFile:null,
currentEditor:null,
currentSolver:null,
currentApp:null,
currentActivity:null,
currentRevision:null
};
priv.loading_object = {
spinstate: 0, spinstate: 0,
savestate: 0, savestate: 0,
loadstate: 0, loadstate: 0,
...@@ -304,7 +59,7 @@ ...@@ -304,7 +59,7 @@
} }
this[string+'state'] ++; this[string+'state'] ++;
}, },
end_main: function (string){ endmain: function (string){
if (this[string+'state']>0) { if (this[string+'state']>0) {
this[string+'state']--; this[string+'state']--;
} }
...@@ -318,510 +73,1018 @@ ...@@ -318,510 +73,1018 @@
load:function(){this.main('load');this.spin();}, load:function(){this.main('load');this.spin();},
getlist:function(){this.main('getlist');this.spin();}, getlist:function(){this.main('getlist');this.spin();},
remove:function(){this.main('remove');this.spin();}, remove:function(){this.main('remove');this.spin();},
end_spin:function(){this.end_main('spin');}, endspin:function(){this.endmain('spin');},
end_save:function(){this.end_main('save');this.end_spin();}, endsave:function(){this.endmain('save');this.endspin();},
end_load:function(){this.end_main('load');this.end_spin();}, endload:function(){this.endmain('load');this.endspin();},
end_getlist:function(){this.end_main('getlist');this.end_spin();}, endgetlist:function(){this.endmain('getlist');this.endspin();},
end_remove:function(){this.end_main('remove');this.end_spin();} endremove:function(){this.endmain('remove');this.endspin();}
}; }
priv.lastfailure = {}; };
// Initializer // // End Top Nav Bar //
priv.init = function() {
};
// Methods //
/**
* Shows a list of document inside the left nav bar
* @method showDocumentListInsideLeftNavBar
*/
priv.showDocumentListInsideLeftNavBar = function () {
$('#nav_document_list_header').show();
};
/** // Left Nav Bar //
* @method getRealApplication OfficeJS.system.applications['left_nav_bar'] = {
* @param {string} appname The app name set in preference. name: 'left_nav_bar',
* @return {object} The real application object. componentpath: 'component/left_nav_bar.html',
*/ gadgetid: 'page-left_nav_bar',
priv.getRealApplication = function (appname) { varname: 'OfficeJS_left_nav_bar',
var realappname = that.getPreference (appname); api: {
if (!realappname) { login: function () {
return priv.app_object[appname]; OfficeJS.lib.openApplication(
OfficeJS.system.applications['login']
);
},
newTextDocument: function () {
OfficeJS.lib.openApplication(
OfficeJS.lib.getAppFromPref('html-editor')
);
},
newImage: function () {
OfficeJS.lib.openApplication(
OfficeJS.lib.getAppFromPref('svg-editor')
);
},
newSpreadSheet: function () {
OfficeJS.lib.openApplication(
OfficeJS.lib.getAppFromPref('jqs-sheet')
);
},
showActivities: function () {
OfficeJS.lib.openApplication(
OfficeJS.lib.getAppFromPref('activities')
);
},
showDocumentList: function () {
OfficeJS.lib.openApplication(
OfficeJS.lib.getAppFromPref('documentlister')
);
} }
return priv.app_object[realappname]; },
}; lib:{
showTools: function () {
/** var elmt;
* @method isJioSet if (OfficeJS.run.jio && !OfficeJS.tmp.tools_opened) {
* @return {boolean} true if jio is set else false. OfficeJS.tmp.tools_opened = true;
*/ elmt = document.querySelector ('script#left-nav-tools');
priv.isJioSet = function () { document.querySelector ('#left-nav-bar').innerHTML +=
return (typeof priv.jio === 'object'); elmt.innerHTML;
}; }
/**
* Opens an application
* @method open
* @param {object} option Contains some settings:
* - app {string} The app name we want to open, set in preferences
* - force {boolean} To reload applications even if it is the same.
* (optional)
* - ... and some other parameters
*/
that.open = function (option) {
var realapp, realgadgetid, realpath, acientapp;
if (!option) {
console.error ('open: This function needs a parameter');
return null;
};
realapp = priv.getRealApplication (option.app);
if (!realapp) {
// cannot get real app
console.error ('Unknown application: ' + option.app);
return null;
} }
realgadgetid = option.gadget_id || realapp.gadget_id; }
realpath = realapp.path; };
if (option.force || priv.data_object.currentEditor !== realapp) { // End Left Nav Bar //
ancientapp = priv.data_object.gadget_object[realgadgetid];
if (ancientapp) { // login //
// if there is already a gadget there, unload it OfficeJS.system.applications['login'] = {
if (typeof ancientapp.onunload !== 'undefined' && name: 'login',
!ancientapp.onunload()) { componentpath: 'component/login.html',
// if onunload return false, it means that we must not gadgetid: 'page-content',
// load a new gadget because this one is not ready to varname: 'OfficeJS_login',
// exit. api: {
return null; connect: function (spec) {
if (!OfficeJS.run.jio) {
if (typeof spec === 'string') {
spec = JSON.parse (spec);
} }
OfficeJS.run.jio = jio.newJio(spec);
OfficeJS.system.applications['left_nav_bar'].
lib.showTools();
OfficeJS.lib.allDocs();
} }
priv.data_object.gadget_object[realgadgetid] = realapp;
TabbularGadget.addNewTabGadget(realpath,realgadgetid);
// set current editor
switch (realapp.type) {
case 'editor':
priv.data_object.currentEditor = realapp;
break;
case 'solver':
priv.data_object.currentSolver = realapp;
break;
default:
break;
}
priv.data_object.currentApp = realapp;
}
// onload call
if (typeof realapp.onload !== 'undefined') {
return realapp.onload(option);
} }
}; }
};
// End login //
/** // about //
* Load an empty page in the place of a specific gadget id OfficeJS.system.applications['about'] = {
* @method closeGadgetId type: 'about',
* @param {string} gadgetid The gadget id 'class': 'viewer',
*/ name: 'about',
that.closeGadgetId = function (gadgetid) { componentpath: 'component/about.html',
TabbularGadget.addNewTabGadget('component/empty.html',gadgetid); gadgetid: 'page-content'
}; };
// End about //
/** // contact //
* @method getPreference OfficeJS.system.applications['contact'] = {
* @param {string} key The preference type: 'contact',
* @return {string} The content of the preference. 'class': 'viewer',
*/ name: 'contact',
that.getPreference = function (key) { componentpath: 'component/contact.html',
return priv.preference_object[key]; gadgetid: 'page-content'
}; };
// End contact //
/** // elRTE //
* @method getContentOf OfficeJS.system.applications['elrte'] = {
* @param {string} app The application name type: 'html-editor',
* @return {string} The content of the application, or null. name: 'elrte',
*/ 'class': 'editor',
that.getContentOf = function (app) { componentpath: 'component/elrte.html',
var realapp = priv.getRealApplication (app); gadgetid: 'page-content',
if (!realapp) { varname: 'OfficeJS_elrte',
console.error ('Unknown application: ' + app); exts: ['html'],
return null; default_ext: 'html',
docid_elmnt: '#elrte_docid',
editor_elmnt: '#elrte_editor',
api: {
save: function () {
var id, content;
id = OfficeJS.system.applications['elrte'].
lib.getDocId();
content = OfficeJS.system.applications['elrte'].
lib.getContent();
console.log ('content ' + content);
if (id) {
OfficeJS.lib.put({
_id:id+'.'+OfficeJS.system.applications['elrte'].
default_ext,
content:content||''
},function (err,val) {
setTimeout(function(){
OfficeJS.lib.allDocs();
});
});
}
} }
if (typeof realapp.getContent !== 'undefined') { },
return realapp.getContent(); lib: {
getDocId: function () {
return $(OfficeJS.system.applications['elrte'].docid_elmnt).
attr('value');
},
getContent: function () {
$(OfficeJS.system.applications['elrte'].editor_elmnt).
elrte('updateSource');
return $(OfficeJS.system.applications['elrte'].editor_elmnt).
elrte('val');
},
setDocId: function (docid) {
$(OfficeJS.system.applications['elrte'].docid_elmnt).
attr('value',docid);
},
setContent: function (content) {
return $(OfficeJS.system.applications['elrte'].editor_elmnt).
elrte('val',content);
} }
return null; },
}; onload: function (doc) {
if (doc) {
/** setTimeout(function(){
* @method getPathOf OfficeJS.system.applications['elrte'].
* @param {string} app The application name lib.setDocId(OfficeJS.lib.basename(doc._id));
* @return {string} The path of the application component, or null. OfficeJS.system.applications['elrte'].
*/ lib.setContent('loading...');
that.getPathOf = function (app) { console.log ('get docid ' + doc._id);
var realapp = priv.getRealApplication (app); OfficeJS.lib.get(doc._id,null,function (err,val) {
if (!realapp) { if (val) {
console.error ('Unknown application: ' + app); console.log ('receive ' + JSON.stringify (val));
return null; OfficeJS.system.applications['elrte'].
lib.setContent(val.content);
} else {
// TODO :
}
});
},500); // FIXME :
} }
return realapp.path; },
}; update: function (content) {
OfficeJS.system.applications['elrte'].lib.setContent (content);
/** }
* Returns the current editor file extension. };
* @return {string} The current editor file extension. OfficeJS.system.preferences['html-editor'] =
*/ OfficeJS.system.applications['elrte'];
that.getExt = function () { OfficeJS.system.mime['html'] = 'html-editor';
return priv.data_object.currentEditor.ext; OfficeJS.system.icon['html'] = '<i class="icon-font"></i>';
}; // End elRTE //
/** // svg edit //
* Returns a clone of the mime object having this file [extension]. OfficeJS.system.applications['svg-edit'] = {
* @method getMimeOfExt type: 'svg-editor',
* @param {string} extension The extension without '.'. name: 'svg-edit',
* @return {object} A clone of the mime object 'class': 'editor',
*/ componentpath: 'component/svg-edit.html',
that.getMimeOfExt = function (extension) { gadgetid: 'page-content',
if (typeof priv.mime_object[extension] === 'undefined') { varname: 'OfficeJS_svgedit',
return null; exts: ['svg'],
default_ext: 'svg',
docid_elmnt: '#svg-edit_docid',
editor_elmnt: '#svg-edit_frame',
api: {
save: function () {
var id, content;
id = OfficeJS.system.applications['svg-edit'].
lib.getDocId();
content = OfficeJS.system.applications['svg-edit'].
lib.getContent();
if (id) {
OfficeJS.lib.put({
_id:id+'.'+OfficeJS.system.applications['svg-edit'].
default_ext,
content:content||''
},function (err,val) {
setTimeout(function(){
OfficeJS.lib.allDocs();
});
});
}
} }
return $.extend (true,{},priv.mime_object[extension]); },
}; lib:{
getDocId: function () {
/** return $(OfficeJS.system.applications['svg-edit'].docid_elmnt).
* @method setJio attr('value');
* @param {object} storage The storage informations },
*/ setDocId: function (docid) {
that.setJio = function (storage) { $(OfficeJS.system.applications['svg-edit'].docid_elmnt).
var leftnavbar; attr('value',docid);
if (priv.isJioSet()) { },
alert ('Jio already set.'); getContent: function () {
return; return document.querySelector (
OfficeJS.system.applications['svg-edit'].editor_elmnt).
contentWindow.svgCanvas.getSvgString();
},
setContent: function (content) {
return document.querySelector (
OfficeJS.system.applications['svg-edit'].editor_elmnt).
contentWindow.svgCanvas.setSvgString(content);
} }
// if there is not any jio created },
priv.jio = JIO.newJio (JSON.parse(storage)); onload: function (doc) {
// update left nav bar if (doc) {
leftnavbar = priv.getRealApplication ('leftnavbar'); setTimeout(function(){
if (typeof leftnavbar.update !== 'undefined') { OfficeJS.system.applications['svg-edit'].
leftnavbar.update(); lib.setDocId(OfficeJS.lib.basename(doc._id));
OfficeJS.lib.get(doc._id,null,function (err,val) {
if (val) {
OfficeJS.system.applications['svg-edit'].
lib.setContent(val.content);
} else {
// TODO :
}
});
},500); // FIXME :
} }
that.getList(); }
}; };
OfficeJS.system.preferences['svg-editor'] =
OfficeJS.system.applications['svg-edit'];
OfficeJS.system.mime['svg'] = 'svg-editor';
OfficeJS.system.icon['svg'] = '<i class="icon-pencil"></i>';
// End svg edit //
/** // jquery-sheet //
* Returns the array list in priv.data_object OfficeJS.system.applications['jquery-sheet'] = {
* @method getList type: 'jqs-sheet',
* @param {function} callback Another callback called after retrieving name: 'jquery-sheet',
* the list. (optional) 'class': 'editor',
*/ componentpath: 'component/jquery-sheet.html',
that.getList = function (callback) { gadgetid: 'page-content',
if (!priv.isJioSet()) { varname: 'OfficeJS_jquerysheet',
console.error ('No Jio set yet.'); exts: ['jqs'],
return; default_ext: 'jqs',
docid_elmnt: '#jquery-sheet_docid',
sheet_elmnt: '#jQuerySheet',
api: {
save: function () {
var id, content;
id = OfficeJS.system.applications['jquery-sheet'].
lib.getDocId();
content = OfficeJS.system.applications['jquery-sheet'].
lib.getContent();
if (id) {
OfficeJS.lib.put({
_id:id+'.'+OfficeJS.system.applications['jquery-sheet'].
default_ext,
content:content||''
},function (err,val) {
setTimeout(function(){
OfficeJS.lib.allDocs();
});
});
}
},
firstload: function () {
OfficeJS.system.applications['jquery-sheet'].lib.firstload();
} }
priv.loading_object.getlist(); },
priv.jio.getDocumentList( lib:{
'.',{ getDocId: function () {
sort:{last_modified:'descending', return $(OfficeJS.system.applications['jquery-sheet'].
name:'ascending'}, docid_elmnt).attr('value');
limit:{begin:0,end:50}, },
// search:{name:'a'}, setDocId: function (docid) {
max_retry:3, $(OfficeJS.system.applications['jquery-sheet'].
success: function (result) { docid_elmnt).attr('value',docid);
priv.data_object.documentList = result; },
priv.showDocumentListInsideLeftNavBar(); getContent: function () {
priv.loading_object.end_getlist(); return JSON.stringify (
if (typeof callback === 'function') { $.sheet.instance[0].exportSheet.json()
callback(); );
} },
}, setContent: function (content) {
error: function (error) { return $(OfficeJS.system.applications['jquery-sheet'].
priv.lastfailure.path = '.'; sheet_elmnt).sheet({
priv.lastfailure.method = 'getDocumentList'; title: '',
console.error (error.message); inlineMenu: OfficeJS.system.applications[
priv.loading_object.end_getlist(); 'jquery-sheet'].lib.inlineMenu(
if (typeof callback === 'function') { $.sheet.instance),
callback(); buildSheet: $.sheet.makeTable.json(
} JSON.parse (content)),
} autoFiller: true
});
},
//This function builds the inline menu to make it easy to
//interact with each sheet instance
inlineMenu: function (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());
}); });
};
that.cloneCurrentDocumentList = function () { menu.find('.colorPickers').children().eq(1).
// clone document list css('background-image',
return $.extend(true,[],priv.data_object.documentList); "url('lib/jquery.sheet/images/palette.png')");
}; menu.find('.colorPickers').children().eq(3).
css('background-image',
"url('lib/jquery.sheet/images/palette_bg.png')");
return menu;
},
firstload: function () {
//Here is where we initiate the sheets
//every time sheet is created it creates a new
//jQuery.sheet.instance
//(array), to manipulate each sheet,
//the jQuery object is returned
$('#jQuerySheet').sheet({
title: '',
inlineMenu: OfficeJS.system.applications[
'jquery-sheet'].lib.inlineMenu($.sheet.instance),
urlGet: 'component/newspreadsheet.html',
// buildSheet: true,
editable: true,
autoFiller: true
});
/** //This is for some fancy menu stuff
* Saves the document. var o = $('#structures');
* @method save var top = o.offset().top - 300;
* @param {string} basename The document name without ext. $(document).scroll(function(e){
*/ if ($(this).scrollTop() > top) {
that.save = function (basename) { $('#lockedMenu').removeClass('locked');
var current_editor = priv.data_object.currentEditor, }
current_content = current_editor.getContent(); else {
if (!priv.isJioSet()) { $('#lockedMenu').addClass('locked');
console.error ('No Jio set yet.'); }
return; }).scroll();
} }
priv.loading_object.save(); },
priv.jio.saveDocument( onload: function (doc) {
basename+'.'+current_editor.ext, if (doc) {
current_content,{ setTimeout(function(){
previous_revision: priv.data_object.currentRevision || '0', OfficeJS.system.applications['jquery-sheet'].
success: function (result) { lib.setDocId(OfficeJS.lib.basename(doc._id));
if (result && result.revision) { OfficeJS.lib.get(doc._id,null,function (err,val) {
priv.data_object.currentRevision = result.revision; if (val) {
} OfficeJS.system.applications['jquery-sheet'].
priv.loading_object.end_save(); lib.setContent(val.content);
that.getList(); } else {
}, // TODO :
error: function (error) {
priv.lastfailure.path = basename;
priv.lastfailure.method = 'saveDocument';
console.error (error.message);
priv.loading_object.end_save();
that.getList();
if (error.conflict_object) {
priv.onConflict (error.conflict_object);
} }
});
},500); // FIXME :
}
}
};
OfficeJS.system.preferences['jqs-sheet'] =
OfficeJS.system.applications['jquery-sheet'];
OfficeJS.system.mime['jqs'] = 'jqs-sheet';
OfficeJS.system.icon['jqs'] = '<i class="icon-signal"></i>';
// End jquery-sheet //
// slickgrid //
OfficeJS.system.applications['slickgrid'] = {
type: 'documentlister',
name: 'slickgrid',
'class': 'viewer',
componentpath: 'component/slickgrid_document_lister.html',
gadgetid: 'page-content',
varname: 'OfficeJS_slickgrid',
list_elmnt: '#slickgrid_documentlist',
api: {
load: function () {
setTimeout (function () {
try {
OfficeJS.tmp.slick_reload = 0;
OfficeJS.system.applications['slickgrid'].lib.reload();
} catch (e) {} // avoid reload the wrong component
});
},
refresh: function () {
OfficeJS.lib.allDocs(function (err,val) {
if (val) {
try {
OfficeJS.tmp.slick_reload = 0;
OfficeJS.system.applications['slickgrid'].
lib.reload();
} catch (e) {} // avoid reload the wrong component
} else {
// TODO :
} }
}); });
};
/**
* Loads a document.
* @method load
* @param {string} basename The document name without ext.
*/
that.load = function (basename) {
var current_editor = priv.data_object.currentEditor;
if (!priv.isJioSet()) {
console.error ('No Jio set yet.');
return;
} }
priv.loading_object.load(); },
priv.jio.loadDocument( lib:{
basename+'.'+current_editor.ext,{ reload: function () {
max_retry:3, var grid, onSortFunction, onClickFunction,
success: function (result) { check_box_selector, i, array,
if (result && result.revision) { onRemoveSeveral,showIconFormatter,
priv.data_object.currentRevision = result.revision; document_list,columns,options;
if (result.conflict_object) {
priv.onConflict(result.conflict_object); if (!OfficeJS.tmp.documentlist) {
if (OfficeJS.tmp.slick_reload === 3) { return; }
setTimeout(function() {
OfficeJS.tmp.slick_reload =
OfficeJS.tmp.slick_reload?
OfficeJS.tmp.slick_reload++:1;
OfficeJS.system.applications['slickgrid'].lib.reload();
},100);
return;
}
$(OfficeJS.system.applications['slickgrid'].
list_elmnt).html('');
document_list = OfficeJS.tmp.documentlist;
options = {
enableCellNavigation: true,
enableColumnReorder: false,
multiColumnSort: true,
forceFitColumns: true
};
showIconFormatter = function (
row,cell,value,columnDef,dataContext) {
return dataContext.icon;
};
// make array
array = [];
for (i = 0; i < document_list.total_rows; i+= 1) {
var arrayi = {}, lm, cd, j;
arrayi.id = document_list.rows[i].id;
arrayi.basename = OfficeJS.lib.basename(arrayi.id);
arrayi.ext = OfficeJS.lib.extOf(arrayi.id);
if (arrayi.ext) {
arrayi.icon = OfficeJS.system.icon[arrayi.ext] || '?';
arrayi.app = OfficeJS.lib.getAppFromMime(arrayi.ext) ||
OfficeJS.lib.getAppFromPref('html-editor');
} else {
arrayi.icon = '?';
arrayi.app = OfficeJS.lib.getAppFromPref('html-editor');
}
if (document_list.conflicts) {
arrayi.conflict = '';
for (j = 0;
j < document_list.conflicts.total_rows;
j+= 1) {
if (document_list.conflicts.rows[j].id ===
arrayi.id) {
var row = document_list.conflicts.rows[j];
arrayi.conflict = 'X';
arrayi.showConflict = function () {
console.log ('showConflict');
OfficeJS.lib.openApplication(
OfficeJS.lib.getAppFromPref(
'conflictsolver'),
{_id:arrayi.id,row:row} // wrong
);
};
break;
} }
} }
current_editor.setContent(result.content);
priv.loading_object.end_load();
},
error: function (error) {
priv.lastfailure.path = basename;
priv.lastfailure.method = 'loadDocument';
console.error (error.message);
priv.loading_object.end_load();
} }
// dates
// FIXME : we can have 2012/1/1 12:5
// we should have 2012/01/01 12:05
lm = (new Date(document_list.rows[i].value._last_modified));
cd = (new Date(document_list.rows[i].value._creation_date));
arrayi.last_modified = lm.getFullYear()+'/'+
(lm.getMonth()+1)+'/'+lm.getDate()+' '+
lm.getHours()+':'+lm.getMinutes();
arrayi.creation_date = cd.getFullYear()+'/'+
(cd.getMonth()+1)+'/'+cd.getDate()+' '+
cd.getHours()+':'+cd.getMinutes();
array.push(arrayi);
}
check_box_selector = new Slick.CheckboxSelectColumn({
cssClass: "slick-cell-checkboxsel"
}); });
}; columns = [];
columns.push(check_box_selector.getColumnDefinition());
/** columns.push({id:"icon",name:"",field:"icon",
* Removes a document. sortable:true,resizable:false,width:24,
* @method remove formatter:showIconFormatter});
* @param {string} name The document name. columns.push({id:"file_name",name:"Document",
* @param {string} revision The document name. field:"basename",sortable:true});
*/ columns.push({id:"last_modified",name:"Modified",
that.remove = function (name,revision) { field:"last_modified",sortable:true});
console.log (arguments); columns.push({id:"creation_date",name:"Created",
if (!priv.isJioSet()) { field:"creation_date",sortable:true});
console.error ('No Jio set yet.'); if (document_list.conflicts) {
return; columns.push({id:'on_conflict',name:'',
} field:'conflict',sortable:true,
priv.loading_object.remove(); resizable:false,width:24});
priv.jio.removeDocument( }
name,{ grid = new Slick.Grid(
revision: revision || 'last', OfficeJS.system.applications['slickgrid'].list_elmnt,
success: function (result) { array,columns,options);
priv.loading_object.end_remove(); grid.setSelectionModel(new Slick.RowSelectionModel(
that.getList(); {selectActiveRow: false}));
}, grid.registerPlugin(check_box_selector);
error: function (error) { onSortFunction = function (e, args) {
priv.lastfailure.path = name; var cols = args.sortCols;
priv.lastfailure.method = 'removeDocument'; document_list.sort(function (data_row1, data_row2) {
console.error (error.message); var i, l, field, sign, value1, value2, result;
priv.loading_object.end_remove(); for (i = 0, l = cols.length; i < l; i++) {
that.getList(); field = cols[i].sortCol.field;
if (error.conflict_object) { sign = cols[i].sortAsc ? 1 : -1;
priv.onConflict (error.conflict_object); value1 = data_row1[field];
value2 = data_row2[field];
result = (value1==value2?0:
(value1>value2?1:-1))*sign;
if (result != 0) {
return result;
}
} }
return 0;
});
grid.invalidate();
grid.render();
};
onClickFunction = function (e) {
var cell = grid.getCellFromEvent(e);
if (cell.cell === grid.getColumnIndex('file_name')) {
OfficeJS.lib.openApplication(
array[cell.row].app,{_id:array[cell.row].id});
} else if (cell.cell ===
grid.getColumnIndex('on_conflict')) {
array[cell.row].showConflict?
array[cell.row].showConflict():true;
} }
}); };
}; onRemoveSeveral = function () {
var document_name_array = [], selected, i, l, cpt = 0;
/** selected = grid.getSelectedRows();
* Removes several files. for (i = 0, l = selected.length; i < l; i+= 1) {
* @method removeSeveralFromArray OfficeJS.lib.remove(
* @param {array} documentarray Contains all file names ({string}). {_id:document_list.rows[selected[i]].id},'last',
*/ function (err,val) {
that.removeSeveralFromArray = function (documentarray) { cpt ++;
var i, l, cpt = 0, current_editor = priv.data_object.currentEditor; if (l === cpt) {
if (!priv.isJioSet()) { OfficeJS_slickgrid.refresh();
console.error ('No Jio set yet.'); }
return; });
}
};
document.querySelector (
'#slickgrid_document_lister_remove_selected').
onclick = onRemoveSeveral;
document.querySelector (
'#slickgrid_document_lister_refresh').
onclick = OfficeJS_slickgrid.refresh;
grid.onClick.subscribe(onClickFunction);
grid.onSort.subscribe(onSortFunction);
} }
var onResponse = function (result) { },
cpt += 1; update: function () {
if (cpt === l) { OfficeJS.system.applications['slickgrid'].lib.reload();
if (typeof current_editor.update !== 'undefined') { }
if (priv.data_object.currentEditor !== null && };
current_editor.path === OfficeJS.system.preferences['documentlister'] =
priv.data_object.currentEditor.path) { OfficeJS.system.applications['slickgrid'];
that.getList(current_editor.update); // End slickgrid //
} else {
that.getList(); // work in progress //
OfficeJS.system.applications['workinprogress'] = {
type: 'activities',
name: 'workinprogress',
'class': 'viewer',
componentpath: 'component/workinprogress.html',
gadgetid: 'page-content',
main_elmnt: '#workinprogress_activities',
api: {},
lib:{
id: null,
start: function () {
if (OfficeJS.system.applications['workinprogress'].
lib.id === null) {
var update = function () {
var act = OfficeJS.run.jio.getJobArray(), i, str = '';
for (i = 0; i < act.length; i+= 1) {
str += act[i].command.label +' try number '+
act[i].command.tried + '<br />';
} }
} if (OfficeJS.tmp.lastfailure) {
str += '<span style="color:red;">Last failure: '+
OfficeJS.tmp.lastfailure.label +
', status: '+OfficeJS.tmp.lastfailure.status+
', reason: '+OfficeJS.tmp.lastfailure.reason+
'</span><br/>';
}
if (str === '') {
str = 'There is no on going tasks.<br />';
}
document.querySelector (
OfficeJS.system.applications['workinprogress'].
main_elmnt).innerHTML = str;
};
update();
OfficeJS.system.applications['workinprogress'].
lib.id = setInterval (update, 200);
} }
priv.loading_object.end_remove(); },
}; stop: function () {
for (i = 0, l = documentarray.length; i < l; i+= 1) { if (OfficeJS.system.applications['workinprogress'].
priv.loading_object.remove(); lib.id !== null) {
priv.jio.removeDocument( clearInterval(OfficeJS.system.applications[
documentarray[i],{ 'workinprogress'].lib.id);
revision: 'last', OfficeJS.system.applications['workinprogress'].
success: onResponse, lib.id = null;
error: onResponse }
}
},
onload: function () {
setTimeout(function(){
OfficeJS.system.applications['workinprogress'].lib.start();
},50);
},
onunload: function () {
OfficeJS.system.applications['workinprogress'].lib.stop();
return true;
}
};
OfficeJS.system.preferences['activities'] =
OfficeJS.system.applications['workinprogress'];
// End work in progress //
// basic conflict solver //
OfficeJS.system.applications['basic_conflict_solver'] = {
type: 'conflictsolver',
'class': 'editor',
name: 'basic_conflict_solver',
componentpath: 'component/basic_conflict_solver.html',
gadgetid: 'page-conflict',
varname: 'OfficeJS_basic_conflict_solver',
docid_elmnt: '#basic_conflict_solver_docid',
main_elmnt: '#basic_conflict_solver_div',
api: {
abort: function () {
OfficeJS.lib.openApplication(
OfficeJS.system.applications['close_conflict_solver']);
},
removeRevision: function () {
OfficeJS.system.applications['top_nav_bar'].lib.spin('remove');
OfficeJS.tmp.basic_conflict_solver_current_conflict.value.
_solveConflict(
{conflicts:true,revs:true,revs_info:true},
function (err,val) {
OfficeJS.system.applications['top_nav_bar'].lib.
endspin('remove');
if (err && err.conflicts.total_rows > 0) {
OfficeJS.lib.openApplication(
OfficeJS.lib.getAppFromPref(
'conflictsolver'));
}
OfficeJS.lib.allDocs ( function () {
if (OfficeJS.tmp['page-content'].type ===
'documentlister') {
OfficeJS.tmp['page-content'].update?
OfficeJS.tmp['page-content'].update():
true;
}
});
if (OfficeJS.tmp['page-content']['class'] ===
'editor') {
OfficeJS.tmp['page-content'].update?
OfficeJS.tmp['page-content'].update(''):
true;
}
});
OfficeJS.system.applications['basic_conflict_solver'].
api.abort();
},
keepRevision: function (revision) {
var content = $('#'+revision).text();
OfficeJS.system.applications['top_nav_bar'].lib.spin('save');
OfficeJS.tmp.basic_conflict_solver_current_conflict.value.
_solveConflict(
content,
{conflicts:true,revs:true,revs_info:true},
function (err,val) {
OfficeJS.system.applications['top_nav_bar'].lib.
endspin('save');
if (err && err.conflicts.total_rows > 0) {
OfficeJS.lib.openApplication(
OfficeJS.lib.getAppFromPref(
'conflictsolver'));
}
OfficeJS.lib.allDocs ( function () {
if (OfficeJS.tmp['page-content'].type ===
'documentlister') {
OfficeJS.tmp['page-content'].update?
OfficeJS.tmp['page-content'].update():
true;
}
});
if (OfficeJS.tmp['page-content']['class'] ===
'editor') {
OfficeJS.tmp['page-content'].update?
OfficeJS.tmp['page-content'].update(
content):
true;
}
});
OfficeJS.system.applications['basic_conflict_solver'].
api.abort();
}
},
lib:{
addRevision: function (doc) {
setTimeout( function () {
document.querySelector (OfficeJS.system.applications[
'basic_conflict_solver'].main_elmnt+' #revisions').
innerHTML += '<div class="row-fluid"><div class="span12">'+
'<div>'+(new Date(doc._last_modified)).toString()+'</div>'+
'<div><textarea id="'+doc._rev+'">'+doc.content+
'</textarea></div>'+
'<div><button onclick="'+
//'console.log('+"'"+revision+"'"+');'+
"OfficeJS_basic_conflict_solver.keepRevision('"+doc._rev+"');"+
'">Save this one</button></div><hr/>'+
'</div></div>';
},50);
},
addRemovedRevision: function (doc) {
setTimeout( function () {
document.querySelector (OfficeJS.system.applications[
'basic_conflict_solver'].main_elmnt+' #revisions').
innerHTML += '<div class="row-fluid"><div class="span12">'+
'<div>'+(new Date(doc._last_modified)).toString()+'</div>'+
'<div>Removed</div>'+
'<div><button onclick="'+
//'console.log('+"'"+revision+"'"+');'+
"OfficeJS_basic_conflict_solver.removeRevision();"+
'">Save this one</button></div><hr/>'+
'</div></div>';
},50);
}
},
onload: function (doc) {
// doc.row
OfficeJS.tmp.basic_conflict_solver_current_conflict = doc.row;
setTimeout(function(){
document.querySelector (
OfficeJS.system.applications[
'basic_conflict_solver'].docid_elmnt
).textContent = doc._id;
},50); // FIXME : wait for init end
console.log (OfficeJS.tmp.basic_conflict_solver_current_conflict);
var i;
for (i = 0; i < OfficeJS.tmp.basic_conflict_solver_current_conflict.
key.length; i+= 1) {
console.log ('a');
OfficeJS.system.applications['top_nav_bar'].lib.spin('load');
OfficeJS.lib.get(
doc._id,
OfficeJS.tmp.basic_conflict_solver_current_conflict.key[i],
function (err,val) {
OfficeJS.system.applications['top_nav_bar'].lib.
endspin('load');
if (val) {
OfficeJS.system.applications[
'basic_conflict_solver'].
lib.addRevision(val);
} else if (err && err.status === 404) {
OfficeJS.system.applications[
'basic_conflict_solver'].
lib.addRemovedRevision(err);
}
}); });
} }
}; }
};
OfficeJS.system.preferences['conflictsolver'] =
OfficeJS.system.applications['basic_conflict_solver'];
// End basic conflict solver //
/** OfficeJS.system.applications['close_conflict_solver'] = {
* Called when there is conflict componentpath: 'component/empty.html',
* @method onConflict gadgetid: 'page-conflict'
* @param {object} doc The document object };
* @param {object} conflict_object The conflict object //////////////////////////////////////////////////////////////////////
*/
priv.onConflict = function (conflict_object) {
// get the good conflict solver and load it
// if (ext && priv.conflict_solver_object[ext]) {
// that.open({app:priv.conflict_solver_object[ext],
// // local_content:document.content,
// conflict_object:conflict_object});
// } else {
that.open({app:'basic_conflict_solver',
// local_content:document.content,
conflict_object:conflict_object});
// }
};
/** odf(OfficeJS.lib,'basename',function (docid) {
* Solve the conflict var basename = docid.split('.').slice(0,-1).join('.');
* @method solveConflict if (basename === '') {
* @param {object} conflict_data The conflict object return docid;
* @param {string} data The new content of the new revision }
*/ return basename;
that.solveConflict = function (conflict_object, data) { });
that.closeGadgetId (priv.data_object.currentSolver.gadget_id); odf(OfficeJS.lib,'extOf',function (docid) {
priv.data_object.currentSolver = null; var ext = docid.split('.').splice(-1)[0];
priv.data_object.currentEditor.setContent(data); if (ext === docid) {
priv.loading_object.save(); return '';
conflict_object.solveConflict( }
data,{ return ext;
success: function (result) { });
if (result && result.revision) { odf(OfficeJS.lib,'put',function (doc,callback) {
priv.data_object.currentRevision = result.revision; if (OfficeJS.run.jio) {
} if (OfficeJS.tmp[doc._id + ' knownrevision']) {
priv.loading_object.end_save(); doc._rev = OfficeJS.tmp[doc._id + ' knownrevision'];
that.getList(); }
}, OfficeJS.system.applications['top_nav_bar'].lib.spin('save');
error: function (error) { OfficeJS.run.jio.put(
priv.lastfailure.path = basename; doc,{conflicts:true,revs:true,revs_info:true},
priv.lastfailure.method = 'saveDocument'; function (err,val) {
console.error (error.message); OfficeJS.system.applications['top_nav_bar'].lib.
priv.loading_object.end_save(); endspin('save');
that.getList(); OfficeJS.tmp[doc._id + ' knownrevision'] =
if (error.conflict_object) { (err||val||{rev:undefined}).rev;
priv.onConflict (error.conflict_object); if (err) {
OfficeJS.tmp.lastfailure =
OfficeJS.lib.cloneObjectRoot(err);
OfficeJS.tmp.lastfailure.label = 'put';
OfficeJS.tmp.lastfailure.docid = doc._id;
}
if ((err||val).conflicts &&
(err||val).conflicts.total_rows > 0) {
OfficeJS.lib.openApplication(
OfficeJS.lib.getAppFromPref(
'conflictsolver'),
{_id:doc._id,row:(err||val).conflicts.rows[0]}
);
}
callback?callback(err,val):true;
}
);
}
});
odf(OfficeJS.lib,'get',function (docid,rev,callback) {
if (OfficeJS.run.jio) {
var opts = {conflicts:true,revs:true,revs_info:true,max_retry:3};
if (rev) {
opts.rev = rev;
}
OfficeJS.system.applications['top_nav_bar'].lib.spin('load');
OfficeJS.run.jio.get(
docid,opts,
function (err,val) {
OfficeJS.system.applications['top_nav_bar'].lib.
endspin('load');
if (!rev) {
OfficeJS.tmp[docid + ' knownrevision'] =
(err||val||{_rev:undefined})._rev;
if ((err||val)._conflicts &&
(err||val)._conflicts.total_rows > 0) {
OfficeJS.lib.openApplication(
OfficeJS.lib.getAppFromPref(
'conflictsolver'),
{_id:docid,row:(err||val)._conflicts.rows[0]}
);
} }
} }
}); if (err) {
}; OfficeJS.tmp.lastfailure =
OfficeJS.lib.cloneObjectRoot(err);
that.abortSolveConflict = function () { OfficeJS.tmp.lastfailure.label = 'get';
that.closeGadgetId (priv.data_object.currentSolver.gadget_id); OfficeJS.tmp.lastfailure.docid = docid;
priv.data_object.currentSolver = null; }
}; callback?callback(err,val):true;
}
/** );
* Get current activity. }
* @method getActivity });
* @return {array} A list of current states for each current activities. odf(OfficeJS.lib,'allDocs',function (callback) {
*/ if (OfficeJS.run.jio) {
that.getActivity = function () { OfficeJS.system.applications['top_nav_bar'].lib.spin('getlist');
var activity = priv.jio.getJobArray (); OfficeJS.run.jio.allDocs(
var lastfailure = that.getLastFailure(); {conflicts:true,revs:true,revs_info:true,max_retry:3},
var res = [], i; function (err,val) {
for (i = 0; i < activity.length; i+= 1) { OfficeJS.system.applications['top_nav_bar'].lib.
switch (activity[i].command.label) { endspin('getlist');
case 'saveDocument': if (val) {
res.push(activity[i].storage.type+ OfficeJS.tmp.documentlist = val;
': Saving "' + activity[i].command.path + '".'); } else if (err) {
break; OfficeJS.tmp.lastfailure =
case 'loadDocument': OfficeJS.lib.cloneObjectRoot(err);
res.push(activity[i].storage.type+ OfficeJS.tmp.lastfailure.label = 'allDocs';
': Loading "' + activity[i].command.path + '".'); }
break; callback?callback(err,val):true;
case 'removeDocument':
res.push(activity[i].storage.type+
': Removing "' + activity[i].command.path + '".');
break;
case 'getDocumentList':
res.push(activity[i].storage.type+
': Get document list' +
' at "' + activity[i].command.path + '".');
break;
default:
res.push('Unknown action.');
break;
} }
);
}
});
odf(OfficeJS.lib,'remove',function (doc,rev,callback) {
if (OfficeJS.run.jio) {
var opts = {conflicts:true,revs:true,revs_info:true};
if (rev) {
opts.rev = rev;
} else if (OfficeJS.tmp[doc._id + ' knownrevision']) {
opts.rev = OfficeJS.tmp[doc._id + ' knownrevision'];
} }
if (lastfailure.method) { OfficeJS.system.applications['top_nav_bar'].lib.spin('remove');
switch (lastfailure.method) { OfficeJS.run.jio.remove(
case 'saveDocument': doc,opts,
res.push('<span style="color:red;">LastFailure: '+ function (err,val) {
'Fail to save "'+ lastfailure.path + '"</span>'); OfficeJS.system.applications['top_nav_bar'].lib.
break; endspin('remove');
case 'loadDocument': if (err) {
res.push('<span style="color:red;">LastFailure: '+ OfficeJS.tmp.lastfailure =
'Fail to load "'+ lastfailure.path + '"</span>'); OfficeJS.lib.cloneObjectRoot(err);
break; OfficeJS.tmp.lastfailure.label = 'remove';
case 'removeDocument': OfficeJS.tmp.lastfailure.docid = doc._id;
res.push('<span style="color:red;">LastFailure: '+ }
'Fail to remove "'+ lastfailure.path + '"</span>'); callback?callback(err,val):true;
break;
case 'getDocumentList':
res.push('<span style="color:red;">LastFailure: '+
'Fail to retreive list ' +
' at "' + lastfailure.path + '"</span>');
break;
default:
break;
} }
);
}
});
odf(OfficeJS.lib,'getAppFromPref',function (spec) {
return OfficeJS.system.preferences[spec];
});
odf(OfficeJS.lib,'getAppFromMime',function (ext) {
return OfficeJS.lib.getAppFromPref(OfficeJS.system.mime[ext]);
});
odf(OfficeJS.lib,'cloneObjectRoot',function (obj) {
var cloned_obj = {}, key;
for (key in obj) {
cloned_obj[key] = obj[key];
}
return cloned_obj;
});
odf(OfficeJS.lib,'cloneAndProtectObjectRoot',function (obj) {
var cloned_obj = {}, key;
for (key in obj) {
odf(cloned_obj,key,obj[key]);
}
return cloned_obj;
});
odf(OfficeJS.lib,'openApplication',function (app,obj) {
// unload
if (app.gadgetid && OfficeJS.tmp[app.gadgetid] &&
OfficeJS.tmp[app.gadgetid].onunload) {
if (!OfficeJS.tmp[app.gadgetid].onunload()) {
return false;
} }
return res; }
}; // set api
if (app.varname) {
scope[app.varname]=OfficeJS.lib.cloneAndProtectObjectRoot(app.api);
}
// open
TabbularGadget.addNewTabGadget(app.componentpath,app.gadgetid);
OfficeJS.tmp[app.gadgetid] = app;
// load
if (app.onload) {
app.onload(obj);
}
return true;
});
odf(OfficeJS.lib,'hideApplication',function (app) {
// TODO :
});
//////////////////////////////////////////////////////////////////////
odf(OfficeJS.command,'getEnv',function (env) {
return OfficeJS.env[env];
});
odf(OfficeJS.command,'setEnv',function (env,value) {
OfficeJS.env[env] = value;
});
odf(OfficeJS.command,'setPreference',function (id,value) {
// TODO :
});
/** //////////////////////////////////////////////////////////////////////
* Returns the last job failure.
* @method getLastFailure
* @return {object} The last failure.
*/
that.getLastFailure = function () {
return priv.lastfailure;
};
// End of class // odf(scope,'OfficeJS',OfficeJS.command);
priv.init();
return that;
}()); // end OfficeJS
// show gadgets OfficeJS.lib.openApplication(OfficeJS.system.applications['top_nav_bar']);
OfficeJS.open({app:'topnavbar'}); OfficeJS.lib.openApplication(OfficeJS.system.applications['left_nav_bar']);
OfficeJS.open({app:'leftnavbar'}); OfficeJS.lib.openApplication(OfficeJS.system.applications['login']);
OfficeJS.open({app:'login'}); }(window));
}());
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