Permalink
Browse files

Lien du front avec le server sails

  • Loading branch information...
hugomallet committed Mar 13, 2013
1 parent 7f091e4 commit f4b4177966f63d34366b58243d954564094a5179
View
@@ -20,7 +20,9 @@
"trailing": true,
"smarttabs": true,
"globals": {
- "$": "false",
- "gravityBlog": "false"
+ "$": false,
+ "_": false,
+ "Backbone": false,
+ "gravityBlog": false
}
}
View
@@ -21,7 +21,7 @@
<p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
<![endif]-->
- <div class="container">
+ <div id="container">
<div id="header">
@@ -1,5 +1,7 @@
gravityBlog.Collections.ArticleCollection = Backbone.Collection.extend({
- model: gravityBlog.Models.ArticleModel
+ model: gravityBlog.Models.ArticleModel,
+
+ url: 'http://localhost:1337/article/'
});
View
@@ -9,11 +9,11 @@ window.gravityBlog = {
console.log('| Gravity Blog Initialisation');
var articleList = new gravityBlog.Collections.ArticleCollection();
+ articleList.fetch();
gravityBlog.view = new gravityBlog.Views.applicationView({
collection : articleList,
});
-
}
};
@@ -1,11 +1,13 @@
+'use strict';
gravityBlog.Models.ArticleModel = Backbone.Model.extend({
defaults: {
- title: "titre par défaut",
- content: "content par défaut"
+ title: 'titre par défaut',
+ content: 'content par défaut'
},
-
+
initialize: function() {
- console.log("un nouvel article : ",this)
- },
+ console.log('New article: ', this);
+ }
+
});
@@ -1,70 +1,68 @@
+'use strict';
gravityBlog.Views.applicationView = Backbone.View.extend({
- el: $("#container"),
+ el: $('#container'),
- events: {
- "click #new-article": "createArticle",
- "click #add-article" : "showTools"
- },
+ events: {
+ 'click #new-article': 'createArticle',
+ 'click #add-article': 'showTools'
+ },
- initialize: function() {
- //this.collection appel la collection passée en paramètre dans le main.js
- this.addCollectionListener(this.collection);
- },
+ initialize: function() {
+ this.addCollectionListener(this.collection);
+ },
- addCollectionListener: function(collection) {
- collection.on('add', this.addOne, this);
- collection.on('remove', this.removeOne, this);
- collection.on('reset', this.reset, this);
+ addCollectionListener: function(collection) {
+ collection.on('add', this.addOne, this);
+ collection.on('remove', this.removeOne, this);
+ collection.on('reset', this.reset, this);
},
- addOne : function(article){
- var view = new gravityBlog.Views.articleView({
- model : article
- });
- //on ajoute la vue au DOM
- this.$el.find("#blog").prepend(view.render().el);
+ addOne: function(article) {
+ var view = new gravityBlog.Views.articleView({
+ model : article
+ });
+ //on ajoute la vue au DOM
+ this.$el.find('#blog').prepend(view.render().el);
return false;
},
- remove : function(){
+ remove: function() {
},
- reset : function(){
+ reset: function() {
+ this.collection.each(this.addOne, this);
},
- createArticle: function(){
- var articleObj = {},
- input_val = $("#new-title").val(),
- textarea_val= $("#new-content").val();
-
- if(input_val){
- articleObj.title=input_val;
- }
- if(textarea_val){
- articleObj.content = textarea_val;
- }
- //if(input_val && textarea_val){
- this.collection.add(articleObj);
- this.resetTools();
- this.hideTools();
- //}
+ createArticle: function(){
+ var articleObj = {},
+ inputVal = $('#new-title').val(),
+ textareaVal= $('#new-content').val();
- },
+ if(inputVal){
+ articleObj.title=inputVal;
+ }
+ if(textareaVal){
+ articleObj.content = textareaVal;
+ }
+ this.collection.create(articleObj);
+ this.resetTools();
+ this.hideTools();
+ },
- resetTools :function(){
- $("#new-title").val("");
- $("#new-content").val("");
- },
+ resetTools: function() {
+ $('#new-title').val('');
+ $('#new-content').val('');
+ },
- hideTools : function(){
- $("#createTool").hide();
- $("#add-article").show();
- },
+ hideTools: function() {
+ $('#createTool').hide();
+ $('#add-article').show();
+ },
- showTools : function(){
- $("#add-article").hide();
- $("#createTool").fadeIn();
- }
+ showTools: function() {
+ $('#add-article').hide();
+ $('#createTool').fadeIn();
+ }
});
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f4b4177

Please sign in to comment.