PageRenderTime 63ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/CMSModules/AdminControls/Controls/Class/FieldEditor/FieldEditor.ascx.cs

https://bitbucket.org/mchudo89/cms.io.rackspace-with-kentico
C# | 4441 lines | 3254 code | 594 blank | 593 comment | 625 complexity | 7e1a44de649d7a392a8359477eecba91 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Runtime.InteropServices;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Text;
  10. using System.Xml;
  11. using CMS.CMSHelper;
  12. using CMS.DataEngine;
  13. using CMS.EventLog;
  14. using CMS.ExtendedControls;
  15. using CMS.FormControls;
  16. using CMS.FormEngine;
  17. using CMS.GlobalHelper;
  18. using CMS.PortalEngine;
  19. using CMS.SettingsProvider;
  20. using CMS.SiteProvider;
  21. using CMS.UIControls;
  22. using CMS.ExtendedControls.ActionsConfig;
  23. using CMS.DocumentEngine;
  24. using CMS.IO;
  25. [Guid("B1E7505C-1699-4872-9A02-6D17FD661ABA")]
  26. public partial class CMSModules_AdminControls_Controls_Class_FieldEditor_FieldEditor : CMSUserControl
  27. {
  28. #region "Events"
  29. /// <summary>
  30. /// Event raised when OK button is clicked and before xml definition is changed.
  31. /// </summary>
  32. public event EventHandler OnBeforeDefinitionUpdate;
  33. /// <summary>
  34. /// Event raised when OK button is clicked and after xml definition is changed.
  35. /// </summary>
  36. public event EventHandler OnAfterDefinitionUpdate;
  37. /// <summary>
  38. /// Event raised when new field is created and form definition is saved.
  39. /// </summary>
  40. public event OnFieldCreatedEventHandler OnFieldCreated;
  41. /// <summary>
  42. /// Event raised when field name was changed.
  43. /// </summary>
  44. public event OnFieldNameChangedEventHandler OnFieldNameChanged;
  45. #endregion
  46. #region "Variables"
  47. private FormInfo fi = null;
  48. private FormFieldInfo ffi = null;
  49. private FormCategoryInfo fci = null;
  50. private IEnumerable<string> columnNames = null;
  51. private bool mShowFieldVisibility = false;
  52. private bool mDevelopmentMode = false;
  53. private string mClassName = String.Empty;
  54. private string mImageDirectoryPath = null;
  55. private bool mDisplaySourceFieldSelection = true;
  56. private int mWebPartId = 0;
  57. private FieldEditorModeEnum mMode;
  58. private FieldEditorControlsEnum mDisplayedControls = FieldEditorControlsEnum.ModeSelected;
  59. private bool mEnableSystemFields = false;
  60. private bool mEnableMacrosForDefaultValue = true;
  61. private string mDisplayIn = String.Empty;
  62. private HeaderAction btnSave;
  63. private HeaderAction btnSimplified;
  64. private HeaderAction btnAdvanced;
  65. private bool mIsWizard;
  66. #endregion
  67. #region "Properties"
  68. /// <summary>
  69. /// Messages placeholder
  70. /// </summary>
  71. public override MessagesPlaceHolder MessagesPlaceHolder
  72. {
  73. get
  74. {
  75. return plcMess;
  76. }
  77. }
  78. /// <summary>
  79. /// Indicates if control is used on live site.
  80. /// </summary>
  81. public override bool IsLiveSite
  82. {
  83. get
  84. {
  85. return base.IsLiveSite;
  86. }
  87. set
  88. {
  89. hdrActions.IsLiveSite = value;
  90. plcMess.IsLiveSite = value;
  91. base.IsLiveSite = value;
  92. }
  93. }
  94. /// <summary>
  95. /// Adjust the context in which the attribute can be displayed.
  96. /// </summary>
  97. public string DisplayIn
  98. {
  99. get
  100. {
  101. return mDisplayIn;
  102. }
  103. set
  104. {
  105. mDisplayIn = value;
  106. }
  107. }
  108. /// <summary>
  109. /// Indicates if system fields from tables CMS_Tree and CMS_Document are offered to the user.
  110. /// </summary>
  111. public bool EnableSystemFields
  112. {
  113. get
  114. {
  115. return mEnableSystemFields;
  116. }
  117. set
  118. {
  119. mEnableSystemFields = value;
  120. databaseConfiguration.EnableSystemFields = value;
  121. }
  122. }
  123. /// <summary>
  124. /// Indicates if field visibility selector should be displayed.
  125. /// </summary>
  126. public bool ShowFieldVisibility
  127. {
  128. get
  129. {
  130. return mShowFieldVisibility;
  131. }
  132. set
  133. {
  134. mShowFieldVisibility = value;
  135. fieldAppearance.ShowFieldVisibility = value;
  136. }
  137. }
  138. /// <summary>
  139. /// Indicates if field editor works in development mode.
  140. /// </summary>
  141. public bool DevelopmentMode
  142. {
  143. get
  144. {
  145. return mDevelopmentMode;
  146. }
  147. set
  148. {
  149. fieldAppearance.DevelopmentMode = value;
  150. mDevelopmentMode = value;
  151. }
  152. }
  153. /// <summary>
  154. /// Class name.
  155. /// </summary>
  156. public string ClassName
  157. {
  158. get
  159. {
  160. return mClassName;
  161. }
  162. set
  163. {
  164. mClassName = value;
  165. fieldAppearance.ClassName = value;
  166. }
  167. }
  168. /// <summary>
  169. /// Coupled class name.
  170. /// </summary>
  171. public string CoupledClassName
  172. {
  173. get;
  174. set;
  175. }
  176. /// <summary>
  177. /// Header actions control.
  178. /// </summary>
  179. public override HeaderActions HeaderActions
  180. {
  181. get
  182. {
  183. return hdrActions;
  184. }
  185. }
  186. /// <summary>
  187. /// Directory path for images.
  188. /// </summary>
  189. public string ImageDirectoryPath
  190. {
  191. get
  192. {
  193. if (String.IsNullOrEmpty(mImageDirectoryPath))
  194. {
  195. mImageDirectoryPath = "CMSModules/CMS_Class/";
  196. }
  197. return mImageDirectoryPath;
  198. }
  199. set
  200. {
  201. if (!value.EndsWithCSafe("/"))
  202. {
  203. mImageDirectoryPath = value + "/";
  204. }
  205. else
  206. {
  207. mImageDirectoryPath = value;
  208. }
  209. }
  210. }
  211. /// <summary>
  212. /// Indicates if display source field selection.
  213. /// </summary>
  214. public bool DisplaySourceFieldSelection
  215. {
  216. get
  217. {
  218. return mDisplaySourceFieldSelection;
  219. }
  220. set
  221. {
  222. mDisplaySourceFieldSelection = value;
  223. }
  224. }
  225. /// <summary>
  226. /// Webpart ID.
  227. /// </summary>
  228. public int WebPartId
  229. {
  230. get
  231. {
  232. return mWebPartId;
  233. }
  234. set
  235. {
  236. mWebPartId = value;
  237. }
  238. }
  239. /// <summary>
  240. /// Field editor mode.
  241. /// </summary>
  242. public FieldEditorModeEnum Mode
  243. {
  244. get
  245. {
  246. return mMode;
  247. }
  248. set
  249. {
  250. mMode = value;
  251. fieldAppearance.Mode = value;
  252. }
  253. }
  254. /// <summary>
  255. /// Type of custom controls that can be selected from the control list in FieldEditor.
  256. /// </summary>
  257. public FieldEditorControlsEnum DisplayedControls
  258. {
  259. get
  260. {
  261. return mDisplayedControls;
  262. }
  263. set
  264. {
  265. mDisplayedControls = value;
  266. fieldAppearance.DisplayedControls = value;
  267. }
  268. }
  269. /// <summary>
  270. /// Indicates if simplified mode is enabled.
  271. /// </summary>
  272. public bool EnableSimplifiedMode
  273. {
  274. get;
  275. set;
  276. }
  277. /// <summary>
  278. /// Form XML definition.
  279. /// </summary>
  280. public string FormDefinition
  281. {
  282. get
  283. {
  284. return ValidationHelper.GetString(ViewState["FormDefinition"], "");
  285. }
  286. set
  287. {
  288. ViewState["FormDefinition"] = value;
  289. }
  290. }
  291. /// <summary>
  292. /// Enable or disable the option to use macros as default value.
  293. /// </summary>
  294. public bool EnableMacrosForDefaultValue
  295. {
  296. get
  297. {
  298. return mEnableMacrosForDefaultValue;
  299. }
  300. set
  301. {
  302. mEnableMacrosForDefaultValue = value;
  303. }
  304. }
  305. /// <summary>
  306. /// Gets or sets value indicating if control is placed in wizard.
  307. /// </summary>
  308. public bool IsWizard
  309. {
  310. get
  311. {
  312. return mIsWizard;
  313. }
  314. set
  315. {
  316. mIsWizard = value;
  317. categoryEdit.IsWizard = value;
  318. fieldAdvancedSettings.IsWizard = value;
  319. }
  320. }
  321. /// <summary>
  322. /// Indicates if Field Editor is used as alternative form.
  323. /// </summary>
  324. public bool IsAlternativeForm
  325. {
  326. get;
  327. set;
  328. }
  329. /// <summary>
  330. /// Gets or sets alternative form full name.
  331. /// </summary>
  332. public string AlternativeFormFullName
  333. {
  334. get;
  335. set;
  336. }
  337. /// <summary>
  338. /// Shows in what control is this basic form used.
  339. /// </summary>
  340. public FormTypeEnum FormType
  341. {
  342. get
  343. {
  344. return simpleMode.FormType;
  345. }
  346. set
  347. {
  348. simpleMode.FormType = value;
  349. controlSettings.FormType = value;
  350. }
  351. }
  352. /// <summary>
  353. /// Enables or disables to edit <see cref='CMS.FormEngine.FormFieldInfo.Inheritable'> settings.
  354. /// </summary>
  355. public bool ShowInheritanceSettings
  356. {
  357. get
  358. {
  359. return fieldAppearance.ShowInheritanceSettings;
  360. }
  361. set
  362. {
  363. fieldAppearance.ShowInheritanceSettings = value;
  364. }
  365. }
  366. #endregion
  367. #region "Private properties"
  368. /// <summary>
  369. /// Returns True if system fields are enabled and one of them is selected.
  370. /// </summary>
  371. private bool IsSystemFieldSelected
  372. {
  373. get
  374. {
  375. return databaseConfiguration.IsSystemFieldSelected;
  376. }
  377. }
  378. /// <summary>
  379. /// Selected mode.
  380. /// </summary>
  381. private FieldEditorSelectedModeEnum SelectedMode
  382. {
  383. get
  384. {
  385. FieldEditorSelectedModeEnum mode;
  386. if (ViewState["SelectedMode"] == null)
  387. {
  388. mode = GetDefaultSelectedMode();
  389. }
  390. else
  391. {
  392. switch (ValidationHelper.GetInteger(ViewState["SelectedMode"], 0))
  393. {
  394. case 0:
  395. mode = FieldEditorSelectedModeEnum.Simplified;
  396. break;
  397. case 1:
  398. mode = FieldEditorSelectedModeEnum.Advanced;
  399. break;
  400. default:
  401. mode = GetDefaultSelectedMode();
  402. break;
  403. }
  404. }
  405. return mode;
  406. }
  407. set
  408. {
  409. switch (value)
  410. {
  411. case FieldEditorSelectedModeEnum.Simplified:
  412. ViewState["SelectedMode"] = 0;
  413. break;
  414. case FieldEditorSelectedModeEnum.Advanced:
  415. ViewState["SelectedMode"] = 1;
  416. break;
  417. }
  418. }
  419. }
  420. /// <summary>
  421. /// Indicates whether new item is edited.
  422. /// </summary>
  423. private bool IsNewItemEdited
  424. {
  425. get
  426. {
  427. return ValidationHelper.GetBoolean(ViewState["IsNewItemEdited"], false);
  428. }
  429. set
  430. {
  431. ViewState["IsNewItemEdited"] = value;
  432. databaseConfiguration.IsNewItemEdited = value;
  433. simpleMode.IsNewItemEdited = value;
  434. }
  435. }
  436. /// <summary>
  437. /// Selected item name.
  438. /// </summary>
  439. private string SelectedItemName
  440. {
  441. get
  442. {
  443. return ValidationHelper.GetString(ViewState["SelectedItemName"], "");
  444. }
  445. set
  446. {
  447. ViewState["SelectedItemName"] = value;
  448. }
  449. }
  450. /// <summary>
  451. /// Selected item type.
  452. /// </summary>
  453. private FieldEditorSelectedItemEnum SelectedItemType
  454. {
  455. get
  456. {
  457. object obj = ViewState["SelectedItemType"];
  458. return (obj == null) ? 0 : (FieldEditorSelectedItemEnum)obj;
  459. }
  460. set
  461. {
  462. ViewState["SelectedItemType"] = value;
  463. }
  464. }
  465. /// <summary>
  466. /// Is field primary.
  467. /// </summary>
  468. private bool IsPrimaryField
  469. {
  470. get
  471. {
  472. return ValidationHelper.GetBoolean(ViewState["IsPrimaryField"], false);
  473. }
  474. set
  475. {
  476. ViewState["IsPrimaryField"] = value;
  477. }
  478. }
  479. /// <summary>
  480. /// Indicates if document type is edited.
  481. /// </summary>
  482. private bool IsDocumentType
  483. {
  484. get
  485. {
  486. object obj = ViewState["IsDocumentType"];
  487. if ((obj == null) && (!string.IsNullOrEmpty(ClassName)))
  488. {
  489. DataClassInfo dci = DataClassInfoProvider.GetDataClass(mClassName);
  490. ViewState["IsDocumentType"] = ((dci != null) && dci.ClassIsDocumentType);
  491. }
  492. return ValidationHelper.GetBoolean(ViewState["IsDocumentType"], false);
  493. }
  494. }
  495. /// <summary>
  496. /// Gets or sets value indicating what item was selected in field type drop-down list.
  497. /// </summary>
  498. private string PreviousField
  499. {
  500. get
  501. {
  502. return ValidationHelper.GetString(ViewState["PreviousValue"], "");
  503. }
  504. set
  505. {
  506. ViewState["PreviousValue"] = value;
  507. }
  508. }
  509. /// <summary>
  510. /// Gets or sets value indicating if detailed controls are visible.
  511. /// </summary>
  512. private bool FieldDetailsVisible
  513. {
  514. get
  515. {
  516. return ValidationHelper.GetBoolean(ViewState["FieldDetailsVisible"], false);
  517. }
  518. set
  519. {
  520. ViewState["FieldDetailsVisible"] = value;
  521. }
  522. }
  523. /// <summary>
  524. /// Gets macro resolver name.
  525. /// </summary>
  526. private string ResolverName
  527. {
  528. get
  529. {
  530. if (!string.IsNullOrEmpty(ClassName))
  531. {
  532. return "form." + ClassName;
  533. }
  534. else
  535. {
  536. return "formdefinition." + FormDefinition;
  537. }
  538. }
  539. }
  540. #endregion
  541. #region "Global definitions"
  542. // Constants
  543. private const string newCategPreffix = "#categ##new#";
  544. private const string newFieldPreffix = "#field##new#";
  545. private const string categPreffix = "#categ#";
  546. private const string fieldPreffix = "#field#";
  547. private const int preffixLength = 7; // Length of categPreffix = length of fieldPreffix = 7
  548. private const string controlPrefix = "#uc#";
  549. #endregion
  550. #region "Page events"
  551. protected override void OnInit(EventArgs e)
  552. {
  553. base.OnInit(e);
  554. var page = Page as CMSPage;
  555. if (page != null)
  556. {
  557. page.EnsureScriptManager();
  558. if (page.ScriptManagerControl != null)
  559. {
  560. var script = new ScriptReference("~/CMSScripts/RestoreLostFocus.js");
  561. page.ScriptManagerControl.Scripts.Add(script);
  562. }
  563. }
  564. CreateHeaderActions();
  565. // Set method delegates
  566. fieldAppearance.GetControls = GetControls;
  567. simpleMode.GetControls = GetControls;
  568. }
  569. /// <summary>
  570. /// Creates header actions - save, switch to advanced and switch to simple mode buttons.
  571. /// </summary>
  572. private void CreateHeaderActions()
  573. {
  574. HeaderActions.ActionsList.Clear();
  575. btnSave = new HeaderAction()
  576. {
  577. RegisterShortcutScript = true,
  578. CommandName = "save",
  579. CommandArgument = "save",
  580. Text = GetString("general.save"),
  581. ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/save.png"),
  582. SmallImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/16/save.png")
  583. };
  584. btnSimplified = new HeaderAction()
  585. {
  586. CommandName = "simplified",
  587. Text = GetString("fieldeditor.tabs.simplifiedmode"),
  588. ControlType = HeaderActionTypeEnum.Hyperlink,
  589. ImageUrl = GetImageUrl("CMSModules/CMS_FormEngine/arrowup.png"),
  590. Visible = false
  591. };
  592. btnAdvanced = new HeaderAction()
  593. {
  594. CommandName = "advanced",
  595. Text = GetString("fieldeditor.tabs.advancedmode"),
  596. ControlType = HeaderActionTypeEnum.Hyperlink,
  597. ImageUrl = GetImageUrl("CMSModules/CMS_FormEngine/arrowdown.png"),
  598. Visible = false
  599. };
  600. HeaderActions.AddAction(btnSave);
  601. HeaderActions.AddAction(btnSimplified);
  602. HeaderActions.AddAction(btnAdvanced);
  603. HeaderActions.ActionPerformed += HeaderActions_ActionPerformed;
  604. }
  605. /// <summary>
  606. /// Actions handler.
  607. /// </summary>
  608. protected void HeaderActions_ActionPerformed(object sender, CommandEventArgs e)
  609. {
  610. switch (e.CommandName)
  611. {
  612. case "save":
  613. SaveField();
  614. break;
  615. case "simplified":
  616. SwitchToSimpleMode();
  617. break;
  618. case "advanced":
  619. SwitchToAdvancedMode();
  620. break;
  621. }
  622. }
  623. protected void Page_Load(object sender, EventArgs e)
  624. {
  625. if (EnableSystemFields)
  626. {
  627. btnNewSysAttribute.Visible = true;
  628. btnNewSysAttribute.ImageUrl = GetImageUrl(ImageDirectoryPath + "NewSystem.png");
  629. btnNewSysAttribute.ToolTip = GetString("TemplateDesigner.NewSysAttribute");
  630. }
  631. else
  632. {
  633. btnNewSysAttribute.Visible = false;
  634. }
  635. fieldAdvancedSettings.ResolverName = categoryEdit.ResolverName = ResolverName;
  636. fieldAdvancedSettings.ShowDisplayInSimpleModeCheckBox = (Mode == FieldEditorModeEnum.FormControls);
  637. // Hide New primary attribute if we are not in system development mode
  638. btnNewPrimaryAttribute.Visible = DevelopmentMode;
  639. simpleMode.DevelopmentMode = DevelopmentMode;
  640. simpleMode.Mode = Mode;
  641. lnkCode.Visible = SettingsKeyProvider.DevelopmentMode && !IsWizard;
  642. lnkFormDef.Visible = SettingsKeyProvider.DevelopmentMode && !IsWizard;
  643. // Set images url
  644. btnNewCategory.ImageUrl = GetImageUrl(ImageDirectoryPath + "NewCategory.png");
  645. btnNewAttribute.ImageUrl = GetImageUrl(ImageDirectoryPath + "New.png");
  646. btnNewPrimaryAttribute.ImageUrl = GetImageUrl(ImageDirectoryPath + "NewPK.png");
  647. btnDeleteItem.ImageUrl = GetImageUrl(ImageDirectoryPath + "Delete.png");
  648. btnUpAttribute.ImageUrl = GetImageUrl(ImageDirectoryPath + "Up.png");
  649. btnDownAttribute.ImageUrl = GetImageUrl(ImageDirectoryPath + "Down.png");
  650. btnDeleteItem.ToolTip = GetString("TemplateDesigner.DeleteItem");
  651. btnNewCategory.ToolTip = GetString("TemplateDesigner.NewCategory");
  652. btnNewAttribute.ToolTip = GetString("TemplateDesigner.NewAttribute");
  653. btnNewPrimaryAttribute.ToolTip = GetString("TemplateDesigner.NewPrimaryAttribute");
  654. btnDownAttribute.ToolTip = GetString("TemplateDesigner.DownAttribute");
  655. btnUpAttribute.ToolTip = GetString("TemplateDesigner.UpAttribute");
  656. if (CMSString.Compare(DisplayIn, FormInfo.DISPLAY_CONTEXT_DASHBOARD, true) == 0)
  657. {
  658. pnlDisplayInDashBoard.Visible = true;
  659. }
  660. ltlConfirmText.Text = "<input type=\"hidden\" id=\"confirmdelete\" value=\"" + GetString("TemplateDesigner.ConfirmDelete") + "\"/>";
  661. btnDeleteItem.Attributes.Add("onclick", "javascript:return confirmDelete();");
  662. btnUpAttribute.Enabled = true;
  663. btnDownAttribute.Enabled = true;
  664. btnDeleteItem.Enabled = true;
  665. btnNewAttribute.Enabled = true;
  666. btnNewCategory.Enabled = true;
  667. databaseConfiguration.LoadGroupField();
  668. if (!URLHelper.IsPostback())
  669. {
  670. Reload(null);
  671. }
  672. else
  673. {
  674. LoadControlSettings(PreviousField, false);
  675. }
  676. // Register event handlers
  677. databaseConfiguration.DropChanged += databaseConfiguration_DropChanged;
  678. databaseConfiguration.AttributeChanged += databaseConfiguration_AttributeChanged;
  679. fieldAppearance.OnFieldSelected += control_FieldSelected;
  680. simpleMode.OnFieldSelected += control_FieldSelected;
  681. simpleMode.OnGetFieldInfo += simpleMode_OnGetFieldInfo;
  682. documentSource.OnSourceFieldChanged += documentSource_OnSourceFieldChanged;
  683. plcValidation.Visible = true;
  684. plcQuickValidation.Visible = true;
  685. plcSettings.Visible = true;
  686. }
  687. protected void Page_PreRender(object sender, EventArgs e)
  688. {
  689. // Display controls and quick links according to current mode
  690. bool displayDetails = FieldDetailsVisible && chkDisplayInForm.Checked;
  691. fieldAppearance.Visible = displayDetails;
  692. fieldAdvancedSettings.Visible = displayDetails;
  693. cssSettings.Visible = displayDetails;
  694. validationSettings.DisplayControls();
  695. validationSettings.Visible = displayDetails && validationSettings.Visible;
  696. controlSettings.CheckVisibility();
  697. controlSettings.Visible = displayDetails && controlSettings.Visible;
  698. plcQuickValidation.Visible = displayDetails && validationSettings.Visible;
  699. plcQuickSettings.Visible = displayDetails && controlSettings.Visible;
  700. plcQuickStyles.Visible = displayDetails && cssSettings.Visible;
  701. plcQuickAppearance.Visible = displayDetails && fieldAppearance.Visible;
  702. chkDisplayInDashBoard.Enabled = chkDisplayInForm.Checked;
  703. // Display and store last value for simple mode
  704. if (SelectedMode == FieldEditorSelectedModeEnum.Simplified)
  705. {
  706. PreviousField = simpleMode.FieldType;
  707. plcQuickSelect.Visible = false;
  708. }
  709. // Display and store last value for advanced mode
  710. else
  711. {
  712. PreviousField = fieldAppearance.FieldType;
  713. plcQuickSelect.Visible = true;
  714. }
  715. // Display or hide tabs
  716. btnAdvanced.Visible = btnSimplified.Visible = false;
  717. if (EnableSimplifiedMode)
  718. {
  719. if (SelectedItemType == FieldEditorSelectedItemEnum.Field)
  720. {
  721. btnAdvanced.Visible = (SelectedMode == FieldEditorSelectedModeEnum.Simplified);
  722. btnSimplified.Visible = (SelectedMode != FieldEditorSelectedModeEnum.Simplified);
  723. }
  724. }
  725. // Hide quick links if only 'database quick link' should be displayed
  726. if ((SelectedItemType == 0) || (!plcQuickValidation.Visible && !plcQuickSettings.Visible && !plcQuickStyles.Visible && !plcQuickAppearance.Visible))
  727. {
  728. plcQuickSelect.Visible = false;
  729. }
  730. // Register script for scrolling content using quick links
  731. ScriptHelper.RegisterJQuery(Page);
  732. ScriptHelper.RegisterStartupScript(this, typeof(string), "ContentSlider", ScriptHelper.GetScript(@"
  733. jQuery(document).ready(function(){
  734. jQuery('a[href*=#]').click(function() {
  735. if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
  736. && location.hostname == this.hostname) {
  737. var $target = jQuery(this.hash);
  738. $target = $target.length && $target
  739. || jQuery('[name=' + this.hash.slice(1) +']');
  740. if ($target.length) {
  741. var targetOffset = $target." + (IsWizard ? "position" : "offset") + @"().top;
  742. jQuery('" + (IsWizard ? ".FieldPanelRightWizard" : "html, body") + @"')
  743. .animate({scrollTop: targetOffset}, 300);
  744. return false;
  745. }
  746. }
  747. });
  748. });
  749. "));
  750. // Disable padding on the page caused by PageContent CSS class
  751. Panel contentPanel = ((CMSPage)Page).CurrentMaster.PanelContent;
  752. if (!IsWizard && contentPanel != null)
  753. {
  754. contentPanel.CssClass = string.Empty;
  755. }
  756. // Highlight attribute list items
  757. HighlightListItems();
  758. }
  759. /// <summary>
  760. /// Highlights attribute list items like categories, primary keys and hidden fields.
  761. /// </summary>
  762. private void HighlightListItems()
  763. {
  764. if (fi == null)
  765. {
  766. LoadFormDefinition();
  767. }
  768. if ((lstAttributes.Items.Count > 0) && (fi != null))
  769. {
  770. FormFieldInfo formField = null;
  771. string cssClass = null;
  772. foreach (ListItem li in lstAttributes.Items)
  773. {
  774. // Mark category item with different color
  775. if (li.Value.StartsWithCSafe(categPreffix))
  776. {
  777. li.Attributes.Add("class", "FieldEditorCategoryItem");
  778. }
  779. else
  780. {
  781. // Get form field info
  782. formField = fi.GetFormField(li.Value.Substring(preffixLength));
  783. if (formField != null)
  784. {
  785. cssClass = string.Empty;
  786. if (DevelopmentMode && formField.PrimaryKey)
  787. {
  788. // Highlight primary keys in the list
  789. cssClass = "FieldEditorPrimaryAttribute";
  790. }
  791. if (!formField.Visible)
  792. {
  793. if (!string.IsNullOrEmpty(cssClass))
  794. {
  795. cssClass += " ";
  796. }
  797. // Highlight fields that are not visible
  798. cssClass += "FieldEditorHiddenItem";
  799. }
  800. if (!string.IsNullOrEmpty(cssClass))
  801. {
  802. li.Attributes.Add("class", cssClass);
  803. }
  804. }
  805. }
  806. }
  807. }
  808. }
  809. #endregion
  810. #region "Methods"
  811. /// <summary>
  812. /// Reload field editor.
  813. /// </summary>
  814. /// <param name="selectedValue">Selected field in field list</param>
  815. public void Reload(string selectedValue)
  816. {
  817. Reload(selectedValue, false);
  818. }
  819. /// <summary>
  820. /// Reload field editor.
  821. /// </summary>
  822. /// <param name="selectedValue">Selected field in field list</param>
  823. /// <param name="partialReload">Indicates if not all controls need to be reloaded</param>
  824. private void Reload(string selectedValue, bool partialReload)
  825. {
  826. bool isModeSelected = false;
  827. bool isItemSelected = false;
  828. // Check for alternative form mode
  829. if (IsAlternativeForm)
  830. {
  831. if (!string.IsNullOrEmpty(FormDefinition))
  832. {
  833. isModeSelected = true;
  834. }
  835. else
  836. {
  837. // Clear item list
  838. lstAttributes.Items.Clear();
  839. }
  840. }
  841. else
  842. {
  843. switch (mMode)
  844. {
  845. case FieldEditorModeEnum.General:
  846. case FieldEditorModeEnum.FormControls:
  847. if (!string.IsNullOrEmpty(FormDefinition))
  848. {
  849. isModeSelected = true;
  850. }
  851. else
  852. {
  853. // Clear item list
  854. lstAttributes.Items.Clear();
  855. }
  856. break;
  857. case FieldEditorModeEnum.ClassFormDefinition:
  858. case FieldEditorModeEnum.BizFormDefinition:
  859. case FieldEditorModeEnum.SystemTable:
  860. case FieldEditorModeEnum.CustomTable:
  861. if (!string.IsNullOrEmpty(mClassName))
  862. {
  863. isModeSelected = true;
  864. }
  865. else
  866. {
  867. ShowError(GetString("fieldeditor.noclassname"));
  868. }
  869. break;
  870. case FieldEditorModeEnum.WebPartProperties:
  871. if ((mWebPartId > 0))
  872. {
  873. isModeSelected = true;
  874. }
  875. else
  876. {
  877. ShowError(GetString("fieldeditor.nowebpartid"));
  878. }
  879. break;
  880. default:
  881. ShowError(GetString("fieldeditor.nomode"));
  882. break;
  883. }
  884. }
  885. if (!partialReload)
  886. {
  887. // Display controls if mode is determined
  888. ShowOrHideFieldDetails(true);
  889. }
  890. if (isModeSelected)
  891. {
  892. isItemSelected = LoadInnerControls(selectedValue, partialReload);
  893. }
  894. // Hide controls when item isn't selected
  895. if ((!partialReload) && (!isItemSelected))
  896. {
  897. HideAllPanels();
  898. btnSave.Enabled = false;
  899. btnSave.ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/savedisabled.png");
  900. btnUpAttribute.Enabled = false;
  901. btnDownAttribute.Enabled = false;
  902. btnDeleteItem.Enabled = false;
  903. btnNewAttribute.Enabled = true; // Only new items can be added
  904. btnNewCategory.Enabled = true; // Only new items can be added
  905. ShowInformation(GetString("fieldeditor.nofieldsdefined"));
  906. }
  907. DisplayOrHideActions();
  908. if (documentSource.VisibleContent)
  909. {
  910. documentSource.Reload();
  911. }
  912. // Show or hide field visibility selector
  913. fieldAppearance.ShowFieldVisibility = ShowFieldVisibility;
  914. }
  915. /// <summary>
  916. /// Loads inner FieldEditor controls.
  917. /// </summary>
  918. /// <returns>Returns TRUE if any item is selected</returns>
  919. private bool LoadInnerControls(string selectedValue, bool partialReload)
  920. {
  921. bool isItemSelected = false;
  922. LoadFormDefinition();
  923. if (!partialReload)
  924. {
  925. LoadAttributesList(selectedValue);
  926. }
  927. documentSource.FormInfo = fi;
  928. documentSource.Mode = Mode;
  929. documentSource.IsAlternativeForm = IsAlternativeForm;
  930. documentSource.ClassName = ClassName;
  931. fieldAppearance.IsAlternativeForm = IsAlternativeForm;
  932. fieldAppearance.AlternativeFormFullName = AlternativeFormFullName;
  933. if (SelectedItemType == FieldEditorSelectedItemEnum.Field)
  934. {
  935. isItemSelected = true;
  936. DisplaySelectedTabContent();
  937. ffi = fi.GetFormField(SelectedItemName);
  938. if (EnableSimplifiedMode)
  939. {
  940. btnAdvanced.Visible = (SelectedMode == FieldEditorSelectedModeEnum.Simplified);
  941. btnSimplified.Visible = (SelectedMode != FieldEditorSelectedModeEnum.Simplified);
  942. }
  943. LoadSelectedField(partialReload);
  944. }
  945. else if (SelectedItemType == FieldEditorSelectedItemEnum.Category)
  946. {
  947. isItemSelected = true;
  948. btnAdvanced.Visible = btnSimplified.Visible = false;
  949. LoadSelectedCategory();
  950. }
  951. return isItemSelected;
  952. }
  953. /// <summary>
  954. /// Load xml definition of the form.
  955. /// </summary>
  956. private void LoadFormDefinition()
  957. {
  958. bool isError = false;
  959. switch (mMode)
  960. {
  961. case FieldEditorModeEnum.General:
  962. // Definition is loaded from external xml
  963. break;
  964. case FieldEditorModeEnum.WebPartProperties:
  965. if (!IsAlternativeForm)
  966. {
  967. // Load xml definition from web part info
  968. WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(mWebPartId);
  969. if (wpi != null)
  970. {
  971. FormDefinition = wpi.WebPartProperties;
  972. }
  973. else
  974. {
  975. isError = true;
  976. }
  977. }
  978. break;
  979. case FieldEditorModeEnum.ClassFormDefinition:
  980. case FieldEditorModeEnum.BizFormDefinition:
  981. case FieldEditorModeEnum.SystemTable:
  982. case FieldEditorModeEnum.CustomTable:
  983. if (!IsAlternativeForm)
  984. {
  985. // Load xml definition from Class info
  986. DataClassInfo dci = DataClassInfoProvider.GetDataClass(mClassName);
  987. if (dci != null)
  988. {
  989. FormDefinition = dci.ClassFormDefinition;
  990. }
  991. else
  992. {
  993. isError = true;
  994. }
  995. }
  996. break;
  997. }
  998. if (isError)
  999. {
  1000. ShowError("[ FieldEditor.LoadFormDefinition() ]: " + GetString("FieldEditor.XmlDefinitionNotLoaded"));
  1001. }
  1002. fi = new FormInfo(FormDefinition);
  1003. }
  1004. /// <summary>
  1005. /// Fill attribute list.
  1006. /// </summary>
  1007. /// <param name="selectedValue">Selected value in attribute list, null if first item is selected</param>
  1008. private void LoadAttributesList(string selectedValue)
  1009. {
  1010. FormFieldInfo formField = null;
  1011. FormCategoryInfo formCategory = null;
  1012. ListItem li = null;
  1013. // Reload list only if new item is not edited
  1014. if (!IsNewItemEdited)
  1015. {
  1016. // Clear item list
  1017. lstAttributes.Items.Clear();
  1018. // Get all list items (fields and categories)
  1019. var itemList = fi.GetFormElements(true, true);
  1020. if (itemList != null)
  1021. {
  1022. string itemDisplayName = null;
  1023. string itemCodeName = null;
  1024. foreach (object item in itemList)
  1025. {
  1026. if (item is FormFieldInfo)
  1027. {
  1028. formField = ((FormFieldInfo)(item));
  1029. itemDisplayName = formField.Name;
  1030. if (!formField.AllowEmpty)
  1031. {
  1032. itemDisplayName += ResHelper.RequiredMark;
  1033. }
  1034. itemCodeName = fieldPreffix + formField.Name;
  1035. li = new ListItem(itemDisplayName, itemCodeName);
  1036. }
  1037. else if (item is FormCategoryInfo)
  1038. {
  1039. formCategory = ((FormCategoryInfo)(item));
  1040. itemDisplayName = ResHelper.LocalizeString(formCategory.CategoryCaption);
  1041. itemCodeName = categPreffix + formCategory.CategoryName;
  1042. li = new ListItem(itemDisplayName, itemCodeName);
  1043. }
  1044. // Load list box
  1045. if (li != null)
  1046. {
  1047. lstAttributes.Items.Add(li);
  1048. }
  1049. }
  1050. }
  1051. // Set selected item
  1052. if (lstAttributes.Items.Count > 0)
  1053. {
  1054. if (!string.IsNullOrEmpty(selectedValue) && lstAttributes.Items.FindByValue(selectedValue) != null)
  1055. {
  1056. lstAttributes.SelectedValue = selectedValue;
  1057. }
  1058. else
  1059. {
  1060. // Select first item of the list
  1061. lstAttributes.SelectedIndex = 0;
  1062. }
  1063. }
  1064. // Default values - list is empty
  1065. SelectedItemName = null;
  1066. SelectedItemType = 0;
  1067. // Save selected item info
  1068. if (lstAttributes.SelectedValue != null)
  1069. {
  1070. if (lstAttributes.SelectedValue.StartsWithCSafe(fieldPreffix))
  1071. {
  1072. SelectedItemName = lstAttributes.SelectedValue.Substring(preffixLength);
  1073. SelectedItemType = FieldEditorSelectedItemEnum.Field;
  1074. }
  1075. else if (lstAttributes.SelectedValue.StartsWithCSafe(categPreffix))
  1076. {
  1077. SelectedItemName = lstAttributes.SelectedValue.Substring(preffixLength);
  1078. SelectedItemType = FieldEditorSelectedItemEnum.Category;
  1079. }
  1080. }
  1081. }
  1082. }
  1083. /// <summary>
  1084. /// Sets all values of the category edit form to defaults.
  1085. /// </summary>
  1086. private void LoadDefaultCategoryEditForm()
  1087. {
  1088. plcCategory.Visible = true;
  1089. plcSimple.Visible = false;
  1090. plcAdvanced.Visible = false;
  1091. categoryEdit.Value = string.Empty;
  1092. categoryEdit.Collapsible = false;
  1093. categoryEdit.CollapsedByDefault = false;
  1094. categoryEdit.VisibleMacro = string.Empty;
  1095. categoryEdit.CategoryVisible = true;
  1096. LoadFormDefinition();
  1097. }
  1098. /// <summary>
  1099. /// Sets all values of form to defaults.
  1100. /// </summary>
  1101. /// <param name="system">True - empty form for node or document attribute should be loaded, False - standard form should be loaded</param>
  1102. /// <param name="partialReload">True - indicates that only some controls should be loaded, False - reload all controls</param>
  1103. private void LoadDefaultAttributeEditForm(bool system, bool partialReload)
  1104. {
  1105. ffi = null;
  1106. plcCategory.Visible = false;
  1107. chkDisplayInForm.Checked = true;
  1108. chkDisplayInDashBoard.Checked = true;
  1109. if ((SelectedMode == FieldEditorSelectedModeEnum.Advanced) && !partialReload)
  1110. {
  1111. databaseConfiguration.DevelopmentMode = DevelopmentMode;
  1112. databaseConfiguration.ShowSystemFields = system;
  1113. databaseConfiguration.IsDocumentType = IsDocumentType;
  1114. databaseConfiguration.Mode = Mode;
  1115. databaseConfiguration.ClassName = ClassName;
  1116. databaseConfiguration.CoupledClassName = CoupledClassName;
  1117. databaseConfiguration.IsAlternativeForm = IsAlternativeForm;
  1118. databaseConfiguration.Reload("", IsNewItemEdited);
  1119. databaseConfiguration.ShowDefaultControl();
  1120. }
  1121. if (system)
  1122. {
  1123. LoadSystemField();
  1124. }
  1125. if (SelectedMode == FieldEditorSelectedModeEnum.Advanced)
  1126. {
  1127. fieldAppearance.ClassName = ClassName;
  1128. fieldAppearance.AttributeType = databaseConfiguration.AttributeType;
  1129. fieldAppearance.Reload();
  1130. fieldAdvancedSettings.Reload();
  1131. cssSettings.Reload();
  1132. LoadValidationSettings();
  1133. validationSettings.DisplayControls();
  1134. validationSettings.Reload();
  1135. chkDisplayInForm.Checked = true;
  1136. chkDisplayInDashBoard.Checked = true;
  1137. }
  1138. else
  1139. {
  1140. simpleMode.FieldInfo = null;
  1141. simpleMode.DisplayedControls = DisplayedControls;
  1142. simpleMode.Mode = Mode;
  1143. simpleMode.ClearForm();
  1144. simpleMode.LoadTypes();
  1145. simpleMode.LoadControlSettings(null, true);
  1146. }
  1147. }
  1148. /// <summary>
  1149. /// Fill form with selected category data.
  1150. /// </summary>
  1151. private void LoadSelectedCategory()
  1152. {
  1153. plcAdvanced.Visible = false;
  1154. plcSimple.Visible = false;
  1155. plcCategory.Visible = true;
  1156. fci = fi.GetFormCategory(SelectedItemName);
  1157. if (fci != null)
  1158. {
  1159. HandleInherited(fci.IsInherited);
  1160. categoryEdit.Value = fci.CategoryCaption;
  1161. categoryEdit.Collapsible = fci.CategoryCollapsible;
  1162. categoryEdit.CollapsedByDefault = fci.CategoryCollapsedByDefault;
  1163. categoryEdit.VisibleMacro = fci.VisibleMacro;
  1164. categoryEdit.CategoryVisible = fci.Visible;
  1165. }
  1166. else
  1167. {
  1168. LoadDefaultCategoryEditForm();
  1169. }
  1170. }
  1171. /// <summary>
  1172. /// Displays controls for advanced editing.
  1173. /// </summary>
  1174. private void ShowAdvancedOptions()
  1175. {
  1176. if (SelectedMode != FieldEditorSelectedModeEnum.Simplified)
  1177. {
  1178. plcSimple.Visible = false;
  1179. plcCategory.Visible = false;
  1180. databaseConfiguration.Visible = true;
  1181. controlSettings.Visible = true;
  1182. fieldAppearance.Visible = true;
  1183. fieldAdvancedSettings.Visible = true;
  1184. validationSettings.Visible = true;
  1185. cssSettings.Visible = true;
  1186. FieldDetailsVisible = true;
  1187. }
  1188. }
  1189. /// <summary>
  1190. /// Handles the inheritance of the field.
  1191. /// </summary>
  1192. private void HandleInherited(bool inherited)
  1193. {
  1194. pnlField.Enabled = true;
  1195. btnSave.Enabled = true;
  1196. btnDeleteItem.Visible = true;
  1197. ShowInformation("");
  1198. if (inherited)
  1199. {
  1200. // Get information on inherited class
  1201. DataClassInfo dci = DataClassInfoProvider.GetDataClass(mClassName);
  1202. if (dci != null)
  1203. {
  1204. DataClassInfo parentCi = DataClassInfoProvider.GetDataClass(dci.ClassInheritsFromClassID);
  1205. if (parentCi != null)
  1206. {
  1207. pnlField.Enabled = false;
  1208. btnSave.Enabled = false;
  1209. btnDeleteItem.Visible = false;
  1210. ShowInformation(String.Format(GetString("DocumentType.FieldIsInherited"), parentCi.ClassDisplayName));
  1211. }
  1212. }
  1213. }
  1214. }
  1215. /// <summary>
  1216. /// Fill form with selected attribute data.
  1217. /// </summary>
  1218. /// <param name="partialReload">Indicates if only some controls should be reloaded</param>
  1219. private void LoadSelectedField(bool partialReload)
  1220. {
  1221. // Fill form
  1222. if (ffi != null)
  1223. {
  1224. HandleInherited(ffi.IsInherited);
  1225. IsPrimaryField = ffi.PrimaryKey;
  1226. if (!partialReload)
  1227. {
  1228. bool controlIsInvalid = !ffi.Visible || (CMSString.Compare(ffi.Settings["controlname"] as String, FormHelper.GetFormFieldControlTypeString(FormFieldControlTypeEnum.Unknown), true) != 0);
  1229. chkDisplayInForm.Checked = ffi.Visible && controlIsInvalid;
  1230. chkDisplayInDashBoard.Checked = (CMSString.Compare(ffi.DisplayIn, DisplayIn, true) == 0);
  1231. }
  1232. DisplaySelectedTabContent();
  1233. ShowAdvancedOptions();
  1234. // Load controls for advanced mode
  1235. if (SelectedMode == FieldEditorSelectedModeEnum.Advanced)
  1236. {
  1237. if (!partialReload)
  1238. {
  1239. databaseConfiguration.DevelopmentMode = DevelopmentMode;
  1240. databaseConfiguration.ShowSystemFields = ffi.External;
  1241. databaseConfiguration.FieldInfo = ffi;
  1242. databaseConfiguration.IsDocumentType = IsDocumentType;
  1243. databaseConfiguration.Mode = Mode;
  1244. databaseConfiguration.IsAlternativeForm = IsAlternativeForm;
  1245. databaseConfiguration.ClassName = ClassName;
  1246. databaseConfiguration.CoupledClassName = CoupledClassName;
  1247. databaseConfiguration.Reload(ffi.Name, IsNewItemEdited);
  1248. }
  1249. if (chkDisplayInForm.Checked && fieldAppearance.Visible)
  1250. {
  1251. fieldAppearance.Mode = Mode;
  1252. fieldAppearance.ClassName = ClassName;
  1253. fieldAppearance.FieldInfo = ffi;
  1254. fieldAppearance.AttributeType = databaseConfiguration.AttributeType;
  1255. fieldAppearance.Reload();
  1256. }
  1257. if (chkDisplayInForm.Checked && fieldAdvancedSettings.Visible)
  1258. {
  1259. fieldAdvancedSettings.FieldInfo = ffi;
  1260. fieldAdvancedSettings.Reload();
  1261. }
  1262. if (chkDisplayInForm.Checked && validationSettings.Visible)
  1263. {
  1264. LoadValidationSettings();
  1265. validationSettings.DisplayControls();
  1266. validationSettings.Reload();
  1267. }
  1268. if (chkDisplayInForm.Checked && cssSettings.Visible)
  1269. {
  1270. cssSettings.FieldInfo = ffi;
  1271. cssSettings.Reload();
  1272. cssSettings.Enabled = true;
  1273. }
  1274. }
  1275. // Load controls for simple mode
  1276. else
  1277. {
  1278. simpleMode.FieldInfo = ffi;
  1279. simpleMode.Mode = Mode;
  1280. simpleMode.LoadTypes();
  1281. }
  1282. LoadControlSettings(null, false);
  1283. }
  1284. else
  1285. {
  1286. LoadDefaultAttributeEditForm(false, partialReload);
  1287. }
  1288. }
  1289. /// <summary>
  1290. /// Loads validation settings.
  1291. /// </summary>
  1292. private void LoadValidationSettings()
  1293. {
  1294. validationSettings.IsPrimary = IsPrimaryField;
  1295. validationSettings.FieldInfo = ffi;
  1296. validationSettings.Mode = Mode;
  1297. validationSettings.AttributeType = databaseConfiguration.AttributeType;
  1298. validationSettings.FieldType = fieldAppearance.FieldType;
  1299. }
  1300. /// <summary>
  1301. /// Displays or hides actions according to the selected mode.
  1302. /// </summary>
  1303. protected void DisplayOrHideActions()
  1304. {
  1305. // Hide actions only when alternative form definition is edited
  1306. if (IsAlternativeForm)
  1307. {
  1308. plcActions.Visible = false;
  1309. }
  1310. }
  1311. protected void lnkCode_Click(object sender, EventArgs e)
  1312. {
  1313. GenerateCode(false);
  1314. }
  1315. protected void lnkFormDef_Click(object sender, EventArgs e)
  1316. {
  1317. GetFormDefinition();
  1318. }
  1319. /// <summary>
  1320. /// Outputs the form definition XML of the current view
  1321. /// </summary>
  1322. protected void GetFormDefinition()
  1323. {
  1324. LoadFormDefinition();
  1325. if (fi != null)
  1326. {
  1327. string xml = HTMLHelper.ReformatHTML(fi.GetXmlDefinition());
  1328. // Write directly to response
  1329. Response.Clear();
  1330. Response.AddHeader("Content-Disposition", "attachment; filename=formDefinition.xml");
  1331. Response.ContentType = "text/xml";
  1332. Response.Write(xml);
  1333. Response.End();
  1334. }
  1335. }
  1336. /// <summary>
  1337. /// Generates the class code.
  1338. /// </summary>
  1339. /// <param name="file">If true, the code is generated to a file, if false, it gets directly to output</param>
  1340. protected void GenerateCode(bool file)
  1341. {
  1342. switch (mMode)
  1343. {
  1344. case FieldEditorModeEnum.WebPartProperties:
  1345. case FieldEditorModeEnum.SystemTable:
  1346. case FieldEditorModeEnum.FormControls:
  1347. return;
  1348. }
  1349. try
  1350. {
  1351. // Prepare the folders
  1352. string templateFile = Server.MapPath("~/App_Data/CodeTemplates/");
  1353. string codeFile = Server.MapPath("~/App_Code");
  1354. if (!Directory.Exists(codeFile))
  1355. {
  1356. codeFile = Server.MapPath("~/Old_App_Code");
  1357. }
  1358. codeFile += "/Global/AutoGenerated/";
  1359. // Ensure the directory
  1360. if (file)
  1361. {
  1362. Directory.CreateDirectory(codeFile);
  1363. }
  1364. // Save xml string to CMS_Class table
  1365. DataClassInfo dci = DataClassInfoProvider.GetDataClass(mClassName);
  1366. if (dci != null)
  1367. {
  1368. // Prepare the class name
  1369. string className = dci.ClassName;
  1370. int dotIndex = className.LastIndexOf('.');
  1371. if (dotIndex >= 0)
  1372. {
  1373. className = className.Substring(dotIndex + 1);
  1374. }
  1375. className = ValidationHelper.GetIdentifier(className, "");
  1376. className = (className[0]) + className.Substring(1).ToUpperCSafe();
  1377. string originalClassName = null;
  1378. if (dci.ClassIsDocumentType)
  1379. {
  1380. // Document type
  1381. className += "Document";
  1382. codeFile += "DocumentTypes/";
  1383. templateFile += "DocType.template";
  1384. originalClassName = "DocType";
  1385. }
  1386. else if (dci.ClassIsCustomTable)
  1387. {
  1388. // Custom table
  1389. className += "Item";
  1390. codeFile += "CustomTables/";
  1391. templateFile += "CustomTableType.template";
  1392. originalClassName = "CustomTableType";
  1393. }
  1394. else
  1395. {
  1396. // BizForm
  1397. className += "Item";
  1398. codeFile += "BizForms/";
  1399. templateFile += "BizFormType.template";
  1400. originalClassName = "BizFormType";
  1401. }
  1402. // Generate the code
  1403. string code = File.ReadAllText(templateFile);
  1404. StringBuilder sbInit = new StringBuilder();
  1405. if (fi == null)
  1406. {
  1407. fi = new FormInfo(dci.ClassFormDefinition);
  1408. }
  1409. string propertiesCode = CodeGenerator.GetPropertiesCode(fi, false, null, null, false);
  1410. // Replace in code
  1411. code = code.Replace("##CLASSNAME##", dci.ClassName);
  1412. code = code.Replace(originalClassName, className);
  1413. code = code.Replace("// ##PROPERTIES##", propertiesCode);
  1414. code = code.Replace("##SUMMARY##", dci.ClassDisplayName);
  1415. codeFile += className + ".cs";
  1416. if (file)
  1417. {
  1418. File.WriteAllText(codeFile, code);
  1419. }
  1420. else
  1421. {
  1422. // Write directly to response
  1423. Response.Clear();
  1424. Response.AddHeader("Content-Disposition", "attachment; filename=" + className + ".cs");
  1425. Response.ContentType = "text/plain";
  1426. Response.Write(code);
  1427. Response.End();
  1428. }
  1429. }
  1430. else
  1431. {
  1432. ShowError("[FieldEditor.UpdateFormDefinition]: " + GetString("FieldEditor.ClassNotFound"));
  1433. }
  1434. }
  1435. catch (Exception ex)
  1436. {
  1437. // Log the error silently
  1438. EventLogProvider.LogException("FieldEditor", "CODEGEN", ex);
  1439. }
  1440. }
  1441. /// <summary>
  1442. /// Saves the f…

Large files files are truncated, but you can click here to view the full file