/
grid-shared.js
58 lines (55 loc) · 2.09 KB
/
grid-shared.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/** This class renders the grid list with shared section. */
import GridView from "mvc/grid/grid-view";
var View = Backbone.View.extend({
initialize: function(options) {
var self = this;
this.setElement($("<div/>"));
this.model = new Backbone.Model(options);
this.item = this.model.get("item");
this.title = this.model.get("plural");
$.ajax({
url: `${Galaxy.root + this.item}/${this.model.get("action_id")}?${$.param(Galaxy.params)}`,
success: function(response) {
self.model.set(response);
self.render();
}
});
},
render: function() {
var grid = new GridView(this.model.attributes);
this.$el.empty().append(grid.$el);
this.$el.append(this._templateShared());
},
_templateShared: function() {
var self = this;
var $tmpl = $(`<div><h2>${this.model.get("plural")} shared with you by others</h2></div>`);
var options = this.model.attributes;
if (options.shared_by_others && options.shared_by_others.length > 0) {
var $table = $(
'<table class="colored" border="0" cellspacing="0" cellpadding="0" width="100%">' +
'<tr class="header">' +
"<th>Title</th>" +
"<th>Owner</th>" +
"</tr>" +
"</table>"
);
_.each(options.shared_by_others, (it, index) => {
var display_url = `${Galaxy.root + self.item}/display_by_username_and_slug?username=${
it.username
}&slug=${it.slug}`;
$table.append(
`<tr><td><a href="${display_url}">${_.escape(it.title)}</a></td><td>${_.escape(
it.username
)}</td></tr>`
);
});
$tmpl.append($table);
} else {
$tmpl.append(`No ${this.model.get("plural").toLowerCase()} have been shared with you.`);
}
return $tmpl;
}
});
export default {
View: View
};