Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

system groups - address style comments from pull request 1837 review

Addresses a few minor style comments from 1837:
- spacing around => in controller
- spacing after lambda in controller
- inclusion of () on selector callback function
- indentation in *selector.js
  • Loading branch information...
commit e036360fbae77992d4fd0521ac37a9165189a2c0 1 parent ac176ca
@bbuckingham bbuckingham authored
View
114 src/app/controllers/system_groups_controller.rb
@@ -12,38 +12,38 @@
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, :edit_systems,
- :update_systems, :copy]
+ 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, :edit_systems,
+ :update_systems, :copy]
before_filter :authorize
def rules
- any_readable = lambda{current_organization && SystemGroup.any_readable?(current_organization)}
- read_perm = lambda{@group.readable?}
- edit_perm = lambda{@group.editable?}
- 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?}
+ any_readable = lambda {current_organization && SystemGroup.any_readable?(current_organization)}
+ read_perm = lambda {@group.readable?}
+ edit_perm = lambda {@group.editable?}
+ 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,
+ :index => any_readable,
+ :items => any_readable,
:new => create_perm,
- :create=>create_perm,
- :copy=>create_perm,
- :edit=>read_perm,
+ :create => create_perm,
+ :copy => create_perm,
+ :edit => read_perm,
:systems => read_perm,
- :update=>edit_perm,
- :destroy=>destroy_perm,
- :destroy_systems=>destroy_systems_perm,
- :show=>read_perm,
- :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
+ :update => edit_perm,
+ :destroy => destroy_perm,
+ :destroy_systems => destroy_systems_perm,
+ :show => read_perm,
+ :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
@@ -71,15 +71,15 @@ def new
end
def create
- @group = SystemGroup.create!(params[:system_group].merge({:organization_id=>current_organization.id}))
+ @group = SystemGroup.create!(params[:system_group].merge({:organization_id => current_organization.id}))
notify.success _("System Group %s created successfully.") % @group.name
if !search_validate(SystemGroup, @group.id, params[:search])
notify.message _("'%s' did not meet the current search criteria and is not being shown.") % @group.name
render :json => { :no_match => true }
else
respond_to do |format|
- format.html {render :partial => "system_groups/list_group", :locals=>{:item=>@group, :accessor=>"id",
- :name=>controller_display_name}}
+ format.html {render :partial => "system_groups/list_group", :locals => {:item => @group, :accessor => "id",
+ :name => controller_display_name}}
format.json {render :json => @group}
end
end
@@ -98,17 +98,18 @@ def copy
notify.success _("System Group %{new_group} created successfully as a copy of system group %{group}.") % {:new_group => new_group.name, :group => @group.name}
- render :partial => "system_groups/list_group", :locals=>{:item=>new_group, :accessor=>"id", :name=>controller_display_name}
+ render :partial => "system_groups/list_group", :locals=> {:item => new_group, :accessor => "id",
+ :name => controller_display_name}
end
def edit
- render :partial => "edit", :locals => {:filter => @group, :name=>controller_display_name,
- :editable=>@group.editable?
- }
+ render :partial => "edit", :locals => {:filter => @group, :name => controller_display_name,
+ :editable => @group.editable?
+ }
end
def show
- render :partial => "system_groups/list_group", :locals=>{:item=>@group, :accessor=>"id", :name=>controller_display_name}
+ render :partial => "system_groups/list_group", :locals => {:item => @group, :accessor => "id", :name => controller_display_name}
end
def update
@@ -133,13 +134,13 @@ def update
:asynchronous => false
end
- render :text=>to_ret
+ render :text => to_ret
end
def destroy
@group.destroy
notify.success _("System Group %s deleted.") % @group.name
- render :partial => "common/list_remove", :locals => {:id=>params[:id], :name=>controller_display_name}
+ render :partial => "common/list_remove", :locals => {:id => params[:id], :name => controller_display_name}
end
def destroy_systems
@@ -154,14 +155,15 @@ def destroy_systems
notify.success _("Deleted System Group %{group} and it's %{count} systems.") % {:group => @group.name, :count => system_names.length.to_s},
:details => system_names.join("\n")
- render :partial => "common/list_remove.js", :locals => {:id=>params[:id], :name=>controller_display_name}
+ render :partial => "common/list_remove.js", :locals => {:id => params[:id], :name => controller_display_name}
end
def items
ids = SystemGroup.readable(current_organization).collect{|s| s.id}
render_panel_direct(SystemGroup, @panel_options, params[:search], params[:offset], [:name_sort, :asc],
- {:default_field => :name, :load=>true, :filter=>[{:id=>ids},{:organization_id=>[current_organization.id]}]})
+ {:default_field => :name, :load => true, :filter => [{:id => ids},
+ {:organization_id => [current_organization.id]}]})
end
def panel_options
@@ -171,43 +173,43 @@ def panel_options
:titles => [_('Name')],
:create => _('System Group'),
:name => controller_display_name,
- :ajax_scroll=>items_system_groups_path(),
- :enable_create=> SystemGroup.creatable?(current_organization),
- :initial_action=>:systems,
+ :ajax_scroll => items_system_groups_path(),
+ :enable_create => SystemGroup.creatable?(current_organization),
+ :initial_action =>:systems,
:list_partial => 'system_groups/list_groups',
- :ajax_load=>true,
- :search_class=>SystemGroup
+ :ajax_load => true,
+ :search_class => SystemGroup
}
end
def systems
@system_joins = @group.system_system_groups.sort_by{|a| a.system.name}
render :partial => "systems",
- :locals => {:filter => @group, :name=>controller_display_name, :editable=>@group.editable?,
- :systems_deletable=>@group.systems_deletable?}
+ :locals => {:filter => @group, :name => controller_display_name, :editable => @group.editable?,
+ :systems_deletable => @group.systems_deletable?}
end
def add_systems
ids = params[:system_ids].collect{|s| s.to_i} - @group.system_ids #ignore dups
- systems = System.readable(current_organization).where(:id=>ids)
+ systems = System.readable(current_organization).where(:id => ids)
@group.system_ids = (@group.system_ids + systems.collect{|s| s.id}).uniq
@group.save!
- system_joins = @group.system_system_groups.where(:system_id=>ids)
+ system_joins = @group.system_system_groups.where(:system_id => ids)
notify.success _("Successfully added system[s] to group '%s'.") % @group.name
- render :partial=>'system_item', :collection=>system_joins, :as=>:system,
- :locals=>{:editable=>@group.editable?}
+ render :partial => 'system_item', :collection => system_joins, :as => :system,
+ :locals => {:editable => @group.editable?}
end
def remove_systems
- systems = System.readable(current_organization).where(:id=>params[:system_ids]).collect{|s| s.id}
+ systems = System.readable(current_organization).where(:id => params[:system_ids]).collect{|s| s.id}
@group.system_ids = (@group.system_ids - systems).uniq
@group.save!
notify.success _("Successfully removed system[s] from group '%s'.") % @group.name
- render :text=>''
+ render :text => ''
end
def edit_systems
@@ -230,7 +232,7 @@ def update_systems
notify.success _("Successfully updated environment and content view for all systems in group %{group}") %
{:group => @group.name}
- render :text=>''
+ render :text => ''
end
def auto_complete
@@ -242,11 +244,11 @@ def auto_complete
string query
end
filter :term, {:organization_id => org.id}
- filter :terms, {:id=>SystemGroup.editable(org).collect{|g| g.id}}
+ filter :terms, {:id => SystemGroup.editable(org).collect{|g| g.id}}
end
- render :json=>groups.map{|s| {:label=>s.name, :value=>s.name, :id=>s.id}}
+ render :json => groups.map{|s| {:label => s.name, :value => s.name, :id => s.id}}
rescue Tire::Search::SearchRequestFailed => e
- render :json=>Util::Support.array_with_total
+ render :json => Util::Support.array_with_total
end
def controller_display_name
@@ -255,7 +257,7 @@ def controller_display_name
def validate_name
name = params[:term]
- render :json=>SystemGroup.search("name:#{name}").count
+ render :json => SystemGroup.search("name:#{name}").count
end
def find_group
View
279 src/public/javascripts/env_content_view_selector.js
@@ -13,165 +13,164 @@
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;
- }
+ 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();
+ 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();
- };
+ //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();
+ $('#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.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_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();
- 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) {
+ 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();
- data.ajaxSubmit({
- success: function(data) {
- highlight_content_views(false);
- enable_buttons();
- if (settings.save_success_cb) {
- settings.save_success_cb();
+ $.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(e) {
- highlight_content_views(false);
- enable_buttons();
- if (settings.save_error_cb) {
- settings.save_error_cb();
+ },
+ error: function(data) {
+ initialize_edit();
+ if (settings.cancel_error_cb) {
+ settings.cancel_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();
}
+ });
+ } 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>");
+ }
+ },
+ 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});
- });
+ // 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);
+ $("#content_view_id").html(options);
- if (response.length > 0) {
- highlight_content_views(true);
- }
- enable_buttons();
- },
- error: function(data) {
- enable_buttons();
+ if (response.length > 0) {
+ highlight_content_views(true);
}
- });
- }
- },
- 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>');
+ enable_buttons();
+ },
+ error: function(data) {
+ enable_buttons();
}
- } else {
- select_input.removeClass('highlight_input');
- $('.highlight_input_text').remove();
+ });
+ }
+ },
+ 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,
Please sign in to comment.
Something went wrong with that request. Please try again.