Sitecore 8 Speak UI - Call Pagecode Javascript from HTMLTemplate link

308 Views Asked by At

I am working on ListControl and one of the columns has Delete link which I am formatting using HTMLTemplate as follows:

<a href="javascript: app.showConfirmation()" >Delete</a>

My Javascript looks as follows:

define(["sitecore", function (Sitecore) {
  var DestinationRules = Sitecore.Definitions.App.extend({
      initialized: function () {
          this.processDestinationRules();
      },
      showConfirmation: function () {
          alert('here');

      },

  });

  return DestinationRules;
});

For some reason, I am not able to call showConfirmation(). It says is undefined. I even tried Sitecore.Speak.app.showconfirmation() but not working.

I tried my best to search online but not able to find much help around calling function through controls embedded inside HTMLTemplate.

My next step is to call DialogWindow.

Please if you can help me with the syntax of the above. Thanks in advance.

2

There are 2 best solutions below

0
Parry Brookes On BEST ANSWER

Finally, managed to do this. Always knew that it can be done this way but did not like the way its done.

The Delete link in List control opens up a confirmation Dialogue window. And if user selects Yes then it calls the app.onDeleteYes()

The HtmlMarkup for the column:

<a href="javascript:destinationRulePage.showDeleteDialog({{itemId}});">Delete</a>

Added a button called btnDelete with visibility set to false.

Added following function, outside the scope of App:

var destinationRulePage = (function () {
    var self = this;
    self.showDeleteDialog = function (id) {
        $("button[data-sc-id='btnYes']").attr("data-sc-click",
            "javascript:app.onDeleteYes(" + id + ");");
        $("button[data-sc-id='btnDelete']").click();
    }
    return self;
}())

This does the job for me. Thanks.

0
Parry Brookes On

Fixed it in a different way.

I wanted to show in-line Delete button in each row of the Listcontrol. Could not figure out way to call the

javascript: app.showConfirmation()

I changed the way to delete the record:

  • Have one Delete button outside the ListControl.
  • Enable/Disable the Delete button based on binding ListControl.HasSelectedItem.
  • On click of the Delete button, call showConfirmation()

As of now seems to be a better way. Sitecore itself uses similar approach for "Kicking off" users. Can be found here:

/sitecore/client/Applications/LicenseOptions/KickUser

Hope that helps. Thanks.