Skip to content

Commit

Permalink
Added AJAX functionality to display a dialog box containing a source …
Browse files Browse the repository at this point in the history
…feature files contents.

Added pending spec but had trouble getting it to pass, will implement when paying off our technical debt
  • Loading branch information
baphled committed Jul 6, 2010
1 parent 87c4e64 commit 8c6dd3f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/features_controller.rb
Expand Up @@ -178,6 +178,7 @@ def file
@file = File.read(@feature.path)
respond_to do |format|
format.html
format.js { render :html => @file }
end
end

Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Expand Up @@ -17,6 +17,7 @@
<%= javascript_include_tag "jquery" %>
<%= javascript_include_tag "jquery-ui" %>
<%= javascript_include_tag "jquery-icon-animation" %>
<%= javascript_include_tag "jquery.ajax.dialog" %>
<!-- JS Head start -->
<%= yield :js_head %>
<!-- JS Head end -->
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/no_sidebar.html.erb
Expand Up @@ -25,6 +25,7 @@
<%= javascript_include_tag "scrollingHoverable" %>
<%= javascript_include_tag "jquery-validate" %>
<%= javascript_include_tag "jquery.formtastic.tooltips" %>
<%= javascript_include_tag "jquery.ajax.dialog" %>
<%= javascript_include_tag "pagination" %>
<%= javascript_include_tag "application" %>
<%= yield :js_head %>
Expand Down
39 changes: 39 additions & 0 deletions public/javascripts/jquery.ajax.dialog.js
@@ -0,0 +1,39 @@
/**
* This plugin makes an ajax call to the backend requesting a specific piece of data from an object
* For the moment, we'll primarily be using this to retrieve Salad's feature content but we should be able
* to extend it to pull in any time of data and display it in a dialog box.
*
* @author Yomi Colledge
*
**/
$(function() {
// create dialog div
var $dialog = $('<div>').addClass('dialog path');

// bind click event to related property on page
$('a#file-feature').live('click', function() {
// make ajax call
$.ajax({
url: $('a#file-feature').attr('href'),
type: 'GET',
dataType: 'html',
complete: function(xhr, textStatus) {
},
success: function(data, textStatus, xhr) {
// populate dialog box with content
$dialog
.append(data)
.dialog({
title: 'Source feature content',
width: '75%',
buttons: { "Ok": function() { $(this).dialog("close"); } }
});
},
error: function(xhr, textStatus, errorThrown) {
// display flash error
}
});

return false;
})
});
4 changes: 4 additions & 0 deletions spec/controllers/features_controller_spec.rb
Expand Up @@ -371,5 +371,9 @@ def mock_feature(stubs={})
File.should_receive :read
get :file, {:feature => @feature}
end

context "Making call via AJAX" do
it "should return the feature files content in HTML format"
end
end
end

0 comments on commit 8c6dd3f

Please sign in to comment.