Created
November 13, 2013 18:41
-
-
Save acmisiti/7454101 to your computer and use it in GitHub Desktop.
Something I just noticed with the wage backbone stuff in the profile. When you add methods to backbone views, avoid at all costs using just jquery selector $(..). Try to always use this.$el.find(....). I avoid it as much as possible and really try my hardest to only use it for general alerts which i keep in employiiAnimations.js. Other than that…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TCB.Views.StaffProfileCompensation = Backbone.View.extend({ | |
el: "#js-staff-profile-compensation", | |
attributes : function(){ | |
return {} | |
}, | |
initialize: function(){ | |
}, | |
events: { | |
'...' : '...', | |
}, | |
template: _.template('...'), | |
process_changed_comp_type : function(){ | |
var comptype = $('select[name=comp_type]').val(); | |
if (comptype === "salary"){ | |
$('#profile-comp-amount-hourly-edit').hide(); | |
$('#profile-comp-amount-piece-edit').hide(); | |
$('#profile-comp-amount-salary-edit').show(); | |
}else if (comptype === "hourly"){ | |
$('#profile-comp-amount-salary-edit').hide(); | |
$('#profile-comp-amount-piece-edit').hide(); | |
$('#profile-comp-amount-hourly-edit').show(); | |
}else if (comptype === "piece"){ | |
$('#profile-comp-amount-salary-edit').hide(); | |
$('#profile-comp-amount-hourly-edit').hide(); | |
$('#profile-comp-amount-piece-edit').show(); | |
} | |
$('.compensation-input').val('0'); | |
}, | |
process_edit_clicked : function() { | |
$("#js-edit-profile-comp").hide(); | |
$("#js-save-profile-comp").fadeIn('slow'); | |
$('#profile-comp-type').hide(); | |
$('#profile-comp-type-edit').fadeIn('slow'); | |
var comptype = $('select[name=comp_type]').val(); | |
if (comptype === "salary"){ | |
$('#profile-comp-amount-salary').hide(); | |
$('#profile-comp-amount-salary-edit').show(); | |
}else if (comptype === "hourly"){ | |
$('#profile-comp-amount-hourly').hide(); | |
$('#profile-comp-amount-hourly-edit').show(); | |
}else if (comptype === "piece"){ | |
$('#profile-comp-amount-piece').hide(); | |
$('#profile-comp-amount-piece-edit').show(); | |
} | |
}, | |
process_sig_clicked : function(){ | |
$('#js-sign-wage-change-notice-submit').show(); | |
}, | |
process_user_input : function(e){ | |
var valid = $("#js-staff-profile-form").validate().form() | |
if (valid){ | |
if(e.which === ENTER_KEY){ | |
set_compensation_confirm_message(); | |
$('#js-sign-wage-change-notice').modal('show'); | |
} | |
} | |
return; | |
}, | |
process_save_clicked : function() { | |
var valid = $("#js-staff-profile-form").validate().form() | |
if (valid){ | |
set_compensation_confirm_message(); | |
$('#js-sign-wage-change-notice').modal('show'); | |
} | |
return; | |
}, | |
process_cancel_clicked : function(){ | |
$('#js-sign-wage-change-notice').modal('hide'); | |
}, | |
process_submit_clicked : function(){ | |
var valid = $("#js-staff-profile-form").validate().form() | |
if (valid){ | |
var options = { | |
'success' : function(data) { | |
if(data.success) | |
window.location.reload(); | |
}, | |
} | |
var JSON = { | |
'eid' : $('input[name=eid]').val() | |
}; | |
$('.edit-comp-input:visible').each(function(){ | |
JSON[$(this).attr('name')] = $(this).attr('value'); | |
}); | |
$('.edit_sig_input').each(function(){ | |
JSON[$(this).attr('name')] = $(this).attr('value'); | |
}); | |
TCB.router.make_request('/api/update_profile_info/', JSON , null, null, options ); | |
} | |
return; | |
}, | |
render : function(employee, hirepack, account_state) { | |
var JSON = { hirepack: hirepack, employee: employee, account_state: account_state }; | |
this.$el.html(this.template(JSON)); | |
this.$el.find('.tooltip_global').tipsy({gravity: 'n'}); | |
if (employee.comptype === "salary"){ | |
$('#profile-comp-type').append('Salary'); | |
$('#profile-comp-amount-salary').show(); | |
}else if (employee.comptype === "hourly"){ | |
$('#profile-comp-type').append('Hourly'); | |
$('#profile-comp-amount-hourly').show(); | |
}else if (employee.comptype === "piece"){ | |
$('#profile-comp-type').append('Paid by the Piece'); | |
$('#profile-comp-amount-piece').show(); | |
} | |
this.$el.find('') | |
return this; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment