1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-29 00:17:18 +00:00
seahub/static/scripts/app/views/group-discussion.js

95 lines
2.7 KiB
JavaScript
Raw Normal View History

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',
2016-03-19 06:47:44 +00:00
'click .js-del-msg': 'delMessage',
'click .js-reply-msg': 'reply'
2016-03-08 05:36:58 +00:00
},
2016-03-19 06:47:44 +00:00
initialize: function(options) {
2016-03-18 03:21:26 +00:00
this.listenTo(this.model, 'destroy', this.remove);
2016-03-19 06:47:44 +00:00
this.parentView = options.parentView;
this.is_group_owner = options.is_group_owner;
this.is_group_admin = options.is_group_admin;
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 can_delete_msg = false;
if (this.is_group_owner ||
this.is_group_admin ||
this.model.get('user_email') == app.pageOptions.username) {
can_delete_msg = true;
}
2016-03-17 07:43:05 +00:00
var user_profile_url = Common.getUrl({
'name': 'user_profile',
'username': encodeURIComponent(obj.user_email)
});
2016-03-08 05:36:58 +00:00
_.extend(obj, {
'content_marked': Marked(obj.content, {
breaks: true,
sanitize: true
}),
2016-03-17 07:43:05 +00:00
'time': m.format('LLLL'),
'time_from_now': Common.getRelativeTimeStr(m),
'can_delete_msg': can_delete_msg,
2016-03-17 07:43:05 +00:00
'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');
this.$('.msg-ops').removeClass('vh');
2016-03-08 05:36:58 +00:00
},
rmHighlight: function() {
this.$el.removeClass('hl');
this.$('.msg-ops').addClass('vh');
2016-03-18 03:21:26 +00:00
},
2016-03-19 06:47:44 +00:00
reply: function() {
this.parentView.replyTo(this.model.get("user_name"));
2016-03-19 06:47:44 +00:00
},
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;
});