git-svn-id: https://msi/svn/firstRepo/WebClient/trunk@13 0f545695-f87b-41b6-9a03-7f16563b5454
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
define(['jquery', 'underscore', 'backbone','text!modules/note/noteViewTemplate.html', 'text!modules/note/noteItemTemplate.html', 'modules/base/baseView', 'classes/profile'],
|
||||
function($, _, Backbone, noteViewTemplate, noteItemTemplate, BaseView, Profile){
|
||||
|
||||
var NoteView = BaseView.extend({
|
||||
|
||||
collection: null,
|
||||
//initialize template
|
||||
template:_.template(noteViewTemplate),
|
||||
itemtemplate:_.template(noteItemTemplate),
|
||||
current_ricetta_id: null,
|
||||
|
||||
initialize: function (options) {
|
||||
var self = this;
|
||||
NoteView.__super__.initialize.call(this);
|
||||
this.collection = options.collection;
|
||||
this.collection.fetch({ success: function(){ self.renderItem(); } });
|
||||
},
|
||||
|
||||
events: {
|
||||
"click #deleteItem": "deleteItemClick",
|
||||
"popupafterclose #popupMenu": "popupMenuPopupafterclose"
|
||||
},
|
||||
|
||||
updateList: function(){
|
||||
var $ul = this.$el.find('#allNote');
|
||||
|
||||
var items = this.itemtemplate({data:this.collection.toJSON()});
|
||||
|
||||
$ul.html( items );
|
||||
$ul.listview( "refresh" );
|
||||
$ul.trigger( "updatelayout");
|
||||
},
|
||||
|
||||
renderItem: function(){
|
||||
this.updateList();
|
||||
|
||||
$.mobile.loading( 'hide' );
|
||||
var self = this;
|
||||
this.$el.find('.optionLink').on("click", function(e){
|
||||
e.preventDefault();
|
||||
self.current_ricetta_id = $(e.target.parentElement).find('#itemID').text();
|
||||
self.$el.find('#popupMenu').popup("open");
|
||||
});
|
||||
},
|
||||
|
||||
deleteItemClick: function(e){
|
||||
e.preventDefault();
|
||||
var self = this;
|
||||
Profile.removeRicettaBloccoNote(this.current_ricetta_id, function(msg) {
|
||||
var item = self.collection.get(self.current_ricetta_id);
|
||||
|
||||
self.$el.find('#popupMenu').popup("close");
|
||||
|
||||
self.collection.remove(item);
|
||||
self.updateList();
|
||||
});
|
||||
},
|
||||
|
||||
popupMenuPopupafterclose: function( event, ui ) {
|
||||
this.current_ricetta_id = null;
|
||||
},
|
||||
|
||||
//render the content into div of view
|
||||
render: function(){
|
||||
//this.header.title = "pippo";
|
||||
NoteView.__super__.render.call(this);
|
||||
|
||||
var self = 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());
|
||||
this.$el.append(this.footer.$el);
|
||||
|
||||
//return to enable chained calls
|
||||
this.$el.find("#noteBtn").addClass("ui-btn-active");
|
||||
return this;
|
||||
}
|
||||
});
|
||||
return NoteView;
|
||||
});
|
||||
Reference in New Issue
Block a user