From 72993c60e125c59b1dfc44759426b99fd6c5fcd3 Mon Sep 17 00:00:00 2001 From: Jeff Cross Date: Sat, 26 Nov 2011 11:57:50 -0700 Subject: [PATCH 1/3] Updated item edit form to render more appropriate form elements depending on type. --- public/dashboard/index.html | 18 +++++----- public/dashboard/js/model/collection-model.js | 2 -- .../js/view/partial/collection-view.js | 36 ++++++++++++++++++- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/public/dashboard/index.html b/public/dashboard/index.html index bb9e534..8147857 100644 --- a/public/dashboard/index.html +++ b/public/dashboard/index.html @@ -66,16 +66,18 @@
<%= name %>

Fill out the fields below to create/edit an object in the <%= name %> collection.

- <% _.each(description, function (val, key, obj) { - var type = 'text'; %> + <% _.each(description, function (val, key, obj) { %>
- + + <% } + else if (val.formType === 'checkbox') {%> + /> + <% } + else { %> + /> + <% } %>
<% }); %>
diff --git a/public/dashboard/js/model/collection-model.js b/public/dashboard/js/model/collection-model.js index d9f67b1..8aedd62 100644 --- a/public/dashboard/js/model/collection-model.js +++ b/public/dashboard/js/model/collection-model.js @@ -5,8 +5,6 @@ window.CollectionModel = Backbone.Model.extend({ }, getItemById: function (id) { var _items = this.get('results'); - console.log('_items'); - console.log(_items); var _item; _.each(this.get('results'), function (item, index, list){ if (item._id === id) { diff --git a/public/dashboard/js/view/partial/collection-view.js b/public/dashboard/js/view/partial/collection-view.js index 8a2d118..5056d1e 100644 --- a/public/dashboard/js/view/partial/collection-view.js +++ b/public/dashboard/js/view/partial/collection-view.js @@ -9,7 +9,14 @@ window.CollectionView = Backbone.View.extend({ console.log('editItem:'+$(e.currentTarget).attr("id")); //TODO: Implement auto-saving model. var values = this.model.getItemById($(e.currentTarget).attr("id").replace('edit-item-','')); + var description = this.model.get('description'); + _.each(description.toJSON(), function (val, key, obj){ + obj[key] = typeof val === "object" ? val : { type: val}; + console.log(JSON.stringify(obj)); + }); console.log(values); + console.log('description'); + console.log(this.model.get('description')); var _itemModel = new ItemEditModel({ description: this.model.get('description'), //schema definition name: this.model.get('name'), @@ -31,8 +38,35 @@ window.CollectionView = Backbone.View.extend({ }, createItem: function () { //TODO: Dynamically create a form. + var description = this.model.get('description'); + _.each(description, function (val, key, obj) { + obj[key] = typeof val === "object" ? val : { type: val}; + + switch (obj[key].type) { + case "email": + type = "email"; + break; + case "password": + type = 'password' + break; + case "object": + type = 'textarea'; + break; + case 'boolean': + type = 'checkbox'; + break; + case 'mutli-select': + type = 'multi-select'; + break; + default: + type = "text"; + } + + obj[key].formType = type; + console.log(JSON.stringify(obj)); + }); var _newItemModel = new ItemEditModel({ - description: this.model.get('description'), //schema definition + description: description, //schema definition name: this.model.get('name'), plugin: this.model.get('plugin'), values: {} From d4830b093e51eaff59a70dfc4410e36e416b4c2b Mon Sep 17 00:00:00 2001 From: Jeff Cross Date: Sat, 26 Nov 2011 13:30:01 -0700 Subject: [PATCH 2/3] Item edit modal is saving to server somewhat reliably, status messages are shown on error/success. --- public/dashboard/index.html | 23 ++++++++++--- public/dashboard/js/model/item-edit-model.js | 11 ++++++- .../js/view/partial/collection-view.js | 33 +++++++++++++++---- .../js/view/partial/item-edit-view.js | 30 +++++++++++++++++ 4 files changed, 85 insertions(+), 12 deletions(-) diff --git a/public/dashboard/index.html b/public/dashboard/index.html index 8147857..b5a9490 100644 --- a/public/dashboard/index.html +++ b/public/dashboard/index.html @@ -68,19 +68,32 @@
<% _.each(description, function (val, key, obj) { %>
- + <% if (val.type === 'object') print('requires valid JSON'); %> <% if (val.formType === 'textarea' || val.formType === 'multi-select') { %> - + <% } else if (val.formType === 'checkbox') {%> - /> + /> <% } else { %> - /> + /> <% } %>
<% }); %>
+ Save Changes Discard Changes @@ -162,7 +175,7 @@ "> unique in this collection - Remove + Remove