bebeboutik/modules/invite/openinviter.tpl

162 lines
6.3 KiB
Smarty
Raw Normal View History

2016-01-04 12:49:26 +01:00
<div id="inviter">
<script type="text/javascript">{literal}
<!--
var data = null;
function getContacts() {
$('#oinotification').text("{/literal}{l s='Connecting, please wait...' mod='invite'}{literal}").show();
$('#oilogin').hide();
$('#oicontacts').html('');
$.post('{/literal}{$base_dir_ssl}{literal}modules/invite/ajax_inviter.php', $('#opinviter select, #opinviter input').serialize(), function(data) {
data = $.parseJSON(data);
if(data == null) {
$('#oinotification').html("{/literal}{l s='An error happened' mod='invite'}{literal}");
$('#oinotification').show();
} else if(data.errors != false) {
switch(data.errors) {
case "Login missing":
$('#oinotification').html("{/literal}{l s='Login missing' mod='invite'}{literal}");
break;
case "Password missing":
$('#oinotification').html("{/literal}{l s='Password missing' mod='invite'}{literal}");
break;
case "Login failed. Please check the email and password you have provided and try again later":
$('#oinotification').html("{/literal}{l s='Login failed. Please check the email and password you have provided and try again later' mod='invite'}{literal}");
break;
case "Unable to get contacts":
$('#oinotification').html("{/literal}{l s='Unable to get contacts' mod='invite'}{literal}");
break;
case "Please enter the full email, not just the username":
$('#oinotification').html("{/literal}{l s='Please enter the full email, not just the username' mod='invite'}{literal}");
break;
default:
$('#oinotification').html(data.errors);
break;
}
$('#oinotification').show();
$('#oilogin').show();
} else {
$('#oinotification').hide();
var contactshtml = '<table class="std">\
<thead>\
<tr>\
<th class="first_item">\
<input type="checkbox" value="" onclick="var boxes = $(\'#oicontacts table tbody tr td input\');if(this.checked) { for(var i=0; i < boxes.length; i++) { boxes[i].checked=true; } } else { for(var i=0; i < boxes.length; i++) { boxes[i].checked=false; } }" />\
</th>\
<th class="item">\
{/literal}{l s='Name' mod='invite'}{literal}\
</th>';
if(data.type == 'email') {
contactshtml += '<th class="item">\
{/literal}{l s='Email' mod='invite'}{literal}\
</th>';
}
contactshtml += '\
</tr>\
</thead>\
<tbody>';
if(data.type == "email") {
for(el in data.contacts) {
contactshtml += '<tr>\
<td><input type="checkbox" value="'+ $("<div />").text(el).html().replace('"', '\\"') +'" /></td>\
<td>' + $("<div />").text(data.contacts[el]).html() + '</td>\
<td>' + $("<div />").text(el).html() + '</td>\
</tr>';
}
} else {
for(el in data.contacts) {
contactshtml += '<tr>\
<td><input type="checkbox" value="'+ $("<div />").text(el).html().replace('"', '\\"') +'" /></td>\
<td>' + $("<div />").text(data.contacts[el]).html() + '</td>\
</tr>';
}
}
contactshtml += '</tbody>\
</table>\
<p class="actions">\
<input type="button" id="backToInviterButton" class="button" value="{/literal}{l s='Back to the login form' mod='invite'}{literal}" onclick="backToInviter();" />\
<input type="button" class="exclusive" id="addToListButton" value="{/literal}{l s='Add the selection to the list' mod='invite'}{literal}" onclick="addToList($(\'#oiservices input:checked\').val());" />\
</p>';
$("#oicontacts").html(contactshtml).show();
}
});
}
function backToInviter() {
$("#oicontacts").html("").hide();
$("#oinotification").html("").hide();
$("#oilogin").show();
}
function addToList(provider) {
var blankinputs = $("#invite_list input.email:text[value='']").toArray();
console.log(blankinputs);
var invite_list_length = $("#invite_list tbody tr").length;
$("#oicontacts input:checked").each(function(id, el) {
if(blankinputs.length > 0) {
var i = blankinputs.shift();
$(i).val($(el).val());
} else {
$("#invite_list tbody").append("\
<tr class=\"" + (invite_list_length % 2 == 0? "alternate_": "") + "item\">\
<td class=\"align_right\">" + (invite_list_length + 1) + "</td>\{/literal}
{if $askName}\
<td class="item"><input type=\"text\" value=\"" + $(el).val() + "\" size=\"20\" name=\"friendsFirstname[" + invite_list_length + "]\" class=\"text firstname\"></td>\
<td class="item"><input type=\"text\" value=\"" + $(el).val() + "\" size=\"20\" name=\"friendsLastname[" + invite_list_length + "]\" class=\"text lastname\"></td>\
{/if}\
{literal}<td><input type=\"text\" value=\"" + $(el).val() + "\" size=\"20\" name=\"friendsEmail[" + invite_list_length + "]\" class=\"text email\"></td>\
</tr>\
");
invite_list_length++;
}
$(el).attr("checked", false);
});
}
-->
{/literal}</script>
<form action="{$base_dir_ssl}modules/invite/ajax_inviter.php" method="POST" id="opinviter" onsubmit="getContacts(); return false;">
<h3 onclick="$('#oi_block').toggle(); $(this).toggleClass('active');">{l s='Select your contacts from your other accounts' mod='invite'}</h3>
<div id="oi_block">
<div id="oilogin">
<div id="oiform">
<p class="notification">{l s='We do not keep any credentials.' mod='invite'}</p>
<p>
<label for="oiservices">{l s='Provider' mod='invite'}</label>
<select id="oiservices" name="provider_box">
{foreach $oi_services as $type=>$providers}
{foreach $providers as $provider=>$details}
<option value="{$provider}"{if isset($smarty.post.provider_box) && $smarty.post.provider_box==$provider} selected="selected"{/if}>{$details.name}</option>
{/foreach}
{/foreach}
</select>
</p>
<p>
<label for="oilogin">{l s='Login' mod='invite'}</label>
<input id="oilogin" type="text" name="login" value="" />
</p>
<p>
<label for="oipassword">{l s='Password' mod='invite'}</label>
<input id="oipassword" type="password" name="password" value="" />
</p>
<div id="oicontrols" class="actions">
<input type="submit" name="import" value="{l s='Show contact list' mod='invite'}" class="button_large" />
<input type="hidden" name="step" value="get_contacts" />
</div>
</div>
</div>
<div id="oinotification" class="bold hidden"></div>
<div id="oicontacts" style="display: none;"></div>
</div>
</form>
</div>