Skip to main content
some grammar fixes.
Source Link
Glenn Stevens
  • 1.9k
  • 2
  • 18
  • 33

How do I resolve the issue of the browser being Asynchroomasynchronous and each new event will be addbeing added to the event stack.?

In my previous question I gotit was suggested tothat, because of caching, I should wait tilluntil the full component is loaded because of caching. Also this answer was giving to Robert in another topic, see below.

This works all good, the only issue is that isEnabledthe isEnabled function is finished before _onItemLoad_onItemLoad is done, this way return isAvailableisAvailable is always false. Where I would like to check if the component is in the same publication created as being selected.

How do I resolve the issue of the browser being Asynchroom and each new event will be add to the event stack. In my previous question I got suggested to wait till the full component is loaded because of caching. Also this answer was giving to Robert in another topic, see below.

This works all good, the only issue is that isEnabled function is finished before _onItemLoad is done, this way return isAvailable is always false. Where I would like to check if the component is in the same publication created as being selected.

How do I resolve the issue of the browser being asynchronous and each new event being added to the event stack?

In my previous question it was suggested that, because of caching, I should wait until the full component. Also this answer was giving to Robert in another topic, see below.

This works all good, the only issue is the isEnabled function is finished before _onItemLoad is done, this way return isAvailable is always false. Where I would like to check if the component is in the same publication created as being selected.

Tweeted twitter.com/#!/StackTridion/status/378447901833592832
added syntax highlighting to code for readability
Source Link
Bart Koopman
  • 29.6k
  • 3
  • 40
  • 90
