Commit b00b3424 authored by alexandre's avatar alexandre

Contionnal render on the home page

parent d414b87f
......@@ -13,10 +13,15 @@ window.W = window.W || {};
keydown: 'keydown'
},
channelName:'user',
onStart: function(options) {
var channel = this.getChannel();
var radio = this.getChannel();
this.model = new W.UserAuthModel();
this.listenTo(this.model, 'change', function() { radio.request('change', this.model); });
var baseView = new W.BaseView({model: this.model});
this.showView(baseView);
baseView.model.fetch();
......
......@@ -45,7 +45,7 @@ window.W.utils = window.W.utils || {};
W.utils.translate = window.t = function (string) {
if (!(W.config.lang in W.lang)) {
console.log(W.config.lang + " n'est pas une langue defini. On passe au français");
// console.log(W.config.lang + " n'est pas une langue defini. On passe au français");
W.config.lang = "fr"
};
......@@ -54,7 +54,7 @@ window.W.utils = window.W.utils || {};
if (string in entries) {
return entries[string];
} else {
console.log(string + " n'est pas traduit");
// console.log(string + " n'est pas traduit");
return string;
}
}
......
......@@ -1719,6 +1719,7 @@ window.W = window.W || {};
template: '#score-template-vue',
attributes: function () {
console.log(this.model);
return {
id: 'score',
class: this.model.get('is_editable') ? "content" : "content read-only",
......@@ -2360,14 +2361,21 @@ window.W = window.W || {};
W.ScoreListFooView = Marionette.CollectionView.extend({
tagName: 'ol',
childView: W.ScoreItemView,
attributes: { class: 'score-list-foo' },
childViewContainer: 'ol',
childView: W.ScoreItemView,
template: _.template('<h1><%- title %></h1><ol class="score-list-foo"></ul>'),
initialize: function () {
templateContext: function () {
return {
title: this.title,
}
},
initialize: function (options) {
this.listenTo(this.collection, 'sync', this.render);
this.title = options.title || 'untitled section';
}
});
......@@ -2401,7 +2409,8 @@ window.W = window.W || {};
});
var myListView = new W.ScoreListFooView({
collection: scoreCollection
collection: scoreCollection,
title: "Partitions existantes"
});
var mySearchPanelView = new W.SearchPanelView({collection: scoreCollection});
......@@ -2456,7 +2465,8 @@ window.W = window.W || {};
var myListView = new W.ScoreListFooView({
collection: scoreCollection
collection: scoreCollection,
title: "Partitions partagées avec vous"
});
var that = this;
......@@ -2621,65 +2631,76 @@ window.W = window.W || {};
template: '#home-template',
regions: {
latest_updated: '#latest_updated',
user_scores: '#user_scores'
latest_updated: {
el: '#latest_updated',
replaceElement: true
},
user_scores: {
el: '#user_scores',
replaceElement: true
},
},
attributes: {
class: 'content',
},
onRender: function () {
var that = this;
initialize: function() {
Backbone.Radio.channel('user').reply('change', (this.renderUserScores).bind(this));
},
document.title = 'Notation W';
renderUserScores: function (model) {
if (model.get("username")) {
var collection = new W.ScoreCollection([], {
state: {
pageSize: 5,
sortKey: "updated_at",
order: -1
}
});
var scoreCollection = new W.ScoreCollection([], {
// url: '/test',
state: {
pageSize: 5,
// firstPage: 1,
// currentPage: 1,
sortKey: "updated_at",
order: 1,
}
});
collection.queryParams.shared_with = true;
scoreCollection.queryParams.is_featured=true;
var view = new W.ScoreListFooView({
title: _("Mes partitions"),
collection: collection
});
var myListView = new W.ScoreListFooView({
collection: scoreCollection
});
view.collection.fetch({
success: (function () {
this.showChildView('user_scores', view);
}).bind(this)
});
} else {
this.getRegion('user_scores').reset();
}
},
myListView.collection.fetch({
success: function () {
that.showChildView('latest_updated', myListView);
}
});
onRender: function () {
document.title = 'Notation W';
var scoreCollection2 = new W.ScoreCollection([], {
// All the `state` and `queryParams` key value pairs are merged with
// the defaults too.
var collection = new W.ScoreCollection([], {
state: {
pageSize: 5,
firstPage: 1,
currentPage: 1,
sortKey: "updated_at",
order: -1
order: 1,
}
});
scoreCollection2.queryParams.shared_with=true;
collection.queryParams.is_featured = true;
var myListView2 = new W.ScoreListFooView({
collection: scoreCollection2
var view = new W.ScoreListFooView({
collection: collection,
title: t("Le choix de W")
});
myListView2.collection.fetch({
success: function () {
that.showChildView('user_scores', myListView2);
}
view.collection.fetch({
success: (function () {
this.showChildView('latest_updated', view);
}).bind(this)
});
}
});
......
......@@ -11,14 +11,9 @@
<br>
<section>
<h1><%- t('Le choix de W') %></h1>
<br>
<div id="latest_updated"></div>
<br>
<br>
<h1><%- t('Mes partitions') %></h1>
<br>
<div id="user_scores"></div>
</section>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment