Skip to content

Instantly share code, notes, and snippets.

Created January 11, 2018 15:57
Show Gist options
  • Save anonymous/1c6999d10642f2afc1a743ce6af1c052 to your computer and use it in GitHub Desktop.
Save anonymous/1c6999d10642f2afc1a743ce6af1c052 to your computer and use it in GitHub Desktop.
Template for editable picklist column
#set($stringObjectName = "${pagegenerator.FormName}${qfcontrol.ControlId}_Strings")
## -----------Column and Grid macros -----------------------------------------------
#macro(doDefaultColParts $col)
field: '$col.DataField',
#if($col.TextFormatString != "")
displayFields: ['$col.DataField'],
displayFormatString: ${stringObjectName}['$generator.ConvertResourceKeyToScriptReference($col.getColResourceKey("FormatString"))'] || '$col.TextFormatString',
#end
#doHideCondition($col)
label: ${stringObjectName}['$generator.ConvertResourceKeyToScriptReference($col.getColResourceKey("ColumnHeading"))'] || '$col.ColumnHeading',
sortable: $generator.GetJavascriptBoolString($col.IsSortable)
#end
#macro(doStyleScheme $col)
#if ($col.StyleScheme != '')
className: '$col.StyleScheme',
#elseif ($col.HorizontalAlignment == 'right' || $col.HeaderAlignment == 'right')
className: 'alignright',
#elseif ($col.HorizontalAlignment == 'center' || $col.HeaderAlignment == 'center')
className: 'aligncenter',
#else
#end
#end
#macro(doStyleSchemeRight $col)
#if ($col.StyleScheme != '')
className: 'alignright ' + '$col.StyleScheme',
#elseif ($col.HorizontalAlignment == 'right' || $col.HeaderAlignment == 'right')
className: 'alignright',
#elseif ($col.HorizontalAlignment == 'center' || $col.HeaderAlignment == 'center')
className: 'aligncenter',
#else
#end
#end
#macro(doAbbreviationLength $col)
#if($col.AbbreviationLength > 0)
,formatter: Sage.Format.abbreviationFormatter(${col.AbbreviationLength})
#end
#end
#macro(doReadOnlyCondition $qfcontrol)
#if($qfcontrol.ReadOnlyCondition != "")
//Set to the value of the ReadOnlyCondition property
#if($qfcontrol.ReadOnlyCondition.ToLower() == "true" || $qfcontrol.ReadOnlyCondition.ToLower() == "false")
readOnly: ${qfcontrol.ReadOnlyCondition.ToLower()},
#else
readOnly: ${qfcontrol.ReadOnlyCondition}(),
#end
#end
#end
#macro(doHideCondition $col)
#if($col.HideCondition != "")
//Set to the value of the visibleCondition property
hidden: ${col.HideCondition}(),
unhidable: ${col.HideCondition}(),
#end
#end
#macro(doEditableField $col)
{
#doDefaultColParts($col),
#doStyleScheme($col)
defaultValue: '',
#doColIsEditableCondition($col),
editor: TextBox,
editOn: 'click'
#doAbbreviationLength ($col)
#if($col.CustomFormatter != "")
,formatter: ${col.CustomFormatter}
#end
}
#end
#macro(doDateTimeCol $col)
{
#doDefaultColParts($col),
#doStyleScheme($col)
dateOnly: $generator.GetJavascriptBoolString(${col.DateOnly}),
#if($col.AbbreviationLength > 0)
abbreviationLength: ${col.AbbreviationLength},
#end
type: DateTime
}
#end
#macro(doSlxUserCol $col)
{
#doDefaultColParts($col),
#doStyleScheme($col)
type: SlxUser
}
#end
#macro(doColIsEditableCondition $col)
#if($col.IsEditable != "")
#if($col.IsEditable.ToLower() == "true" || $col.IsEditable.ToLower() == "false")
editable: ${col.IsEditable.ToLower()}
#else
editable: ${col.IsEditable}()
#end
#else
editable: false,
#end
#end
#macro(doLookupCol $col)
{
#doDefaultColParts($col),
#doStyleScheme($col)
#doColIsEditableCondition($col),
type: Lookup,
editor: LookupControl,
editOn: 'click',
editorArgs: {
labelAttr: '$col.LookupDisplayProperty',
searchAttr: '$col.LookupDisplayProperty',
autoComplete: true,
required: true,
lookupOptions: {
field: '$col.LookupDisplayProperty',
seedOnRowEntity: $generator.GetJavascriptBoolString(${col.SeedOnRowEntity}),
seedOnRelatedEntity: '$col.SeedOnRelatedEntity',
returnObject: #if($col.LookupBindingMode == "Object")true #else false #end
},
lookupGridOptions: {
#if($col.ConditionalWhere != "")
contextualCondition: ${col.ConditionalWhere}
#end
},
lookupStoreOptions: {
resourceKind: #if ($col.ResourceKind == "")'$generator.GetSDataPathName(${col.DataField})' #else '$col.ResourceKind' #end
}
},
#doAbbreviationLength ($col)
}
#end
#macro(doCurrencyCol $col)
{
#doDefaultColParts($col),
#doStyleSchemeRight($col)
#doColIsEditableCondition($col),
#if($col.AbbreviationLength > 0)
abbreviationLength: ${col.AbbreviationLength},
#end
type: Currency,
editor: CurrencyControl,
editorArgs: {
constraints: { #if($col.DecimalDigits != "-1") places: ${col.DecimalDigits} #else places: Sys.CultureInfo.CurrentCulture.numberFormat.CurrencyDecimalDigits #end },
## TODO: Uncomment this after Exchange Rate Type enum has been updated
## exchangeRateType: #if ($col.ExchangeRateType == "") 'EntityRate' #else '$col.ExchangeRateType' #end,
exchangeRateType: #if ($col.ExchangeRateType == "OpportunityRate" || $col.ExchangeRateType == "SalesOrderRate") 'EntityRate' #else '$col.ExchangeRateType' #end,
displayCurrencyCode: $generator.GetJavascriptBoolString(${col.DisplayCurrencyCode}),
#if ($col.ExchangeRate != "")
exchangeRateField: '$col.ExchangeRate',
#end
#if ($col.CurrentCode != "")
exchangeRateCodeField: '$col.CurrentCode',
#end
displayMode: '$col.CurrencyDisplayMode',
multiCurrency: isMultiCurrencyEnabled() //TODO: Move this method to Sage.IntegrationContractService.isMultiCurrencyEnabled()
},
editOn: 'click'
}
#end
#macro(doLinkCol $col)
{
#doDefaultColParts($col)
#doStyleScheme($col)
,type: SlxLink
,editable: false
#if($col.AppliedSecurity != "")
,appliedSecurity: '$col.AppliedSecurity'
#end
#if($col.Target != "")
,target: '$col.Target'
#end
#if($col.EntityTypeName != ""),
#if($col.EntityTypeName.StartsWith("function()") || $col.EntityTypeName.StartsWith("function ()"))
pageName: $col.EntityTypeName,
#else
pageName: '$col.EntityTypeName',
#end
#if($col.EntityIdField.StartsWith("function()") || $col.EntityIdField.StartsWith("function ()"))
idField: $col.EntityIdField
#else
#if($col.EntityIdField == "Id")
idField: '$col.EntityIdField.Replace("Id", "$key")'
#else
idField: '$col.EntityIdField.Replace(".Id", ".$key")'
#end
#end
#elseif($col.DestinationFormatString != "")
,urlFields: [$col.DestinationBindFields]
,urlFormatString: ${stringObjectName}['$generator.ConvertResourceKeyToScriptReference($col.getColResourceKey("DestinationFormatString"))'] || '$col.DestinationFormatString'
#elseif($col.Destination != "")
,urlFields: []
,urlFormatString: '$col.Destination'
#end ## different linking types...
}
#end
#macro(doEditCol $col)
{
#if($col.DialogSpecs.SmartPart != "")
#doDefaultColParts($col),
type: SlxEdit,
unhidable: true,
editCellValue: ${stringObjectName}['$generator.ConvertResourceKeyToScriptReference($col.getColResourceKey("Text"))'] || '$col.Text',
entityType: '${col.DialogSpecs.GetFullyQualifiedEntityType()}',
smartPart: '${col.DialogSpecs.SmartPart}',
dialogTitle: ${stringObjectName}['$generator.ConvertResourceKeyToScriptReference("${col.DialogSpecs.ResourceKey}.DialogTitleOverride")'] || '${col.DialogSpecs.TitleOverride}',
isCentered: #if($col.DialogSpecs.CenterDialog == "True")true #else false #end,
dialogTop: ${col.DialogSpecs.Top},
dialogLeft: ${col.DialogSpecs.Left},
dialogHeight: ${col.DialogSpecs.Height},
dialogWidth: ${col.DialogSpecs.Width},
formObjectName: '${pagegenerator.FormScriptObjectName}'
#if($col.AppliedSecurity != "")
,appliedSecurity: '$col.AppliedSecurity'
#end
#end
}
#end
#macro(doCheckBoxCol $col)
{
#doDefaultColParts($col),
#doStyleScheme($col)
editor: CheckBox,
editorArgs: {
#if($col.IsEditable != "")
#if($col.IsEditable.ToLower() == "true")
disabled: false,
#elseif ($col.IsEditable.ToLower() == "false")
disabled: true,
#else
disabled: ${col.IsEditable}()
#end
#else
disabled: true,
#end
}
}
#end
#macro(doNumericCol $col)
{
#doDefaultColParts($col),
#doStyleScheme($col)
#doColIsEditableCondition($col),
type: NumericFormatter,
editor: Numeric,
editOn: 'click',
editorArgs: {
shouldPublishMarkDirty: false,
#if($col.AbbreviationLength > 0)
abbreviationLength: ${col.AbbreviationLength},
#end
constraints: { places: #if($col.DecimalDigits.DecimalDigits != "-1") #if($col.DecimalDigits.Strict == "True") ${col.DecimalDigits.DecimalDigits} #else '0,${col.DecimalDigits.DecimalDigits}' #end , #else Sys.CultureInfo.CurrentCulture.numberFormat.NumberDecimalDigits , #end round: -1 },
formatType: '${col.FormatType}'
},
}
#end
#macro(doPickListCol $col)
{
#doDefaultColParts($col),
#doStyleScheme($col)
#doColIsEditableCondition($col),
type: PickList,
pickListName: '${col.PickListName}',
storageMode: #if ($col.StorageMode == "Text") 'text' #elseif ($col.StorageMode == "Code") 'code' #elseif ($col.StorageMode == "ID") 'id' #end,
displayMode: '${col.DisplayMode}',
editOn: 'click',
editorArgs: {
pickListName: '${col.PickListName}',
storageMode: #if ($col.StorageMode == "Text") 'text' #elseif ($col.StorageMode == "Code") 'code' #elseif ($col.StorageMode == "ID") 'id' #end,
displayMode: '${col.DisplayMode}',
},
editor: DropDownSelectPickList
}
#end
#macro(doPhoneCol $col)
{
#doDefaultColParts($col),
#doStyleScheme($col)
#doColIsEditableCondition($col),
type: Phone,
editor: PhoneControl,
editOn: 'click'
}
#end
#macro(doEmailCol $col)
{
#doDefaultColParts($col),
#doStyleScheme($col)
#doColIsEditableCondition($col),
type: Email,
editor: EmailControl,
editOn: 'click'
}
#end
## ----------- Tool macros -----------------------------------------------
#macro(doBaseTool $tool)
id : '${pagegenerator.FormName}_$tool.Name',
displayInInsert : $generator.GetJavascriptBoolString($tool.DisplayInInsert),
imageClass: #if($tool.Image == "")'icon_No_icon_16x16',#else'$generator.getImageClassName($tool.Image)',#end
'alternateText' : ${stringObjectName}['$generator.ConvertResourceKeyToScriptReference(${tool.getResourceKey("ToolTip")})'] || '$tool.ToolTip',
#if($tool.StyleScheme != "")'class': '$tool.StyleScheme',#end
#if($tool.AppliedSecurity != "") appliedSecurity : '$tool.AppliedSecurity',#end
#if(${tool.MergeControlId} != "") mergePosition : '${tool.MergePosition}',#end
#if(${tool.MergeControlId} != "") mergeControlId : '${tool.MergeControlId}',#end
#end
#macro(doCustomBtn $tool)
{
#doBaseTool($tool)
'handler' : $tool.OnClick
}
#end
#macro(doAddBtn $tool)
{
#doBaseTool($tool)
'handler' : function() {
this.addNew({
scope: this,
onComplete: function(item) {
#if ($tool.OnClick != "")
var customAction = ${tool.OnClick};
customAction(item);
#end
this.store.saveNewEntity(item, function(entity) { grid._refresh(); }, function() { }, this );
}
}) }
}
#end
#macro(doCancelBtn $tool)
{
#doBaseTool($tool)
'handler' : function() { this.cancelChanges(); }
}
#end
#macro(doDeleteBtn $tool)
{
#doBaseTool($tool)
'handler' : function() { this.deleteSelected($tool.OnClick); }
}
#end
#macro(doSaveBtn $tool)
{
#doBaseTool($tool)
'handler' : function() {
this.saveChanges($tool.OnClick);
}
}
#end
#macro(doAddRelationBtn $tool)
{
id : '${pagegenerator.FormName}_$tool.Name',
displayInInsert : $generator.GetJavascriptBoolString($tool.DisplayInInsert),
#if($tool.StyleScheme != "")'class': '$tool.StyleScheme',#end
#if($tool.AppliedSecurity != "") appliedSecurity : '$tool.AppliedSecurity',#end
#if(${tool.MergeControlId} != "") mergePosition : '${tool.MergePosition}',#end
#if(${tool.MergeControlId} != "") mergeControlId : '${tool.MergeControlId}',#end
type : 'Sage.UI.SDataLookup',
controlConfig : $pagegenerator.parseControl($tool.LookupButton)
}
#end
## ----------- Actual grid start -----------------------------------------------
$pagegenerator.AddToInitializationScript("setTimeout(function() { ${pagegenerator.FormScriptObjectName}.makeGrid(runtimeConfig); }, 1);")
makeGrid : function(runtimeConfig) {
require([
'Sage/UI/Controls/GridParts/Columns/DateTime',
'Sage/UI/Controls/GridParts/Columns/SlxLink',
'Sage/UI/Controls/GridParts/Columns/SlxEdit',
'Sage/UI/Controls/GridParts/Columns/PickList',
'Sage/UI/Controls/GridParts/Columns/Phone',
'Sage/UI/Controls/GridParts/Columns/Email',
'Sage/UI/Controls/GridParts/Columns/CheckBox',
'Sage/UI/NumberTextBox',
'Sage/UI/Controls/GridParts/Columns/Numeric',
'Sage/UI/Controls/GridParts/Columns/Currency',
'Sage/UI/Controls/GridParts/Columns/Lookup',
'Sage/UI/GridView',
'Sage/UI/Controls/GridParts/Columns/SlxUser',
'Sage/Utility/Workspace',
'Sage/Data/SDataServiceRegistry',
'dijit/form/TextBox',
'Sage/UI/Controls/Phone',
'Sage/UI/Controls/GridParts/Columns/EmailControl',
'Sage/UI/Controls/CurrencyTextBox',
'Sage/UI/Controls/DropDownSelectPickList',
'Sage/UI/Controls/GridParts/Columns/LookupControl',
'dojo/when'
#if($qfcontrol.FeedCategory == "Proxy")
,'Sage/Data/ProxySDataStore'
#end
],
function(DateTime, SlxLink, SlxEdit, PickList, Phone, Email, CheckBox,
Numeric, NumericFormatter, Currency, Lookup, GridView, SlxUser, workspaceUtil, sDataServiceRegistry, TextBox, PhoneControl, EmailControl, CurrencyControl, DropDownSelectPickList, LookupControl, when) {
if (typeof $stringObjectName === 'undefined') {
$stringObjectName = {};
}
var options = {
#if($qfcontrol.AppliedSecurity != "")
appliedSecurity : '${qfcontrol.AppliedSecurity}',
#end
context: runtimeConfig,
#if($qfcontrol.EmptyTableRowText != "")
noDataMessage: ${stringObjectName}['$generator.ConvertResourceKeyToScriptReference("${qfcontrol.ControlId}.EmptyTableRowText")'] || '${qfcontrol.EmptyTableRowText}',
#end
#doReadOnlyCondition($qfcontrol)
columns: [
{
field: '$key',
editable: false,
excludeFromFilters: true,
unhidable: true,
hidden: true,
id: 'id',
formatter: function (value, rowIdx) {
return ['<div id=', value, ' >', value, '</ div>'].join('');
}
},
#set ($comma = "")
#foreach($column in $qfcontrol.Columns)
$comma
#if($column.ColumnType == "EditableField")#doEditableField($column)
#elseif($column.ColumnType == "Link")#doLinkCol($column)
#elseif($column.ColumnType == "Currency")#doCurrencyCol($column)
#elseif($column.ColumnType == "Lookup")#doLookupCol($column)
#elseif($column.ColumnType == "Edit")#doEditCol($column)
#elseif($column.ColumnType == "CheckBox")#doCheckBoxCol($column)
#elseif($column.ColumnType == "Numeric")#doNumericCol($column)
#elseif($column.ColumnType == "DateTime")#doDateTimeCol($column)
#elseif($column.ColumnType == "SlxUser")#doSlxUserCol($column)
#elseif($column.ColumnType == "PickList")#doPickListCol($column)
#elseif($column.ColumnType == "Phone")#doPhoneCol($column)
#elseif($column.ColumnType == "Email")#doEmailCol($column)
#end ##ColumnType checking
#set ($comma = ",")
#if($column.ColumnType == "Currency")
## TODO: Uncomment this condition when the EntityRateType enum has been updated
##$qfcontrol.SelectUtil.Clear()
## #if($column.ExchangeRateType == "EntityRate")
#if($column.ExchangeRate != "")
## The String Collection Add method returns the index. Set to a garbage var so it doesn't write to the output.
#if (!$qfcontrol.SelectUtil.Contains("$column.ExchangeRate")) #set ($garbage = $qfcontrol.SelectUtil.Add("$column.ExchangeRate")) #end
#if (!$qfcontrol.SelectUtil.Contains("$column.CurrentCode")) #set ($garbage = $qfcontrol.SelectUtil.Add("$column.CurrentCode")) #end
#end
#end
#end ## foreach
],
## Assemble the Select criteria from the Select property and any controls requiring additional fields
#if ($qfcontrol.Select.Count > 0)
#foreach($item in $qfcontrol.Select)
## The String Collection Add method returns the index. Set to a garbage var so it doesn't write to the output.
#if (!$qfcontrol.SelectUtil.Contains("$item")) #set ($garbage = $qfcontrol.SelectUtil.Add("$item")) #end
#end ##foreach
#end
#if($qfcontrol.FeedCategory == "Proxy")
store : new Sage.Data.ProxySDataStore({
service : Sage.Utility.getSDataService('proxy', true),
resourceKind: '${qfcontrol.ResourceKind.Name}',
#if($qfcontrol.ResourceKind.GetPredicate != "")
getResourcePredicate: ${qfcontrol.ResourceKind.GetPredicate},
#end
getAppId: ${qfcontrol.OnGetMappingId},
include: [${qfcontrol.StringsToQuotedArray($qfcontrol.Include)}],
select: [${qfcontrol.StringsToQuotedArray($qfcontrol.SelectUtil)}],
pathSegments: [
#set ($comma = "")
#foreach($seg in $qfcontrol.PathSegments)
$comma {
'text' : '$seg.Name'
#if($seg.GetPredicate != "")
,'getPredicate' : $seg.GetPredicate
#end ##if
}
#set ($comma = ",")
#end ##foreach
]
}),
#else
storeOptions: {
service: sDataServiceRegistry.getSDataService('dynamic'),
resourceKind: '$qfcontrol.ResourceKind',
#if (${qfcontrol.ParentRelationshipPropertyName} != "")
newItemParentReferenceProperty: '${qfcontrol.ParentRelationshipPropertyName}',
#end
include: [${qfcontrol.StringsToQuotedArray($qfcontrol.Include)}],
select: [${qfcontrol.StringsToQuotedArray($qfcontrol.SelectUtil)}],
//The .net vehicle to store grid data on postback
dataCarrierId: '${pagegenerator.FormName}${qfcontrol.ControlId}_DataCarrier',
#if($qfcontrol.ConditionalWhere != "")
where: ${qfcontrol.ConditionalWhere},
#elseif($qfcontrol.ParentRelationshipPropertyName != "")
where: function() { return '${qfcontrol.ParentRelationshipPropertyName}.Id eq "' + Sage.Utility.getCurrentEntityId() + '"'; },
#end
queryArgs: { count: ${qfcontrol.PageSize} },
},
#end
tools: [
#set ($comma = "")
#foreach($tool in $qfcontrol.Tools)
$comma
#if($tool.Name == "Add")#doAddBtn($tool)
#elseif($tool.Name == "Delete")#doDeleteBtn($tool)
#elseif($tool.Name == "Save")#doSaveBtn($tool)
#elseif($tool.Name == "Cancel")#doCancelBtn($tool)
#elseif($tool.Name == "Relate")#doAddRelationBtn($tool)
#else #doCustomBtn($tool)
#end ##button types
#set ($comma = ",")
#end ##foreach
],
#if($qfcontrol.OnDataChange != "")
onDataChange : ${qfcontrol.OnDataChange},
#end
tabId : '${pagegenerator.FormName}',
placeHolder: '${pagegenerator.FormName}${qfcontrol.ControlId}_Grid',
id : '${pagegenerator.FormName}${qfcontrol.ControlId}',
minRowsPerPage: ${qfcontrol.PageSize},
sort: [
## Default sort
#set ($comma = "")
#foreach($column in $qfcontrol.Columns)
#if ($column.SortDirection != "None")
$comma { attribute: "${column.SortField}"
#if ($column.SortDirection == "Descending")
,descending: true
#end
}
#set ($comma = ",")
#end
#end ## foreach
],
};
#if($qfcontrol.PreviewField != "")
options.previewField = '$qfcontrol.PreviewField';
#end
options.columnHiding = true;
options.columnResizing = true;
options.columnReordering = true;
options.selectionMode = 'extended';
options.rowSelection = true;
var grid = new GridView(options);
grid.createGridView();
#if (${qfcontrol.OnAdd} != "")
grid.store.onNew = ${qfcontrol.OnAdd} ;
#end
## if it was a relate tool, we might need to add more script...
#foreach($tool in $qfcontrol.Tools)
#if($tool.Name == 'Relate')
#if(${tool.LookupButton.OnSelection} == "")
var lup = dijit.byId('${tool.LookupButton.ControlId}');
if (lup) {
lup.doSelected = function (items) {
var grid = dijit.byId('${pagegenerator.FormName}${qfcontrol.ControlId}');
grid.addAssociatedItems(items, "${qfcontrol.ParentRelationshipPropertyName}", "${qfcontrol.ChildRelationshipPropertyName}", lup);
};
}
#end
#end ##if tool is Relate
#end ##foreach
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment