Skip to content

Instantly share code, notes, and snippets.

@aalasolutions-zz
Last active August 16, 2016 07:44
Show Gist options
  • Save aalasolutions-zz/75c48691ba71b9b1def5980176a03316 to your computer and use it in GitHub Desktop.
Save aalasolutions-zz/75c48691ba71b9b1def5980176a03316 to your computer and use it in GitHub Desktop.
Ember Check All Deep
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
acl2: {
"carpet_design":{
"title":"Manage Designs",
"create":{"title":"Create","allowed":true,"depends":["carpet_design.read"]},
"read":{"title":"View","allowed":0},
"update":{"title":"Edit","allowed":0},
"delete":{"title":"Delete","allowed":true},
"columns":{
"design_collection":{"title":"Design Collection","allowed":1},
"status":{"title":"Status","allowed":false}
}
}
},
actions: {
checkAll(index, e){
var acl = this.get('acl2');
var a = acl[index];
this.checkAllSuper(a, e);
},
},
checkAllSuper(o, e){
for (var k in o) {
if (typeof o[k] === "object" && o[k] !== null) {
this.checkAllSuper(o[k], e);
} else {
if (o.hasOwnProperty('allowed')) {
Ember.set(o, 'allowed', e.target.checked);
}
}
}
}
});
import Ember from 'ember';
export function checkAll(params/*, hash*/) {
var r = true;
for (var x = 0; x < params.length; x++) {
if (typeof params[x] === "object" && params[x] !== null) {
for (var y in params[x]) {
if (params[x][y].allowed === false || params[x][y].allowed === 0) {
r = false;
break;
}
}
} else if (params[x] === false || params[x] === 0) {
r = false;
break;
}
}
return r;
}
export default Ember.Helper.helper(checkAll);
{{#each-in acl2 as |i v|}}
<div class="row">
<h1>{{v.title}}</h1>
<label style="display: inline;">{{input
change=(action 'checkAll' i) type="checkbox"
checked=(check-all
v.create.allowed
v.read.allowed
v.update.allowed
v.delete.allowed
v.columns
)}} Check/Uncheck All with Columns</label><br>
<label style="display: inline;">{{input
change=(action 'checkAll' i) type="checkbox"
checked=(check-all
v.create.allowed
v.read.allowed
v.update.allowed
v.delete.allowed
)}} Check/Uncheck All without columns</label>
<div class="row">
<div class="columns medium-20" style="float: left">
<h3>Basic</h3>
<ul>
<li><label> {{input type="checkbox" checked=v.create.allowed}} {{v.create.title}}</label></li>
<li><label> {{input type="checkbox" checked=v.read.allowed}} {{v.read.title}}</label></li>
<li><label> {{input type="checkbox" checked=v.update.allowed}} {{v.update.title}}</label></li>
<li><label> {{input type="checkbox" checked=v.delete.allowed}} {{v.delete.title}}</label></li>
</ul>
</div>
<div class="columns medium-10" style="float: left">
<h3>Extra Columns</h3>
<ul>
{{#each-in v.columns as |k v|}}
<li><label> {{input type="checkbox" checked=v.allowed}} {{v.title}} </label></li>
{{/each-in}}
</ul>
</div>
</div>
</div>
{{/each-in}}
{
"version": "0.10.4",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.7.0",
"ember-data": "2.7.0",
"ember-template-compiler": "2.7.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment