Last active
December 1, 2017 06:28
-
-
Save kand/4733278 to your computer and use it in GitHub Desktop.
Add a custom dialog as an option in the sidekick. customSidekickDialog.js will add another action to the DEFAULT_ACTIONS list for the sidekick. In this example, the action will open a dialog but, in practice, you could put any action you wanted in the handler. launchSidekick.js is Javascript that should replace the Javascript in your project tha…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set up your file structure something like this: | |
/apps/your-site/components/page | |
-> yourPage | |
-> clientlibs | |
-> js | |
-> customSidekickDialog.js | |
-> .content.xml | |
-> js.txt | |
-> customDialog.xml | |
-> ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function(CQ){ | |
var DIALOG_PATH = '/apps/your-project/path/to/customDialog.xml'; | |
var DIALOG_PROPS = '/jcr:content/were/dialog/properties/should/be/stored'; | |
// add dialog to default actions | |
CQ.wcm.Sidekick.DEFAULT_ACTIONS.push({ | |
context: CQ.wcm.Sidekick.PAGE, | |
text: 'Title of your dialog in sidekick', | |
handler: function() { | |
// set up dialog configuration | |
var dialogConfig = CQ.WCM.getDialogConfig(DIALOG_PATH); | |
dialogConfig.success = function(form, action){ | |
// reload page on dialog success | |
CQ.Util.reload(CQ.WCM.getContentWindow()); | |
}; | |
dialogConfig.failure = function(form, action){ | |
// alert user when dialog fails | |
var resp = CQ.HTTP.buildPostResponseFromHTML(action.response); | |
CQ.Ext.Msg.alert(response.headers[CQ.HTTP.HEADER_MESSAGE]); | |
}; | |
// prepare and show dialog | |
var dialog = CQ.WCM.getDialog(dialogConfig, DIALOG_PATH); | |
dialog.loadContent(this.getPath() + DIALOG_PROPS); | |
dialog.setTitle('Title of your dialog in dialog window'); | |
dialog.show(); | |
} | |
}); | |
})(CQ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// replace sidekick launch in init.jsp with this | |
CQ.WCM.launchSidekick("<%= currentPage.getPath() %>", { | |
propsDialog: "<%= dlgPath == null ? "" : dlgPath %>", | |
locked: <%= currentPage.isLocked() %>, | |
previewReload: "true", | |
actions: CQ.wcm.Sidekick.DEFAULT_ACTIONS // make sure actions is explicitly specified | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment