November Happy Hour will be moved to Thursday December 5th.

Argument på Publicera-knappen

Vote:
 
Jag arbetar med ett fall då kunden vill ha en bekräfta-ruta när publicera-knappen trycks ner om ett argument är uppfyllt. Man ska alltså kunna avbryta publiceringen eller forstätta som vanligt Tack på förhand Martin Hedlund
#12474
Dec 15, 2005 13:25
Vote:
 
Här är en möjlig lösning. Det är en plugin som inte syns. När den kör så hittar den publiceringsknapparna och lägger på javascript på knapparna. Koden nedan är bara ett exempel på hur man kan gå till väga, inget testkört exempel som garanterat fungerar. namespace ExtendedButton { /// /// This class has no UI. It's purpose is to add javascript confirmations /// on the Publish button. /// The reason for register as a plugin is to be able to enter the lifecycle of the page rendering /// specially handling PreRender event when all controls on page are in place. /// /// [ GuiPlugIn( DisplayName = "wont be visible", Description = "", Area = PlugInArea.EditPanel, Url = "" ) ] public class PublishConfirmation : UserControlBase, ICustomPlugInLoader { PlugInDescriptor[] ICustomPlugInLoader.List() { PlugInDescriptor [] plugins = new PlugInDescriptor[0]; this.PageBase.PreRender += new EventHandler( Page_PreRender ); return plugins; } private void Page_Load(object sender, System.EventArgs e) { } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion private void Page_PreRender(object sender, EventArgs e) { // first Find active tab control //index 0 = PreView //index 1 = Edit //index 2 = VersionList int activeTab = GetActiveTab( page.Controls[0] ); switch (activeTab) { //We are only interested to handle publish button on PreView or Edit tab case 0: RegisterConfirmationOnCommandTool( page.Controls[0] ); break; case 1: RegisterConfirmationOnCommandTool( page.Controls[0] ); break; default: break; } } //Recursive function that finds tab ctrl and returns index of the currently active tab private int GetActiveTab( Control ctrl ) { if ( ctrl is EPiServer.SystemControls.Tab ) { EPiServer.SystemControls.Tab command = (EPiServer.SystemControls.Tab) ctrl; if ( command.Active ) return command.Index; } //If not found check child ctls foreach ( Control child in ctrl.Controls ) { int tab = GetActiveTab( child ); if ( tab != -1 ) return tab; } return -1; } //Recursive function that finds ctrl of type CommandTool (publish button e.g.) with name Publish. //It will then add a client javascript to the control for clientside confirmation private void RegisterConfirmationOnCommandTool( Control ctrl ) { if ( ctrl is EPiServer.SystemControls.CommandTool ) { EPiServer.SystemControls.CommandTool command = (EPiServer.SystemControls.CommandTool) ctrl; if (command.Name != null && command.Name.IndexOf("Publish") != -1 ) { command.CustomClickScript = string.Format( "if( !confirm('Are you sure you want to publish page?'))return false;SimulateFormField('Publish','Publish');__doPostBack('{0}$SaveAndPublish','');", command.NamingContainer.ClientID ); } } //Check child ctls foreach ( Control child in ctrl.Controls ) { RegisterConfirmationOnCommandTool( child ); } } } }
#14335
Dec 28, 2005 10:45
* 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.