Create a DropDownButton in the GlobalToolbar

Vote:
 

Hi,

Im stuck with dojo. I try to have a DropDownButton in the GloabToolbar. So far I have managed to have a simple "dijit/form/Button" to call a function

return declare([_Command], {
    id: "ClearCacheButton",
    name: "ClearCache",
    label: "Cache",
    tooltip: "Click to clear server side frontend cache",
    iconClass: "epi-iconTrash",
    canExecute: true,

    _execute: function () {
      clearAllCache();
    }
  });

But as I have two functions with the same purpose, I like to have a DropDownButton, where the editor can choose which cahe to clear. Some thing like

Clear Cache
- Clear all caches
- Clear cache for this page only

So I tried with the "dijit/form/DropDownButton", but I cant get the "DropDownMenu" included. The dojo documentation is not working.

define([
  "dojo/_base/declare",
  "dijit/DropDownMenu", "dijit/MenuItem",
  "epi/shell/command/_Command"
], function (declare, DropDownMenu, MenuItem, _Command) {
  return declare([_Command], {
    id: "ClearSelectedCacheButton",
    name: "ClearSelectedCache",
    label: "Cache",
    tooltip: "Click to clear server side frontend cache",
    iconClass: "epi-iconTrash", //Define your own icon css class here.
    canExecute: true,
    
    dropDown: new DropDownMenu(function () {
      var menuItem1 = new MenuItem({
        label: "Clear all caches",
        iconClass:"dijitEditorIcon dijitEditorIconSave",
        onClick: function(){ clearAllCache(); }
      });
      this.addChild(menuItem1);

      var menuItem2 = new MenuItem({
        label: "Clear cache for this page only",
        iconClass:"dijitEditorIcon dijitEditorIconCut",
        onClick: function(){ clearPageCache(path); }
      });
      this.addChild(menuItem2);
    })
  });

  function clearAllCache() {
    fetch("/api/revalidate-tag?tag=URL", {
      method: "POST",
      headers: {
        "Content-type": "application/json; charset=UTF-8"
      }
    })
      .then((response) => response.json())
      .then((json) => alert("Cache cleared: " + JSON.parse(json.revalidated)));
  }
  
  function clearPageCache(path) {
    fetch("/api/revalidate-path?path=" + path, {
      method: "POST",
      headers: {
        "Content-type": "application/json; charset=UTF-8"
      }
    })
      .then((response) => response.json())
      .then((json) => alert("Cache cleared for page ' + path + ': " + JSON.parse(json.revalidated)));
  }

#324950
Jul 05, 2024 13:28
Vote:
 

Hi Ralph,

When you say global navigation, do you mean the navigation at the very top of the CMS?

I like the way you got the button to working for one function globally. I assume this is your Clear all?

You could extend the standard navigation on page view and add your a button there to clear the cache. Check out the inspectinfind plugin https://github.com/BVNetwork/InspectInIndex/blob/master/src%2FClientResources%2FScripts%2FInspectInIndexView.js this should give you some guidance.

Hopefully you develop the as a plugin as would be really useful to other I am sure.

Paul

#325021
Jul 06, 2024 23:26
Vote:
 

For the single button it workes for now. As this is not urgent, we had to postpone this feature.

But if I'll find out more in some spare time, I'm happy to share.

#330164
Sep 18, 2024 7:49
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.