// -- The main (so far only) Vue instance --
var app = new Vue({
// In the html file, need to enclose in an element with the class specified
// here, if we want Vue to know where to put it.
el: '.app12',
data: {
appTitle: 'We can edit an existing tiddler',
tiddlers: [],
currentCreated: undefined,
emptyTiddler: {
text: '',
tags: []
},
currentTiddler: {
text: 'Texty text text. Semper ubi sub ubi',
tags: ['onetag', 'twotag', 'threetag', 'four']
},
editFlag: false
},
template: `
Tiddler text:
Clear
Submit
`,
methods: {
updateTiddlerText(ev) {
this.currentTiddler.text = ev.target.innerText
},
addNewTag(ev) {
this.currentTiddler.tags.push(ev.target.textContent)
this.currentTiddler.tags = [...new Set(this.currentTiddler.tags)]
ev.target.textContent = ''
},
removeTag(tag) {
this.currentTiddler.tags.splice(this.currentTiddler.tags.indexOf(tag), 1)
},
selectTiddler(tiddler) {
this.currentTiddler = JSON.parse(JSON.stringify(tiddler))
// this.currentIdx = this.tiddlers.indexOf(tiddler)
this.currentCreated = tiddler.created
this.editFlag = true
console.log("selecting tiddler created " + this.currentCreated)
},
submitTiddler(tiddler) {
if (this.editFlag == true) {
this.updateTiddler()
} else {
this.addTiddler()
}
this.resetTiddler()
},
isTheTiddler(tiddler) {
return tiddler.created === this.currentCreated
},
updateTiddler() {
console.log("updateTiddler:")
console.log(" currentCreated was " + this.currentCreated)
var tiddler = this.tiddlers.find(this.isTheTiddler)
var idx = this.tiddlers.indexOf(tiddler)
console.log(" replacing tiddler created at " + tiddler.created)
this.tiddlers.splice(idx, 1, this.currentTiddler)
},
addTiddler() {
this.currentTiddler.created = moment().utc().format('YYYYMMDDHHmmssSSS') // In TW, times are stored in UTC
this.currentTiddler.utcOffset = moment().utcOffset()
this.tiddlers.push(this.currentTiddler)
},
resetTiddler() {
this.currentTiddler = JSON.parse(JSON.stringify(this.emptyTiddler))
this.currentCreated = undefined
this.editFlag = false
},
localFromUTC(tiddler) {
var timeInt = moment.utc(tiddler.created, 'YYYYMMDDHHmmssSSS')
var localInt = timeInt.add(tiddler.utcOffset, 'minute')
var localTime = localInt.format('YYYY-MM-DD, hh:mm a')
return localTime
}
}
})