Skip to content

Commit a0a06bf

Browse files
committed
Deprecated widgy.backbone.render
1 parent 9fc240d commit a0a06bf

File tree

6 files changed

+53
-54
lines changed

6 files changed

+53
-54
lines changed

widgy/static/widgy/js/modal/modal.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ define([ 'jquery',
2121
},
2222

2323
open: function() {
24-
$(document.body).append(this.render().$el.css({
25-
left: $(window).width()/2,
26-
top: $(window).height()/2,
27-
position: 'fixed'
28-
}));
24+
this.renderPromise().then(
25+
$(document.body).append(
26+
this.$el.css({
27+
left: $(window).width()/2,
28+
top: $(window).height()/2,
29+
position: 'fixed'
30+
})
31+
)
32+
);
2933
}
3034
});
3135

widgy/static/widgy/js/nodes/base.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ define(['jquery', 'underscore', 'widgy.backbone', 'geometry'], function(
4646
this.parent = options.parent;
4747
},
4848

49-
render: function() {
50-
Backbone.View.prototype.render.apply(this, arguments);
51-
_.each(this.cssClasses(), this.$el.addClass, this.$el);
52-
53-
return this;
54-
},
55-
5649
renderPromise: function() {
5750
return Backbone.View.prototype.renderPromise.apply(this, arguments)
5851
.then(function(self) {

widgy/static/widgy/js/nodes/nodes.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,13 @@ define([ 'exports', 'jquery', 'underscore', 'widgy.backbone', 'lib/q', 'shelves/
286286
}
287287

288288
if (this.canAcceptChild(view)) {
289-
$children.prepend(this.createDropTarget(view).el);
289+
this.createDropTarget(view).then(function(drop_target) {
290+
$children.prepend(drop_target.el);
291+
});
290292
this.list.each(function(node_view) {
291-
var drop_target = that.createDropTarget(view).$el.insertAfter(node_view.el);
293+
that.createDropTarget(view).then(function(that_drop_target) {
294+
var drop_target = that_drop_target.$el.insertAfter(node_view.el);
295+
})
292296
}, this);
293297
this.refreshDropTargetVisibility();
294298

@@ -331,7 +335,7 @@ define([ 'exports', 'jquery', 'underscore', 'widgy.backbone', 'lib/q', 'shelves/
331335
}
332336
}
333337

334-
return drop_target.render();
338+
return drop_target.renderPromise();
335339
},
336340

337341
clearDropTargets: function() {
@@ -442,11 +446,13 @@ define([ 'exports', 'jquery', 'underscore', 'widgy.backbone', 'lib/q', 'shelves/
442446
// this must happen after shelf.$el is in the dom so fixto can
443447
// find the .node element
444448
if ( this.isRootNode() ) {
445-
this.shelf.$el.fixTo('.node', {
446-
// mezzanine header
447-
mind: '#container > .breadcrumbs, #container > #header',
448-
// XXX: move this to css
449-
zIndex: 50
449+
this.shelf.shelf_promise.then(function(shelf) {
450+
shelf.$el.fixTo('.node', {
451+
// mezzanine header
452+
mind: '#container > .breadcrumbs, #container > #header',
453+
// XXX: move this to css
454+
zIndex: 50
455+
});
450456
});
451457
}
452458
},
@@ -472,10 +478,15 @@ define([ 'exports', 'jquery', 'underscore', 'widgy.backbone', 'lib/q', 'shelves/
472478

473479
var shelf = this.shelf = this.makeShelf();
474480

481+
var children = this.$children;
482+
475483
this.listenTo(shelf, 'startDrag', this.startDrag)
476484
.listenTo(shelf, 'stopDrag', this.stopDrag);
477485

478-
this.$children.before(shelf.render().el);
486+
shelf.shelf_promise = shelf.renderPromise()
487+
shelf.shelf_promise.then(function(rendered_shelf) {
488+
children.before(rendered_shelf.el);
489+
});
479490
return shelf;
480491
},
481492

widgy/static/widgy/js/shelves/shelves.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,24 @@ define([ 'jquery', 'underscore', 'widgy.backbone', 'nodes/base',
6363

6464
},
6565

66-
render: function() {
67-
Backbone.View.prototype.render.apply(this, arguments);
68-
this.$scroll = this.$el.find('> .scroll');
69-
var $list = this.$list = this.$scroll.find('> .list');
70-
this.collection.on('sort', this.resort);
71-
72-
this.list.on('push', function(view) {
73-
$list.append(view.render().el);
66+
renderPromise: function() {
67+
var promise = Backbone.View.prototype.renderPromise.apply(this, arguments);
68+
promise.then(function(shelf) {
69+
shelf.$scroll = shelf.$el.find('> .scroll');
70+
var $list = shelf.$list = shelf.$scroll.find('> .list');
71+
72+
shelf.collection.on('sort', this.resort);
73+
74+
shelf.list.on('push', function(view) {
75+
view.renderPromise().then(function(promise_view) {
76+
$list.append(promise_view.el);
77+
});
78+
});
79+
80+
shelf.resizeShelf();
81+
$(window).resize(shelf.resizeShelf);
7482
});
75-
76-
this.resizeShelf();
77-
$(window).resize(this.resizeShelf);
78-
return this;
83+
return promise;
7984
},
8085

8186
resizeShelf: function() {
@@ -176,10 +181,12 @@ define([ 'jquery', 'underscore', 'widgy.backbone', 'nodes/base',
176181
return this.model.get('css_classes');
177182
},
178183

179-
render: function() {
180-
DraggableView.prototype.render.apply(this, arguments);
181-
this.$el.attr('title', this.model.get('tooltip'));
182-
return this;
184+
renderPromise: function() {
185+
var promise = DraggableView.prototype.renderPromise.apply(this, arguments);
186+
promise.then(function(shelf_view) {
187+
shelf_view.$el.attr('title', shelf_view.model.get('tooltip'));
188+
});
189+
return promise;
183190
}
184191

185192
});

widgy/static/widgy/js/widgy.backbone.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,7 @@ define([ 'jquery', 'underscore', 'backbone', 'lib/mustache', 'lib/q', 'geometry'
103103
},
104104

105105
render: function() {
106-
var context = this.toJSON(),
107-
template = this.getTemplate();
108-
109-
if (template) {
110-
this.$el.html(this.renderTemplate(template, context));
111-
}
112-
113-
return this;
106+
// Deprecated for renderPromise
114107
},
115108

116109
renderPromise: function() {

widgy/static/widgy/js/widgy.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ define([ 'jquery', 'underscore', 'widgy.backbone', 'lib/csrf', 'lib/q', 'nodes/n
5050
});
5151
},
5252

53-
render: function() {
54-
Backbone.View.prototype.render.apply(this, arguments);
55-
56-
this.$editor = this.$el.children('.editor');
57-
this.$editor.append(this.root_node_view.render().el);
58-
59-
return this;
60-
},
61-
6253
renderPromise: function() {
6354
var compatibility_promise = this.fetchCompatibility();
6455

0 commit comments

Comments
 (0)