Files

57 lines
2.5 KiB
JavaScript

define(['jquery', 'underscore', 'backbone','text!modules/search/searchViewTemplate.html', 'modules/base/baseView', 'classes/profile', 'jQueryPlugins'],
function($, _, Backbone, searchViewTemplate, BaseView, Profile) {
var SearchView = BaseView.extend({
collection: null,
//initialize template
template:_.template(searchViewTemplate),
initialize: function (options) {
var self = this;
SearchView.__super__.initialize.call(this);
this.collection = options.collection;
this.collection.fetch({ success: function () { self.render(); } });
//this.header.title = "pippo";
},
events: {
"click [button='true']": "performSearch"
},
performSearch: function (e) {
e.preventDefault();
var titolo = $('#titolo').val();
var categoria = $('#categoria').val();
var nResult = $('#nResult').val();
var diffi = $('#difficoltaFrm').serialize();
diffi = diffi.replace("difficolta=", "");
if (diffi === "") {
diffi = "0";
}
Backbone.history.navigate('search/' + nResult + "/"+ categoria + "/" + diffi + "/" + titolo, { trigger: true });
},
//render the content into div of view
render: function () {
//this.header.title = "pippo";
SearchView.__super__.render.call(this);
//this.el is the root element of Backbone.View. By default, it is a div.
//$el is cached jQuery object for the view's element.
//append the compiled template into view div container
this.$el.append(this.header.$el);
this.$el.append(this.template({data:this.collection.toJSON()}));
this.$el.append(this.footer.$el);
this.$el.find('#nResult').val(Profile.data.risRic);
// this.$el.find('#search').on("click", function(e){
// e.preventDefault();
//
// });
this.trigger("renderCompleted:Search", this);
this.$el.find("#searchBtn").addClass("ui-btn-active");
//$("#homeBtn").addClass("ui-btn-active");
//return to enable chained calls
return this;
}
});
return SearchView;
});