Commit 9ebb2c8e authored by alexandre's avatar alexandre

Sharing a score with users

parent 91bc7384
......@@ -221,5 +221,9 @@ window.W = window.W || {};
});
W.PermissionModel = Backbone.RelationalModel.extend({});
W.PermissionModel = Backbone.RelationalModel.extend({
defaults: {
permissions: []
},
});
})();
......@@ -1207,19 +1207,6 @@ window.W = window.W || {};
onRender: function () {
document.title = this.model.get('title');
var users = new W.UserCollection();
users.fetch({success: function() {
new AutoCompleteView({
input: $("#plugin"), // your input field
model: users, // your collection
queryParameter: 'search',
onSelect: function (model) {
console.log();
// $("#selected").show().find("p").html(model.label());
}
}).render();
}});
var mainlineView = new W.TreeNode({ model: this.model.get('mainline') });
this.showChildView('mainline', mainlineView);
......@@ -1227,7 +1214,6 @@ window.W = window.W || {};
this.showChildView('slider', sliderView);
var permissions = this.model.get("permissions");
console.log(permissions);
var permissionView = new W.PermissionView({ collection: permissions });
this.showChildView('permissions', permissionView);
......@@ -1310,6 +1296,20 @@ window.W = window.W || {};
});
W.UserDataListItemView = Backbone.Marionette.View.extend({
template: _.template('<option value="<%- username %>">'),
});
W.UserDataListView = Backbone.Marionette.CollectionView.extend({
tagName: 'datalist',
attributes: { id: 'users' },
childView: W.UserDataListItemView,
});
W.PermissionItemView = Backbone.Marionette.View.extend({
tagName: 'li',
template: '#permission-item-template',
......@@ -1325,11 +1325,10 @@ window.W = window.W || {};
initialize: function () {
this.$el.attr("data-username", this.model.get("username"))
},
});
W.PermissionView = Backbone.Marionette.CollectionView.extend({
W.PermissionListView = Backbone.Marionette.CollectionView.extend({
tagName: 'ol',
attributes: { class: 'permission-list' },
......@@ -1360,6 +1359,41 @@ window.W = window.W || {};
});
W.PermissionView = Backbone.Marionette.View.extend({
template: '#permissions-template',
regions: {
permissionList: '#permission-list',
dataList: '#datalist',
},
ui: {
'search': '.search-username',
'add': '.submit-username'
},
triggers: {
'click @ui.add': 'submit',
},
onSubmit: function(view, event) {
console.log("ok");
var username = view.$el.find(".search-username").val();
this.collection.add({username: username, permissions: []})
},
onRender: function() {
var permissionListView = new W.PermissionListView({ collection: this.collection });
this.showChildView('permissionList', permissionListView);
var users = new W.UserCollection();
users.fetch();
var dataListView = new W.UserDataListView({ collection: users });
this.showChildView('dataList', dataListView);
}
});
/**
* List page views
*/
......
......@@ -75,6 +75,10 @@
{% include "playground/underscore/node-vue.mtpl" %}
</script>
<script id="permissions-template" type="text/template">
{% include "playground/underscore/permissions.mtpl" %}
</script>
<script id="permission-item-template" type="text/template">
{% include "playground/underscore/permission-item.mtpl" %}
</script>
......
<input class="search-username" list="users">
<input class="submit-username" type="submit" value="ok">
<div id="datalist"></div>
<div id="permission-list"></div>
<div>
<header id="sidebar" data-expanded="<%- metaExpanded %>">
<input type="text" placeholder="Select a plugin (type backbone)" id="plugin" />
<div id="permissions"></div>
<div class="score-actions">
......
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