44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
/*jshint multistr:true */
|
|
|
|
this.recline = this.recline || {};
|
|
this.recline.View = this.recline.View || {};
|
|
|
|
(function($, my) {
|
|
|
|
my.QueryEditor = Backbone.View.extend({
|
|
className: 'recline-query-editor',
|
|
template: ' \
|
|
<form action="" method="GET" class="form-inline"> \
|
|
<div class="input-prepend text-query"> \
|
|
<span class="add-on"><i class="icon-search"></i></span> \
|
|
<input type="text" name="q" value="{{q}}" class="span2" placeholder="Search data ..." class="search-query" /> \
|
|
</div> \
|
|
<button type="submit" class="btn">Go »</button> \
|
|
</form> \
|
|
',
|
|
|
|
events: {
|
|
'submit form': 'onFormSubmit'
|
|
},
|
|
|
|
initialize: function() {
|
|
_.bindAll(this, 'render');
|
|
this.el = $(this.el);
|
|
this.model.bind('change', this.render);
|
|
this.render();
|
|
},
|
|
onFormSubmit: function(e) {
|
|
e.preventDefault();
|
|
var query = this.el.find('.text-query input').val();
|
|
this.model.set({q: query});
|
|
},
|
|
render: function() {
|
|
var tmplData = this.model.toJSON();
|
|
var templated = Mustache.render(this.template, tmplData);
|
|
this.el.html(templated);
|
|
}
|
|
});
|
|
|
|
})(jQuery, recline.View);
|
|
|