src/helpers/navigation/PlatformMenu.js
import PlatformMenuModel from '../../models/navigation/PlatformMenu';
import PlatformMenuService from '../../services/PlatformMenuService';
import Helper from '../Helper';
import { aggregate } from '../../utilities/ClassUtility';
/**
* Helper class representing an platformMenu.
*
* @extends {PlatformMenuModel}
* @extends {Helper}
*
* @example
* import { PlatformMenu, platformMenuService } from 'clinical6';
*
* // Typically use PlatformMenuService.get()
* platformMenuService.get().then(platformMenus => console.log(platformMenus));
*
* const platformMenu = new PlatformMenu({
* "data": {
* "id": "319",
* "type": "menus",
* "attributes": {
* "icon": "icon-star",
* "title": "vitae",
* "position": 1,
* "enabled": true,
* "url": "#",
* "access_class": null,
* },
* "relationships": {
* "parent": {
* "data": null
* },
* "children": {
* "data": []
* },
* "authorizable": {
"data": null
}
* }
* }
* });
*/
class PlatformMenu extends aggregate(PlatformMenuModel, Helper) {
/**
* Constructor for helper class representing an PlatformMenu
*
* @param {Object} json - json api response from server
*/
constructor(json = {}) {
super(json);
this.deserializeRelationshipStubs(json);
this.syncRelationships(json);
}
/** @type {String} - The type */
static get type() {
return 'menus';
}
/** @type {PlatformMenu} */
get parent() {
return this._relationships.parent;
}
/** @type {PlatformMenu} */
set parent(parent) {
/** @type {PlatformMenu} */
this._relationships.parent = parent;
}
/** @type {PlatformMenu[]} */
get children() {
return this._relationships.children;
}
/** @type {PlatformMenu[]} */
set children(children) {
/** @type {PlatformMenu[]} */
this._relationships.children = children;
}
/** @type {Section | Flow | Content} */
get authorizable() {
return this._relationships.authorizable;
}
/** @type {Section | Flow | Content} */
set authorizable(authorizable) {
/** @type {Section | Flow | Content} */
this._relationships.authorizable = authorizable;
}
/**
* Saves a platformMenu (insert if id doesn't exist, update if it does)
* @return {Promise} - Returns a promise via ajax call.
*
* @example
* import { PlatformMenu, Client } from 'clinical6';
*
* // Removes platformMenu from server and local storage
* const platformMenu = new PlatformMenu({
* "data": {
* "id": "319",
* "type": "menus",
* "attributes": {
* "icon": "icon-star",
* "title": "vitae",
* "position": 1,
* "enabled": true,
* "url": "#"
* },
* "relationships": {
* "parent": {
* "data": null
* },
* "children": {
* "data": []
* },
* "authorizable": {
* "data": null
* }
* }
* }
* });
* platformMenu.delete();
*
* // No longer in storage
* Client.instance.storageUtility.has('platformMenus', { id: 1 });
*/
delete() {
return (new PlatformMenuService()).delete(this);
}
/**
* Saves a platformMenu (insert if id doesn't exist, update if it does)
* @return {Promise<PlatformMenu>} - Returns a promise via ajax call.
*
* @example
* import { PlatformMenu, platformMenuService } from 'clinical6';
*
* // Insert is different from other inserts. Uses mobile application key
* const platformMenu = new PlatformMenu({
* "title": "My Favorite Menu"
* });
* platformMenu.save();
*
* // After you have the authtoken and then you've logged in
*
* // Updates existing platformMenu (has existing id)
* platformMenuService.get().then(platformMenus => platformMenus[0].save());
*/
save() {
return (this.id)
? (new PlatformMenuService()).update(this)
: (new PlatformMenuService()).insert(this);
}
}
export default PlatformMenu;