forked from fernandokosh/redmine_time_tracker
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:hicknhack-software/redmine_time_t…
…racker
- Loading branch information
Showing
18 changed files
with
265 additions
and
197 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
@redmine_time_tracker ?= {} | ||
class @redmine_time_tracker.FieldUpdater | ||
@updateBookingHours: (name) -> | ||
start = timeString2min($("#" + name + "_start_time").val()) | ||
stop = timeString2min($("#" + name + "_stop_time").val()) | ||
|
||
# if the stop-time is smaller than the start-time, we assume a booking over midnight | ||
$("#" + name + "_spent_time").val min2timeString(stop + ((if stop < start then 1440 else 0)) - start) | ||
|
||
@updateBookingStop: (name) -> | ||
start = timeString2min($("#" + name + "_start_time").val()) | ||
spent_time = timeString2min($("#" + name + "_spent_time").val()) | ||
$("#" + name + "_stop_time").val min2parsedTimeString((start + spent_time) % 1440) | ||
|
||
@updateBookingProject: (name) -> | ||
issue_id_field = $("#" + name + "_issue_id") | ||
project_id_field = $("#" + name + "_project_id") | ||
project_id_select = $("#" + name + "_project_id_select") | ||
issue_id = issue_id_field.val() | ||
|
||
# check if the string is blank | ||
if not issue_id or $.trim(issue_id) is "" | ||
project_id_select.attr "disabled", false | ||
issue_id_field.removeClass "invalid" | ||
else | ||
$.ajax | ||
url: redmine_time_tracker.TimeTracker.base_url() + "issues/" + issue_id + ".json?key=" + current_user_api_key() | ||
type: "GET" | ||
success: (transport) => | ||
issue_id_field.removeClass "invalid" | ||
issue = transport.issue | ||
unless issue? | ||
project_id_select.attr "disabled", false | ||
else | ||
project_id_select.attr "disabled", true | ||
project_id_field.val issue.project.id | ||
$("#" + project_id_select.attr("id")) | ||
.val(issue.project.id) | ||
.trigger('change') | ||
@updateBookingActivity name | ||
|
||
error: -> | ||
project_id_select.attr "disabled", false | ||
issue_id_field.addClass "invalid" | ||
|
||
@updateBookingActivity: (name) -> | ||
$.ajax | ||
url: redmine_time_tracker.TimeTracker.base_url() + "tt_completer/get_activity.json?key=" + current_user_api_key() + "&project_id=" + $("#" + name + "_project_id").val() | ||
type: "GET" | ||
success: (activites) => | ||
activity_field = $("#" + name + "_activity_id_select") | ||
selected_activity = activity_field.find("option:selected").text() | ||
activity_field.find("option[value!=\"\"]").remove() | ||
$.each activites, (i, activity) -> | ||
activity_field.append "<option value=\"" + activity.id + "\">" + activity.name + "</option>" | ||
activity_field.val activity.id if selected_activity is activity.name |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@redmine_time_tracker ?= {} | ||
class @redmine_time_tracker.TimeTracker | ||
@hideMultiFormButtons: (button_class) -> | ||
last = $("input.#{button_class}").parent().parent().last().index() | ||
$("input." + button_class).each -> | ||
unless last is $(@).parent().parent().index() | ||
$(this).hide() | ||
else | ||
$(this).show() | ||
|
||
@base_url: -> | ||
src = $("link[href*=\"time_tracker.css\"]")[0].href | ||
src.substr 0, src.indexOf("plugin_assets") | ||
|
||
$ -> | ||
$(document).on "ajax:success", ".tt_stop, .tt_start, .tt_dialog_stop", (xhr, html, status) -> | ||
$("#content .flash").remove() | ||
$("#content").prepend html | ||
|
||
$(document).on "ajax:success", ".tt_stop, .tt_start, .tt_dialog_stop", (xhr, html, status) -> | ||
$("#content .flash").remove() | ||
$("#content").prepend html | ||
|
||
$(document).on "ajax:success", ".tt_stop, .tt_start, .tt_dialog_stop", (xhr, html, status) -> | ||
$("#content .flash").remove() | ||
$("#content").prepend html |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
@redmine_time_tracker ?= {} | ||
class @redmine_time_tracker.FormValidator | ||
constructor: (@form)-> | ||
|
||
validate: -> | ||
@_clean_up() | ||
@_do_validation() | ||
@_update_submit_button_state() | ||
|
||
_do_validation: -> | ||
#do stuff | ||
|
||
_clean_up: -> | ||
@_invalid_form_inputs().removeClass 'invalid' | ||
|
||
_validates_presence_of: (element) -> | ||
@_validates element, element.val() isnt '' | ||
|
||
_validates: (element, condition) -> | ||
element.addClass 'invalid' unless condition | ||
|
||
_form_is_invalid: -> | ||
@_invalid_form_inputs().length > 0 | ||
|
||
_invalid_form_inputs: -> | ||
@form.find(':input.invalid') | ||
|
||
_update_submit_button_state: -> | ||
@form.find(':submit').attr 'disabled', @_form_is_invalid() | ||
|
||
class @redmine_time_tracker.ListInputValidator extends @redmine_time_tracker.FormValidator | ||
constructor: (name)-> | ||
@start_field = $("#" + name + "_start_time") | ||
@stop_field = $("#" + name + "_stop_time") | ||
@spent_field = $("#" + name + "_spent_time") | ||
super @start_field.closest "form" | ||
|
||
_do_validation: -> | ||
@_validates_presence_of @start_field | ||
@_validates_presence_of @stop_field | ||
@_validates_presence_of @spent_field | ||
super | ||
|
||
class @redmine_time_tracker.EditTimeLogValidator extends @redmine_time_tracker.ListInputValidator | ||
constructor: (name) -> | ||
@date_field = $("#" + name + "_tt_log_date") | ||
super name | ||
|
||
_do_validation: () -> | ||
@_validates_presence_of @date_field | ||
super | ||
|
||
class @redmine_time_tracker.AddBookingValidator extends @redmine_time_tracker.ListInputValidator | ||
constructor: (name) -> | ||
@proj_id_field = $("#" + name + "_project_id") | ||
@proj_select = $("#" + name + "_project_id_select") | ||
@activity_select = $("#" + name + "_activity_id_select") | ||
@max_time_field = $("#" + name + "_max_time") | ||
@min_time_field = $("#" + name + "_min_time") | ||
@max_spent_time_field = $("#" + name + "_max_spent_time") | ||
super name | ||
|
||
_do_validation: () -> | ||
@_validates_presence_of @proj_select | ||
@_validates_presence_of @activity_select | ||
|
||
start = timeString2min(@start_field.val()) | ||
min_time = timeString2min(@min_time_field.val()) | ||
stop = timeString2min(@stop_field.val()) | ||
max_time = timeString2min(@max_time_field.val()) | ||
spent_time = timeString2min(@spent_field.val()) | ||
max_spent_time = timeString2min(@max_spent_time_field.val()) | ||
|
||
@_validates @spent_field, spent_time <= max_spent_time | ||
if max_spent_time < 1440 | ||
if min_time > max_time | ||
@_validates @start_field, not (max_time <= start < min_time) | ||
@_validates @stop_field, not (max_time < stop <= min_time) | ||
else | ||
@_validates @start_field, min_time <= start < max_time | ||
@_validates @stop_field, min_time < stop <= max_time | ||
super | ||
|
||
class @redmine_time_tracker.EditBookingValidator extends @redmine_time_tracker.AddBookingValidator | ||
constructor: (name) -> | ||
@date_field = $("#" + name + "_tt_booking_date") | ||
@valid_dates = $("#" + name + "_valid_dates").val().split("|") | ||
super name | ||
|
||
_do_validation: () -> | ||
@_validates_presence_of @date_field | ||
@_validates @date_field, not ($.inArray(@date_field.val(), @valid_dates) is -1) | ||
super | ||
|
||
class @redmine_time_tracker.TimeTrackerFormValidator extends @redmine_time_tracker.FormValidator | ||
constructor: -> | ||
@proj_field = $('#time_tracker_project_id') | ||
@activity_select = $('#time_tracker_activity_id') | ||
super $('.time-tracker-form') | ||
|
||
_do_validation: () -> | ||
proj_id = @proj_field.val() | ||
activity_id = @activity_select.val() | ||
@_validates @activity_select, proj_id is "" or activity_id isnt "" | ||
super |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
$('#<%= "booking-entry-" + @entry.id.to_s %>').html('<%= escape_javascript(render(:partial => 'time_bookings/list_entry', :locals => {:entry => @entry, :query => @query_bookings, :button => :book})) %>'); | ||
contextMenuHide(); | ||
contextMenuUnselectAll(); | ||
hideMultiFormButtons('tb_edit_form_update_button'); | ||
redmine_time_tracker.TimeTracker.hideMultiFormButtons('tb_edit_form_update_button'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
<% @time_bookings.each do |item| %> | ||
|
||
$('#<%= "booking-entry-" + item.id.to_s %>').html('<%= escape_javascript(render(:partial => 'time_bookings/edit_form', :locals => {:time_booking => item})) %>'); | ||
|
||
<% @time_bookings.each do |time_booking| %> | ||
var name = 'time_booking_edit_<%=time_booking.id%>'; | ||
var $entry = $('#<%="booking-entry-#{time_booking.id}"%>') | ||
.html('<%=j render(:partial => 'time_bookings/edit_form', :locals => {:time_booking => time_booking})%>') | ||
.removeClass('hascontextmenu'); | ||
var validator = new redmine_time_tracker.EditBookingValidator(name); | ||
$entry.on('change', 'input, select', function () { | ||
validator.validate(); | ||
var updater = $(this).data('updater'); | ||
if (updater != null && updater != '') { | ||
redmine_time_tracker.FieldUpdater[updater](name) | ||
} | ||
}); | ||
<% end %> | ||
contextMenuHide(); | ||
contextMenuUnselectAll(); | ||
hideMultiFormButtons('tb_edit_form_update_button'); | ||
redmine_time_tracker.TimeTracker.hideMultiFormButtons('tb_edit_form_update_button'); |
Oops, something went wrong.