Skip to content

Instantly share code, notes, and snippets.

View zoghal's full-sized avatar
🏠
Working from home

Saleh Souzanchi zoghal

🏠
Working from home
View GitHub Profile
@zoghal
zoghal / view.handlebars
Created July 25, 2012 02:54 — forked from coop/view.handlebars
Getting access to form properties in Ember.js
<form>
<div>
<label for="name">Name</label>
{{view Ember.TextField valueBinding="view.name"}}
</div>
<div>
<label for="application">Application</label>
{{view Ember.TextField valueBinding="view.file" type="file"}}
</div>
@zoghal
zoghal / localization_helper.js
Created July 24, 2012 19:23 — forked from davidwkeith/localization_helper.js
Localization Helper for Ember.js's Handlebars
Handlebars.registerHelper('loc', function(property, fn) {
var str;
// we are bound to a value, it is now the context
if (fn.contexts && typeof fn.contexts[0] === 'string') {
str = fn.contexts[0];
// Convention, start all localization keys with _
} else if (property[0] === '_') {
str = property;
@zoghal
zoghal / ember-store.js
Created July 10, 2012 22:32
Ember-Data Example
// <== BOOTSTRAP
var App = Ember.Application.create();
App.stateManager = Ember.StateManager.create();
DS.fixtureAdapter.createRecord = function(store, type, record) {
var json = record.toJSON();
json.id = 1;
store.didCreateRecord(record, json);
@zoghal
zoghal / index.html
Created July 1, 2012 07:00 — forked from fpauser/index.html
Ember.Router
<!doctype html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type='text/javascript' src="http://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script>
<script type='text/javascript' src="http://cloud.github.com/downloads/emberjs/ember.js/ember-latest.js"></script>
</head><body>
<script type="text/x-handlebars" data-template-name="application">
<h1>Application</h1>
<a href="#/dashboard">Dashboard</a>
@zoghal
zoghal / gist:2918210
Created June 12, 2012 15:31 — forked from xdissent/gist:2860403
Ember-data hasMany computed properties test
test("filtered property on hasMany assoctiation", function() {
var File = DS.Model.extend({
primaryKey: 'name',
name: DS.attr('string'),
status: DS.attr('string')
});
var Project = DS.Model.extend({
primaryKey: 'name',
Species = DS.Model.extend({
name: DS.attr('string')
});
Person = DS.Model.extend({
name: DS.attr('string'),
species: DS.belongsTo(Species, { embedded: true })
tags: DS.hasMany(Tag, { embedded: true })
});
@zoghal
zoghal / coffeescript
Created June 4, 2012 20:35 — forked from krisselden/gist:1473687
Ember ajax wrapper
App.ajax = (url, settings)->
deferred = $.Deferred()
settings.xhr = ->
xhr = $.ajaxSettings.xhr()
if 'onprogress' of xhr
context = this
xhr.onprogress = (e)->
Ember.run(deferred, deferred.notifyWith, context, [e.loaded/e.total])
xhr
jqXHR = $.ajax(url, settings)
@zoghal
zoghal / app.js
Created June 4, 2012 20:21 — forked from johanvalcoog/app.js
ember.js login form
App = Ember.Application.create({});
App.loginController = Ember.Object.create({
// do login stuff
});
App.LoginFormView = Ember.View.extend({
login: null,
password: null,
@zoghal
zoghal / loginState.js
Created June 4, 2012 19:53
Ember.js login animations
App.LoginState = Ember.State.extend({
enter: function() {
App.loginView = App.LoginView.create();
App.loginView.appendTo('#content.container');
},
submit: function(a, params) {
App.loginView.loggingIn();
findAll: function(store, type) {
var root = this.rootForType(type);
this.ajax(root, "GET", {
success: function(json) {
store.loadMany(type, json["objects"]);
store.typeMapFor(type).modelArrays.forEach( function(item) {
item.set('isLoaded', true);
});