My global issue is create an ACL object in controller that provide list of all actions, just a part of them available for use. Accessible of actions depends on controllers properties. I like to make an computed property from each of actions
to controller's property. How to create computed property from controller's nested object's property to controller's property? I did create snippet to illustrate my question.
var App = window.App = Ember.Application.create();
var AccessibleMixin = Em.Mixin.create({
list: [
Ember.Object.createWithMixins({
name: "Permitted to write",
isAccessible: Ember.computed.alias('isWritable')
}),
Ember.Object.createWithMixins({
name: "Permitted to read",
isAccessible: Ember.computed.alias('isReadable')
})
]
});
App.IndexController = Ember.ObjectController.extend(AccessibleMixin, {
model: {
isWritable: true,
isReadable: false
},
init: function() {
var first = this.get('list.firstObject');
console.log(first);
},
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<link rel="stylesheet" href="//wheely.github.io/ember-dialog/css/ember.dialog.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"></script>
<script src="//builds.emberjs.com/tags/v1.8.1/ember.prod.js"></script>
</head>
<body>
<script type="text/x-handlebars" data-template-name="index">
{{#each list}}
<div>{{name}}: {{#if isAccessible}}YES{{else}}NO{{/if}}</div>
{{/each}}
</script>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire