Sha256: 0af1fd0b1b737b6fe23f7877e8d17a226a6b499c553ea6fef58cdb58af0270a5

Contents?: true

Size: 1.18 KB

Versions: 15

Compression:

Stored size: 1.18 KB

Contents

module DiscoApp::ApplicationHelper

  # Generates a link pointing to an object (such as an order or customer) inside
  # the given shop's Shopify admin. This helper makes it easy to  create links
  # to objects within the admin that support both right-clicking and opening in
  # a new tab as well as capturing a left click and redirecting to the relevant
  # object using `ShopifyApp.redirect()`.
  def link_to_shopify_admin(shop, name, admin_path, options = {})
    options[:onclick] = "ShopifyApp.redirect('#{admin_path}'); return false;"
    options[:'data-no-turbolink'] = true
    link_to(name, "https://#{shop.shopify_domain}/admin/#{admin_path}", options)
  end

  # Generate a link that will open its href in an embedded Shopify modal.
  def link_to_modal(name, path, options = {})
    modal_options = {
      src: path,
      title: options.delete(:modal_title),
      width: options.delete(:modal_width),
      height: options.delete(:modal_height),
      buttons: options.delete(:modal_buttons),
    }
    options[:onclick] = "ShopifyApp.Modal.open(#{modal_options.to_json}); return false;"
    options[:onclick].gsub!(/"function(.*?)"/, 'function\1')
    link_to(name, path, options)
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
disco_app-0.6.8 app/helpers/disco_app/application_helper.rb
disco_app-0.6.9 app/helpers/disco_app/application_helper.rb
disco_app-0.7.0 app/helpers/disco_app/application_helper.rb
disco_app-0.7.1 app/helpers/disco_app/application_helper.rb
disco_app-0.7.2 app/helpers/disco_app/application_helper.rb
disco_app-0.8.0 app/helpers/disco_app/application_helper.rb
disco_app-0.8.1 app/helpers/disco_app/application_helper.rb
disco_app-0.8.2 app/helpers/disco_app/application_helper.rb
disco_app-0.8.3 app/helpers/disco_app/application_helper.rb
disco_app-0.8.4 app/helpers/disco_app/application_helper.rb
disco_app-0.8.5 app/helpers/disco_app/application_helper.rb
disco_app-0.8.6 app/helpers/disco_app/application_helper.rb
disco_app-0.8.7 app/helpers/disco_app/application_helper.rb
disco_app-0.8.8 app/helpers/disco_app/application_helper.rb
disco_app-0.8.9 app/helpers/disco_app/application_helper.rb