From 4524237d374fed02b90a47bf0c87fe18c120e6de Mon Sep 17 00:00:00 2001 From: opi Date: Mon, 3 Mar 2014 20:20:48 +0100 Subject: [PATCH] Change main domain form. --- js/app.js | 40 +++++++++++++++++++++++++++++++++++++++- views/domain_list.ms | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/js/app.js b/js/app.js index 995caaff..9eadf620 100644 --- a/js/app.js +++ b/js/app.js @@ -454,7 +454,19 @@ app = Sammy('#main', function (sam) { sam.get('#/domains', function (c) { c.api('/domains', function(data) { // http://api.yunohost.org/#!/domain/domain_list_get_2 - c.view('domain_list', data); + c.api('/domain/main', function(data2) { + domains = []; + $.each(data.Domains, function(k, domain) { + domains.push({ + url: domain, + main: (domain == data2.current_main_domain) ? true : false + }); + }) + + // Sort domains with main domain first + domains.sort(function(a, b){ return -2*(a.main) + 1; }) + c.view('domain_list', {domains: domains}); + }, 'PUT') }); }); @@ -491,6 +503,32 @@ app = Sammy('#main', function (sam) { } }); + // Set default domain + sam.post('#/domains', function (c) { + if (c.params['domain'] == '') { + c.flash('fail', "You should select a domain default domain"); + store.clear('slide'); + c.redirect('#/domains'); + } else if (confirm('Are you sure you want to change the main domain ?')) { + + params = {'new_domain': c.params['domain']} + c.api('/domain/main', function(data) { // http://api.yunohost.org/#!/tools/tools_maindomain_put_1 + store.clear('slide'); + c.redirect('#/domains'); + }, 'PUT', params); + + // Wait 15s and refresh the page + refreshDomain = window.setTimeout(function(){ + store.clear('slide'); + c.redirect('#/domains') + }, 15000); + + } else { + store.clear('slide'); + c.redirect('#/domains'); + } + }); + /** * Apps diff --git a/views/domain_list.ms b/views/domain_list.ms index f7a1dc37..4acfeaf5 100644 --- a/views/domain_list.ms +++ b/views/domain_list.ms @@ -9,13 +9,44 @@
- {{#Domains}} + {{#domains}}
+ {{#if main}} + + Default + + {{else}} Delete -

{{.}}

- https://{{.}} + {{/if}} +

{{url}}

+ https://{{url}}
- {{/Domains}} + {{/domains}} +
+ +
+
+

+ Default domain +

+
+
+

+ The default domain is the connection domain where users log in. +

+
+
+ +
+
+ +
+
+ +