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
@task = Task.new(params[:task])
if params[:periodic]
@task.periodic_task_group = PeriodicTaskGroup.new
end
if @task.save
redirect_to tasks_url, :notice => I18n.t('tasks.create.notice')
else

View File

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

View File

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

View File

@ -23,8 +23,9 @@
= f.input :required_users
= f.association :workgroup
= f.input :due_date, as: :date_picker
= f.input :periodic, as: :boolean
= f.input :done
.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

View File

@ -29,6 +29,6 @@
= 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?",
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,
: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
get "periodic_task_groups/destroy"
get "order_comments/new"
get "comments/new"