Skip to content

Instantly share code, notes, and snippets.

View johnpapa's full-sized avatar
💭
🐺Winter is coming

John Papa johnpapa

💭
🐺Winter is coming
View GitHub Profile
my.router = (function () {
// Client-side routes
Sammy(function () {
this.get('#:folder', function () {
amplify.request({ // This would instead call the data service, not amplify
resourceId: "getFolder",
data: { folder: this.params.folder },
success: my.webmailVM.displayFolderCallback, // I don't like that it calls the VM.
error: function () {
toastR.error('oops!');
<%@ Page
Inherits="ViewPage<GenericPresentationModel<object>>"
Language="C#"
MasterPageFile="~/Views/Shared/Site.master" %>
<asp:Content runat="server" ContentPlaceHolderID="ViewHead">
<%
Bundles.Reference("Content/New/Styles/App.less");
Bundles.Reference("Content/New/Scripts");
Bundles.AddPageData("accountData", Model.Model);
var Attendance = function () {
var self = this;
self.datacontext = datacontext;
self.sessionId = ko.observable();
self.personId = ko.observable();
// id is string compound key {personId,sessionId} like "3,10"
self.id = ko.computed({
read: function () {
return attendanceMakeId(self.personId(), self.sessionId());
@johnpapa
johnpapa / partial main.js
Created June 18, 2012 03:41
partial main.js
requirejs([
// 3rd party libraries
'json2',
'jquery',
'underscore',
'moment',
'sammy',
'amplify',
'ko',
'toastr',
@johnpapa
johnpapa / DirtyFlag
Created June 18, 2012 03:44
DirtyFlag
define(['ko'], function(ko) {
// (function (ko) {
ko.DirtyFlag = function (objectToTrack, isInitiallyDirty, hashFunction) {
hashFunction = hashFunction || ko.toJSON;
var
_objectToTrack = objectToTrack,
_lastCleanState = ko.observable(hashFunction(_objectToTrack)),
_isInitiallyDirty = ko.observable(isInitiallyDirty),
@johnpapa
johnpapa / main.js for Jim
Created June 26, 2012 17:44
main.js for Jim
requirejs.config({
// script default location
baseUrl: 'scripts/app',
// shim in the libs that don't know define.amd (excluding extensions)
shim: {
'amplify': { deps: [], exports: 'amplify' },
// jquery 1.7.x understands define; no shim needed.
'jquery.ui': ['jquery'],
@johnpapa
johnpapa / main.js - now with less calories
Created June 27, 2012 14:07
main.js - now with less calories
(function () {
// Establish the root object, `window` in the browser, or `global` on the server.
var root = this;
requirejs.config(
{
baseUrl: 'scripts/app', /* script default location */
}
);
registerNonAmdLibs();
@johnpapa
johnpapa / EFRepository<T>
Created July 19, 2012 14:40
EF Repository Foundations
public class EFRepository<T> : IRepository<T> where T : class
{
public EFRepository(DbContext dbContext)
{
if (dbContext == null)
throw new ArgumentNullException("dbContext");
DbContext = dbContext;
DbSet = DbContext.Set<T>();
}
@johnpapa
johnpapa / model.attendance.js
Created August 7, 2012 01:56
model.attendance.js
define('model.attendance',
['ko'],
function (ko) {
var attendanceMakeId = function (personId, sessionId) {
return (personId + ',' + sessionId);
};
var Attendance = function () {
var self = this;
@johnpapa
johnpapa / gist:3342697
Created August 13, 2012 17:40
async command issues
saveCmd = ko.asyncCommand({
execute: function (complete) {
if (canEditSession()) {
setTimeout(function() {
$.when(datacontext.sessions.updateData(session()))
.always(complete);
}, 3000);
return;
}