Skip to content

Instantly share code, notes, and snippets.

View PetersonDave's full-sized avatar

David Peterson PetersonDave

View GitHub Profile
@PetersonDave
PetersonDave / gist:7636551
Created November 25, 2013 04:51
routing with Sitecore item version number
function getRoutes() {
return [
{
url: '/profiles',
config: {
templateUrl: 'Views/allprofiles?v=4',
controller: 'allprofiles'
}
}, {
url: '/profiles/:profileId',
@PetersonDave
PetersonDave / gist:7636456
Created November 25, 2013 04:39
Define the routes - templateUrls are all Sitecore items! Sitecore now serves our views :)
function getRoutes() {
return [
{
url: '/profiles',
config: {
templateUrl: 'Views/allprofiles',
controller: 'allprofiles'
}
}, {
url: '/profiles/:profileId',
@PetersonDave
PetersonDave / gist:7636427
Created November 25, 2013 04:35
Sitecore rendering for view within an Angular app
<%@ Control Language="c#" AutoEventWireup="true" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<div data-ng-controller="allprofiles as vm">
<p><a class="btn btn-primary btn-lg" ng-click="vm.load();">Load Data</a></p>
<div class="row" ng-repeat="profile in vm.repository">
<div class=" col-md-1">
<a class="btn btn-danger btn-small" href="#profiles/{{profile.ID}}">Edit</a>
</div>
<div class="col-md-1">{{profile.DisplayName}}</div>
<div class="col-md-6">{{profile.ID}}</div>
@PetersonDave
PetersonDave / gist:7636365
Created November 25, 2013 04:27
PartialView used as a layout for our Angular views in Sitecore
<%@ Page language="c#" Codepage="65001" AutoEventWireup="true" %>
<%@ OutputCache Location="None" VaryByParam="none" %>
<sc:FieldRenderer ID="FieldRenderer1" runat="server" FieldName="details" />
<sc:placeholder key="main" runat="server" />
@PetersonDave
PetersonDave / gist:7636020
Created November 25, 2013 03:46
Setting Sitecore Item Web API permissions
app.config(
...
'$httpProvider', function($httpProvider) {
$httpProvider.defaults.headers.put = { 'X-Scitemwebapi-Username': 'admin' };
$httpProvider.defaults.headers.put = { 'X-Scitemwebapi-Password': 'b' };
});
@PetersonDave
PetersonDave / gist:7635829
Created November 25, 2013 03:24
Angular view for populating based on controller allprofiles
<div data-ng-controller="allprofiles as vm">
<p><a class="btn btn-primary btn-lg" ng-click="vm.load();">Load Data</a></p>
<div class="row" ng-repeat="profile in vm.repository">
<div class=" col-md-1">
<a class="btn btn-danger btn-small" href="#profiles/{{profile.ID}}">Edit</a>
</div>
<div class="col-md-1">{{profile.DisplayName}}</div>
<div class="col-md-6">{{profile.ID}}</div>
</div>
@PetersonDave
PetersonDave / gist:7635778
Created November 25, 2013 03:17
Angular controller calling our factory profileService to pull Sitecore items
(function () {
'use strict';
// Controller name is handy for logging
var controllerId = 'allprofiles';
// Define the controller on the module.
// Inject the dependencies.
// Point to the controller definition function.
angular.module('app').controller(controllerId,
@PetersonDave
PetersonDave / gist:7635743
Created November 25, 2013 03:13
Example Angular Factory for obtaining Sitecore items
app.factory('profileservice', function ($http) {
var items = {};
var myProfileService = {};
myProfileService.addItem = function (item) {
items.push(item);
};
myProfileService.removeItem = function (item) {
var index = items.indexOf(item);
items.splice(index, 1);
@PetersonDave
PetersonDave / gist:6921465
Created October 10, 2013 16:37
Formats Sitecore WFFM save action to pull parameters field.
public class FormSaveActionUtilities
{
public static string GetGoogleAnalyticsScriptFromSaveAction(SubmitSuccessArgs args)
{
var googleAnalyticsSubmitActionId = new ID("{617DD7D9-950B-4767-B40A-CEFA848B64C6}");
var script = string.Empty;
var lid = ListDefinition.Parse(args.Form.SaveActions).Groups[0].ListItems;
if (lid == null) return script;
@PetersonDave
PetersonDave / gist:6921421
Created October 10, 2013 16:35
WFFM format success message in custom Save Action.
public class FormatSuccessMessage
{
public void Process(SubmitSuccessArgs args)
{
var script = FormSaveActionUtilities.GetGoogleAnalyticsScriptFromSaveAction(args);
Assert.IsNotNull((object)args, "args");
if (args.Form == null)
return;
args.Result = args.Form.SuccessMessage + script;