Commits

Anonymous committed 11c2609

Fix the bug for getting the correct users' input when updating token. Make options page prettier.

Comments (0)

Files changed (6)

+<!DOCTYPE HTML>
+<html lang="en">
+<head>
+<link rel='stylesheet' type='text/css' href='styles/chrome-bootstrap.css'/>
+<link rel='stylesheet' type='text/css' href='styles/app2.css'/>
+<link rel='stylesheet' type='text/css' href='styles/options.css'/>
+<!-- <link rel="stylesheet" href="scripts/frameworks/jquery-ui-1.10.3/themes/base/jquery-ui.css" /> -->
+<!-- <script src="frameworks/jquery-ui.js"></script> -->
+<meta charset="UTF-8">
+<title>Tag History</title>
+<link rel='stylesheet' type='text/css' href='styles/wj.css'>
+
+</head>
+<body class="chrome-bootstrap new_tags">
+<div class="app">
+    <div class="frame">
+        <div class="mainview view">
+            <div class="day_view with_controls selected" style="display: block;", id="main_body">
+
+            <h1>Update Evernote Token for Tag History</h1>
+            <h2>please sign in on the left window and paste contents here</h2>
+            <br>
+            <h3 class="option_item">Evernote token</h3>
+            <br>
+            <div><input class="option_input_text" type="text" id="evernote_token_input"></div>
+            <br>
+            <h3 class="option_item">Notestore URL:</h3>
+            <br>
+            <div><input class="option_input_text" type="text" id="evernote_notestore_input"></div>
+            <br>
+            <div><button type="button" id="evernote_token_input_button">Update</button></div>
+            </div>
+        </div>
+
+    </div>
+</div>
+
+<!-- <script type="text/javascript" src='scripts/pretty.js'></script> -->
+<!-- <script type="text/javascript" src='scripts/frameworks/zepto.js'></script> -->
+<!-- <script type="text/javascript" src="frameworks/require.js"></script>   -->
+<link rel="stylesheet" href="frameworks/jquery-ui.css" />
+
+<script src="frameworks/jquery-1.10.2.js"></script>
+<script type="text/javascript" src="frameworks/jquery-ui.js"></script>
+<script type="text/javascript" src="scripts/options.js"></script>
+</body>
+</html>

build/scripts/main.js

     /*jslint unparam: false*/
 
     TH_views.updateInterval(TH.Para.Interval.init);
-    TH.Services.Evernote.init();
+    // TH.Services.Evernote.init();
     $('#sync_to_evernote').on("click", TH.Services.Evernote.sync);
-    $('#update_evernote_token').on("click", TH.Services.Evernote.updateToken);
+    $('#update_evernote_token').on("click", TH.Services.Evernote.promptUpdateToken);
 };
 
 main(TH);

build/scripts/namespace.js

     Services: {
         Evernote: {
             evernoteHost: "https://sandbox.evernote.com",
-            authenticationToken: 'S=s1:U=87f14:E=1492b56b806:C=141d3a58c0a:P=1cd:A=en-devtoken:V=2:H=cfb7ab84ff2f5a7a6a527657d51fb3f8',
-            noteStoreURL: 'https://sandbox.evernote.com/shard/s1/notestore'
+            // evernoteToken: 'S=s1:U=87f14:E=1492b56b806:C=141d3a58c0a:P=1cd:A=en-devtoken:V=2:H=cfb7ab84ff2f5a7a6a527657d51fb3f8',
+            // noteStoreURL: 'https://sandbox.evernote.com/shard/s1/notestore'
         }
     },
     Templates: {},

build/scripts/options.js

+fetchInputToken = function () {
+    var evernoteToken = $("#evernote_token_input")[0].value;
+    console.log("evernoteToken: " + evernoteToken);
+    var notestoreUrl = $("#evernote_notestore_input")[0].value;
+    console.log("notestoreUrl: " + notestoreUrl);
+    var info = {
+        evernoteToken: evernoteToken,
+        notestoreUrl: notestoreUrl
+    };
+    // debugger;
+    chrome.storage.sync.set({'evernoteOAuth': info}, function () {
+        console.log('successfully stored token');
+        $("#main_body").html("<h1>Successfully updated token!</h1>");
+    });
+};
+$('#evernote_token_input_button').on("click", fetchInputToken);
+

