Skip to content

Instantly share code, notes, and snippets.

View jamiepollock's full-sized avatar

Jamie Pollock jamiepollock

View GitHub Profile
@jamiepollock
jamiepollock / MultipleIPublishedTypeConverterBase.cs
Last active September 22, 2015 07:59
Ditto TypeConverter - Multiple IEnumerable<IPublishedContent> & Single IPublishedContent
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using Umbraco.Core;
using Umbraco.Core.Models;
namespace My.Website.ComponentModel.TypeConverters
{
public abstract class MultipleIPublishedContentTypeConverterBase<T> : TypeConverter
@jamiepollock
jamiepollock / DirectiveController.js
Created January 11, 2016 09:16
simpledatepicker - basic angularjs datetime picker for custom Umbraco backoffces. It's a little hacky :/
angular.module("umbraco.directives")
.directive('simpledatepicker', function ($parse, $filter, assetsService) {
return {
restrict: 'E',
scope: {
field: '='
},
controller: function ($scope, $element) {
assetsService.loadCss('/umbraco/lib/datetimepicker/bootstrap-datetimepicker.min.css').then(function () {
var filesToLoad = ["/umbraco/lib/moment/moment-with-locales.js",
@jamiepollock
jamiepollock / MyDirective.js
Created January 11, 2016 10:22
Simple reusable rte editor - wrapping umb-editor rte with a reusable config for use in a custom Umbraco backoffice ui
angular.module("umbraco.directives").directive('simplerichtexteditor', function (assetsService) {
return {
restrict: 'E',
scope: {
field: '='
},
controller: function ($scope, $element) {
$scope.model = {
alias: 'simpleRichtextEditor',
view: 'rte',
@jamiepollock
jamiepollock / CreateOnlyDictionaryHandler.cs
Last active July 29, 2020 08:24
A uSync custom DictionaryHandler which only imports items if they're missing. It will not overwrite any existing authored translations.
using Jumoo.uSync.BackOffice;
using Jumoo.uSync.BackOffice.Handlers;
using Jumoo.uSync.BackOffice.Helpers;
using Jumoo.uSync.Core;
using Jumoo.uSync.Core.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
@jamiepollock
jamiepollock / ArchetypeLabelHelper.js
Created April 7, 2016 16:48
A JS Helper for making Umbraco Archetype template labels beautiful :)
var ArchetypeLabelHelper = (function () {
//private helpers
if (!String.prototype.format) {
String.prototype.format = function () {
var args = arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
@jamiepollock
jamiepollock / MyContentSmellerEventHandler.cs
Created June 7, 2016 15:02
Untested example of checking what's changed between revisions of a IContent save event handler in Umbraco.
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
namespace My.App.Events
{
public class MyContentSmellerEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
@jamiepollock
jamiepollock / ProtectedContentNotifyEventHandler.cs
Last active June 27, 2016 13:04
ProtectedContentNotifyEventHandler an Umbraco event which will look for any members who have access to the current content node being saved then send an email to them
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
namespace DemoApp
{
public class ProtectedContentNotifyEventHandler : ApplicationEventHandler
@jamiepollock
jamiepollock / AddCustomPropertyToBeAddedLaterToMyPocoTable.cs
Last active May 15, 2018 23:57
Code to represent using custom Umbraco Migrations with Umbraco v7.3.0
using System;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Migrations;
using Umbraco.Core.Persistence.SqlSyntax;
namespace MyApp.Migrations
{
[Migration("1.1.0", 1, MyCustomSectionMigrationConstants.ProductName)]
public class AddCustomPropertyToBeAddedLaterToMyPocoTable : MigrationBase
@jamiepollock
jamiepollock / LocalizedEditorModelEventManagerEventHandler.cs
Created October 21, 2016 16:30
Working with EditorModelEventManager to localise an EditorContentModel powered by /config/lang/*.user.xml files
using System.Collections.Generic;
using System.Globalization;
using Umbraco.Core;
using Umbraco.Core.Services;
using Umbraco.Web;
using Umbraco.Web.Editors;
using Umbraco.Web.Models.ContentEditing;
namespace MyWebsite
{
@jamiepollock
jamiepollock / FormHtmlApiController.cs
Created January 26, 2017 19:12
In Theory (TM)! How to return an Umbraco Form HTML from an ApiController
using System.Web;
using Umbraco.Web.WebApi;
namespace My.Website.Controllers.Api
{
public class FormHtmlApiController : UmbracoApiController
{
public IHtmlString Get(string id)
{
return Umbraco.RenderMacro("FormsRenderForm", new { FormGuid = id });