Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Work Tasks

PropertyLookup​.cs

  • Last UpdatedMar 12, 2021
  • 2 minute read

using Skelta.Forms.Core;

using Skelta.Forms.Core.Controls;

namespace Custom.Forms.Controls

{

using System.Collections.Generic;

using System.Text;

/// <summary>

/// Lookup control for property window

/// </summary>

////[DesignerControl(992202, CoreDesigner.NextGenDesigner, DesignerCategory.Custom)]

[SuppressedPropertiesNextGen("DefaultValue;EnableResponsiveView")]

public class PropertyLookup : BaseDataExternalControl

{

public override BaseControl GetNewInstanceForClone()

{

var propertyLookup = new PropertyLookup

{

ImageClass = this.ImageClass,

ClickFunction = this.ClickFunction,

EnableDisplayValueBinding = this.EnableDisplayValueBinding

};

return propertyLookup;

}

/// <summary>

/// Get the Display name

/// </summary>

public static string TypeDisplayName

{

get

{

return "PropertyLookup";

}

}

public override string TypeAssociation

{

get

{

return "Custom";

}

}

/// <summary>

/// Get or set the Image name

/// </summary>

public string ImageClass

{

get;

set;

}

/// <summary>

/// Get or set the Click Function name

/// </summary>

public string ClickFunction

{

get;

set;

}

/// <summary>

/// Get or set the Property Lookup binding event

/// </summary>

public string PropertyLookupEvents

{

get;

set;

}

/// <summary>

/// Get or set a value indicating whether the control requires a Display Value binding property

/// </summary>

public bool EnableDisplayValueBinding

{

get;

set;

}

/// <summary>

/// Get a value indicating whether the control requires Display Value binding

/// </summary>

public override bool RequiresDisplayValueBinding

{

get

{

return this.EnableDisplayValueBinding;

}

}

/// <summary>

/// Set the Display Value handler

/// </summary>

public override string SetDisplayValueHandlerMethod

{

get

{

return Common.ViewUtilitiesVarName + ".updateDisplayValue;";

}

}

public override string GetViewModelDefinition()

{

var control = "_" + this.ParentForm.Id + "." + this.Id;

var stringBuilder = new StringBuilder();

stringBuilder.Append(base.GetViewModelDefinition());

stringBuilder.AppendLine(control + ".clickFunction=function (d, e) {propertyLookup." + this.ClickFunction + "(d, e," + control + ");};");

return stringBuilder.ToString();

}

/// <summary>

/// Get the control structure or the view

/// </summary>

/// <returns>The control view</returns>

public override string GetControlHtml()

{

AddCssFiles();

AddJsFiles();

var stringBuilder = new StringBuilder();

stringBuilder.AppendLine("<div class=\"" + CssClasses.EventLookup + "\">");

stringBuilder.AppendLine("<div class=\"" + CssClasses.FlexContent + "\">");

stringBuilder.Append("<input type='text' id='" + this.Id + "' readonly ='readonly'");

stringBuilder.Append(this.DataBindProperties());

stringBuilder.Append("class='" + CssClasses.FlexContent + " " + CssClasses.Inputs + "' >");

stringBuilder.AppendLine("</div>");

stringBuilder.AppendLine("<div>");

stringBuilder.AppendLine("<div class='" + this.ImageClass + "' " + BaseDataControl.DataBindAttribute + "='click:" + this.Id + ".clickFunction, clickBubble:false' ></div>");

stringBuilder.AppendLine("</div>");

stringBuilder.AppendLine("</div>");

return stringBuilder.ToString();

}

private void AddJsFiles()

{

if (string.IsNullOrEmpty(this.TopLevelForm.RuntimeJS["PropertyLookup.js"]))

{

// "this.TopLevelForm.RuntimeJS" is the collection which holds your custom JS files.

// It is a key-value pair collection where the key is the file name and the value is the file path(absolute or relative).

// Ensure the JS files are present in the "BPMUITemplates\Default\NextGenForms\js" folder. Otherwise, it will not be rendered.

this.TopLevelForm.RuntimeJS.Add("PropertyLookup.js", "js/PropertyLookup.js");

}

}

/// <summary>

/// Method to add the CSS files associated with the custom control

/// </summary>

private void AddCssFiles()

{

if (string.IsNullOrEmpty(this.TopLevelForm.RuntimeCss["PropertyLookup.css"]))

{

this.TopLevelForm.RuntimeCss.Add("PropertyLookup.css", "css/PropertyLookup.css");

}

}

/// <summary>

/// Data bind properties of property lookup input field

/// </summary>

/// <returns>Data bind attribute value</returns>

private string DataBindProperties()

{

var dataBindProperties = new List<string>

{

"value:" + this.Id + (this.RequiresDisplayValueBinding ? "._displayValue" : "._value"),

"mandatory:" + this.Id + "._isMandatory",

"hasfocus:" + this.Id + "._lostFocus"

};

return Common.GetDataBindAttributeString(dataBindProperties.ToArray());

}

}

}

TitleResults for “How to create a CRG?”Also Available in