Sha256: 99dacf80e86e6b833d6c50e8eebb3c3016af86bcefed3763d402f1fa1178a80d

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

<% message = flash[:notice] || flash[:alert] %>
<% flash.delete(:notice); flash.delete(:alert) %>
<% alert = message.present? ? "alert('#{message}');" : '' %>

<% if @path.present? %>
  <% if @template_format == 'html' %>
    $.ajax({ url: "<%= @path %>", data: <%= raw @data.to_json %>, type: "<%= @method.to_s.upcase %>", dataType: "html"}).done(function(data) {
      $("<%= @target %>").html(data);
      <%= raw alert %>
      <% if @close_modal %>$('#modal').modal('hide');<% end %>
    })
    .fail(function(data) {
      <%= raw alert %>
      alert("Failed to load <%= @path %>!");
      <% if @close_modal %>$('#modal').modal('hide');<% end %>
    });
  <% else %>
    $.ajax({ url: "<%= @path %>", data: <%= raw @data.to_json %>, type: "<%= @method.to_s.upcase %>", dataType: "script"}).done(function(data) {
      eval(data);
      <%= raw alert %>
      <% if @close_modal %>$('#modal').modal('hide');<% end %>
    })
    .fail(function(data) {
      <%= raw alert %>
      alert("Failed to load <%= @path %>!");
      <% if @close_modal %>$('#modal').modal('hide');<% end %>
    });
  <% end %>
<% elsif @template.present? %>
  <% if @template_format == 'html' %>
    <% if @target_needs_modal_layout %>
      $("<%= @target %>").html("<%= escape_javascript(
        render(
          partial: 'shared/layouts/modal', 
          locals: { title: @modal_title, body: render(template: "#{@template_namespace}/#{@template}.html") }
        ) 
      ) %>");
    <% else %>
      $("<%= @target %>").html("<%= escape_javascript render(template: "#{@template_namespace}/#{@template}.html") %>");
      <% if @close_modal %>$('#modal').modal('hide');<% end %>
    <% end %>
  <% elsif @template_format == 'js' %>
    <%= render template: "#{@template_namespace}/#{@template}.js" %>
    <% if @close_modal %>$('#modal').modal('hide');<% end %>
  <% end %>
  <%= raw alert %>
<% elsif message.present? %>
  <%= raw alert %>
  <% if @close_modal %>$('#modal').modal('hide');<% end %>
<% end %>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
home_page-0.0.6 app/views/shared/_javascript_response.js.erb