build/scripts/services.js

 var Evernote = Services.Evernote;
 
 
-Evernote.init = function () {
-    console.log('test');
-    var noteStoreURL = Services.Evernote.noteStoreURL;
+Evernote.init = function (noteStoreURL) {
     var noteStoreTransport = new Thrift.BinaryHttpTransport(noteStoreURL);
     var noteStoreProtocol = new Thrift.BinaryProtocol(noteStoreTransport);
     Evernote.noteStore = new NoteStoreClient(noteStoreProtocol);
 };
 
 Evernote.getToken = function (callback) {
-    if (Evernote.authenticationToken !== undefined) {
-        callback(Evernote.authenticationToken);
+    if (Evernote.evernoteToken !== undefined) {
+        callback({'evernoteToken': Evernote.evernoteToken,
+                  'notestoreUrl': Evernote.notestoreUrl
+                 });
     }
-    chrome.storage.sync.get('evernoteToken', function (res) {
-        console.log("evernoteToken: " + res.evernoteToken);
-        if (typeof res.evernoteToken === 'string') {
-            Evernote.authenticationToken = res.evernoteToken;
-            callback(res.evernoteToken);
+    chrome.storage.sync.get('evernoteOAuth', function (res) {
+        var oAuth = res.evernoteOAuth;
+        var evernoteToken = oAuth.evernoteToken;
+        var notestoreUrl = oAuth.notestoreUrl;
+        if (typeof evernoteToken === 'string') {
+            Evernote.evernoteToken = evernoteToken;
+            Evernote.notestoreUrl = notestoreUrl;
+            callback(oAuth);
             return;
         }
         // Evernote.updateToken(callback);
-        alert("You must update Evernote token first");
+        alert("You must update Evernote oAuth information first");
     });
 };
 
 
 
-Evernote.updateToken = function (callback) {
+Evernote.promptUpdateToken = function (callback) {
     window.open(Evernote.evernoteHost + "/api/DeveloperToken.action",
                 "Evernote Token Setup page",
                 "left=0,width=700, height=600");
     window.open("options.html",
                 "Options page",
                 "left=700,width=700, height=600");
-    // var evernoteToken = window.prompt("Please enter Evernote token.\n" +
-    //                                   " You can get one from www.evernote.com/api/DeveloperToken.action",
-    // "");
-
-    // chrome.storage.sync.set({'evernoteToken': evernoteToken}, function () {
-    //     console.log('successfully stored token');
-    //     if (callback !== undefined) {
-    //         callback(evernoteToken);
-    //     }
-    // });
 }
 
 Evernote.sync = function () {
 
 
     TH.Models.fetchAllData(searchQuery, function (storedInfo) {
-        Evernote.getToken(function (authenticationToken) {
+        Evernote.getToken(function (oAuth) {
+            Evernote.init(oAuth.notestoreUrl);
             var note = new Note();
 
-            Evernote.noteStore.listNotebooks(authenticationToken,
+            Evernote.noteStore.listNotebooks(oAuth.evernoteToken,
                 function (notebooks) {
                     console.log(notebooks);
                 },
             note.content += Evernote.format(storedInfo);
             note.content += '</en-note>';
 
-            Evernote.noteStore.createNote(authenticationToken, note, function (res) {
+            // debugger;
+            Evernote.noteStore.createNote(oAuth.evernoteToken, note, function (res) {
                 if (res.guid !== undefined) {
                     console.log("Creating a new note in the default notebook");
                     console.log("Successfully created a new note with GUID: " +

build/styles/options.css

+.option_item {
+    padding-bottom:5px;
+    display: inline-block;
+    font-weight: bold;
+    margin: 0 32px 0 0;
+    width: 160px;
+    vertical-align: top;
+    zoom: 1;
+    line-height: 24px;
+}
+
+.option_input_text {
+    width: 420px;
+    max-width: 420px;
+    letter-spacing: normal;
+    word-spacing: normal;
+    text-transform: none;
+    text-indent: 0px;
+    text-shadow: none;
+    display: inline-block;
+    text-align: start;
+}