mirror of
https://github.com/Hopiu/postal.js.git
synced 2026-03-16 22:20:23 +00:00
52 lines
No EOL
1.1 KiB
JavaScript
52 lines
No EOL
1.1 KiB
JavaScript
define( [
|
|
'jquery',
|
|
'backbone',
|
|
'text!views/templates/menu.html',
|
|
'bus',
|
|
'models/menu-model'
|
|
],
|
|
function( $, Backbone, template, bus, MenuModel ) {
|
|
"use strict";
|
|
|
|
return Backbone.View.extend( {
|
|
el: "#menu",
|
|
|
|
events: {
|
|
"click #btnSearch" : "updateSearch"
|
|
},
|
|
|
|
initialize: function() {
|
|
_.bindAll( this );
|
|
this.template = _.template( template );
|
|
this.model = new MenuModel();
|
|
this.model.bind( "change", this.updateView );
|
|
},
|
|
|
|
render: function() {
|
|
this.$el.html( this.template( this.model.toJSON() ) );
|
|
},
|
|
|
|
show: function( data ) {
|
|
this.$el.show();
|
|
},
|
|
|
|
updateSearch: function() {
|
|
var searchTerm = this.$el.find('#searchTerm').val();
|
|
if( searchTerm ) {
|
|
bus.app.publish({
|
|
topic: "search.new.request",
|
|
data: {
|
|
searchTerm: searchTerm
|
|
}
|
|
});
|
|
}
|
|
},
|
|
|
|
updateView: function() {
|
|
this.$el.find( "#currentSearch" ).text( this.model.get("searchTerm") );
|
|
this.$el.find( "#search-ownership").text( this.model.get("searchOwnership" ));
|
|
var reqs = this.model.get("requests").length
|
|
this.$el.find( "#request-indicator").text( reqs ? " *" : "" );
|
|
}
|
|
} );
|
|
} ); |