From 62fd657a4168bbf7de80f4d17161110d612144f8 Mon Sep 17 00:00:00 2001 From: Kiran Jonnalagadda Date: Tue, 3 May 2016 17:06:03 +0530 Subject: [PATCH 1/2] Use single thumb for pay range slider, for #334. Breaks job posting form. --- hasjob/static/js/app.js | 50 +++++++++++++++++------------------ hasjob/templates/index.html | 3 +-- hasjob/templates/layout.html | 3 +-- hasjob/templates/macros.html | 3 +-- hasjob/templates/postjob.html | 3 +-- hasjob/views/index.py | 19 ++++++++----- 6 files changed, 41 insertions(+), 40 deletions(-) diff --git a/hasjob/static/js/app.js b/hasjob/static/js/app.js index 3ceb7f251..aa682b513 100644 --- a/hasjob/static/js/app.js +++ b/hasjob/static/js/app.js @@ -213,8 +213,7 @@ window.Hasjob.Filters = { selectedCategories: window.Hasjob.Config.selectedCategories, selectedQuery: window.Hasjob.Config.selectedQuery, selectedCurrency: window.Hasjob.Config.selectedCurrency, - pmin: window.Hasjob.Config.pmin, - pmax: window.Hasjob.Config.pmax, + pay: window.Hasjob.Config.pay, equity: window.Hasjob.Config.equity, sidebarOn: false }, @@ -421,12 +420,15 @@ window.Hasjob.Filters = { } currencyVal = formParams[fpIndex].value; } - // format pmin and pmax based on currency value - if (formParams[fpIndex].name === 'pmin' || formParams[fpIndex].name === 'pmax') { + // format pay based on currency value + if (formParams[fpIndex].name === 'pay') { if (currencyVal === '') { formParams[fpIndex].value = ''; } else { formParams[fpIndex].value = Hasjob.PaySlider.toNumeric(formParams[fpIndex].value); + if (formParams[fpIndex].value === '0') { + formParams[fpIndex].value = ''; + } } } // remove empty values @@ -447,8 +449,7 @@ window.Hasjob.Filters = { selectedCategories: window.Hasjob.Config.selectedCategories, selectedQuery: window.Hasjob.Config.selectedQuery, selectedCurrency: window.Hasjob.Config.selectedCurrency, - pmin: window.Hasjob.Config.pmin, - pmax: window.Hasjob.Config.pmax, + pay: window.Hasjob.Config.pay, equity: window.Hasjob.Config.equity }).then(function() { $('#job-filters-location').multiselect('rebuild'); @@ -461,10 +462,8 @@ window.Hasjob.Filters = { window.Hasjob.PaySlider = function(options){ this.selector = options.selector; this.slider = null; - this.start = options.start; - this.end = options.end; - this.minField = options.minField; - this.maxField = options.maxField; + this.pay = options.pay; + this.payField = options.payField; this.init(); }; @@ -568,9 +567,8 @@ window.Hasjob.PaySlider.range = function(currency){ window.Hasjob.PaySlider.prototype.init = function(){ this.slider = $(this.selector).noUiSlider({ - start: [this.start, this.end], - connect: true, - behaviour: "tap", + start: this.pay, + behaviour: 'tap', range: { 'min': [0, 50000], '10%': [1000000, 100000], @@ -582,23 +580,20 @@ window.Hasjob.PaySlider.prototype.init = function(){ prefix: '¤' }) }); - this.slider.Link('lower').to($(this.minField)); - this.slider.Link('upper').to($(this.maxField)); + this.slider.Link('lower').to($(this.payField)); return this; }; window.Hasjob.PaySlider.prototype.resetSlider = function(currency) { - var start = Hasjob.PaySlider.toNumeric(this.slider.val()[0]), - end = Hasjob.PaySlider.toNumeric(this.slider.val()[1]); + var pay = Hasjob.PaySlider.toNumeric(this.slider.val()); this.slider.noUiSlider({ - start: [start, end], + start: pay, range: Hasjob.PaySlider.range(window.Hasjob.Currency.prefix(currency)), format: Hasjob.Currency.wNumbFormat(currency) }, true); - this.slider.Link('lower').to($(this.minField)); - this.slider.Link('upper').to($(this.maxField)); + this.slider.Link('lower').to($(this.payField)); }; $(function() { @@ -632,7 +627,12 @@ $(function() { if (getCurrencyVal().toLowerCase() === 'na'){ currencyLabel = 'Pay'; } else { - currencyLabel = $('#job-filters-pmin').val() + ' - ' + $('#job-filters-pmax').val(); + var payVal = Hasjob.PaySlider.toNumeric($('#job-filters-payval').val()); + if (payVal === '0') { + currencyLabel = 'Pay ' + getCurrencyVal(); + } else { + currencyLabel = $('#job-filters-payval').val(); + }; } if (currencyLabel === 'Pay' && equityLabel !== '') { payFieldLabel = 'Equity (%)'; @@ -642,7 +642,7 @@ $(function() { $('#job-filters-pay-text').html(payFieldLabel); }; - $('#job-filters-equity').on('change', function(){ + $('#job-filters-equity').on('change', function() { setPayTextField(); }); @@ -679,11 +679,9 @@ $(function() { }; var paySlider = new Hasjob.PaySlider({ - start: (Hasjob.Config && Hasjob.Config.pmin) || 0, - end: (Hasjob.Config && Hasjob.Config.pmax) || 10000000, + pay: (Hasjob.Config && Hasjob.Config.pay) || 0, selector: '#pay-slider', - minField: '#job-filters-pmin', - maxField: '#job-filters-pmax' + payField: '#job-filters-payval' }); $('#pay-slider').on('slide', function(){ diff --git a/hasjob/templates/index.html b/hasjob/templates/index.html index 552bfd8c8..900eb34ef 100644 --- a/hasjob/templates/index.html +++ b/hasjob/templates/index.html @@ -196,8 +196,7 @@

