Created
July 21, 2011 09:07
-
-
Save k33g/1096826 to your computer and use it in GitHub Desktop.
Species.MVC à la Papa, dédicace à @loic_d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var Customer = Species.Class({ | |
Extends : Species.Model, | |
Name : { | |
get : function() { return this.name; }, | |
set : function(value) { this.name = value; } | |
}, | |
Budget : { | |
get : function() { return this.budget; }, | |
set : function(value) { this.budget = value; } | |
}, | |
initialize : function _Customer(id, name, budget){ | |
console.log(this.UID); | |
this.name = name; | |
this.id = id; | |
this.budget = budget; | |
} | |
}); | |
var Customers = Species.Class({ | |
Extends : Species.ModelHelper, | |
initialize : function _CustomerHelper() { | |
this.Model = Customer; | |
} | |
}); | |
var CustomerController = Species.Class({ | |
Extends : Species.Controller, | |
populate : function() { | |
var toto = Customer.New("001", "TOTO", 45000); | |
var tutu = Customer.New("002", "TUTU", 3000); | |
var tata = this.customers.clone(tutu); | |
tata.Id = "003"; | |
tata.Name = "TATA"; | |
//this.customers.add([toto, tutu, tata]); | |
this.customers.add(toto); | |
this.customers.add(tutu); | |
this.customers.add(tata); | |
this.customers.save(toto); | |
this.customers.save(tutu); | |
this.customers.save(tata); | |
this.customers.each(function(e) { | |
$("#customersList").append("<li>" + e.Id + " : " + e.Name + " : " + e.Budget + "</li>"); | |
}); | |
/*this.customers.getAll().forEach(function(e) { console.log( e.Id, e.Name, e.Budget); } );*/ | |
}, | |
initialize : function _CustomerController() { | |
var that = this; | |
this.customers = Customers.New(), | |
this.customers.bind({ | |
method : "add", | |
before : function(data){ console.log("BEFORE ADD : " + data.Name); } , | |
after : function(data){ console.log("AFTER ADD : " + data.Name); } | |
}); | |
this.customers.bind({ | |
method : "save", | |
after : function(data){ console.log(data.UID + " : " + data.Name + " ("+ data.Id +") SAVED"); } | |
}) | |
this.View = $('#customersView'); /* pour le moment pas utilisée */ | |
this.Events = [ | |
{ | |
element : '#cmd01', | |
event : 'click', | |
onEvent : function(){ | |
$('result').html(that.customers.find(function(e) { return e.Budget === 3000; } ).Name); | |
} | |
}, | |
{ | |
element : '#cmd02', | |
event : 'click', | |
onEvent : function(){ | |
$('result').html(''); | |
that.customers.filter(function(e) { | |
return e.Budget === 3000; | |
} ).forEach(function(e){ | |
$('result').html(e.Name + ' - ' + $('result').html()); | |
}); | |
} | |
} | |
]; | |
this.populate(); | |
} | |
}); | |
var control = CustomerController.New(); | |
}()); |
oh p... mme pas eu le tps de faire la surprise ;)
…On Thu, Jul 21, 2011 at 11:17 AM, mklabs < ***@***.***>wrote:
MVC la Papa @loicdescotte on tiens un truc l!
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1096826
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MVC à la Papa @loicdescotte on tiens un truc là!