Created
November 8, 2013 13:26
-
-
Save TheLarkInn/7371016 to your computer and use it in GitHub Desktop.
Time Adjustment App
This file contains 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
class Timer.Model.TimerModel extends Backbone.Model | |
urlRoot: "/adjust_time" | |
idAttribute: 'session_id' | |
defaults: | |
'start' : null | |
'end' : null | |
'time_total' : null | |
'phase_id' : null | |
'ticket_id' : '' | |
'form_id' : '' | |
'form_name' : '' | |
class Timer.Collection.TimerCollection extends Backbone.Collection | |
model: Timer.Model.TimerModel | |
initialize: (options) -> | |
@url = "/adjust_time/#{options.ticket_id}" | |
This file contains 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
class Timer.View.TimerView extends Backbone.View | |
className: 'adjust_timer_row' | |
template: _.template($("#TimerTableViewTemplate").html()) | |
tagName: "tr" | |
events: | |
'keyup' : 'isModelDirty' | |
'click .save' : 'save' | |
initialize: (options) => | |
@ticket_id = options.ticket_id | |
@start = options.start | |
@end = options.end | |
@time_total = options.time_total | |
@session_id = this.model.attributes.session_id | |
console.log(@session_id) | |
console.log(options.forms_model) | |
@listenTo @model, 'change', @render | |
@render() | |
@save_button = $(".save", @el) | |
render: => | |
@$el.html(@template()) | |
$('.phase_billing_row_footer').before(@$el) | |
isModelDirty: => | |
startTime = $("input.start_time", @el).val() | |
endTime = $("input.end_time", @el).val() | |
console.log(startTime, endTime, @model.attributes.start, @model.attributes.end) | |
if (this.model.attributes.start).trim() == startTime+"-05:00" and (this.model.attributes.end).trim() == endTime+"-05:00" | |
$("input.save", @$el).hide() | |
else | |
$("input.save", @$el).show() | |
if @regexTimeValidation(startTime) is false or @regexTimeValidation(endTime) is false | |
$(".save",@$el).attr("disabled", true) | |
else | |
$(".save",@$el).attr("disabled", false) | |
save: => | |
startTime = $("input.start_time", @el).val()+"-05:00" | |
endTime = $("input.end_time", @el).val()+"-05:00" | |
time_total = $(".time_total", @el) | |
@model.save {start: startTime, end: endTime}, | |
success:(data) => | |
# @saveSuccessCallback | |
error: (a, err) -> | |
alert("Error saving: '#{err.statusText}'") | |
$(".save",@$el).attr("disabled", true) | |
# saveSuccessCallback: => | |
# @save_button.val("Saved") | |
# setTimeout(( => | |
# @save_button.val("Save").attr("disabled", false).hide() | |
# ), 2000) | |
# $.ajax { | |
# url: "/adjust_time/session/"+@session_id | |
# type: "GET" | |
# dataType: "json" | |
# success: (data) => | |
# time_total = $(".time_total", @el) | |
# replace_with = "#{(data.time_total/60).toFixed(2)}" | |
# $("td.time_total", @el).text(replace_with) | |
# } | |
regexTimeValidation: (text)-> | |
/^20[1-2][3-9]-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9]$/.test(text) |
This file contains 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
class Timer.View.TimerViewController extends Backbone.View | |
id: 'timer_view_popup' | |
timerViews: [] | |
forms_model: [] | |
template: _.template($("#TimerViewTemplate").html()) | |
events: | |
'click #cancel_button' : 'closeWindow' | |
initialize: (options) => | |
@ticket_id = options.ticket_id | |
@timerCollection = new Timer.Collection.TimerCollection({ticket_id: @ticket_id}) | |
console.log(options.forms_model) | |
@forms_model = options.forms_model | |
@render() | |
render: -> | |
@$el.html(@template()) | |
$('body').append(@$el) | |
@fetchTimerCollection() | |
fetchTimerCollection: => | |
@timerCollection.fetch { | |
success:(collection) => | |
_.each collection.models, (model) => | |
obj = _.find @forms_model, (obj) => return obj.form_name if obj.form_id == model.attributes.form_id | |
model.set({form_name: obj.form_name } | |
_.each collection.models, (model) => | |
timerView = new Timer.View.TimerView({model: model, forms_model: @forms_model}) | |
@timerViews.push timerView | |
} | |
closeWindow: -> | |
$(@$el).fadeOut( => | |
@remove() | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment