delete list finished

This commit is contained in:
Zoker 2016-10-07 17:52:09 +08:00
parent 3f5dcad488
commit 14edac459d
6 changed files with 63 additions and 21 deletions

View File

@ -124,6 +124,12 @@
font-weight: bold;
background-color: #f8f8f8;
border-color: #f8f8f8;
.list-limit-operations{
display: none;
}
&:hover .list-limit-operations{
display: inline;
}
}
.panel-heading .badge {
color: #999;
@ -191,15 +197,15 @@
.closed-task{
text-decoration: line-through;
}
.task_operation{
.list-operations{
float: right;
font-style: italic;
}
.operation-icons{
float: right;
color: #888;
color: #a5a5a5;
.add-task-plus{
color: #888888;
}
i {
cursor: pointer;
padding: 3px;
}
}
.add-task-field{

View File

@ -32,14 +32,10 @@ class ListsController < ApplicationController
end
end
# DELETE /lists/1
# DELETE /lists/1.json
def destroy
@list.destroy
respond_to do |format|
format.html { redirect_to lists_url, notice: '列表删除成功!' }
format.json { head :no_content }
end
render json: {status: 'success', message: '删除列表成功!'}
end
private

View File

@ -3,7 +3,7 @@
%span.plan_title{'v-text' => 'plan.title'}
%span.plan_description{'v-text' => 'plan.description'}
.plan-operations
%i.icon-trash.has-tooltip{ title: '删除此计划项', 'data-toggle' => 'tooltip', 'data-placement' => 'bottom',
%i.icon-trash.has-tooltip{ title: '删除此计划项', 'data-toggle' => 'tooltip', 'data-placement' => 'right',
'data-toggle' => 'modal', 'data-target' => '.delete_plan_modal' }
.delete_plan_modal.modal.fade{'aria-hidden' => 'true', :role => 'dialog', :tabindex => '-1'}
.modal-dialog
@ -28,8 +28,26 @@
.panel-heading
%span
{{list.title}}
.operation-icons
%i.icon-plus{'v-on:click' => 'newTask'}
.list-operations
.list-limit-operations
%i.icon-trash{title: '删除此任务组', 'v-on:click' => 'deleteListModal', 'data-toggle' => 'tooltip',
'data-placement' => 'left', onmouseover: "$(this).tooltip('show')"}
%i.icon-plus.add-task-plus{title: '添加任务', 'v-on:click' => 'newTask', 'data-toggle' => 'tooltip',
'data-placement' => 'left', onmouseover: "$(this).tooltip('show')"}
.delete_list_modal.modal.fade{'aria-hidden' => 'true', :role => 'dialog', :tabindex => '-1'}
.modal-dialog
.modal-content
.modal-header
%button.close{'data-dismiss' => 'modal', :type => 'button'}
%span{'aria-hidden' => 'true'}
%i.icon-remove
%h4.modal-title
确认删除 {{list.title}}
.modal-body
所属的任务都会被删除,且无法恢复,请谨慎操作。
.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'
@ -63,7 +81,7 @@
title: '',
color_tag: '',
color_tag_class: '',
new_task_path:'',
path:'',
tasks: [{
title: '',
status: '',
@ -141,6 +159,27 @@
}
xhr.send()
},
deleteListModal: function() {
$(event.currentTarget).closest('.panel-heading').find('.delete_list_modal').modal('show')
},
deleteList: function() {
var xhr = new XMLHttpRequest()
var listPath = $(event.currentTarget).closest('.panel').find('#new_task_path').val()
var data = this.plan.lists
xhr.open("DELETE", listPath + '.json')
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded")
xhr.onload = function () {
result = JSON.parse(xhr.responseText)
for (var i = 0; i < data.length; i++){
if ( data[i].path == listPath ){
data.splice(i, 1)
}
}
notifyTop(result.message)
}
xhr.send()
$(event.currentTarget).closest('.delete_list_modal').modal('hide')
},
addList: function () {
var xhr = new XMLHttpRequest()
var self = this
@ -164,13 +203,14 @@
addTask: function () {
var xhr = new XMLHttpRequest()
var self = this
var addTaskUrl = $(event.currentTarget).closest('#new_task').find('#new_task_path').val()
var listPath = $(event.currentTarget).closest('#new_task').find('#new_task_path').val()
var addTaskUrl = listPath + '/tasks.json'
var taskInput = $(event.currentTarget).closest('#new_task').find('#task_title')
var task = taskInput.val()
var list = false
var data = self.plan.lists
for (var i = 0; i < data.length; i++){
if ( data[i].new_task_path == addTaskUrl ){
if ( data[i].path == listPath ){
list = data[i]
}
}

View File

@ -3,7 +3,7 @@ json.new_list_path "#{plan_lists_path(@plan)}.json"
json.lists @lists do |list|
json.(list, :title, :color_tag)
json.color_tag_class color_tag_class('panel-', list.color_tag)
json.new_task_path "#{plan_list_tasks_path(@plan, list)}.json"
json.path "#{plan_list_path(@plan, list)}"
json.tasks list.tasks do |task|
json.(task, :title, :status)
json.status_class task.status == 0 ? 'closed-task' : ''

View File

@ -2,7 +2,7 @@
.field
= text_field_tag :task_title, nil, class: 'form-control', required: true, placeholder: '任务名称',
'v-on:keyup.enter' => 'addTask'
= hidden_field_tag :new_task_path, nil, ':value' => 'list.new_task_path'
= hidden_field_tag :new_task_path, nil, ':value' => 'list.path'
.field.add-task-buttons
%button.btn.btn-sm.btn-default{ :type => "button", 'v-on:click' => 'cancelTask' } 取消
%button.btn.btn-sm.btn-primary{ :type => "button", 'v-on:click' => 'addTask' } 提交

View File

@ -7,8 +7,8 @@ Rails.application.routes.draw do
root to: 'home#index'
resources :plans, path: :p do
resources :lists, only: [:new, :create, :update] do
resources :tasks, only: [:new, :create, :update] do
resources :lists, only: [:new, :create, :update, :destroy] do
resources :tasks, only: [:new, :create, :update, :destroy] do
member do
put 'action'
end