Delete confirmation when deleting from floating menu in a page editor in sitecore - sitecore

I am very new sitecore, working with sitecore 7.
The question is when I am in a page editor, when I delete an item using the floating menu 'delete' function, It just deletes the item.
Customer requirement is to add a confirmation box here. Something like 'are you sure to delete'. and two typical buttons(yes/cancel).
is that even possible? any help would be appreciated.
EDIT:
In the picture below, The red cross, is a delete/remove button. If I click it just deletes. I want to show confirmation upon clicking the button.
EDIT 2:
Ok, I am writing a custom command.
I have added a new button. The target is this new button will ask if the user wants to remove the component or not. And if user says 'yes' it will do the same as the default built in remove button does.
Code:
public class RemoveWithNoti:Sitecore.Shell.Applications.WebEdit.Commands.WebEditCommand
{
public override void Execute(CommandContext context)
{
Context.ClientPage.Start(this, "Run", context.Parameters);
}
protected static void Run(ClientPipelineArgs args)
{
if (args.IsPostBack)
{
if (args.HasResult)
{
//Here I need to call "chrome:rendering:delete" this . I just dont know how to!!
}
}
else
{
SheerResponse.Confirm("Are you certain that you want to remove this component");
args.WaitForPostBack();
}
}
}
How do I call chrome:rendering:delete from code??

