Move everything to models and services #17
|
@ -283,14 +283,25 @@
|
|||
this.newTask = {}
|
||||
},
|
||||
markAsDone(e) {
|
||||
let context = this
|
||||
if (e.target.checked) {
|
||||
setTimeout(doTheDone, 300); // Delay it to show the animation when marking a task as done
|
||||
} else {
|
||||
doTheDone() // Don't delay it when un-marking it as it doesn't have an animation the other way around
|
||||
//let context = this
|
||||
let updateFunc = () => {
|
||||
this.taskService.update({id: e.target.id}, {done: e.target.checked})
|
||||
.then(() => {
|
||||
this.list.sortTasks()
|
||||
this.handleSuccess({message: 'The task was successfully ' + (e.target.checked ? '' : 'un-') + 'marked as done.'})
|
||||
})
|
||||
.catch(e => {
|
||||
this.handleError(e)
|
||||
})
|
||||
}
|
||||
|
||||
function doTheDone() {
|
||||
if (e.target.checked) {
|
||||
setTimeout(updateFunc(), 300); // Delay it to show the animation when marking a task as done
|
||||
} else {
|
||||
updateFunc() // Don't delay it when un-marking it as it doesn't have an animation the other way around
|
||||
}
|
||||
|
||||
/*function doTheDone() {
|
||||
const cancel = message.setLoading(context)
|
||||
|
||||
HTTP.post(`tasks/` + e.target.id, {done: e.target.checked}, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
|
||||
|
@ -303,7 +314,7 @@
|
|||
cancel()
|
||||
context.handleError(e)
|
||||
})
|
||||
}
|
||||
}*/
|
||||
},
|
||||
editTask(id) {
|
||||
// Find the selected task and set it to the current object
|
||||
|
|
|
@ -56,4 +56,8 @@ export default class TaskModel extends AbstractModel {
|
|||
}
|
||||
return dateobj
|
||||
}
|
||||
|
||||
markAsDone() {
|
||||
|
||||
}
|
||||
}
|
|
@ -162,6 +162,12 @@ export default class AbstractService {
|
|||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a put request to the url specified before
|
||||
* @param pathparams
|
||||
* @param data
|
||||
* @returns {Promise<any | never>}
|
||||
*/
|
||||
create(pathparams, data) {
|
||||
const cancel = this.setLoading()
|
||||
|
||||
|
@ -177,4 +183,26 @@ export default class AbstractService {
|
|||
cancel()
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a post request to the update url
|
||||
* @param pathparams
|
||||
* @param data
|
||||
* @returns {Q.Promise<any>}
|
||||
*/
|
||||
update(pathparams, data) {
|
||||
const cancel = this.setLoading()
|
||||
|
||||
// Finally make the request and get our data.
|
||||
return this.http.post(this.getReplacedRoute(this.paths.update, pathparams), data)
|
||||
.catch(error => {
|
||||
return this.errorHandler(error)
|
||||
})
|
||||
.then(response => {
|
||||
return Promise.resolve(this.modelFactory(response.data))
|
||||
})
|
||||
.finally(() => {
|
||||
cancel()
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user