javascriptsitecoresitecore8sitecore-speak-ui

Sitecore 8 Speak UI - Call Pagecode Javascript from HTMLTemplate link


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.


Solution

  • 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.