Fixed models to work with new /settings service in dashboard.

This commit is contained in:
Jeff Cross
2011-11-26 16:33:51 -07:00
parent 407b677ff2
commit dabe536d31
4 changed files with 17 additions and 17 deletions

View File

@@ -4,26 +4,24 @@ window.App = Backbone.Model.extend({
var plugins, _pluginsFromResponse, app = [];
plugins = new Plugins();
//Group the plugins into an object like {plugin: [{config: object}}
_pluginsFromResponse = _.groupBy(response, function(obj) {
return obj.plugin;
});
_.each(_pluginsFromResponse, function (value, key, list){
if (key !== "undefined") {
var _pluginObjects = new Backbone.Collection();
_pluginObjects.model = PluginObject;
_.each(value, function (element, index, list) {
_pluginObjects.add(element);
//Iterate through each plugin
_.each(_pluginsFromResponse, function (objectsArray, pluginName, list){
if (pluginName !== "undefined") {
var _pluginObjects = new Backbone.Collection(objectsArray, {
model: PluginObject
});
plugins.add({
//TODO: Add actual ID
_id: 0,
name: key,
name: pluginName,
plugin: pluginName,
objects: _pluginObjects
});
}
});

View File

@@ -16,12 +16,11 @@ window.Plugins = Backbone.Collection.extend({
getByPluginName: function (name) {
var _plugin;
this.each(function (plugin){
if (plugin.get("name") === name) {
if (plugin.get("plugin") === name) {
_plugin = plugin;
return;
}
});
return _plugin;
}
});
@@ -34,8 +33,7 @@ objects: [...]
window.PluginObject = Backbone.Model.extend({
validate: function (attributes) {
if(typeof attributes._id === "undefined"
|| typeof attributes.name === "undefined") {
if(typeof attributes._id === "undefined") {
return { error: "error validating object", attributes: attributes };
}
}

View File

@@ -25,6 +25,7 @@ var Router = Backbone.Router.extend({
plugin: function(name, tabId) {
var model = app.get("plugins").getByPluginName(name);
console.log(model);
var view = new PluginView({
model: model
});

View File

@@ -5,11 +5,14 @@ window.PluginView = Backbone.View.extend({
template: 'plugin-detail-template',
render: function () {
console.log('render() in PluginView');
var _self = this;
$(this.el).empty();
$(this.tabsEl).empty();
this.model.get("objects").each(function(obj){
console.log('object:');
console.log(obj);
var tabContent = _self.addTab(obj.get("name"), obj.get("_id"));
if (obj.get("description")) {
@@ -54,7 +57,7 @@ window.PluginView = Backbone.View.extend({
addTab: function (tabName, id) {
//Create a new li to add to the tabs nav
var _navItem = $("<dd />").attr('id','tab-link-'+id);
$(_navItem).append($('<a />').attr('href','/dashboard/#/plugins/'+this.model.get('name')+'/'+id).html(tabName));
$(_navItem).append($('<a />').attr('href','/dashboard/#/plugins/'+this.model.get('plugin')+'/'+id).html(tabName));
$(this.tabsEl).append(_navItem);
//Create a new container to add to the content area