diff --git a/.gitignore b/.gitignore index 334ac12..3bb4dd2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /platforms /plugins npm-debug.log +nbproject/private/ diff --git a/www/img/accounticons/business.svg b/www/img/accounticons/business.svg new file mode 100644 index 0000000..6a80e3f --- /dev/null +++ b/www/img/accounticons/business.svg @@ -0,0 +1,2 @@ + + diff --git a/www/img/accounticons/nextcloud.svg b/www/img/accounticons/nextcloud.svg new file mode 100644 index 0000000..6040d3c --- /dev/null +++ b/www/img/accounticons/nextcloud.svg @@ -0,0 +1,2 @@ + + diff --git a/www/img/accounticons/personal.svg b/www/img/accounticons/personal.svg new file mode 100644 index 0000000..6666313 --- /dev/null +++ b/www/img/accounticons/personal.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..11c8b48 --- /dev/null +++ b/www/img/accounticons/selfhosted.svg @@ -0,0 +1,2 @@ + + diff --git a/www/js/main.js b/www/js/main.js index 22036e9..2079ec2 100644 --- a/www/js/main.js +++ b/www/js/main.js @@ -54,4 +54,9 @@ router.on("pageInit", function (pagedata) { // Run platform-specific setup code for Cordova or NW.js initPlatform(); -router.navigate("/home"); \ No newline at end of file +if (localStorage.getItem("configured") == null) { + // Open the setup page + router.navigate("/setup/0"); +} else { + router.navigate("/home"); +} \ No newline at end of file diff --git a/www/js/platform.js b/www/js/platform.js index 15909bd..23675db 100644 --- a/www/js/platform.js +++ b/www/js/platform.js @@ -20,7 +20,7 @@ function initCordova() { } function initNW() { - + // TODO: something clever with desktop integration } function initPlatform() { diff --git a/www/js/setup1.js b/www/js/setup1.js new file mode 100644 index 0000000..fbd7ea9 --- /dev/null +++ b/www/js/setup1.js @@ -0,0 +1,103 @@ +/* + * 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/. + */ + + +netsymscomurl = "https://apps.netsyms.com/notepost"; +netsymsbizurl = "https://BIZID.netsyms.biz/notepost"; + + +$('#use-security-checkbox-li').click(function () { + // Event fires before the checkbox is changed, so we need to do the opposite + if ($("#use-security").prop("checked")) { + $('#protocol-select').text("http://"); + } else { + $('#protocol-select').text("https://"); + } +}); + +/* Detect if the user typed "http[s]://" into the URL box and correct for it */ +$("#url").blur(function () { + if ($('#url').val().toLowerCase().startsWith("https://")) { + $('#url').val($('#url').val().replace(/https\:\/\//ig, "")); + $('#protocol-select').text("https://"); + $('#use-security').prop('checked', true); + } else if ($('#url').val().toLowerCase().startsWith("http://")) { + $('#url').val($('#url').val().replace(/http\:\/\//ig, "")); + $('#protocol-select').text("http://"); + $('#use-security').prop('checked', false); + } +}); + +$('#username').on("keyup", function () { + $('#username').val($('#username').val().toLowerCase()); +}); + +function checkAndSave(url, username, password, nextcloud) { + app.preloader.show(); + + if (typeof nextcloud === 'undefined') { + nextcloud = false; + } + + var checkurl = url + "/api/ping"; + + if (nextcloud) { + // TODO + } + + $.ajax({ + url: checkurl, + dataType: "json", + cache: false, + method: "POST", + beforeSend: function (xhr) { + xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password)); + }, success: function (data) { + app.preloader.hide(); + if (data.status == "OK") { + localStorage.setItem("username", username); + localStorage.setItem("password", password); + localStorage.setItem("serverurl", url); + localStorage.setItem("configured", true); + // Restart the app to re-read the config + restartApplication(); + } else if (data.status == "ERROR") { + app.dialog.alert(data.msg, "Error"); + } else { + app.dialog.alert("", "Error"); + } + }, error: function () { + app.preloader.hide(); + app.dialog.alert("Could not sign in. Check your credentials and connection.", "Error"); + } + }); +} + +function setupAccount() { + var type = $("#accttype").val(); + + var username = $("#username").val(); + var password = $("#password").val(); + + switch (type) { + case "personal": + checkAndSave(netsymscomurl, username, password); + break; + case "business": + var url = netsymsbizurl.replace("BIZID", $("#bizid").val()); + checkAndSave(url, username, password); + break; + case "selfhosted": + if (/^(https?:\/\/)/.test($('#url').val())) { + var url = $('#url').val(); + } else { + var url = $('#protocol-select').text() + $('#url').val(); + } + url = url.replace(/\/$/, ""); // Remove trailing slash + checkAndSave(url, username, password); + break; + } +} \ No newline at end of file diff --git a/www/pages/setup0.html b/www/pages/setup0.html new file mode 100644 index 0000000..65306e8 --- /dev/null +++ b/www/pages/setup0.html @@ -0,0 +1,125 @@ + + +
+ + + + +
+ +
+

Select an option to get started.

+
+ + + +
+ +
\ No newline at end of file diff --git a/www/pages/setup1.html b/www/pages/setup1.html new file mode 100644 index 0000000..c608fad --- /dev/null +++ b/www/pages/setup1.html @@ -0,0 +1,120 @@ + + +
+ + + + +
+ +
+
+
+ {{#if personal}} +

Type your netsyms.com username and password.

+ {{/if}} + {{#if business}} +

Type your netsyms.biz username, password, and business ID.

+ {{/if}} + {{#if selfhosted}} +

Type your username, password, and server URL.

+ {{/if}} + +
+
    +
  • +
    +
    Username
    +
    + + +
    +
    +
  • + +
  • +
    +
    Password
    +
    + + +
    +
    +
  • + + {{#if business}} +
  • +
    +
    Business ID (____.netsyms.biz)
    +
    + + +
    +
    +
  • + {{/if}} + + {{#if selfhosted}} +
  • +
    +
    Server Address: https://
    +
    + + +
    +
    +
  • + +
  • + +
  • + {{/if}} + +
+
+ + {{#if personal}} + + {{/if}} + {{#if business}} + + {{/if}} + {{#if selfhosted}} + + {{/if}} + {{#if nextcloud}} + + {{else}} + + {{/if}} +
+
+ Continue +
+
+
+ +
+ +
+ + + +
\ No newline at end of file diff --git a/www/routes.js b/www/routes.js index ae72772..f333fc9 100644 --- a/www/routes.js +++ b/www/routes.js @@ -28,6 +28,16 @@ var routes = [ }); } }, + { + path: '/setup/0', + url: './pages/setup0.html', + name: 'setup0' + }, + { + path: '/setup/1', + templateUrl: './pages/setup1.html', + name: 'setup1' + }, { path: '/credits', url: './pages/credits.html',