(function(fs){ fs('extend', 'hasPermission', function(fs,permissionId, callback){ fs('get','permission/has/'+permissionId, callback); }); function permissionCheckbox(fs,permissionId,element){ fs('ready', function(){ if(typeof element == "string"){ element = document.getElementById(element); }else if(typeof element == "object"){ //Do nothing }else{ throw new Error('permissionCheckbox called with '+(typeof element)+' only domElement or string Id is supported'); } if(element && element.type && element.type =="checkbox"){ var that = this; fs('hasPermission', permissionId, function(result){ if(result.status == "success"){ element.checked = result.result; element.addEventListener("change",function(e){ if(this.checked){ fs('get','permission/set/'+permissionId); }else{ fs('get','permission/remove/'+permissionId); } }) } }); }else{ throw new Error('permissionCheckbox called on non checkbox element'); } }) }; fs('extend', 'permissionCheckbox', permissionCheckbox); fs('addDataTag', 'permission'); })(window[window['FS_CORE_NAME']])