mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 09:22:49 +03:00
2b7d0f054d
Added a basic UI and implementation for importing and exporting data. Hooked up the routes and tested importing and exporting a version 001 file. Slipped in the TemplateView in base.js but didn't end up using it. I think it will encapsulate common logic for template views pretty well. Should close #175.
76 lines
2.0 KiB
JavaScript
76 lines
2.0 KiB
JavaScript
/*global window, document, Ghost, Backbone, $, JST, _ */
|
|
(function (_, undefined) {
|
|
"use strict";
|
|
|
|
Ghost.View = Backbone.View.extend({
|
|
|
|
// Adds a subview to the current view, which will
|
|
// ensure its removal when this view is removed,
|
|
// or when view.removeSubviews is called
|
|
addSubview: function (view) {
|
|
if (!(view instanceof Backbone.View)) {
|
|
throw new Error("Subview must be a Backbone.View");
|
|
}
|
|
this.subviews = this.subviews || [];
|
|
this.subviews.push(view);
|
|
return view;
|
|
},
|
|
|
|
// Removes any subviews associated with this view
|
|
// by `addSubview`, which will in-turn remove any
|
|
// children of those views, and so on.
|
|
removeSubviews: function () {
|
|
var i, l, children = this.subviews;
|
|
if (!children) {
|
|
return this;
|
|
}
|
|
for (i = 0, l = children.length; i < l; i += 1) {
|
|
children[i].remove();
|
|
}
|
|
this.subviews = [];
|
|
return this;
|
|
},
|
|
|
|
// Extends the view's remove, by calling `removeSubviews`
|
|
// if any subviews exist.
|
|
remove: function () {
|
|
if (this.subviews) {
|
|
this.removeSubviews();
|
|
}
|
|
return Backbone.View.prototype.remove.apply(this, arguments);
|
|
}
|
|
|
|
});
|
|
|
|
Ghost.TemplateView = Ghost.View.extend({
|
|
templateName: "widget",
|
|
|
|
template: function (data) {
|
|
return JST[this.templateName](data);
|
|
},
|
|
|
|
templateData: function () {
|
|
if (this.model) {
|
|
return this.model.toJSON();
|
|
}
|
|
|
|
if (this.collection) {
|
|
return this.collection.toJSON();
|
|
}
|
|
|
|
return {};
|
|
},
|
|
|
|
render: function () {
|
|
this.$el.html(this.template(this.templateData()));
|
|
|
|
if (_.isFunction(this.afterRender)) {
|
|
this.afterRender();
|
|
}
|
|
|
|
return this;
|
|
}
|
|
});
|
|
|
|
}(_));
|