From 9ed1f4012cb32559294aacc636cec09d78fcfc69 Mon Sep 17 00:00:00 2001
From: cat <carinasadres@gmail.com>
Date: Thu, 21 Aug 2014 14:11:20 +0200
Subject: [PATCH] LSP createacc landing page with option to enable protocols

---
 lsp/main.js  |  4 +++-
 lsp/pages.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/lsp/main.js b/lsp/main.js
index 4979a3ab..d46fdc54 100755
--- a/lsp/main.js
+++ b/lsp/main.js
@@ -1706,7 +1706,9 @@ $(window).on('hashchange', function(e) {
     ignoreHashChange = false;
     return; 
   }
-  var loc = location.hash.split('&')[1].split('@');
+  var loc = location.hash.split('&')[1];
+  if (!loc) {return;}
+  loc = loc.split('@');
   if (loc[1]) {
     showTab(loc[0],loc[1]);
   }
diff --git a/lsp/pages.js b/lsp/pages.js
index a8f14c66..1dbe9d1f 100755
--- a/lsp/pages.js
+++ b/lsp/pages.js
@@ -139,7 +139,7 @@ function showTab(tabName,streamName) {
             location.hash = settings.credentials.username+'@'+settings.server;
             $('#user_and_host').text(settings.credentials.username+' @ '+settings.server);
             
-            saveAndReload('overview');
+            saveAndReload('acccreated');
           })
         ).append(
           $('<button>').text('Cancel').addClass('escape-to-cancel').click(function(){
@@ -148,6 +148,54 @@ function showTab(tabName,streamName) {
         )
       );
     break;
+    case 'acccreated':
+      $('#menu').css('visibility', 'hidden');
+      $('#page').html(
+        'Your account was succesfully created. You can log in with these credentials in the future.'
+      ).append(
+        $('<div>').addClass('input_container').append(
+          $('<p>').text('Enable all protocols')
+        ).append(
+          $('<div>').addClass('description').text(
+            'Would you like to enable all (currently) available protocols with default settings?'
+          )
+        ).append(
+          $('<button>').text('Skip').css('float','left').addClass('escape-to-cancel').click(function(){
+            showTab('overview');
+          })
+        ).append(
+          $('<button>').text('Enable protocols').css('float','left').addClass('enter-to-submit').click(function(){
+            if (settings.settings.config.protocols) {
+              $('#page').append('Unable to enable all protocols as protocol settings already exist.<br>');
+              return;
+            }
+            
+            $('#page').append('Retrieving available protocols..<br>');
+            getData(function(data){
+              settings.settings.capabilities = data.capabilities;
+              settings.settings.config.protocols = [];
+              
+              for (var i in settings.settings.capabilities.connectors) {
+                var connector = settings.settings.capabilities.connectors[i];
+                
+                if (connector.required) {
+                  $('#page').append('Could not enable protocol "'+i+'" because it has required settings.<br>');
+                  continue;
+                }
+                
+                settings.settings.config.protocols.push(
+                  {connector: i}
+                );
+                $('#page').append('Enabled protocol "'+i+'".<br>');
+              }
+              
+              saveAndReload('protocols');
+            },{capabilities:true});
+          })
+        )
+      );
+      
+    break;
     case 'overview':
       $('#page').html(
         $('<div>').addClass('description').html('An overview of MistServer statistics. General settings can be modified here.')