/// <summary>
///
/// </summary>
/// <returns>boolean</returns>
Extensions.Unlocalize.prototype.isEnabled = function Unlocalize$isEnabled(selection) {
    var item = $models.getItem(selection.getItem(0)),
        itemTCM = item.getId(),
        pubTCM = null,
        isAvailable = false,
        itemRegex = /.?tcm:(.*?)\-/,
        pubRegex = /.*?\-(.*)-.*/;

console.log("Extensions.Unlocalize.prototype.isEnabled; Started."); 
console.log("Info of parameter item at start: ", item.getInfo());     

    //Make sure the component is loaded before using getOwningPublicationId();
    var onItemLoaded = function Extensions$Unlocalize$_onItemLoaded() {
console.log("Extensions$Unlocalize$_isEnabled; Started."); 
        $evt.removeEventHandler(item, "load", onItemLoaded);
      
        var itemInfo = item.getInfo();
        console.log("Info of parameter item in eventHandler: ", itemInfo);
    
        pubTCM = item.getOwningPublicationId(); 
        pubTCM = pubTCM.match(pubRegex);
        itemTCM = itemTCM.match(itemRegex);
    
        if (itemTCM[1] == pubTCM[1]) {
            isAvailable = true;
        }
    
console.log("Extensions$Unlocalize$_isEnabled; ", isAvailable);         

    };

console.log("Extensions.Unlocalize.prototype.isEnabled; addEventHandler"); 
    $evt.addEventHandler(item, "load", onItemLoaded);

console.log("Extensions.Unlocalize.prototype.isEnabled; item.load()"); 
    item.load(item.isLoaded(true), $const.OpenMode.VIEW);

console.log("Extensions.Unlocalize.prototype.isEnabled; Return."); 

    return isAvailable;
}
/// <summary>
///
/// </summary>
/// <returns>boolean</returns>
Extensions.Unlocalize.prototype.isEnabled = function Unlocalize$isEnabled(selection) {
    var item = $models.getItem(selection.getItem(0)),
        itemTCM = item.getId(),
        pubTCM = null,
        isAvailable = false,
        itemRegex = /.?tcm:(.*?)\-/,
        pubRegex = /.*?\-(.*)-.*/;

    console.log("Extensions.Unlocalize.prototype.isEnabled; Started."); 
    console.log("Info of parameter item at start: ", item.getInfo());     

    //Make sure the component is loaded before using getOwningPublicationId();
    var onItemLoaded = function Extensions$Unlocalize$_onItemLoaded() {
        console.log("Extensions$Unlocalize$_isEnabled; Started."); 
        $evt.removeEventHandler(item, "load", onItemLoaded);
      
        var itemInfo = item.getInfo();
        console.log("Info of parameter item in eventHandler: ", itemInfo);
    
        pubTCM = item.getOwningPublicationId(); 
        pubTCM = pubTCM.match(pubRegex);
        itemTCM = itemTCM.match(itemRegex);
    
        if (itemTCM[1] == pubTCM[1]) {
            isAvailable = true;
        }        
        console.log("Extensions$Unlocalize$_isEnabled; ", isAvailable);         
    };

    console.log("Extensions.Unlocalize.prototype.isEnabled; addEventHandler"); 
    $evt.addEventHandler(item, "load", onItemLoaded);

    console.log("Extensions.Unlocalize.prototype.isEnabled; item.load()"); 
    item.load(item.isLoaded(true), $const.OpenMode.VIEW);

    console.log("Extensions.Unlocalize.prototype.isEnabled; Return."); 
    return isAvailable;
}
/// <summary>
///
/// </summary>
/// <returns>boolean</returns>
Extensions.Unlocalize.prototype.isEnabled = function Unlocalize$isEnabled(selection) {
    var item = $models.getItem(selection.getItem(0)),
        itemTCM = item.getId(),
        pubTCM = null,
        isAvailable = false,
        itemRegex = /.?tcm:(.*?)\-/,
        pubRegex = /.*?\-(.*)-.*/;

console.log("Extensions.Unlocalize.prototype.isEnabled; Started."); 
console.log("Info of parameter item at start: ", item.getInfo());     

    //Make sure the component is loaded before using getOwningPublicationId();
    var onItemLoaded = function Extensions$Unlocalize$_onItemLoaded() {
console.log("Extensions$Unlocalize$_isEnabled; Started."); 
        $evt.removeEventHandler(item, "load", onItemLoaded);
      
        var itemInfo = item.getInfo();
        console.log("Info of parameter item in eventHandler: ", itemInfo);
    
        pubTCM = item.getOwningPublicationId(); 
        pubTCM = pubTCM.match(pubRegex);
        itemTCM = itemTCM.match(itemRegex);
    
        if (itemTCM[1] == pubTCM[1]) {
            isAvailable = true;
        }
    
console.log("Extensions$Unlocalize$_isEnabled; ", isAvailable);         

    };

console.log("Extensions.Unlocalize.prototype.isEnabled; addEventHandler"); 
    $evt.addEventHandler(item, "load", onItemLoaded);

console.log("Extensions.Unlocalize.prototype.isEnabled; item.load()"); 
    item.load(item.isLoaded(true), $const.OpenMode.VIEW);

console.log("Extensions.Unlocalize.prototype.isEnabled; Return."); 

    return isAvailable;
}
/// <summary>
///
/// </summary>
/// <returns>boolean</returns>
Extensions.Unlocalize.prototype.isEnabled = function Unlocalize$isEnabled(selection) {
    var item = $models.getItem(selection.getItem(0)),
        itemTCM = item.getId(),
        pubTCM = null,
        isAvailable = false,
        itemRegex = /.?tcm:(.*?)\-/,
        pubRegex = /.*?\-(.*)-.*/;

    console.log("Extensions.Unlocalize.prototype.isEnabled; Started."); 
    console.log("Info of parameter item at start: ", item.getInfo());     

    //Make sure the component is loaded before using getOwningPublicationId();
    var onItemLoaded = function Extensions$Unlocalize$_onItemLoaded() {
        console.log("Extensions$Unlocalize$_isEnabled; Started."); 
        $evt.removeEventHandler(item, "load", onItemLoaded);
      
        var itemInfo = item.getInfo();
        console.log("Info of parameter item in eventHandler: ", itemInfo);
    
        pubTCM = item.getOwningPublicationId(); 
        pubTCM = pubTCM.match(pubRegex);
        itemTCM = itemTCM.match(itemRegex);
    
        if (itemTCM[1] == pubTCM[1]) {
            isAvailable = true;
        }        
        console.log("Extensions$Unlocalize$_isEnabled; ", isAvailable);         
    };

    console.log("Extensions.Unlocalize.prototype.isEnabled; addEventHandler"); 
    $evt.addEventHandler(item, "load", onItemLoaded);

    console.log("Extensions.Unlocalize.prototype.isEnabled; item.load()"); 
    item.load(item.isLoaded(true), $const.OpenMode.VIEW);

    console.log("Extensions.Unlocalize.prototype.isEnabled; Return."); 
    return isAvailable;
}
Source Link
user219
user219
Loading