From 9c8b4c18d3dc3677e5c88fa125d761f3827200ea Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Sat, 18 Jan 2014 22:41:59 +0100 Subject: [PATCH] Add subscribe feature --- inc/myco.js | 57 ++++++++++++++++++++++++++++++++++++++++++++- inc/myco_objects.js | 31 ++++++++++++++++++++++++ index.html | 45 +++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 1 deletion(-) diff --git a/inc/myco.js b/inc/myco.js index 5cc9b93..b4cb6bb 100644 --- a/inc/myco.js +++ b/inc/myco.js @@ -470,7 +470,51 @@ on_valid_login_modal=function(e) { ); } +on_click_go_to_subscribe_btn=function() { + $('#login_modal').modal('hide'); + $('#subscribe_modal').modal('show'); +} +/******************** + * Subscribe + ********************/ +on_close_subscribe_modal=function(e) { + $('#subscribe_modal form')[0].reset(); +} + +sync_server=false; +on_valid_subscribe_modal=function(e) { + e.preventDefault(); + email=$('#subscribe_modal #subscribe_email')[0].value; + name=$('#subscribe_modal #subscribe_name')[0].value; + pass=$('#subscribe_modal #subscribe_pass')[0].value; + server=$('#subscribe_modal #subscribe_server')[0].value; + $('#subscribe_modal').modal('hide'); + pleaseWaitShow(); + sync_server.subscribe(server,email,name,pass, + function(data) { + localStorage.user=JSON.stringify({ + 'name': data.name, + 'email': data.email, + 'password': data.password, + 'server': server, + }); + pleaseWaitHide(); + logged_menu(); + alert('Bienvenu '+data.name+' !'); + }, + function(data) { + pleaseWaitHide(); + if (jQuery.type(data) == 'object' && jQuery.type(data.subscribeerror)!='undefined') { + alert(data.subscribeerror); + } + else { + console.log(data); + alert('Erreur durant la connexion au serveur'); + } + } + ); +} /******************** * Sync @@ -531,8 +575,10 @@ logged_out_menu=function() { $('#user-name').html('Connexion'); $('#user-menu li').remove(); menu=$('#user-menu'); - menu.html("
  • Connexion
  • "); + menu.html("
  • Connexion
  • "+ + "
  • Inscription
  • "); $('#login_btn').bind('click',on_click_login_btn); + $('#subscribe_btn').bind('click',on_click_subscribe_btn); } on_click_myaccount_btn=function() { @@ -546,6 +592,10 @@ on_click_login_btn=function() { $('#login_modal').modal('show'); } +on_click_subscribe_btn=function() { + $('#subscribe_modal').modal('show'); +} + on_click_logoff_btn=function() { delete localStorage.user; logged_out_menu(); @@ -598,8 +648,13 @@ $( document ).ready( function() { $('#login_modal').on('hidden.bs.modal',on_close_login_modal); $('#login_modal #login_submit').bind('click',on_valid_login_modal); + $('#login_modal #go_to_subscribe_btn').bind('click',on_click_go_to_subscribe_btn); $('#login_modal form').bind('submit',on_valid_login_modal); + $('#subscribe_modal').on('hidden.bs.modal',on_close_subscribe_modal); + $('#subscribe_modal #subscribe_submit').bind('click',on_valid_subscribe_modal); + $('#subscribe_modal form').bind('submit',on_valid_subscribe_modal); + $('#view-group #contributor').bind('change',on_contributor_change); $('#add_contributor_btn').bind('click',on_click_add_contributor_btn); diff --git a/inc/myco_objects.js b/inc/myco_objects.js index 5cdd5bd..e00a998 100644 --- a/inc/myco_objects.js +++ b/inc/myco_objects.js @@ -372,6 +372,37 @@ function SyncServer() { } } + this.subscribe=function(url,email,name,password,onsuccess,onerror) { + this.url=url; + this.email=email; + this.name=name; + this.password=password; + + try { + jQuery.getJSON( + this.url+'/subscribe', + {'email':email,'name': name,'password':password}, + function(data, textStatus) { + console.log(data); + if (textStatus=='success') { + if(jQuery.type(data.email) != 'undefined' && jQuery.type(data.name) != 'undefined') { + onsuccess(data); + return true; + } + } + onerror(data); + return false; + } + ).fail(onerror); + } + catch(e) { + if(jQuery.type(onerror)=='function') { + onerror(); + } + } + } + + this.sync=function(url,email,password,groups,onsuccess,onerror) { this.url=url; this.email=email; diff --git a/index.html b/index.html index 3cc5e1c..b0fc0d2 100644 --- a/index.html +++ b/index.html @@ -253,11 +253,56 @@ body{ + + +