Last active
August 16, 2016 07:44
-
-
Save aalasolutions-zz/75c48691ba71b9b1def5980176a03316 to your computer and use it in GitHub Desktop.
Ember Check All Deep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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