vhochstein / active_scaffold

Rails 4 Version of activescaffold supporting jquery
MIT License
156 stars 34 forks source link

dhtml confirm + modal #184

Closed vptcnt closed 12 years ago

vptcnt commented 13 years ago

Hi

I tried to update my application from Rails 2.3.8 + activescaffold (from activescaffold) to Rails 3.1 + activescaffold_vho

For delete action, I used :

class ModalboxConfirm < DHTMLConfirm 
  def onclick_handler(controller, link_id)
    "Modalbox.show(\"<div class='buttons'><p>#{I18n.t('confirmation.body')}</p><a href='javascript:none' style='float:left;margin-bottom:0;' onclick='Modalbox.hide({afterHide:function(){window.gFireModalLink();}});'>#{I18n.t('confirmation.yes_button')}</a><a href='javascript:none' onclick='Modalbox.hide();' style='float:right;margin-right:0;margin-bottom:0;'>#{I18n.t('confirmation.no_button')}</a></div>\", {title: '#{I18n.t('confirmation.title')}', width: 300, overlayDuration: 0, resizeDuration: 0, slideDownDuration: 0, slideUpDuration: 0, autoFocusing: false});"
  end
end

where DHTMLConfirm comes from the plugin

class DHTMLConfirm
  attr_accessor :value, :message, :options

  def initialize( options = {} )
    @options = options
    @value = @options.delete(:value) { |key| "yes" }
    @message = @options.delete(:message) { |key| "Are you sure?" }
  end

  def onclick_function( controller, link_id )
    script = <<-END
window.gFireModalLink = function() {
  var link = $('#{link_id}').action_link;
  link.open_action.call( link );
};
#{ensure_termination(onclick_handler(controller,link_id))}
return false;
END
    # script = "window.gModalLink = $('#{link_id}').action_link;#{onclick_handler(controller,link_id)}return false;"
  end

  def onclick_handler( controller, link_id )
    ""
  end

protected
  def ensure_termination( expression )
    expression =~ /;$/ ? expression : "#{expression};"
  end

end

But in Active_Scaffold_Vho, no more DHTMLConfirm class...

So how to get the action link ?

I tried to adapt the previous code with somethink like that :

class ConstellationConfirm
  attr_accessor :value, :message, :options
  def initialize(options = {})
    @options = options
    @value = @options.delete(:value) {|key| 'yes'}
    @message = @options.delete(:message) {|key| 'are you sure ?'}
  end
  def onclick_function(controller, link_id)
    #return "console.log($('##{link_id}')); return false;"
    "$.modal({
        title: 'Confirmation',
        content: '#{@message}',
        width: 300,
        closeButton: false,
        buttons: {
            'Yes': function(win) {
                var link = $('##{link_id}').action_link;
console.log($('##{link_id}'));
                link.open_action.call(link);
            },
            'No': function(win) {
                win.closeModal();

            }
        }
    });
    return false;"
  end
end

But link is undefined...

Any help ???

Thanks Vincent

vhochstein commented 13 years ago

DHTML Confirmation is nt supported anymore. We use unobtrusive javascript with rails 3.

vhochstein commented 12 years ago

Will close this issue.