2019-01-14 22:40:30 +01:00
|
|
|
import Vue from 'vue'
|
|
|
|
|
import { Component, Prop, Watch } from 'vue-property-decorator'
|
|
|
|
|
|
|
|
|
|
import { rescodes } from '../../../store/Modules/rescodes'
|
|
|
|
|
import { UserStore } from '@modules'
|
|
|
|
|
|
|
|
|
|
import { ITodo } from '../../../model/index'
|
|
|
|
|
|
2019-01-30 01:05:31 +01:00
|
|
|
import { SubMenus } from '../SubMenus'
|
2019-01-29 23:13:28 +01:00
|
|
|
|
|
|
|
|
|
2019-01-28 03:13:04 +01:00
|
|
|
import $ from 'jquery'
|
|
|
|
|
|
2019-01-29 23:13:28 +01:00
|
|
|
// import { debounce } from '../../../classes/debounce'
|
|
|
|
|
import { askConfirm } from '../../../classes/routinestd'
|
2019-01-29 03:12:18 +01:00
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
@Component({
|
2019-01-29 23:13:28 +01:00
|
|
|
name: 'SingleTodo',
|
|
|
|
|
components: { SubMenus }
|
2019-01-14 22:40:30 +01:00
|
|
|
})
|
|
|
|
|
export default class SingleTodo extends Vue {
|
2019-01-16 02:26:43 +01:00
|
|
|
public selectPriority: [] = []
|
2019-01-28 03:13:04 +01:00
|
|
|
public menuPopupTodo: any[] = []
|
2019-01-16 02:26:43 +01:00
|
|
|
public iconCompleted: string = ''
|
2019-01-27 19:09:48 +01:00
|
|
|
public classCompleted: string = ''
|
|
|
|
|
public classDescr: string = ''
|
2019-01-28 20:39:40 +01:00
|
|
|
public classDescrEdit: string = ''
|
2019-01-27 19:09:48 +01:00
|
|
|
public classExpiring: string = ''
|
|
|
|
|
public classExpiringEx: string = ''
|
2019-01-16 02:26:43 +01:00
|
|
|
public iconPriority: string = ''
|
|
|
|
|
public popover: boolean = false
|
2019-01-29 03:12:18 +01:00
|
|
|
public popover_menu: boolean = false // Serve
|
2019-01-27 19:09:48 +01:00
|
|
|
public classRow: string = ''
|
|
|
|
|
public sel: boolean = false
|
2019-01-28 03:13:04 +01:00
|
|
|
public inEdit: boolean = false
|
2019-01-28 20:39:40 +01:00
|
|
|
public precDescr: string = ''
|
2019-01-29 00:48:04 +01:00
|
|
|
public menuProgress: string = 'menuprogress'
|
|
|
|
|
public percProgress: string = 'percProgress'
|
|
|
|
|
public colProgress: string = 'blue'
|
2019-01-29 23:13:28 +01:00
|
|
|
public togglemenu: boolean = false
|
2019-01-30 02:01:04 +01:00
|
|
|
public percentageProgress: number = 0
|
2019-01-16 02:26:43 +01:00
|
|
|
$q: any
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
@Prop({ required: true }) itemtodo: ITodo
|
|
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
|
|
|
|
|
@Watch('itemtodo.completed') valueChanged() {
|
2019-01-28 03:13:04 +01:00
|
|
|
this.watchupdate()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Watch('itemtodo.enableExpiring') valueChanged4() {
|
|
|
|
|
this.watchupdate()
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
2019-01-27 19:09:48 +01:00
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
@Watch('itemtodo.expiring_at') valueChanged2() {
|
2019-01-28 03:13:04 +01:00
|
|
|
this.watchupdate()
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
2019-01-27 19:09:48 +01:00
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
@Watch('itemtodo.priority') valueChanged3() {
|
2019-01-28 03:13:04 +01:00
|
|
|
this.watchupdate()
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-29 00:48:04 +01:00
|
|
|
|
2019-02-04 04:17:50 +01:00
|
|
|
@Watch('itemtodo.descr') valueChanged5() {
|
2019-01-28 20:39:40 +01:00
|
|
|
this.precDescr = this.itemtodo.descr
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-29 00:48:04 +01:00
|
|
|
@Watch('itemtodo.progress') valueChanged6() {
|
|
|
|
|
this.updateClasses()
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-11 02:58:53 +01:00
|
|
|
dateToYYYYMMDD(date) {
|
|
|
|
|
// may have timezone caveats https://stackoverflow.com/a/29774197/1850609
|
|
|
|
|
return date && date.toISOString().split('T')[0]
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-28 20:39:40 +01:00
|
|
|
isTodo() {
|
2019-01-28 03:13:04 +01:00
|
|
|
return this.isTodoByElem(this.itemtodo)
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-28 20:39:40 +01:00
|
|
|
isTodoByElem(elem) {
|
2019-01-28 03:13:04 +01:00
|
|
|
return elem.descr.slice(-1) !== ':'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
watchupdate() {
|
2019-01-14 22:40:30 +01:00
|
|
|
this.$emit('eventupdate', this.itemtodo)
|
2019-01-27 19:09:48 +01:00
|
|
|
this.updateicon()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateClasses() {
|
2019-01-27 21:49:10 +01:00
|
|
|
// this.classCompleted = 'completed-item'
|
|
|
|
|
this.classCompleted = 'completed-item-popover'
|
2019-01-28 13:31:41 +01:00
|
|
|
this.classDescr = 'flex-item div_descr show'
|
2019-01-28 03:13:04 +01:00
|
|
|
this.classDescrEdit = 'flex-item div_descr_edit'
|
|
|
|
|
if (!this.isTodo())
|
|
|
|
|
this.classDescr += ' titleLista-item'
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
this.classExpiring = 'flex-item data-item'
|
|
|
|
|
this.classExpiringEx = ''
|
|
|
|
|
if (this.itemtodo.completed) {
|
2019-01-30 02:01:04 +01:00
|
|
|
this.percentageProgress = 100
|
2019-01-27 19:09:48 +01:00
|
|
|
this.classCompleted += ' icon_completed'
|
|
|
|
|
this.classDescr += ' status_completed'
|
|
|
|
|
this.classExpiring += ' status_completed'
|
|
|
|
|
this.classExpiringEx += ' status_completed'
|
2019-01-30 02:01:04 +01:00
|
|
|
} else {
|
|
|
|
|
this.percentageProgress = this.itemtodo.progress
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-29 00:48:04 +01:00
|
|
|
this.menuProgress = 'menuProgress'
|
|
|
|
|
this.percProgress = 'percProgress'
|
|
|
|
|
|
|
|
|
|
let mycolcl = ''
|
|
|
|
|
if (this.itemtodo.progress < 33) {
|
|
|
|
|
mycolcl = ' lowperc'
|
|
|
|
|
} else if (this.itemtodo.progress < 66) {
|
|
|
|
|
mycolcl = ' medperc'
|
|
|
|
|
} else {
|
|
|
|
|
mycolcl = ' highperc'
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-29 03:12:18 +01:00
|
|
|
if (this.itemtodo.completed)
|
|
|
|
|
mycolcl = ' percompleted'
|
|
|
|
|
|
2019-01-29 00:48:04 +01:00
|
|
|
this.colProgress = mycolcl
|
|
|
|
|
|
|
|
|
|
this.menuProgress += mycolcl
|
|
|
|
|
this.percProgress += mycolcl
|
|
|
|
|
|
2019-01-28 13:31:41 +01:00
|
|
|
// if (this.inEdit) {
|
|
|
|
|
// this.classDescr += ' hide'
|
|
|
|
|
// this.classDescrEdit += ' show'
|
|
|
|
|
// } else {
|
|
|
|
|
// this.classDescrEdit += ' hide'
|
|
|
|
|
// this.classDescr += ' show'
|
|
|
|
|
// }
|
2019-01-28 03:13:04 +01:00
|
|
|
|
2019-02-01 04:10:31 +01:00
|
|
|
// this.getinputdescr = 'inputdescr' + this.itemtodo._id
|
2019-01-28 03:13:04 +01:00
|
|
|
|
2019-01-28 20:39:40 +01:00
|
|
|
// console.log('classDescrEdit = ', this.classDescrEdit)
|
|
|
|
|
// console.log('classDescr', this.classDescr)
|
2019-01-28 03:13:04 +01:00
|
|
|
|
|
|
|
|
if (this.isTodo())
|
|
|
|
|
this.menuPopupTodo = rescodes.menuPopupTodo[UserStore.state.lang]
|
|
|
|
|
else {
|
|
|
|
|
this.menuPopupTodo = []
|
2019-01-29 03:12:18 +01:00
|
|
|
this.menuPopupTodo.push(rescodes.menuPopupTodo[UserStore.state.lang][rescodes.INDEX_MENU_DELETE])
|
2019-01-28 03:13:04 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
created() {
|
2019-01-28 20:39:40 +01:00
|
|
|
this.precDescr = this.itemtodo.descr
|
2019-01-27 19:09:48 +01:00
|
|
|
this.updateicon()
|
|
|
|
|
|
|
|
|
|
this.updateClasses()
|
|
|
|
|
|
|
|
|
|
this.selectPriority = rescodes.selectPriority[UserStore.state.lang]
|
|
|
|
|
|
2019-01-27 21:49:10 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
getClassRow() {
|
|
|
|
|
return 'row flex-container2 ' + this.classRow
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-28 20:39:40 +01:00
|
|
|
clickRiga() {
|
|
|
|
|
// console.log('CLICK RIGA ************')
|
2019-01-28 03:13:04 +01:00
|
|
|
if (!this.inEdit) {
|
|
|
|
|
this.$emit('deselectAllRows', this.itemtodo, true)
|
|
|
|
|
|
|
|
|
|
if (!this.sel) {
|
|
|
|
|
this.selectRiga()
|
|
|
|
|
} else {
|
|
|
|
|
this.deselectRiga()
|
|
|
|
|
}
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
2019-01-28 03:13:04 +01:00
|
|
|
}
|
2019-01-27 19:09:48 +01:00
|
|
|
|
2019-01-28 03:13:04 +01:00
|
|
|
selectRiga() {
|
2019-01-28 20:39:40 +01:00
|
|
|
// console.log('selectRiga', this.itemtodo.descr)
|
2019-01-28 03:13:04 +01:00
|
|
|
this.sel = true
|
2019-01-27 19:09:48 +01:00
|
|
|
this.classRow = 'rowselected'
|
2019-01-28 03:13:04 +01:00
|
|
|
this.updateClasses()
|
2019-01-28 20:39:40 +01:00
|
|
|
// console.log('FINE selectRiga', this.itemtodo.descr)
|
2019-01-28 03:13:04 +01:00
|
|
|
}
|
2019-01-27 19:09:48 +01:00
|
|
|
|
2019-01-28 03:13:04 +01:00
|
|
|
deselectRiga() {
|
2019-01-28 20:39:40 +01:00
|
|
|
// console.log('DeselectRiga', this.itemtodo.descr)
|
2019-01-28 03:13:04 +01:00
|
|
|
this.sel = false
|
|
|
|
|
this.classRow = ''
|
|
|
|
|
this.inEdit = false
|
2019-01-27 19:09:48 +01:00
|
|
|
this.updateClasses()
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-28 20:39:40 +01:00
|
|
|
deselectAndExitEdit() {
|
2019-01-28 03:13:04 +01:00
|
|
|
this.deselectRiga()
|
|
|
|
|
this.exitEdit()
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
mouseUp() {
|
2019-01-28 03:13:04 +01:00
|
|
|
if (!this.inEdit) {
|
|
|
|
|
if (this.sel) {
|
|
|
|
|
this.selectRiga()
|
|
|
|
|
} else {
|
|
|
|
|
this.deselectRiga()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-27 19:09:48 +01:00
|
|
|
|
2019-01-28 20:39:40 +01:00
|
|
|
editTodo() {
|
|
|
|
|
// console.log('INIZIO - editTodo')
|
2019-01-28 03:13:04 +01:00
|
|
|
this.$emit('click')
|
2019-01-28 20:39:40 +01:00
|
|
|
this.precDescr = this.itemtodo.descr
|
2019-01-28 03:13:04 +01:00
|
|
|
this.inEdit = true
|
|
|
|
|
if (!this.sel)
|
|
|
|
|
this.selectRiga()
|
|
|
|
|
else
|
|
|
|
|
this.updateClasses()
|
|
|
|
|
|
2019-01-28 20:39:40 +01:00
|
|
|
this.faiFocus('inputdescr')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// console.log('FINE - editTodo')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
faiFocus(elem, isparent: boolean = false) {
|
2019-01-28 11:39:02 +01:00
|
|
|
let mythis = this
|
|
|
|
|
setTimeout(() => {
|
2019-01-28 20:39:40 +01:00
|
|
|
let theField = null
|
|
|
|
|
if (isparent)
|
|
|
|
|
theField = <HTMLInputElement>mythis.$parent.$parent.$parent.$parent.$refs[elem]
|
|
|
|
|
else
|
|
|
|
|
theField = <HTMLInputElement>mythis.$refs[elem]
|
2019-01-28 11:39:02 +01:00
|
|
|
theField.focus()
|
2019-01-28 20:39:40 +01:00
|
|
|
// console.log('focus()')
|
2019-01-28 13:31:41 +01:00
|
|
|
}, 100)
|
2019-01-28 03:13:04 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-28 20:39:40 +01:00
|
|
|
exitEdit(singola: boolean = false) {
|
2019-01-28 03:13:04 +01:00
|
|
|
if (this.inEdit) {
|
2019-02-04 04:17:50 +01:00
|
|
|
if (this.precDescr !== this.itemtodo.descr)
|
|
|
|
|
this.updateTodo()
|
2019-01-28 20:39:40 +01:00
|
|
|
// console.log('exitEdit')
|
2019-01-28 03:13:04 +01:00
|
|
|
this.inEdit = false
|
|
|
|
|
this.updateClasses
|
2019-01-28 13:31:41 +01:00
|
|
|
this.$emit('deselectAllRows', this.itemtodo, false, singola)
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
2019-01-28 03:13:04 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
|
2019-01-28 20:39:40 +01:00
|
|
|
keyDownArea(e) {
|
2019-02-04 04:17:50 +01:00
|
|
|
/*
|
|
|
|
|
if ((e.key === 'ArrowUp') && !e.shiftKey) {
|
|
|
|
|
e.key = 'Tab'
|
|
|
|
|
e.shiftKey = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((e.key === 'ArrowDown') && !e.shiftKey) {
|
|
|
|
|
let nextInput = inputs.get(inputs.index(this) + 1)
|
|
|
|
|
if (nextInput) {
|
|
|
|
|
nextInput.focus()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (((e.key === 'Enter') || (e.key === 'Tab')) && !e.shiftKey) {
|
2019-01-28 20:39:40 +01:00
|
|
|
this.updateTodo()
|
2019-02-04 04:17:50 +01:00
|
|
|
|
|
|
|
|
if ((e.key === 'Tab') && !e.shiftKey) {
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
this.deselectRiga()
|
|
|
|
|
this.faiFocus('insertTask', true)
|
|
|
|
|
}
|
2019-01-28 20:39:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// console.log('keyDownArea', e)
|
|
|
|
|
if (e.key === 'Escape') {
|
|
|
|
|
this.deselectRiga()
|
|
|
|
|
this.faiFocus('insertTask', true)
|
|
|
|
|
console.log('LOAD this.precDescr', this.precDescr)
|
|
|
|
|
this.precDescr = this.itemtodo.descr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateTodo() {
|
2019-02-04 04:17:50 +01:00
|
|
|
if (this.itemtodo.descr === this.precDescr)
|
|
|
|
|
return
|
|
|
|
|
|
2019-01-28 20:39:40 +01:00
|
|
|
this.itemtodo.descr = this.precDescr
|
|
|
|
|
console.log('updateTodo', this.precDescr, this.itemtodo.descr)
|
2019-01-28 03:13:04 +01:00
|
|
|
this.watchupdate()
|
|
|
|
|
this.inEdit = false
|
2019-01-28 20:39:40 +01:00
|
|
|
// this.precDescr = this.itemtodo.descr
|
2019-01-28 03:13:04 +01:00
|
|
|
this.updateClasses()
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setCompleted() {
|
2019-01-16 02:26:43 +01:00
|
|
|
// console.log('setCompleted')
|
|
|
|
|
this.itemtodo.completed = !this.itemtodo.completed
|
|
|
|
|
|
|
|
|
|
this.updateicon()
|
|
|
|
|
|
|
|
|
|
this.updatedata()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updatedata() {
|
2019-01-27 19:09:48 +01:00
|
|
|
console.log('calling this.$emit(eventupdate)')
|
2019-01-16 02:26:43 +01:00
|
|
|
this.$emit('eventupdate', this.itemtodo)
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
updateicon() {
|
2019-01-31 13:52:52 +01:00
|
|
|
// console.log('updateicon')
|
2019-01-16 02:26:43 +01:00
|
|
|
if (this.itemtodo.completed)
|
|
|
|
|
this.iconCompleted = 'check_circle'
|
|
|
|
|
else
|
|
|
|
|
this.iconCompleted = 'check_circle_outline'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.itemtodo.priority === rescodes.Todos.PRIORITY_HIGH)
|
|
|
|
|
this.iconPriority = 'expand_less' // expand_less
|
|
|
|
|
else if (this.itemtodo.priority === rescodes.Todos.PRIORITY_NORMAL)
|
|
|
|
|
this.iconPriority = 'remove'
|
|
|
|
|
else if (this.itemtodo.priority === rescodes.Todos.PRIORITY_LOW)
|
|
|
|
|
this.iconPriority = 'expand_more' // expand_more
|
|
|
|
|
|
2019-01-28 03:13:04 +01:00
|
|
|
this.updateClasses()
|
2019-01-16 02:26:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
removeitem(id) {
|
|
|
|
|
this.$emit('deleteitem', id)
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-28 03:13:04 +01:00
|
|
|
enableExpiring() {
|
|
|
|
|
this.itemtodo.enableExpiring = !this.itemtodo.enableExpiring
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
clickMenu(action) {
|
|
|
|
|
console.log('click menu: ', action)
|
2019-01-28 03:13:04 +01:00
|
|
|
if (action === rescodes.MenuAction.DELETE) {
|
2019-01-29 23:13:28 +01:00
|
|
|
this.askConfirmDelete()
|
2019-01-28 03:13:04 +01:00
|
|
|
} else if (action === rescodes.MenuAction.TOGGLE_EXPIRING) {
|
|
|
|
|
this.enableExpiring()
|
2019-01-28 13:31:41 +01:00
|
|
|
} else if (action === rescodes.MenuAction.COMPLETED) {
|
|
|
|
|
this.setCompleted()
|
2019-01-29 03:12:18 +01:00
|
|
|
} else if (action === rescodes.MenuAction.PROGRESS_BAR) {
|
|
|
|
|
this.updatedata()
|
2019-01-28 03:13:04 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
setPriority(newpriority) {
|
2019-01-16 02:26:43 +01:00
|
|
|
|
|
|
|
|
this.itemtodo.priority = newpriority
|
|
|
|
|
|
|
|
|
|
this.updatedata()
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
this.updateicon()
|
|
|
|
|
|
2019-01-16 02:26:43 +01:00
|
|
|
// this.$q.notify('setPriority: ' + elem)
|
|
|
|
|
}
|
2019-01-29 00:48:04 +01:00
|
|
|
|
2019-01-29 23:13:28 +01:00
|
|
|
askConfirmDelete() {
|
|
|
|
|
const deletestr = this.$t('dialog.delete')
|
|
|
|
|
const cancelstr = this.$t('dialog.cancel')
|
|
|
|
|
|
|
|
|
|
askConfirm(this.$q, this.$t('dialog.msg.titledeleteTask'), this.$t('dialog.msg.deleteTask').toString(), deletestr, cancelstr)
|
|
|
|
|
.then(ris => {
|
|
|
|
|
console.log('ris', ris)
|
|
|
|
|
if (ris)
|
2019-02-01 04:10:31 +01:00
|
|
|
this.removeitem(this.itemtodo._id)
|
2019-01-29 23:13:28 +01:00
|
|
|
}).catch(err => {
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|