Skip to content

Commit

Permalink
Sync theme settings if user is logged in - fix fossasia#89 (fossasia#101
Browse files Browse the repository at this point in the history
)
  • Loading branch information
tstreamDOTh authored Nov 3, 2017
1 parent 10f0445 commit 9027c13
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/scripts/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ function logout(){
browser.storage.sync.remove("messagesHistory");
browser.storage.sync.remove("userMapObj");
browser.storage.sync.remove("loggedUser");
accessToken = "";
showLoggedInBlock(false);
}
function applyUserSettings(){
Expand Down Expand Up @@ -259,12 +260,42 @@ function saveOptions(e) {
e.preventDefault();
var nameOfSettingsChanged = e.target.name;
if(nameOfSettingsChanged === "theme"){
// locally change the theme value
browser.storage.sync.set({
theme: document.querySelector("#theme").value
});

//check if user is logged in
if(accessToken!=""){

var selectedtheme = document.querySelector("#theme").value;

var url = BASE_URL+"/aaa/changeUserSettings.json?key1=theme&value1="+selectedtheme+"&access_token="+accessToken+"&count=1";

// fire the api call to change settings value on server
$.ajax({

url: url,
dataType: "jsonp",
jsonpCallback: "q",
jsonp: "callback",
crossDomain: true,
success: function (response) {

alert("Theme updated successfuly.");

}

});

}


}

}


function createMyMessageHistory(message,timeString,msgId){
var htmlMsg="<div class='message-container message-container-my' id='myMessage"+msgId+"'> \
<div class='message-box message-my'> \
Expand Down

0 comments on commit 9027c13

Please sign in to comment.