1: using System;
2: using System.Collections;
3: using System.Web.UI;
4:
5: using Sitecore;
6: using Sitecore.Data.Items;
7: using Sitecore.Diagnostics;
8: using Sitecore.Globalization;
9: using Sitecore.Resources;
10: using Sitecore.Shell.Applications.ContentEditor;
11: using Sitecore.Text;
12:
13: namespace SCUSAINC.Shell.Applications.ContentEditor
14: {
15: public class CustomLookup : LookupEx
16: {
17: // the name of the field that we have defined for the "Template field" template
18: private const string sourceFieldName = "SourceFieldName";
19: protected string itemlanguage;
20:
21: protected override void OnLoad(EventArgs args)
22: {
23: if (!Sitecore.Context.ClientPage.IsEvent)
24: {
25: Item contextItem = Sitecore.Context.ContentDatabase.Items[this.ItemID];
26:
27: foreach (TemplateFieldItem tfItem in contextItem.Template.OwnFields)
28: {
29: // do the necessary checks
30: if (tfItem.Source == this.Source &&
31: tfItem.InnerItem != null &&
32: tfItem.InnerItem.Fields[sourceFieldName] != null &&
33: tfItem.InnerItem.Fields[sourceFieldName].Value != string.Empty)
34: {
35: // setting the FieldName property that will store the field name of the data source item
36: // that we will consume in the "GetItemHeader" method
37: FieldName = tfItem.InnerItem.Fields[sourceFieldName].Value;
38: break;
39: }
40: }
41: }
42: base.OnLoad(args);
43: }
44:
45: protected override string GetItemHeader(Item item)
46: {
47: Assert.ArgumentNotNull(item, "item");
48: if (this.FieldName.StartsWith("@"))
49: {
50: return item[this.FieldName.Substring(1)];
51: }
52: if (this.FieldName.Length > 0)
53: {
54: if (ItemLanguage != null)
55: {
56: // return the language specific value of the source item's field
57: return Sitecore.Context.ContentDatabase.GetItem(item.ID, Language.Parse(ItemLanguage))[this.FieldName];
58: }
59: }
60: return item.DisplayName;
61: }
62:
63: // this method is used to retrieve the currently selected content language
64: // note that there is no code that sets this value, it is being set from outside by Content Editor
65: public string ItemLanguage
66: {
67: set { this.itemlanguage = value; }
68: get { return this.itemlanguage; }
69: }
70: }
71: }