Update card number now works with new inside table din_card

This commit is contained in:
nikolark committed 2015-07-22 00:24:49 +02:00
1 parent 15aa28790b
commit 393d57f4fe
8 files changed
+154 -67

No files matched your search

+60 -27
View File
@@ -20,15 +20,45 @@ function getParameterByName(name) {
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
function update_with_card_details(results) {
/* Cards with a number lower than this is legacy as of 2015-08 */
var legacy_card_limit = 100000000;
for(var i=0; i<results.length; i++) {
var res = results[i];
if(res.cards === '') {
continue;
}
for(var j=0; j<res.cards.length; j++) {
if(parseInt(res.cards[j].card_number, 10) < legacy_card_limit) {
res.cards[j].is_legacy = "1";
}
if(res.cards[j].is_active == "1") {
res.card_number_active = res.cards[j].card_number;
}
}
}
return results;
}
function format_results(results) {
return nunjucks.render('search_results.html', {'results':results});
return nunjucks.render('search_results.html', {'results': update_with_card_details(results)});
}
function render_selected_user(user_data) {
user_data = update_with_card_details(user_data);
user_data.checked = true;
var selected_user_html = nunjucks.render('search_result.html', user_data);
_dom.selectedUserWrap.html(selected_user_html);
}
function set_toast(message) {
//var html = nunjucks.render('toast.html', {'message': message});
_dom.toastWrap.html(message);
_dom.toastWrap.addClass('visible');
setTimeout(function() {
_dom.toastWrap.removeClass('visible');
}, 4000);
}
function set_selected_user(user, update_search_result) {
selectedUser = user;
var new_val = '';
@@ -162,7 +192,8 @@ $(document).ready(function(){
registerButton: $('#register-submit-btn'),
usernameField: $('#id_username'),
userIdField: $('#id_user_id'),
selectedUserWrap: $('.register-card-form--selected-user-wrap')
selectedUserWrap: $('.register-card-form--selected-user-wrap'),
toastWrap: $('.toast-wrap')
};
var urls = {
insideUserApi: '/inside/user/',
@@ -171,31 +202,6 @@ $(document).ready(function(){
insideRegister: '/inside/register/'
};
/* User search as you type */
_dom.query.on('keyup', function() {
var val = _dom.query.val().trim();
if(val.length <= 2) {
return;
}
$.getJSON(urls.insideUserApi, {q: val}, function(data) {
console.log(data);
if(data.results && data.results.length > 0) {
_dom.results.html(format_results(data.results));
users = data.results;
}
else if(data.error) {
_dom.results.html(data.error);
}
else {
if(val !== "") {
_dom.results.html("Found no existing user with search param: '"+ val +"'");
} else {
_dom.results.html('');
}
}
});
});
/* Phone number as you type */
_dom.phoneNumberField.on('input', function() {
var val = _dom.phoneNumberField.val().trim();
@@ -253,6 +259,31 @@ $(document).ready(function(){
});
});
/* User search as you type */
_dom.query.on('keyup', function() {
var val = _dom.query.val().trim();
if(val.length <= 2) {
return;
}
$.getJSON(urls.insideUserApi, {q: val}, function(data) {
console.log(data);
if(data.results && data.results.length > 0) {
_dom.results.html(format_results(data.results));
users = data.results;
}
else if(data.error) {
_dom.results.html(data.error);
}
else {
if(val !== "") {
_dom.results.html("Found no existing user with search param: '"+ val +"'");
} else {
_dom.results.html('');
}
}
});
});
/* On search result click */
_dom.results.on('click', '.search-result input', function(e){
var label = $(this).parent();
@@ -299,9 +330,11 @@ $(document).ready(function(){
headers: {'X-CSRFToken': getCookie('csrftoken')}
}).success(function(data){
console.log("success", data);
set_toast('Success :-)');
}).fail(function(data) {
console.log("failed", data);
set_toast('Failed!');
});
});
+23 -3
View File
@@ -57,6 +57,10 @@ input[type=number] {
font-weight: normal;
line-height: 2;
&.can-register-card:hover {
cursor: pointer;
}
.label {
font-size: 1em;
}
@@ -80,9 +84,6 @@ input[type=number] {
visibility: visible;
}
}
&.has-card {
padding-left: 44px;
}
}
.selected-icon {
visibility: hidden;
@@ -104,6 +105,25 @@ input[type=number] {
.love {
color: #faafba;
}
/* Toasts */
.toast-wrap {
position: absolute;
bottom: 20px;
left: 20px;
background-color: rgba(0, 0, 0, .8);
color: white;
min-width: 100px;
padding: 18px 32px;
font-size: 18px;
visibility: hidden;
transform: translateY(20px);
transition: all 0.3s ease-in-out;
&.visible {
visibility: visible;
transform: translateY(0);
}
}
/* Header */
@import "header";
+4 -4
View File
@@ -1,5 +1,5 @@
{% if not placeholder %}
{% if not res.cardno or res.card_is_legacy %}
{% if not res.card_number_active %}
<label for="{{ res.id }}" data-phone-number="{{ res.number }}" data-user-id="{{ res.id }}" class="list-group-item search-result can-register-card{% if res.is_member == "1" %} member{% else %} not-member{% endif %}">
<input type="radio" name="user" id="{{ res.id }}"{% if checked %} checked{% endif %}>
{% else %}
@@ -19,7 +19,7 @@
{% endif %}
<!-- Card -->
{% if not res.card_is_legacy %}
<span class="label label-card "><span class="glyphicon glyphicon-user"></span> {{ res.cardno|default('No card') }}</span>
<span class="label label-card "><span class="glyphicon glyphicon-user"></span> {{ res.card_number_active|default('No card') }}</span>
{% else %}
<span class="label label-card "><span class="glyphicon glyphicon-user"></span> No card</span>
{% endif %}
@@ -28,7 +28,7 @@
<span class="label label-is-active">Active</span>
{% endif %}
</div>
{% if not res.cardno or res.card_is_legacy %}
{% if not res.card_number_active %}
<div class="selected-icon"><span class="glyphicon glyphicon-ok"></span></div>
</label>
{% else %}
@@ -40,7 +40,7 @@
<input type="radio" name="user" checked>
<em>New member</em>
<div class="labels">
<span class="label label-card "><span class="glyphicon glyphicon-user"></span> {{ res.cardno|default('New card') }}</span>
<span class="label label-card "><span class="glyphicon glyphicon-user"></span> {{ res.card_number_active|default('New card') }}</span>
</div>
</div>
{% endif %}
+60 -27
View File
@@ -20,15 +20,45 @@ function getParameterByName(name) {
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
function update_with_card_details(results) {
/* Cards with a number lower than this is legacy as of 2015-08 */
var legacy_card_limit = 100000000;
for(var i=0; i<results.length; i++) {
var res = results[i];
if(res.cards === '') {
continue;
}
for(var j=0; j<res.cards.length; j++) {
if(parseInt(res.cards[j].card_number, 10) < legacy_card_limit) {
res.cards[j].is_legacy = "1";
}
if(res.cards[j].is_active == "1") {
res.card_number_active = res.cards[j].card_number;
}
}
}
return results;
}
function format_results(results) {
return nunjucks.render('search_results.html', {'results':results});
return nunjucks.render('search_results.html', {'results': update_with_card_details(results)});
}
function render_selected_user(user_data) {
user_data = update_with_card_details(user_data);
user_data.checked = true;
var selected_user_html = nunjucks.render('search_result.html', user_data);
_dom.selectedUserWrap.html(selected_user_html);
}
function set_toast(message) {
//var html = nunjucks.render('toast.html', {'message': message});
_dom.toastWrap.html(message);
_dom.toastWrap.addClass('visible');
setTimeout(function() {
_dom.toastWrap.removeClass('visible');
}, 4000);
}
function set_selected_user(user, update_search_result) {
selectedUser = user;
var new_val = '';
@@ -162,7 +192,8 @@ $(document).ready(function(){
registerButton: $('#register-submit-btn'),
usernameField: $('#id_username'),
userIdField: $('#id_user_id'),
selectedUserWrap: $('.register-card-form--selected-user-wrap')
selectedUserWrap: $('.register-card-form--selected-user-wrap'),
toastWrap: $('.toast-wrap')
};
var urls = {
insideUserApi: '/inside/user/',
@@ -171,31 +202,6 @@ $(document).ready(function(){
insideRegister: '/inside/register/'
};
/* User search as you type */
_dom.query.on('keyup', function() {
var val = _dom.query.val().trim();
if(val.length <= 2) {
return;
}
$.getJSON(urls.insideUserApi, {q: val}, function(data) {
console.log(data);
if(data.results && data.results.length > 0) {
_dom.results.html(format_results(data.results));
users = data.results;
}
else if(data.error) {
_dom.results.html(data.error);
}
else {
if(val !== "") {
_dom.results.html("Found no existing user with search param: '"+ val +"'");
} else {
_dom.results.html('');
}
}
});
});
/* Phone number as you type */
_dom.phoneNumberField.on('input', function() {
var val = _dom.phoneNumberField.val().trim();
@@ -253,6 +259,31 @@ $(document).ready(function(){
});
});
/* User search as you type */
_dom.query.on('keyup', function() {
var val = _dom.query.val().trim();
if(val.length <= 2) {
return;
}
$.getJSON(urls.insideUserApi, {q: val}, function(data) {
console.log(data);
if(data.results && data.results.length > 0) {
_dom.results.html(format_results(data.results));
users = data.results;
}
else if(data.error) {
_dom.results.html(data.error);
}
else {
if(val !== "") {
_dom.results.html("Found no existing user with search param: '"+ val +"'");
} else {
_dom.results.html('');
}
}
});
});
/* On search result click */
_dom.results.on('click', '.search-result input', function(e){
var label = $(this).parent();
@@ -299,9 +330,11 @@ $(document).ready(function(){
headers: {'X-CSRFToken': getCookie('csrftoken')}
}).success(function(data){
console.log("success", data);
set_toast('Success! '+ data);
}).fail(function(data) {
console.log("failed", data);
set_toast('Failed! '+ data);
});
});
+4 -4
View File
@@ -5,7 +5,7 @@ var output = "";
try {
if(!runtime.contextOrFrameLookup(context, frame, "placeholder")) {
output += "\n ";
if(!runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "res")),"cardno", env.opts.autoescape) || runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "res")),"card_is_legacy", env.opts.autoescape)) {
if(!runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "res")),"card_number_active", env.opts.autoescape)) {
output += "\n <label for=\"";
output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "res")),"id", env.opts.autoescape), env.opts.autoescape);
output += "\" data-phone-number=\"";
@@ -71,7 +71,7 @@ output += "</span>\n ";
output += "\n <!-- Card -->\n ";
if(!runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "res")),"card_is_legacy", env.opts.autoescape)) {
output += "\n <span class=\"label label-card \"><span class=\"glyphicon glyphicon-user\"></span> ";
output += runtime.suppressValue(env.getFilter("default").call(context, runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "res")),"cardno", env.opts.autoescape),"No card"), env.opts.autoescape);
output += runtime.suppressValue(env.getFilter("default").call(context, runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "res")),"card_number_active", env.opts.autoescape),"No card"), env.opts.autoescape);
output += "</span>\n ";
;
}
@@ -85,7 +85,7 @@ output += "\n <span class=\"label label-is-active\">Active</span>\n
;
}
output += "\n </div>\n ";
if(!runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "res")),"cardno", env.opts.autoescape) || runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "res")),"card_is_legacy", env.opts.autoescape)) {
if(!runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "res")),"card_number_active", env.opts.autoescape)) {
output += "\n <div class=\"selected-icon\"><span class=\"glyphicon glyphicon-ok\"></span></div>\n </label>\n ";
;
}
@@ -98,7 +98,7 @@ output += "\n";
}
else {
output += "\n <!-- Placeholder -->\n <div class=\"list-group-item search-result placeholder\">\n <input type=\"radio\" name=\"user\" checked>\n <em>New member</em>\n <div class=\"labels\">\n <span class=\"label label-card \"><span class=\"glyphicon glyphicon-user\"></span> ";
output += runtime.suppressValue(env.getFilter("default").call(context, runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "res")),"cardno", env.opts.autoescape),"New card"), env.opts.autoescape);
output += runtime.suppressValue(env.getFilter("default").call(context, runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "res")),"card_number_active", env.opts.autoescape),"New card"), env.opts.autoescape);
output += "</span>\n </div>\n </div>\n";
;
}
+1 -1
View File
@@ -1 +1 @@
html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}b,strong{font-weight:700}dfn{font-style:italic}h1{margin:.67em 0}mark{background:#ff0;color:#000}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-.5em}sub{bottom:-.25em}img{border:0}svg:not(:root){overflow:hidden}hr{box-sizing:content-box;height:0}pre{overflow:auto}samp{font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid silver}textarea{overflow:auto}optgroup{font-weight:700}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}@media print{*,*:before,*:after{background:transparent!important;color:#000!important;box-shadow:none!important;text-shadow:none!important}a,a:visited{text-decoration:underline}a[href]:after{content:" (" attr(href)")"}abbr[title]:after{content:" (" attr(title)")"}a[href^="#"]:after,a[href^="javascript:"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100%!important}p,h2,h3{orphans:3;widows:3}h2,h3{page-break-after:avoid}.navbar{display:none}.btn>.caret,.dropup>.btn>.caret{border-top-color:#000!important}.label{border:1px solid #000}.table{border-collapse:collapse!important}.table td,.table th{background-color:#fff!important}.table-bordered th,.table-bordered td{border:1px solid #ddd!important}}@font-face{font-family:'Glyphicons Halflings';src:url("../fonts/glyphicons-halflings-regular.eot");src:url("../fonts/glyphicons-halflings-regular.eot?#iefix") format("embedded-opentype"),url("../fonts/glyphicons-halflings-regular.woff2") format("woff2"),url("../fonts/glyphicons-halflings-regular.woff") format("woff"),url("../fonts/glyphicons-halflings-regular.ttf") format("truetype"),url("../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular") format("svg")}.glyphicon{position:relative;top:1px;display:inline-block;font-family:'Glyphicons Halflings';font-style:normal;font-weight:400;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.glyphicon-asterisk:before{content:"\2a"}.glyphicon-plus:before{content:"\2b"}.glyphicon-euro:before,.glyphicon-eur:before{content:"\20ac"}.glyphicon-minus:before{content:"\2212"}.glyphicon-cloud:before{content:"\2601"}.glyphicon-envelope:before{content:"\2709"}.glyphicon-pencil:before{content:"\270f"}.glyphicon-glass:before{content:"\e001"}.glyphicon-music:before{content:"\e002"}.glyphicon-search:before{content:"\e003"}.glyphicon-heart:before{content:"\e005"}.glyphicon-star:before{content:"\e006"}.glyphicon-star-empty:before{content:"\e007"}.glyphicon-user:before{content:"\e008"}.glyphicon-film:before{content:"\e009"}.glyphicon-th-large:before{content:"\e010"}.glyphicon-th:before{content:"\e011"}.glyphicon-th-list:before{content:"\e012"}.glyphicon-ok:before{content:"\e013"}.glyphicon-remove:before{content:"\e014"}.glyphicon-zoom-in:before{content:"\e015"}.glyphicon-zoom-out:before{content:"\e016"}.glyphicon-off:before{content:"\e017"}.glyphicon-signal:before{content:"\e018"}.glyphicon-cog:before{content:"\e019"}.glyphicon-trash:before{content:"\e020"}.glyphicon-home:before{content:"\e021"}.glyphicon-file:before{content:"\e022"}.glyphicon-time:before{content:"\e023"}.glyphicon-road:before{content:"\e024"}.glyphicon-download-alt:before{content:"\e025"}.glyphicon-download:before{content:"\e026"}.glyphicon-upload:before{content:"\e027"}.glyphicon-inbox:before{content:"\e028"}.glyphicon-play-circle:before{content:"\e029"}.glyphicon-repeat:before{content:"\e030"}.glyphicon-refresh:before{content:"\e031"}.glyphicon-list-alt:before{content:"\e032"}.glyphicon-lock:before{content:"\e033"}.glyphicon-flag:before{content:"\e034"}.glyphicon-headphones:before{content:"\e035"}.glyphicon-volume-off:before{content:"\e036"}.glyphicon-volume-down:before{content:"\e037"}.glyphicon-volume-up:before{content:"\e038"}.glyphicon-qrcode:before{content:"\e039"}.glyphicon-barcode:before{content:"\e040"}.glyphicon-tag:before{content:"\e041"}.gLine truncated
html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}b,strong{font-weight:700}dfn{font-style:italic}h1{margin:.67em 0}mark{background:#ff0;color:#000}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-.5em}sub{bottom:-.25em}img{border:0}svg:not(:root){overflow:hidden}hr{box-sizing:content-box;height:0}pre{overflow:auto}samp{font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid silver}textarea{overflow:auto}optgroup{font-weight:700}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}@media print{*,*:before,*:after{background:transparent!important;color:#000!important;box-shadow:none!important;text-shadow:none!important}a,a:visited{text-decoration:underline}a[href]:after{content:" (" attr(href)")"}abbr[title]:after{content:" (" attr(title)")"}a[href^="#"]:after,a[href^="javascript:"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100%!important}p,h2,h3{orphans:3;widows:3}h2,h3{page-break-after:avoid}.navbar{display:none}.btn>.caret,.dropup>.btn>.caret{border-top-color:#000!important}.label{border:1px solid #000}.table{border-collapse:collapse!important}.table td,.table th{background-color:#fff!important}.table-bordered th,.table-bordered td{border:1px solid #ddd!important}}@font-face{font-family:'Glyphicons Halflings';src:url("../fonts/glyphicons-halflings-regular.eot");src:url("../fonts/glyphicons-halflings-regular.eot?#iefix") format("embedded-opentype"),url("../fonts/glyphicons-halflings-regular.woff2") format("woff2"),url("../fonts/glyphicons-halflings-regular.woff") format("woff"),url("../fonts/glyphicons-halflings-regular.ttf") format("truetype"),url("../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular") format("svg")}.glyphicon{position:relative;top:1px;display:inline-block;font-family:'Glyphicons Halflings';font-style:normal;font-weight:400;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.glyphicon-asterisk:before{content:"\2a"}.glyphicon-plus:before{content:"\2b"}.glyphicon-euro:before,.glyphicon-eur:before{content:"\20ac"}.glyphicon-minus:before{content:"\2212"}.glyphicon-cloud:before{content:"\2601"}.glyphicon-envelope:before{content:"\2709"}.glyphicon-pencil:before{content:"\270f"}.glyphicon-glass:before{content:"\e001"}.glyphicon-music:before{content:"\e002"}.glyphicon-search:before{content:"\e003"}.glyphicon-heart:before{content:"\e005"}.glyphicon-star:before{content:"\e006"}.glyphicon-star-empty:before{content:"\e007"}.glyphicon-user:before{content:"\e008"}.glyphicon-film:before{content:"\e009"}.glyphicon-th-large:before{content:"\e010"}.glyphicon-th:before{content:"\e011"}.glyphicon-th-list:before{content:"\e012"}.glyphicon-ok:before{content:"\e013"}.glyphicon-remove:before{content:"\e014"}.glyphicon-zoom-in:before{content:"\e015"}.glyphicon-zoom-out:before{content:"\e016"}.glyphicon-off:before{content:"\e017"}.glyphicon-signal:before{content:"\e018"}.glyphicon-cog:before{content:"\e019"}.glyphicon-trash:before{content:"\e020"}.glyphicon-home:before{content:"\e021"}.glyphicon-file:before{content:"\e022"}.glyphicon-time:before{content:"\e023"}.glyphicon-road:before{content:"\e024"}.glyphicon-download-alt:before{content:"\e025"}.glyphicon-download:before{content:"\e026"}.glyphicon-upload:before{content:"\e027"}.glyphicon-inbox:before{content:"\e028"}.glyphicon-play-circle:before{content:"\e029"}.glyphicon-repeat:before{content:"\e030"}.glyphicon-refresh:before{content:"\e031"}.glyphicon-list-alt:before{content:"\e032"}.glyphicon-lock:before{content:"\e033"}.glyphicon-flag:before{content:"\e034"}.glyphicon-headphones:before{content:"\e035"}.glyphicon-volume-off:before{content:"\e036"}.glyphicon-volume-down:before{content:"\e037"}.glyphicon-volume-up:before{content:"\e038"}.glyphicon-qrcode:before{content:"\e039"}.glyphicon-barcode:before{content:"\e040"}.glyphicon-tag:before{content:"\e041"}.gLine truncated