In this following code :disable_with is not working in rails 3. But it is perfectly working in rails 2.2
What is wrong in this code?
<%= submit_tag "Save", :class => "buttons",
:disable_with => "Processing",
:id => 'save_btn' %>
Since version 3.2.5 you should not use :disable_with.
<%= submit_tag "Save", 'data-disable-with' => "Processing", :class => "buttons", :id => 'save_btn' %>
or
<%= submit_tag "Save", data: { disable_with: "Processing" }, :class => "buttons", :id => 'save_btn' %>
Check the following in your raw html:
the submit button has data-disable-with attribute
your page includes jQuery js. For me I have:
https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
you page includes jquery_ujs js. For me I have:
/javascripts/jquery_ujs.js
You can read more on https://github.com/rails/jquery-ujs. Different installations for different rails versions.
I had a similar issue on Safari 8.0.6 and latest rails-ujs. Here's my approach of solving this issue:
%button{ class: 'btn btn-action js-submit', data: { method: :put, 'href' => '...', disable_with: "<i class='icon icon-spinner icon-spin'></i>".html_safe }} Submit
$('.js-select-plan').click(function(event) {
event.preventDefault();
var $target = $(this),
href = $target.data('href'),
method = $target.data('method'),
formTarget = $target.attr('target'),
csrfToken = $('meta[name=csrf-token]').attr('content'),
csrfParam = $('meta[name=csrf-param]').attr('content'),
form = $('<form method="post" action="' + href + '"></form>'),
metaData = '<input name="_method" value="' + method + '" type="hidden" />';
if (csrfParam !== undefined && csrfToken !== undefined) {
metaData += '<input name="' + csrfParam + '" value="' + csrfToken + '" type="hidden" />';
}
if (formTarget) {
form.attr('target', formTarget);
}
// disable button/link element
var contentMethod = $target.is('button') ? 'html' : 'val';
var replacement = $target.data('disable-with');
$target.data('ujs:enable-with', $target[contentMethod]());
if (replacement !== undefined) {
$target[contentMethod](replacement);
}
$target.prop('disabled', true);
form.hide().append(metaData).appendTo('body');
setTimeout(function(){
form.submit();
}, 50);
});
This works like a charm in all browsers. For better flexibility you might want to wrap this in a helper.
Related
I am trying to adapt the Product Comments "add a review feature" (which is on the Product page) to work on the Products List page, but the link is only recognizing the first product in the list. There is a pencil icon link next to each product in the list, but they all link to the first product only.
Can anybody let me know why this is happening, and point me in the right direction to fixing it.
Following is the code in my custom hook:
include_once dirname(__FILE__).'/ProductComment.php';
include_once dirname(__FILE__).'/ProductCommentCriterion.php';
if(in_array($this->context->controller->php_self, array('product-list'))) $products = Product::getProducts((int) Tools::getValue('id_product'), $this->context->language->id);
{
$id_guest = (!$id_customer = (int) $this->context->cookie->id_customer) ? (int) $this->context->cookie->id_guest : false;
$customerComment = ProductComment::getByCustomer((int) (Tools::getValue('id_product')), (int) $this->context->cookie->id_customer, true, (int) $id_guest);
$average = ProductComment::getAverageGrade((int) Tools::getValue('id_product'));
$image = Product::getCover((int) Tools::getValue('id_product'));
$cover_image = $this->context->link->getImageLink($product->link_rewrite, $image['id_image'], 'medium_default');
$this->context->smarty->assign(array(
'id_product_comment_form' => (int) Tools::getValue('id_product'),
'product' => $products,
'secure_key' => $this->secure_key,
'logged' => $this->context->customer->isLogged(true),
'allow_guests' => (int) Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'),
'productcomment_cover' => (int) Tools::getValue('id_product').'-'.(int) $image['id_image'], // retro compat
'productcomment_cover_image' => $cover_image,
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
'criterions' => ProductCommentCriterion::getByProduct((int) Tools::getValue('id_product'), $this->context->language->id),
'action_url' => '',
'averageTotal' => round($average['grade']),
'ratings' => ProductComment::getRatings((int) Tools::getValue('id_product')),
'too_early' => ($customerComment && (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()),
'nbComments' => (int) (ProductComment::getCommentNumber((int) Tools::getValue('id_product'))),
));
return $this->display(__FILE__, '/mytemplate.tpl');
}
This is the code in my template:
<SCRIPT>
$(document).ready(function() {
if (!!$.prototype.fancybox)
$('.open-comment-form').fancybox({
'autoSize' : false,
'width': 800,
'height': auto,
'hideOnContentClick': false,
'title' : null,
});
});
</SCRIPT>
{if (!$too_early AND ($is_logged OR ($PRODUCT_COMMENTS_ALLOW_GUESTS == 0)))}
<p class="align_center">
<a class="open-comment-form" href="#new_comment_form" title="{l s='Write your review' mod='productcomments'}!"></a>
</p>
{/if}
I am using Prestashop version 1.6.1.14. Thanks aussiecomet
I'm trying to implement infinite scrolling into my project.
I have do everything as in this howto: https://github.com/amatsuda/kaminari/wiki/How-To:-Create-Infinite-Scrolling-with-jQuery
But it's not working for me :(
Controller:
def show
category = Category.find(params[:id])
products = category.products.page(params[:page])
#category = CategoryDecorator.decorate(category)
#products = ProductDecorator.decorate_collection(products)
respond_to do |format|
format.js
format.html
format.xml { render :xml => #products }
end
end
show.html.haml:
#products_list
%page
= render 'products_list'
:javascript
$(function() {
var page = 1,
loading = false;
function nearBottomOfPage() {
return $(window).scrollTop() > $(document).height() - $(window).height() - 200;
}
$(window).scroll(function(){
if (loading) {
return;
}
if(nearBottomOfPage()) {
loading=true;
page++;
$.ajax({
url: '/universes/nautique/sports/surfwear/categories/boarshorts?per_page=' + page,
type: 'get',
dataType: 'script',
success: function() {
$(window).sausage('draw');
loading=false;
}
});
}
});
$(window).sausage();
}());
- content_for :javascript do
= javascript_include_tag "jquery.sausage"
Partial _products_list.html.haml:
- #products.each_with_index do |product,index|
.block-prodlist{ data: { index: product.id } }
.inner.onfocus
.selection
%label AJOUTER À MA SÉLECTION
%input.chk{:name => "", :type => "checkbox", :value => ""}/
.thumbproduit
= index
%img{:alt => "Produit", :height => "194", :src => "/assets/editorial/produit1.jpg", :width => "194"}/
.prixcaption -20%
.context
%h3
= product.brand_name
And show.js.haml:
$("#products_list").append("#{escape_javascript(render(#products))}");
I don't see show.js in my firebug.
Error was with store script - show.js.haml
I have change #products to my partial name:
$("#products_list").append("#{escape_javascript(render('products_list'))}");
I am trying to add Custom Button to each row of Kendo Grid, but I am not getting the desired output.So my requirement is to add dynamic buttons to each row and on clicking on these button I need to process few thing for which I need few column values to be passed to that button click.
I have tried something like
#(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(o => o.Id);
columns.Bound(o => o.TBRId).Width(100).Title(UI_Resources.ListLabel_TBRId);
columns.Bound(o => o.THUQuantity).Width(50).Title(UI_Resources.ListLabel_THUQuantity).HtmlAttributes(new { style = "text-align:right" });
columns.Bound(o => o.Id).ClientTemplate("<input width='50px' type='button' value= " + UI_Resources.Button_Details + " onclick='onDetailUnitClick(#= Id #);' class='btn btnTable' />").Width(50).Title("");
columns.Bound(o => o.IsPOD).ClientTemplate("#= AppendZeroPODButton(Id,IsPOD) #").Width(60).Title("");
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetUnitsForShipment", "POD",new { shipmentId = #Model, Mode = "POD" }))
)
)
/*JavaScript */
function onDetailUnitClick(Id) {
var podDateTime = $("#enteredPODDateTime").val();
var stopId = $("#hiddenStopId").val();
var mode = '';
if (typeof $("#hiddenMode").val() != 'undefined')
mode = $("#hiddenMode").val();
window.location.href = "/POD/Details/" + Id + "?stopId=" + stopId + "&date=" + podDateTime + "&mode=" + mode;
};
function AppendZeroPODButton(Id, isPOD) {
if (isPOD == true) {
return "<input width='100px' type='button' value= 'Zero POD' onclick='onPODUnitClick(" + Id + ",1);' class='btn btnTable btn-success' disabled />";
}
else {
return "<input width='100px' type='button' value= 'Zero POD' onclick='onPODUnitClick(" + Id + ",1);' class='btn btnTable btn-danger' />";
}}
Can you please suggest me what I am doing wrong!!
It was working for Telerek MVC grids.
Thanks
Yogendra Singh
It worked if I change the ClientTemplate to
columns.Template(t => t.IsPOD).HeaderTemplate("").ClientTemplate(#"<a href='javascript: void(0)' class='btn btnTable' onclick='onDetailUnitClick(#= Id #)' title='button delete'>" + UI_Resources.Button_Details + " </a>").Title("").Width(50);
AND
columns.Bound(p => p.IsPOD).ClientTemplate("# if( IsPOD == true) { # <a href='javascript: void(0)' class='btn btnTable btn-success' onclick='onPODUnitClick(#= Id #, 1)' title='Zero POD'>" + UI_Resources.Button_ZeroPOD + "</a> # } else {# <a href='javascript: void(0)' class='btn btnTable btn-danger' onclick='onPODUnitClick(#= Id #, 1)' title='Zero POD'>" + UI_Resources.Button_ZeroPOD + "</a> # } #").Title("").Width(100);
You can add Custom button as well.Refer this http://demos.kendoui.com/web/grid/custom-command.html
Does anyone knows how or point me in the direction to show the last guestbook entry (using the simple guestbook module) in the sidebar or homepage?
trying to have a go, I've put in HomePage.php this function
function LastGuest($nume=1) {
$guest = DataObject::get_one("Guestbook");
return ($guest) ? DataObject::get("GuestbookEntry", "", "Date DESC", "", $nume) : false;
}
and in HomePage.ss this:
<% control LastGuest %>
<div class="newsList">
<h2 class="newsTitle">$Title.XML</h2>
<article class="newsSummary">$Comment</article>
</div>
<% end_control %>
But it doesn't work. I get a 500 error. Any idea?
Thanks in advance.
This works for me. First see if you have a page of class Guestbook, grab the ID of the page. Then use that ID in the arguments to GuestbookEntry::getEntryList.
function LastGuest() {
if ($guestbook = DataObject::get_one('GuestBook')) {
$id = $guestbook->ID;
$params = array(
'filter' => 'IsActive = 1 AND IsSpam = 0 AND GuestbookID = ' . $id,
'sort' => 'Created DESC',
'limit_start' => 0,
'limit_end' => 1,
'comments' => false,
'cryptmail' => false,
'emoticons' => false,
);
$entries = GuestbookEntry::getEntryList($params);
return $entries;
}
return;
}
I'm working with Ruby On Rails 3, and I would like to do the following, but from the code behind:
<% form_tag "https://www.sandbox.paypal.com/cgi-bin/webscr" do %>
<%= hidden_field_tag :cmd, "_s-xclick" %>
<%= hidden_field_tag :encrypted, #cart.paypal_encrypted(products_url, payment_notifications_url) %>
<p><%= submit_tag "Checkout" %></p>
<% end %>
I've tried this in my Cart model, but it's not redirecting anywhere, and I don't know what to do:
PAYPAL_CERT_PEM = File.read("#{Rails.root}/certs/paypal_cert.pem")
APP_CERT_PEM = File.read("#{Rails.root}/certs/app_cert.pem")
APP_KEY_PEM = File.read("#{Rails.root}/certs/app_key.pem")
PANEL = 'sandbox.paypal.com'
PATH = '/cgi-bin/webscr'
USERAGENT = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1'
def paypal_url(order_id, return_url, notify_url)
http = Net::HTTP.new(PANEL, 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
# GET request -> so the host can set cookies
resp, data = http.get2(PATH, {'User-Agent' => USERAGENT})
cookie = resp.response['set-cookie'].split('; ')[0]
values = {
:cmd => '_s-xclick',
:encrypted => paypal_encrypted(order_id, return_url, notify_url)
}
#headers = {
'Cookie' => cookie,
'Referer' => 'https://'+PANEL+PATH,
'Content-Type' => 'application/x-www-form-urlencoded',
'User-Agent' => USERAGENT
}
resp, data = http.post2(PATH, values.to_query, #headers)
end
def paypal_encrypted(order_id, return_url, notify_url)
values = {
:business => 'seller_1234111143_biz#asciicasts.com',
:cmd => '_cart',
:upload => 1,
:return => return_url,
:invoice => order_id.to_s,
:notify_url => notify_url,
:currency_code => "USD"
}
items.each_with_index do |item, index|
values.merge!({
"amount_#{index + 1}" => item.unit_price,
"item_name_#{index + 1}" => item.product.title,
"item_number_#{index + 1}" => item.product.id + Time.now.to_i,
"quantity_#{index + 1}" => item.quantity.to_i
})
end
encrypt_for_paypal(values)
end
def encrypt_for_paypal(values)
signed = OpenSSL::PKCS7::sign(OpenSSL::X509::Certificate.new(APP_CERT_PEM), OpenSSL::PKey::RSA.new(APP_KEY_PEM, ''), values.map { |k, v| "#{k}=#{v}" }.join("\n"), [], OpenSSL::PKCS7::BINARY)
OpenSSL::PKCS7::encrypt([OpenSSL::X509::Certificate.new(PAYPAL_CERT_PEM)], signed.to_der, OpenSSL::Cipher::Cipher::new("DES3"), OpenSSL::PKCS7::BINARY).to_s.gsub("\n", "")
end
If you're wondering why I can't just use the html form, that's because I let users choose between more than one payment option, using radio fields, and once they have selected one, they will click on the "Submit Order" button, generating the respective movements in my database, before redirecting to the payment method.