Fixed schema creation/edit to nullify empty fields before submitting.

This commit is contained in:
Jeff Cross
2011-11-26 17:01:21 -07:00
parent dabe536d31
commit b36a2d6308
4 changed files with 12 additions and 6 deletions

3
.gitignore vendored
View File

@@ -6,3 +6,6 @@ bin/test
.DS_Store
.sass-cache/
node_modules/
public/npm-debug.log

View File

@@ -11,7 +11,7 @@ window.App = Backbone.Model.extend({
});
//Iterate through each plugin
_.each(_pluginsFromResponse, function (objectsArray, pluginName, list){
_.each(_pluginsFromResponse, function (objectsArray, pluginName, list) {
if (pluginName !== "undefined") {
var _pluginObjects = new Backbone.Collection(objectsArray, {
@@ -22,7 +22,7 @@ window.App = Backbone.Model.extend({
name: pluginName,
plugin: pluginName,
objects: _pluginObjects
});
});
}
});

View File

@@ -40,6 +40,13 @@ window.ItemEditView = Backbone.View.extend({
var _values = this._formObjectFromArray($('form', this.el).serializeArray());
$.each(_values, function(i, field){
//Convert values to null if they are empty
if (_values[i].replace(/ /g,'') === '') {
console.log('value was empty, '+i);
_values[i] = null;
return;
}
//Convert strings to objects, if they should be objects
if (_self.model.get('description')[i].type === 'object') {
try {
_values[i] = JSON.parse(field);

View File

@@ -5,17 +5,13 @@ 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")) {
var _schemaModel = new SchemaModel(obj);
var _schemaEl = $("<div />").attr("id", "id-"+obj.get('_id'));
$(tabContent).append(_schemaEl);