Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-4943

Provide a before destroy callback / event when replacing an embedded instance for cleanup

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Normal
    • Resolution: Done
    • Affects Version/s: 9.6.0
    • Fix Version/s: 9.6.0
    • Component/s: None
    • Security Level: Jimmy
    • Labels:

      Description

      User Story

      As an developper, I want to unsubscribe or update elements located on my outer page when i replace an embedded instance by a different one.

      This could be a callback or a listener to be triggered by the the zEmbedded.load method on the old desktop before cleaning up the page.

       

      Acceptance Criteria

      Developer can execute an action before the old desktop is unloaded. 

      Details

      POC:

      var originalDestroy = zEmbedded.destroy;
      zEmbedded.destroy = function (domId, skipError) {
      	if (typeof zk === 'undefined') {
      				if (skipError) return;
      				else throw new Error('zk is not loaded.');
      			}
      			var n = document.getElementById(domId);
      			if (n) {
      				var page = n.hasChildNodes() ? zk.$(n.firstChild) : null;
      				if (page) {
      					page.desktop.fire("onBeforeDestroy");
      				}
      			}
      
      	var result = originalDestroy.apply(this,arguments);
      	return result;
      }
      
      function loadZk(){
      	zEmbedded.load('zkapp', 'http://localhost:8080/zkembedded-app/index.zul?myparam=init-from-client-side')
      		.then(function(result) {
      			var myWin = result.widget;
      			myWin.desktop.listen({onBeforeDestroy:function(){
      				console.log("before destroy this desktop")
      			}});
      			
      		})
      		.catch(function(error) {
      			console.error(error);
      		});
      }
      clientSideButton.addEventListener('click', function() {
      	loadZk();
      });
      

        Attachments

          Activity

            People

            Assignee:
            DevChu DevChu
            Reporter:
            MDuchemin MDuchemin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: