diff --git a/app/assets/javascripts/time_entries.js b/app/assets/javascripts/time_entries.js index a504ded..6fc3766 100644 --- a/app/assets/javascripts/time_entries.js +++ b/app/assets/javascripts/time_entries.js @@ -45,4 +45,35 @@ $(document).ready(function(){ } }); }); + + $(".work_entry-delete-btn").click(function(){ + row = $(this).closest("tr"); + entry_id = row.data("id"); + start_date = row.data("start_date"); + duration = row.data("duration"); + description = row.data("description"); + $("#work_entry_start_date").html(start_date); + $("#work_entry_duration").html(duration); + $("#work_entry_description").html(description); + $("#confirmation_delete").data("entry_id", entry_id); + }); + + $("#confirmation_delete").click(function(){ + console.log($(this).data("entry_id")); + /** + $.ajax({ + url: $("#confirmation_delete").data("url"), + type: "delete", + data: JSON.stringify(json_data), + contentType: 'application/json', + dataType: "json", + success: function(data, status, xhr){ + window.location = forward; + }, + error: function(data, status ){ + displayFormErrors(data.responseJSON); + } + }); + */ + }); }); diff --git a/app/views/time_entries/index.haml b/app/views/time_entries/index.haml index ca3c142..608dc83 100644 --- a/app/views/time_entries/index.haml +++ b/app/views/time_entries/index.haml @@ -2,30 +2,42 @@ %span{ class:"icon-home"} %h2 Your Timesheet -%p Total Hours Worked: #{@hours_worked} -%p Total Credits Available: #{@credits_available} +%dl.dl-horizontal + %dd + %span.badge #{@hours_worked} + Total Hours Worked + %dd + %span.badge #{@credits_available} + Total Credits Available %table.table %tbody - @user_time_entries.each do |entry| - %tr + %tr{ "data-id" => entry.id, "data-description" => entry.description, + "data-duration" => entry.duration_in_hours, + "data-start_date" => entry.start_date.to_date.to_formatted_s(:rfc822)} %td #{entry.start_date.to_date.to_formatted_s(:rfc822)} %td #{entry.duration_in_hours} %td #{truncate(entry.description)} %td - %button{ class: "btn icon-remove btn-danger", role: "button", "data-toggle" => "modal", "data-target" => "#confirmation" } + %button{ class: "btn icon-remove btn-danger work_entry-delete-btn", role: "button", "data-toggle" => "modal", "data-target" => "#confirmation" } %a{class: "btn btn-lg btn-block btn-primary", href: new_time_entry_path } Add Time Entry .modal{ id: "confirmation", class: "hide", role: "dialog", "aria-labelledby" => "confirmation_title", "aria-hidden" => "true", tabindex: -1 } .modal-header %button{ class: "close", "data-dismiss" => "modal", "aria-hidden" => "true"}x - %h4{ id: "confirmation_title" } header + %h4{ id: "confirmation_title" } Are you sure you want to delete? .modal-body - Are you sure? + %div{ id: "work_entry_start_date" } + Start Date + %div{ id: "work_entry_duration" } + Duration + %div{ id: "work_entry_description" } + Description .modal-footer %button{ class: "btn", "data-dismiss" => "modal", "aria-hidden" => "true"} Close - %button{ class: "btn btn-primary" } Delete + %button{ id: "confirmation_delete", class: "btn btn-primary" } Delete