The "chrome:rendering:delete" event is handled on the client side by javascript. Here is the exact places:
/sitecore/shell/Applications/Page Modes/ChromeTypes/RenderingChromeType.js file:
handleMessage: function(message, params, sender) {
switch (message) {
...
case "chrome:rendering:delete":
this.deleteControl();
break;
...
},
You can do something like this in the same file:
deleteControl: function() {
if(confirm('Are you sure to remove this component?')){
var placeholder = this.getPlaceholder();
if (placeholder) {
placeholder.type.deleteControl(this.chrome);
}
}
}

Related

SwiftUI: append menu entry to group "View" after "Enter Full Screen"

I'd like to append a new menu entry right below "Enter Full Screen", but I am failing to find the right CommandGroupPlacement property.
CommandGroup(after: .<what needs to be put here??>) {
//my buttons here
}
Attempting to override "View" results in just another group with the same name (see image).
CommandMenu("View") {
//add button here
}
Shoutout to Majid Jabrayilov for his blogpost on this: https://swiftwithmajid.com/2020/11/24/commands-in-swiftui/
To find a solution to my above issue though I still had to think a bit around the corner–what does work is this:
CommandGroup(before: .toolbar) {
Button("Foo") {
}
}
This works, because the toolbar menu entry is located within "View" (even thought I don't have a toolbar in my app, the placement still works nonetheless...)
You said you were looking for the proper CommandGroupPlacement so for your case (relative to full screen mode), you would technically want CommandGroupPlacement.sidebar. CommandGroupPlacement.toolbar works because toolbar options live in the View menu, though you have none set.
/// Example in a CommandsBuilder
CommandGroup(after: CommandGroupPlacement.sidebar) {
Button("New View Action", action: { print("After sidebar menu options") }).keyboardShortcut("s", modifiers: [.command, .option, .control, .function]
}
This should also come in handy for others. The Apple documentation that corresponds to this: CommandGroupPlacement

Copy Presentation Details to new PlaceHolder programmatically Sitecore 7.2

currently I am working on a page that generates a print view of a specific item. So this means I dont need all the stuff from my MainLayout like Navigation etc.
For this reason I have created a new Layout that only has a placeholder.
Lets call this PrintLayout.aspx:
<sc:placeholder ID="PlPrint" runat="server" key="phPrintOutput"></sc:placeholder>
In the code behind I have a method that fetches the renderings from the item, but I am stuck at the point where I want to copy them to my phPrintOutput Placeholder on the fly:
public void AddPresentationDetailsToPlaceHolder(Item item)
{
List<RenderingReference> renderings = item.Visualization.GetRenderings(Sitecore.Context.Device, false).ToList();
foreach(RenderingReference r in renderings)
{
// How can I apply the renderings on the fly to my phPrintOutput Placeholder??
}
}
Of course it is very important that every sublayout keeps it current datasource.
Any help would be appreciated, thank you all
You only require to add the control to the placeholder. To do so, please see the code below:
public void AddPresentationDetailsToPlaceHolder(Item item)
{
List<RenderingReference> renderings = item.Visualization.GetRenderings(Sitecore.Context.Device, false).ToList();
foreach(RenderingReference r in renderings)
{
if(r.RenderingID == new ID("Rendering Id you want to be displayed on layout"))
{
this.PlPrint.Controls.Add(r.GetControl());
}
}
}
This will automatically add the rendering to the layout.

Sitecore custom ribbon button not working

I have created a custom ribbon button following the steps mentioned in http://jondjones.com/how-to-add-a-custom-sitecore-button-to-the-editor-ribbon/
I can see the button appearing in sitecore:
Custom button
Command does not get triggered when clicked on the button.
Below is my code:
using System;
using Sitecore.Shell.Applications.Dialogs.ProgressBoxes;
using Sitecore.Shell.Framework.Commands;
namespace SitecoreVsPoc.Commands
{
public class TranslateContent : Command
{
private static readonly object Monitor = new object();
public override void Execute(CommandContext context)
{
if (context == null)
return;
try
{
ProgressBox.Execute("Arjun", "Title", "Applications/32x32/refresh.png", Refresh);
}
catch (Exception ex)
{
Sitecore.Diagnostics.Log.Error("Error!", ex, this);
}
}
public void Refresh(params object[] parameters)
{
// Do Stuff
}
}
}
Below is the command I have registered in commands.config:
<command name="contenteditor:translatecontent" type="SitecoreVsPoc.Commands.TranslateContent,SitecoreVsPoc" />
Note: I am using Sitecore 8.2 initial release.
Can someone suggest a solution for this?
In Sitecore 8 it was changed the way you add Ribbon button. As far I see your link is from Sitecore 7 or 6.
To create the new button item for the Experience Editor ribbon:
In the Core database, open the Content Editor and navigate to /sitecore/content/Applications/WebEdit/Ribbons/WebEdit/Page Editor/Edit.
Create a new item based on the relevant ribbon control template, for example, the Small Button template. The templates are located at /sitecore/templates/System/Ribbon/.
For the new item, add the following information:
In the Header field, enter the display name of the button.
In the ID field, enter a unique identifier for the item. For example, you can include the ribbon group name in the ID.
In the Icon field, enter the path to the relevant icon. Depending on the button you create, adjust the icon size accordingly.
Open Sitecore Rocks and add the relevant control rendering, for example SmallButton, to the layout of the button item you created.
Enter a unique ID for the rendering.
For other SPEAK controls, you can point to another item in the Data Source field and specify the configuration in this other item.
Important
More informations you can find here: https://doc.sitecore.net/sitecore_experience_platform/content_authoring/the_editing_tools/the_experience_editor/customize_the_experience_editor_ribbon
http://reyrahadian.com/2015/04/15/sitecore-8-adding-edit-meta-data-button-in-experience-editor/
Before it was very simple, you didn't need to add new code:
https://blog.istern.dk/2012/05/21/running-sitecore-field-editor-from-a-command/

How to override this buttons?

When I trying to add a new record for a One2many tree, I've got a new pop up from(like the image below), I've need validate every value added to the tree, for that, I used onchange methods but they don't work properly...I would like override the method called when I click over the 'Save & Close' button, I tried overriding the write method, but in this way I don't have so many control over the error message what I want show for every single record added. I'm sure the best way to do what I need is get the name for method called when I clicked over the Save & Close method(In other words what method send the values from popup from to the One2many tree?). Please please HELPPP ME!
EDIT: Or how can I call a specific from(wizard) clicking on Add an item???
Call method on Button "Save & Close"
Add Js in module and do like this.
In js file:
openerp.module_name = function(instance) {
var QWeb = openerp.web.qweb;
_t = instance.web._t;
instance.web.FormView.include({
load_form: function(data) {
var self = this;
this.$el.find('.oe_abstractformpopup-form-save').click(this.on_button_save);
return self._super(data);
},
on_button_save: function() {
this.dataset.index = null;
this.do_show();
console.log('Save & Close button method call...');
},
});
};

In Sitecore how to open a custom Sitecore app by right clicking on a content item?

I want to be able to right click on a content item in Sitecore and then select something like "Run My App" in the context menu. Then in the app that runs I need to be able to reference the content item that was right clicked. Is this possible?
Yes you can do this, its not as hard as it sounds.
You want to drop into the Core database and open up the content editor. The right click menu is defined within the sitecore/content/Applications/Content Editor/Context Menus/Default
The items within that folder are what you see when you right-click an item in the tree. So you can add a new item there with a template of Menu Item.
If you look at the existing ones, most of them send a message to the Sitecore Desktop. These messages are the commands defined in /App_Config/Commands.config. I can't see anything in there that would just launch another Sitecore application, so you would need to create a new command to do that. To create one, just inherit from the Sitecore.Shell.Framework.Commands.Command class. That passes in a CommandContext which will holds a collection of Items.
public class DemoCommand: Command
{
#region Overrides of Command
/// <summary>
/// Executes the command in the specified context.
/// </summary>
/// <param name="context">The context.</param>
public override void Execute(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
var parameters = new NameValueCollection();
if (context.Items != null && context.Items.Length == 1)
{
var item = context.Items[0];
parameters["id"] = item.ID.ToString();
}
Context.ClientPage.Start(this, "Run", parameters);
}
#endregion
public CommandState QueryStat(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
return CommandState.Enabled;
}
protected static void Run(ClientPipelineArgs args)
{
Assert.ArgumentNotNull(args, "args");
SheerResponse.CheckModified(false);
SheerResponse.Broadcast(
SheerResponse.ShowModalDialog(
"[Path to your application here]"
),
"Shell");
}
}
To get the item passed over, in your message call - just pass the variable $Target.
So the field Message in the Menu Item would be something like:
item:runMyApplication(id=$Target)
Hope that makes sense :)