Created modal view for creating/editing collection items.

This commit is contained in:
Jeff Cross
2011-11-25 08:47:35 -07:00
parent 97bde11d33
commit c2221099d9
5 changed files with 62 additions and 8 deletions

View File

@@ -52,6 +52,8 @@
<ul class="tabs-content twelve columns" id="content">
</ul>
<div class="reveal-modal">
</div>
</div>
</div>
@@ -59,6 +61,22 @@
<!-- container -->
<!-- PARTIAL TEMPLATES -->
<script id="item-edit-modal-template" type="html/template">
<a class="close-reveal-modal">x</a>
<h6><%= name %></h6>
<p>Fill out the fields below to create/edit an object in the <%= name %> collection.</p>
<form class="item-edit-form">
<% _.each(description, function (val, key, obj) {
var type = 'text'; %>
<fieldset>
<label for="item-val-<%= key %>"><%= key %></label>
<input id="item-val-<%= key %>" type="<%= type %>" <% if (val.required) print('required="true"'); %> />
</fieldset>
<% }); %>
</form>
<a class="nice medium radius blue button save-item">Save Changes</a>
<a class="nice medium radius white button discard-changes">Discard Changes</a>
</script>
<script id="collection-view-template" type="html/template">
<div class="twelve columns">
<div class="panel">
@@ -98,7 +116,7 @@
<% } else {%>
<p><em>No items in collection.</em></p>
<% } %>
<a class="small radius nice blue button">Create New <%= name %></a>
<a class="small radius nice blue button create-collection-item">Create New <%= name %></a>
<a class="small radius nice white button">Export <%= name %></a>
<a class="small radius nice white button">Upload <%= name %></a>
</div>
@@ -437,6 +455,7 @@
.script(p + 'plugin-view.js')
.script(p + 'schema-view.js')
.script(p + 'collection-view.js')
.script(p + 'item-edit-view.js')
// views
.script(v + 'app-nav-view.js')
// router

View File

@@ -14,13 +14,14 @@ window.Plugin = Backbone.Model.extend({
window.Plugins = Backbone.Collection.extend({
model: Plugin,
getByPluginName: function (name) {
var _plugin = {};
var _plugin;
this.each(function (plugin){
if (plugin.get("name") === name) {
_plugin = plugin;
return;
}
});
return _plugin;
}
});

View File

@@ -1,5 +1,22 @@
window.CollectionView = Backbone.View.extend({
template: _.template($("#collection-view-template").html()),
events : {
"click .create-collection-item" : "createItem"
},
createItem: function () {
//TODO: Dynamically create a form.
console.log(this.model);
var _newItemModel = new Backbone.Model({
description: this.model.get('description'),
name: this.model.get('name'),
plugin: this.model.get('plugin')
});
var _newItemView = new ItemEditView({
model: _newItemModel,
el: '.reveal-modal'
});
_newItemView.render();
},
schemaChange: function (msg) {
// $(".save-changes", this.el).html("Save Changes").removeClass("white").addClass("blue");
if (msg.get("errors")) {

View File

@@ -0,0 +1,20 @@
window.ItemEditView = Backbone.View.extend({
template: _.template($('#item-edit-modal-template').html()),
events: {
'click .save-item' : 'save',
'click .discard-changes' : 'discard'
},
discard : function (e) {
console.log('discard');
this._closeModal();
},
_closeModal : function () {
},
save: function (e) {
console.log('save');
},
render: function () {
$(this.el).empty().append(this.template(this.model.toJSON())).reveal();
}
});

View File

@@ -23,11 +23,11 @@ window.PluginView = Backbone.View.extend({
_schemaView.render();
}
if (obj.get("collection")) {
console.log("There is a collection: "+obj.get('collection'));
var _collectionModel = new CollectionModel({
name: obj.get('collection'),
numFields: _.size(obj.get('decsription')),
description: obj.get('decsription'),
plugin: obj.get('plugin'),
numFields: _.size(obj.get('description')),
description: obj.get('description'),
results: []
});
@@ -43,13 +43,10 @@ window.PluginView = Backbone.View.extend({
});
if (typeof this.tabId !== "undefined") {
console.log("tabId is defined");
console.log('#tab-content-'+this.tabId);
$('#tab-content-'+this.tabId).addClass('active').show();
$('#tab-link-'+this.tabId+' > a').addClass('active');
}
else {
console.log("tabId is NOT defined");
$('#plugin-tabs-nav > dd > a').addClass('active');
$('.tabs-content > li').show();
}