Commit 0c6d60ed authored by alexandre's avatar alexandre

permission views

parent aec4d178
......@@ -28,7 +28,7 @@ class AttachmentSerializer(serializers.HyperlinkedModelSerializer):
class PermissionsField(serializers.Serializer):
def to_representation(self, obj):
perms = get_users_with_perms(obj, attach_perms=True)
return {k.username: v for k, v in perms.items()}
return [{"username": k.username, "permissions": v} for k, v in perms.items()]
def to_internal_value(self, data):
# I don't understand why I can't just return data
......
......@@ -47,4 +47,9 @@ window.W = window.W || {};
W.LineCollection = Backbone.Collection.extend({
model: W.LineModel
});
W.PermissionCollection = Backbone.Collection.extend({
model: W.PermissionModel
});
})();
......@@ -6,6 +6,7 @@ window.W = window.W || {};
(function (undefined) {
'use strict';
W.Plugin = Backbone.Model.extend({
urlRoot: '/api/users/',
......@@ -21,6 +22,7 @@ window.W = window.W || {};
},
});
W.UserModel = Backbone.Model.extend({
urlRoot: '/rest-auth/user/',
......@@ -52,6 +54,7 @@ window.W = window.W || {};
presentation: "",
effectif: "",
language: "",
permissions: {}
},
urlRoot: '/api/scores/',
......@@ -63,16 +66,28 @@ window.W = window.W || {};
return parsed_url;
},
relations: [{
type: Backbone.HasOne,
key: 'mainline',
relatedModel: 'LineModel',
reverseRelation: {
key: 'score',
includeInJSON: false,
type: Backbone.HasOne
relations: [
{
type: Backbone.HasOne,
key: 'mainline',
relatedModel: 'LineModel',
reverseRelation: {
key: 'score',
includeInJSON: false,
type: Backbone.HasOne
}
},
{
type: Backbone.HasMany,
key: 'permissions',
relatedModel: 'PermissionModel',
reverseRelation: {
key: 'score',
includeInJSON: false,
type: Backbone.HasOne
}
}
}],
],
getDepth: function () {
// Methode pour le vue "slider"
......@@ -204,4 +219,7 @@ window.W = window.W || {};
}
}]
});
W.PermissionModel = Backbone.RelationalModel.extend({});
})();
......@@ -1034,7 +1034,7 @@ window.W = window.W || {};
},
regions: {
// plugin: '#foo',
permissions: '#permissions',
mainline: 'ol',
......@@ -1226,6 +1226,11 @@ window.W = window.W || {};
var sliderView = new W.SliderView({ depth: this.model.getDepth() });
this.showChildView('slider', sliderView);
var permissions = this.model.get("permissions");
console.log(permissions);
var permissionView = new W.PermissionView({ collection: permissions });
this.showChildView('permissions', permissionView);
this.getRegion('mainline').$el.nestedSortable({
placeholder: 'placeholder',
forcePlaceholderSize: true,
......@@ -1305,6 +1310,18 @@ window.W = window.W || {};
});
W.PermissionItemView = Backbone.Marionette.View.extend({
tagName: 'li',
template: '#permission-item-template',
});
W.PermissionView = Backbone.Marionette.CollectionView.extend({
tagName: 'ol',
childView: W.PermissionItemView,
});
/**
* List page views
*/
......
......@@ -75,6 +75,10 @@
{% include "playground/underscore/node-vue.mtpl" %}
</script>
<script id="permission-item-template" type="text/template">
{% include "playground/underscore/permission-item.mtpl" %}
</script>
<!-- Perhaps remove -->
<script id="rangefield-template" type="text/template">
{% include "playground/underscore/rangefield.mtpl" %}
......
<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">
<button class="save" data-label-progress="Saving..." data-label="Enregistrer" <% if (!hasChanges) { %>disabled<% } %>><%- t('Enregistrer') %></button>
......
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