using System;
using CMS.CMSHelper;
using CMS.FormControls;
using CMS.GlobalHelper;
using CMS.SettingsProvider;
public partial class CMSFormControls_Classes_SelectQuery : FormEngineUserControl
{
#region "Properties"
///
/// Gets or sets the enabled state of the control.
///
public override bool Enabled
{
get
{
return base.Enabled;
}
set
{
base.Enabled = value;
if (uniSelector != null)
{
uniSelector.Enabled = value;
}
}
}
///
/// Returns ClientID of the textbox with query.
///
public override string ValueElementID
{
get
{
return uniSelector.TextBoxSelect.ClientID;
}
}
///
/// Gets or sets the field value.
///
public override object Value
{
get
{
return uniSelector.Value;
}
set
{
if (uniSelector == null)
{
pnlUpdate.LoadContainer();
}
uniSelector.Value = value;
}
}
#endregion
#region "Methods"
protected void Page_Load(object sender, EventArgs e)
{
if (StopProcessing)
{
uniSelector.StopProcessing = true;
}
else
{
ReloadData();
}
}
///
/// Reloads the data in the selector.
///
public void ReloadData()
{
uniSelector.IsLiveSite = IsLiveSite;
uniSelector.AllowEmpty = false;
uniSelector.SetValue("FilterMode", SettingsObjectType.QUERY);
// Check if user can edit the transformation
bool editAuthorized = CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Design", "EditSQLCode");
bool createAuthorized = editAuthorized;
SetDialog(editAuthorized, createAuthorized);
}
///
/// Returns true if user control is valid.
///
public override bool IsValid()
{
string value = uniSelector.TextBoxSelect.Text.Trim();
// If macro or special value, do not validate
if (ContextResolver.ContainsMacro(value) || value == string.Empty)
{
return true;
}
// Check if culture exists
Query query = QueryProvider.GetQuery(value, false);
if (query == null)
{
ValidationError = GetString("query.queryorclassnotexist").Replace("%%code%%", value);
return false;
}
else
{
return true;
}
}
///
/// Sets edit and new dialog URLs depending on whether the user is authorized.
///
/// True, if edit button should be active, otherwise false
/// True, if new button should be active, otherwise false
private void SetDialog(bool allowEdit, bool allowNew)
{
string baseUrl = "~/CMSModules/DocumentTypes/Pages/Development/DocumentType_Edit_Query_Edit.aspx?editonlycode=true";
if (allowEdit)
{
uniSelector.EditItemPageUrl = URLHelper.AddParameterToUrl(baseUrl, "name", "##ITEMID##");
;
}
if (allowNew)
{
uniSelector.NewItemPageUrl = URLHelper.AddParameterToUrl(baseUrl, "selectedvalue", "##ITEMID##");
}
}
#endregion
}