class TimeCardsViewController extends ViewController { constructor(element) { super(element); this.onCurrentUserRoleUpdateBound = this.onCurrentUserRoleUpdate.bind(this); this.onCurrentUserUpdateBound = this.onCurrentUserUpdate.bind(this); } viewDidAppear() { super.viewDidAppear(); //Add a data listener to the current user. //The callback will then add a role data listener which will apply the permissions to the interface when the role is loaded or has changed. TimeCards.dataManager.addDataListener("user", { is_session_user: true }, this.onCurrentUserUpdateBound); } viewDidDisappear() { TimeCards.dataManager.removeDataListener("user_role", this.onCurrentUserRoleUpdateBound); TimeCards.dataManager.removeDataListener("user", this.onCurrentUserUpdateBound); this.addedRoleListener = false; } onCurrentUserUpdate(userId, user) { if (!this.addedRoleListener) { TimeCards.dataManager.addDataListener("user_role", { role_id: Authentication.currentUser.id_role }, this.onCurrentUserRoleUpdateBound); this.addedRoleListener = true; } } onCurrentUserRoleUpdate(roleId, role) { this.updatePermissions(); } updatePermissions() { Authentication.applyPermissionsToInterface(); this.applyPermissions(Authentication.getPermissions()); } applyPermissions(permissions) { } }