What these jobs pay per annum

//For setting the pay slider window.Hasjob.PayFilterParameters = { 'currency': {{ request.args.get('currency') | tojson }}, - 'pmin': {{ request.args.get('pmin') | tojson }}, - 'pmax': {{ request.args.get('pmax') | tojson }} + 'pay': {{ request.args.get('pay') | tojson }}, }; $('textarea').autosize(); $("#newpost_details").hide().removeClass('jshidden'); diff --git a/hasjob/templates/layout.html b/hasjob/templates/layout.html index 9c5b0fc2d..a4e1ae215 100644 --- a/hasjob/templates/layout.html +++ b/hasjob/templates/layout.html @@ -136,8 +136,7 @@

  • - - +
  • diff --git a/hasjob/templates/macros.html b/hasjob/templates/macros.html index a1560cff8..321ffeed2 100644 --- a/hasjob/templates/macros.html +++ b/hasjob/templates/macros.html @@ -199,8 +199,7 @@

    {{ headline or post.headline }}

    window.Hasjob.Config.selectedCategories = {{request.args.getlist('c') | tojson}}; window.Hasjob.Config.selectedQuery = {{request.args.getlist('q') | tojson}}; window.Hasjob.Config.selectedCurrency = {{request.args.get('currency') | tojson}}; - window.Hasjob.Config.pmin = {{request.args.get('pmin') | tojson}}; - window.Hasjob.Config.pmax = {{request.args.get('pmax') | tojson}}; + window.Hasjob.Config.pay = {{request.args.get('pay') | tojson}}; window.Hasjob.Config.equity = {{request.args.get('equity') | tojson}}; {%- endwith %} diff --git a/hasjob/templates/postjob.html b/hasjob/templates/postjob.html index 934f753fe..413638205 100644 --- a/hasjob/templates/postjob.html +++ b/hasjob/templates/postjob.html @@ -153,8 +153,7 @@

    Next, tell us about your organization

    }); var cashslider = new Hasjob.PaySlider({ - start: {{ (form.job_pay_cash_min.data or 0)|tojson }}, - end: {{ (form.job_pay_cash_max.data or 10000000)|tojson }}, + start: [{{ (form.job_pay_cash_min.data or 0)|tojson }}, {{ (form.job_pay_cash_max.data or 10000000)|tojson }}], selector: "#cashslider", minField: '#job_pay_cash_min', maxField: '#job_pay_cash_max' diff --git a/hasjob/views/index.py b/hasjob/views/index.py index 27f23f51f..67d9acd77 100644 --- a/hasjob/views/index.py +++ b/hasjob/views/index.py @@ -165,14 +165,21 @@ def index(basequery=None, md5sum=None, tag=None, domain=None, location=None, tit # Only works as a positive filter: you can't search for jobs that DON'T pay in equity data_filters['equity'] = True basequery = basequery.filter(JobPost.pay_equity_min != None) # NOQA - if 'pmin' in request.args and 'pmax' in request.args: - f_min = string_to_number(request.args['pmin']) - f_max = string_to_number(request.args['pmax']) - if f_min is not None and f_max is not None: - data_filters['pay_min'] = f_min - data_filters['pay_max'] = f_max + if 'pay' in request.args or ('pmin' in request.args and 'pmax' in request.args): + if 'pay' in request.args: + f_pay = string_to_number(request.args['pay']) + f_min = int(f_pay * 0.90) + f_max = int(f_pay * 1.30) + else: + # Legacy URL with min/max values + f_min = string_to_number(request.args['pmin']) + f_max = string_to_number(request.args['pmax']) + f_pay = f_min # Use min for pay now + if f_pay is not None and f_min is not None and f_max is not None: + data_filters['pay'] = f_pay basequery = basequery.filter(JobPost.pay_cash_min < f_max, JobPost.pay_cash_max >= f_min) else: + f_pay = None f_min = None f_max = None From 1e8eb98f2008271cffd59548f3f8fb8ad559e6ba Mon Sep 17 00:00:00 2001 From: Kiran Jonnalagadda Date: Wed, 4 May 2016 06:57:48 +0530 Subject: [PATCH 2/2] Fix pay slider for post job page --- hasjob/static/js/app.js | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/hasjob/static/js/app.js b/hasjob/static/js/app.js index aa682b513..4a4c8aa08 100644 --- a/hasjob/static/js/app.js +++ b/hasjob/static/js/app.js @@ -462,8 +462,9 @@ window.Hasjob.Filters = { window.Hasjob.PaySlider = function(options){ this.selector = options.selector; this.slider = null; - this.pay = options.pay; - this.payField = options.payField; + this.start = options.start; + this.minField = options.minField; + this.maxField = options.maxField; this.init(); }; @@ -567,7 +568,8 @@ window.Hasjob.PaySlider.range = function(currency){ window.Hasjob.PaySlider.prototype.init = function(){ this.slider = $(this.selector).noUiSlider({ - start: this.pay, + start: this.start, + connect: (this.start.constructor === Array)?true:false, behaviour: 'tap', range: { 'min': [0, 50000], @@ -580,20 +582,32 @@ window.Hasjob.PaySlider.prototype.init = function(){ prefix: '¤' }) }); - this.slider.Link('lower').to($(this.payField)); + this.slider.Link('lower').to($(this.minField)); + if (typeof this.maxField !== 'undefined') { + this.slider.Link('upper').to($(this.maxField)); + }; return this; }; window.Hasjob.PaySlider.prototype.resetSlider = function(currency) { - var pay = Hasjob.PaySlider.toNumeric(this.slider.val()); + var startval = this.slider.val(), start; + if (startval.constructor === Array) { + start = [Hasjob.PaySlider.toNumeric(startval[0]), Hasjob.PaySlider.toNumeric(startval[1])]; + } else { + start = Hasjob.PaySlider.toNumeric(startval); + }; this.slider.noUiSlider({ - start: pay, + start: start, + connect: (start.constructor === Array)?true:false, range: Hasjob.PaySlider.range(window.Hasjob.Currency.prefix(currency)), format: Hasjob.Currency.wNumbFormat(currency) }, true); - this.slider.Link('lower').to($(this.payField)); + this.slider.Link('lower').to($(this.minField)); + if (typeof this.maxField !== 'undefined') { + this.slider.Link('upper').to($(this.maxField)); + }; }; $(function() { @@ -631,7 +645,7 @@ $(function() { if (payVal === '0') { currencyLabel = 'Pay ' + getCurrencyVal(); } else { - currencyLabel = $('#job-filters-payval').val(); + currencyLabel = $('#job-filters-payval').val() + ' per year'; }; } if (currencyLabel === 'Pay' && equityLabel !== '') { @@ -679,9 +693,9 @@ $(function() { }; var paySlider = new Hasjob.PaySlider({ - pay: (Hasjob.Config && Hasjob.Config.pay) || 0, + start: (Hasjob.Config && Hasjob.Config.pay) || 0, selector: '#pay-slider', - payField: '#job-filters-payval' + minField: '#job-filters-payval' }); $('#pay-slider').on('slide', function(){