Add subscribe feature
This commit is contained in:
parent
e21a1bfed0
commit
9c8b4c18d3
3 changed files with 132 additions and 1 deletions
57
inc/myco.js
57
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("<li><a id='login_btn'>Connexion</a></li>");
|
||||
menu.html("<li><a id='login_btn'>Connexion</a></li>"+
|
||||
"<li><a id='subscribe_btn'>Inscription</a></li>");
|
||||
$('#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);
|
||||
|
|
|
@ -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;
|
||||
|
|
45
index.html
45
index.html
|
@ -253,11 +253,56 @@ body{
|
|||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Annuler</button>
|
||||
<button type="button" class="btn btn-primary" id='login_submit'>Connexion</button>
|
||||
<button type="button" class="btn btn-primary" id='go_to_subscribe_btn'>Inscription</button>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="subscribe_modal" tabindex="-1" role="dialog" aria-labelledby="subscribeModal" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title">Inscription</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-horizontal" role="form">
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">Email *</span>
|
||||
<input type='text' id='subscribe_email' class="form-control" placeholder='Email'/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">Nom *</span>
|
||||
<input type='text' id='subscribe_name' class="form-control" placeholder='Nom'/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">Mot de passe *</span>
|
||||
<input type='password' id='subscribe_pass' class="form-control" placeholder='Mot de passe'/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">Serveur *</span>
|
||||
<input type='text' id='subscribe_server' class="form-control" value='http://mycoserver.zionetrix.net'/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Annuler</button>
|
||||
<button type="button" class="btn btn-primary" id='subscribe_submit'>Valider</button>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div>
|
||||
|
||||
|
||||
<div class="modal fade" id="add_contribution_modal" tabindex="-1" role="dialog" aria-labelledby="addContributorModal" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
|
|
Loading…
Reference in a new issue