Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Nodes you select remain selected in the playground.

  • Loading branch information...
commit 685aa8ed25fc70eb360ae6cc673dad7ee7a285ae 1 parent 5f86037
Nameless authored
2  canvas/form_generator/form_generator.py
View
@@ -110,7 +110,7 @@ def add_shape(self, feeling_data):
def feelings_to_json(self):
jsonFeelings = []
for feeling, subgroups in self.settings['Feeling groups'].items():
- newNode = {'data': feeling, 'children': []}
+ newNode = {'data': feeling, 'attr': {'id': feeling+'_node' }, 'children': []}
for i,subgroup in enumerate(subgroups):
newNode['children'].append({ 'data': str(i), 'children': subgroup})
jsonFeelings.append(newNode)
2  canvas/static/jquery.jstree.js
View
@@ -2807,7 +2807,7 @@
if(rc) {
if(!$t.children(":checkbox").length) {
nm = rcn.call(_this, $t);
- $t.prepend("<input type='checkbox' class='jstree-real-checkbox' id='" + nm[0] + "' name='" + nm[0] + "' value='" + nm[1] + "' />");
+ $t.prepend("<input type='checkbox' class='jstree-real-checkbox' id='" + nm[0] + "' name='" + nm[1] + "' value='" + nm[2] + "' />");
}
else {
$t.children(":checkbox").addClass("jstree-real-checkbox");
17 canvas/static/loadtree.js
View
@@ -1,21 +1,28 @@
-function loadTree(treedata, initially_open) {
- $('#feelingtree').jstree({
+function loadTree(treedata, checked_nodes) {
+ var tree = $('#feelingtree').jstree({
'json_data': {
'data': treedata
},
'themes': {
'icons': false
},
- 'initially_open': initially_open,
'checkbox': {
'override_ui': false,
'real_checkboxes': true,
'real_checkboxes_names': function(n) {
- console.log(n.children("a").text());
+ var feeling = $.trim(n.children("a").text());
- return ['feeling', $.trim(n.children("a").text())];
+ return [feeling+"_check", 'feeling', feeling];
}
},
plugins: ['themes', 'json_data', 'ui', 'checkbox']
+ }).bind("loaded.jstree", function (event, data) {
+ console.log(checked_nodes.length);
+ for(node in checked_nodes)
+ {
+ console.log(checked_nodes[node]);
+ data.inst.check_node("#"+checked_nodes[node]+"_node");
+ }
});
+ return tree;
}
12 canvas/views.py
View
@@ -56,16 +56,21 @@ class PlaygroundView(CanvasView):
def get_queryset(self):
filters = []
+ self.selection = False
+
if self.request.GET:
self.form = PlaygroundFilterForm(self.request.GET)
if self.form.is_valid(): # All validation rules pass
- self.feelings = self.request.GET.getlist('feeling')
+ self.selection = True # something was selected
+
date = self.form.cleaned_data['date']
# ugly filter to get data from specific date
filters.extend([Q(postdatetime__gte=datetime.datetime.combine(date, datetime.time.min)), Q(postdatetime__lte=datetime.datetime.combine(date, datetime.time.max)) ])
- filters.append(Q(feeling__name__in=self.feelings))
+ self.feelings = self.request.GET.getlist('feeling')
+ if self.feelings:
+ filters.append(Q(feeling__name__in=self.feelings))
else:
self.form = PlaygroundFilterForm()
@@ -87,7 +92,8 @@ def get_context_data(self, **kwargs):
context['ongoing'] = False
context['form'] = self.form
context['feelingtree'] = self.form_generator.feelings_to_json()
- context['selected_feelings'] = self.feelings
+ if(self.selection):
+ context['checked_nodes'] = json.dumps(self.feelings)
return context
class FeelingDataDetailView(DetailView):
3  templates/canvas/playground.html
View
@@ -29,7 +29,8 @@
<script type="text/javascript" src="{% get_static_prefix %}loadtree.js"></script>
<script type="text/javascript">
var treedata = {{ feelingtree|safe }};
- loadTree(treedata);
+ var checked_nodes = {{ checked_nodes|safe }};
+ var tree = loadTree(treedata, checked_nodes);
var paper = Raphael(10, 10, {{ width }}, {{ height }});
{% for shape in shapes %}
Please sign in to comment.
Something went wrong with that request. Please try again.