Skip to content

Commit

Permalink
[wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
itowtips committed Feb 23, 2018
1 parent 5c75131 commit 7daa3d7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
32 changes: 28 additions & 4 deletions app/models/concerns/gws/addon/reminder.rb
Expand Up @@ -8,7 +8,7 @@ module Reminder

included do
permit_params :reminder_url, :in_reminder_state, :in_reminder_date
permit_params in_reminder_conditions: [:user_id, :state, :interval, :interval_type]
permit_params in_reminder_conditions: [:user_id, :state, :interval, :interval_type, :base_time]

validate :validate_in_reminder_conditions
after_save :save_reminders, if: -> { in_reminder_conditions }
Expand Down Expand Up @@ -83,13 +83,34 @@ def reminder_interval_type_options
]
end

def reminder_base_time_options
[
[ "午前 8:00", "8:00" ],
[ "午前 8:30", "8:30" ],
[ "午前 9:00", "9:00" ],
[ "午前 9:30", "9:30" ],
[ "午前 10:00", "10:00" ],
[ "午前 10:30", "10:30" ],
[ "午前 11:00", "11:00" ],
[ "午前 11:30", "11:30" ],
[ "午前 12:00", "12:00" ],
]
end

def validate_in_reminder_conditions
return if in_reminder_conditions.blank?
self.in_reminder_conditions = in_reminder_conditions.map do |cond|
cond["date"] = start_at - (cond["interval"].to_i.send(cond["interval_type"]))
if allday == "allday"
base_at = Time.zone.parse("#{start_at.strftime("%Y/%m/%d")} #{cond["base_time"]}")
else
base_at = start_at
cond.delete("base_time")
end

cond["notify_at"] = base_at - (cond["interval"].to_i.send(cond["interval_type"]))
cond
end
self.in_reminder_conditions = in_reminder_conditions.sort_by! { |cond| cond["date"] }
self.in_reminder_conditions = in_reminder_conditions.sort_by! { |cond| cond["notify_at"] }
end

def remove_repeat_reminder(base_plan)
Expand Down Expand Up @@ -130,11 +151,14 @@ def save_reminders
in_reminder_conditions.each do |cond|
next if cond["state"] != "enabled"

dump(cond)

notification = reminder.notifications.new
notification.notify_at = cond["date"]
notification.notify_at = cond["notify_at"]
notification.state = cond["state"]
notification.interval = cond["interval"]
notification.interval_type = cond["interval_type"]
notification.base_time = cond["base_time"]
end

reminder.save!
Expand Down
2 changes: 1 addition & 1 deletion app/models/gws/reminder/notification.rb
@@ -1,13 +1,13 @@
class Gws::Reminder::Notification
include SS::Document

attr_accessor :in_notify_before
field :notify_at, type: DateTime
field :delivered_at, type: DateTime

field :state, type: String
field :interval, type: Integer
field :interval_type, type: String
field :base_time, type: String

embedded_in :reminder, inverse_of: :notifications

Expand Down
21 changes: 12 additions & 9 deletions app/views/gws/agents/addons/reminder/_form.html.erb
@@ -1,28 +1,31 @@
<%= jquery do %>
var sort = new SS_SortableForm('.remider-conditions', { limit: 10 });
sort.renderItems(<%== @item.reminder_conditions(@cur_user).to_json %>);

var toggleConditions = function() {
if ($("#addon-basic #item_allday").prop('checked')) {
$(".remider-conditions .allday").show();
}
else {
$(".remider-conditions .allday").hide();
}
};
$("#addon-basic #item_allday").on("click", toggleConditions);
toggleConditions();
<% end %>

<dl class="see gws-addon-reminder">
<dt>
<%= @model.t :reminder_date %><%= @model.tt :reminder_date %>
</dt>
<dd>
<!--
<%= f.text_field :in_reminder_date, value: tryb { @item.in_reminder_date.strftime("%Y/%m/%d %H:%M") }, class: "datetime js-datetime" %>
<label style="margin-left: 10px; vertical-align: middle;">
<%= f.check_box :in_reminder_state, {}, 'disabled', 'enabled' %>
<%= t 'gws.options.reminder_state.disable' %>
</label>
-->

<%= hidden_field_tag 'item[reminder_user_id]', @cur_user.id %>
<table class="remider-conditions">
<tbody>
<tr data-base="true">
<td><%= select_tag 'item[in_reminder_conditions][][state]', options_for_select(@item.reminder_state_options), id: nil %></td>
<td><%= number_field_tag 'item[in_reminder_conditions][][interval]', nil, id: nil %></td>
<td><%= select_tag 'item[in_reminder_conditions][][interval_type]', options_for_select(@item.reminder_interval_type_options), id: nil %></td>
<td class="allday"><%= select_tag 'item[in_reminder_conditions][][base_time]', options_for_select(@item.reminder_base_time_options), id: nil %></td>
</tr>
</tbody>
</table>
Expand Down

0 comments on commit 7daa3d7

Please sign in to comment.