Hi Devs!
I'm building my own stream note type so that I can have custom notes on the Stream of my entities. I've created a note record of type mmxRelated and added some data into the note.data field that I want to parse and display on the front end. I've adapted it from the code in the CreateRelated note type.
It basically works except that I don't have access to the contents of the note.data field in my view file so I can't do the parsing. I'm trying to get this data in my second code block below - in the init function (almost verbatim from the CreateRelated view).
The Update and Create note types get the data in the same way and it is available to them (eg in the setup function of view file at client\src\views\stream\notes\update.js), but it is not available in either CreateRelated or my custom view. I think it must be to do with how the PHP is fetching the record from the DB but I can't find where it's happening.
Can anyone please help with how can I give my view access to this data field?
Here is my code:
In \custom\Espo\Custom\Resources\metadata\clientDefs\ Note.json I've created an entry to tell espo where to find the view file:
I have created that view file at client\custom\src\views\stream\notes\mmx-related.js
and the custom template at client\custom\res\templates\stream\notes\mmx-related.tpl:
I have extended the Global.json file to create the text template for the content at custom\Espo\Custom\Resources\i18n\en_US\Global.jso n:
Cheers,
Clare
I'm building my own stream note type so that I can have custom notes on the Stream of my entities. I've created a note record of type mmxRelated and added some data into the note.data field that I want to parse and display on the front end. I've adapted it from the code in the CreateRelated note type.
It basically works except that I don't have access to the contents of the note.data field in my view file so I can't do the parsing. I'm trying to get this data in my second code block below - in the init function (almost verbatim from the CreateRelated view).
The Update and Create note types get the data in the same way and it is available to them (eg in the setup function of view file at client\src\views\stream\notes\update.js), but it is not available in either CreateRelated or my custom view. I think it must be to do with how the PHP is fetching the record from the DB but I can't find where it's happening.
Can anyone please help with how can I give my view access to this data field?
Here is my code:
In \custom\Espo\Custom\Resources\metadata\clientDefs\ Note.json I've created an entry to tell espo where to find the view file:
Code:
{ "itemViews": { "MmxRelated": "custom:views/stream/notes/mmx-related" } }
Code:
define('custom:views/stream/notes/mmx-related', ['views/stream/note'], function (Dep) { return Dep.extend({ template: 'custom:stream/notes/mmx-related', messageName: 'mmxRelated', // messageName: 'createRelated', data: function () { return _.extend({ relatedTypeString: this.translateEntityType(this.entityType), iconHtml: this.getIconHtml(this.entityType, this.entityId), }, Dep.prototype.data.call(this)); }, init: function () { console.log('in my mmmx one'); if (this.getUser().isAdmin()) { this.isRemovable = true; } Dep.prototype.init.call(this); }, setup: function () { let data = this.model.get('data'); console.log('my mmx one setup function - data = ',data); // this is null - how do it get it?? // do stuff here to construct the message for the note }, }); });
and the custom template at client\custom\res\templates\stream\notes\mmx-related.tpl:
Code:
{{#unless noEdit}} <div class="pull-right right-container cell-buttons"> {{{right}}} </div> {{/unless}} <div class="stream-head-container"> <div class="pull-left"> {{{avatar}}} </div> <div class="stream-head-text-container"> {{#if iconHtml}}{{{iconHtml}}}{{/if}} <span class="text-muted message">{{{message}}} this is my mmx one</span> </div> </div> <div class="stream-date-container"> <a class="text-muted small" href="#Note/view/{{model.id}}">{{{createdAt}}}</a> </div>
Code:
{ "streamMessages": { "mmxRelated": "{user} my mmx related {entityType} {entity}", "mmxRelatedThis": "{user} my mmx related {entityType} {entity} this" } }
Clare
Comment