PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/CMSWebParts/SmartSearch/SearchDialogWithResults.ascx.cs

https://bitbucket.org/kudutest2/kenticogit
C# | 791 lines | 557 code | 105 blank | 129 comment | 5 complexity | 692bda1668d12fb33585750ddb97d94d MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Web;
  4. using System.Web.UI;
  5. using System.Web.UI.WebControls;
  6. using System.Data;
  7. using CMS.GlobalHelper;
  8. using CMS.Controls;
  9. using CMS.PortalControls;
  10. using CMS.CMSHelper;
  11. using CMS.ISearchEngine;
  12. public partial class CMSWebParts_SmartSearch_SearchDialogWithResults : CMSAbstractWebPart
  13. {
  14. #region "Variables"
  15. private string mFilterSuffix = "diarespsfx";
  16. #endregion
  17. #region "Dialog properties"
  18. /// <summary>
  19. /// Gets or sets the label search for text.
  20. /// </summary>
  21. public string SearchForLabel
  22. {
  23. get
  24. {
  25. return DataHelper.GetNotEmpty(this.GetValue("SearchForLabel"), this.srchDialog.SearchForLabel);
  26. }
  27. set
  28. {
  29. this.SetValue("SearchForLabel", value);
  30. this.srchDialog.SearchForLabel = value;
  31. }
  32. }
  33. /// <summary>
  34. /// Gets or sets the value that indicates whether search mode settings should be displayed.
  35. /// </summary>
  36. public bool ShowSearchMode
  37. {
  38. get
  39. {
  40. return ValidationHelper.GetBoolean(this.GetValue("ShowSearchMode"), this.srchDialog.ShowSearchMode);
  41. }
  42. set
  43. {
  44. this.SetValue("ShowSearchMode", value);
  45. this.srchDialog.ShowSearchMode = value;
  46. }
  47. }
  48. /// <summary>
  49. /// Gets or sets the search button text.
  50. /// </summary>
  51. public string SearchButton
  52. {
  53. get
  54. {
  55. return DataHelper.GetNotEmpty(this.GetValue("SearchButton"), this.srchDialog.SearchButton);
  56. }
  57. set
  58. {
  59. this.SetValue("SearchButton", value);
  60. this.srchDialog.SearchButton = value;
  61. }
  62. }
  63. /// <summary>
  64. /// Gets or sets the search mode.
  65. /// </summary>
  66. public SearchModeEnum SearchMode
  67. {
  68. get
  69. {
  70. return SearchHelper.GetSearchModeEnum(DataHelper.GetNotEmpty(this.GetValue("SearchMode"), SearchHelper.GetSearchModeString(this.srchDialog.SearchMode)));
  71. }
  72. set
  73. {
  74. this.SetValue("SearchMode", SearchHelper.GetSearchModeString(value));
  75. this.srchDialog.SearchMode = value;
  76. }
  77. }
  78. /// <summary>
  79. /// Gets or sets the search mode label text.
  80. /// </summary>
  81. public string SearchModeLabel
  82. {
  83. get
  84. {
  85. return DataHelper.GetNotEmpty(this.GetValue("SearchModeLabel"), this.srchDialog.SearchModeLabel);
  86. }
  87. set
  88. {
  89. this.SetValue("SearchModeLabel", value);
  90. this.srchDialog.SearchModeLabel = value;
  91. }
  92. }
  93. #endregion
  94. #region "Result properties"
  95. /// <summary>
  96. /// Gets or sets sorting of search.
  97. /// </summary>
  98. public string SearchSort
  99. {
  100. get
  101. {
  102. return ValidationHelper.GetString(this.GetValue("SearchSort"), srchResults.SearchSort);
  103. }
  104. set
  105. {
  106. this.SetValue("SearchSort", value);
  107. srchResults.SearchSort = value;
  108. }
  109. }
  110. /// <summary>
  111. /// Gets or sets sorting of search.
  112. /// </summary>
  113. public string SearchCondition
  114. {
  115. get
  116. {
  117. return ValidationHelper.GetString(this.GetValue("SearchCondition"), srchResults.SearchCondition);
  118. }
  119. set
  120. {
  121. this.SetValue("SearchCondition", value);
  122. srchResults.SearchCondition = value;
  123. }
  124. }
  125. /// <summary>
  126. /// Gets or sets indexes.
  127. /// </summary>
  128. public string Indexes
  129. {
  130. get
  131. {
  132. return ValidationHelper.GetString(this.GetValue("Indexes"), srchResults.Indexes);
  133. }
  134. set
  135. {
  136. this.SetValue("Indexes", value);
  137. srchResults.Indexes = value;
  138. }
  139. }
  140. /// <summary>
  141. /// Gets or sets path.
  142. /// </summary>
  143. public string Path
  144. {
  145. get
  146. {
  147. return ValidationHelper.GetString(this.GetValue("Path"), srchResults.Path);
  148. }
  149. set
  150. {
  151. this.SetValue("Path", value);
  152. srchResults.Path = value;
  153. }
  154. }
  155. /// <summary>
  156. /// Gets or sets document types.
  157. /// </summary>
  158. public string DocumentTypes
  159. {
  160. get
  161. {
  162. return ValidationHelper.GetString(this.GetValue("DocumentTypes"), srchResults.DocumentTypes);
  163. }
  164. set
  165. {
  166. this.SetValue("DocumentTypes", value);
  167. srchResults.DocumentTypes = value;
  168. }
  169. }
  170. /// <summary>
  171. /// Gets or sets check permissions.
  172. /// </summary>
  173. public bool CheckPermissions
  174. {
  175. get
  176. {
  177. return ValidationHelper.GetBoolean(this.GetValue("CheckPermissions"), srchResults.CheckPermissions);
  178. }
  179. set
  180. {
  181. this.SetValue("CheckPermissions", value);
  182. srchResults.CheckPermissions = false;
  183. }
  184. }
  185. /// <summary>
  186. /// Gets or sets search option.
  187. /// </summary>
  188. public CMS.SiteProvider.SearchOptionsEnum SearchOptions
  189. {
  190. get
  191. {
  192. return CMS.SiteProvider.SearchHelper.GetSearchOptionsEnum(ValidationHelper.GetString(this.GetValue("SearchOptions"), CMS.SiteProvider.SearchHelper.GetSearchOptionsString(srchResults.SearchOptions)));
  193. }
  194. set
  195. {
  196. this.SetValue("SearchOptions", CMS.SiteProvider.SearchHelper.GetSearchOptionsString(value));
  197. srchResults.SearchOptions = value;
  198. }
  199. }
  200. /// <summary>
  201. /// Gets or sets transformation name.
  202. /// </summary>
  203. public string TransformationName
  204. {
  205. get
  206. {
  207. return ValidationHelper.GetString(this.GetValue("TransformationName"), srchResults.TransformationName);
  208. }
  209. set
  210. {
  211. this.SetValue("TransformationName", value);
  212. srchResults.TransformationName = value;
  213. }
  214. }
  215. /// <summary>
  216. /// Gets or sets culture code.
  217. /// </summary>
  218. public string CultureCode
  219. {
  220. get
  221. {
  222. return ValidationHelper.GetString(this.GetValue("CultureCode"), srchResults.CultureCode);
  223. }
  224. set
  225. {
  226. this.SetValue("CultureCode", value);
  227. srchResults.CultureCode = value;
  228. }
  229. }
  230. /// <summary>
  231. /// Gets or sets combine with default culture.
  232. /// </summary>
  233. public bool CombineWithDefaultCulture
  234. {
  235. get
  236. {
  237. return ValidationHelper.GetBoolean(this.GetValue("CombineWithDefaultCulture"), srchResults.CombineWithDefaultCulture);
  238. }
  239. set
  240. {
  241. this.SetValue("CombineWithDefaultCulture", value);
  242. srchResults.CombineWithDefaultCulture = value;
  243. }
  244. }
  245. /// <summary>
  246. /// Gets or sets search in attachments.
  247. /// </summary>
  248. public bool SearchInAttachments
  249. {
  250. get
  251. {
  252. return ValidationHelper.GetBoolean(this.GetValue("SearchInAttachments"), srchResults.SearchInAttachments);
  253. }
  254. set
  255. {
  256. this.SetValue("SearchInAttachments", value);
  257. srchResults.SearchInAttachments = value;
  258. }
  259. }
  260. /// <summary>
  261. /// Gets or sets attachments where.
  262. /// </summary>
  263. public string AttachmentsWhere
  264. {
  265. get
  266. {
  267. return ValidationHelper.GetString(this.GetValue("AttachmentsWhere"), srchResults.AttachmentsWhere);
  268. }
  269. set
  270. {
  271. this.SetValue("AttachmentsWhere", value);
  272. srchResults.AttachmentsWhere = value;
  273. }
  274. }
  275. /// <summary>
  276. /// Gets or sets attachment order by.
  277. /// </summary>
  278. public string AttachmentsOrderBy
  279. {
  280. get
  281. {
  282. return ValidationHelper.GetString(this.GetValue("AttachmentsOrderBy"), srchResults.AttachmentsOrderBy);
  283. }
  284. set
  285. {
  286. this.SetValue("AttachmentsOrderBy", value);
  287. srchResults.AttachmentsOrderBy = value;
  288. }
  289. }
  290. /// <summary>
  291. /// Gets or sets results text.
  292. /// </summary>
  293. public string NoResultsText
  294. {
  295. get
  296. {
  297. return ValidationHelper.GetString(this.GetValue("NoResultsText"), srchResults.NoResultsText);
  298. }
  299. set
  300. {
  301. this.SetValue("NoResultsText", value);
  302. srchResults.NoResultsText = value;
  303. }
  304. }
  305. /// <summary>
  306. /// Gets or sets the maximal displayed results.
  307. /// </summary>
  308. public int MaxResults
  309. {
  310. get
  311. {
  312. return ValidationHelper.GetInteger(this.GetValue("MaxResults"), srchResults.MaxResults);
  313. }
  314. set
  315. {
  316. this.SetValue("MaxResults", value);
  317. srchResults.MaxResults = value;
  318. }
  319. }
  320. #endregion
  321. #region "UniPager properties"
  322. /// <summary>
  323. /// Gets or sets page size.
  324. /// </summary>
  325. public int PageSize
  326. {
  327. get
  328. {
  329. return ValidationHelper.GetInteger(this.GetValue("PageSize"), srchResults.PageSize);
  330. }
  331. set
  332. {
  333. this.SetValue("PageSize", value);
  334. srchResults.PageSize = value;
  335. }
  336. }
  337. /// <summary>
  338. /// Gets or sets search option.
  339. /// </summary>
  340. public string PagingMode
  341. {
  342. get
  343. {
  344. return ValidationHelper.GetString(this.GetValue("PagingMode"), srchResults.PagingMode.ToString());
  345. }
  346. set
  347. {
  348. SetValue("PagingMode", value);
  349. srchResults.PagingMode = UniPagerMode.Querystring;
  350. if (value == "postback")
  351. {
  352. srchResults.PagingMode = UniPagerMode.PostBack;
  353. }
  354. }
  355. }
  356. /// <summary>
  357. /// Gets or sets query string key.
  358. /// </summary>
  359. public string QueryStringKey
  360. {
  361. get
  362. {
  363. return ValidationHelper.GetString(this.GetValue("QueryStringKey"), srchResults.QueryStringKey);
  364. }
  365. set
  366. {
  367. this.SetValue("QueryStringKey", value);
  368. srchResults.QueryStringKey = value;
  369. }
  370. }
  371. /// <summary>
  372. /// Gets or sets group size.
  373. /// </summary>
  374. public int GroupSize
  375. {
  376. get
  377. {
  378. return ValidationHelper.GetInteger(this.GetValue("GroupSize"), srchResults.PageSize);
  379. }
  380. set
  381. {
  382. this.SetValue("GroupSize", value);
  383. srchResults.PageSize = value;
  384. }
  385. }
  386. /// <summary>
  387. /// Gets or sets the value that indicates whether first and last item template are displayed dynamically based on current view.
  388. /// </summary>
  389. public bool DisplayFirstLastAutomatically
  390. {
  391. get
  392. {
  393. return ValidationHelper.GetBoolean(GetValue("DisplayFirstLastAutomatically"), srchResults.DisplayFirstLastAutomatically);
  394. }
  395. set
  396. {
  397. SetValue("DisplayFirstLastAutomatically", value);
  398. srchResults.DisplayFirstLastAutomatically = value;
  399. }
  400. }
  401. /// <summary>
  402. /// Gets or sets the value that indicates whether first and last item template are displayed dynamically based on current view.
  403. /// </summary>
  404. public bool DisplayPreviousNextAutomatically
  405. {
  406. get
  407. {
  408. return ValidationHelper.GetBoolean(GetValue("DisplayPreviousNextAutomatically"), srchResults.DisplayPreviousNextAutomatically);
  409. }
  410. set
  411. {
  412. SetValue("DisplayPreviousNextAutomatically", value);
  413. srchResults.DisplayPreviousNextAutomatically = value;
  414. }
  415. }
  416. /// <summary>
  417. /// Gets or sets the value that indicates whether pager should be hidden for single page.
  418. /// </summary>
  419. public bool HidePagerForSinglePage
  420. {
  421. get
  422. {
  423. return ValidationHelper.GetBoolean(GetValue("HidePagerForSinglePage"), srchResults.HidePagerForSinglePage);
  424. }
  425. set
  426. {
  427. SetValue("HidePagerForSinglePage", value);
  428. srchResults.HidePagerForSinglePage = value;
  429. }
  430. }
  431. /// <summary>
  432. /// Gets or sets the max. pages.
  433. /// </summary>
  434. public int MaxPages
  435. {
  436. get
  437. {
  438. return ValidationHelper.GetInteger(this.GetValue("MaxPages"), srchResults.MaxPages);
  439. }
  440. set
  441. {
  442. this.SetValue("MaxPages", value);
  443. srchResults.MaxPages = value;
  444. }
  445. }
  446. #endregion
  447. #region "UniPager Template properties"
  448. /// <summary>
  449. /// Gets or sets the pages template.
  450. /// </summary>
  451. public string PagesTemplate
  452. {
  453. get
  454. {
  455. return ValidationHelper.GetString(GetValue("Pages"), srchResults.PagesTemplateName);
  456. }
  457. set
  458. {
  459. SetValue("Pages", value);
  460. srchResults.PagesTemplateName = value;
  461. }
  462. }
  463. /// <summary>
  464. /// Gets or sets the current page template.
  465. /// </summary>
  466. public string CurrentPageTemplate
  467. {
  468. get
  469. {
  470. return ValidationHelper.GetString(GetValue("CurrentPage"), srchResults.CurrentPageTemplateName);
  471. }
  472. set
  473. {
  474. SetValue("CurrentPage", value);
  475. srchResults.CurrentPageTemplateName = value;
  476. }
  477. }
  478. /// <summary>
  479. /// Gets or sets the separator template.
  480. /// </summary>
  481. public string SeparatorTemplate
  482. {
  483. get
  484. {
  485. return ValidationHelper.GetString(GetValue("PageSeparator"), srchResults.SeparatorTemplateName);
  486. }
  487. set
  488. {
  489. SetValue("PageSeparator", value);
  490. srchResults.SeparatorTemplateName = value;
  491. }
  492. }
  493. /// <summary>
  494. /// Gets or sets the first page template.
  495. /// </summary>
  496. public string FirstPageTemplate
  497. {
  498. get
  499. {
  500. return ValidationHelper.GetString(GetValue("FirstPage"), srchResults.FirstPageTemplateName);
  501. }
  502. set
  503. {
  504. SetValue("FirstPage", value);
  505. srchResults.FirstPageTemplateName = value;
  506. }
  507. }
  508. /// <summary>
  509. /// Gets or sets the last page template.
  510. /// </summary>
  511. public string LastPageTemplate
  512. {
  513. get
  514. {
  515. return ValidationHelper.GetString(GetValue("LastPage"), srchResults.LastPageTemplateName);
  516. }
  517. set
  518. {
  519. SetValue("LastPage", value);
  520. srchResults.LastPageTemplateName = value;
  521. }
  522. }
  523. /// <summary>
  524. /// Gets or sets the previous page template.
  525. /// </summary>
  526. public string PreviousPageTemplate
  527. {
  528. get
  529. {
  530. return ValidationHelper.GetString(GetValue("PreviousPage"), srchResults.PreviousPageTemplateName);
  531. }
  532. set
  533. {
  534. SetValue("PreviousPage", value);
  535. srchResults.PreviousPageTemplateName = value;
  536. }
  537. }
  538. /// <summary>
  539. /// Gets or sets the next page template.
  540. /// </summary>
  541. public string NextPageTemplate
  542. {
  543. get
  544. {
  545. return ValidationHelper.GetString(GetValue("NextPage"), srchResults.NextPageTemplateName);
  546. }
  547. set
  548. {
  549. SetValue("NextPage", value);
  550. srchResults.NextPageTemplateName = value;
  551. }
  552. }
  553. /// <summary>
  554. /// Gets or sets the previous group template.
  555. /// </summary>
  556. public string PreviousGroupTemplate
  557. {
  558. get
  559. {
  560. return ValidationHelper.GetString(GetValue("PreviousGroup"), srchResults.PreviousGroupTemplateName);
  561. }
  562. set
  563. {
  564. SetValue("PreviousGroup", value);
  565. srchResults.NextPageTemplateName = value;
  566. }
  567. }
  568. /// <summary>
  569. /// Gets or sets the next group template.
  570. /// </summary>
  571. public string NextGroupTemplate
  572. {
  573. get
  574. {
  575. return ValidationHelper.GetString(GetValue("NextGroup"), srchResults.NextGroupTemplateName);
  576. }
  577. set
  578. {
  579. SetValue("NextGroup", value);
  580. srchResults.NextGroupTemplateName = value;
  581. }
  582. }
  583. /// <summary>
  584. /// Gets or sets the layout template.
  585. /// </summary>
  586. public string LayoutTemplate
  587. {
  588. get
  589. {
  590. return ValidationHelper.GetString(GetValue("PagerLayout"), srchResults.LayoutTemplateName);
  591. }
  592. set
  593. {
  594. SetValue("PagerLayout", value);
  595. srchResults.LayoutTemplateName = value;
  596. }
  597. }
  598. #endregion
  599. #region "Methods"
  600. /// <summary>
  601. /// Content loaded event handler.
  602. /// </summary>
  603. public override void OnContentLoaded()
  604. {
  605. base.OnContentLoaded();
  606. SetupControl();
  607. }
  608. /// <summary>
  609. /// Initializes the control properties.
  610. /// </summary>
  611. protected void SetupControl()
  612. {
  613. if (this.StopProcessing)
  614. {
  615. // Do nothing
  616. srchDialog.StopProcessing = true;
  617. srchResults.StopProcessing = true;
  618. }
  619. else
  620. {
  621. string webpartID = ValidationHelper.GetString(this.GetValue("WebPartControlID"), this.ClientID);
  622. // Set settings to search dialog
  623. srchDialog.SearchForLabel = this.SearchForLabel;
  624. srchDialog.SearchModeLabel = this.SearchModeLabel;
  625. srchDialog.SearchButton = this.SearchButton;
  626. srchDialog.SearchMode = this.SearchMode;
  627. srchDialog.ShowSearchMode = this.ShowSearchMode;
  628. srchDialog.FilterID = webpartID;
  629. srchDialog.ResultWebpartID = webpartID + mFilterSuffix;
  630. srchDialog.LoadData();
  631. // Get unipage mode
  632. UniPagerMode mode = UniPagerMode.Querystring;
  633. if (PagingMode == "postback")
  634. {
  635. mode = UniPagerMode.PostBack;
  636. }
  637. // Search results properties
  638. srchResults.SearchSort = SearchSort;
  639. srchResults.Indexes = Indexes;
  640. srchResults.Path = Path;
  641. srchResults.DocumentTypes = DocumentTypes;
  642. srchResults.CheckPermissions = CheckPermissions;
  643. srchResults.SearchOptions = SearchOptions;
  644. srchResults.TransformationName = TransformationName;
  645. srchResults.CultureCode = CultureCode;
  646. srchResults.CombineWithDefaultCulture = CombineWithDefaultCulture;
  647. srchResults.SearchInAttachments = SearchInAttachments;
  648. srchResults.AttachmentsOrderBy = AttachmentsOrderBy;
  649. srchResults.AttachmentsWhere = AttachmentsWhere;
  650. srchResults.NoResultsText = NoResultsText;
  651. srchResults.FilterID = webpartID + mFilterSuffix;
  652. srchResults.SearchCondition = SearchCondition;
  653. srchResults.LoadData();
  654. // UniPager properties
  655. srchResults.PageSize = PageSize;
  656. srchResults.GroupSize = GroupSize;
  657. srchResults.QueryStringKey = QueryStringKey;
  658. srchResults.DisplayFirstLastAutomatically = DisplayFirstLastAutomatically;
  659. srchResults.DisplayPreviousNextAutomatically = DisplayPreviousNextAutomatically;
  660. srchResults.HidePagerForSinglePage = HidePagerForSinglePage;
  661. srchResults.PagingMode = mode;
  662. srchResults.MaxPages = this.MaxPages;
  663. srchResults.MaxResults = this.MaxResults;
  664. // Unipager template properties
  665. srchResults.PagesTemplateName = PagesTemplate;
  666. srchResults.CurrentPageTemplateName = CurrentPageTemplate;
  667. srchResults.SeparatorTemplateName = SeparatorTemplate;
  668. srchResults.FirstPageTemplateName = FirstPageTemplate;
  669. srchResults.LastPageTemplateName = LastPageTemplate;
  670. srchResults.PreviousPageTemplateName = PreviousPageTemplate;
  671. srchResults.NextPageTemplateName = NextPageTemplate;
  672. srchResults.PreviousGroupTemplateName = PreviousGroupTemplate;
  673. srchResults.NextGroupTemplateName = NextGroupTemplate;
  674. srchResults.LayoutTemplateName = LayoutTemplate;
  675. }
  676. }
  677. /// <summary>
  678. /// Reloads data.
  679. /// </summary>
  680. public override void ReloadData()
  681. {
  682. SetupControl();
  683. base.ReloadData();
  684. }
  685. #endregion
  686. }