Hey,
I have been trying to get todays date written to an object using JavaScript in my polymer screens. I have found some information on this in the tutorial from Cuba Studio here: CUBA Platform. Polymer UI Tutorial
The issue is that I can’t seem to get this working properly. What I want is to use a paper card, and when it is pressed it will change the value of laatstUitgevoerd (means last executed) to today’s date. The part where I call the method on press of the paper card works properly, but I can’t get seem to get the correct JavaScript code for changing the value of laatstUitgevoerd into today’s date.
In the tutorial it states that I should use: this.set('user.name', 'value');
In my case this would be: this.set('onderhoudsregel.laatstuitgevoerd', 'today');
But this will not work, I defined the variable today before as var today = new Date();
in order to get today’s date.
I have also tried different syntax for the laatstUitgevoerd and today in JavaScript like [[item.laatstuitgevoerd]], item.onderhoudsregel.laatstuitgevoerd, ‘[[laatstuitgevoerd]]’ and pretty much any combination of these.
What am I doing wrong here? Or is the Date datatype from JavaScript not compatible with the Date datatype from Cuba?
The total code for this screen looks like this (to give you all information)
<dom-module id="machineonderhoud-onderhoudsregel-cards">
<template>
<style include="cuba-styles"></style>
<style include="shared-styles"></style>
<style>
:host {
display: block;
}
paper-card {
cursor: pointer;
}
</style>
<cuba-entities id="data"
entity-name="machineonderhoud$Onderhoudsregel"
data="{{entities}}"
view="onderhoudsregel-view-browse"
loading="{{dataLoading}}"
limit="10"
provide-count="true"
count="{{entitiesCount}}"
auto="[[active]]">
</cuba-entities>
<iron-selector id="selector" on-iron-activate="_handleSelectionChange">
<template id="entitiesList" is="dom-repeat" items="{{entities}}" filter="isNeeded" observe="type item.prioriteit">
<paper-card heading="[[item.taak]] op [[item.machine.code]]" on-tap="regelAfronden" class="page-widget">
<div class="card-content">
<b>Laatst uitgevoerd</b>: [[item.laatstuitgevoerd]]<br>
<br>
<b>Prioriteit</b>: [[item.prioriteit]]<br>
<br>
<b>ID</b>: [[item._instanceName]]<br>
</div>
</paper-card>
</template>
</iron-selector>
<vaadin-button on-tap="_loadMore" class="load-more" hidden$="[[!moreDataAvailable]]">
[[msg('Load more')]]
</vaadin-button>
</template>
<script>
{
/**
* @extends {Polymer.Element}
* @appliesMixin CubaLocalizeBehavior
* @appliesMixin CubaEntityListViewBehavior
*/
class MachineonderhoudOnderhoudsregelCards extends Polymer.mixinBehaviors([CubaLocalizeBehavior, CubaEntityListViewBehavior], Polymer.Element) {
static get is() { return 'machineonderhoud-onderhoudsregel-cards' }
isNeeded(item) {
return item.prioriteit > '0' && item.instructieNodig == false;
}
regelAfronden() {
var today = new Date();
if (confirm("Wil je de regel afronden?")) {
this.set('onderhoudsregel.laatstuitgevoerd', 'today');
}
else {
}
}
}
customElements.define(MachineonderhoudOnderhoudsregelCards.is, MachineonderhoudOnderhoudsregelCards);
}
</script>
</dom-module>