Files

48 lines
2.1 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.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.trigger("renderCompleted:Search", this);
this.$el.find("#searchBtn").addClass("ui-btn-active");
return this;
}
});
return SearchView;
});