Files
bbs/static/dist/js/app.js
T
2014-10-11 17:03:58 +02:00

1 line
6.4 KiB
JavaScript

function enable_all_customers(){$("li.customer").each(function(){$(this).removeClass("marked"),$(this).show()})}function filter_customers(t){setTimeout(function(){$("li.customer").each(function(){var e=new RegExp(t,"i"),r=$(this).children("span.name").text();if(e.test(r)){$(this).show();var a=r.toLowerCase()==t.toLowerCase(),i=1==$("li.customer:visible").length;console.log(a,i),a?$(this).addClass("marked"):$(this).removeClass("marked")}else $(this).hide(),$(this).removeClass("marked")})},50)}function enable_all_products(){$("li.product").each(function(){$(this).removeClass("marked"),$(this).show()})}function reset_qtys(){$(".qty").each(function(){$(this).html("0")}),$("input[name$=amount]").each(function(){$(this).val("0")})}function update_total(){var t=0;$("li.product").each(function(){var e=Number($(this).find("[name$=amount]").val()),r=".sale_price_int";"Ekstern"===$("#id_customer_typeahead").val()&&(r=".sale_price_ext");var a=Number($(this).find(r).text());t+=e*a}),0===t&&(t=""),$("span.total_text").html(t)}$(document).ready(function(){function t(t){var e=n;for(var r in t.products)if(null===e.get(r)){e.addSeries({data:[],id:r,name:r});var a=e.get(r);_.each(t.products[r],function(t){a.addPoint({id:t[0],x:t[0],y:t[1]})})}else{var a=e.get(r);_.each(t.products[r],function(t){null===e.get(t[0])&&a.addPoint({id:t[0],x:t[0],y:t[1]})})}}function e(){$.ajax({url:s,dataType:"json",success:function(r){t(r),setTimeout(function(){e()},15e3)},cache:!1})}if($("a[data-dismiss=alert]").click(function(){$(this).parent().parent().parent().slideUp()}),setTimeout(function(){$("a[data-dismiss=alert]").parent().parent().parent().slideUp()},5e3),$("h2").tooltip({placement:"right"}),$("img.customer").tooltip(),$("a.product").tooltip(),$("#footer .credits .love").tooltip(),$("#id_customer_typeahead").keyup(function(t){filter_customers(t.target.value)}),$("li.customer").click(function(){enable_all_customers(),$(this).addClass("marked");var t=$(this).children("span.name").text();$("#id_customer_typeahead").val(t);var e=$(this).children("span.id").text();$("#id_customer option, #id_user option").removeAttr("selected"),""===e?$("#id_customer option:first-child, #id_user option:first-child").attr("selected","selected"):$("#id_customer option[value="+e+"], #id_user option[value="+e+"]").attr("selected","selected"),update_total(this)}),Highcharts.setOptions({credits:{enabled:!1}}),$("#register li.product").click(function(){$(this).addClass("marked");var t=$(this).children("input[name$=amount]"),e=$(this).children(".qty"),r=Number(t.val())+1;t.val(r),e.html(r),update_total(this)}),$("#register button[type=reset]").click(function(){$("#id_customer option").removeAttr("selected"),$("#id_customer_typeahead").val(""),$("span.total_text").html(""),enable_all_customers(),enable_all_products(),reset_qtys()}),$(".toggle-infrequent-users").on("click",function(t){t.preventDefault(),$("li.customer.infrequent").toggleClass("hidden"),$(".users-description .infrequent-users").toggleClass("hidden"),$(this).text("Vis alle"===$(this).text()?"Skjul gamliser":"Vis alle")}),$("#stats").length>0){var r=[],a="/stats/products/",i="/stats/orders/",o="/stats/orders/hourly",s="/stats/orders/products_realtime";$.getJSON(i,function(t){var e="order_chart",a={chart:{renderTo:e,plotBackgroundColor:null,plotBorderWidth:null,plotShadow:!1},title:{text:"Fordeling av ordre på person"},tooltip:{formatter:function(){return"<b>"+this.point.name+"</b>: "+Highcharts.numberFormat(this.percentage,1)+" %"}},plotOptions:{pie:{allowPointSelect:!0,cursor:"pointer",dataLabels:{enabled:!0,color:"#000000",connectorColor:"#000000",formatter:function(){return"<b>"+this.point.name+"</b>: "+this.y}}}},series:[{type:"pie",name:"Orders",data:t}]};r.push(new Highcharts.Chart(a))}),$.getJSON(a,function(t){var e=t.response.products;for(var a in e){var i="product_chart"+e[a].product.id,o=e[a].counts,s={chart:{renderTo:i,plotBackgroundColor:null,plotBorderWidth:null,plotShadow:!1},title:{text:e[a].product.name},tooltip:{formatter:function(){return"<b>"+this.point.name+"</b>: "+Highcharts.numberFormat(this.percentage,1)+" %"}},plotOptions:{pie:{allowPointSelect:!0,cursor:"pointer",dataLabels:{enabled:!0,color:"#000000",connectorColor:"#000000",formatter:function(){return"<b>"+this.point.name+"</b>: "+this.y}}}},series:[{type:"pie",name:"Orders",data:o}]};r.push(new Highcharts.Chart(s))}}),$.getJSON(o,function(t){var e="order_hourly_chart",a={chart:{renderTo:e,type:"column"},title:{text:"Ordre - time for time"},tooltip:{formatter:function(){return this.y+" stk"}},yAxis:{title:{text:"Ordre"}},xAxis:{title:{text:"Tid (h)"},labels:{formatter:function(){return this.value+":00"}}},plotOptions:{column:{minPointLength:3},series:{groupPadding:0,pointPadding:.05}},series:[{name:"Ordre",data:t.hourly}]};r.push(new Highcharts.Chart(a))});var n=new Highcharts.Chart({chart:{renderTo:"products_realtime_chart"},title:{text:"Produkter solgt over tid"},xAxis:{type:"datetime"},yAxis:{title:{text:"Antall solgt"}},plotOptions:{series:{marker:{radius:3}}},series:{}});r.push(n),e()}var l="#id_facebook_username";$(l).on("keyup",_.debounce(function(t){var e=t.target.value;if(0===e.trim().length)return $(l).parent().removeClass("has-success has-feedback has-error"),void $(l).parent().find(".facebook-image img").attr("src",i);var r="https://graph.facebook.com/"+e+"/picture",a=$("meta[name=x-django-static-url]").attr("content"),i=a+"img/unknown_person.png";$.ajax({url:r,statusCode:{200:function(){$(l).parent().addClass("has-success has-feedback"),$(l).parent().removeClass("has-error"),$(l).parent().find(".facebook-image img").attr("src",r)},404:function(){$(l).parent().addClass("has-error has-feedback"),$(l).parent().removeClass("has-success"),$(l).parent().find(".facebook-image img").attr("src",i)}}})},300));var c=$(".inventory-report-form #id_start_time");c.datepicker({language:"nb",format:"yyyy-mm-dd",todayHighlight:!0,weekStart:1,endDate:new Date}).on("changeDate",function(t){d.datepicker("setStartDate",t.date)});var d=$(".inventory-report-form #id_end_time");if(d.datepicker({language:"nb",format:"yyyy-mm-dd",todayHighlight:!0,weekStart:1,endDate:new Date}).on("changeDate",function(t){c.datepicker("setEndDate",t.date)}),$("#user-profile").length){var u="/stats/products/by_user/",h=$("#user-profile").attr("data-user-id");$.getJSON(u+h,function(t){t.hasOwnProperty("error")||$(".profile-stats-orderline").highcharts({title:{text:!1},xAxis:{type:"datetime"},yAxis:{title:{text:"Kjøp"}},plotOptions:{series:{marker:{radius:3}}},series:t})})}});