Skip to content

Instantly share code, notes, and snippets.

View alexspeller's full-sized avatar
🏁

Alex Speller alexspeller

🏁
View GitHub Profile
@alexspeller
alexspeller / router.js
Last active December 20, 2015 21:28 — forked from bricker/router.js
ArticlesRoute = Em.Route.extend({
model: function() {
Article.find({page: 1});
return Article.all();
}
});
ArticlesController = Em.ArrayController.extend({
currentPage: 1,
I have the following snippets of code:
//my-custom-view.js
MyCustomView = Ember.View.extend({
myPropertyBinding: 'parentView.propertyINeed'
})
// outerView.handlebars
{{view MyCustomView}}
LibraryAdapter = Ember.RESTAdapter.extend
didFind: (record, id, data)->
if /^code:/.test(id)
id = data.id
record.load(id, data)
# Create a new class A with instance method a
A = Em.Object.extend
a: -> 1
# Create a new class B with instance method b
B = Em.Object.extend
b: -> 2
# Create a new class C with instance methods b & c
C = B.extend
App.RadioButtonGroup = Em.View.extend
templateName: 'radio_button_group'
classNames: ['radio-group']
groupName: (->
"radiogroup-#{Em.guidFor(@)}"
).property()
change: ->
@set 'value', @$('input:checked').val()
@alexspeller
alexspeller / foo.js
Last active December 20, 2015 23:18
var utils = require('../utils.js');
var ChannelsModel = require('../models/channels.js');
var ChannelModel = require("../models/channel.js");
var ChannelsRoute = Ember.Route.extend({
model: function() {
return ChannelsModel.findAll().then(function(result){
return Ember.Object.create({
channels: result,
subChannels: function() {
{{#each button in view.content}}
<label>
<input type="radio" {{bindAttr value="button.value"}} {{bindAttr name="view.groupName"}}/>
{{button.label}}
</label>
{{/each}}
@alexspeller
alexspeller / base64encode.js.coffee
Last active December 21, 2015 04:38
Ember Table Extensions
# So, this is pretty horrible. If we just encode using btoa, any UTF-8 chars cause an error.
# If we use either of the workarounds on MDN[1], the £ sign is encoded wrong. I suspect
# Excel totally sucking at encodings is the reason why. So, the workaround is, to use
# the MDN workaround on chars with values > 255, and allow chars 0-255 to be encoded
# as is with btoa. Note that if you use either of the workarounds on MDN, chars
# 128-255 will be encoded as UTF-8, which includeds the £ sign. This will cause excel
# to choke on these chars. Excel will still choke on chars > 255, but at least the £
# sign works now...
# [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding
MyAdapter = Ember.RESTAdapter.extend
didSaveRecord: (record, data) ->
rootKey = Em.get(record.constructor, 'rootKey')
primaryKey = Em.get(record.constructor, 'primaryKey')
dataToLoad = if rootKey then data[rootKey] else data
if dataToLoad
record.load(dataToLoad[primaryKey], dataToLoad)
record.didSaveRecord()
App.Book.adapter = MyAdapter.create()
// RESOURCES
filteredContent: function() {
var view = this;
active_asset = view.get('settings.active_asset'),
active_playlist = view.get('parentView.settings.active_playlist'),
smart_playlist = ['all', 'pending_review', 'reviewed', 'approved'],
content = view.get('context.resources');
view.set('activePlaylist', null);
switch(active_playlist) {