Sha256: 929f7af89f8f73f90c56b5a1fd0344fdc23f428db43faed4588cfffe87078f80

Contents?: true

Size: 1.71 KB

Versions: 112

Compression:

Stored size: 1.71 KB

Contents

# Matt Mower <matt@cominded.com>
# 
# A base class for creating DHTML confirmation types.
#
# The real work is done by the onclick_function and onclick_handler methods. In
# general it should only be required to override the default onclick_handler
# method and provide the specific Javascript required to invoke the DHTML confirm
# dialog of your choice.
#
# It is up to this dialog, if the user confirms the intended action, to invoke
# the function window.gFireModalLink() to trigger the intended action of the link.
# For example, using the Modalbox library, you would use something like:
#
#     Modalbox.hide( {
#               afterHide: function() {
#                 window.gFireModalLink();
#               } } );
#
# By default the only action recognized is :value which is used to add a
# dhtml_confirm attribute to the link <a> tag. This value is detected by the
# ActiveScaffold link and triggers the DHTML confirmation logic.
#
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

Version data entries

112 entries across 112 versions & 6 rubygems

Version Path
brisk-bills-0.8.2 vendor/plugins/active_scaffold/lib/dhtml_confirm.rb
brisk-bills-0.8.1 vendor/plugins/active_scaffold/lib/dhtml_confirm.rb
six-updater-web-0.24.15 lib/six-updater-web/vendor/plugins/active_scaffold/lib/dhtml_confirm.rb
six-updater-web-0.24.14 lib/six-updater-web/vendor/plugins/active_scaffold/lib/dhtml_confirm.rb
six-updater-web-0.24.13 lib/six-updater-web/vendor/plugins/active_scaffold/lib/dhtml_confirm.rb
active_scaffold_vho-3.0.9 lib/dhtml_confirm.rb
active_scaffold_vho-3.0.8 lib/dhtml_confirm.rb
active_scaffold_vho-3.0.7 lib/dhtml_confirm.rb
active_scaffold_vho-3.0.6 lib/dhtml_confirm.rb
six-updater-web-0.24.12 lib/six-updater-web/vendor/plugins/active_scaffold/lib/dhtml_confirm.rb
six-updater-web-0.24.11 lib/six-updater-web/vendor/plugins/active_scaffold/lib/dhtml_confirm.rb
six-updater-web-0.24.10 lib/six-updater-web/vendor/plugins/active_scaffold/lib/dhtml_confirm.rb
six-updater-web-0.24.9 lib/six-updater-web/vendor/plugins/active_scaffold/lib/dhtml_confirm.rb
six-updater-web-0.24.8 lib/six-updater-web/vendor/plugins/active_scaffold/lib/dhtml_confirm.rb
six-updater-web-0.24.7 lib/six-updater-web/vendor/plugins/active_scaffold/lib/dhtml_confirm.rb
active_scaffold-3.0.5 lib/dhtml_confirm.rb
active_scaffold-3.0.4 lib/dhtml_confirm.rb
active_scaffold-3.0.2 lib/dhtml_confirm.rb
active_scaffold-3.0.1 lib/dhtml_confirm.rb
active_scaffold-3.0.0 lib/dhtml_confirm.rb