Skip to content

Commit

Permalink
checkpoint WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave McLain committed Oct 12, 2011
1 parent f405782 commit bdd720a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
13 changes: 10 additions & 3 deletions armstrong/core/arm_wells/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from django.contrib.contenttypes import generic
from reversion.admin import VersionAdmin

from armstrong.hatband.options import GenericKeyInline
from armstrong.hatband.options import BackboneInline
from armstrong.hatband.forms import OrderableGenericKeyLookupForm

from . import models

Expand All @@ -12,9 +13,15 @@ class NodeAdmin(VersionAdmin):
pass


class NodeInline(GenericKeyInline):
class NodeInlineAdminForm(OrderableGenericKeyLookupForm):
class Media:
js = ('arm_wells/js/well-node-inline.js', )


class NodeInline(BackboneInline):
template = 'arm_wells/admin/well-node-inline.html'
form = NodeInlineAdminForm
model = models.Node
extra = 1

# This is for Grappelli
sortable_field_name = "order"
Expand Down
38 changes: 38 additions & 0 deletions armstrong/core/arm_wells/static/arm_wells/js/well-node-inline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
window.Node = Backbone.Model.extend({
url: "",
});

window.NodeList = Backbone.Collection.extend({
url: "",
model: window.Node
});

window.NodeListItemView = Backbone.View.extend({
tagName: "div",
render: function() {
var html = this.options.template(this.model.toJSON());
django.jQuery(this.el).html(html);
return this;
}
});

window.NodeListView = Backbone.View.extend({
tagName: "div",
render: function() {
return this;
},
addOne: function(node) {
var view = new window.NodeListItemView({
model: node,
prefix: this.options.prefix,
template: _.template(django.jQuery('#nodes-list-item-template').html()),
});
alert(this.options.target_id);
django.jQuery(this.options.target_id).append(view.render().el);
},
addAll: function() {
for(i=0; i<this.collection.length; i++){
this.addOne(this.collection.at(i));
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends 'admin/edit_inline/backbone.html' %}

{% block templates %}
<script type="text/template" id="{{ prefix }}-list-item-template">
<li class="item">
<span class="content"><%= content_id %></span>
<h4>Rendering</h4>
<button class="delete">Delete</button
</li>
</script>
<script>
(function($) {
$(document).ready(function($) {
var collection = new window.NodeList();
collection.add(new Node({content_id: 4}));
collection.add(new Node({content_id: 6}));
collection.add(new Node({content_id: 7}));
collection.add(new Node({content_id: 3}));
window.App = new window.NodeListView({
prefix: '{{ prefix }}',
collection: collection,
target_id: '#{{ prefix }}-collection'
});
window.App.addAll();
});
})(django.jQuery);
</script>
{% endblock %}

0 comments on commit bdd720a

Please sign in to comment.