checkboxes now control list membership behavior, autocomplete is turned off
parent
e963c3c1ec
commit
2d53f317b0
|
@ -82,7 +82,8 @@ var ListWidgetChildView = Backbone.View.extend({
|
||||||
tagName: 'tr',
|
tagName: 'tr',
|
||||||
|
|
||||||
events:{
|
events:{
|
||||||
"click .btn-delete-list-item":'deleteItem'
|
"click .btn-delete-list-item":'deleteItem',
|
||||||
|
"change .checkbox-list-item":'toggleCheckbox'
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteItem:function (e) {
|
deleteItem:function (e) {
|
||||||
|
@ -110,6 +111,17 @@ var ListWidgetChildView = Backbone.View.extend({
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
toggleCheckbox:function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopImmediatePropagation();
|
||||||
|
if ($(e.target).is(':checked')) {
|
||||||
|
this.options.collection.add(this.model);
|
||||||
|
} else {
|
||||||
|
this.options.collection.remove(this.model);
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
initialize:function (options) {
|
initialize:function (options) {
|
||||||
this.options = {toggle: false, checked: false};
|
this.options = {toggle: false, checked: false};
|
||||||
|
@ -212,11 +224,6 @@ var ListWidgetView = Backbone.View.extend({
|
||||||
this.$el.html(this.template({placeholder:this.options.placeholder,
|
this.$el.html(this.template({placeholder:this.options.placeholder,
|
||||||
helpBlockText:this.options.helpBlockText}));
|
helpBlockText:this.options.helpBlockText}));
|
||||||
|
|
||||||
// bind autocomplete options
|
|
||||||
if (this.options.autocomplete) {
|
|
||||||
$('input', this.$el).typeahead({source:this.options.autocomplete});
|
|
||||||
}
|
|
||||||
|
|
||||||
_self = this;
|
_self = this;
|
||||||
|
|
||||||
if (_.size(this.collection.models) == 0 && _.size(this.options.autocomplete) == 0) {
|
if (_.size(this.collection.models) == 0 && _.size(this.options.autocomplete) == 0) {
|
||||||
|
@ -247,7 +254,7 @@ var ListWidgetView = Backbone.View.extend({
|
||||||
checked = false;
|
checked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var el = new this.childView({model:model, toggle: true, checked: checked}).render().el;
|
var el = new this.childView({model:model, toggle: true, checked: checked, collection: _self.collection}).render().el;
|
||||||
$("tbody", _self.el).append(el);
|
$("tbody", _self.el).append(el);
|
||||||
|
|
||||||
}, this);
|
}, this);
|
||||||
|
@ -257,7 +264,7 @@ var ListWidgetView = Backbone.View.extend({
|
||||||
// now render everything not in the autocomplete list
|
// now render everything not in the autocomplete list
|
||||||
_.each(values.models, function (model) {
|
_.each(values.models, function (model) {
|
||||||
|
|
||||||
var el = new this.childView({model:model}).render().el;
|
var el = new this.childView({model:model, collection: _self.collection}).render().el;
|
||||||
$("tbody", _self.el).append(el);
|
$("tbody", _self.el).append(el);
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
<% if (!opt.toggle) { %>
|
<% if (!opt.toggle) { %>
|
||||||
<a class="btn btn-small btn-delete-list-item" href="#"><i class="icon-minus-sign"></i></a>
|
<a class="btn btn-small btn-delete-list-item" href="#"><i class="icon-minus-sign"></i></a>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
<input type="checkbox" <%- opt.checked ? 'checked="checked"' : '' %> />
|
<input class="checkbox-list-item" type="checkbox" <%- opt.checked ? 'checked="checked"' : '' %> />
|
||||||
<% } %>
|
<% } %>
|
||||||
</td>
|
</td>
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue