Commit d5b5c39e authored by François Billioud's avatar François Billioud

Implement button to change language

parent 00469f12
/* /*
* global variables * global variables
*/ */
var languages = ["fr","en"]; languages = ["fr","en"];
var availableLanguages = window.document.getElementById("available_languages"); var availableLanguages = window.document.getElementById("available_languages");
currentPage = null; currentPage = null;
...@@ -86,10 +86,12 @@ Page.prototype = { ...@@ -86,10 +86,12 @@ Page.prototype = {
/* display the list of availaible languages */ /* display the list of availaible languages */
displayLanguages: function(user) { displayLanguages: function(user) {
var avLang = ""; var avLang = "";
for (var l in languages) {
for (var i = 0; i<languages.length; i++) {
var l = languages[i];
if(l==user.getLanguage()) {this.getHTML().getElementById("current_language").innerHTML = l;} if(l==user.getLanguage()) {this.getHTML().getElementById("current_language").innerHTML = l;}
else { else {
avLang = avLang + "<li><span onclick='getCurrentUser.setLanguage(this.innerHTML)' id="+l+">"+l+"</span></li>\n" avLang = avLang + "<li><span onclick='changeLanguage(this.innerHTML)' id='" +l+ "'>"+l+"</span></li>\n"
} }
} }
this.getHTML().getElementById("available_languages").innerHTML = avLang; this.getHTML().getElementById("available_languages").innerHTML = avLang;
...@@ -136,17 +138,13 @@ User.prototype = { ...@@ -136,17 +138,13 @@ User.prototype = {
getName: function() {return this.name;}, getName: function() {return this.name;},
setName: function(newName) {this.name = newName;}, setName: function(newName) {this.name = newName;},
getLanguage: function() {return this.language;}, getLanguage: function() {return this.language;},
setLanguage:function(language) { setLanguage:function(language) {this.language = language;},
this.language = language;
getCurrentPage().displayLanguages();
},
getStorageLocation: function() {return this.storage;}, getStorageLocation: function() {return this.storage;},
setStorageLocation: function(storage) {this.storage = storage;}, setStorageLocation: function(storage) {this.storage = storage;},
getIdentityProvider: function() {return this.identityProvider;}, getIdentityProvider: function() {return this.identityProvider;},
setIdentityProvider: function(IDProv) {this.identityProvider = IDProv;}, setIdentityProvider: function(IDProv) {this.identityProvider = IDProv;},
setAsCurrentUser: function() { setAsCurrentUser: function() {
getCurrentPage().displayUserName(this); getCurrentPage().displayUserName(this);
getCurrentPage().displayLanguages(this); getCurrentPage().displayLanguages(this);
setCurrentUser(this); setCurrentUser(this);
...@@ -169,6 +167,9 @@ setCurrentUser = function(user) {localStorage.setItem("currentUser", JSON.string ...@@ -169,6 +167,9 @@ setCurrentUser = function(user) {localStorage.setItem("currentUser", JSON.string
/* JSON document */ /* JSON document */
var JSONDocument = function() { var JSONDocument = function() {
this.type = "text"; this.type = "text";
this.language = getCurrentUser().getLanguage();
this.version = null;
this.author=getCurrentUser().getName(); this.author=getCurrentUser().getName();
this.title="Untitled"; this.title="Untitled";
this.content=""; this.content="";
...@@ -182,6 +183,14 @@ JSONDocument.prototype = { ...@@ -182,6 +183,14 @@ JSONDocument.prototype = {
//type //type
getType: function() {return this.type;}, getType: function() {return this.type;},
//version
getVersion: function() {return this.version;},
setVersion: function(version) {this.version = version;},
//language
getLanguage: function() {return this.language;},
setLanguage: function(language) {this.language = language;},
//content //content
getContent:function() {return this.content;}, getContent:function() {return this.content;},
setContent:function(content) {this.content=content;}, setContent:function(content) {this.content=content;},
...@@ -223,13 +232,40 @@ setCurrentDocument = function(doc) {localStorage.setItem("currentDocument",JSON. ...@@ -223,13 +232,40 @@ setCurrentDocument = function(doc) {localStorage.setItem("currentDocument",JSON.
/* /*
* tools * actions
*/ */
currentTime = function() {return (new Date()).toUTCString();} editDocumentSettings = function() {
$("#edit_document").dialog({
autoOpen: false,
height: 131,
width: 389,
modal: true,
buttons: {
"Save": function(){
/*getCurrentDocument().setTitle($(getCurrentDocument()).find("#name").attr("value"));
//var new_short_title = $("input#short_title.short_title").attr("value");
getCurrentDocument().setLanguage($(getCurrentDocument()).find("#language").attr("value"));
getCurrentDocument().setVersion($(getCurrentDocument()).find("#version").attr("value"));
//var new_int_index = $("input#sort_index.sort_index").attr("value");
//var new_subject_list = $("textarea#keyword_list").attr("value").replace(/\n+/g, ",");
getCurrentDocument().setAsCurrentDocument();//diplay modifications
//save_button.click();*/
$(this).dialog("close");
},
Cancel: function() {
$(this).dialog("close");
}
}
});
}
changeLanguage = function(language) {
var user = getCurrentUser();
user.setLanguage(language);
setCurrentUser(user);
getCurrentPage().displayLanguages(user);
}
cancel_sharing = function() {alert("cancel");} cancel_sharing = function() {alert("cancel");}
translate = function() {alert("translate");} translate = function() {alert("translate");}
submit = function() {alert("submit");} submit = function() {alert("submit");}
share = function() {alert("share");} share = function() {alert("share");}
//test = new User();
\ No newline at end of file
...@@ -33,7 +33,8 @@ ...@@ -33,7 +33,8 @@
// initialize // initialize
init = function() { init = function() {
setCurrentPage("editor"); setCurrentPage("editor");
new User(); alert(getCurrentUser());
if(getCurrentUser()==null) {new User();}
doc = new JSONTextDocument();//load the document (it's just for testing) doc = new JSONTextDocument();//load the document (it's just for testing)
doc.setAsCurrentDocument(); doc.setAsCurrentDocument();
} }
...@@ -141,7 +142,7 @@ ...@@ -141,7 +142,7 @@
</a> </a>
<a id="loading_message" lang="en">Loading...</a> <a id="loading_message" lang="en">Loading...</a>
<a id="document_title" name="document_title" onclick="javascript:rename()">Untitled</a> <a id="document_title" name="document_title" onclick="javascript:editDocumentSettings()">Untitled</a>
<a id="document_state" name="document_state">...</a> <a id="document_state" name="document_state">...</a>
<div id="edit_document" title="Rename Document"> <div id="edit_document" title="Rename Document">
......
This diff is collapsed.
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