How to make a Custom Dashlet Toolbar Button be simple html link?

When adding custom buttons to things in Sugar 7, like the record view or dashlets, is there a way to add a button that is a simple link?

This is the context I'm looking at when talking about adding buttons to stuff: http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.7/User_Interface/Views/Adding_Buttons_… 

For example, if I wanted a button labeled "Google" and when you click on it you should be taken to https://www.google.com  

Closest thing would be to do a normal button and when it is clicked, the event function could do something like window.location = 'https://www.google.com'; but I need to also be able to define a "target" attribute to tell it where to open the new window.

Any ideas? Thanks!

  • If I understand your question... 

    Short answer: in your Controller, in the on click event, use window.open(url) to target a new window/tab.

    I've not tried in Dashlet but In Record View I've added some Actions to the blue-Edit Dropdown on Cases which go to various internal websites from Cases Record View, in this example go to TheKitchenSink (kitchen_sink).

    I've also added buttons next to the blue-Edit to jump down to the Email subpanel (gotoemail) (our Cases Record View is pretty big), and bring you back to the top (gototop):

    in cases/views/record/record.php

    $viewdefs['Cases']['base']['view']['record'] = array (
      'buttons' =>
      array (
        array (
          'type' => 'button',
          'name' => 'cancel_button',
          'label' => 'LBL_CANCEL_BUTTON_LABEL',
          'css_class' => 'btn-invisible btn-link',
          'showOn' => 'edit',
        ),
        array (
          'type' => 'rowaction',
          'event' => 'button:save_button:click',
          'name' => 'save_button',
          'label' => 'LBL_SAVE_BUTTON_LABEL',
          'css_class' => 'btn btn-primary',
          'showOn' => 'edit',
          'acl_action' => 'edit',
        ),
        array(
         'type' => 'button',
         'name' => 'gotoemail',
         'label'=> 'LBL_GOTOEMAIL',
         'showOn' => 'view',
        ),
        array(
         'type' => 'button',
         'name' => 'gototop',
         'label'=> 'LBL_GOTOTOP',
         'showOn' => 'view',
        ),
        array (
          'type' => 'actiondropdown',
          'name' => 'main_dropdown',
          'primary' => true,
          'showOn' => 'view',
          'buttons' =>
          array (
            //a bunch more buttons here....
            array (
              'type' => 'rowaction',
              'event' => 'button:kitchensink:click',
              'name' => 'kitchen_sink',
              'label' => 'LBL_KITCHEN_SINK_ACTION',
              'acl_action' => 'view',
            ),
        array (
          'name' => 'sidebar_toggle',
          'type' => 'sidebartoggle',
        ),
      ),
       //the panels...

    In record.js the events that the buttons trigger:

    goToEmailSubpanel scrolls to the archived_emails div

    gotToTop, scrolls to the main-pane container

    And build the

    kitchensinkClicked builds the url for TheKitchenSink with some parameters passed from the Case for good measure, and opens the link in a new window:

    ({
      extendsFrom: 'RecordView',

      initialize: function(options){
          this._super('initialize', [options]);
          //some more custom stuff
          //events for the the buttons to go the email subpanel and back to the top
          this.events = _.extend({}, this.events, {
            'click [name=gotoemail]':'goToEmailSubpanel',
            'click [name=gototop]':'goToTop',
          });
          //events for the various custom buttons
          //e.g. the kitchensink
          this.context.on('button:kitchensink:click', this.kitchensinkClicked, this);
          //and a bunch more...
      },
      goToEmailSubpanel: function(){
        var container = $(".main-pane");
            email_subp = $("div[data-subpanel-link='archived_emails']");
        //takes it back to top so email position  it's relative to top
        //needed in case you scrolled and then hit the button
        container.scrollTop(0);
        container.animate({
            scrollTop: email_subp.position().top
        }, 1000);
      },
      goToTop: function(){
        var container = $(".main-pane");
            //thetop = $(".content-tabs");
        container.animate({
          scrollTop: 0
        }, 1000);
      },
       kitchensinkClicked: function(){
         if(!_.isEmpty(this.model.get('case_keywords_c'))){
            var url = "https://thekitchensink.com/search/TS?search="+this.model.get('case_keywords_c');
              window.open(url);
         }else{
           app.alert.show('no-keywords',{
             level: 'info',
             messages: 'No Keywords to look up',
             autoClose: 'false'
           });
         }
       },
       //....and a bunch more

    HTH

    FrancescaS

  • Thanks Francesca! I think what you have there is the best/safest way to do it.

    Another option I found is when the page loads you can actually change the href attribute of the <a> button element that is added from "javascript:void(0)" to the url you want. $('...the selector...').attr('href','https://www.google.com') so that it's then clickable as a normal link.