From 9646b2d9843de6fe898d257918d83071b29ffed1 Mon Sep 17 00:00:00 2001 From: frech Date: Sat, 15 Jul 2017 20:57:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=A0=E9=99=A4=E5=B1=9E?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/application.js | 3 ++- app/assets/javascripts/vue-resource.min.js | 7 ++++++ app/views/plans/show.html.haml | 26 +++++++++++++++++++--- 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 app/assets/javascripts/vue-resource.min.js diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index f7e5415..f821a39 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -16,6 +16,7 @@ //= require bootstrap.js //= require bootstrap-notify.min //= require vue.min +//= require vue-resource.min //= require plans //= require lists -//= require tasks \ No newline at end of file +//= require tasks diff --git a/app/assets/javascripts/vue-resource.min.js b/app/assets/javascripts/vue-resource.min.js new file mode 100644 index 0000000..2f1f4b2 --- /dev/null +++ b/app/assets/javascripts/vue-resource.min.js @@ -0,0 +1,7 @@ +/*! + * vue-resource v1.3.4 + * https://github.com/pagekit/vue-resource + * Released under the MIT License. + */ + +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueResource=e()}(this,function(){"use strict";function t(t){this.state=J,this.value=void 0,this.deferred=[];var e=this;try{t(function(t){e.resolve(t)},function(t){e.reject(t)})}catch(t){e.reject(t)}}function e(t,e){t instanceof Promise?this.promise=t:this.promise=new Promise(t.bind(e)),this.context=e}function n(t){"undefined"!=typeof console&&_&&console.warn("[VueResource warn]: "+t)}function o(t){"undefined"!=typeof console&&console.error(t)}function r(t,e){return F(t,e)}function i(t){return t?t.replace(/^\s*|\s*$/g,""):""}function u(t,e){return t&&void 0===e?t.replace(/\s+$/,""):t&&e?t.replace(new RegExp("["+e+"]+$"),""):t}function s(t){return t?t.toLowerCase():""}function a(t){return t?t.toUpperCase():""}function c(t){return"string"==typeof t}function f(t){return"function"==typeof t}function p(t){return null!==t&&"object"==typeof t}function h(t){return p(t)&&Object.getPrototypeOf(t)==Object.prototype}function d(t){return"undefined"!=typeof Blob&&t instanceof Blob}function l(t){return"undefined"!=typeof FormData&&t instanceof FormData}function m(t,n,o){var r=e.resolve(t);return arguments.length<2?r:r.then(n,o)}function y(t,e,n){return n=n||{},f(n)&&(n=n.call(e)),b(t.bind({$vm:e,$options:n}),t,{$options:n})}function v(t,e){var n,o;if(Q(t))for(n=0;n=200&&r<300,this.status=r||0,this.statusText=i||"",this.headers=new mt(o),this.body=t,c(t)?this.bodyText=t:d(t)&&(this.bodyBlob=t,L(t)&&(this.bodyText=H(t)))};yt.prototype.blob=function(){return m(this.bodyBlob)},yt.prototype.text=function(){return m(this.bodyText)},yt.prototype.json=function(){return m(this.text(),function(t){return JSON.parse(t)})},Object.defineProperty(yt.prototype,"data",{get:function(){return this.body},set:function(t){this.body=t}});var vt=function(t){this.body=null,this.params={},Y(this,t,{method:a(t.method||"GET")}),this.headers instanceof mt||(this.headers=new mt(this.headers))};vt.prototype.getUrl=function(){return U(this)},vt.prototype.getBody=function(){return this.body},vt.prototype.respondWith=function(t,e){return new yt(t,Y(e||{},{url:this.getUrl()}))};var bt={Accept:"application/json, text/plain, */*"},gt={"Content-Type":"application/json;charset=utf-8"};return B.options={},B.headers={put:gt,post:gt,patch:gt,delete:gt,common:bt,custom:{}},B.interceptor={before:ct,method:ft,jsonp:at,json:ut,form:it,header:pt,cors:rt},B.interceptors=["before","method","jsonp","json","form","header","cors"],["get","delete","head","jsonp"].forEach(function(t){B[t]=function(e,n){return this(Y(n||{},{url:e,method:t}))}}),["post","put","patch"].forEach(function(t){B[t]=function(e,n,o){return this(Y(o||{},{url:e,method:t,body:n}))}}),M.actions={get:{method:"GET"},save:{method:"POST"},query:{method:"GET"},update:{method:"PUT"},remove:{method:"DELETE"},delete:{method:"DELETE"}},"undefined"!=typeof window&&window.Vue&&window.Vue.use(D),D}); diff --git a/app/views/plans/show.html.haml b/app/views/plans/show.html.haml index 5c8435e..6c30efa 100644 --- a/app/views/plans/show.html.haml +++ b/app/views/plans/show.html.haml @@ -54,7 +54,7 @@ = render 'tasks/form' %p{'v-if' => 'list.tasks.length == 0'} 暂无相关任务 - %template{'v-for' => 'task in list.tasks'} + %template{'v-for' => '(task, index) in list.tasks'} .task-field %span.task-item{':class' => 'task.status_class'} {{task.title}} @@ -63,7 +63,7 @@ .non-group{'v-show' => 'task.status == 1'} %i.icon-pencil .non-group - %i.icon-remove + %i.icon-remove{'@click' => 'removeTask(index)'} %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' } @@ -194,6 +194,26 @@ xhr.send() $(event.currentTarget).closest('.delete_list_modal').modal('hide') }, + removeTask: function(index) { + var $currentTarget = $(event.currentTarget) + var data = this.plan.lists + var path = $currentTarget.closest('.task-operations').find('#task_path').val() + var listPath = $(event.currentTarget).closest('.panel').find('#new_task_path').val() + for (var i = 0; i < data.length; i++){ + if ( data[i].path == listPath ){ + list = data[i] + } + } + this.$http.delete(path).then( + response => { + list.tasks.splice(index, 1) + notifyTop('任务删除成功!') + }, + response => { + notifyTop(result.alert) + } + ) + }, updateTask: function() { var xhr = new XMLHttpRequest() var data = this.plan.lists @@ -281,4 +301,4 @@ xhr.send( "task[title]="+ task ) }, } - }) \ No newline at end of file + })