2016-03-08 05:36:58 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
|
|
|
'common',
|
2016-03-17 07:43:05 +00:00
|
|
|
'marked',
|
|
|
|
'moment'
|
|
|
|
], function($, _, Backbone, Common, Marked, Moment) {
|
2016-03-08 05:36:58 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var View = Backbone.View.extend({
|
|
|
|
tagName: 'li',
|
2016-03-18 03:21:26 +00:00
|
|
|
className: 'msg ovhd',
|
2016-03-08 05:36:58 +00:00
|
|
|
|
|
|
|
template: _.template($('#group-discussion-tmpl').html()),
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'mouseenter': 'highlight',
|
2016-03-18 03:21:26 +00:00
|
|
|
'mouseleave': 'rmHighlight',
|
|
|
|
'click .js-del-msg': 'delMessage'
|
2016-03-08 05:36:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function() {
|
2016-03-18 03:21:26 +00:00
|
|
|
this.listenTo(this.model, 'destroy', this.remove);
|
2016-03-08 05:36:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var obj = this.model.attributes;
|
2016-03-17 07:43:05 +00:00
|
|
|
var m = Moment(obj['created_at']);
|
|
|
|
|
|
|
|
var user_profile_url = Common.getUrl({
|
|
|
|
'name': 'user_profile',
|
|
|
|
'username': encodeURIComponent(obj.user_email)
|
|
|
|
});
|
2016-03-08 05:36:58 +00:00
|
|
|
_.extend(obj, {
|
2016-03-17 07:43:05 +00:00
|
|
|
'content_marked': Marked(obj.content, { breaks: true }),
|
|
|
|
'time': m.format('LLLL'),
|
|
|
|
'time_from_now': Common.getRelativeTimeStr(m),
|
|
|
|
'user_profile_url': user_profile_url
|
2016-03-08 05:36:58 +00:00
|
|
|
});
|
|
|
|
this.$el.html(this.template(obj));
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
highlight: function() {
|
|
|
|
this.$el.addClass('hl');
|
|
|
|
},
|
|
|
|
|
|
|
|
rmHighlight: function() {
|
|
|
|
this.$el.removeClass('hl');
|
2016-03-18 03:21:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
delMessage: function() {
|
|
|
|
this.model.destroy({
|
|
|
|
wait: true,
|
|
|
|
success: function() {
|
|
|
|
},
|
|
|
|
error: function(model, response) {
|
|
|
|
var err;
|
|
|
|
if (response.responseText) {
|
|
|
|
err = $.parseJSON(response.responseText).error_msg;
|
|
|
|
} else {
|
|
|
|
err = gettext("Failed. Please check the network.");
|
|
|
|
}
|
|
|
|
Common.feedback(err, 'error');
|
|
|
|
}
|
|
|
|
});
|
2016-03-08 05:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return View;
|
|
|
|
});
|