/* Authors: * Endi Sukma Dewata * * Copyright (C) 2010 Red Hat * see file 'COPYING' for use and warranty information * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ define([ './metadata', './ipa', './jquery', './navigation', './phases', './reg', './rpc', './text', './details', './search', './association', './entity', './hbac'], function(metadata_provider, IPA, $, navigation, phases, reg, rpc, text) { var exp = {}; var make_spec = function() { return { name: 'hbactest', facet_groups: [ 'default' ], facets: [ { $factory: IPA.hbac.test_select_facet, name: 'user', label: '@i18n:objects.hbacrule.user', managed_entity: 'user', disable_breadcrumb: true, facet_group: 'default', row_disabled_attribute: 'nsaccountlock', columns: [ 'uid', 'givenname', 'sn', { name: 'nsaccountlock', label: '@i18n:status.label', formatter: { $type: 'boolean_status', invert_value: true } } ] }, { $factory: IPA.hbac.test_select_facet, name: 'targethost', label: '@i18n:objects.hbacrule.host', managed_entity: 'host', disable_breadcrumb: true, facet_group: 'default', columns: [ 'fqdn', 'description', { name: 'has_keytab', label: '@i18n:objects.host.enrolled', formatter: 'boolean' } ] }, { $factory: IPA.hbac.test_select_facet, name: 'service', label: '@i18n:objects.hbacrule.service', managed_entity: 'hbacsvc', disable_breadcrumb: true, facet_group: 'default', columns: [ 'cn', 'description' ] }, { $factory: IPA.hbac.test_rules_facet, name: 'rules', label: '@i18n:objects.hbactest.rules', managed_entity: 'hbacrule', disable_breadcrumb: true, facet_group: 'default', row_enabled_attribute: 'ipaenabledflag', columns: [ 'cn', { name: 'ipaenabledflag', label: '@i18n:status.label', formatter: 'boolean_status' }, 'description' ] }, { $factory: IPA.hbac.test_run_facet, name: 'run_test', label: '@i18n:objects.hbactest.run_test', managed_entity: 'hbacrule', disable_breadcrumb: true, facet_group: 'default', row_enabled_attribute: 'ipaenabledflag', columns: [ 'cn', { name: 'matched', label: '@i18n:objects.hbactest.matched', formatter: 'boolean' }, { name: 'ipaenabledflag', label: '@i18n:status.label', formatter: 'boolean_status' }, 'description' ] } ] };}; IPA.hbac.test_entity = function(spec) { var that = IPA.entity(spec); that.label = text.get('@i18n:objects.hbactest.label'); that.get_default_metadata = function() { return metadata_provider.get('@mc:'+that.name); }; return that; }; IPA.hbac.test_facet = function(spec) { spec = spec || {}; var that = IPA.table_facet(spec); var init = function() { that.managed_entity = IPA.get_entity(that.managed_entity); var columns = that.columns.values; for (var i=0; i', { 'class': 'hbac-test-navigation-buttons' }).appendTo(container); var facet_group = that.entity.get_facet_group('default'); var index = facet_group.get_facet_index(that.name); if (index > 0) { that.prev_button = IPA.button({ name: 'prev', label: '@i18n:widget.prev', icon: 'fa-chevron-left', click: that.prev }).appendTo(buttons); buttons.append(' '); } that.next_button = IPA.button({ name: 'next', label: '@i18n:widget.next', icon: 'fa-chevron-right', click: that.next }).appendTo(buttons); }; that.prev = function() { var facet_group = that.entity.get_facet_group('default'); var index = facet_group.get_facet_index(that.name); if (index <= 0) return; var facet = facet_group.get_facet_by_index(index - 1); navigation.show(facet); }; that.next = function() { var facet_group = that.entity.get_facet_group('default'); var index = facet_group.get_facet_index(that.name); if (index >= facet_group.get_facet_count() - 1) return; var facet = facet_group.get_facet_by_index(index + 1); navigation.show(facet); }; that.get_search_command_name = function() { return that.managed_entity.name + '_find' + (that.pagination ? '_pkeys' : ''); }; that.refresh = function() { var filter = that.state.filter; var command = rpc.command({ name: that.get_search_command_name(), entity: that.managed_entity.name, method: 'find', args: [filter] }); if (that.pagination) { command.set_option('pkey_only', true); command.set_option('sizelimit', 0); } command.on_success = function(data, text_status, xhr) { that.load(data); that.show_content(); }; command.on_error = function(xhr, text_status, error_thrown) { that.report_error(error_thrown); }; command.execute(); }; init(); return that; }; IPA.hbac.test_select_facet = function(spec) { var that = IPA.hbac.test_facet(spec); var init = function() { that.table.multivalued = false; that.table.set_values = function(values) { if (values && values.length && values[0] === '__external__') { if (that.external_radio) that.external_radio.prop('checked', true); } else { that.table.table_set_values(values); } }; }; that.create_content = function(container) { var header = $('
', { 'class': 'hbac-test-header' }).appendTo(container); var title = $('', { text: that.label, 'class': 'hbac-test-title' }).appendTo(header); var filter_container = $('
', { 'class': 'search-filter' }).appendTo(header); that.filter = $('', { type: 'text', 'class': 'form-control', name: 'filter' }).appendTo(filter_container); that.filter.keypress(function(e) { /* if the key pressed is the enter key */ if (e.which == 13) { that.find(); } }); that.find_button = IPA.action_button({ name: 'find', icon: 'fa-search', click: function() { that.find(); return false; } }).appendTo(filter_container); var content = $('
', { 'class': 'hbac-test-content' }).appendTo(container); that.table.create(content); var id = that.entity.name+'-'+that.name+'-external'; var pkey_name = that.managed_entity.metadata.primary_key; var tr = $('').appendTo(that.table.tfoot); var td = $('', { name: 'external', colspan: that.columns.length + 1 }).appendTo(tr); that.external_radio = $('', { id: id, type: 'radio', name: pkey_name, value: '__external__', click: function() { that.selected_values = [ that.external_radio.val() ]; } }).appendTo(td); var message = text.get('@i18n:objects.hbactest.specify_external'); message = message.replace('${entity}', that.managed_entity.metadata.label_singular); $('