- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
//HELPER FUNCTIONS:
function getSortedLanguageBoxes(lvls, lang){
var thislang = lang || 'esp';
var tmp = [];
for(var i=0, l=lvls.length||0; i<l ;i++){
tmp = tmp.concat( RSI({cat:thislang,media:"box",lvl:lvls[i]}) );
}
return tmp;
}
var getBoxesByLang = getSortedLanguageBoxes.bind(this, ['L1','S3','S5']);
function getLabelMarkup(d){
return '<label class="i"><span style="width: 7em;"><input type="radio" name="lvl" value="' +
d.cart +
'"><span >' +
d.desc +
'</span></span><span style="color: transparent;"><sup style="visibility: hidden;">$</sup><span class="roundprice">' +
'' /*spacer*/ +
'</span>/mo.</span><span style="vertical-align: top"><sup>$</sup><s><span style="color: black">' +
d.msrp +
'</span></s><sup>$</sup>' +
d.price +
'<span class="under">You save <sup>$</sup>' +
d.save +
'</span></span></label>';
}
var all_langs = [];
for(var allprods = RSI(), langdict = {}, i = 0, l = allprods.length; i<l; i++){
!langdict[allprods[i].cat] && all_langs.push(allprods[i].cat);
langdict[allprods[i].cat] = true;
}
var lvldescriptions = {
'L1': 'Level 1',
'S3': 'Levels 1-3',
'S5': 'Levels 1-5'
}
var boxlabels = {};
for(var i = 0, l = all_langs.length; i<l; i++){
var thislang = all_langs[i];
var boxes = getBoxesByLang(thislang);
boxlabels[thislang] = [];
for(var j = 0, m = boxes.length; j<m; j++){
var thisbox = boxes[j];
var mk = getLabelMarkup({cart:thisbox.cart,desc:lvldescriptions[thisbox.lvl],msrp:thisbox.msrp,price:thisbox.price,save:(parseInt(thisbox.msrp, 10)-parseInt(thisbox.price, 10))});
boxlabels[thislang].push($(mk));
}
}
var defaultlang = ["esp","Spanish"];
$(function(){
/***********************
EMAIL/MAIL SELECT
***********************/
var tosublabels = $('.selectlevel .i').clone();
var detachedoptions = null;
//BUSINESS LOGIC OPERATIONS:
// Prior to page complete, we should precompile inputs and li elements for each as much as possible
$('.selectproduct').on('change', function(e){
var $frm = $(this);
var products_selected = $frm.find('input:checked').val();
var $lvl = $('.selectlevel');
var $hd = $lvl.find('.hd');
var $suboptions = $('.giftselect .desktopleft > *:nth-child(-n+6)');
if(products_selected === 'box'){
// When "box" is selected add the lang picker
$lvl.prepend('<div class="langpicker" data-currentlang="' + defaultlang[0] + '"><span>' + defaultlang[1] + '▼</span></div>');
// When "box" is selected, change .selectlevel class to "box"
$lvl.removeClass('tosub');
$lvl.addClass('box');
// When "box" selected, change headers
// $hd.find('span:eq(0)').text('');
// $hd.find('span:nth-child(n+2)').css('color','transparent');
$hd.hide();
// When "box" selected, hide email gift form stuff
if(!detachedoptions){
detachedoptions = $suboptions.detach();
}
}
else {
// When ~"box", remove the picker
$lvl.find('.langpicker').remove();
// When ~"box", we have to clear the disable
// When "box" is selected, change .selectlevel class to "box"
$lvl.removeClass('box');
$lvl.addClass('tosub');
// When ~"box" selected, change headers
// $hd.find('span:eq(0)').text('Online Subscription');
// $hd.find('span:nth-child(n+1)').css('color','black');
$hd.show();
// When ~"box" selected, show email gift form stuff
if(!!detachedoptions){
$('.giftselect .desktopleft').prepend(detachedoptions);
detachedoptions = null;
}
}
// When either is selected, we should replace the product entries with the new ones
var labelstoadd = (products_selected === 'box' ? $.map(boxlabels[defaultlang[0]], function(v){ return v.clone();}) : tosublabels);
//debugger;
$('.selectlevel').find('.i').remove();
$('.selectlevel .hd').after(labelstoadd);
// When either is selected, we should "check" the highest option
// We should "trigger" the select so listeners on the bottom form do the right thing
$('.selectlevel .i').last().trigger('click');
});
/***********************
LANGUAGE SELECT
***********************/
$(document).on('click','.langpicker', function(v){
$('.langpickoverlay').show();
});
$(document).on('click','.langpickoverlay .langs li', function(e){
//Change the defaultlang
var $li = $(this);
defaultlang = [$li.data('lang'), $li.text()];
//Change the level labels (if box is on)
var labelstoadd = $.map(boxlabels[defaultlang[0]], function(v){ return v.clone();});
$('.selectlevel').find('.i').remove();
$('.selectlevel .hd').after(labelstoadd);
//Trigger a click on the highest label
$('.selectlevel .i').last().trigger('click');
//Change the langpicker display
$('.langpicker').text(defaultlang[1]);
$('.langpicker').attr('data-currentlang',defaultlang[0]);
//Hide the langpickoverlay
$('.langpickoverlay').hide();
});
/***********************
FORM SUBMIT
***********************/
function handleFormSubmit(e){
e.preventDefault();
//egift_filled=1&theme_id=themeupdated_29&sender_name=karthi&receiver_name=keyan&receiver_email=karthitestgift@gmail.com&personalized_message=aw%20sad%20asd%20asd%20asd%20as&send_at=12%2F08%2F2016
var params = [
['egift_filled','1']
];
var selectedpic = $('.selectpic input:checked').data('themeid') || 'themeupdated_29';
!!selectedpic && params.push(['theme_id', selectedpic]);
var msg = $('.lblmessage textarea').val() || '';
!!msg && params.push(['personalized_message', msg])
var giftdate = $('.giftdate').val();
!!giftdate && params.push(['send_at', giftdate]);
if( $('.selectlevel').hasClass('box') ){
}
else {
params.push(['sender_name', $('.desktopleft label:eq(0) input').val()]);
params.push(['receiver_name', $('.desktopleft label:eq(1) input').val()]);
params.push(['receiver_email', $('.desktopleft label:eq(2) input').val()]);
}
//debugger;
var toappend = $.map(params, function(v){ return encodeURIComponent(v[0]) + '=' + encodeURIComponent(v[1]) }).join('&');
var loc = $('.selectlevel input:checked').val();
loc += ((loc.match(/\?/) ? '&' : '') + toappend);
//console.log(loc);
if('_satellite' in window && !!_satellite.getQueryParam('stg')){
loc = loc.replace(/https:\/\/secure.rosetta/ig, 'http://secure.stg.rosetta')
}
debugger;
window.location = loc;
return false;
}
window._handleFormSubmit = handleFormSubmit;
$('form.giftselect').on('submit', handleFormSubmit)
});