Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

CHEF-1999 get rid of global vars in the cookbook version constraints …

…javascript
  • Loading branch information...
commit 84a37b156ca2147c2d18802eb962d3691344d256 1 parent e5ed1ae
Nuo Yan authored
1  chef-server-webui/app/controllers/cookbooks.rb
View
@@ -33,7 +33,6 @@ def params_helper
end
def index
- provides :html, :json # Because the Environment web form needs to retrieve the list of cookbooks, this method needs to provide both html and json results.
@cl = begin
if session[:environment]
result = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("environments/#{session[:environment]}/cookbooks")
21 chef-server-webui/app/views/environments/_form.html.erb
View
@@ -23,7 +23,7 @@
<% if !@environment.invalid_fields[:cookbook_version].nil? && !@environment.invalid_fields[:cookbook_version].empty? %>
<span class="inline_error_message" id='error'>There was a problem in one of your constraints. Please enter version constraints in acceptable formats (e.g. 0.0.0). </span>
<% end %>
- <table class="table" id="cbVerPickerTable">
+ <table class="table" id="cbVerPickerTable" data-cookbook_names=<%= @cookbooks.to_json %>>
<tbody>
<tr>
<th class = "first" id="CookbookVersionConstraints">Name</th>
@@ -54,17 +54,12 @@
<script type='text/javascript' charset="utf-8" src="/javascripts/cookbook_constraint_ctrl.js"></script>
<script type='text/javascript'>
-var cookbook_names = <%= @cookbooks.to_json %>;
-
-isEdit = document.getElementById('edit');
-if (isEdit != null){
- <%unless @environment.cookbook_versions.nil? || @environment.cookbook_versions.empty?%>
- var existing_env_cookbook_version_constraints = <%= @environment.cookbook_versions.to_json %>;
- for (var cookbook in existing_env_cookbook_version_constraints){
- var operator = existing_env_cookbook_version_constraints[cookbook].split(" ")[0];
- var version = existing_env_cookbook_version_constraints[cookbook].split(" ")[1];
+ $('body').data('cookbook_versions', <%=@environment.cookbook_versions.to_json%>);
+ if (document.getElementById('edit') != null){
+ for (var cookbook in $('body').data('cookbook_versions')){
+ var operator = $('body').data('cookbook_versions')[cookbook].split(" ")[0];
+ var version = $('body').data('cookbook_versions')[cookbook].split(" ")[1];
addTableRow(cookbook, operator, version);
}
- <% end %>
-}
-</script>
+ }
+</script>
2  chef-server-webui/public/javascripts/cookbook_constraint_ctrl.js
View
@@ -57,6 +57,8 @@ function retrieveCbName(timestamp){
}
function addTableRow(default_cookbook, default_operator, default_version){
+ var cookbook_names_string = document.getElementById('cbVerPickerTable').getAttribute('data-cookbook_names');
+ var cookbook_names = cookbook_names_string.substring(2, cookbook_names_string.length-2).split('","');
var timestamp = new Date().getTime();
var row = '<tr id=' + '"' + timestamp + '"><td>' + '<select size="1" name="cookbook_name_' + timestamp + '" ' + 'id="cookbook_name_' + timestamp + '" class="cookbook_version_constraints_cb_name" onchange="jQuerySuggest(' + timestamp + ')"'+'>'
+ buildCookbookList(cookbook_names, default_cookbook) + '</select>'
Please sign in to comment.
Something went wrong with that request. Please try again.