diff --git a/www/img/accounticons/business.svg b/www/img/accounticons/business.svg new file mode 100644 index 0000000..d5a8595 --- /dev/null +++ b/www/img/accounticons/business.svg @@ -0,0 +1,2 @@ + + diff --git a/www/img/accounticons/selfhosted.svg b/www/img/accounticons/selfhosted.svg new file mode 100644 index 0000000..f81c196 --- /dev/null +++ b/www/img/accounticons/selfhosted.svg @@ -0,0 +1,2 @@ + + diff --git a/www/js/accounts.js b/www/js/accounts.js index e27b72f..b2b7abe 100644 --- a/www/js/accounts.js +++ b/www/js/accounts.js @@ -35,6 +35,10 @@ function saveaccounts(accounts) { function recoveraccounts(callback) { NativeStorage.getItem("accounts", function (data) { + if (data == null || data == "" || data == "[]") { + callback(false); + return; + } localStorage.setItem("accounts", data); callback(true); }, function () { @@ -63,6 +67,9 @@ function switchaccount(account) { localStorage.setItem("syncurl", accountinfo['syncurl']); localStorage.setItem("key", accountinfo['key']); accountid = account; + + restartApplication(); + navigator.notification.alert("Successfully switched accounts.", null, "Switched", 'OK'); } /** @@ -136,4 +143,51 @@ function passwd(newpass) { var accounts = getaccounts(); accounts[accountid]["password"] = newpass; saveaccounts(accounts); +} + +function openAccountSwitcher(reload) { + if (typeof reload == 'undefined') { + reload = false; + } + var accounts = getaccounts(); + var noaccounts = (accounts.length == 0); + for (var i = 0; i < accounts.length; i++) { + accounts[i]["id"] = i; + // Escape HTML characters + accounts[i]["username"] = $('
').html(accounts[i]["username"]).html(); + var synckey = accounts[i]["key"]; + var stars = ""; + for (var j = 0; j < synckey.length - 6; j++) { + stars += "*"; + } + accounts[i]["synckey"] = $('
').html(synckey.slice(0, 3) + stars + synckey.slice(-3)).html(); + + accounts[i]["syncurl"] = $('
').html(accounts[i]["syncurl"].replace("/mobile/index.php", "")).html(); + accounts[i]["showsyncurl"] = false; + accounts[i]["showtypestring"] = true; + + if (accounts[i]["syncurl"].includes(".netsyms.biz")) { + accounts[i]["type"] = "Business"; + accounts[i]["icon"] = "business"; + } else if (accounts[i]["syncurl"].includes(".netsyms.com")) { + accounts[i]["type"] = "Personal"; + accounts[i]["icon"] = "personal"; + } else { + accounts[i]["type"] = "Self-hosted"; + accounts[i]["icon"] = "selfhosted"; + accounts[i]["showsyncurl"] = true; + accounts[i]["showtypestring"] = false; + } + + if (localStorage.getItem("username") == accounts[i]['username']) { + accounts[i]["active"] = true; + } + } + router.navigate("/settings/accounts", { + context: { + accounts: accounts, + noaccounts: noaccounts + }, + reloadCurrent: reload + }); } \ No newline at end of file diff --git a/www/js/home.js b/www/js/home.js index 08fc0c8..3a9b370 100644 --- a/www/js/home.js +++ b/www/js/home.js @@ -62,7 +62,8 @@ function loadHomePage(reload) { context: { appcards: appcards, notifications: notifications, - unreadnotifications: (notifications != false && notifications != []) + unreadnotifications: (notifications != false && notifications != []), + homeloaded: true }, reloadCurrent: true }); @@ -74,7 +75,8 @@ function loadHomePage(reload) { context: { appcards: appcards, notifications: notifications, - unreadnotifications: (notifications != false && notifications != []) + unreadnotifications: (notifications != false && notifications != []), + homeloaded: true } }); $(".view-main").on("click", "#applist .applist-item", function () { diff --git a/www/js/settings.js b/www/js/settings.js index 6d25ad5..248a557 100644 --- a/www/js/settings.js +++ b/www/js/settings.js @@ -93,7 +93,7 @@ function getSettingsTemplateData() { { setting: "accounts", title: "Manage and switch accounts", - onclick: "openAccountPicker()" + onclick: "openAccountSwitcher(false)" }, { setting: "updatepassword", diff --git a/www/js/setup2.js b/www/js/setup2.js new file mode 100644 index 0000000..02a5afe --- /dev/null +++ b/www/js/setup2.js @@ -0,0 +1,28 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + + +function savePassword() { + $.post(setupsyncurl, { + username: setupusername, + key: setupsynckey, + password: $('#passbox').val(), + action: "check_password" + }, function (data) { + if (data.status === 'OK') { + setuppassword = $('#passbox').val(); + var accid = addaccount(setupusername, setuppassword, setupsyncurl, setupsynckey); + switchaccount(accid); + localStorage.setItem("firstrun", "1"); + navigator.notification.alert("Account connected!", null, "Success", 'Continue'); + restartApplication(); + } else { + navigator.notification.alert(data.msg, null, "Error", 'Dismiss'); + } + }, "json").fail(function () { + navigator.notification.alert("Could not connect to the server. Try again later.", null, "Error", 'Dismiss'); + }); +} \ No newline at end of file diff --git a/www/pages/accounts.html b/www/pages/accounts.html new file mode 100644 index 0000000..a56e32a --- /dev/null +++ b/www/pages/accounts.html @@ -0,0 +1,81 @@ + +
+ + + +
+ + {{#unless noaccounts}} +
+
    + {{#each accounts}} +
  • +
    +
    +
    +
    +
    + {{username}} +
    + + {{#if active}} +
    + +
    + {{/if}} +
    + {{#if showtypestring}} +
    {{type}} account
    + {{/if}} + {{#if showsyncurl}} +
    {{syncurl}}
    + {{/if}} +
    +
    +
    + Delete +
    +
  • + {{/each}} +
+
+ {{else}} +
+
+ You haven't added any accounts yet. Press add to add one. +
+
+ {{/unless}} +
+ + + + + +
\ No newline at end of file diff --git a/www/pages/home.html b/www/pages/home.html index 0123d54..9b8114f 100644 --- a/www/pages/home.html +++ b/www/pages/home.html @@ -77,6 +77,13 @@
+ + + {{#unless homeloaded}} + + {{/unless}} \ No newline at end of file diff --git a/www/pages/setup2.html b/www/pages/setup2.html index 89728f8..4a5925e 100644 --- a/www/pages/setup2.html +++ b/www/pages/setup2.html @@ -35,27 +35,5 @@ - + \ No newline at end of file diff --git a/www/routes.js b/www/routes.js index b39cf0c..f2889a6 100644 --- a/www/routes.js +++ b/www/routes.js @@ -41,6 +41,11 @@ var routes = [ } } }, + { + path: '/settings/accounts', + templateUrl: './pages/accounts.html', + name: 'accounts' + }, { path: '/credits', url: './pages/credits.html',