task over function finished

This commit is contained in:
Zoker 2016-10-15 15:57:11 +08:00
parent 8ef2ba7167
commit 5cd98475cc
5 changed files with 44 additions and 13 deletions

View File

@ -1,6 +1,6 @@
class TasksController < ApplicationController
before_action :authenticate_user!
before_action :set_plan_list, only: [:new, :create]
before_action :set_plan_list, only: [:new, :create, :update]
before_action :set_task, only: [:update, :action, :destroy]
# GET /tasks/new
@ -34,17 +34,10 @@ class TasksController < ApplicationController
end
end
# PATCH/PUT /tasks/1
# PATCH/PUT /tasks/1.json
def update
respond_to do |format|
if @task.update(task_params)
format.html { redirect_to @task, notice: '更新任务成功!' }
format.json { render :show, status: :ok, location: @task }
else
format.html { render :edit }
format.json { render json: @task.errors, status: :unprocessable_entity }
end
unless @task.update(task_params)
render json: {status: 'failed', message: '任务更新失败, 请稍后重试 !'}
end
end

View File

@ -48,20 +48,23 @@
.modal-footer
%button.btn.btn-default{'data-dismiss' => 'modal', :type => 'button'} 取消
%button.btn.btn-danger{:type => 'button', 'v-on:click' => 'deleteList'} 确认删除
.panel-body
.add-task-field
= render 'tasks/form'
%p{'v-if' => 'list.tasks.length == 0'} 暂无相关任务
%template{'v-for' => 'task in list.tasks'}
.task-field
%span.task-item{':class' => 'task.status_class'}
{{task.title}}
.task-operations
.non-group
= hidden_field_tag :task_path, nil, 'v-model' => 'task.path'
.non-group{'v-show' => 'task.status == 1'}
%i.icon-pencil
.non-group
%i.icon-remove
%button.btn.btn-primary.btn-xs
%button.btn.btn-primary.btn-xs{'v-on:click' => 'updateTask', 'v-show' => 'task.status == 1'}
over
.col-md-3#new_list_area{ 'v-show' => 'newListField' }
#new_list_field
@ -90,6 +93,7 @@
color_tag_class: '',
path:'',
tasks: [{
path: '',
title: '',
status: '',
status_class: ''
@ -190,6 +194,35 @@
xhr.send()
$(event.currentTarget).closest('.delete_list_modal').modal('hide')
},
updateTask: function() {
var xhr = new XMLHttpRequest()
var data = this.plan.lists
var listPath = $(event.currentTarget).closest('.panel').find('#new_task_path').val()
var path = $(event.currentTarget).parent().find('#task_path').val()
var list = false
var task = false
for (var i = 0; i < data.length; i++){
if ( data[i].path == listPath ){
list = data[i]
}
}
xhr.open("PUT", path + '.json')
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded")
xhr.onload = function () {
result = JSON.parse(xhr.responseText)
if (result.status == 'failed') {
notifyTop(result.message, 'danger')
} else {
for (var i = 0; i < list.tasks.length; i++){
if ( list.tasks[i].path == path ){
list.tasks.splice(i, 1, result)
}
}
notifyTop('任务更新成功 !')
}
}
xhr.send('task[status]=0')
},
addList: function () {
var xhr = new XMLHttpRequest()
var self = this

View File

@ -7,5 +7,6 @@ json.lists @lists do |list|
json.tasks list.tasks do |task|
json.(task, :title, :status)
json.status_class task.status == 0 ? 'closed-task' : ''
json.path plan_list_task_path(@plan, list, task)
end
end

View File

@ -1,2 +1,3 @@
json.extract! @task, :title, :status
json.status_class ''
json.status_class ''
json.path plan_list_task_path(@plan, @list, @task)

View File

@ -0,0 +1,3 @@
json.extract! @task, :title, :status
json.status_class @task.status == 0 ? 'closed-task' : ''
json.path plan_list_task_path(@plan, @list, @task)