-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanagers-add.js
More file actions
110 lines (99 loc) · 3.35 KB
/
Copy pathmanagers-add.js
File metadata and controls
110 lines (99 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
$(function(){
// $("h2 input").change(function(){
// var the_date = $(this).val();
// var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
// $("form").attr("action", "?date=" + the_date);
// the_date = the_date.split('/');
// $("#work_date").val(the_date[2] + the_date[0] + the_date[1]);
// $("h2 .work_date").html(months[parseInt(the_date[0]-1)] + ' ' + parseInt(the_date[1]) + ', ' + the_date[2]);
// });
// used for checkboxes
var counter = 1;
function set_buttons() {
$("form .add_button").unbind("click").click(function(){
var $new = $('.line:eq(0)').clone();
$new.removeClass("highlight");
$('select', $new).each(function(index){
var numItems = $('.employee select').length;
if (index == 0) {
// need to default employee to previous employee
$(this).get(0).selectedIndex = $('.employee select').eq(numItems-1).prop("selectedIndex");
} else {
$(this).get(0).selectedIndex = 0;
}
});
$('input.text', $new).val("");
$('input.checkbox', $new).attr('checked');
$('input.checkbox', $new).val(counter);
$('.add', $new).append('<span class="remove remove_button">X Remove</span>');
$("#time_entry #lines").append( $new );
set_buttons();
});
$("form .remove_button").unbind("click").click(function(){
$(this).parent().parent().remove();
});
counter++;
}
set_buttons();
$("#jumper select").change(function(){
if ( $(this).val() != '' ) {
window.location = $(this).val() + '?date=' + $("#work_date").val();
}
});
$("#jumper .date_picker").change(function(){
if ( $(this).val() != '' ) {
window.location = '?date=' + $(this).val();
}
});
$("#time_entry form").submit(function(){
var errors = '';
var entries = '';
$(".line", this).removeClass("highlight").each(function(){
var the_line = this;
var ok = true;
ok = ok && $(".employee select", this).val() != '';
ok = ok && $(".task select", this).val() != '';
ok = ok && $("input.text", this).val() != '';
var pair = $(".employee select", this).val() + ',' + $(".task select", this).val();
if ( ok && entries.indexOf(pair) != -1 ) {
ok = false;
errors = 'One or more entries are duplicate values for an employee/task combination.';
return false;
}
else entries += "|" + pair;
// check for existing
if ( ok ) {
var ajax_params = {
action: 'entry_exists',
project_id: $("input#project_id").val(),
work_date: $("input#work_date").val(),
user_id: $(".employee select", this).val(),
task_id: $(".task select", this).val()
};
$.ajax({
url: '/managers/ajax/',
data: ajax_params,
success: function(data) {
var $response = eval('(' + data + ')');
if ( $response.status ) {
$(the_line).prepend('<div class="inline_error">' + $response.message + '</div>');
}
}
});
}
if ( !ok ) {
$(this).addClass("highlight");
if ( errors == '' ) errors = 'One or more entries is incomplete. They have been highlighted. Please correct these entries or remove them before submitting.';
}
});
if ( errors != '' ) {
$('.errors', this).remove();
$(this).prepend('<div class="errors" style="display: none;"><p>' + errors + '</p></div>');
$('.errors', this).fadeIn("slow");
return false;
}
else {
return true;
}
});
});