Created
July 2, 2012 20:03
-
-
Save scottshea/3035354 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_asset | |
@asset = Asset.new(:name => params[:name], | |
:description => params[:description], | |
:serial_number => params[:serial_number], | |
:asset_manufacturer_id => params[:asset_manufacturer_id], | |
:asset_model_id => params[:asset_model_id], | |
:image_filename => params[:image_filename]) | |
respond_to do |format| | |
format.js | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% if @asset.errors.any? %> | |
var errors = $('<ul />'); | |
errors.append('<li><%= escape_javascript( error ) %></li>'); | |
jQuery('#create_asset_message').html(errors); | |
<% else %> | |
jQuery("form#create_asset_form").before('<div id="flash_notice"><%= escape_javascript(flash.delete(:notice)) %></div>'); | |
jQuery('form#create_asset_form')[0].reset(); | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function () { | |
jQuery('#create_asset_from_template_form').hide(); | |
jQuery('#create_asset_from_template').bind('click', function() { | |
jQuery('#create_asset_from_template_form').toggle(); | |
}); | |
jQuery('#asset_create_link').bind('click', function(){ | |
if (jQuery("#name").val().length < 1){ | |
jQuery('#create_asset_message').text("Asset Name cannot be blank"); | |
return false; | |
} | |
jQuery.ajax({ | |
url: "/assets/create_asset", | |
type: "GET", | |
data: {"name" : jQuery('#name').val(), | |
"description" : jQuery('#description').val(), | |
"serial_number" : jQuery('#serial_number').val(), | |
"asset_manufacturer_id" : jQuery('#manufacturer_select').val(), | |
"asset_model_id" : jQuery('#models_select').val(), | |
"image_name" : jQuery('#image_name').val()}, | |
dataType: "html"//, | |
// success: function(data){ | |
// jQuery("#create_asset_message").text("Asset Created"); | |
// }, | |
// error: function(data) { | |
// jQuery("#create_asset_message").text(data.responseText); | |
// } | |
}); | |
return false; | |
}); | |
jQuery('form#create_asset_form').submit( function () { | |
alert("Meow") | |
jQuery.ajax({ | |
url: "/assets/create_asset.js", | |
type: "GET", | |
data: {"name" : jQuery('#name').val(), | |
"description" : jQuery('#description').val(), | |
"serial_number" : jQuery('#serial_number').val(), | |
"asset_manufacturer_id" : jQuery('#manufacturer_select').val(), | |
"asset_model_id" : jQuery('#models_select').val(), | |
"image_name" : jQuery('#image_name').val()}, | |
dataType: "html" | |
}); | |
return false; | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_tag create_asset_assets_path, :method => :get, :id => "create_asset_form", :remote => true do %> | |
<div class="row-fluid"> | |
<h3>Choose your template: </h3> | |
<%= collection_select(:asset, :id, @asset_templates,:id,:name, {:prompt => "Select your template..."}, {:class=>'chzn-select', :onchange => "update_asset_form_div(this.value)"}) %> | |
</div> | |
<br/> | |
<%= render :partial => "create_asset_form", :object => @asset_template, :manufacturers => @manufacturers %> | |
<%= submit_tag "Create Asset", :disable_with => "Please wait..." %> | |
<div id="create_asset_message"></div> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment