5

I need to refresh the list in the GUI after a component of a certain type has been created. I already figured out how to refresh the list:

$display.getView().refreshList();

But now I want to have this fired when the popup is closed (or when the save button is clicked) OR when you see the title of the newly created item appear in the list.

(the reason I want the list to refresh is that a 2nd component is created by the EventSystem, which the user should be able to see...)

This only needs to run when a (multimedia) component of a certain schema has been created...

Does anyone know how to hook up to either one of these events?

UPDATE:

Scenario: users upload a multimedia component using a specific schema; during the save, the binary is moved to a (temporary) CDN location and a second component is created holding the path to the file on CDN. The original MM component is deleted. So, after saving, the user should see the newly created component and not the (deleted) MM component.

External multimedia components are not an option, since some of the images are under embargo and may not be reachable on the live website yet.

Some FTP upload mechanism is not an option either, since that takes too much time according to client.

I now have this all working using the EventSystem, but I'm left with a deleted component in the folders list and a not yet visible component that the user should actually see, after saving...

2 Answers 2

3

I would update the model object for the list, instead of calling "refreshList" in the editor. Anything that uses the data (such as the folder list view) will automatically be updated that way.

The model object for the Component will fire a "save" event. Hook into that, find out the ID of its parent Folder, and look up the appropriate list model object in the list registry.

Here is some example code:

function RefreshAfterSave(event)
{
    var item = event.source;
    var listRegistry = $models.getListsRegistry();
    for (var i = 0; i < listRegistry.length; i++) 
    { 
        var list = $models.getItem(listRegistry[i]);
        if (list.getParentId() == item.getOrganizationalItemId())
        {
            list.load(true);
            return;
        }
    }
}

Don't forget to hook into the "save" event for the Component - for instance:

$evt.addEventHandler($display.getItem(), "save", RefreshAfterSave)

And remove the event handler again when appropriate (using $evt.removeEventHandler). You'll probably want to check if the item has been saved for the first time and such, as opposed to always refreshing the list.

5
  • thanks Peter. Please check my update as for the requirements. Your sample seems to work great in Firefox, but Chrome somehow still shows the deleted component. I have to do another refresh to see the final list. After saving a component, the list is updated with a new row; can't I hook into that event somehow? Jul 4, 2013 at 7:21
  • Oh I see - that's quite different indeed. Your problem is likely that the "save" event is also caught by the list model object and a new entry is added dynamically to the list (to avoid needing a full refresh). You might be able to prevent it by adding a second parameter called "pipeline" to RefreshAfterSave and setting its "stop" property to true (pipeline.stop = true;). But I think that only works for Commands. Jul 4, 2013 at 9:12
  • You could consider simply adding a timeout to the refresh action -- executing it a short while after, which lets the other event handlers do their thing first. Jul 4, 2013 at 9:17
  • I would also like to suggest that you simply change the existing MM Component instead of deleting it. You wouldn't get weird issues from the item being deleted immediately upon creation, users can still see the thumbnail of the image, etc. You could just have the CDN link in a metadata field. Jul 4, 2013 at 9:25
  • The refreshing option doesn't seem to work, that probably has to do with the fact that the popup has been closed in the meantime. The idea is to move all binaries out of Tridion, so keeping the item around is not really an option, unfortunately. Jul 4, 2013 at 13:17
2

You can try to override the SaveClose command (not supported extension).

Tridion.Cme.Extensions.SaveClose.prototype._originalexecute = Tridion.Cme.Commands.SaveClose.prototype._execute;

Tridion.Cme.Commands.SaveClose.prototype._execute = Custom$SaveClose$_execute(selection) {
    var itemUri = selection.getItem(0);
    var item = $models.getItem(itemUri);

    if (item.getItemType() == "tcm:16") {
    if (item.getChanged()) {
            $evt.addEventListener(item, "save", this.getDelegate(this._OnItemSaved));
        }
    }    
    this._originalexecute();
};


Tridion.Cme.Extensions.SaveClose.prototype._OnItemSaved = Custom$SaveClose$_OnItemSaved() {
    // Refresh the view here.
};

In the source code above I am saving the original _execute method for the SaveClose command and then add some extra logic and also calling the original SaveClose comamnd.

You may ask, where I should put this code, well, there are several places for this one, I think by executing this code after the ComponentView is completely loaded is a good place, Please refer to this a in order to get some reference.

Reference Answer here.

1
  • Thanks Eric. I've put the sample javascript in, but what do I have to put in place for 'Custom$SaveClose$...'? I now get a ReferenceError: Custom$SaveClose$_execute is not defined Jul 2, 2013 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.