-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathmodule-view.js
70 lines (66 loc) · 1.97 KB
/
module-view.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
59
60
61
62
63
64
65
66
67
68
69
70
$(function () {
var template =
'<div class="addnode button module-icon" title="<%= info.description %>"></div>' +
'<h2 class="title" title="<%= src %>"><%= info.title %></h2>';
Iframework.ModuleView = Backbone.View.extend({
tagName: 'div',
className: 'library-module',
template: _.template(template),
events: {
'click .addnode': 'addNode',
'dragstart .addnode': 'dragStart',
'dragstop .addnode': 'dragStop',
},
initialize: function () {
this.render();
var self = this;
this.$('.addnode')
.data({module: this.model})
.draggable({
helper: function () {
var h = $('<div class="addnode-drag-helper module-icon" />').data({
'meemoo-drag-type': 'library-module',
});
// .text( self.model.get("info")["title"]);
if (self.model.isNative) {
h.addClass(
'module-icon-' +
self.model.groupAndName[0] +
'-' +
self.model.groupAndName[1]
);
}
$('.app').append(h);
return h;
},
});
if (this.model.isNative) {
this.$('.addnode').addClass(
'module-icon-' +
this.model.groupAndName[0] +
'-' +
this.model.groupAndName[1]
);
}
return this;
},
render: function () {
this.$el.html(this.template(this.model.toJSON()));
},
addNode: function (options) {
Iframework.$('.addbyurlinput').val(this.model.get('src'));
Iframework.addByUrl(options);
},
dragAddNode: function (options) {
// options has x and y from GraphView.drop()
options.src = this.model.get('src');
Iframework.shownGraph.addNode(options);
},
dragStart: function () {
Iframework.shownGraph.view.maskFrames();
},
dragStop: function () {
Iframework.shownGraph.view.unmaskFrames();
},
});
});