You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.6 KiB
82 lines
2.6 KiB
function mruInfo() { |
|
return { |
|
dopen: false, |
|
copen: false, |
|
loading: false, |
|
d: {}, |
|
c: {}, |
|
tagName(type, id) { |
|
if (id == null) |
|
return; |
|
if (type === 'd') { |
|
return this.d.find(i => i.id == id).code; |
|
} else if (type === 'c') { |
|
return this.c.find(i => i.id == id).code; |
|
} |
|
}, |
|
bid: Alpine.store('mru').objectid, |
|
did: null, |
|
cid: [], |
|
date: {}, |
|
search() { |
|
generateRequest(this.did, this.cid, this.date.from, this.date.to, this.bid); |
|
}, |
|
selectEntry(element, entry) { |
|
console.debug(element.text.substr(0, element.text.indexOf(' '))); |
|
if (element.id.split('-')[1] === 'desc') { |
|
// highlight |
|
element.parentElement.querySelectorAll('a').forEach(el => el.classList.remove('is-active')); |
|
element.classList.add('is-active'); |
|
// update variables; |
|
this.cid = []; |
|
this.did = entry; |
|
this.dopen = false; |
|
} else if (element.id.split('-')[1] === 'crit') { |
|
// toggle |
|
element.classList.toggle('is-active'); |
|
// update variables; |
|
this.cid.indexOf(entry) === -1 ? this.cid.push(entry) : this.cid = this.cid.filter(function(id) { return id !== entry}); |
|
this.copen = false; |
|
// add tag |
|
} |
|
}, |
|
getDropdownData(dropdown) { |
|
Alpine.store('loading', true); |
|
let url = BASE_URL; |
|
switch(dropdown) { |
|
case 'd': |
|
url += '/interface/dropdowns/descriptors?body_id=' + this.bid; |
|
break; |
|
case 'c': |
|
url += '/interface/dropdowns/criterias?desc_id=' + this.did; |
|
break; |
|
} |
|
fetch(url) |
|
.then(res => res.json()) |
|
.then(data => { |
|
Alpine.store('loading', false); |
|
eval('this.' + dropdown + '=data'); |
|
}); |
|
}, |
|
loadCal() { |
|
const calendars = bulmaCalendar.attach('[type=date]', {dateFormat: 'dd/MM/yyyy', isRange: true}); |
|
// Loop on each calendar initialized |
|
calendars.forEach(calendar => { |
|
calendar.on('save', data => { |
|
this.date = { |
|
from: calendar.startDate.toLocaleDateString(), |
|
to: calendar.endDate.toLocaleDateString() |
|
} |
|
}); |
|
}); |
|
}, |
|
populateFeatureGrid(grid) { |
|
const features = Alpine.store('mru'); |
|
const featureCols = Object.getOwnPropertyNames(Alpine.store('mru')).filter(name => aliasMap.has(name)); |
|
const featureVals = featureCols.map(col => {return {feature: aliasMap.get(col), value: features[col]}}); |
|
new gridjs.Grid({ |
|
data: featureVals |
|
}).render(grid); |
|
} |
|
}; |
|
}
|
|
|