|
|
|
|
@@ -8,137 +8,137 @@ using Umbraco.Web.Composing;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.UI.Controls
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents the 'insert macro' button when editing a template which includes the drop down list selector
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Though this would be nicer to do in a UserControl, unfortunatley the way that the ScrollingMenu control is designed it seems that
|
|
|
|
|
/// we have to insert all items via code and loading a UserControl in dynamically is equally ugly.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
[ClientDependency(ClientDependencyType.Css, "splitbutton/splitbutton.css", "UmbracoClient")]
|
|
|
|
|
[ClientDependency(ClientDependencyType.Javascript, "splitbutton/jquery.splitbutton.js", "UmbracoClient", Priority = 100)]
|
|
|
|
|
[ClientDependency(ClientDependencyType.Javascript, "splitbutton/InsertMacroSplitButton.js", "UmbracoClient", Priority = 101)]
|
|
|
|
|
internal class InsertMacroSplitButton : UmbracoControl
|
|
|
|
|
{
|
|
|
|
|
protected LiteralControl ListContainer;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents the 'insert macro' button when editing a template which includes the drop down list selector
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Though this would be nicer to do in a UserControl, unfortunatley the way that the ScrollingMenu control is designed it seems that
|
|
|
|
|
/// we have to insert all items via code and loading a UserControl in dynamically is equally ugly.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
[ClientDependency(ClientDependencyType.Css, "splitbutton/splitbutton.css", "UmbracoClient")]
|
|
|
|
|
[ClientDependency(ClientDependencyType.Javascript, "splitbutton/jquery.splitbutton.js", "UmbracoClient", Priority = 100)]
|
|
|
|
|
[ClientDependency(ClientDependencyType.Javascript, "splitbutton/InsertMacroSplitButton.js", "UmbracoClient", Priority = 101)]
|
|
|
|
|
internal class InsertMacroSplitButton : UmbracoControl
|
|
|
|
|
{
|
|
|
|
|
protected LiteralControl ListContainer;
|
|
|
|
|
|
|
|
|
|
protected override void OnInit(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnInit(e);
|
|
|
|
|
EnsureChildControls();
|
|
|
|
|
}
|
|
|
|
|
protected override void OnInit(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnInit(e);
|
|
|
|
|
EnsureChildControls();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The JS callback to display the dialog modal screen to customize the macro to be inserted into the editor if the
|
|
|
|
|
/// macro has parameters.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string ClientCallbackOpenMacroModel { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The JS callback to display the dialog modal screen to customize the macro to be inserted into the editor if the
|
|
|
|
|
/// macro has parameters.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string ClientCallbackOpenMacroModel { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The JS callback method which accepts an 'alias' parameter that is invoked when clicking the macro button
|
|
|
|
|
/// to insert a macro that has no parameters.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string ClientCallbackInsertMacroMarkup { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The JS callback method which accepts an 'alias' parameter that is invoked when clicking the macro button
|
|
|
|
|
/// to insert a macro that has no parameters.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string ClientCallbackInsertMacroMarkup { get; set; }
|
|
|
|
|
|
|
|
|
|
protected override void CreateChildControls()
|
|
|
|
|
{
|
|
|
|
|
base.CreateChildControls();
|
|
|
|
|
protected override void CreateChildControls()
|
|
|
|
|
{
|
|
|
|
|
base.CreateChildControls();
|
|
|
|
|
|
|
|
|
|
//var menuItemsId = ClientID + "menuitems";
|
|
|
|
|
//var placeHolderId = ClientID + "sbPlaceholder";
|
|
|
|
|
//var menuItemsId = ClientID + "menuitems";
|
|
|
|
|
//var placeHolderId = ClientID + "sbPlaceholder";
|
|
|
|
|
|
|
|
|
|
/*create the list, similar to this, but swap the repeater for real html:
|
|
|
|
|
|
|
|
|
|
<div id="macroMenu" style="width: 285px">
|
|
|
|
|
<asp:Repeater ID="rpt_macros" runat="server">
|
|
|
|
|
<ItemTemplate>
|
|
|
|
|
<div class="macro" rel="<%# DataBinder.Eval(Container, "DataItem.macroAlias")%>"
|
|
|
|
|
data-has-params="<%# DoesMacroHaveSettings(DataBinder.Eval(Container, "DataItem.id").ToString()) %>">
|
|
|
|
|
<%# DataBinder.Eval(Container, "DataItem.macroName")%>
|
|
|
|
|
</div>
|
|
|
|
|
</ItemTemplate>
|
|
|
|
|
</asp:Repeater>
|
|
|
|
|
</div>
|
|
|
|
|
*/
|
|
|
|
|
/*create the list, similar to this, but swap the repeater for real html:
|
|
|
|
|
|
|
|
|
|
//Create the drop down menu list first (it is hidden)
|
|
|
|
|
var divMacroItemContainer = new TagBuilder("div");
|
|
|
|
|
divMacroItemContainer.Attributes.Add("style", "width: 285px;display:none;");
|
|
|
|
|
divMacroItemContainer.Attributes.Add("class", "sbMenu");
|
|
|
|
|
<div id="macroMenu" style="width: 285px">
|
|
|
|
|
<asp:Repeater ID="rpt_macros" runat="server">
|
|
|
|
|
<ItemTemplate>
|
|
|
|
|
<div class="macro" rel="<%# DataBinder.Eval(Container, "DataItem.macroAlias")%>"
|
|
|
|
|
data-has-params="<%# DoesMacroHaveSettings(DataBinder.Eval(Container, "DataItem.id").ToString()) %>">
|
|
|
|
|
<%# DataBinder.Eval(Container, "DataItem.macroName")%>
|
|
|
|
|
</div>
|
|
|
|
|
</ItemTemplate>
|
|
|
|
|
</asp:Repeater>
|
|
|
|
|
</div>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
var macros = Services.MacroService.GetAll().OrderBy(x => x.Name);
|
|
|
|
|
foreach (var macro in macros)
|
|
|
|
|
{
|
|
|
|
|
var divMacro = new TagBuilder("div");
|
|
|
|
|
divMacro.AddCssClass("macro-item");
|
|
|
|
|
divMacro.Attributes.Add("rel", macro.Alias);
|
|
|
|
|
divMacro.Attributes.Add("data-has-params", DoesMacroHaveParameters(macro.Id).ToString().ToLower());
|
|
|
|
|
divMacro.SetInnerText(macro.Name);
|
|
|
|
|
divMacroItemContainer.InnerHtml += divMacro.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*create the button itself, similar to this:
|
|
|
|
|
|
|
|
|
|
<div id="splitButtonMacro" style="display: inline; height: 23px; vertical-align: top;">
|
|
|
|
|
<a href="javascript:openMacroModal();" class="sbLink">
|
|
|
|
|
<img alt="Insert Macro" src="../images/editor/insMacroSB.png" title="Insert Macro"
|
|
|
|
|
style="vertical-align: top;">
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
//Create the drop down menu list first (it is hidden)
|
|
|
|
|
var divMacroItemContainer = new TagBuilder("div");
|
|
|
|
|
divMacroItemContainer.Attributes.Add("style", "width: 285px;display:none;");
|
|
|
|
|
divMacroItemContainer.Attributes.Add("class", "sbMenu");
|
|
|
|
|
|
|
|
|
|
var divSplitButtonWrapper = new TagBuilder("div");
|
|
|
|
|
divSplitButtonWrapper.AddCssClass("sbPlaceHolder");
|
|
|
|
|
divSplitButtonWrapper.Attributes.Add("id", ClientID + "sbPlaceholder");
|
|
|
|
|
var divButton = new TagBuilder("div");
|
|
|
|
|
divButton.Attributes.Add("style", "display: inline; height: 23px; vertical-align: top;");
|
|
|
|
|
var aButton = new TagBuilder("a");
|
|
|
|
|
aButton.Attributes.Add("href", "#"); //will be bound with jquery
|
|
|
|
|
aButton.AddCssClass("sbLink");
|
|
|
|
|
var imgButton = new TagBuilder("img");
|
|
|
|
|
imgButton.Attributes.Add("alt", "Insert Macro");
|
|
|
|
|
imgButton.Attributes.Add("src", this.ResolveUrl(SystemDirectories.Umbraco + "/images/editor/insMacroSB.png"));
|
|
|
|
|
imgButton.Attributes.Add("title", "Insert Macro");
|
|
|
|
|
imgButton.Attributes.Add("style", "vertical-align: top;");
|
|
|
|
|
aButton.InnerHtml = imgButton.ToString();
|
|
|
|
|
divButton.InnerHtml = aButton.ToString();
|
|
|
|
|
divSplitButtonWrapper.InnerHtml = divButton.ToString();
|
|
|
|
|
var macros = Services.MacroService.GetAll().OrderBy(x => x.Name);
|
|
|
|
|
foreach (var macro in macros)
|
|
|
|
|
{
|
|
|
|
|
var divMacro = new TagBuilder("div");
|
|
|
|
|
divMacro.AddCssClass("macro-item");
|
|
|
|
|
divMacro.Attributes.Add("rel", macro.Alias);
|
|
|
|
|
divMacro.Attributes.Add("data-has-params", DoesMacroHaveParameters(macro.Id).ToString().ToLower());
|
|
|
|
|
divMacro.SetInnerText(macro.Name);
|
|
|
|
|
divMacroItemContainer.InnerHtml += divMacro.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ListContainer = new LiteralControl(divMacroItemContainer.ToString() + divSplitButtonWrapper.ToString());
|
|
|
|
|
Controls.Add(ListContainer);
|
|
|
|
|
/*create the button itself, similar to this:
|
|
|
|
|
|
|
|
|
|
// Page.ClientScript.RegisterStartupScript(
|
|
|
|
|
// typeof(InsertMacroSplitButton),
|
|
|
|
|
// ClientID,
|
|
|
|
|
// @"jQuery(document).ready(function() {
|
|
|
|
|
// jQuery('#" + placeHolderId + " a.sbLink').splitbutton({menu:'#" + menuItemsId + "'}); " +
|
|
|
|
|
// "});",
|
|
|
|
|
// true);
|
|
|
|
|
<div id="splitButtonMacro" style="display: inline; height: 23px; vertical-align: top;">
|
|
|
|
|
<a href="javascript:openMacroModal();" class="sbLink">
|
|
|
|
|
<img alt="Insert Macro" src="../images/editor/insMacroSB.png" title="Insert Macro"
|
|
|
|
|
style="vertical-align: top;">
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
Page.ClientScript.RegisterStartupScript(
|
|
|
|
|
typeof(InsertMacroSplitButton),
|
|
|
|
|
typeof(InsertMacroSplitButton).Name, //same key for all instancees, we should only render once
|
|
|
|
|
@"jQuery(document).ready(function() {
|
|
|
|
|
var splitButton = new Umbraco.Controls.InsertMacroSplitButton({
|
|
|
|
|
openMacroModel: " + ClientCallbackOpenMacroModel + @",
|
|
|
|
|
insertMacroMarkup: " + ClientCallbackInsertMacroMarkup + @"
|
|
|
|
|
});
|
|
|
|
|
splitButton.init();
|
|
|
|
|
});",
|
|
|
|
|
true);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
var divSplitButtonWrapper = new TagBuilder("div");
|
|
|
|
|
divSplitButtonWrapper.AddCssClass("sbPlaceHolder");
|
|
|
|
|
divSplitButtonWrapper.Attributes.Add("id", ClientID + "sbPlaceholder");
|
|
|
|
|
var divButton = new TagBuilder("div");
|
|
|
|
|
divButton.Attributes.Add("style", "display: inline; height: 23px; vertical-align: top;");
|
|
|
|
|
var aButton = new TagBuilder("a");
|
|
|
|
|
aButton.Attributes.Add("href", "#"); //will be bound with jquery
|
|
|
|
|
aButton.AddCssClass("sbLink");
|
|
|
|
|
var imgButton = new TagBuilder("img");
|
|
|
|
|
imgButton.Attributes.Add("alt", "Insert Macro");
|
|
|
|
|
imgButton.Attributes.Add("src", this.ResolveUrl(SystemDirectories.Umbraco + "/images/editor/insMacroSB.png"));
|
|
|
|
|
imgButton.Attributes.Add("title", "Insert Macro");
|
|
|
|
|
imgButton.Attributes.Add("style", "vertical-align: top;");
|
|
|
|
|
aButton.InnerHtml = imgButton.ToString();
|
|
|
|
|
divButton.InnerHtml = aButton.ToString();
|
|
|
|
|
divSplitButtonWrapper.InnerHtml = divButton.ToString();
|
|
|
|
|
|
|
|
|
|
ListContainer = new LiteralControl(divMacroItemContainer.ToString() + divSplitButtonWrapper.ToString());
|
|
|
|
|
Controls.Add(ListContainer);
|
|
|
|
|
|
|
|
|
|
// Page.ClientScript.RegisterStartupScript(
|
|
|
|
|
// typeof(InsertMacroSplitButton),
|
|
|
|
|
// ClientID,
|
|
|
|
|
// @"jQuery(document).ready(function() {
|
|
|
|
|
// jQuery('#" + placeHolderId + " a.sbLink').splitbutton({menu:'#" + menuItemsId + "'}); " +
|
|
|
|
|
// "});",
|
|
|
|
|
// true);
|
|
|
|
|
|
|
|
|
|
Page.ClientScript.RegisterStartupScript(
|
|
|
|
|
typeof(InsertMacroSplitButton),
|
|
|
|
|
typeof(InsertMacroSplitButton).Name, //same key for all instancees, we should only render once
|
|
|
|
|
@"jQuery(document).ready(function() {
|
|
|
|
|
var splitButton = new Umbraco.Controls.InsertMacroSplitButton({
|
|
|
|
|
openMacroModel: " + ClientCallbackOpenMacroModel + @",
|
|
|
|
|
insertMacroMarkup: " + ClientCallbackInsertMacroMarkup + @"
|
|
|
|
|
});
|
|
|
|
|
splitButton.init();
|
|
|
|
|
});",
|
|
|
|
|
true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool DoesMacroHaveParameters(int macroId)
|
|
|
|
|
{
|
|
|
|
|
bool hasParameters;
|
|
|
|
|
using (var scope = Current.ScopeProvider.CreateScope())
|
|
|
|
|
{
|
|
|
|
|
private bool DoesMacroHaveParameters(int macroId)
|
|
|
|
|
{
|
|
|
|
|
bool hasParameters;
|
|
|
|
|
using (var scope = Current.ScopeProvider.CreateScope())
|
|
|
|
|
{
|
|
|
|
|
hasParameters = scope.Database.ExecuteScalar<int>("SELECT COUNT(*) from cmsMacroProperty where macro=@macroId", new { macroId }) > 0;
|
|
|
|
|
scope.Complete();
|
|
|
|
|
}
|
|
|
|
|
return hasParameters;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return hasParameters;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|