Now creating periodic task via button

This commit is contained in:
Robert Waltemath 2013-06-21 13:48:48 +02:00
parent 4037ef12da
commit 6b62fc90d8
6 changed files with 10 additions and 12 deletions

View file

@ -18,6 +18,9 @@ class TasksController < ApplicationController
def create def create
@task = Task.new(params[:task]) @task = Task.new(params[:task])
if params[:periodic]
@task.periodic_task_group = PeriodicTaskGroup.new
end
if @task.save if @task.save
redirect_to tasks_url, :notice => I18n.t('tasks.create.notice') redirect_to tasks_url, :notice => I18n.t('tasks.create.notice')
else else

View file

@ -1,5 +1,5 @@
class PeriodicTaskGroup < ActiveRecord::Base class PeriodicTaskGroup < ActiveRecord::Base
has_many :tasks, :inverse_of => :periodic_task_group, :dependent => :destroy has_many :tasks, :dependent => :destroy
PeriodDays = 7 PeriodDays = 7

View file

@ -2,7 +2,7 @@ class Task < ActiveRecord::Base
has_many :assignments, :dependent => :destroy has_many :assignments, :dependent => :destroy
has_many :users, :through => :assignments has_many :users, :through => :assignments
belongs_to :workgroup belongs_to :workgroup
belongs_to :periodic_task_group, :inverse_of => :tasks belongs_to :periodic_task_group
scope :non_group, where(workgroup_id: nil, done: false) scope :non_group, where(workgroup_id: nil, done: false)
scope :done, where(done: true) scope :done, where(done: true)
@ -47,14 +47,10 @@ class Task < ActiveRecord::Base
end end
end end
def periodic def periodic?
not periodic_task_group.nil? not periodic_task_group.nil?
end end
def periodic=(p)
self.periodic_task_group = PeriodicTaskGroup.new if p == "1"
end
def is_assigned?(user) def is_assigned?(user)
self.assignments.detect {|ass| ass.user_id == user.id } self.assignments.detect {|ass| ass.user_id == user.id }
end end

View file

@ -23,8 +23,9 @@
= f.input :required_users = f.input :required_users
= f.association :workgroup = f.association :workgroup
= f.input :due_date, as: :date_picker = f.input :due_date, as: :date_picker
= f.input :periodic, as: :boolean
= f.input :done = f.input :done
.form-actions .form-actions
= f.submit class: 'btn' = f.submit class: 'btn btn-primary'
- unless @task.id
= f.submit 'Wöchentliche Aufgabe erstellen', name: 'periodic', class: 'btn'
= link_to t('ui.or_cancel'), :back = link_to t('ui.or_cancel'), :back

View file

@ -29,6 +29,6 @@
= link_to t('ui.edit'), edit_task_path(@task), class: 'btn' = link_to t('ui.edit'), edit_task_path(@task), class: 'btn'
= link_to t('ui.delete'), task_path(@task), :method => :delete, :confirm => "Die Aufgabe wirklich löschen?", = link_to t('ui.delete'), task_path(@task), :method => :delete, :confirm => "Die Aufgabe wirklich löschen?",
class: 'btn btn-danger' class: 'btn btn-danger'
- if @task.periodic - if @task.periodic?
= link_to t('ui.delete_all'), periodic_task_group_path(@task.periodic_task_group), :method => :delete, = link_to t('ui.delete_all'), periodic_task_group_path(@task.periodic_task_group), :method => :delete,
:confirm => "Alle Aufgaben dieser wöchentlichen Aufgabe wirklich löschen?", class: 'btn btn-danger' :confirm => "Alle Aufgaben dieser wöchentlichen Aufgabe wirklich löschen?", class: 'btn btn-danger'

View file

@ -1,7 +1,5 @@
Foodsoft::Application.routes.draw do Foodsoft::Application.routes.draw do
get "periodic_task_groups/destroy"
get "order_comments/new" get "order_comments/new"
get "comments/new" get "comments/new"