Permalink
Browse files

system groups - ui - allow user to change env/view for systems in a g…

…roup

This commit contains changes to allow a user to navigate to
a system group and then 'edit' the environment/content view
for all systems in that group.

As part of the change, created env_content_view_selector.js, which
we may be able to leverage in other places in the UI where similar
behavior is used (e.g. activation key & system 'create').
  • Loading branch information...
1 parent fbbae0c commit ac176ca570a14fdf6593d8637f0be948d6859a6a @bbuckingham bbuckingham committed Apr 3, 2013
@@ -14,7 +14,8 @@ class SystemGroupsController < ApplicationController
before_filter :panel_options, :only=>[:index, :items, :create, :copy]
before_filter :find_group, :only=>[:edit, :update, :destroy, :destroy_systems, :systems,
- :show, :add_systems, :remove_systems, :copy]
+ :show, :add_systems, :remove_systems, :edit_systems,
+ :update_systems, :copy]
before_filter :authorize
def rules
@@ -24,6 +25,7 @@ def rules
create_perm = lambda{SystemGroup.creatable?(current_organization)}
destroy_perm = lambda{@group.deletable?}
destroy_systems_perm = lambda{@group.systems_deletable?}
+ edit_systems_perm = lambda{@group.systems_editable?}
{
:index=>any_readable,
:items=>any_readable,
@@ -39,6 +41,8 @@ def rules
:auto_complete=>any_readable,
:add_systems=> edit_perm,
:remove_systems=>edit_perm,
+ :edit_systems=>edit_systems_perm,
+ :update_systems=>edit_systems_perm,
:validate_name=>any_readable
}
end
@@ -48,7 +52,8 @@ def param_rules
:create => {:system_group => [:name, :description, :max_systems]},
:update => {:system_group => [:name, :description, :max_systems]},
:add_systems => [:system_ids, :id],
- :remove_systems => [:system_ids, :id]
+ :remove_systems => [:system_ids, :id],
+ :update_systems => {:system_group => [:environment_id, :content_view_id]}
}
end
@@ -205,6 +210,29 @@ def remove_systems
render :text=>''
end
+ def edit_systems
+ accessible_envs = current_organization.environments
+ setup_environment_selector(current_organization, accessible_envs)
+ @organization = current_organization
+ @environment = first_env_in_path(accessible_envs)
+
+ render :partial => "edit_systems",
+ :locals => {:filter => @group, :accessible_envs => accessible_envs}
+ end
+
+ def update_systems
+ unless params[:system_group].blank?
+ @group.systems.each do|system|
+ system.update_attributes!(params[:system_group])
+ end
+ end
+
+ notify.success _("Successfully updated environment and content view for all systems in group %{group}") %
+ {:group => @group.name}
+
+ render :text=>''
+ end
+
def auto_complete
query = "name_autocomplete:#{params[:term]}"
org = current_organization
@@ -0,0 +1,32 @@
+= content_for :title do
+ = _("Edit Systems' Environment and Content View")
+
+= content_for :subcontent do
+
+ = form_tag update_systems_system_group_path(@group.id), :id => 'update_form',
+ :method => :put, :class => 'env_content_view_selector' do
+
+ = hidden_field_tag 'system_group[environment_id]', @environment.id, :id => :environment_id
+
+ %fieldset
+ .grid_2.ra
+ %label #{_('Choose Environment:')}
+
+ .grid_10.la
+ = environment_selector(:path_widget_class => "grid_7",
+ :path_entries_class => "grid_7", :library_clickable => false,
+ :accessible_envs => accessible_envs,
+ :url_content_views_proc => url_content_views_proc)
+
+ %fieldset
+ .grid_2.ra
+ %label #{_('Content View:')}
+
+ .grid_10.la
+ = select_tag 'system_group[content_view_id]',
+ options_for_select(content_view_select_labels(@organization, @environment), no_content_view),
+ :id => :content_view_id
+
+ = submit_tag _('Save'), :class => 'submit dialogbutton', :id=>"save_button"
+
+= render :template => "layouts/tupane_layout"
@@ -31,9 +31,14 @@
%input#add_system_input_id{:type=>'hidden'}
%input{:type=>'text', :id=>'add_system_input', :size=>'30', :placeholder => help_text, :title => help_text, :tabindex => auto_tab_index}
%input#add_system.button{:style => 'padding-left: 10px;', :value=>_("Add"), :type=>:button, :tabindex => auto_tab_index}
+
%table#systems_table.filter_table.list
%thead.header
%tr
+ %td{:colspan => 4}
+ %a.subpanel_element{"data-url" => edit_systems_system_group_path(@group.id)}
+ = _("Edit Details for All Systems")
+ %tr
%th
= _("Name")
%th
@@ -6,7 +6,8 @@
"delete_system_group_confirm": '#{escape_javascript(_('Are you sure you want to delete the system group?'))}',
"delete_systems_confirm": '#{escape_javascript(_('Do you also want to delete the systems in the system group?'))}',
"delete_systems_warning": '#{escape_javascript(_('This will completely remove those systems.'))}',
- "delete_system_group_continue": '#{escape_javascript(_('No, only delete the system group.'))}'
+ "delete_system_group_continue": '#{escape_javascript(_('No, only delete the system group.'))}',
+ "change_systems_confirm": '#{escape_javascript(_('Are you sure you want to change all systems in the group?'))}'
});
.grid_16
View
@@ -133,6 +133,7 @@ javascripts:
- public/javascripts/packages.js
- public/javascripts/package_actions.js
- public/javascripts/auto_complete.js
+ - public/javascripts/env_content_view_selector.js
system_subscriptions:
- public/javascripts/system_subscriptions.js
system_packages:
View
@@ -48,6 +48,8 @@
post :add_systems
post :remove_systems
delete :destroy_systems
+ get :edit_systems
+ put :update_systems
end
resources :events, :controller => "system_group_events", :only => [:index, :show] do
collection do
@@ -0,0 +1,180 @@
+/**
+ Copyright 2013 Red Hat, Inc.
+
+ This software is licensed to you under the GNU General Public
+ License as published by the Free Software Foundation; either version
+ 2 of the License (GPLv2) or (at your option) any later version.
+ There is NO WARRANTY for this software, express or implied,
+ including the implied warranties of MERCHANTABILITY,
+ NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
+ have received a copy of GPLv2 along with this software; if not, see
+ http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ */
+KT.env_content_view_selector = (function(){
+ var settings,
+
+ initialize = function(params) {
+ /**
+ * params:
+ * override_save // (default: true) if false, perform save on form submit
+ * override_cancel // (default: true) if false, perform cancel when cancel button clicked
+ * cv_change_cb() // callback function to perform custom logic after user selects content view
+ * save_success_cb() // callback function to perform custom logic after a successful save
+ * save_error_cb // callback function to perform custom logic after an unsuccessful save
+ * cancel_success_cb() // callback function to perform custom logic after a successful cancel
+ * cancel_success_cb() // callback function to perform custom logic after an unsuccessful cancel
+ */
+ var pane = $(".env_content_view_selector");
+ if (pane.length === 0){
+ return;
+ }
+
+ settings = params;
+ disable_buttons();
+
+ //Set the callback on the environment selector
+ env_select.click_callback = function(env_id) {
+ save_selected_environment(env_id);
+ get_content_views();
+ };
+
+ $('#content_view_id').unbind('change');
+ $('#content_view_id').change(function() {
+ highlight_content_views(false);
+ enable_buttons();
+
+ if (settings.cv_change_cb) {
+ settings.cv_change_cb();
+ }
+ });
+
+ if (settings.override_save === false) {
+ $('#update_form').unbind('submit');
+ $('#update_form').submit(function(e) {
+ e.preventDefault();
+ save($(this));
+ });
+ }
+
+ if (settings.override_cancel === true) {
+ $('#cancel_button').unbind('click');
+ $('#cancel_button').click(function(e) {
+ e.preventDefault();
+ cancel($(this));
+ });
+ }
+ },
+ disable_buttons = function() {
+ $('#cancel_button').attr("disabled","disabled");
+ $('input[id^=save_button]').attr("disabled","disabled");
+ },
+ enable_buttons = function() {
+ $('#cancel_key').removeAttr('disabled');
+ $('input[id^=save_button]').removeAttr('disabled');
+ },
+ save = function(data) {
+ disable_buttons();
+
+ data.ajaxSubmit({
+ success: function(data) {
+ highlight_content_views(false);
+ enable_buttons();
+ if (settings.save_success_cb) {
+ settings.save_success_cb();
+ }
+ }, error: function(e) {
+ highlight_content_views(false);
+ enable_buttons();
+ if (settings.save_error_cb) {
+ settings.save_error_cb();
+ }
+ }});
+ },
+ cancel = function(data) {
+ var url = $('#cancel_button').attr('data-url');
+ if (url !== undefined) {
+ disable_buttons();
+
+ $.ajax({
+ type: "GET",
+ url: url,
+ cache: false,
+ success: function(response) {
+ $('.panel-content').html(response);
+ if (settings.cancel_success_cb) {
+ settings.cancel_success_cb();
+ }
+ },
+ error: function(data) {
+ initialize_edit();
+ if (settings.cancel_error_cb) {
+ settings.cancel_error_cb();
+ }
+ }
+ });
+ } else {
+ if (settings.cancel_success_cb) {
+ settings.cancel_success_cb();
+ }
+ }
+ },
+ save_selected_environment = function(env_id) {
+ // save the id of the env selected
+ $("#environment_id").attr('value', env_id);
+ },
+ get_content_views = function() {
+ // this function will retrieve the views associated with a given environment and
+ // update the views box with the results
+ var url = $('.path_link.active').attr('data-content_views_url');
+ if (url !== undefined) {
+ disable_buttons();
+ $.ajax({
+ type: "GET",
+ url: url,
+ cache: false,
+ success: function(response) {
+ // update the appropriate content on the page
+ var options = '';
+ var opt_template = KT.utils.template("<option value='<%= key %>'><%= text %></option>");
+
+ // create an html option list using the response
+ options += opt_template({key: "", text: i18n.no_content_view});
+ $.each(response, function(key, item) {
+ options += opt_template({key: item.id, text: item.name});
+ });
+
+ $("#content_view_id").html(options);
+
+ if (response.length > 0) {
+ highlight_content_views(true);
+ }
+ enable_buttons();
+ },
+ error: function(data) {
+ enable_buttons();
+ }
+ });
+ }
+ },
+ highlight_content_views = function(add_highlight) {
+ highlight_input("#content_view_id", add_highlight);
+ },
+ highlight_input = function(element_id, add_highlight) {
+ var select_input = $(element_id);
+ if (add_highlight) {
+ if( !select_input.next('span').hasClass('highlight_input_text')) {
+ select_input.addClass('highlight_input');
+ select_input.after('<span class ="highlight_input_text">' + i18n.select_content_view + '</span>');
+ }
+ } else {
+ select_input.removeClass('highlight_input');
+ $('.highlight_input_text').remove();
+ }
+ };
+
+ return {
+ initialize: initialize,
+ save: save,
+ cancel: cancel
+ }
+})();
@@ -21,9 +21,10 @@ $(document).ready(function() {
KT.menu.hoverMenu(item, { top : '75px' });
});
- KT.system_groups.init();
+ KT.system_groups.initialize();
KT.system_groups.new_setup();
KT.system_groups.details_setup();
+ KT.system_groups.env_content_view_setup();
});
});
@@ -152,7 +153,7 @@ KT.system_groups = (function(){
}
});
},
- init = function(){
+ initialize = function(){
$('.pane_action.remove').bind('click', prompt_to_destroy_group);
},
prompt_to_destroy_group = function(e) {
@@ -359,15 +360,44 @@ KT.system_groups = (function(){
var url = add ? KT.routes.add_systems_system_group_path(grp_id) :
KT.routes.remove_systems_system_group_path(grp_id);
$.post(url, {'system_ids':sys_ids}, cb).error(error_cb);
+ },
+ env_content_view_setup = function(){
+ var pane = $(".env_content_view_selector");
+ if (pane.length === 0){
+ return;
+ }
+
+ KT.env_content_view_selector.initialize(
+ {
+ save_success_cb: updated_env_content_view,
+ override_save: true
+ }
+ );
+
+ $('#update_form').unbind('submit');
+ $('#update_form').submit(function(e) {
+ var form = $(this);
+ e.preventDefault();
+ KT.common.customConfirm({
+ message: i18n.change_systems_confirm,
+ yes_callback: function(){
+ KT.env_content_view_selector.save(form);
+ }
+ });
+ });
+ },
+ updated_env_content_view = function (){
+ KT.panel.panelAjax('', KT.routes.systems_system_group_path($('#system_group_systems').data('id')) ,$('#panel'));
+ KT.panel.closeSubPanel($('#subpanel'));
};
return {
- init: init,
+ initialize: initialize,
new_setup: new_setup,
details_setup: details_setup,
systems_setup: systems_setup,
+ env_content_view_setup: env_content_view_setup,
add_system : add_system,
refresh_list_item: refresh_list_item
}
-})();
-
+})();
Oops, something went wrong.

0 comments on commit ac176ca

Please sign in to comment.