(function ($) { var fpa = { selector : { form: '#user-admin-permissions', table : '#permissions', row : 'tbody tr', filter : 'td.permission', grouping : 'td.module' }, dom : { table : '', // jquery object for entire permissions table rows : '', // jquery object containing just the rows perm_style : '', // jquery object containing permissions style role_style : '', // jquery object containing roles style section_left: '', section_right: '' }, search:'' }; /** * Kick a function to the Back Of The Line. * * Anything that is botl'd will run after other attach events, like sticky table headers. */ fpa.botl = function (func) { setTimeout(function () { func(); }, 0); }; /** * Changes a string into a safe single css class. */ fpa.classify = function (str) { return str.toLowerCase().replace(/ /ig, '-'); }; /** * Callback for click events on module list. */ fpa.filter_module = function () { var $this = $(this); $('div.fpa-left-section ul li').removeClass('active'); $this.parent().addClass('active'); var current_perm = fpa.dom.filter.val().split('@'); current_perm[1] = $this.attr('title'); fpa.dom.filter.val(current_perm.join('@').replace(/@$/ig, '')); // remove trailing @ as that means no module; clean 'All' filter value fpa.filter('='); }; fpa.filter = function (module_match) { module_match = module_match || '*='; perm = fpa.dom.filter.val(); fpa.botl(function () { if (typeof perm != 'undefined' && ['', '@'].indexOf(perm) == -1) { var perm_copy = fpa.classify(perm).split('@'); var selector = fpa.selector.table + ' ' + fpa.selector.row; var perm_style_code = selector + '[fpa-module]{display:none;}'; if (perm_copy[0]) selector += '[fpa-permission*="' + perm_copy[0] + '"]'; if (perm_copy[1]) selector += '[fpa-module' + module_match + '"' + perm_copy[1] + '"]'; perm_style_code += selector + '{display: table-row;}'; fpa.dom.perm_style[0].innerHTML = perm_style_code; } else { fpa.dom.perm_style[0].innerHTML = ''; } }); }; fpa.prepare = function (context) { fpa.dom.form = $(fpa.selector.form, context); if (fpa.dom.form.length == 0) { return; } fpa.dom.table = fpa.dom.form.find(fpa.selector.table); fpa.dom.section_right = fpa.dom.table.wrap('
').parent(); fpa.dom.module_list = $('