Last active
August 21, 2016 04:12
-
-
Save hernandezalek/aa902458c09d8bc2529e4644ba493e31 to your computer and use it in GitHub Desktop.
Materialize Modal
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
$( document ).ready(function(){ | |
$(document).ready(function(){ | |
$('.modal-trigger').leanModal(); | |
}); | |
}) |
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 @product.errors.empty? %> | |
Materialize.toast('Se creo correctamente!', 4000); | |
$('#modal1').closeModal(); | |
<% else %> | |
Materialize.toast('Ocurrio un error!', 4000) | |
<% 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
<%= render partial: 'form' %> |
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
$('#modal1').html('<%= j render "form" %>').openModal(); |
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
<!-- Modal Structure --> | |
<div class="modal-content"> | |
<h2>Producto</h2> | |
<%= form_for @product, html: { multipart: true }, remote: true, authenticity_token: true do |f| %> | |
<% if @product.errors.any? %> | |
<div id="error_explanation"> | |
<h2> | |
<%= pluralize(@product.errors.count, "error") %> prohibited | |
this article from being saved: | |
</h2> | |
<ul> | |
<% @product.errors.full_messages.each do |msg| %> | |
<li><%= msg %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<div class="input-field col s12 m12 l12 block-center"> | |
<%= f.text_field :name, autofocus: true, placeholder: 'Nombre del producto' %> | |
</div> | |
<div class="input-field col s12 m12 l12"> | |
<%= f.text_field :description, placeholder: 'Descripcion del producto' %> | |
</div> | |
<div class="input-field col s12 m12 l12"> | |
<div class="file-field input-field"> | |
<div class="btn teal accent-5"> | |
<span>IMG</span> | |
<%= f.file_field :picture %> | |
</div> | |
<div class="file-path-wrapper"> | |
<input class="file-path validate" type="text" placeholder="Agregar imagen"> | |
</div> | |
</div> <br> | |
</div> | |
<div class="row"> | |
<div class="input-field col s12 m12 l12 center"> | |
<%= f.submit "Crear producto", class: 'btn teal accent-5' %> | |
</div> | |
</div> | |
<% end %> | |
</div> | |
<div class="modal-footer"> | |
<a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat ">Agree</a> | |
</div> |
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
<div class="container"> | |
<nav> | |
<div class="nav-wrapper teal accent-5"> | |
<div class="col s12 m12 l12 center"> | |
<ul> | |
<li class="hover-disabled">Productos <i class="material-icons left">chevron_right</i></li> | |
<% if enterprise_signed_in? %> | |
<li class="right hover-disabled"> | |
<%= link_to new_product_path, remote: true do %> | |
<button class="btn teal lighten-2 z-depth-0"> | |
Crear producto | |
</button> | |
<% end %> | |
</li> | |
<% end %> | |
</ul> | |
</div> | |
</div> | |
</nav> | |
<br> | |
<div class="row"> | |
<% if @products.any? %> | |
<% @products.each do |product| %> | |
<div class="col s12 m6 l4"> | |
<%= link_to product_path(product) do %> | |
<div class="card z-depth-1"> | |
<div class="card-image valign-wrapper" style="background-image: url( <%= product.picture.url %> );"> | |
<h5 class="white-text block-center"><b><%= product.name %></b></h5> | |
</div> | |
<div class="card-action center"> | |
<% if enterprise_signed_in? %> | |
<%= link_to product_path(product), method: :delete, data: { confirm: '¿Estas seguro de querer eliminar este producto?' }, class: "btn-floating waves-effect waves-light red" do %> | |
<i class="material-icons">delete</i> | |
<% end %> | |
<%= link_to edit_product_path(product), remote: true do %> | |
<button class="btn-floating teal lighten-2 z-depth-0"> | |
<i class="material-icons">edit</i> | |
</button> | |
<% end %> | |
<% end %> | |
<a class="btn-floating waves-effect waves-light red"><i class="material-icons">favorite</i></a> | |
</div> | |
</div> | |
<% end %> | |
</div> | |
<% end %> | |
<% else %> | |
<p class="center">No hay productos disponibles por el momento</p> | |
<% end %> | |
</div> | |
</div> | |
<div id="modal1" class="modal modal-fixed-footer"> | |
</div> |
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
<%= render partial: 'form' %> |
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
$('#modal1').html('<%= j render "form" %>').openModal(); | |
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
class ProductsController < ApplicationController | |
before_action :authenticate_enterprise!, except: [:index] | |
def index | |
@products = Product.all | |
end | |
def show | |
@product = Product.find(params[:id]) | |
end | |
def new | |
@product = current_enterprise.products.new | |
end | |
def edit | |
@product = Product.find(params[:id]) | |
end | |
def create | |
@product = current_enterprise.products.new(products_params) | |
respond_to do |format| | |
if @product.save | |
format.html { redirect_to products_path } | |
format.js { render :index } | |
else | |
format.js { render :new } | |
end | |
end | |
end | |
def update | |
@product = Product.find(params[:id]) | |
respond_to do |format| | |
if @product.update(products_params) | |
format.html { redirect_to products_path } | |
format.js { render :index } | |
else | |
format.js { render :edit } | |
end | |
end | |
end | |
def destroy | |
@product = Product.find(params[:id]) | |
@product.destroy | |
redirect_to products_path | |
end | |
private | |
def products_params | |
params.require(:product).permit(:name, :picture, :description, :enterprise_id) | |
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 @products.errors.empty? %> | |
swal("Datos actualizados", "Se ha actualizado los datos del documento", "success"); | |
$('#modal1').closeModal(); | |
<% else %> | |
swal("Ha ocurrido un problema", "Datos erroneos", "error"); | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment