Skip to content

Instantly share code, notes, and snippets.

@gregwiechec
Created May 18, 2015 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregwiechec/d1138797b3df8f11e153 to your computer and use it in GitHub Desktop.
Save gregwiechec/d1138797b3df8f11e153 to your computer and use it in GitHub Desktop.
Inline checkbox editor
using System;
using System.Collections.Generic;
using EPiServer.Shell;
using EPiServer.Shell.ObjectEditing;
using EPiServer.Shell.ObjectEditing.EditorDescriptors;
namespace EpiServerThumbnail.Business.EditorDescriptors
{
[EditorDescriptorRegistration(TargetType = typeof (bool), UIHint = UiHint)]
[EditorDescriptorRegistration(TargetType = typeof(bool?), UIHint = UiHint)]
public class InlineBoleanEditorDescriptor : BooleanEditorDescriptor
{
public const string UiHint = "InlineBoolean";
public InlineBoleanEditorDescriptor()
{
this.ClientEditingClass = "epi.shell.widget.CheckBox";
}
public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
{
base.ModifyMetadata(metadata, attributes);
metadata.CustomEditorSettings["uiWrapperType"] = UiWrapperType.Inline;
metadata.CustomEditorSettings["uiType"] = "alloy.editors.inlineCheckbox";
}
}
}
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CheckboxProperty.ascx.cs" Inherits="EpiServerThumbnail.Views.Properties.CheckboxProperty" %>
<div class="property-checkbox"><%# this.CurrentData == null || this.CurrentData.Value == false ? "Maintenance message hidden": "Maintenance message visible" %></div>
define([
"dojo/_base/array",
"dojo/_base/connect",
"dojo/_base/declare",
"dojo/_base/lang",
"dojo/dom-construct",
"dijit/focus",
"dojo/on",
"dojo/query",
"dojo/dom-attr",
"dojo/dom-style",
"epi/dependency",
"dijit/Tooltip",
"epi/shell/widget/CheckBox"
],
function(
array,
connect,
declare,
lang,
domConstruct,
focusUtil,
on,
query,
domAttr,
domStyle,
dependency,
Tooltip,
CheckBox
) {
return declare("alloy.editors.inlineCheckbox", [CheckBox], {
labelNode: null,
postCreate: function () {
this.inherited(arguments);
this.own(
on(this.checkbox, "change", lang.hitch(this, function(e) {
this._updateText();
}))
);
this.labelNode = domConstruct.toDom("<label style='font-weight: bold;'>Show/hide message</label>");
domAttr.set(this.labelNode, "for", this.checkbox.id);
domConstruct.place(this.labelNode, this.checkbox.domNode, "after");
domStyle.set(this.domNode, "padding", "20px");
},
focus: function () {
this._makeContentEditable();
this.inherited(arguments);
},
isValid: function (/*Boolean*/ isFocused) {
return true;
},
_makeContentEditable: function () {
focusUtil.focus(this.domNode);
},
isEditing: function () {
return false;
},
_updateText: function() {
var value = this.get('value');
var propertyText = query('.property-checkbox', this.get("overlayItem").sourceItemNode);
if (value) {
propertyText.text("Maintenance message visible");
} else {
propertyText.text("Maintenance message hidden");
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment