Commit 437e88f1 authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

Add method 'open' to OfficeJS that can open applications set in preferences.

parent 916cae47
...@@ -50,7 +50,7 @@ $().ready(function() { ...@@ -50,7 +50,7 @@ $().ready(function() {
<input type="text" <input type="text"
name="fileName" name="fileName"
id="input_fileName" id="input_fileName"
value="{{CurrentFileName}}" 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"
......
...@@ -6,8 +6,7 @@ ...@@ -6,8 +6,7 @@
<li> <li>
<a href="#/login" <a href="#/login"
onclick="javascript: onclick="javascript:
TabbularGadget.addNewTabGadget( OfficeJS.open({app:'login'});
'component/login.html','page-content');
return false;"> return false;">
<i class="icon-ok"> <i class="icon-ok">
</i> </i>
...@@ -18,16 +17,43 @@ ...@@ -18,16 +17,43 @@
<li class="texteditor"> <li class="texteditor">
<a href="#/texteditor" <a href="#/texteditor"
onclick="javascript: onclick="javascript:
TabbularGadget.addNewTabGadget( OfficeJS.open({app:'textEditor'});
OfficeJS.getPathOf(OfficeJS.getPreference('textEditor')),
'page-content');
return false;"> return false;">
<i class="icon-font"></i> <i class="icon-font"></i>
Text Editor Writer
</a>
</li>
<li class="imgeditor">
<a href="#/imgeditor"
onclick="javascript:
OfficeJS.open({app:'imgEditor'});
'page-content');
return false;">
<i class="icon-pencil"></i>
Image Editor
</a> </a>
</li> </li>
<li class="nav-header"><a href="#/doclist">Document List</a></li> <li class="spreadsheet">
<div id="document_list"></div> <a href="#/spreadsheet"
onclick="javascript:
OfficeJS.open({app:'speadsheet'});
return false;">
<i class="icon-signal"></i>
Spreadsheet
</a>
</li>
<li id="nav_document_list_header"
style="display:none">
<a href="#/doclist"
onclick="javascript:
OfficeJS.open({app:'documentLister'});
return false;">
<!-- <i class="icon-list"></i> -->
Document List
</a>
<div id="nav_document_list">
</div>
</li>
</ul> </ul>
</div> </div>
</div> </div>
......
...@@ -15,9 +15,18 @@ ...@@ -15,9 +15,18 @@
login:'login', login:'login',
topnavbar:'topnavbar', topnavbar:'topnavbar',
leftnavbar:'leftnavbar', leftnavbar:'leftnavbar',
documentLister:'slickgrid',
textEditor:'elrte' textEditor:'elrte'
}; };
priv.app_object = { priv.app_object = {
topnavbar: {
path:'component/top_nav_bar.html',
gadgetid:'page-top_nav_bar'
},
leftnavbar: {
path:'component/left_nav_bar.html',
gadgetid:'page-left_nav_bar'
},
login: { login: {
path:'component/login.html', path:'component/login.html',
gadgetid:'page-content', gadgetid:'page-content',
...@@ -32,17 +41,23 @@ ...@@ -32,17 +41,23 @@
}, },
elrte: { elrte: {
path:'component/elrte.html', path:'component/elrte.html',
gadgetid:'page-content',
element:'#elrte_editor', element:'#elrte_editor',
getContent: function () { getContent: function () {
$(this.element).elrte('updateSource'); $(this.element).elrte('updateSource');
return $(this.element).elrte('val'); return $(this.element).elrte('val');
}, },
onload: function () {}, },
onunload: function () {} slickgrid: {
path:'component/slickgrid_document_lister.html',
gadgetid:'page-content',
onload: function () {}
} }
}; };
priv.data_object = { priv.data_object = {
documentList:[] documentList:[],
gadget_object:{}, // contains current gadgets id with their location
currentFile:null
}; };
priv.loading_object = { priv.loading_object = {
spinstate: 0, spinstate: 0,
...@@ -84,31 +99,108 @@ ...@@ -84,31 +99,108 @@
// Methods // // Methods //
/** /**
* @method getPreference * Shows a list of document inside the left nav bar
* @param {string} key The preference * @method showDocumentListInsideLeftNavBar
* @return {object} a clone of the preference object
*/ */
that.getPreference = function (key) { priv.showDocumentListInsideLeftNavBar = function () {
return priv.preference_object[key]; var i, html_string = '<ul>';
for (i = 0; i < priv.data_object.length; i += 1) {
html_string += '<li>' +
'<a href="#/texteditor:' +
priv.data_object[i].fileName + '">' +
priv.data_object[i].fileName +
'</a>' +
'</li>';
}
html_string += '</ul>';
if (html_string === '<ul></ul>') {
// if there's no document
html_string = '<ul><li>No document</li></ul>';
}
// show list in the left nav bar
$('#nav_document_list').html(html_string);
$('#nav_document_list_header').show();
};
/**
* @method getRealApplication
* @param {string} appname The app name set in preference.
* @return {object} The real application object.
*/
priv.getRealApplication = function (appname) {
var realappname = that.getPreference (appname);
if (!realappname) { return; } // undefined
return priv.app_object[realappname];
}; };
/** /**
* @method jioIsSet * @method isJioSet
* @return {boolean} true if jio is set else false. * @return {boolean} true if jio is set else false.
*/ */
priv.jioIsSet = function () { priv.isJioSet = function () {
return (typeof priv.jio === 'object'); return (typeof priv.jio === 'object');
}; };
/**
* Opens an application
* @method open
* @param {object} option Contains some settings:
* - app {string} The app name we want to open, set in preferences
* - ... and some other parameters
*/
that.open = function (option) {
var realapp, realgadgetid, realpath, acientapp;
realapp = priv.getRealApplication (option.app);
realgadgetid = realapp.gadgetid;
realpath = realapp.path;
if (!realapp) {
// cannot get real app
console.error ('Unknown application: ' +
that.getPreference(option.app));
return null;
}
ancientapp = priv.data_object.gadget_object[realgadgetid];
if (ancientapp) {
// if there is already a gadget there, unload it
if (typeof ancientapp.onunload !== 'undefined' &&
!ancientapp.onunload()) {
// if onunload return false, it means that we must not
// load a new gadget because this one is not ready to
// exit.
return null;
}
}
priv.data_object.gadget_object[realgadgetid] = realapp;
TabbularGadget.addNewTabGadget(realpath,realgadgetid);
if (typeof realapp.onload !== 'undefined') {
return realapp.onload(option);
}
};
/**
* @method getPreference
* @param {string} key The preference
* @return {string} The content of the preference.
*/
that.getPreference = function (key) {
return priv.preference_object[key];
};
/** /**
* @method getContentOf * @method getContentOf
* @param {string} app The application name * @param {string} app The application name
* @return {string} The content of the application, or null. * @return {string} The content of the application, or null.
*/ */
that.getContentOf = function (app) { that.getContentOf = function (app) {
if (priv.app_object[app] && var realapp = that.getPreference (app);
typeof priv.app_object[app].getContent !== 'undefined') { if (!realapp) {
return priv.app_object[app].getContent(); console.error ('Unknown application: ' +
that.getPreference(app));
return null;
}
if (priv.app_object[realapp] &&
typeof priv.app_object[realapp].getContent !== 'undefined') {
return priv.app_object[realapp].getContent();
} }
return null; return null;
}; };
...@@ -119,8 +211,14 @@ ...@@ -119,8 +211,14 @@
* @return {string} The path of the application component, or null. * @return {string} The path of the application component, or null.
*/ */
that.getPathOf = function (app) { that.getPathOf = function (app) {
if (priv.app_object[app]) { var realapp = that.getPreference(app);
return priv.app_object[app].path; if (!realapp) {
console.error ('Unknown application: ' +
that.getPreference(app));
return null;
}
if (priv.app_object[realapp]) {
return priv.app_object[realapp].path;
} }
return null; return null;
}; };
...@@ -131,7 +229,7 @@ ...@@ -131,7 +229,7 @@
* @param {object} applicant The applicant informations * @param {object} applicant The applicant informations
*/ */
that.setJio = function (storage,applicant) { that.setJio = function (storage,applicant) {
if (priv.jioIsSet()) { if (priv.isJioSet()) {
alert ('Jio already set.'); alert ('Jio already set.');
return; return;
} }
...@@ -145,7 +243,7 @@ ...@@ -145,7 +243,7 @@
* @method getList * @method getList
*/ */
that.getList = function () { that.getList = function () {
if (!priv.jioIsSet()) { if (!priv.isJioSet()) {
console.error ('No Jio set yet.'); console.error ('No Jio set yet.');
return; return;
} }
...@@ -155,11 +253,11 @@ ...@@ -155,11 +253,11 @@
'callback':function (result) { 'callback':function (result) {
if (result.status === 'done') { if (result.status === 'done') {
priv.data_object = result.return_value; priv.data_object = result.return_value;
priv.showDocumentListInsideLeftNavBar();
} else { } else {
console.error (result.message); console.error (result.message);
} }
priv.loading_object.end_getlist(); priv.loading_object.end_getlist();
// TODO : show list somewhere
} }
}); });
}; };
...@@ -171,7 +269,7 @@ ...@@ -171,7 +269,7 @@
* @param {string} content The content of the document. * @param {string} content The content of the document.
*/ */
that.save = function (name, content) { that.save = function (name, content) {
if (!priv.jioIsSet()) { if (!priv.isJioSet()) {
console.error ('No Jio set yet.'); console.error ('No Jio set yet.');
return; return;
} }
...@@ -195,7 +293,7 @@ ...@@ -195,7 +293,7 @@
* @param {string} name The document name. * @param {string} name The document name.
*/ */
that.load = function (name) { that.load = function (name) {
if (!priv.jioIsSet()) { if (!priv.isJioSet()) {
console.error ('No Jio set yet.'); console.error ('No Jio set yet.');
return; return;
} }
...@@ -219,7 +317,7 @@ ...@@ -219,7 +317,7 @@
* @param {string} name The document name. * @param {string} name The document name.
*/ */
that.remove = function (name) { that.remove = function (name) {
if (!priv.jioIsSet()) { if (!priv.isJioSet()) {
console.error ('No Jio set yet.'); console.error ('No Jio set yet.');
return; return;
} }
...@@ -242,16 +340,7 @@ ...@@ -242,16 +340,7 @@
}()); // end OfficeJS }()); // end OfficeJS
// show gadgets // show gadgets
TabbularGadget.addNewTabGadget( OfficeJS.open({app:'topnavbar'});
'component/top_nav_bar.html', OfficeJS.open({app:'leftnavbar'});
'page-top_nav_bar', OfficeJS.open({app:'login'});
undefined);
TabbularGadget.addNewTabGadget(
'component/left_nav_bar.html',
'page-left_nav_bar',
undefined);
TabbularGadget.addNewTabGadget(
'component/login.html',
'page-content',
undefined);
}()); }());
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