Skip to content

Instantly share code, notes, and snippets.

@gregwiechec
Created July 8, 2015 07:48
Show Gist options
  • Save gregwiechec/bb63f5a218ca9696e87e to your computer and use it in GitHub Desktop.
Save gregwiechec/bb63f5a218ca9696e87e to your computer and use it in GitHub Desktop.
Extended CheckboxList property
define([
"dojo/_base/declare",
"dojo/_base/array",
"epi-cms/contentediting/editors/CheckBoxListEditor"
], function (
declare,
array,
_CheckBoxListEditor
) {
return declare("alloy.editors.extendedCheckBoxListEditor", _CheckBoxListEditor, {
buildRendering: function () {
this.inherited(arguments);
if (this.readOnly) {
return;
}
array.forEach(this._checkboxes, this._setCheckboxEnabled, this);
},
_setCheckboxEnabled: function(checkbox) {
var selectedItem = array.filter(this.selections, function (item) {
return item.value == checkbox.value;
}, this)[0];
checkbox.set("readOnly", selectedItem.enabled === false);
}
});
});
public class ExtendedSelectItem : SelectItem
{
public bool Enabled { get; set; }
}
public class ProductPage : StandardPage
{
//...
[ClientEditor(ClientEditingClass = "alloy.editors.extendedCheckBoxListEditor", SelectionFactoryType = typeof(ContinentSelectionFactory))]
public virtual string Continents { get; set; }
//...
}
using System.Collections.Generic;
using EPiServer.Shell.ObjectEditing;
namespace EpiServerThumbnail.Business.EditorDescriptors
{
public class ContinentSelectionFactory: ISelectionFactory
{
public IEnumerable GetSelections(ExtendedMetadata metadata)
{
var items = new[]
{
new ExtendedSelectItem
{
Enabled = false,
Text = "Australia",
Value = "Au"
},
new ExtendedSelectItem
{
Enabled = true,
Text = "Africa",
Value = "Af"
},
new ExtendedSelectItem
{
Enabled = true,
Text = "Asia",
Value = "As"
},
new ExtendedSelectItem
{
Enabled = true,
Text = "Europe",
Value = "Eu",
},
new ExtendedSelectItem
{
Enabled = true,
Text = "North America",
Value = "NoAm"
},
new ExtendedSelectItem
{
Enabled = false,
Text = "South America",
Value = "SoAm"
}
};
return items;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment